* .version, sdcc.spec, doc/sdccman.lyx, doc/INSTALL.txt: changed version to 2.8.0
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.5 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes would otherwise result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.8.0
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc.) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the -
840 \begin_inset ERT
841 status collapsed
842
843 \begin_layout Standard
844
845
846 \backslash
847 /
848 \end_layout
849
850 \end_inset
851
852 -short-is-8bits commandline option (see 
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
854
855 \end_inset
856
857 ).
858 \end_layout
859
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862  files are stored is now in /usr/local/share.
863 \end_layout
864
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
868
869 \end_inset
870
871  functions are casted to int unless explicitly casted and 
872 \series bold
873 -
874 \begin_inset ERT
875 status collapsed
876
877 \begin_layout Standard
878
879
880 \backslash
881 /
882 \end_layout
883
884 \end_inset
885
886 -std-c89
887 \begin_inset LatexCommand \index{-\/-std-c89}
888
889 \end_inset
890
891  
892 \series default
893 and
894 \series bold
895  -
896 \begin_inset ERT
897 status collapsed
898
899 \begin_layout Standard
900
901
902 \backslash
903 /
904 \end_layout
905
906 \end_inset
907
908 -std-c99
909 \begin_inset LatexCommand \index{-\/-std-c99}
910
911 \end_inset
912
913
914 \series default
915  command line option are not defined 
916 \begin_inset Marginal
917 status collapsed
918
919 \begin_layout Standard
920
921 \series bold
922 \InsetSpace ~
923 !
924 \end_layout
925
926 \end_inset
927
928 , e.g.: 
929 \newline
930
931 \family typewriter
932 \InsetSpace ~
933 \InsetSpace ~
934 char a=3;
935 \newline
936 \InsetSpace ~
937 \InsetSpace ~
938 printf ("%d %c
939 \backslash
940 n", a, (char)a);
941 \family default
942
943 \newline
944  will push a as an int and as a char resp if
945 \series bold
946  -
947 \begin_inset ERT
948 status collapsed
949
950 \begin_layout Standard
951
952
953 \backslash
954 /
955 \end_layout
956
957 \end_inset
958
959 -std-c89
960 \begin_inset LatexCommand \index{-\/-std-c89}
961
962 \end_inset
963
964  
965 \series default
966 and
967 \series bold
968  -
969 \begin_inset ERT
970 status collapsed
971
972 \begin_layout Standard
973
974
975 \backslash
976 /
977 \end_layout
978
979 \end_inset
980
981 -std-c99
982 \begin_inset LatexCommand \index{-\/-std-c99}
983
984 \end_inset
985
986
987 \series default
988  command line options are not defined,
989 \newline
990  will push a as two ints if
991 \series bold
992  -
993 \begin_inset ERT
994 status collapsed
995
996 \begin_layout Standard
997
998
999 \backslash
1000 /
1001 \end_layout
1002
1003 \end_inset
1004
1005 -std-c89
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1007
1008 \end_inset
1009
1010  
1011 \series default
1012 or
1013 \series bold
1014  -
1015 \begin_inset ERT
1016 status collapsed
1017
1018 \begin_layout Standard
1019
1020
1021 \backslash
1022 /
1023 \end_layout
1024
1025 \end_inset
1026
1027 -std-c99
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1029
1030 \end_inset
1031
1032
1033 \series default
1034  command line option is defined.
1035 \end_layout
1036
1037 \begin_layout Itemize
1038 option -
1039 \begin_inset ERT
1040 status collapsed
1041
1042 \begin_layout Standard
1043
1044
1045 \backslash
1046 /
1047 \end_layout
1048
1049 \end_inset
1050
1051 -regextend has been removed.
1052 \end_layout
1053
1054 \begin_layout Itemize
1055 option -
1056 \begin_inset ERT
1057 status collapsed
1058
1059 \begin_layout Standard
1060
1061
1062 \backslash
1063 /
1064 \end_layout
1065
1066 \end_inset
1067
1068 -noregparms has been removed.
1069 \end_layout
1070
1071 \begin_layout Itemize
1072 option -
1073 \begin_inset ERT
1074 status collapsed
1075
1076 \begin_layout Standard
1077
1078
1079 \backslash
1080 /
1081 \end_layout
1082
1083 \end_inset
1084
1085 -stack-after-data has been removed.
1086 \end_layout
1087
1088 \begin_layout Itemize
1089 bit
1090 \begin_inset LatexCommand \index{bit}
1091
1092 \end_inset
1093
1094  and sbit
1095 \begin_inset LatexCommand \index{sbit}
1096
1097 \end_inset
1098
1099
1100 \begin_inset LatexCommand \index{\_\_sbit}
1101
1102 \end_inset
1103
1104  types now consistently behave like the C99 _Bool type with respect to type
1105  conversion
1106 \begin_inset LatexCommand \index{type conversion}
1107
1108 \end_inset
1109
1110
1111 \begin_inset LatexCommand \index{type promotion}
1112
1113 \end_inset
1114
1115 .
1116  The most common incompatibility resulting from this change is related to
1117  bit toggling
1118 \begin_inset LatexCommand \index{Bit toggling}
1119
1120 \end_inset
1121
1122  idioms, e.g.:
1123 \newline
1124
1125 \family typewriter
1126 \InsetSpace ~
1127 \InsetSpace ~
1128 bit b;
1129 \newline
1130 \InsetSpace ~
1131 \InsetSpace ~
1132 b = ~
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1134
1135 \end_inset
1136
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1139 status collapsed
1140
1141 \begin_layout Standard
1142
1143 \series bold
1144 \InsetSpace ~
1145 !
1146 \end_layout
1147
1148 \end_inset
1149
1150
1151 \newline
1152 \InsetSpace ~
1153 \InsetSpace ~
1154 b = !b; /* toggles b */
1155 \newline
1156
1157 \family default
1158 In previous versions, both forms would have toggled the bit.
1159 \end_layout
1160
1161 \begin_layout Standard
1162
1163 \emph on
1164 <pending: more incompatibilities?>
1165 \end_layout
1166
1167 \begin_layout Section
1168 System Requirements
1169 \end_layout
1170
1171 \begin_layout Standard
1172 What do you need before you start installation of SDCC? A computer, and
1173  a desire to compute.
1174  The preferred method of installation is to compile SDCC from source using
1175  GNU gcc and make.
1176  For Windows some pre-compiled binary distributions are available for your
1177  convenience.
1178  You should have some experience with command line tools and compiler use.
1179 \end_layout
1180
1181 \begin_layout Section
1182 Other Resources
1183 \end_layout
1184
1185 \begin_layout Standard
1186 The SDCC home page at 
1187 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1188
1189 \end_inset
1190
1191  is a great place to find distribution sets.
1192  You can also find links to the user mailing lists that offer help or discuss
1193  SDCC with other SDCC users.
1194  Web links to other SDCC related sites can also be found here.
1195  This document can be found in the DOC directory of the source package as
1196  a text or HTML file.
1197  A pdf version of this document is available at 
1198 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1199
1200 \end_inset
1201
1202 .
1203  Some of the other tools (simulator and assembler) included with SDCC contain
1204  their own documentation and can be found in the source distribution.
1205  If you want the latest unreleased software, the complete source package
1206  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1207 sdcc/trunk/sdcc.
1208 \end_layout
1209
1210 \begin_layout Section
1211 Wishes for the future
1212 \end_layout
1213
1214 \begin_layout Standard
1215 There are (and always will be) some things that could be done.
1216  Here are some I can think of:
1217 \newline
1218
1219 \end_layout
1220
1221 \begin_layout Standard
1222
1223 \family typewriter
1224 char KernelFunction3(char p) at 0x340;
1225 \newline
1226
1227 \end_layout
1228
1229 \begin_layout Standard
1230
1231 \family typewriter
1232 better code banking
1233 \begin_inset LatexCommand \index{code banking (limited support)}
1234
1235 \end_inset
1236
1237  support for mcs51
1238 \newline
1239
1240 \newline
1241
1242 \family default
1243 If you can think of some more, please see the section 
1244 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1245
1246 \end_inset
1247
1248  about filing feature requests
1249 \begin_inset LatexCommand \index{Requesting features}
1250
1251 \end_inset
1252
1253
1254 \begin_inset LatexCommand \index{Feature request}
1255
1256 \end_inset
1257
1258 .
1259 \newline
1260
1261 \end_layout
1262
1263 \begin_layout Chapter
1264 Installing SDCC
1265 \begin_inset LatexCommand \index{Installation}
1266
1267 \end_inset
1268
1269
1270 \end_layout
1271
1272 \begin_layout Standard
1273 For most users it is sufficient to skip to either section 
1274 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1275
1276 \end_inset
1277
1278  (Unix) or section 
1279 \begin_inset LatexCommand \ref{sub:Windows-Install}
1280
1281 \end_inset
1282
1283  (Windows).
1284  More detailed instructions follow below.
1285 \end_layout
1286
1287 \begin_layout Section
1288 Configure Options
1289 \begin_inset LatexCommand \index{Options SDCC configuration}
1290
1291 \end_inset
1292
1293
1294 \end_layout
1295
1296 \begin_layout Standard
1297 The install paths, search paths and other options are defined when running
1298  'configure'.
1299  The defaults can be overridden by:
1300 \end_layout
1301
1302 \begin_layout List
1303 \labelwidthstring 00.00.0000
1304 -
1305 \begin_inset ERT
1306 status collapsed
1307
1308 \begin_layout Standard
1309
1310
1311 \backslash
1312 /
1313 \end_layout
1314
1315 \end_inset
1316
1317 -prefix see table below
1318 \end_layout
1319
1320 \begin_layout List
1321 \labelwidthstring 00.00.0000
1322 -
1323 \begin_inset ERT
1324 status collapsed
1325
1326 \begin_layout Standard
1327
1328
1329 \backslash
1330 /
1331 \end_layout
1332
1333 \end_inset
1334
1335 -exec_prefix see table below
1336 \end_layout
1337
1338 \begin_layout List
1339 \labelwidthstring 00.00.0000
1340 -
1341 \begin_inset ERT
1342 status collapsed
1343
1344 \begin_layout Standard
1345
1346
1347 \backslash
1348 /
1349 \end_layout
1350
1351 \end_inset
1352
1353 -bindir see table below
1354 \end_layout
1355
1356 \begin_layout List
1357 \labelwidthstring 00.00.0000
1358 -
1359 \begin_inset ERT
1360 status collapsed
1361
1362 \begin_layout Standard
1363
1364
1365 \backslash
1366 /
1367 \end_layout
1368
1369 \end_inset
1370
1371 -datadir see table below
1372 \end_layout
1373
1374 \begin_layout List
1375 \labelwidthstring 00.00.0000
1376 -
1377 \begin_inset ERT
1378 status collapsed
1379
1380 \begin_layout Standard
1381
1382
1383 \backslash
1384 /
1385 \end_layout
1386
1387 \end_inset
1388
1389 -datarootdir see table below
1390 \newline
1391
1392 \end_layout
1393
1394 \begin_layout List
1395 \labelwidthstring 00.00.0000
1396 \InsetSpace ~
1397 \InsetSpace ~
1398 docdir environment variable, see table below
1399 \end_layout
1400
1401 \begin_layout List
1402 \labelwidthstring 00.00.0000
1403 \InsetSpace ~
1404 \InsetSpace ~
1405 include_dir_suffix environment variable, see table below
1406 \end_layout
1407
1408 \begin_layout List
1409 \labelwidthstring 00.00.0000
1410 \InsetSpace ~
1411 \InsetSpace ~
1412 lib_dir_suffix environment variable, see table below
1413 \end_layout
1414
1415 \begin_layout List
1416 \labelwidthstring 00.00.0000
1417 \InsetSpace ~
1418 \InsetSpace ~
1419 sdccconf_h_dir_separator environment variable, either / or 
1420 \backslash
1421
1422 \backslash
1423  makes sense here.
1424  This character will only be used in sdccconf.h; don't forget it's a C-header,
1425  therefore a double-backslash is needed there.
1426 \newline
1427
1428 \end_layout
1429
1430 \begin_layout List
1431 \labelwidthstring 00.00.0000
1432 -
1433 \begin_inset ERT
1434 status collapsed
1435
1436 \begin_layout Standard
1437
1438
1439 \backslash
1440 /
1441 \end_layout
1442
1443 \end_inset
1444
1445 -disable-mcs51-port Excludes the Intel mcs51 port
1446 \end_layout
1447
1448 \begin_layout List
1449 \labelwidthstring 00.00.0000
1450 -
1451 \begin_inset ERT
1452 status collapsed
1453
1454 \begin_layout Standard
1455
1456
1457 \backslash
1458 /
1459 \end_layout
1460
1461 \end_inset
1462
1463 -disable-gbz80-port Excludes the Gameboy gbz80 port
1464 \end_layout
1465
1466 \begin_layout List
1467 \labelwidthstring 00.00.0000
1468 -
1469 \begin_inset ERT
1470 status collapsed
1471
1472 \begin_layout Standard
1473
1474
1475 \backslash
1476 /
1477 \end_layout
1478
1479 \end_inset
1480
1481 -disable-z80-port Excludes the z80 port
1482 \end_layout
1483
1484 \begin_layout List
1485 \labelwidthstring 00.00.0000
1486 -
1487 \begin_inset ERT
1488 status collapsed
1489
1490 \begin_layout Standard
1491
1492
1493 \backslash
1494 /
1495 \end_layout
1496
1497 \end_inset
1498
1499 -disable-avr-port Excludes the AVR port
1500 \end_layout
1501
1502 \begin_layout List
1503 \labelwidthstring 00.00.0000
1504 -
1505 \begin_inset ERT
1506 status collapsed
1507
1508 \begin_layout Standard
1509
1510
1511 \backslash
1512 /
1513 \end_layout
1514
1515 \end_inset
1516
1517 -disable-ds390-port Excludes the DS390 port
1518 \end_layout
1519
1520 \begin_layout List
1521 \labelwidthstring 00.00.0000
1522 -
1523 \begin_inset ERT
1524 status collapsed
1525
1526 \begin_layout Standard
1527
1528
1529 \backslash
1530 /
1531 \end_layout
1532
1533 \end_inset
1534
1535 -disable-hc08-port Excludes the HC08 port
1536 \end_layout
1537
1538 \begin_layout List
1539 \labelwidthstring 00.00.0000
1540 -
1541 \begin_inset ERT
1542 status collapsed
1543
1544 \begin_layout Standard
1545
1546
1547 \backslash
1548 /
1549 \end_layout
1550
1551 \end_inset
1552
1553 -disable-pic-port Excludes the PIC14 port
1554 \end_layout
1555
1556 \begin_layout List
1557 \labelwidthstring 00.00.0000
1558 -
1559 \begin_inset ERT
1560 status collapsed
1561
1562 \begin_layout Standard
1563
1564
1565 \backslash
1566 /
1567 \end_layout
1568
1569 \end_inset
1570
1571 -disable-pic16-port Excludes the PIC16 port
1572 \end_layout
1573
1574 \begin_layout List
1575 \labelwidthstring 00.00.0000
1576 -
1577 \begin_inset ERT
1578 status collapsed
1579
1580 \begin_layout Standard
1581
1582
1583 \backslash
1584 /
1585 \end_layout
1586
1587 \end_inset
1588
1589 -disable-xa51-port Excludes the XA51 port
1590 \end_layout
1591
1592 \begin_layout List
1593 \labelwidthstring 00.00.0000
1594 -
1595 \begin_inset ERT
1596 status collapsed
1597
1598 \begin_layout Standard
1599
1600
1601 \backslash
1602 /
1603 \end_layout
1604
1605 \end_inset
1606
1607 -disable-ucsim Disables configuring and building of ucsim
1608 \end_layout
1609
1610 \begin_layout List
1611 \labelwidthstring 00.00.0000
1612 -
1613 \begin_inset ERT
1614 status collapsed
1615
1616 \begin_layout Standard
1617
1618
1619 \backslash
1620 /
1621 \end_layout
1622
1623 \end_inset
1624
1625 -disable-device-lib Disables automatically building device libraries
1626 \end_layout
1627
1628 \begin_layout List
1629 \labelwidthstring 00.00.0000
1630 -
1631 \begin_inset ERT
1632 status collapsed
1633
1634 \begin_layout Standard
1635
1636
1637 \backslash
1638 /
1639 \end_layout
1640
1641 \end_inset
1642
1643 -disable-packihx Disables building packihx
1644 \newline
1645
1646 \end_layout
1647
1648 \begin_layout List
1649 \labelwidthstring 00.00.0000
1650 -
1651 \begin_inset ERT
1652 status collapsed
1653
1654 \begin_layout Standard
1655
1656
1657 \backslash
1658 /
1659 \end_layout
1660
1661 \end_inset
1662
1663 -enable-doc Build pdf, html and txt files from the lyx sources
1664 \end_layout
1665
1666 \begin_layout List
1667 \labelwidthstring 00.00.0000
1668 -
1669 \begin_inset ERT
1670 status collapsed
1671
1672 \begin_layout Standard
1673
1674
1675 \backslash
1676 /
1677 \end_layout
1678
1679 \end_inset
1680
1681 -enable-libgc Use the Bohem memory allocator.
1682  Lower runtime footprint.
1683 \end_layout
1684
1685 \begin_layout Standard
1686 Furthermore the environment variables CC, CFLAGS, ...
1687  the tools and their arguments can be influenced.
1688  Please see `configure -
1689 \begin_inset ERT
1690 status collapsed
1691
1692 \begin_layout Standard
1693
1694
1695 \backslash
1696 /
1697 \end_layout
1698
1699 \end_inset
1700
1701 -help' and the man/info pages of `configure' for details.
1702 \newline
1703
1704 \newline
1705 The names of the
1706  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1707 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1708  SDCC_LIB_NAME are defined by `configure' too.
1709  At the moment it's not possible to change the default settings (it was
1710  simply never required).
1711 \newline
1712
1713 \newline
1714 These configure options are compiled into the binaries,
1715  and can only be changed by rerunning 'configure' and recompiling SDCC.
1716  The configure options are written in 
1717 \emph on
1718 italics
1719 \emph default
1720  to distinguish them from run time environment variables (see section search
1721  paths).
1722 \newline
1723
1724 \newline
1725 The settings for 
1726 \begin_inset Quotes sld
1727 \end_inset
1728
1729 Win32 builds
1730 \begin_inset Quotes srd
1731 \end_inset
1732
1733  are used by the SDCC team to build the official Win32 binaries.
1734  The SDCC team uses Mingw32 to build the official Windows binaries, because
1735  it's
1736 \end_layout
1737
1738 \begin_layout Enumerate
1739 open source, 
1740 \end_layout
1741
1742 \begin_layout Enumerate
1743 a gcc compiler and last but not least
1744 \end_layout
1745
1746 \begin_layout Enumerate
1747 the binaries can be built by cross compiling on SDCC Distributed Compile
1748  Farm.
1749 \end_layout
1750
1751 \begin_layout Standard
1752 See the examples, how to pass the Win32 settings to 'configure'.
1753  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1754  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1755  for Win32.
1756 \newline
1757
1758 \newline
1759 These defaults are:
1760 \newline
1761
1762 \end_layout
1763
1764 \begin_layout Standard
1765 \align center
1766 \begin_inset Tabular
1767 <lyxtabular version="3" rows="9" columns="3">
1768 <features>
1769 <column alignment="block" valignment="top" leftline="true" width="0in">
1770 <column alignment="block" valignment="top" leftline="true" width="0in">
1771 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1772 <row topline="true" bottomline="true">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 \begin_inset Text
1775
1776 \begin_layout Standard
1777 Variable
1778 \end_layout
1779
1780 \end_inset
1781 </cell>
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786 default
1787 \end_layout
1788
1789 \end_inset
1790 </cell>
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1792 \begin_inset Text
1793
1794 \begin_layout Standard
1795 Win32 builds
1796 \end_layout
1797
1798 \end_inset
1799 </cell>
1800 </row>
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1803 \begin_inset Text
1804
1805 \begin_layout Standard
1806
1807 \emph on
1808 PREFIX
1809 \end_layout
1810
1811 \end_inset
1812 </cell>
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_inset Text
1815
1816 \begin_layout Standard
1817 /usr/local
1818 \end_layout
1819
1820 \end_inset
1821 </cell>
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1823 \begin_inset Text
1824
1825 \begin_layout Standard
1826
1827 \backslash
1828 sdcc
1829 \end_layout
1830
1831 \end_inset
1832 </cell>
1833 </row>
1834 <row topline="true">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1836 \begin_inset Text
1837
1838 \begin_layout Standard
1839
1840 \emph on
1841 EXEC_PREFIX
1842 \end_layout
1843
1844 \end_inset
1845 </cell>
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1847 \begin_inset Text
1848
1849 \begin_layout Standard
1850
1851 \emph on
1852 $PREFIX
1853 \end_layout
1854
1855 \end_inset
1856 </cell>
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1858 \begin_inset Text
1859
1860 \begin_layout Standard
1861
1862 \emph on
1863 $PREFIX
1864 \end_layout
1865
1866 \end_inset
1867 </cell>
1868 </row>
1869 <row topline="true">
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 \begin_inset Text
1872
1873 \begin_layout Standard
1874
1875 \emph on
1876 BINDIR
1877 \end_layout
1878
1879 \end_inset
1880 </cell>
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1882 \begin_inset Text
1883
1884 \begin_layout Standard
1885
1886 \emph on
1887 $EXEC_PREFIX
1888 \emph default
1889 /bin
1890 \end_layout
1891
1892 \end_inset
1893 </cell>
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1895 \begin_inset Text
1896
1897 \begin_layout Standard
1898
1899 \emph on
1900 $EXEC_PREFIX
1901 \emph default
1902
1903 \backslash
1904 bin
1905 \end_layout
1906
1907 \end_inset
1908 </cell>
1909 </row>
1910 <row topline="true">
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915
1916 \emph on
1917 DATADIR
1918 \end_layout
1919
1920 \end_inset
1921 </cell>
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1923 \begin_inset Text
1924
1925 \begin_layout Standard
1926
1927 \emph on
1928 $DATAROOTDIR
1929 \end_layout
1930
1931 \end_inset
1932 </cell>
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1934 \begin_inset Text
1935
1936 \begin_layout Standard
1937
1938 \emph on
1939 $DATAROOTDIR
1940 \end_layout
1941
1942 \end_inset
1943 </cell>
1944 </row>
1945 <row topline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1947 \begin_inset Text
1948
1949 \begin_layout Standard
1950
1951 \emph on
1952 DATAROOTDIR
1953 \end_layout
1954
1955 \end_inset
1956 </cell>
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961
1962 \emph on
1963 $PREFIX
1964 \emph default
1965 /share
1966 \end_layout
1967
1968 \end_inset
1969 </cell>
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1971 \begin_inset Text
1972
1973 \begin_layout Standard
1974
1975 \emph on
1976 $PREFIX
1977 \end_layout
1978
1979 \end_inset
1980 </cell>
1981 </row>
1982 <row topline="true">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1984 \begin_inset Text
1985
1986 \begin_layout Standard
1987
1988 \emph on
1989 DOCDIR
1990 \end_layout
1991
1992 \end_inset
1993 </cell>
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1995 \begin_inset Text
1996
1997 \begin_layout Standard
1998
1999 \emph on
2000 $DATAROOTDIR
2001 \emph default
2002 /sdcc/doc
2003 \end_layout
2004
2005 \end_inset
2006 </cell>
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 $DATAROOTDIR
2014 \emph default
2015
2016 \backslash
2017 doc
2018 \end_layout
2019
2020 \end_inset
2021 </cell>
2022 </row>
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \begin_layout Standard
2028
2029 \emph on
2030 INCLUDE_DIR_SUFFIX
2031 \end_layout
2032
2033 \end_inset
2034 </cell>
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 \begin_inset Text
2037
2038 \begin_layout Standard
2039 sdcc/include
2040 \end_layout
2041
2042 \end_inset
2043 </cell>
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \begin_layout Standard
2048 include
2049 \end_layout
2050
2051 \end_inset
2052 </cell>
2053 </row>
2054 <row topline="true" bottomline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 \begin_inset Text
2057
2058 \begin_layout Standard
2059
2060 \emph on
2061 LIB_DIR_SUFFIX
2062 \end_layout
2063
2064 \end_inset
2065 </cell>
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2067 \begin_inset Text
2068
2069 \begin_layout Standard
2070 sdcc/lib
2071 \end_layout
2072
2073 \end_inset
2074 </cell>
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2076 \begin_inset Text
2077
2078 \begin_layout Standard
2079 lib
2080 \end_layout
2081
2082 \end_inset
2083 </cell>
2084 </row>
2085 </lyxtabular>
2086
2087 \end_inset
2088
2089
2090 \newline
2091
2092 \end_layout
2093
2094 \begin_layout Standard
2095 \noindent
2096 'configure' also computes relative paths.
2097  This is needed for full relocatability of a binary package and to complete
2098  search paths (see section search paths below):
2099 \newline
2100  
2101 \end_layout
2102
2103 \begin_layout Standard
2104 \align center
2105 \begin_inset Tabular
2106 <lyxtabular version="3" rows="4" columns="3">
2107 <features>
2108 <column alignment="block" valignment="top" leftline="true" width="0in">
2109 <column alignment="block" valignment="top" leftline="true" width="0in">
2110 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2113 \begin_inset Text
2114
2115 \begin_layout Standard
2116 Variable (computed)
2117 \end_layout
2118
2119 \end_inset
2120 </cell>
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2122 \begin_inset Text
2123
2124 \begin_layout Standard
2125 default
2126 \end_layout
2127
2128 \end_inset
2129 </cell>
2130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2131 \begin_inset Text
2132
2133 \begin_layout Standard
2134 Win32 builds
2135 \end_layout
2136
2137 \end_inset
2138 </cell>
2139 </row>
2140 <row topline="true" bottomline="true">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 \begin_inset Text
2143
2144 \begin_layout Standard
2145
2146 \emph on
2147 BIN2DATA_DIR
2148 \end_layout
2149
2150 \end_inset
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \begin_layout Standard
2156 ../share
2157 \end_layout
2158
2159 \end_inset
2160 </cell>
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2162 \begin_inset Text
2163
2164 \begin_layout Standard
2165 ..
2166 \end_layout
2167
2168 \end_inset
2169 </cell>
2170 </row>
2171 <row bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_inset Text
2174
2175 \begin_layout Standard
2176
2177 \emph on
2178 PREFIX2BIN_DIR
2179 \end_layout
2180
2181 \end_inset
2182 </cell>
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2184 \begin_inset Text
2185
2186 \begin_layout Standard
2187 bin
2188 \end_layout
2189
2190 \end_inset
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \begin_layout Standard
2196 bin
2197 \end_layout
2198
2199 \end_inset
2200 </cell>
2201 </row>
2202 <row bottomline="true">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2204 \begin_inset Text
2205
2206 \begin_layout Standard
2207
2208 \emph on
2209 PREFIX2DATA_DIR
2210 \end_layout
2211
2212 \end_inset
2213 </cell>
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2215 \begin_inset Text
2216
2217 \begin_layout Standard
2218 share/sdcc
2219 \end_layout
2220
2221 \end_inset
2222 </cell>
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2224 \begin_inset Text
2225
2226 \begin_layout Standard
2227
2228 \end_layout
2229
2230 \end_inset
2231 </cell>
2232 </row>
2233 </lyxtabular>
2234
2235 \end_inset
2236
2237
2238 \newline
2239
2240 \end_layout
2241
2242 \begin_layout Standard
2243 \noindent
2244 Examples:
2245 \end_layout
2246
2247 \begin_layout LyX-Code
2248 ./configure
2249 \newline
2250 ./configure -
2251 \begin_inset ERT
2252 status collapsed
2253
2254 \begin_layout Standard
2255
2256
2257 \backslash
2258 /
2259 \end_layout
2260
2261 \end_inset
2262
2263 -prefix=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267 /usr/bin
2268 \begin_inset Quotes srd
2269 \end_inset
2270
2271  -
2272 \begin_inset ERT
2273 status collapsed
2274
2275 \begin_layout Standard
2276
2277
2278 \backslash
2279 /
2280 \end_layout
2281
2282 \end_inset
2283
2284 -datarootdir=
2285 \begin_inset Quotes srd
2286 \end_inset
2287
2288 /usr/share
2289 \begin_inset Quotes srd
2290 \end_inset
2291
2292
2293 \newline
2294 ./configure -
2295 \begin_inset ERT
2296 status collapsed
2297
2298 \begin_layout Standard
2299
2300
2301 \backslash
2302 /
2303 \end_layout
2304
2305 \end_inset
2306
2307 -disable-avr-port -
2308 \begin_inset ERT
2309 status collapsed
2310
2311 \begin_layout Standard
2312
2313
2314 \backslash
2315 /
2316 \end_layout
2317
2318 \end_inset
2319
2320 -disable-xa51-port
2321 \end_layout
2322
2323 \begin_layout Standard
2324 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2325 32'):
2326 \end_layout
2327
2328 \begin_layout LyX-Code
2329 ./configure 
2330 \backslash
2331
2332 \newline
2333 CC=
2334 \begin_inset Quotes srd
2335 \end_inset
2336
2337 i586-mingw32msvc-gcc
2338 \begin_inset Quotes srd
2339 \end_inset
2340
2341  CXX=
2342 \begin_inset Quotes srd
2343 \end_inset
2344
2345 i586-mingw32msvc-g++
2346 \begin_inset Quotes srd
2347 \end_inset
2348
2349  
2350 \backslash
2351  
2352 \newline
2353 RANLIB=
2354 \begin_inset Quotes srd
2355 \end_inset
2356
2357 i586-mingw32msvc-ranlib
2358 \begin_inset Quotes srd
2359 \end_inset
2360
2361  
2362 \backslash
2363
2364 \newline
2365 STRIP=
2366 \begin_inset Quotes srd
2367 \end_inset
2368
2369 i586-mingw32msvc-strip
2370 \begin_inset Quotes srd
2371 \end_inset
2372
2373  
2374 \backslash
2375
2376 \newline
2377 -
2378 \begin_inset ERT
2379 status collapsed
2380
2381 \begin_layout Standard
2382
2383
2384 \backslash
2385 /
2386 \end_layout
2387
2388 \end_inset
2389
2390 -prefix=
2391 \begin_inset Quotes srd
2392 \end_inset
2393
2394 /sdcc
2395 \begin_inset Quotes srd
2396 \end_inset
2397
2398  
2399 \backslash
2400
2401 \newline
2402 -
2403 \begin_inset ERT
2404 status collapsed
2405
2406 \begin_layout Standard
2407
2408
2409 \backslash
2410 /
2411 \end_layout
2412
2413 \end_inset
2414
2415 -datarootdir=
2416 \begin_inset Quotes srd
2417 \end_inset
2418
2419 /sdcc
2420 \begin_inset Quotes srd
2421 \end_inset
2422
2423  
2424 \backslash
2425
2426 \newline
2427 docdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431
2432 \backslash
2433 ${datarootdir}/doc
2434 \begin_inset Quotes srd
2435 \end_inset
2436
2437  
2438 \backslash
2439
2440 \newline
2441 include_dir_suffix=
2442 \begin_inset Quotes srd
2443 \end_inset
2444
2445 include
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451
2452 \newline
2453 lib_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 lib
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 sdccconf_h_dir_separator=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469
2470 \backslash
2471
2472 \backslash
2473
2474 \backslash
2475
2476 \backslash
2477
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481  
2482 \backslash
2483
2484 \newline
2485 -
2486 \begin_inset ERT
2487 status collapsed
2488
2489 \begin_layout Standard
2490
2491
2492 \backslash
2493 /
2494 \end_layout
2495
2496 \end_inset
2497
2498 -disable-device-lib
2499 \backslash
2500
2501 \newline
2502 -
2503 \begin_inset ERT
2504 status collapsed
2505
2506 \begin_layout Standard
2507
2508
2509 \backslash
2510 /
2511 \end_layout
2512
2513 \end_inset
2514
2515 -host=i586-mingw32msvc
2516 \backslash
2517
2518 \newline
2519 -
2520 \begin_inset ERT
2521 status collapsed
2522
2523 \begin_layout Standard
2524
2525
2526 \backslash
2527 /
2528 \end_layout
2529
2530 \end_inset
2531
2532 -build=unknown-unknown-linux-gnu
2533 \end_layout
2534
2535 \begin_layout Standard
2536 To 
2537 \begin_inset Quotes sld
2538 \end_inset
2539
2540 cross
2541 \begin_inset Quotes srd
2542 \end_inset
2543
2544 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2545 ):
2546 \end_layout
2547
2548 \begin_layout LyX-Code
2549 ./configure -C 
2550 \backslash
2551
2552 \newline
2553 -
2554 \begin_inset ERT
2555 status collapsed
2556
2557 \begin_layout Standard
2558
2559
2560 \backslash
2561 /
2562 \end_layout
2563
2564 \end_inset
2565
2566 -prefix=
2567 \begin_inset Quotes srd
2568 \end_inset
2569
2570 /sdcc
2571 \begin_inset Quotes srd
2572 \end_inset
2573
2574  
2575 \backslash
2576
2577 \newline
2578 -
2579 \begin_inset ERT
2580 status collapsed
2581
2582 \begin_layout Standard
2583
2584
2585 \backslash
2586 /
2587 \end_layout
2588
2589 \end_inset
2590
2591 -datarootdir=
2592 \begin_inset Quotes srd
2593 \end_inset
2594
2595 /sdcc
2596 \begin_inset Quotes srd
2597 \end_inset
2598
2599  
2600 \backslash
2601
2602 \newline
2603 docdir=
2604 \begin_inset Quotes srd
2605 \end_inset
2606
2607
2608 \backslash
2609 ${datarootdir}/doc
2610 \begin_inset Quotes srd
2611 \end_inset
2612
2613  
2614 \backslash
2615  
2616 \newline
2617 include_dir_suffix=
2618 \begin_inset Quotes srd
2619 \end_inset
2620
2621 include
2622 \begin_inset Quotes srd
2623 \end_inset
2624
2625  
2626 \backslash
2627
2628 \newline
2629 lib_dir_suffix=
2630 \begin_inset Quotes srd
2631 \end_inset
2632
2633 lib
2634 \begin_inset Quotes srd
2635 \end_inset
2636
2637  
2638 \backslash
2639
2640 \newline
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645
2646 \backslash
2647
2648 \backslash
2649
2650 \backslash
2651
2652 \backslash
2653
2654 \begin_inset Quotes srd
2655 \end_inset
2656
2657  
2658 \backslash
2659
2660 \newline
2661 CC=
2662 \begin_inset Quotes srd
2663 \end_inset
2664
2665 gcc -mno-cygwin
2666 \begin_inset Quotes srd
2667 \end_inset
2668
2669  
2670 \backslash
2671
2672 \newline
2673 CXX=
2674 \begin_inset Quotes srd
2675 \end_inset
2676
2677 g++ -mno-cygwin
2678 \begin_inset Quotes srd
2679 \end_inset
2680
2681  
2682 \end_layout
2683
2684 \begin_layout Standard
2685 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2686  The option '-
2687 \begin_inset ERT
2688 status collapsed
2689
2690 \begin_layout Standard
2691
2692
2693 \backslash
2694 /
2695 \end_layout
2696
2697 \end_inset
2698
2699 -C' turns on caching, which gives a little bit extra speed.
2700  However if options are changed, it can be necessary to delete the config.cache
2701  file.
2702 \end_layout
2703
2704 \begin_layout Section
2705 Install paths
2706 \begin_inset LatexCommand \label{sub:Install-paths}
2707
2708 \end_inset
2709
2710
2711 \begin_inset LatexCommand \index{Install paths}
2712
2713 \end_inset
2714
2715
2716 \end_layout
2717
2718 \begin_layout Standard
2719 \begin_inset VSpace medskip
2720 \end_inset
2721
2722
2723 \end_layout
2724
2725 \begin_layout Standard
2726 \align center
2727 \begin_inset Tabular
2728 <lyxtabular version="3" rows="5" columns="4">
2729 <features>
2730 <column alignment="left" valignment="top" leftline="true" width="0">
2731 <column alignment="left" valignment="top" leftline="true" width="0">
2732 <column alignment="left" valignment="top" leftline="true" width="0">
2733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2734 <row topline="true" bottomline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \begin_layout Standard
2739
2740 \series bold
2741 Description
2742 \end_layout
2743
2744 \end_inset
2745 </cell>
2746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_inset Text
2748
2749 \begin_layout Standard
2750
2751 \series bold
2752 Path
2753 \end_layout
2754
2755 \end_inset
2756 </cell>
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_inset Text
2759
2760 \begin_layout Standard
2761
2762 \series bold
2763 Default
2764 \end_layout
2765
2766 \end_inset
2767 </cell>
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2769 \begin_inset Text
2770
2771 \begin_layout Standard
2772
2773 \series bold
2774 Win32 builds
2775 \end_layout
2776
2777 \end_inset
2778 </cell>
2779 </row>
2780 <row topline="true">
2781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_inset Text
2783
2784 \begin_layout Standard
2785 Binary files*
2786 \end_layout
2787
2788 \end_inset
2789 </cell>
2790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_inset Text
2792
2793 \begin_layout Standard
2794
2795 \emph on
2796 $EXEC_PREFIX
2797 \end_layout
2798
2799 \end_inset
2800 </cell>
2801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_inset Text
2803
2804 \begin_layout Standard
2805 /usr/local/bin
2806 \end_layout
2807
2808 \end_inset
2809 </cell>
2810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_inset Text
2812
2813 \begin_layout Standard
2814
2815 \backslash
2816 sdcc
2817 \backslash
2818 bin
2819 \end_layout
2820
2821 \end_inset
2822 </cell>
2823 </row>
2824 <row topline="true">
2825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2826 \begin_inset Text
2827
2828 \begin_layout Standard
2829 Include files
2830 \end_layout
2831
2832 \end_inset
2833 </cell>
2834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2835 \begin_inset Text
2836
2837 \begin_layout Standard
2838
2839 \emph on
2840 $DATADIR/ $INCLUDE_DIR_SUFFIX
2841 \end_layout
2842
2843 \end_inset
2844 </cell>
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2846 \begin_inset Text
2847
2848 \begin_layout Standard
2849 /usr/local/share/sdcc/include
2850 \end_layout
2851
2852 \end_inset
2853 </cell>
2854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2855 \begin_inset Text
2856
2857 \begin_layout Standard
2858
2859 \backslash
2860 sdcc
2861 \backslash
2862 include
2863 \end_layout
2864
2865 \end_inset
2866 </cell>
2867 </row>
2868 <row topline="true">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \begin_layout Standard
2873 Library file**
2874 \end_layout
2875
2876 \end_inset
2877 </cell>
2878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2879 \begin_inset Text
2880
2881 \begin_layout Standard
2882
2883 \emph on
2884 $DATADIR/$LIB_DIR_SUFFIX
2885 \end_layout
2886
2887 \end_inset
2888 </cell>
2889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2890 \begin_inset Text
2891
2892 \begin_layout Standard
2893 /usr/local/share/sdcc/lib
2894 \end_layout
2895
2896 \end_inset
2897 </cell>
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2899 \begin_inset Text
2900
2901 \begin_layout Standard
2902
2903 \backslash
2904 sdcc
2905 \backslash
2906 lib
2907 \end_layout
2908
2909 \end_inset
2910 </cell>
2911 </row>
2912 <row topline="true" bottomline="true">
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2914 \begin_inset Text
2915
2916 \begin_layout Standard
2917 Documentation
2918 \end_layout
2919
2920 \end_inset
2921 </cell>
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2923 \begin_inset Text
2924
2925 \begin_layout Standard
2926
2927 \emph on
2928 $DOCDIR
2929 \end_layout
2930
2931 \end_inset
2932 </cell>
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2934 \begin_inset Text
2935
2936 \begin_layout Standard
2937 /usr/local/share/sdcc/doc
2938 \end_layout
2939
2940 \end_inset
2941 </cell>
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \begin_layout Standard
2946
2947 \backslash
2948 sdcc
2949 \backslash
2950 doc
2951 \end_layout
2952
2953 \end_inset
2954 </cell>
2955 </row>
2956 </lyxtabular>
2957
2958 \end_inset
2959
2960
2961 \end_layout
2962
2963 \begin_layout Verse
2964
2965 \size footnotesize
2966 *compiler, preprocessor, assembler, and linker
2967 \newline
2968 **the 
2969 \shape italic
2970 model
2971 \shape default
2972  is auto-appended by the compiler, e.g.
2973  small, large, z80, ds390 etc
2974 \end_layout
2975
2976 \begin_layout Standard
2977 \noindent
2978 The install paths can still be changed during `make install' with e.g.:
2979 \end_layout
2980
2981 \begin_layout LyX-Code
2982 make install prefix=$(HOME)/local/sdcc
2983 \end_layout
2984
2985 \begin_layout Standard
2986 Of course this doesn't change the search paths compiled into the binaries.
2987 \newline
2988
2989 \newline
2990 Moreove
2991 r the install path can be changed by defining DESTDIR
2992 \begin_inset LatexCommand \index{DESTDIR}
2993
2994 \end_inset
2995
2996 :
2997 \end_layout
2998
2999 \begin_layout LyX-Code
3000 make install DESTDIR=$(HOME)/sdcc.rpm/
3001 \end_layout
3002
3003 \begin_layout Standard
3004 Please note that DESTDIR must have a trailing slash!
3005 \end_layout
3006
3007 \begin_layout Section
3008 Search Paths
3009 \begin_inset LatexCommand \label{sub:Search-Paths}
3010
3011 \end_inset
3012
3013
3014 \begin_inset LatexCommand \index{Search path}
3015
3016 \end_inset
3017
3018
3019 \end_layout
3020
3021 \begin_layout Standard
3022 Some search paths or parts of them are determined by configure variables
3023  (in 
3024 \emph on
3025 italics
3026 \emph default
3027 , see section above).
3028  Further search paths are determined by environment variables during runtime.
3029  
3030 \newline
3031 The paths searched when running the compiler are as follows (the first
3032  catch wins):
3033 \newline
3034
3035 \newline
3036 1.
3037  Binary files (preprocessor, assembler and linker)
3038 \newline
3039
3040 \end_layout
3041
3042 \begin_layout Standard
3043 \align center
3044 \begin_inset Tabular
3045 <lyxtabular version="3" rows="4" columns="3">
3046 <features>
3047 <column alignment="block" valignment="top" leftline="true" width="0in">
3048 <column alignment="block" valignment="top" leftline="true" width="0in">
3049 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3050 <row topline="true" bottomline="true">
3051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_inset Text
3053
3054 \begin_layout Standard
3055 Search path
3056 \end_layout
3057
3058 \end_inset
3059 </cell>
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_inset Text
3062
3063 \begin_layout Standard
3064 default
3065 \end_layout
3066
3067 \end_inset
3068 </cell>
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3070 \begin_inset Text
3071
3072 \begin_layout Standard
3073 Win32 builds
3074 \end_layout
3075
3076 \end_inset
3077 </cell>
3078 </row>
3079 <row topline="true">
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \begin_layout Standard
3084 $SDCC_HOME/
3085 \emph on
3086 $PPREFIX2BIN_DIR
3087 \end_layout
3088
3089 \end_inset
3090 </cell>
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_inset Text
3093
3094 \begin_layout Standard
3095 $SDCC_HOME/bin
3096 \end_layout
3097
3098 \end_inset
3099 </cell>
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3101 \begin_inset Text
3102
3103 \begin_layout Standard
3104 $SDCC_HOME
3105 \backslash
3106 bin
3107 \end_layout
3108
3109 \end_inset
3110 </cell>
3111 </row>
3112 <row topline="true">
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 Path of argv[0] (if available)
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3123 \begin_inset Text
3124
3125 \begin_layout Standard
3126 Path of argv[0]
3127 \end_layout
3128
3129 \end_inset
3130 </cell>
3131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3132 \begin_inset Text
3133
3134 \begin_layout Standard
3135 Path of argv[0]
3136 \end_layout
3137
3138 \end_inset
3139 </cell>
3140 </row>
3141 <row topline="true" bottomline="true">
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3143 \begin_inset Text
3144
3145 \begin_layout Standard
3146 $PATH
3147 \end_layout
3148
3149 \end_inset
3150 </cell>
3151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3152 \begin_inset Text
3153
3154 \begin_layout Standard
3155 $PATH
3156 \end_layout
3157
3158 \end_inset
3159 </cell>
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3161 \begin_inset Text
3162
3163 \begin_layout Standard
3164 $PATH
3165 \end_layout
3166
3167 \end_inset
3168 </cell>
3169 </row>
3170 </lyxtabular>
3171
3172 \end_inset
3173
3174  
3175 \newline
3176
3177 \end_layout
3178
3179 \begin_layout Standard
3180 \noindent
3181 2.
3182  Include files
3183 \newline
3184
3185 \end_layout
3186
3187 \begin_layout Standard
3188 \align center
3189 \begin_inset Tabular
3190 <lyxtabular version="3" rows="6" columns="3">
3191 <features>
3192 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3193 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3194 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3195 <row topline="true" bottomline="true">
3196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3197 \begin_inset Text
3198
3199 \begin_layout Standard
3200 Search path
3201 \end_layout
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \begin_layout Standard
3209 default
3210 \end_layout
3211
3212 \end_inset
3213 </cell>
3214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3215 \begin_inset Text
3216
3217 \begin_layout Standard
3218 Win32 builds
3219 \end_layout
3220
3221 \end_inset
3222 </cell>
3223 </row>
3224 <row topline="true">
3225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3226 \begin_inset Text
3227
3228 \begin_layout Standard
3229 -
3230 \begin_inset ERT
3231 status collapsed
3232
3233 \begin_layout Standard
3234
3235
3236 \backslash
3237 /
3238 \end_layout
3239
3240 \end_inset
3241
3242 -I dir
3243 \end_layout
3244
3245 \end_inset
3246 </cell>
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3248 \begin_inset Text
3249
3250 \begin_layout Standard
3251 -
3252 \begin_inset ERT
3253 status collapsed
3254
3255 \begin_layout Standard
3256
3257
3258 \backslash
3259 /
3260 \end_layout
3261
3262 \end_inset
3263
3264 -I dir
3265 \end_layout
3266
3267 \end_inset
3268 </cell>
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 -
3274 \begin_inset ERT
3275 status collapsed
3276
3277 \begin_layout Standard
3278
3279
3280 \backslash
3281 /
3282 \end_layout
3283
3284 \end_inset
3285
3286 -I dir
3287 \end_layout
3288
3289 \end_inset
3290 </cell>
3291 </row>
3292 <row topline="true">
3293 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3294 \begin_inset Text
3295
3296 \begin_layout Standard
3297 $SDCC_INCLUDE
3298 \end_layout
3299
3300 \end_inset
3301 </cell>
3302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3303 \begin_inset Text
3304
3305 \begin_layout Standard
3306 $SDCC_INCLUDE
3307 \end_layout
3308
3309 \end_inset
3310 </cell>
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3312 \begin_inset Text
3313
3314 \begin_layout Standard
3315 $SDCC_INCLUDE
3316 \end_layout
3317
3318 \end_inset
3319 </cell>
3320 </row>
3321 <row topline="true">
3322 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3323 \begin_inset Text
3324
3325 \begin_layout Standard
3326 $SDCC_HOME/
3327 \newline
3328
3329 \emph on
3330 $PREFIX2DATA_DIR/
3331 \newline
3332 $INCLUDE_DIR_SUFFIX
3333 \end_layout
3334
3335 \end_inset
3336 </cell>
3337 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 \begin_inset Text
3339
3340 \begin_layout Standard
3341 $SDCC_ HOME/
3342 \newline
3343 share/sdcc/
3344 \newline
3345 include
3346 \end_layout
3347
3348 \end_inset
3349 </cell>
3350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3351 \begin_inset Text
3352
3353 \begin_layout Standard
3354 $SDCC_HOME
3355 \backslash
3356 include
3357 \end_layout
3358
3359 \end_inset
3360 </cell>
3361 </row>
3362 <row topline="true">
3363 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3364 \begin_inset Text
3365
3366 \begin_layout Standard
3367 path(argv[0])/
3368 \newline
3369
3370 \emph on
3371 $BIN2DATADIR/
3372 \emph default
3373
3374 \newline
3375
3376 \emph on
3377 $INCLUDE_DIR_SUFFIX
3378 \end_layout
3379
3380 \end_inset
3381 </cell>
3382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3383 \begin_inset Text
3384
3385 \begin_layout Standard
3386 path(argv[0])/
3387 \newline
3388 ../sdcc/include
3389 \newline
3390 \InsetSpace ~
3391 \InsetSpace ~
3392 \InsetSpace ~
3393 \InsetSpace ~
3394 \InsetSpace ~
3395 \InsetSpace ~
3396 \InsetSpace ~
3397 \InsetSpace ~
3398 \InsetSpace ~
3399 \InsetSpace ~
3400 \InsetSpace ~
3401 \InsetSpace ~
3402 \InsetSpace ~
3403 \InsetSpace ~
3404 \InsetSpace ~
3405 \InsetSpace ~
3406 \InsetSpace ~
3407 \InsetSpace ~
3408 \InsetSpace ~
3409 \InsetSpace ~
3410 \InsetSpace ~
3411 \InsetSpace ~
3412 \InsetSpace ~
3413 \InsetSpace ~
3414 \InsetSpace ~
3415 \InsetSpace ~
3416 \InsetSpace ~
3417 \InsetSpace ~
3418 \InsetSpace ~
3419 \InsetSpace ~
3420 \InsetSpace ~
3421 \InsetSpace ~
3422 \InsetSpace ~
3423 \InsetSpace ~
3424 \InsetSpace ~
3425 \InsetSpace ~
3426 \InsetSpace ~
3427 \InsetSpace ~
3428
3429 \end_layout
3430
3431 \end_inset
3432 </cell>
3433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3434 \begin_inset Text
3435
3436 \begin_layout Standard
3437 path(argv[0])
3438 \backslash
3439 ..
3440 \backslash
3441 include
3442 \end_layout
3443
3444 \end_inset
3445 </cell>
3446 </row>
3447 <row topline="true" bottomline="true">
3448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3449 \begin_inset Text
3450
3451 \begin_layout Standard
3452
3453 \emph on
3454 $DATADIR/
3455 \emph default
3456
3457 \newline
3458
3459 \emph on
3460 $INCLUDE_DIR_SUFFIX
3461 \end_layout
3462
3463 \end_inset
3464 </cell>
3465 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3466 \begin_inset Text
3467
3468 \begin_layout Standard
3469 /usr/local/share/sdcc/
3470 \newline
3471 include
3472 \end_layout
3473
3474 \end_inset
3475 </cell>
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3477 \begin_inset Text
3478
3479 \begin_layout Standard
3480 (not on Win32)
3481 \end_layout
3482
3483 \end_inset
3484 </cell>
3485 </row>
3486 </lyxtabular>
3487
3488 \end_inset
3489
3490  
3491 \newline
3492
3493 \end_layout
3494
3495 \begin_layout Standard
3496 \noindent
3497 The option -
3498 \begin_inset ERT
3499 status collapsed
3500
3501 \begin_layout Standard
3502
3503
3504 \backslash
3505 /
3506 \end_layout
3507
3508 \end_inset
3509
3510 -nostdinc disables the last two search paths.
3511 \newline
3512
3513 \newline
3514 3.
3515  Library files 
3516 \newline
3517
3518 \end_layout
3519
3520 \begin_layout Standard
3521 With the exception of 
3522 \begin_inset Quotes sld
3523 \end_inset
3524
3525 -
3526 \begin_inset ERT
3527 status collapsed
3528
3529 \begin_layout Standard
3530
3531
3532 \backslash
3533 /
3534 \end_layout
3535
3536 \end_inset
3537
3538 -L dir
3539 \begin_inset Quotes srd
3540 \end_inset
3541
3542  the 
3543 \shape italic
3544 model
3545 \shape default
3546  is auto-appended by the compiler (e.g.
3547  small, large, z80, ds390 etc.).
3548  
3549 \newline
3550
3551 \end_layout
3552
3553 \begin_layout Standard
3554 \align center
3555 \begin_inset Tabular
3556 <lyxtabular version="3" rows="6" columns="3">
3557 <features>
3558 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3559 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3561 <row topline="true" bottomline="true">
3562 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3563 \begin_inset Text
3564
3565 \begin_layout Standard
3566 Search path
3567 \end_layout
3568
3569 \end_inset
3570 </cell>
3571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3572 \begin_inset Text
3573
3574 \begin_layout Standard
3575 default
3576 \end_layout
3577
3578 \end_inset
3579 </cell>
3580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3581 \begin_inset Text
3582
3583 \begin_layout Standard
3584 Win32 builds
3585 \end_layout
3586
3587 \end_inset
3588 </cell>
3589 </row>
3590 <row topline="true">
3591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3592 \begin_inset Text
3593
3594 \begin_layout Standard
3595 -
3596 \begin_inset ERT
3597 status collapsed
3598
3599 \begin_layout Standard
3600
3601
3602 \backslash
3603 /
3604 \end_layout
3605
3606 \end_inset
3607
3608 -L dir
3609 \end_layout
3610
3611 \end_inset
3612 </cell>
3613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3614 \begin_inset Text
3615
3616 \begin_layout Standard
3617 -
3618 \begin_inset ERT
3619 status collapsed
3620
3621 \begin_layout Standard
3622
3623
3624 \backslash
3625 /
3626 \end_layout
3627
3628 \end_inset
3629
3630 -L dir
3631 \end_layout
3632
3633 \end_inset
3634 </cell>
3635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3636 \begin_inset Text
3637
3638 \begin_layout Standard
3639 -
3640 \begin_inset ERT
3641 status collapsed
3642
3643 \begin_layout Standard
3644
3645
3646 \backslash
3647 /
3648 \end_layout
3649
3650 \end_inset
3651
3652 -L dir
3653 \end_layout
3654
3655 \end_inset
3656 </cell>
3657 </row>
3658 <row topline="true">
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3660 \begin_inset Text
3661
3662 \begin_layout Standard
3663 $SDCC_LIB/
3664 \newline
3665
3666 \emph on
3667 <model>
3668 \end_layout
3669
3670 \end_inset
3671 </cell>
3672 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3673 \begin_inset Text
3674
3675 \begin_layout Standard
3676 $SDCC_LIB/
3677 \newline
3678
3679 \emph on
3680 <model>
3681 \end_layout
3682
3683 \end_inset
3684 </cell>
3685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3686 \begin_inset Text
3687
3688 \begin_layout Standard
3689 $SDCC_LIB
3690 \backslash
3691
3692 \newline
3693
3694 \emph on
3695 <model>
3696 \end_layout
3697
3698 \end_inset
3699 </cell>
3700 </row>
3701 <row topline="true">
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3703 \begin_inset Text
3704
3705 \begin_layout Standard
3706 $SDCC_HOME/
3707 \newline
3708
3709 \emph on
3710 $PREFIX2DATA_DIR/
3711 \newline
3712 $LIB_DIR_SUFFIX/<model>
3713 \end_layout
3714
3715 \end_inset
3716 </cell>
3717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3718 \begin_inset Text
3719
3720 \begin_layout Standard
3721 $SDCC_HOME/
3722 \newline
3723 share/sdcc/
3724 \newline
3725 lib/
3726 \emph on
3727 <model>
3728 \end_layout
3729
3730 \end_inset
3731 </cell>
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3733 \begin_inset Text
3734
3735 \begin_layout Standard
3736 $SDCC_HOME
3737 \backslash
3738 lib
3739 \backslash
3740
3741 \emph on
3742
3743 \newline
3744 <model>
3745 \end_layout
3746
3747 \end_inset
3748 </cell>
3749 </row>
3750 <row topline="true">
3751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3752 \begin_inset Text
3753
3754 \begin_layout Standard
3755 path(argv[0])/
3756 \newline
3757
3758 \emph on
3759 $BIN2DATADIR/
3760 \emph default
3761
3762 \newline
3763
3764 \emph on
3765 $LIB_DIR_SUFFIX/<model>
3766 \end_layout
3767
3768 \end_inset
3769 </cell>
3770 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3771 \begin_inset Text
3772
3773 \begin_layout Standard
3774 path(argv[0])/
3775 \newline
3776 ../sdcc/lib/
3777 \emph on
3778 <model>
3779 \newline
3780 \InsetSpace ~
3781 \InsetSpace ~
3782 \InsetSpace ~
3783 \InsetSpace ~
3784 \InsetSpace ~
3785 \InsetSpace ~
3786 \InsetSpace ~
3787 \InsetSpace ~
3788 \InsetSpace ~
3789 \InsetSpace ~
3790 \InsetSpace ~
3791 \InsetSpace ~
3792 \InsetSpace ~
3793 \InsetSpace ~
3794 \InsetSpace ~
3795 \InsetSpace ~
3796 \InsetSpace ~
3797 \InsetSpace ~
3798 \InsetSpace ~
3799 \InsetSpace ~
3800 \InsetSpace ~
3801 \InsetSpace ~
3802 \InsetSpace ~
3803 \InsetSpace ~
3804 \InsetSpace ~
3805 \InsetSpace ~
3806 \InsetSpace ~
3807 \InsetSpace ~
3808 \InsetSpace ~
3809 \InsetSpace ~
3810 \InsetSpace ~
3811 \InsetSpace ~
3812 \InsetSpace ~
3813 \InsetSpace ~
3814 \InsetSpace ~
3815 \InsetSpace ~
3816 \InsetSpace ~
3817 \InsetSpace ~
3818 \InsetSpace ~
3819
3820 \end_layout
3821
3822 \end_inset
3823 </cell>
3824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3825 \begin_inset Text
3826
3827 \begin_layout Standard
3828 path(argv[0])
3829 \backslash
3830
3831 \newline
3832 ..
3833 \backslash
3834 lib
3835 \backslash
3836
3837 \emph on
3838 <model>
3839 \newline
3840 \InsetSpace ~
3841 \InsetSpace ~
3842 \InsetSpace ~
3843 \InsetSpace ~
3844 \InsetSpace ~
3845 \InsetSpace ~
3846 \InsetSpace ~
3847 \InsetSpace ~
3848 \InsetSpace ~
3849 \InsetSpace ~
3850 \InsetSpace ~
3851 \InsetSpace ~
3852 \InsetSpace ~
3853 \InsetSpace ~
3854 \InsetSpace ~
3855 \InsetSpace ~
3856 \InsetSpace ~
3857 \InsetSpace ~
3858 \InsetSpace ~
3859 \InsetSpace ~
3860 \InsetSpace ~
3861 \InsetSpace ~
3862 \InsetSpace ~
3863 \InsetSpace ~
3864 \InsetSpace ~
3865 \InsetSpace ~
3866 \InsetSpace ~
3867 \InsetSpace ~
3868 \InsetSpace ~
3869 \InsetSpace ~
3870 \InsetSpace ~
3871 \InsetSpace ~
3872 \InsetSpace ~
3873 \InsetSpace ~
3874 \InsetSpace ~
3875
3876 \end_layout
3877
3878 \end_inset
3879 </cell>
3880 </row>
3881 <row topline="true" bottomline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3883 \begin_inset Text
3884
3885 \begin_layout Standard
3886
3887 \emph on
3888 $DATADIR/
3889 \newline
3890 $LIB_DIR_SUFFIX/<model>
3891 \end_layout
3892
3893 \end_inset
3894 </cell>
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3896 \begin_inset Text
3897
3898 \begin_layout Standard
3899 /usr/local/share/sdcc/
3900 \newline
3901 lib/
3902 \emph on
3903 <model>
3904 \end_layout
3905
3906 \end_inset
3907 </cell>
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3909 \begin_inset Text
3910
3911 \begin_layout Standard
3912 (not on Win32)
3913 \end_layout
3914
3915 \end_inset
3916 </cell>
3917 </row>
3918 </lyxtabular>
3919
3920 \end_inset
3921
3922
3923 \newline
3924
3925 \end_layout
3926
3927 \begin_layout Standard
3928 \begin_inset Note Note
3929 status collapsed
3930
3931 \begin_layout Standard
3932 Don't delete any of the stray spaces in the table above without checking
3933  the HTML output (last line)!
3934 \end_layout
3935
3936 \end_inset
3937
3938
3939 \end_layout
3940
3941 \begin_layout Standard
3942 \InsetSpace ~
3943
3944 \newline
3945 The option -
3946 \begin_inset ERT
3947 status collapsed
3948
3949 \begin_layout Standard
3950
3951
3952 \backslash
3953 /
3954 \end_layout
3955
3956 \end_inset
3957
3958 -nostdlib disables the last two search paths.
3959 \end_layout
3960
3961 \begin_layout Section
3962 Building SDCC
3963 \begin_inset LatexCommand \index{Building SDCC}
3964
3965 \end_inset
3966
3967
3968 \end_layout
3969
3970 \begin_layout Subsection
3971 Building SDCC on Linux
3972 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3973
3974 \end_inset
3975
3976
3977 \end_layout
3978
3979 \begin_layout Enumerate
3980
3981 \series medium
3982 Download the source package
3983 \series default
3984  either from the SDCC Subversion repository or from snapshot builds
3985 \series medium
3986 , it will be named something like sdcc
3987 \series default
3988 -src
3989 \series medium
3990 -yyyymmdd-rrrr.t
3991 \series default
3992 ar.
3993 \series medium
3994 bz2
3995 \series default
3996  
3997 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3998
3999 \end_inset
4000
4001 .
4002 \end_layout
4003
4004 \begin_layout Enumerate
4005
4006 \series medium
4007 Bring up a command line terminal, such as xterm.
4008 \end_layout
4009
4010 \begin_layout Enumerate
4011
4012 \series medium
4013 Unpack the file using a command like: 
4014 \family sans
4015 \series bold
4016 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4017 \begin_inset Quotes srd
4018 \end_inset
4019
4020
4021 \family default
4022 \series medium
4023 , this will create a sub-directory called sdcc with all of the sources.
4024 \end_layout
4025
4026 \begin_layout Enumerate
4027 Change directory into the main SDCC directory, for example type: 
4028 \family sans
4029 \series bold
4030 "cd sdcc
4031 \series default
4032 ".
4033 \end_layout
4034
4035 \begin_layout Enumerate
4036
4037 \series medium
4038 Type 
4039 \family sans
4040 \series bold
4041 "./configure
4042 \family default
4043 \series default
4044 ".
4045  This configures the package for compilation on your system.
4046 \end_layout
4047
4048 \begin_layout Enumerate
4049
4050 \series medium
4051 Type 
4052 \family sans
4053 \series bold
4054 "make
4055 \family default
4056 \series default
4057 "
4058 \series medium
4059 .
4060
4061 \series default
4062  All of the source packages will compile, this can take a while.
4063 \end_layout
4064
4065 \begin_layout Enumerate
4066
4067 \series medium
4068 Type 
4069 \family sans
4070 \series bold
4071 "make install"
4072 \family default
4073 \series default
4074  as root
4075 \series medium
4076 .
4077
4078 \series default
4079  This copies the binary executables, the include files, the libraries and
4080  the documentation to the install directories.
4081  Proceed with section 
4082 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4083
4084 \end_inset
4085
4086 .
4087 \end_layout
4088
4089 \begin_layout Subsection
4090 Building SDCC on Mac OS X
4091 \end_layout
4092
4093 \begin_layout Standard
4094 Follow the instruction for Linux.
4095 \newline
4096
4097 \newline
4098 On Mac OS X 10.2.x it was reported, that the
4099  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4100  Fortunately there's also gcc 2.9.x installed, which works fine.
4101  This compiler can be selected by running 'configure' with:
4102 \end_layout
4103
4104 \begin_layout LyX-Code
4105 ./configure CC=gcc2 CXX=g++2
4106 \end_layout
4107
4108 \begin_layout Standard
4109 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4110  Xcode.
4111  Run 'configure' with:
4112 \end_layout
4113
4114 \begin_layout LyX-Code
4115 ./configure 
4116 \backslash
4117
4118 \end_layout
4119
4120 \begin_layout LyX-Code
4121 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4122  ppc" 
4123 \backslash
4124
4125 \end_layout
4126
4127 \begin_layout LyX-Code
4128 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4129  ppc" 
4130 \backslash
4131
4132 \end_layout
4133
4134 \begin_layout LyX-Code
4135 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4136 \end_layout
4137
4138 \begin_layout Subsection
4139 Cross compiling SDCC on Linux for Windows
4140 \end_layout
4141
4142 \begin_layout Standard
4143 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4144  See section 'Configure Options'.
4145 \end_layout
4146
4147 \begin_layout Subsection
4148 Building SDCC using Cygwin and Mingw32
4149 \end_layout
4150
4151 \begin_layout Standard
4152 For building and installing a Cygwin executable follow the instructions
4153  for Linux.
4154 \newline
4155
4156 \newline
4157 On Cygwin a 
4158 \begin_inset Quotes sld
4159 \end_inset
4160
4161 native
4162 \begin_inset Quotes srd
4163 \end_inset
4164
4165  Win32-binary can be built, which will not need the Cygwin-DLL.
4166  For the necessary 'configure' options see section 'configure options' or
4167  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4168 \newline
4169
4170 \newline
4171 In order to install
4172  Cygwin on Windows download setup.exe from 
4173 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4174
4175 \end_inset
4176
4177 .
4178  Run it, set the 
4179 \begin_inset Quotes sld
4180 \end_inset
4181
4182 default text file type
4183 \begin_inset Quotes srd
4184 \end_inset
4185
4186  to 
4187 \begin_inset Quotes sld
4188 \end_inset
4189
4190 unix
4191 \begin_inset Quotes srd
4192 \end_inset
4193
4194  and download/install at least the following packages.
4195  Some packages are selected by default, others will be automatically selected
4196  because of dependencies with the manually selected packages.
4197  Never deselect these packages!
4198 \end_layout
4199
4200 \begin_layout Itemize
4201 flex
4202 \end_layout
4203
4204 \begin_layout Itemize
4205 bison
4206 \end_layout
4207
4208 \begin_layout Itemize
4209 gcc ; version 3.x is fine, no need to use the old 2.9x
4210 \end_layout
4211
4212 \begin_layout Itemize
4213 binutils ; selected with gcc
4214 \end_layout
4215
4216 \begin_layout Itemize
4217 make
4218 \end_layout
4219
4220 \begin_layout Itemize
4221 rxvt ; a nice console, which makes life much easier under windoze (see below)
4222 \end_layout
4223
4224 \begin_layout Itemize
4225 man ; not really needed for building SDCC, but you'll miss it sooner or
4226  later
4227 \end_layout
4228
4229 \begin_layout Itemize
4230 less ; not really needed for building SDCC, but you'll miss it sooner or
4231  later
4232 \end_layout
4233
4234 \begin_layout Itemize
4235 svn ; only if you use Subversion access
4236 \end_layout
4237
4238 \begin_layout Standard
4239 If you want to develop something you'll need:
4240 \end_layout
4241
4242 \begin_layout Itemize
4243 python ; for the regression tests
4244 \end_layout
4245
4246 \begin_layout Itemize
4247 gdb ; the gnu debugger, together with the nice GUI 
4248 \begin_inset Quotes sld
4249 \end_inset
4250
4251 insight
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255
4256 \end_layout
4257
4258 \begin_layout Itemize
4259 openssh ; to access the CF or commit changes
4260 \end_layout
4261
4262 \begin_layout Itemize
4263 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4264  use autoconf-stable!
4265 \end_layout
4266
4267 \begin_layout Standard
4268 rxvt is a nice console with history.
4269  Replace in your cygwin.bat the line
4270 \end_layout
4271
4272 \begin_layout LyX-Code
4273 bash -
4274 \begin_inset ERT
4275 status collapsed
4276
4277 \begin_layout Standard
4278
4279
4280 \backslash
4281 /
4282 \end_layout
4283
4284 \end_inset
4285
4286 -login -i 
4287 \end_layout
4288
4289 \begin_layout Standard
4290 with (one line):
4291 \end_layout
4292
4293 \begin_layout LyX-Code
4294 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4295 \end_layout
4296
4297 \begin_layout LyX-Code
4298      -bg black -fg white -geometry 100x65 -e bash -
4299 \begin_inset ERT
4300 status collapsed
4301
4302 \begin_layout Standard
4303
4304
4305 \backslash
4306 /
4307 \end_layout
4308
4309 \end_inset
4310
4311 -login
4312 \end_layout
4313
4314 \begin_layout Standard
4315 Text selected with the mouse is automatically copied to the clipboard, pasting
4316  works with shift-insert.
4317 \newline
4318
4319 \newline
4320 The other good tip is to make sure you have no //c/-styl
4321 e paths anywhere, use /cygdrive/c/ instead.
4322  Using // invokes a network lookup which is very slow.
4323  If you think 
4324 \begin_inset Quotes sld
4325 \end_inset
4326
4327 cygdrive
4328 \begin_inset Quotes srd
4329 \end_inset
4330
4331  is too long, you can change it with e.g.
4332 \end_layout
4333
4334 \begin_layout LyX-Code
4335 mount -s -u -c /mnt
4336 \end_layout
4337
4338 \begin_layout Standard
4339 SDCC sources use the unix line ending LF.
4340  Life is much easier, if you store the source tree on a drive which is mounted
4341  in binary mode.
4342  And use an editor which can handle LF-only line endings.
4343  Make sure not to commit files with windows line endings.
4344  The tabulator spacing
4345 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4346
4347 \end_inset
4348
4349  used in the project is 8.
4350  Although a tabulator spacing of 8 is a sensible choice for programmers
4351  (it's a power of 2 and allows to display 8/16 bit signed variables without
4352  loosing columns) the plan is to move towards using only spaces in the source.
4353 \end_layout
4354
4355 \begin_layout Subsection
4356 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4357 \end_layout
4358
4359 \begin_layout Standard
4360
4361 \series medium
4362 Download the source package
4363 \series default
4364  either from the SDCC Subversion repository or from the 
4365 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4366
4367 \end_inset
4368
4369
4370 \series medium
4371 , it will be named something like sdcc
4372 \series default
4373 -src
4374 \series medium
4375 -yyyymmdd-rrrr.tar.bz2.
4376
4377 \series default
4378  SDCC is distributed with all the projects, workspaces, and files you need
4379  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4380  The workspace name is 'sdcc.dsw'.
4381  Please note that as it is now, all the executables are created in a folder
4382  called sdcc
4383 \backslash
4384 bin_vc.
4385  Once built you need to copy the executables from sdcc
4386 \backslash
4387 bin_vc to sdcc
4388 \backslash
4389 bin before running SDCC.
4390  
4391 \newline
4392
4393 \newline
4394 WARNING: Visual studio is very picky with line terminations; it expects
4395  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4396  When using the Subversion repository it's easiest to configure the svn
4397  client to convert automatically for you.
4398  If however you are getting a message such as "This makefile was not generated
4399  by Developer Studio etc.
4400  etc.
4401 \begin_inset Quotes srd
4402 \end_inset
4403
4404  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4405  need to convert the Unix style line endings to DOS style line endings.
4406  To do so you can use the 
4407 \begin_inset Quotes sld
4408 \end_inset
4409
4410 unix2dos
4411 \begin_inset Quotes srd
4412 \end_inset
4413
4414  utility freely available on the internet.
4415  Doug Hawkins reported in the sdcc-user list that this works:
4416 \newline
4417
4418 \newline
4419 C:
4420 \backslash
4421 Programming
4422 \backslash
4423 SDCC> unix2dos sdcc.dsw
4424 \newline
4425 C:
4426 \backslash
4427 Programming
4428 \backslash
4429 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4430 \newline
4431
4432 \newline
4433 In order to build SDCC with MSVC
4434  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4435  One good place to get them is 
4436 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4437
4438 \end_inset
4439
4440
4441 \newline
4442
4443 \newline
4444 Download the file UnxUtils
4445 \begin_inset LatexCommand \index{UnxUtils}
4446
4447 \end_inset
4448
4449 .zip.
4450  Now you have to install the utilities and setup MSVC so it can locate the
4451  required programs.
4452  Here there are two alternatives (choose one!):
4453 \end_layout
4454
4455 \begin_layout Enumerate
4456 The easy way:
4457 \newline
4458
4459 \newline
4460 a) Extract UnxUtils.zip to your C:
4461 \backslash
4462  hard disk PRESERVING the original paths, otherwise bison won't work.
4463  (If you are using WinZip make certain that 'Use folder names' is selected)
4464 \newline
4465
4466 \newline
4467 b)
4468  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4469  'Show directories for:' select 'Executable files', and in the directories
4470  window add a new path: 'C:
4471 \backslash
4472 user
4473 \backslash
4474 local
4475 \backslash
4476 wbin', click ok.
4477 \newline
4478
4479 \newline
4480 (As a side effect, you get a bunch of Unix utilities that
4481  could be useful, such as diff and patch.)
4482 \end_layout
4483
4484 \begin_layout Enumerate
4485 A more compact way:
4486 \newline
4487
4488 \newline
4489 This one avoids extracting a bunch of files you may not
4490  use, but requires some extra work:
4491 \newline
4492
4493 \newline
4494 a) Create a directory were to put the
4495  tools needed, or use a directory already present.
4496  Say for example 'C:
4497 \backslash
4498 util'.
4499 \newline
4500
4501 \newline
4502 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4503  gawk.exe to such directory WITHOUT preserving the original paths.
4504  (If you are using WinZip make certain that 'Use folder names' is not selected)
4505 \newline
4506
4507 \newline
4508 c
4509 ) Rename bison.exe to '_bison.exe'.
4510 \newline
4511
4512 \newline
4513 d) Create a batch file 'bison.bat' in 'C:
4514 \backslash
4515 util
4516 \backslash
4517 ' and add these lines: 
4518 \newline
4519 \InsetSpace ~
4520 \InsetSpace ~
4521 set BISON_SIMPLE=C:
4522 \backslash
4523 util
4524 \backslash
4525 bison.simple 
4526 \newline
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 set BISON_HAIRY=C:
4530 \backslash
4531 util
4532 \backslash
4533 bison.hairy
4534 \newline
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4538 \newline
4539
4540 \newline
4541 Steps 'c' and 'd' are needed
4542  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4543  reside in some weird Unix directory, '/usr/local/share/' I think.
4544  So it is necessary to tell bison where those files are located if they
4545  are not in such directory.
4546  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4547 \newline
4548
4549 \newline
4550 e
4551 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4552  in 'Show directories for:' select 'Executable files', and in the directories
4553  window add a new path: 'c:
4554 \backslash
4555 util', click ok.
4556  Note that you can use any other path instead of 'c:
4557 \backslash
4558 util', even the path where the Visual C++ tools are, probably: 'C:
4559 \backslash
4560 Program Files
4561 \backslash
4562 Microsoft Visual Studio
4563 \backslash
4564 Common
4565 \backslash
4566 Tools'.
4567  So you don't have to execute step 'e' :)
4568 \end_layout
4569
4570 \begin_layout Standard
4571 That is it.
4572  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4573  the executables from sdcc
4574 \backslash
4575 bin_vc to sdcc
4576 \backslash
4577 bin, and you can compile using SDCC.
4578 \end_layout
4579
4580 \begin_layout Subsection
4581 Building SDCC Using Borland
4582 \end_layout
4583
4584 \begin_layout Enumerate
4585 From the sdcc directory, run the command "make -f Makefile.bcc".
4586  This should regenerate all the .exe files in the bin directory except for
4587  SDCDB and ucSim.
4588 \end_layout
4589
4590 \begin_layout Enumerate
4591 If you modify any source files and need to rebuild, be aware that the dependenci
4592 es may not be correctly calculated.
4593  The safest option is to delete all .obj files and run the build again.
4594  From a Cygwin BASH prompt, this can easily be done with the command (be
4595  sure you are in the sdcc directory):
4596 \newline
4597
4598 \newline
4599
4600 \family sans
4601 \series bold
4602 find .
4603  
4604 \backslash
4605 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4606 \backslash
4607 ) -print -exec rm {} 
4608 \backslash
4609 ;
4610 \family default
4611 \series default
4612
4613 \newline
4614
4615 \newline
4616 or on Windows NT/2000/XP from the command prompt with the command:
4617 \newline
4618
4619 \family sans
4620 \series bold
4621
4622 \newline
4623 del /s *.obj *.lib *.rul
4624 \family default
4625 \series default
4626  from the sdcc directory.
4627 \end_layout
4628
4629 \begin_layout Subsection
4630 Windows Install Using a ZIP Package
4631 \end_layout
4632
4633 \begin_layout Enumerate
4634 Download the binary zip package from 
4635 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4636
4637 \end_inset
4638
4639  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4640  This should unpack to a group of sub-directories.
4641  An example directory structure after unpacking the mingw32 package is:
4642  c:
4643 \backslash
4644 sdcc
4645 \backslash
4646 bin for the executables, c:
4647 \backslash
4648 sdcc
4649 \backslash
4650 include and c:
4651 \backslash
4652 sdcc
4653 \backslash
4654 lib for the include and libraries.
4655 \end_layout
4656
4657 \begin_layout Enumerate
4658 Adjust your environment variable PATH to include the location of the bin
4659  directory or start sdcc using the full path.
4660 \end_layout
4661
4662 \begin_layout Subsection
4663 Windows Install Using the Setup Program
4664 \begin_inset LatexCommand \label{sub:Windows-Install}
4665
4666 \end_inset
4667
4668
4669 \end_layout
4670
4671 \begin_layout Standard
4672 Download the setup program 
4673 \emph on
4674 sdcc-x.y.z-setup.exe
4675 \emph default
4676  for an official release from 
4677 \newline
4678
4679 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4680
4681 \end_inset
4682
4683  or a setup program for one of the snapshots 
4684 \emph on
4685 sdcc-yyyymmdd-xxxx-setup.exe
4686 \emph default
4687  from 
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4689
4690 \end_inset
4691
4692  and execute it.
4693  A windows typical installer will guide you through the installation process.
4694 \end_layout
4695
4696 \begin_layout Subsection
4697 VPATH
4698 \begin_inset LatexCommand \index{VPATH}
4699
4700 \end_inset
4701
4702  feature
4703 \end_layout
4704
4705 \begin_layout Standard
4706 SDCC supports the VPATH feature provided by configure and make.
4707  It allows to separate the source and build trees.
4708  Here's an example:
4709 \end_layout
4710
4711 \begin_layout Standard
4712
4713 \family typewriter
4714 cd ~\InsetSpace ~
4715 \InsetSpace ~
4716 \InsetSpace ~
4717 \InsetSpace ~
4718 \InsetSpace ~
4719 \InsetSpace ~
4720 \InsetSpace ~
4721 \InsetSpace ~
4722 \InsetSpace ~
4723 \InsetSpace ~
4724 \InsetSpace ~
4725 \InsetSpace ~
4726 \InsetSpace ~
4727 \InsetSpace ~
4728 \InsetSpace ~
4729 \InsetSpace ~
4730 \InsetSpace ~
4731 \InsetSpace ~
4732 \InsetSpace ~
4733 \InsetSpace ~
4734 \InsetSpace ~
4735 # cd $HOME
4736 \end_layout
4737
4738 \begin_layout Standard
4739
4740 \family typewriter
4741 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4742 # extract source to directory sdcc
4743 \end_layout
4744
4745 \begin_layout Standard
4746
4747 \family typewriter
4748 mkdir sdcc.build\InsetSpace ~
4749 \InsetSpace ~
4750 \InsetSpace ~
4751 \InsetSpace ~
4752 \InsetSpace ~
4753 \InsetSpace ~
4754 \InsetSpace ~
4755 \InsetSpace ~
4756 \InsetSpace ~
4757 # put output in sdcc.build
4758 \end_layout
4759
4760 \begin_layout Standard
4761
4762 \family typewriter
4763 cd sdcc.build
4764 \end_layout
4765
4766 \begin_layout Standard
4767
4768 \family typewriter
4769 ../sdcc/configure\InsetSpace ~
4770 \InsetSpace ~
4771 \InsetSpace ~
4772 \InsetSpace ~
4773 \InsetSpace ~
4774 \InsetSpace ~
4775 \InsetSpace ~
4776 \InsetSpace ~
4777 # configure is doing all the magic!
4778 \end_layout
4779
4780 \begin_layout Standard
4781
4782 \family typewriter
4783 make
4784 \end_layout
4785
4786 \begin_layout Standard
4787 \noindent
4788 That's it! 
4789 \series bold
4790 configure
4791 \series default
4792  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4793  It automagically computes the variables srcdir, top_srcdir and top_buildir
4794  for each directory.
4795  After running 
4796 \series bold
4797 make
4798 \series default
4799  the generated files will be in ~/sdcc.build, while the source files stay
4800  in ~/sdcc.
4801 \newline
4802 This is not only usefull for building different binaries, e.g.
4803  when cross compiling.
4804  It also gives you a much better overview in the source tree when all the
4805  generated files are not scattered between the source files.
4806  And the best thing is: if you want to change a file you can leave the original
4807  file untouched in the source directory.
4808  Simply copy it to the build directory, edit it, enter `make clean', `rm
4809  Makefile.dep' and `make'.
4810  
4811 \series bold
4812 make
4813 \series default
4814  will do the rest for you!
4815 \end_layout
4816
4817 \begin_layout Section
4818 Building the Documentation
4819 \end_layout
4820
4821 \begin_layout Standard
4822 Add -
4823 \begin_inset ERT
4824 status collapsed
4825
4826 \begin_layout Standard
4827
4828
4829 \backslash
4830 /
4831 \end_layout
4832
4833 \end_inset
4834
4835 -enable-doc to the configure arguments to build the documentation together
4836  with all the other stuff.
4837  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4838  dvips and makeindex) to get the job done.
4839  Another possibility is to change to the doc directory and to type 
4840 \family sans
4841 \series bold
4842
4843 \begin_inset Quotes srd
4844 \end_inset
4845
4846 make
4847 \begin_inset Quotes srd
4848 \end_inset
4849
4850
4851 \family default
4852 \series default
4853  there.
4854  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4855 x).
4856  Using LyX 
4857 \begin_inset LatexCommand \url{http://www.lyx.org}
4858
4859 \end_inset
4860
4861  as editor is straightforward.
4862  Prebuilt documentation in html and pdf format is available from 
4863 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4864
4865 \end_inset
4866
4867 .
4868 \end_layout
4869
4870 \begin_layout Section
4871 Reading the Documentation
4872 \begin_inset LatexCommand \index{Documentation}
4873
4874 \end_inset
4875
4876
4877 \end_layout
4878
4879 \begin_layout Standard
4880 Currently reading the document in pdf format is recommended, as for unknown
4881  reason the hyperlinks are working there whereas in the html version they
4882  are not
4883 \begin_inset Foot
4884 status open
4885
4886 \begin_layout Standard
4887 If you should know why please drop us a note
4888 \end_layout
4889
4890 \end_inset
4891
4892 .
4893  
4894 \newline
4895 You'll find the pdf version
4896 \begin_inset LatexCommand \index{PDF version of this document}
4897
4898 \end_inset
4899
4900  at 
4901 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4902
4903 \end_inset
4904
4905 .
4906  
4907 \newline
4908 A html version
4909 \begin_inset LatexCommand \index{HTML version of this document}
4910
4911 \end_inset
4912
4913  should be online at 
4914 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4915
4916 \end_inset
4917
4918 .
4919 \newline
4920 This documentation is in some aspects different from a commercial documentation:
4921  
4922 \end_layout
4923
4924 \begin_layout Itemize
4925 It tries to document SDCC for several processor architectures in one document
4926  (commercially these probably would be separate documents/products).
4927  This document
4928 \begin_inset LatexCommand \index{Status of documentation}
4929
4930 \end_inset
4931
4932  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4933 on about f.e.
4934  Z80, PIC14, PIC16 and HC08.
4935 \end_layout
4936
4937 \begin_layout Itemize
4938 There are many references pointing away from this documentation.
4939  Don't let this distract you.
4940  If there f.e.
4941  was a reference like 
4942 \begin_inset LatexCommand \url{http://www.opencores.org}
4943
4944 \end_inset
4945
4946  together with a statement 
4947 \begin_inset Quotes sld
4948 \end_inset
4949
4950 some processors which are targetted by SDCC can be implemented in a 
4951 \emph on
4952 f
4953 \emph default
4954 ield 
4955 \emph on
4956 p
4957 \emph default
4958 rogrammable 
4959 \emph on
4960 g
4961 \emph default
4962 ate 
4963 \emph on
4964 a
4965 \emph default
4966 rray
4967 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4968
4969 \end_inset
4970
4971
4972 \begin_inset Quotes srd
4973 \end_inset
4974
4975  or 
4976 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4977
4978 \end_inset
4979
4980
4981 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4982
4983 \end_inset
4984
4985  
4986 \begin_inset Quotes sld
4987 \end_inset
4988
4989 have you ever heard of an open source compiler that compiles a subset of
4990  C for an FPGA?
4991 \begin_inset Quotes srd
4992 \end_inset
4993
4994  we expect you to have a quick look there and come back.
4995  If you read this you are on the right track.
4996 \end_layout
4997
4998 \begin_layout Itemize
4999 Some sections attribute more space to problems, restrictions and warnings
5000  than to the solution.
5001 \end_layout
5002
5003 \begin_layout Itemize
5004 The installation section and the section about the debugger is intimidating.
5005 \end_layout
5006
5007 \begin_layout Itemize
5008 There are still lots of typos and there are more different writing styles
5009  than pictures.
5010 \end_layout
5011
5012 \begin_layout Section
5013 Testing the SDCC Compiler
5014 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5015
5016 \end_inset
5017
5018
5019 \end_layout
5020
5021 \begin_layout Standard
5022 The first thing you should do after installing your SDCC compiler is to
5023  see if it runs.
5024  Type 
5025 \family sans
5026 \series bold
5027 "sdcc -
5028 \begin_inset ERT
5029 status collapsed
5030
5031 \begin_layout Standard
5032
5033
5034 \backslash
5035 /
5036 \end_layout
5037
5038 \end_inset
5039
5040 -version"
5041 \begin_inset LatexCommand \index{version}
5042
5043 \end_inset
5044
5045
5046 \family default
5047 \series default
5048  at the prompt, and the program should run and output its version like:
5049  
5050 \newline
5051
5052 \family typewriter
5053 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5054  (UNIX)
5055 \end_layout
5056
5057 \begin_layout Standard
5058 If it doesn't run, or gives a message about not finding sdcc program, then
5059  you need to check over your installation.
5060  Make sure that the sdcc bin directory is in your executable search path
5061  defined by the PATH environment setting (
5062 \series medium
5063 see 
5064 \series default
5065 section 
5066 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5067
5068 \end_inset
5069
5070 \InsetSpace ~
5071
5072 \series medium
5073 Install trouble-shooting for suggestions
5074 \series default
5075 ).
5076  Make sure that the sdcc program is in the bin folder, if not perhaps something
5077  did not install correctly.
5078 \newline
5079
5080 \newline
5081
5082 \series medium
5083 SDCC 
5084 \series default
5085 is commonly installed as described in section 
5086 \begin_inset Quotes sld
5087 \end_inset
5088
5089 Install and search paths
5090 \begin_inset Quotes srd
5091 \end_inset
5092
5093 .
5094 \newline
5095
5096 \newline
5097
5098 \series medium
5099 Make sure the compiler works on a very simple example.
5100  Type in the following test.c program using your favorite 
5101 \series default
5102 ASCII 
5103 \series medium
5104 editor:
5105 \end_layout
5106
5107 \begin_layout Verse
5108
5109 \family typewriter
5110 char test;
5111 \newline
5112
5113 \newline
5114 void main(void) {
5115 \newline
5116 \InsetSpace ~
5117 \InsetSpace ~
5118 \InsetSpace ~
5119 \InsetSpace ~
5120 test=0;
5121 \newline
5122 }
5123 \end_layout
5124
5125 \begin_layout Standard
5126
5127 \series medium
5128 Compile this using the following command: 
5129 \family sans
5130 \series bold
5131 "sdcc -c test.c".
5132
5133 \family default
5134 \series default
5135  
5136 \series medium
5137 If all goes well, the compiler will generate a test.asm and test.rel file.
5138  Congratulations, you've just compiled your first program with SDCC.
5139  We used the -c option to tell SDCC not to link the generated code, just
5140  to keep things simple for this step.
5141 \series default
5142
5143 \newline
5144
5145 \newline
5146
5147 \series medium
5148 The next step is to try it with the linker.
5149  Type in 
5150 \family sans
5151 \series bold
5152 "sdcc test.c
5153 \family default
5154 \series default
5155 "
5156 \series medium
5157 .
5158  If all goes well the compiler will link with the libraries and produce
5159  a test.ihx output file.
5160  If this step fails
5161 \series default
5162  
5163 \series medium
5164 (no test.ihx, and the linker generates warnings), then the problem is most
5165  likely that 
5166 \series default
5167 SDCC
5168 \series medium
5169  cannot find the 
5170 \series default
5171 /
5172 \series medium
5173 usr/local/share/sdcc/lib directory
5174 \series default
5175  
5176 \series medium
5177 (see 
5178 \series default
5179 section 
5180 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5181
5182 \end_inset
5183
5184 \InsetSpace ~
5185
5186 \series medium
5187 Install trouble-shooting for suggestions).
5188 \series default
5189
5190 \newline
5191
5192 \newline
5193
5194 \series medium
5195 The final test is to ensure 
5196 \series default
5197 SDCC
5198 \series medium
5199  can use the 
5200 \series default
5201 standard
5202 \series medium
5203  header files and libraries.
5204  Edit test.c and change it to the following:
5205 \end_layout
5206
5207 \begin_layout Verse
5208
5209 \family typewriter
5210 #include <string.h>
5211 \newline
5212
5213 \newline
5214 char str1[10];
5215 \newline
5216
5217 \newline
5218 void main(void) {
5219 \newline
5220 \InsetSpace ~
5221 \InsetSpace ~
5222 strcpy(str1, "testing");
5223 \newline
5224 }
5225 \end_layout
5226
5227 \begin_layout Standard
5228
5229 \series medium
5230 Compile this by typing 
5231 \family sans
5232 \series bold
5233 "sdcc test.c"
5234 \family default
5235 \series medium
5236 .
5237  This should generate a test.ihx output file, and it should give no warnings
5238  such as not finding the string.h file.
5239  If it cannot find the string.h file, then the problem is that 
5240 \series default
5241 SDCC
5242 \series medium
5243  cannot find the /usr/local/share/sdcc/include directory
5244 \series default
5245  
5246 \series medium
5247 (see the 
5248 \series default
5249 section 
5250 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5251
5252 \end_inset
5253
5254 \InsetSpace ~
5255
5256 \series medium
5257 Install trouble-shooting section for suggestions).
5258
5259 \series default
5260  Use option 
5261 \series bold
5262 -
5263 \begin_inset ERT
5264 status collapsed
5265
5266 \begin_layout Standard
5267
5268
5269 \backslash
5270 /
5271 \end_layout
5272
5273 \end_inset
5274
5275 -print-search-dirs
5276 \series default
5277
5278 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5279
5280 \end_inset
5281
5282  to find exactly where SDCC is looking for the include and lib files.
5283 \end_layout
5284
5285 \begin_layout Section
5286 Install Trouble-shooting
5287 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5288
5289 \end_inset
5290
5291
5292 \begin_inset LatexCommand \index{Install trouble-shooting}
5293
5294 \end_inset
5295
5296
5297 \end_layout
5298
5299 \begin_layout Subsection
5300 If SDCC does not build correctly
5301 \end_layout
5302
5303 \begin_layout Standard
5304 A thing to try is starting from scratch by unpacking the .tgz source package
5305  again in an empty directory.
5306  Configure it like:
5307 \newline
5308
5309 \newline
5310
5311 \family sans
5312 \series bold
5313 ./configure 2>&1 | tee configure.log
5314 \family default
5315 \series default
5316
5317 \newline
5318
5319 \newline
5320 and build it like:
5321 \newline
5322
5323 \newline
5324
5325 \family sans
5326 \series bold
5327 make 2>&1 | tee make.log
5328 \family default
5329 \series default
5330
5331 \newline
5332
5333 \newline
5334 If anything goes wrong, you can review the log files to locate the problem.
5335  Or a relevant part of this can be attached to an email that could be helpful
5336  when requesting help from the mailing list.
5337 \end_layout
5338
5339 \begin_layout Subsection
5340 What the 
5341 \begin_inset Quotes sld
5342 \end_inset
5343
5344 ./configure
5345 \begin_inset Quotes srd
5346 \end_inset
5347
5348  does
5349 \end_layout
5350
5351 \begin_layout Standard
5352 The 
5353 \begin_inset Quotes sld
5354 \end_inset
5355
5356 ./configure
5357 \begin_inset Quotes srd
5358 \end_inset
5359
5360  command is a script that analyzes your system and performs some configuration
5361  to ensure the source package compiles on your system.
5362  It will take a few minutes to run, and will compile a few tests to determine
5363  what compiler features are installed.
5364 \end_layout
5365
5366 \begin_layout Subsection
5367 What the 
5368 \begin_inset Quotes sld
5369 \end_inset
5370
5371 make
5372 \begin_inset Quotes srd
5373 \end_inset
5374
5375  does
5376 \end_layout
5377
5378 \begin_layout Standard
5379 This runs the GNU make tool, which automatically compiles all the source
5380  packages into the final installed binary executables.
5381 \end_layout
5382
5383 \begin_layout Subsection
5384 What the 
5385 \begin_inset Quotes sld
5386 \end_inset
5387
5388 make install
5389 \begin_inset Quotes erd
5390 \end_inset
5391
5392  command does.
5393 \end_layout
5394
5395 \begin_layout Standard
5396 This will install the compiler, other executables libraries and include
5397  files into the appropriate directories.
5398  See sections 
5399 \begin_inset LatexCommand \ref{sub:Install-paths}
5400
5401 \end_inset
5402
5403 ,\InsetSpace ~
5404
5405 \begin_inset LatexCommand \ref{sub:Search-Paths}
5406
5407 \end_inset
5408
5409 \InsetSpace ~
5410 about install and search paths.
5411 \newline
5412 On most systems you will need super-user privilege
5413 s to do this.
5414 \end_layout
5415
5416 \begin_layout Section
5417 Components of SDCC
5418 \end_layout
5419
5420 \begin_layout Standard
5421 SDCC is not just a compiler, but a collection of tools by various developers.
5422  These include linkers, assemblers, simulators and other components.
5423  Here is a summary of some of the components.
5424  Note that the included simulator and assembler have separate documentation
5425  which you can find in the source package in their respective directories.
5426  As SDCC grows to include support for other processors, other packages from
5427  various developers are included and may have their own sets of documentation.
5428 \newline
5429
5430 \newline
5431 You
5432  might want to look at the files which are installed in <installdir>.
5433  At the time of this writing, we find the following programs for gcc-builds:
5434 \newline
5435
5436  
5437 \newline
5438 In <installdir>/bin:
5439 \end_layout
5440
5441 \begin_layout Itemize
5442 sdcc - The compiler.
5443 \end_layout
5444
5445 \begin_layout Itemize
5446 sdcpp - The C preprocessor.
5447 \end_layout
5448
5449 \begin_layout Itemize
5450 asx8051 - The assembler for 8051 type processors.
5451 \end_layout
5452
5453 \begin_layout Itemize
5454 as-z80
5455 \series bold
5456
5457 \series default
5458 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5459 \end_layout
5460
5461 \begin_layout Itemize
5462 aslink -The linker for 8051 type processors.
5463 \end_layout
5464
5465 \begin_layout Itemize
5466 link-z80
5467 \series bold
5468
5469 \series default
5470 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5471 \end_layout
5472
5473 \begin_layout Itemize
5474 s51 - The ucSim 8051 simulator.
5475 \end_layout
5476
5477 \begin_layout Itemize
5478 sdcdb - The source debugger.
5479 \end_layout
5480
5481 \begin_layout Itemize
5482 packihx - A tool to pack (compress) Intel hex files.
5483 \end_layout
5484
5485 \begin_layout Standard
5486 In <installdir>/share/sdcc/include
5487 \end_layout
5488
5489 \begin_layout Itemize
5490 the include files
5491 \end_layout
5492
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/lib
5495 \end_layout
5496
5497 \begin_layout Itemize
5498 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5499  relocatables.
5500 \end_layout
5501
5502 \begin_layout Standard
5503 In <installdir>/share/sdcc/doc
5504 \end_layout
5505
5506 \begin_layout Itemize
5507 the documentation
5508 \end_layout
5509
5510 \begin_layout Standard
5511 As development for other processors proceeds, this list will expand to include
5512  executables to support processors like AVR, PIC, etc.
5513 \end_layout
5514
5515 \begin_layout Subsection
5516 sdcc - The Compiler
5517 \end_layout
5518
5519 \begin_layout Standard
5520 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5521  the assembler and linkage editor.
5522 \end_layout
5523
5524 \begin_layout Subsection
5525 sdcpp - The C-Preprocessor
5526 \end_layout
5527
5528 \begin_layout Standard
5529 The preprocessor
5530 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5531
5532 \end_inset
5533
5534  is a modified version of the GNU cpp
5535 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5536
5537 \end_inset
5538
5539  preprocessor 
5540 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5541
5542 \end_inset
5543
5544 .
5545  The C preprocessor is used to pull in #include sources, process #ifdef
5546  statements, #defines and so on.
5547 \end_layout
5548
5549 \begin_layout Subsection
5550 as
5551 \emph on
5552 xxxx
5553 \emph default
5554 , aslink, link-
5555 \emph on
5556 xxx
5557 \emph default
5558  - The Assemblers and Linkage Editors
5559 \end_layout
5560
5561 \begin_layout Standard
5562 This is retargettable assembler & linkage editor, it was developed by Alan
5563  Baldwin.
5564  John Hartman created the version for 8051, and I (Sandeep) have made some
5565  enhancements and bug fixes for it to work properly with SDCC.
5566 \end_layout
5567
5568 \begin_layout Subsection
5569 s51 - The Simulator
5570 \end_layout
5571
5572 \begin_layout Standard
5573 S51
5574 \begin_inset LatexCommand \index{s51}
5575
5576 \end_inset
5577
5578  is a free open source simulator developed by Daniel Drotos.
5579  The simulator is built as part of the build process.
5580  For more information visit Daniel's web site at: 
5581 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5582
5583 \end_inset
5584
5585 .
5586  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5587  XA51 family.
5588 \end_layout
5589
5590 \begin_layout Subsection
5591 sdcdb - Source Level Debugger
5592 \end_layout
5593
5594 \begin_layout Standard
5595 SDCDB
5596 \begin_inset LatexCommand \index{SDCDB (debugger)}
5597
5598 \end_inset
5599
5600  is the companion source level debugger.
5601  More about SDCDB in section 
5602 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5603
5604 \end_inset
5605
5606 .
5607  The current version of the debugger uses Daniel's Simulator S51
5608 \begin_inset LatexCommand \index{s51}
5609
5610 \end_inset
5611
5612 , but can be easily changed to use other simulators.
5613 \end_layout
5614
5615 \begin_layout Chapter
5616 Using SDCC
5617 \end_layout
5618
5619 \begin_layout Section
5620 Compiling
5621 \end_layout
5622
5623 \begin_layout Subsection
5624 Single Source File Projects
5625 \end_layout
5626
5627 \begin_layout Standard
5628 For single source file 8051 projects the process is very simple.
5629  Compile your programs with the following command 
5630 \family sans
5631 \series bold
5632 "sdcc sourcefile.c".
5633
5634 \family default
5635 \series default
5636  This will compile, assemble and link your source file.
5637  Output files are as follows:
5638 \end_layout
5639
5640 \begin_layout Itemize
5641 sourcefile.asm
5642 \begin_inset LatexCommand \index{<file>.asm}
5643
5644 \end_inset
5645
5646  - Assembler source
5647 \begin_inset LatexCommand \index{Assembler source}
5648
5649 \end_inset
5650
5651  file created by the compiler
5652 \end_layout
5653
5654 \begin_layout Itemize
5655 sourcefile.lst
5656 \begin_inset LatexCommand \index{<file>.lst}
5657
5658 \end_inset
5659
5660  - Assembler listing
5661 \begin_inset LatexCommand \index{Assembler listing}
5662
5663 \end_inset
5664
5665  file created by the Assembler
5666 \end_layout
5667
5668 \begin_layout Itemize
5669 sourcefile.rst
5670 \begin_inset LatexCommand \index{<file>.rst}
5671
5672 \end_inset
5673
5674  - Assembler listing
5675 \begin_inset LatexCommand \index{Assembler listing}
5676
5677 \end_inset
5678
5679  file updated with linkedit information, created by linkage editor
5680 \end_layout
5681
5682 \begin_layout Itemize
5683 sourcefile.sym
5684 \begin_inset LatexCommand \index{<file>.sym}
5685
5686 \end_inset
5687
5688  - symbol listing
5689 \begin_inset LatexCommand \index{Symbol listing}
5690
5691 \end_inset
5692
5693  for the sourcefile, created by the assembler
5694 \end_layout
5695
5696 \begin_layout Itemize
5697 sourcefile.rel
5698 \begin_inset LatexCommand \index{<file>.rel}
5699
5700 \end_inset
5701
5702  or sourcefile.o
5703 \begin_inset LatexCommand \index{<file>.o}
5704
5705 \end_inset
5706
5707  - Object file
5708 \begin_inset LatexCommand \index{Object file}
5709
5710 \end_inset
5711
5712  created by the assembler, input to Linkage editor
5713 \end_layout
5714
5715 \begin_layout Itemize
5716 sourcefile.map
5717 \begin_inset LatexCommand \index{<file>.map}
5718
5719 \end_inset
5720
5721  - The memory map
5722 \begin_inset LatexCommand \index{Memory map}
5723
5724 \end_inset
5725
5726  for the load module, created by the Linker
5727 \end_layout
5728
5729 \begin_layout Itemize
5730 sourcefile.mem
5731 \begin_inset LatexCommand \index{<file>.mem}
5732
5733 \end_inset
5734
5735  - A file with a summary of the memory usage
5736 \end_layout
5737
5738 \begin_layout Itemize
5739 sourcefile.ihx
5740 \begin_inset LatexCommand \index{<file>.ihx}
5741
5742 \end_inset
5743
5744  - The load module in Intel hex format
5745 \begin_inset LatexCommand \index{Intel hex format}
5746
5747 \end_inset
5748
5749  (you can select the Motorola S19 format
5750 \begin_inset LatexCommand \index{Motorola S19 format}
5751
5752 \end_inset
5753
5754  with -
5755 \begin_inset ERT
5756 status collapsed
5757
5758 \begin_layout Standard
5759
5760
5761 \backslash
5762 /
5763 \end_layout
5764
5765 \end_inset
5766
5767 -out-fmt-s19
5768 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5769
5770 \end_inset
5771
5772 .
5773  If you need another format you might want to use 
5774 \family sans
5775 \shape italic
5776 objdump
5777 \family default
5778 \shape default
5779
5780 \begin_inset LatexCommand \index{objdump (tool)}
5781
5782 \end_inset
5783
5784  or
5785 \family sans
5786 \shape italic
5787  srecord
5788 \family default
5789 \shape default
5790
5791 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5792
5793 \end_inset
5794
5795
5796 \begin_inset Note Note
5797 status collapsed
5798
5799 \begin_layout Standard
5800 hyperlinks needed
5801 \end_layout
5802
5803 \end_inset
5804
5805  - see also section 
5806 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5807
5808 \end_inset
5809
5810 ).
5811  Both formats are documented in the documentation of srecord
5812 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5813
5814 \end_inset
5815
5816
5817 \end_layout
5818
5819 \begin_layout Itemize
5820 sourcefile.adb
5821 \begin_inset LatexCommand \index{<file>.adb}
5822
5823 \end_inset
5824
5825  - An intermediate file containing debug information needed to create the
5826  .cdb file (with -
5827 \begin_inset ERT
5828 status collapsed
5829
5830 \begin_layout Standard
5831
5832
5833 \backslash
5834 /
5835 \end_layout
5836
5837 \end_inset
5838
5839 -debug
5840 \begin_inset LatexCommand \index{-\/-debug}
5841
5842 \end_inset
5843
5844
5845 \end_layout
5846
5847 \begin_layout Itemize
5848 sourcefile.cdb
5849 \begin_inset LatexCommand \index{<file>.cdb}
5850
5851 \end_inset
5852
5853  - An optional file (with -
5854 \begin_inset ERT
5855 status collapsed
5856
5857 \begin_layout Standard
5858
5859
5860 \backslash
5861 /
5862 \end_layout
5863
5864 \end_inset
5865
5866 -debug) containing debug information.
5867  The format is documented in cdbfileformat.pdf
5868 \end_layout
5869
5870 \begin_layout Itemize
5871 sourcefile.
5872  - (no extension)
5873 \begin_inset LatexCommand \index{<file> (no extension)}
5874
5875 \end_inset
5876
5877  An optional AOMF or AOMF51
5878 \begin_inset LatexCommand \index{AOMF, AOMF51}
5879
5880 \end_inset
5881
5882  
5883 \begin_inset LatexCommand \label{OMF file}
5884
5885 \end_inset
5886
5887 file containing debug information (generated with option -
5888 \begin_inset ERT
5889 status collapsed
5890
5891 \begin_layout Standard
5892
5893
5894 \backslash
5895 /
5896 \end_layout
5897
5898 \end_inset
5899
5900 -debug).
5901  The (Intel)
5902 \emph on
5903  a
5904 \emph default
5905 bsolute 
5906 \emph on
5907 o
5908 \emph default
5909 bject 
5910 \emph on
5911 m
5912 \emph default
5913 odule 
5914 \emph on
5915 f
5916 \emph default
5917 ormat is a subformat of the OMF51 format and is commonly used by third party
5918  tools (debuggers
5919 \begin_inset LatexCommand \index{Debugger}
5920
5921 \end_inset
5922
5923 , simulators, emulators).
5924 \end_layout
5925
5926 \begin_layout Itemize
5927 sourcefile.dump*
5928 \begin_inset LatexCommand \index{<file>.dump*}
5929
5930 \end_inset
5931
5932  - Dump file to debug the compiler it self (generated with option -
5933 \begin_inset ERT
5934 status collapsed
5935
5936 \begin_layout Standard
5937
5938
5939 \backslash
5940 /
5941 \end_layout
5942
5943 \end_inset
5944
5945 -dumpall) (see section 
5946 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5947
5948 \end_inset
5949
5950 \InsetSpace ~
5951  and section 
5952 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5953
5954 \end_inset
5955
5956 \InsetSpace ~
5957
5958 \begin_inset Quotes sld
5959 \end_inset
5960
5961 Anatomy of the compiler
5962 \begin_inset Quotes srd
5963 \end_inset
5964
5965 ).
5966 \end_layout
5967
5968 \begin_layout Subsection
5969 Postprocessing the Intel Hex
5970 \begin_inset LatexCommand \index{Intel hex format}
5971
5972 \end_inset
5973
5974  file
5975 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5976
5977 \end_inset
5978
5979
5980 \end_layout
5981
5982 \begin_layout Standard
5983 In most cases this won't be needed but the Intel Hex file
5984 \begin_inset LatexCommand \index{<file>.ihx}
5985
5986 \end_inset
5987
5988  which is generated by SDCC might include lines of varying length and the
5989  addresses within the file are not guaranteed to be strictly ascending.
5990  If your toolchain or a bootloader does not like this you can use the tool
5991  
5992 \family typewriter
5993 packihx
5994 \family default
5995
5996 \begin_inset LatexCommand \index{packihx (tool)}
5997
5998 \end_inset
5999
6000  which is part of the SDCC distribution: 
6001 \newline
6002
6003 \newline
6004
6005 \family sans
6006 \series bold
6007  packihx sourcefile.ihx >sourcefile.hex
6008 \family default
6009 \series default
6010
6011 \newline
6012
6013 \newline
6014 The separately available
6015 \emph on
6016  srecord
6017 \emph default
6018
6019 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6020
6021 \end_inset
6022
6023  package additionally allows to set undefined locations to a predefined
6024  value, to insert checksums
6025 \begin_inset LatexCommand \index{checksum}
6026
6027 \end_inset
6028
6029  of various flavours (crc, add, xor) and to perform other manipulations
6030  (convert, split, crop, offset, ...).
6031  
6032 \newline
6033
6034 \newline
6035
6036 \family sans
6037 \series bold
6038 srec_cat\InsetSpace ~
6039 \InsetSpace ~
6040 sourcefile.ihx -intel\InsetSpace ~
6041 \InsetSpace ~
6042 -o sourcefile.hex -intel
6043 \newline
6044
6045 \newline
6046
6047 \family default
6048 \series default
6049 An example for a more complex command line
6050 \begin_inset Foot
6051 status open
6052
6053 \begin_layout Standard
6054 the command backfills
6055 \begin_inset LatexCommand \index{backfill unused memory}
6056
6057 \end_inset
6058
6059  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6060  block is zero.
6061  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6062  will be interpreted as an 
6063 \family typewriter
6064 lcall
6065 \family default
6066  to address 
6067 \family typewriter
6068 0x1212
6069 \family default
6070  (where an emergency routine could sit).
6071 \end_layout
6072
6073 \end_inset
6074
6075  could look like:
6076 \newline
6077
6078 \newline
6079
6080 \family sans
6081 \series bold
6082 \size footnotesize
6083 srec_cat\InsetSpace ~
6084 sourcefile.ihx -intel\InsetSpace ~
6085 \InsetSpace ~
6086 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6087 -little-endian-checksum-nega
6088 tive 0xfffe 0x02 0x02\InsetSpace ~
6089 \InsetSpace ~
6090 -o sourcefile.hex -intel
6091 \size default
6092
6093 \newline
6094
6095 \newline
6096
6097 \family default
6098 \series default
6099 The srecord package is available at 
6100 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6101
6102 \end_inset
6103
6104  .
6105 \end_layout
6106
6107 \begin_layout Subsection
6108 Projects with Multiple Source Files
6109 \end_layout
6110
6111 \begin_layout Standard
6112 SDCC can compile only ONE file at a time.
6113  Let us for example assume that you have a project containing the following
6114  files:
6115 \newline
6116
6117 \newline
6118 foo1.c (contains some functions)
6119 \newline
6120 foo2.c (contains some more functions)
6121 \newline
6122 foomai
6123 n.c (contains more functions and the function main)
6124 \newline
6125
6126 \size footnotesize
6127
6128 \newline
6129
6130 \size default
6131 The first two files will need to be compiled separately with the commands:
6132 \size footnotesize
6133  
6134 \size default
6135
6136 \newline
6137
6138 \newline
6139
6140 \family sans
6141 \series bold
6142 sdcc\InsetSpace ~
6143 -c\InsetSpace ~
6144 foo1.c
6145 \family default
6146 \series default
6147 \size footnotesize
6148
6149 \newline
6150
6151 \family sans
6152 \series bold
6153 \size default
6154 sdcc\InsetSpace ~
6155 -c\InsetSpace ~
6156 foo2.c
6157 \family default
6158 \series default
6159
6160 \newline
6161
6162 \newline
6163 Then compile the source file containing the 
6164 \emph on
6165 main()
6166 \emph default
6167  function and link
6168 \begin_inset LatexCommand \index{Linker}
6169
6170 \end_inset
6171
6172  the files together with the following command: 
6173 \newline
6174
6175 \newline
6176
6177 \family sans
6178 \series bold
6179 sdcc\InsetSpace ~
6180 foomain.c\InsetSpace ~
6181 foo1.rel\InsetSpace ~
6182 foo2.rel
6183 \family default
6184 \series default
6185
6186 \begin_inset LatexCommand \index{<file>.rel}
6187
6188 \end_inset
6189
6190
6191 \newline
6192
6193 \newline
6194 Alternatively, 
6195 \emph on
6196 foomain.c 
6197 \emph default
6198 can be separately compiled as well: 
6199 \family sans
6200 \series bold
6201
6202 \newline
6203
6204 \newline
6205 sdcc\InsetSpace ~
6206 -c\InsetSpace ~
6207 foomain.c
6208 \newline
6209 sdcc foomain.rel foo1.rel foo2.rel
6210 \newline
6211
6212 \newline
6213
6214 \family default
6215 \series default
6216 The file containing the 
6217 \emph on
6218 main()
6219 \emph default
6220  function
6221 \emph on
6222  
6223 \emph default
6224 \noun on
6225 must
6226 \noun default
6227  be the 
6228 \noun on
6229 first
6230 \noun default
6231  file specified in the command line, since the linkage editor processes
6232  file in the order they are presented to it.
6233  The linker is invoked from SDCC using a script file with extension .lnk
6234 \begin_inset LatexCommand \index{<file>.lnk}
6235
6236 \end_inset
6237
6238 .
6239  You can view this file to troubleshoot linking problems such as those arising
6240  from missing libraries.
6241 \end_layout
6242
6243 \begin_layout Subsection
6244 Projects with Additional Libraries
6245 \begin_inset LatexCommand \index{Libraries}
6246
6247 \end_inset
6248
6249
6250 \end_layout
6251
6252 \begin_layout Standard
6253 Some reusable routines may be compiled into a library, see the documentation
6254  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6255  for how to create a 
6256 \emph on
6257 .lib
6258 \begin_inset LatexCommand \index{<file>.lib}
6259
6260 \end_inset
6261
6262
6263 \emph default
6264  library file.
6265  Libraries created in this manner can be included in the command line.
6266  Make sure you include the -L <library-path> option to tell the linker where
6267  to look for these files if they are not in the current directory.
6268  Here is an example, assuming you have the source file 
6269 \emph on
6270 foomain.c
6271 \emph default
6272  and a library
6273 \emph on
6274  foolib.lib
6275 \emph default
6276  in the directory 
6277 \emph on
6278 mylib
6279 \emph default
6280  (if that is not the same as your current project):
6281 \newline
6282
6283 \newline
6284
6285 \family sans
6286 \series bold
6287 sdcc foomain.c foolib.lib -L mylib
6288 \newline
6289
6290 \newline
6291
6292 \family default
6293 \series default
6294 Note here that
6295 \emph on
6296  mylib
6297 \emph default
6298  must be an absolute path name.
6299 \newline
6300
6301 \newline
6302 The most efficient way to use libraries is
6303  to keep separate modules in separate source files.
6304  The lib file now should name all the modules.rel
6305 \begin_inset LatexCommand \index{<file>.rel}
6306
6307 \end_inset
6308
6309  files.
6310  For an example see the standard library file 
6311 \emph on
6312 libsdcc.lib
6313 \emph default
6314  in the directory <installdir>/share/lib/small.
6315 \end_layout
6316
6317 \begin_layout Subsection
6318 Using sdcclib to Create and Manage Libraries
6319 \begin_inset LatexCommand \index{sdcclib}
6320
6321 \end_inset
6322
6323
6324 \end_layout
6325
6326 \begin_layout Standard
6327 Alternatively, instead of having a .rel file for each entry on the library
6328  file as described in the preceding section, sdcclib can be used to embed
6329  all the modules belonging to such library in the library file itself.
6330  This results in a larger library file, but it greatly reduces the number
6331  of disk files accessed by the linker.
6332   Additionally, the packed library file contains an index of all include
6333  modules and symbols that significantly speeds up the linking process.
6334  To display a list of options supported by sdcclib type:
6335 \newline
6336
6337 \end_layout
6338
6339 \begin_layout Standard
6340
6341 \family sans
6342 \series bold
6343 sdcclib -?
6344 \begin_inset LatexCommand \index{sdcclib}
6345
6346 \end_inset
6347
6348
6349 \newline
6350
6351 \newline
6352
6353 \family default
6354 \series default
6355 To create a new library file, start by compiling all the required modules.
6356  For example:
6357 \newline
6358
6359 \end_layout
6360
6361 \begin_layout Standard
6362
6363 \family sans
6364 \series bold
6365 sdcc -c _divsint.c
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family sans
6371 \series bold
6372 sdcc -c _divuint.c
6373 \end_layout
6374
6375 \begin_layout Standard
6376
6377 \family sans
6378 \series bold
6379 sdcc -c _modsint.c
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family sans
6385 \series bold
6386 sdcc -c _moduint.c
6387 \end_layout
6388
6389 \begin_layout Standard
6390
6391 \family sans
6392 \series bold
6393 sdcc -c _mulint.c
6394 \newline
6395
6396 \end_layout
6397
6398 \begin_layout Standard
6399 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6400  and _mulint.rel.
6401  The next step is to add the .rel files to the library file:
6402 \newline
6403
6404 \end_layout
6405
6406 \begin_layout Standard
6407
6408 \family sans
6409 \series bold
6410 sdcclib libint.lib _divsint.rel
6411 \family default
6412
6413 \begin_inset LatexCommand \index{sdcclib}
6414
6415 \end_inset
6416
6417
6418 \end_layout
6419
6420 \begin_layout Standard
6421
6422 \family sans
6423 \series bold
6424 sdcclib libint.lib _divuint.rel
6425 \end_layout
6426
6427 \begin_layout Standard
6428
6429 \family sans
6430 \series bold
6431 sdcclib libint.lib _modsint.rel
6432 \end_layout
6433
6434 \begin_layout Standard
6435
6436 \family sans
6437 \series bold
6438 sdcclib libint.lib _moduint.rel
6439 \end_layout
6440
6441 \begin_layout Standard
6442
6443 \family sans
6444 \series bold
6445 sdcclib libint.lib _mulint.rel
6446 \family default
6447 \series default
6448
6449 \newline
6450
6451 \end_layout
6452
6453 \begin_layout Standard
6454 Or, if you preffer:
6455 \family sans
6456 \series bold
6457
6458 \newline
6459
6460 \end_layout
6461
6462 \begin_layout Standard
6463
6464 \family sans
6465 \series bold
6466 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6467 \family default
6468 \series default
6469
6470 \newline
6471
6472 \end_layout
6473
6474 \begin_layout Standard
6475 If the file already exists in the library, it will be replaced.
6476  If a list of .rel files is available, you can tell sdcclib to add those
6477  files to a library.
6478  For example, if the file 'myliblist.txt' contains
6479 \family sans
6480 \series bold
6481
6482 \newline
6483
6484 \end_layout
6485
6486 \begin_layout Standard
6487
6488 \family sans
6489 \series bold
6490 _divsint.rel
6491 \end_layout
6492
6493 \begin_layout Standard
6494
6495 \family sans
6496 \series bold
6497 _divuint.rel
6498 \end_layout
6499
6500 \begin_layout Standard
6501
6502 \family sans
6503 \series bold
6504 _modsint.rel
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family sans
6510 \series bold
6511 _moduint.rel
6512 \end_layout
6513
6514 \begin_layout Standard
6515
6516 \family sans
6517 \series bold
6518 _mulint.rel
6519 \family default
6520 \series default
6521
6522 \newline
6523
6524 \end_layout
6525
6526 \begin_layout Standard
6527 Use
6528 \family sans
6529 \series bold
6530
6531 \newline
6532
6533 \end_layout
6534
6535 \begin_layout Standard
6536
6537 \family sans
6538 \series bold
6539 sdcclib -l libint.lib myliblist.txt
6540 \family default
6541 \series default
6542
6543 \newline
6544
6545 \end_layout
6546
6547 \begin_layout Standard
6548 Additionally, you can instruct sdcclib to compiles the files before adding
6549  them to the library.
6550  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6551  For example:
6552 \family sans
6553 \series bold
6554
6555 \newline
6556
6557 \end_layout
6558
6559 \begin_layout Standard
6560
6561 \family sans
6562 \series bold
6563 set SDCCLIB_CC=sdcc -c
6564 \end_layout
6565
6566 \begin_layout Standard
6567
6568 \family sans
6569 \series bold
6570 sdcclib -l libint.lib myliblist.txt
6571 \family default
6572 \series default
6573
6574 \newline
6575
6576 \end_layout
6577
6578 \begin_layout Standard
6579 To see what modules and symbols are included in the library, options -s
6580  and -m are available.
6581  For example:
6582 \newline
6583
6584 \newline
6585
6586 \family sans
6587 \series bold
6588 sdcclib -s libint.lib
6589 \family default
6590
6591 \begin_inset LatexCommand \index{sdcclib}
6592
6593 \end_inset
6594
6595
6596 \newline
6597
6598 \family typewriter
6599 \series default
6600 _divsint.rel:
6601 \end_layout
6602
6603 \begin_layout Standard
6604
6605 \family typewriter
6606 __divsint_a_1_1
6607 \end_layout
6608
6609 \begin_layout Standard
6610
6611 \family typewriter
6612 __divsint_PARM_2
6613 \end_layout
6614
6615 \begin_layout Standard
6616
6617 \family typewriter
6618 __divsint
6619 \newline
6620 _divuint.rel:
6621 \end_layout
6622
6623 \begin_layout Standard
6624
6625 \family typewriter
6626 __divuint_a_1_1
6627 \end_layout
6628
6629 \begin_layout Standard
6630
6631 \family typewriter
6632 __divuint_PARM_2
6633 \end_layout
6634
6635 \begin_layout Standard
6636
6637 \family typewriter
6638 __divuint_reste_1_1
6639 \end_layout
6640
6641 \begin_layout Standard
6642
6643 \family typewriter
6644 __divuint_count_1_1
6645 \end_layout
6646
6647 \begin_layout Standard
6648
6649 \family typewriter
6650 __divuint
6651 \newline
6652 _modsint.rel:
6653 \end_layout
6654
6655 \begin_layout Standard
6656
6657 \family typewriter
6658 __modsint_a_1_1
6659 \end_layout
6660
6661 \begin_layout Standard
6662
6663 \family typewriter
6664 __modsint_PARM_2
6665 \end_layout
6666
6667 \begin_layout Standard
6668
6669 \family typewriter
6670 __modsint
6671 \newline
6672 _moduint.rel:
6673 \end_layout
6674
6675 \begin_layout Standard
6676
6677 \family typewriter
6678 __moduint_a_1_1
6679 \end_layout
6680
6681 \begin_layout Standard
6682
6683 \family typewriter
6684 __moduint_PARM_2
6685 \end_layout
6686
6687 \begin_layout Standard
6688
6689 \family typewriter
6690 __moduint_count_1_1
6691 \end_layout
6692
6693 \begin_layout Standard
6694
6695 \family typewriter
6696 __moduint
6697 \newline
6698 _mulint.rel:
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family typewriter
6704 __mulint_PARM_2
6705 \end_layout
6706
6707 \begin_layout Standard
6708
6709 \family typewriter
6710 __mulint
6711 \family default
6712 \series bold
6713
6714 \newline
6715
6716 \end_layout
6717
6718 \begin_layout Standard
6719 If the source files are compiled using -
6720 \begin_inset ERT
6721 status collapsed
6722
6723 \begin_layout Standard
6724
6725
6726 \backslash
6727 /
6728 \end_layout
6729
6730 \end_inset
6731
6732 -debug
6733 \begin_inset LatexCommand \index{-\/-debug}
6734
6735 \end_inset
6736
6737 , the corresponding debug information file .adb will be include in the library
6738  file as well.
6739  The library files created with sdcclib are plain text files, so they can
6740  be viewed with a text editor.
6741  It is not recomended to modify a library file created with sdcclib using
6742  a text editor, as there are file indexes numbers located accross the file
6743  used by the linker to quickly locate the required module to link.
6744  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6745  it can be safely deleted, since all the information required for linking
6746  is embedded in the library file itself.
6747  Library files created using sdcclib are used as described in the preceding
6748  sections.
6749 \begin_inset VSpace bigskip
6750 \end_inset
6751
6752
6753 \end_layout
6754
6755 \begin_layout Section
6756 Command Line Options
6757 \begin_inset LatexCommand \index{Command Line Options}
6758
6759 \end_inset
6760
6761
6762 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6763
6764 \end_inset
6765
6766
6767 \end_layout
6768
6769 \begin_layout Subsection
6770 Processor Selection Options
6771 \begin_inset LatexCommand \index{Options processor selection}
6772
6773 \end_inset
6774
6775
6776 \begin_inset LatexCommand \index{Processor selection options}
6777
6778 \end_inset
6779
6780
6781 \end_layout
6782
6783 \begin_layout List
6784 \labelwidthstring 00.00.0000
6785
6786 \series bold
6787 -mmcs51
6788 \begin_inset LatexCommand \index{-mmcs51}
6789
6790 \end_inset
6791
6792
6793 \series default
6794  Generate code for the Intel MCS51
6795 \begin_inset LatexCommand \index{MCS51}
6796
6797 \end_inset
6798
6799  family of processors.
6800  This is the default processor target.
6801 \end_layout
6802
6803 \begin_layout List
6804 \labelwidthstring 00.00.0000
6805
6806 \series bold
6807 -mds390
6808 \begin_inset LatexCommand \index{-mds390}
6809
6810 \end_inset
6811
6812
6813 \series default
6814  Generate code for the Dallas DS80C390
6815 \begin_inset LatexCommand \index{DS80C390}
6816
6817 \end_inset
6818
6819  processor.
6820 \end_layout
6821
6822 \begin_layout List
6823 \labelwidthstring 00.00.0000
6824
6825 \series bold
6826 -mds400
6827 \begin_inset LatexCommand \index{-mds400}
6828
6829 \end_inset
6830
6831
6832 \series default
6833  Generate code for the Dallas DS80C400
6834 \begin_inset LatexCommand \index{DS80C400}
6835
6836 \end_inset
6837
6838  processor.
6839 \end_layout
6840
6841 \begin_layout List
6842 \labelwidthstring 00.00.0000
6843
6844 \series bold
6845 -mhc08
6846 \begin_inset LatexCommand \index{-mhc08}
6847
6848 \end_inset
6849
6850
6851 \series default
6852  Generate code for the Freescale/Motorola HC08
6853 \begin_inset LatexCommand \index{HC08}
6854
6855 \end_inset
6856
6857  family of processors.
6858 \end_layout
6859
6860 \begin_layout List
6861 \labelwidthstring 00.00.0000
6862
6863 \series bold
6864 -mz80
6865 \begin_inset LatexCommand \index{-mz80}
6866
6867 \end_inset
6868
6869
6870 \series default
6871  Generate code for the Zilog Z80
6872 \begin_inset LatexCommand \index{Z80}
6873
6874 \end_inset
6875
6876  family of processors.
6877 \end_layout
6878
6879 \begin_layout List
6880 \labelwidthstring 00.00.0000
6881
6882 \series bold
6883 -mgbz80
6884 \begin_inset LatexCommand \index{-mgbz80}
6885
6886 \end_inset
6887
6888
6889 \series default
6890  Generate code for the GameBoy Z80
6891 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6892
6893 \end_inset
6894
6895  processor (Not actively maintained).
6896 \end_layout
6897
6898 \begin_layout List
6899 \labelwidthstring 00.00.0000
6900
6901 \series bold
6902 -mavr
6903 \begin_inset LatexCommand \index{-mavr}
6904
6905 \end_inset
6906
6907
6908 \series default
6909  Generate code for the Atmel AVR
6910 \begin_inset LatexCommand \index{AVR}
6911
6912 \end_inset
6913
6914  processor (Not maintained, not complete).
6915  AVR users should probably have a look at winavr 
6916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6917
6918 \end_inset
6919
6920  or 
6921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6922
6923 \end_inset
6924
6925 , which is based on AVR-port of the gcc compiler.
6926 \end_layout
6927
6928 \begin_layout Standard
6929 \begin_inset Note Note
6930 status collapsed
6931
6932 \begin_layout Standard
6933 I think it is fair to direct users there for now.
6934  Open source is also about avoiding unnecessary work .
6935  But I didn't find the 'official' link.
6936 \end_layout
6937
6938 \end_inset
6939
6940
6941 \end_layout
6942
6943 \begin_layout List
6944 \labelwidthstring 00.00.0000
6945
6946 \series bold
6947 -mpic14
6948 \begin_inset LatexCommand \index{-mpic14}
6949
6950 \end_inset
6951
6952
6953 \series default
6954  Generate code for the Microchip PIC 14
6955 \begin_inset LatexCommand \index{PIC14}
6956
6957 \end_inset
6958
6959 -bit processors (p16f84 and variants.
6960  In development, not complete).
6961 \end_layout
6962
6963 \begin_layout Standard
6964 \begin_inset Note Note
6965 status collapsed
6966
6967 \begin_layout Standard
6968 p16f627 p16f628 p16f84 p16f873 p16f877?
6969 \end_layout
6970
6971 \end_inset
6972
6973
6974 \end_layout
6975
6976 \begin_layout List
6977 \labelwidthstring 00.00.0000
6978
6979 \series bold
6980 -mpic16
6981 \begin_inset LatexCommand \index{-mpic16}
6982
6983 \end_inset
6984
6985
6986 \series default
6987  Generate code for the Microchip PIC 16
6988 \begin_inset LatexCommand \index{PIC16}
6989
6990 \end_inset
6991
6992 -bit processors (p18f452 and variants.
6993  In development, not complete).
6994 \end_layout
6995
6996 \begin_layout List
6997 \labelwidthstring 00.00.0000
6998
6999 \series bold
7000 -mtlcs900h
7001 \series default
7002  Generate code for the Toshiba TLCS-900H
7003 \begin_inset LatexCommand \index{TLCS-900H}
7004
7005 \end_inset
7006
7007  processor (Not maintained, not complete).
7008 \end_layout
7009
7010 \begin_layout List
7011 \labelwidthstring 00.00.0000
7012
7013 \series bold
7014 -mxa51
7015 \begin_inset LatexCommand \index{-mxa51}
7016
7017 \end_inset
7018
7019
7020 \series default
7021  Generate code for the Phillips XA51
7022 \begin_inset LatexCommand \index{XA51}
7023
7024 \end_inset
7025
7026  processor (Not maintained, not complete).
7027 \end_layout
7028
7029 \begin_layout Standard
7030 \begin_inset VSpace bigskip
7031 \end_inset
7032
7033
7034 \end_layout
7035
7036 \begin_layout Subsection
7037 Preprocessor Options
7038 \begin_inset LatexCommand \index{Options preprocessor}
7039
7040 \end_inset
7041
7042
7043 \begin_inset LatexCommand \index{Preprocessor options}
7044
7045 \end_inset
7046
7047
7048 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7049
7050 \end_inset
7051
7052
7053 \end_layout
7054
7055 \begin_layout List
7056 \labelwidthstring 00.00.0000
7057
7058 \series bold
7059 -I<path>
7060 \begin_inset LatexCommand \index{-I<path>}
7061
7062 \end_inset
7063
7064
7065 \series default
7066  The additional location where the preprocessor will look for <..h> or 
7067 \begin_inset Quotes eld
7068 \end_inset
7069
7070 ..h
7071 \begin_inset Quotes erd
7072 \end_inset
7073
7074  files.
7075 \end_layout
7076
7077 \begin_layout List
7078 \labelwidthstring 00.00.0000
7079
7080 \series bold
7081 -D<macro[=value]>
7082 \begin_inset LatexCommand \index{-D<macro[=value]>}
7083
7084 \end_inset
7085
7086
7087 \series default
7088  Command line definition of macros.
7089  Passed to the preprocessor.
7090 \end_layout
7091
7092 \begin_layout List
7093 \labelwidthstring 00.00.0000
7094
7095 \series bold
7096 -M
7097 \begin_inset LatexCommand \index{-M}
7098
7099 \end_inset
7100
7101
7102 \series default
7103  Tell the preprocessor to output a rule suitable for make describing the
7104  dependencies of each object file.
7105  For each source file, the preprocessor outputs one make-rule whose target
7106  is the object file name for that source file and whose dependencies are
7107  all the files `#include'd in it.
7108  This rule may be a single line or may be continued with `
7109 \backslash
7110 '-newline if it is long.
7111  The list of rules is printed on standard output instead of the preprocessed
7112  C program.
7113  `-M' implies `-E
7114 \begin_inset LatexCommand \index{-E}
7115
7116 \end_inset
7117
7118 '.
7119 \end_layout
7120
7121 \begin_layout List
7122 \labelwidthstring 00.00.0000
7123
7124 \series bold
7125 -C
7126 \begin_inset LatexCommand \index{-C}
7127
7128 \end_inset
7129
7130
7131 \series default
7132  Tell the preprocessor not to discard comments.
7133  Used with the `-E' option.
7134 \end_layout
7135
7136 \begin_layout List
7137 \labelwidthstring 00.00.0000
7138
7139 \series bold
7140 -MM
7141 \begin_inset LatexCommand \index{-MM}
7142
7143 \end_inset
7144
7145
7146 \size large
7147 \bar under
7148  
7149 \series default
7150 \size default
7151 \bar default
7152 Like `-M' but the output mentions only the user header files included with
7153  `#include 
7154 \begin_inset Quotes eld
7155 \end_inset
7156
7157 file"'.
7158  System header files included with `#include <file>' are omitted.
7159 \end_layout
7160
7161 \begin_layout List
7162 \labelwidthstring 00.00.0000
7163
7164 \series bold
7165 -Aquestion(answer)
7166 \begin_inset LatexCommand \index{-Aquestion(answer)}
7167
7168 \end_inset
7169
7170
7171 \series default
7172  Assert the answer answer for question, in case it is tested with a preprocessor
7173  conditional such as `#if #question(answer)'.
7174  `-A-' disables the standard assertions that normally describe the target
7175  machine.
7176 \end_layout
7177
7178 \begin_layout List
7179 \labelwidthstring 00.00.0000
7180
7181 \series bold
7182 -Umacro
7183 \begin_inset LatexCommand \index{-Umacro}
7184
7185 \end_inset
7186
7187
7188 \series default
7189  Undefine macro macro.
7190  `-U' options are evaluated after all `-D' options, but before any `-include'
7191  and `-imacros' options.
7192 \end_layout
7193
7194 \begin_layout List
7195 \labelwidthstring 00.00.0000
7196
7197 \series bold
7198 -dM
7199 \begin_inset LatexCommand \index{-dM}
7200
7201 \end_inset
7202
7203
7204 \series default
7205  Tell the preprocessor to output only a list of the macro definitions that
7206  are in effect at the end of preprocessing.
7207  Used with the `-E' option.
7208 \end_layout
7209
7210 \begin_layout List
7211 \labelwidthstring 00.00.0000
7212
7213 \series bold
7214 -dD
7215 \begin_inset LatexCommand \index{-dD}
7216
7217 \end_inset
7218
7219
7220 \series default
7221  Tell the preprocessor to pass all macro definitions into the output, in
7222  their proper sequence in the rest of the output.
7223 \end_layout
7224
7225 \begin_layout List
7226 \labelwidthstring 00.00.0000
7227
7228 \series bold
7229 -dN
7230 \begin_inset LatexCommand \index{-dN}
7231
7232 \end_inset
7233
7234
7235 \size large
7236 \bar under
7237  
7238 \series default
7239 \size default
7240 \bar default
7241 Like `-dD' except that the macro arguments and contents are omitted.
7242  Only `#define name' is included in the output.
7243 \end_layout
7244
7245 \begin_layout List
7246 \labelwidthstring 00.00.0000
7247
7248 \series bold
7249 -pedantic-parse-number
7250 \begin_inset LatexCommand \index{pedantic}
7251
7252 \end_inset
7253
7254
7255 \begin_inset LatexCommand \index{-pedantic-parse-number}
7256
7257 \end_inset
7258
7259
7260 \size large
7261 \bar under
7262
7263 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7264
7265 \end_inset
7266
7267  
7268 \series default
7269 \size default
7270 \bar default
7271 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7272  and the macro LO_B(3) gets expanded.
7273  See also #pragma pedantic_parse_number 
7274 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7275
7276 \end_inset
7277
7278  in section
7279 \begin_inset LatexCommand \ref{sec:Pragmas}
7280
7281 \end_inset
7282
7283  
7284 \emph on
7285 Note: this functionality is not in conformance with C99 standard!
7286 \end_layout
7287
7288 \begin_layout List
7289 \labelwidthstring 00.00.0000
7290
7291 \series bold
7292 -Wp\InsetSpace ~
7293 preprocessorOption[,preprocessorOption]
7294 \series default
7295
7296 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7297
7298 \end_inset
7299
7300 ...
7301  Pass the preprocessorOption to the preprocessor 
7302 \family typewriter
7303 sdcpp
7304 \family default
7305
7306 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7307
7308 \end_inset
7309
7310 .
7311  SDCC uses an adapted version of the preprocessor 
7312 \emph on
7313 cpp
7314 \emph default
7315  of the GNU Compiler Collection
7316 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7317
7318 \end_inset
7319
7320  (
7321 \emph on
7322 gcc
7323 \emph default
7324  
7325 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7326
7327 \end_inset
7328
7329 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7330 4.1.1\InsetSpace ~
7331 CPP\InsetSpace ~
7332 Manual
7333  at 
7334 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7335
7336 \end_inset
7337
7338 .
7339 \end_layout
7340
7341 \begin_layout Standard
7342 \begin_inset VSpace bigskip
7343 \end_inset
7344
7345
7346 \end_layout
7347
7348 \begin_layout Subsection
7349 Linker Options
7350 \begin_inset LatexCommand \index{Options linker}
7351
7352 \end_inset
7353
7354
7355 \begin_inset LatexCommand \index{Linker options}
7356
7357 \end_inset
7358
7359
7360 \end_layout
7361
7362 \begin_layout List
7363 \labelwidthstring 00.00.0000
7364
7365 \series bold
7366 -L\InsetSpace ~
7367 -
7368 \series default
7369
7370 \begin_inset ERT
7371 status collapsed
7372
7373 \begin_layout Standard
7374
7375
7376 \backslash
7377 /
7378 \end_layout
7379
7380 \end_inset
7381
7382
7383 \series bold
7384 -lib-path
7385 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7386
7387 \end_inset
7388
7389
7390 \begin_inset LatexCommand \index{-L -\/-lib-path}
7391
7392 \end_inset
7393
7394
7395 \series default
7396 \InsetSpace ~
7397 <absolute path to additional libraries> This option is passed to the linkage
7398  editor's additional libraries
7399 \begin_inset LatexCommand \index{Libraries}
7400
7401 \end_inset
7402
7403  search path.
7404  The path name must be absolute.
7405  Additional library files may be specified in the command line.
7406  See section Compiling programs for more details.
7407 \end_layout
7408
7409 \begin_layout List
7410 \labelwidthstring 00.00.0000
7411
7412 \series bold
7413 -
7414 \begin_inset ERT
7415 status collapsed
7416
7417 \begin_layout Standard
7418
7419
7420 \backslash
7421 /
7422 \end_layout
7423
7424 \end_inset
7425
7426 -xram-loc
7427 \series default
7428
7429 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7430
7431 \end_inset
7432
7433 \InsetSpace ~
7434 <Value> The start location of the external ram
7435 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7436
7437 \end_inset
7438
7439 , default value is 0.
7440  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7441 \begin_inset ERT
7442 status collapsed
7443
7444 \begin_layout Standard
7445
7446
7447 \backslash
7448 /
7449 \end_layout
7450
7451 \end_inset
7452
7453 -xram-loc 0x8000 or -
7454 \begin_inset ERT
7455 status collapsed
7456
7457 \begin_layout Standard
7458
7459
7460 \backslash
7461 /
7462 \end_layout
7463
7464 \end_inset
7465
7466 -xram-loc 32768.
7467 \end_layout
7468
7469 \begin_layout List
7470 \labelwidthstring 00.00.0000
7471
7472 \series bold
7473 -
7474 \begin_inset ERT
7475 status collapsed
7476
7477 \begin_layout Standard
7478
7479
7480 \backslash
7481 /
7482 \end_layout
7483
7484 \end_inset
7485
7486 -code-loc
7487 \series default
7488
7489 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7490
7491 \end_inset
7492
7493 \InsetSpace ~
7494 <Value> The start location of the code
7495 \begin_inset LatexCommand \index{code}
7496
7497 \end_inset
7498
7499  segment, default value 0.
7500  Note when this option is used the interrupt vector table
7501 \begin_inset LatexCommand \index{interrupt vector table}
7502
7503 \end_inset
7504
7505  is also relocated to the given address.
7506  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7507 \begin_inset ERT
7508 status collapsed
7509
7510 \begin_layout Standard
7511
7512
7513 \backslash
7514 /
7515 \end_layout
7516
7517 \end_inset
7518
7519 -code-loc 0x8000 or -
7520 \begin_inset ERT
7521 status collapsed
7522
7523 \begin_layout Standard
7524
7525
7526 \backslash
7527 /
7528 \end_layout
7529
7530 \end_inset
7531
7532 -code-loc 32768.
7533 \end_layout
7534
7535 \begin_layout List
7536 \labelwidthstring 00.00.0000
7537
7538 \series bold
7539 -
7540 \begin_inset ERT
7541 status collapsed
7542
7543 \begin_layout Standard
7544
7545
7546 \backslash
7547 /
7548 \end_layout
7549
7550 \end_inset
7551
7552 -stack-loc
7553 \series default
7554
7555 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7556
7557 \end_inset
7558
7559 \InsetSpace ~
7560 <Value> By default the stack
7561 \begin_inset LatexCommand \index{stack}
7562
7563 \end_inset
7564
7565  is placed after the data segment.
7566  Using this option the stack can be placed anywhere in the internal memory
7567  space of the 8051.
7568  The value entered can be in Hexadecimal or Decimal format, e.g.
7569  -
7570 \begin_inset ERT
7571 status collapsed
7572
7573 \begin_layout Standard
7574
7575
7576 \backslash
7577 /
7578 \end_layout
7579
7580 \end_inset
7581
7582 -stack-loc 0x20 or -
7583 \begin_inset ERT
7584 status collapsed
7585
7586 \begin_layout Standard
7587
7588
7589 \backslash
7590 /
7591 \end_layout
7592
7593 \end_inset
7594
7595 -stack-loc 32.
7596  Since the sp register is incremented before a push or call, the initial
7597  sp will be set to one byte prior the provided value.
7598  The provided value should not overlap any other memory areas such as used
7599  register banks or the data segment and with enough space for the current
7600  application.
7601  The 
7602 \series bold
7603 -
7604 \begin_inset ERT
7605 status collapsed
7606
7607 \begin_layout Standard
7608
7609
7610 \backslash
7611 /
7612 \end_layout
7613
7614 \end_inset
7615
7616 -pack-iram
7617 \series default
7618 \InsetSpace ~
7619
7620 \begin_inset LatexCommand \index{-\/-pack-iram}
7621
7622 \end_inset
7623
7624  option (which is now a default setting) will override this setting, so
7625  you should also specify the 
7626 \series bold
7627 -
7628 \begin_inset ERT
7629 status collapsed
7630
7631 \begin_layout Standard
7632
7633
7634 \backslash
7635 /
7636 \end_layout
7637
7638 \end_inset
7639
7640 -no-pack-iram
7641 \series default
7642 \InsetSpace ~
7643
7644 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7645
7646 \end_inset
7647
7648  option if you need to manually place the stack.
7649 \end_layout
7650
7651 \begin_layout List
7652 \labelwidthstring 00.00.0000
7653
7654 \series bold
7655 -
7656 \begin_inset ERT
7657 status collapsed
7658
7659 \begin_layout Standard
7660
7661
7662 \backslash
7663 /
7664 \end_layout
7665
7666 \end_inset
7667
7668 -xstack-loc
7669 \series default
7670
7671 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7672
7673 \end_inset
7674
7675 \InsetSpace ~
7676 <Value> By default the external stack
7677 \begin_inset LatexCommand \index{xstack}
7678
7679 \end_inset
7680
7681  is placed after the pdata
7682 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7683
7684 \end_inset
7685
7686  segment.
7687  Using this option the xstack can be placed anywhere in the external memory
7688  space of the 8051.
7689  The value entered can be in Hexadecimal or Decimal format, e.g.
7690  -
7691 \begin_inset ERT
7692 status collapsed
7693
7694 \begin_layout Standard
7695
7696
7697 \backslash
7698 /
7699 \end_layout
7700
7701 \end_inset
7702
7703 -xstack-loc 0x8000 or -
7704 \begin_inset ERT
7705 status collapsed
7706
7707 \begin_layout Standard
7708
7709
7710 \backslash
7711 /
7712 \end_layout
7713
7714 \end_inset
7715
7716 -stack-loc 32768.
7717  The provided value should not overlap any other memory areas such as the
7718  pdata or xdata segment and with enough space for the current application.
7719 \end_layout
7720
7721 \begin_layout List
7722 \labelwidthstring 00.00.0000
7723
7724 \series bold
7725 -
7726 \begin_inset ERT
7727 status collapsed
7728
7729 \begin_layout Standard
7730
7731
7732 \backslash
7733 /
7734 \end_layout
7735
7736 \end_inset
7737
7738 -data-loc
7739 \series default
7740
7741 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7742
7743 \end_inset
7744
7745 \InsetSpace ~
7746 <Value> The start location of the internal ram data
7747 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7748
7749 \end_inset
7750
7751  segment.
7752  The value entered can be in Hexadecimal or Decimal format, eg.
7753  -
7754 \begin_inset ERT
7755 status collapsed
7756
7757 \begin_layout Standard
7758
7759
7760 \backslash
7761 /
7762 \end_layout
7763
7764 \end_inset
7765
7766 -data-loc 0x20 or -
7767 \begin_inset ERT
7768 status collapsed
7769
7770 \begin_layout Standard
7771
7772
7773 \backslash
7774 /
7775 \end_layout
7776
7777 \end_inset
7778
7779 -data-loc 32.
7780  (By default, the start location of the internal ram data segment  is set
7781  as low as possible in memory, taking into account the used register banks
7782  and the bit segment at address 0x20.
7783  For example if register banks 0 and 1 are used without bit variables, the
7784  data segment will be set, if -
7785 \begin_inset ERT
7786 status collapsed
7787
7788 \begin_layout Standard
7789
7790
7791 \backslash
7792 /
7793 \end_layout
7794
7795 \end_inset
7796
7797 -data-loc is not used, to location 0x10.)
7798 \end_layout
7799
7800 \begin_layout List
7801 \labelwidthstring 00.00.0000
7802
7803 \series bold
7804 -
7805 \begin_inset ERT
7806 status collapsed
7807
7808 \begin_layout Standard
7809
7810
7811 \backslash
7812 /
7813 \end_layout
7814
7815 \end_inset
7816
7817 -idata-loc
7818 \series default
7819
7820 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7821
7822 \end_inset
7823
7824 \InsetSpace ~
7825 <Value> The start location of the indirectly addressable internal ram
7826 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7827
7828 \end_inset
7829
7830  of the 8051, default value is 0x80.
7831  The value entered can be in Hexadecimal or Decimal format, eg.
7832  -
7833 \begin_inset ERT
7834 status collapsed
7835
7836 \begin_layout Standard
7837
7838
7839 \backslash
7840 /
7841 \end_layout
7842
7843 \end_inset
7844
7845 -idata-loc 0x88 or -
7846 \begin_inset ERT
7847 status collapsed
7848
7849 \begin_layout Standard
7850
7851
7852 \backslash
7853 /
7854 \end_layout
7855
7856 \end_inset
7857
7858 -idata-loc 136.
7859 \end_layout
7860
7861 \begin_layout List
7862 \labelwidthstring 00.00.0000
7863
7864 \series bold
7865 -
7866 \begin_inset ERT
7867 status collapsed
7868
7869 \begin_layout Standard
7870
7871
7872 \backslash
7873 /
7874 \end_layout
7875
7876 \end_inset
7877
7878 -bit-loc
7879 \series default
7880 \InsetSpace ~
7881 <Value> The start location of the bit
7882 \begin_inset LatexCommand \index{bit}
7883
7884 \end_inset
7885
7886  addressable internal ram of the 8051.
7887  This is 
7888 \emph on
7889 not
7890 \emph default
7891  implemented yet.
7892  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7893 -bBSEG=<Value>.
7894 \end_layout
7895
7896 \begin_layout List
7897 \labelwidthstring 00.00.0000
7898
7899 \series bold
7900 -
7901 \begin_inset ERT
7902 status collapsed
7903
7904 \begin_layout Standard
7905
7906
7907 \backslash
7908 /
7909 \end_layout
7910
7911 \end_inset
7912
7913 -out-fmt-ihx
7914 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7915
7916 \end_inset
7917
7918
7919 \bar under
7920  
7921 \series default
7922 \bar default
7923 The linker output (final object code) is in Intel Hex format.
7924 \begin_inset LatexCommand \index{Intel hex format}
7925
7926 \end_inset
7927
7928  This is the default option.
7929  The format itself is documented in the documentation of srecord
7930 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7931
7932 \end_inset
7933
7934 .
7935 \end_layout
7936
7937 \begin_layout List
7938 \labelwidthstring 00.00.0000
7939
7940 \series bold
7941 -
7942 \begin_inset ERT
7943 status collapsed
7944
7945 \begin_layout Standard
7946
7947
7948 \backslash
7949 /
7950 \end_layout
7951
7952 \end_inset
7953
7954 -out-fmt-s19
7955 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7956
7957 \end_inset
7958
7959
7960 \bar under
7961  
7962 \series default
7963 \bar default
7964 The linker output (final object code) is in Motorola S19 format
7965 \begin_inset LatexCommand \index{Motorola S19 format}
7966
7967 \end_inset
7968
7969 .
7970  The format itself is documented in the documentation of srecord.
7971 \end_layout
7972
7973 \begin_layout List
7974 \labelwidthstring 00.00.0000
7975
7976 \series bold
7977 -
7978 \begin_inset ERT
7979 status collapsed
7980
7981 \begin_layout Standard
7982
7983
7984 \backslash
7985 /
7986 \end_layout
7987
7988 \end_inset
7989
7990 -out-fmt-elf
7991 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7992
7993 \end_inset
7994
7995
7996 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7997
7998 \end_inset
7999
8000
8001 \bar under
8002  
8003 \series default
8004 \bar default
8005 The linker output (final object code) is in ELF format
8006 \begin_inset LatexCommand \index{ELF format}
8007
8008 \end_inset
8009
8010 .
8011  (Currently only supported for the HC08
8012 \begin_inset LatexCommand \index{HC08}
8013
8014 \end_inset
8015
8016  processors)
8017 \end_layout
8018
8019 \begin_layout List
8020 \labelwidthstring 00.00.0000
8021
8022 \series bold
8023 -Wl\InsetSpace ~
8024 linkOption[,linkOption]
8025 \series default
8026
8027 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8028
8029 \end_inset
8030
8031 ...
8032  Pass the linkOption to the linker.
8033  If a bootloader is used an option like 
8034 \begin_inset Quotes sld
8035 \end_inset
8036
8037 -Wl\InsetSpace ~
8038 -bCSEG=0x1000
8039 \begin_inset Quotes srd
8040 \end_inset
8041
8042  would be typical to set the start of the code segment.
8043  See also #pragma constseg and #pragma codeseg in section 
8044 \begin_inset LatexCommand \ref{sec:Pragmas}
8045
8046 \end_inset
8047
8048  .
8049  File sdcc/as/doc/asxhtm.html has more on linker options.
8050 \end_layout
8051
8052 \begin_layout Standard
8053 \begin_inset VSpace bigskip
8054 \end_inset
8055
8056
8057 \end_layout
8058
8059 \begin_layout Subsection
8060 MCS51 Options
8061 \begin_inset LatexCommand \index{Options MCS51}
8062
8063 \end_inset
8064
8065
8066 \begin_inset LatexCommand \index{MCS51 options}
8067
8068 \end_inset
8069
8070
8071 \end_layout
8072
8073 \begin_layout List
8074 \labelwidthstring 00.00.0000
8075
8076 \series bold
8077 -
8078 \begin_inset ERT
8079 status collapsed
8080
8081 \begin_layout Standard
8082
8083
8084 \backslash
8085 /
8086 \end_layout
8087
8088 \end_inset
8089
8090 -model-small
8091 \begin_inset LatexCommand \index{-\/-model-small}
8092
8093 \end_inset
8094
8095
8096 \series default
8097 \size large
8098 \emph on
8099  
8100 \size default
8101 \emph default
8102 Generate code for Small Model programs, see section Memory Models for more
8103  details.
8104  This is the default model.
8105 \end_layout
8106
8107 \begin_layout List
8108 \labelwidthstring 00.00.0000
8109
8110 \series bold
8111 -
8112 \begin_inset ERT
8113 status collapsed
8114
8115 \begin_layout Standard
8116
8117
8118 \backslash
8119 /
8120 \end_layout
8121
8122 \end_inset
8123
8124 -model-medium
8125 \begin_inset LatexCommand \index{-\/-model-medium}
8126
8127 \end_inset
8128
8129
8130 \series default
8131  Generate code for Medium model programs, see section Memory Models for
8132  more details.
8133  If this option is used all source files in the project have to be compiled
8134  with this option.
8135  It must also be used when invoking the linker.
8136 \end_layout
8137
8138 \begin_layout List
8139 \labelwidthstring 00.00.0000
8140
8141 \series bold
8142 -
8143 \begin_inset ERT
8144 status collapsed
8145
8146 \begin_layout Standard
8147
8148
8149 \backslash
8150 /
8151 \end_layout
8152
8153 \end_inset
8154
8155 -model-large
8156 \begin_inset LatexCommand \index{-\/-model-large}
8157
8158 \end_inset
8159
8160
8161 \series default
8162  Generate code for Large model programs, see section Memory Models for more
8163  details.
8164  If this option is used all source files in the project have to be compiled
8165  with this option.
8166  It must also be used when invoking the linker.
8167 \end_layout
8168
8169 \begin_layout List
8170 \labelwidthstring 00.00.0000
8171
8172 \series bold
8173 -
8174 \begin_inset ERT
8175 status collapsed
8176
8177 \begin_layout Standard
8178
8179
8180 \backslash
8181 /
8182 \end_layout
8183
8184 \end_inset
8185
8186 -xstack
8187 \begin_inset LatexCommand \index{-\/-xstack}
8188
8189 \end_inset
8190
8191
8192 \series default
8193  Uses a pseudo stack in the pdata
8194 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8195
8196 \end_inset
8197
8198  area (usually the first 256 bytes in the external ram) for allocating variables
8199  and passing parameters.
8200  See section 
8201 \begin_inset LatexCommand \ref{sub:External-Stack}
8202
8203 \end_inset
8204
8205 \InsetSpace ~
8206  External Stack for more details.
8207 \end_layout
8208
8209 \begin_layout List
8210 \labelwidthstring 00.00.0000
8211
8212 \series bold
8213 -
8214 \begin_inset ERT
8215 status collapsed
8216
8217 \begin_layout Standard
8218
8219
8220 \backslash
8221 /
8222 \end_layout
8223
8224 \end_inset
8225
8226 -iram-size
8227 \series default
8228 \InsetSpace ~
8229 <Value>
8230 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8231
8232 \end_inset
8233
8234  Causes the linker to check if the internal ram usage is within limits of
8235  the given value.
8236 \end_layout
8237
8238 \begin_layout List
8239 \labelwidthstring 00.00.0000
8240
8241 \series bold
8242 -
8243 \begin_inset ERT
8244 status collapsed
8245
8246 \begin_layout Standard
8247
8248
8249 \backslash
8250 /
8251 \end_layout
8252
8253 \end_inset
8254
8255 -xram-size
8256 \series default
8257 \InsetSpace ~
8258 <Value>
8259 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8260
8261 \end_inset
8262
8263  Causes the linker to check if the external ram usage is within limits of
8264  the given value.
8265 \end_layout
8266
8267 \begin_layout List
8268 \labelwidthstring 00.00.0000
8269
8270 \series bold
8271 -
8272 \begin_inset ERT
8273 status collapsed
8274
8275 \begin_layout Standard
8276
8277
8278 \backslash
8279 /
8280 \end_layout
8281
8282 \end_inset
8283
8284 -code-size
8285 \series default
8286 \InsetSpace ~
8287 <Value>
8288 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8289
8290 \end_inset
8291
8292  Causes the linker to check if the code memory usage is within limits of
8293  the given value.
8294 \end_layout
8295
8296 \begin_layout List
8297 \labelwidthstring 00.00.0000
8298
8299 \series bold
8300 -
8301 \begin_inset ERT
8302 status collapsed
8303
8304 \begin_layout Standard
8305
8306
8307 \backslash
8308 /
8309 \end_layout
8310
8311 \end_inset
8312
8313 -stack-size
8314 \series default
8315 \InsetSpace ~
8316 <Value>
8317 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8318
8319 \end_inset
8320
8321  Causes the linker to check if there is at minimum <Value> bytes for stack.
8322 \end_layout
8323
8324 \begin_layout List
8325 \labelwidthstring 00.00.0000
8326
8327 \series bold
8328 -
8329 \begin_inset ERT
8330 status collapsed
8331
8332 \begin_layout Standard
8333
8334
8335 \backslash
8336 /
8337 \end_layout
8338
8339 \end_inset
8340
8341 -pack-iram
8342 \series default
8343 \InsetSpace ~
8344
8345 \begin_inset LatexCommand \index{-\/-pack-iram}
8346
8347 \end_inset
8348
8349  Causes the linker to use unused register banks for data variables and pack
8350  data, idata and stack together.
8351  This is the default now.
8352 \end_layout
8353
8354 \begin_layout List
8355 \labelwidthstring 00.00.0000
8356
8357 \series bold
8358 -
8359 \begin_inset ERT
8360 status collapsed
8361
8362 \begin_layout Standard
8363
8364
8365 \backslash
8366 /
8367 \end_layout
8368
8369 \end_inset
8370
8371 -no-pack-iram
8372 \series default
8373 \InsetSpace ~
8374
8375 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8376
8377 \end_inset
8378
8379  Causes the linker to use old style for allocating memory areas.
8380 \end_layout
8381
8382 \begin_layout List
8383 \labelwidthstring 00.00.0000
8384
8385 \series bold
8386 -
8387 \begin_inset ERT
8388 status collapsed
8389
8390 \begin_layout Standard
8391
8392
8393 \backslash
8394 /
8395 \end_layout
8396
8397 \end_inset
8398
8399 -acall-ajmp
8400 \series default
8401 \InsetSpace ~
8402
8403 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8404
8405 \end_inset
8406
8407  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8408  acall/ajmp.
8409  Only use this option if your code is in the same 2k block of memory.
8410  You may need to use this option for some 8051 derivatives which lack the
8411  lcall/ljmp instructions..
8412 \end_layout
8413
8414 \begin_layout Standard
8415 \begin_inset VSpace bigskip
8416 \end_inset
8417
8418
8419 \end_layout
8420
8421 \begin_layout Subsection
8422 DS390 / DS400 Options
8423 \begin_inset LatexCommand \index{Options DS390}
8424
8425 \end_inset
8426
8427
8428 \begin_inset LatexCommand \index{DS390}
8429
8430 \end_inset
8431
8432
8433 \end_layout
8434
8435 \begin_layout List
8436 \labelwidthstring 00.00.0000
8437
8438 \series bold
8439 -
8440 \begin_inset ERT
8441 status collapsed
8442
8443 \begin_layout Standard
8444
8445
8446 \backslash
8447 /
8448 \end_layout
8449
8450 \end_inset
8451
8452 -model-flat24
8453 \series default
8454
8455 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8456
8457 \end_inset
8458
8459
8460 \size large
8461 \emph on
8462  
8463 \size default
8464 \emph default
8465 Generate 24-bit flat mode code.
8466  This is the one and only that the ds390 code generator supports right now
8467  and is default when using 
8468 \emph on
8469 -mds390
8470 \emph default
8471 .
8472  See section Memory Models for more details.
8473 \end_layout
8474
8475 \begin_layout List
8476 \labelwidthstring 00.00.0000
8477
8478 \series bold
8479 -
8480 \begin_inset ERT
8481 status collapsed
8482
8483 \begin_layout Standard
8484
8485
8486 \backslash
8487 /
8488 \end_layout
8489
8490 \end_inset
8491
8492 -protect-sp-update
8493 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8494
8495 \end_inset
8496
8497
8498 \series default
8499  disable interrupts during ESP:SP updates.
8500 \end_layout
8501
8502 \begin_layout List
8503 \labelwidthstring 00.00.0000
8504
8505 \series bold
8506 -
8507 \begin_inset ERT
8508 status collapsed
8509
8510 \begin_layout Standard
8511
8512
8513 \backslash
8514 /
8515 \end_layout
8516
8517 \end_inset
8518
8519 -stack-10bit
8520 \series default
8521
8522 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8523
8524 \end_inset
8525
8526  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8527  This is the one and only that the ds390 code generator supports right now
8528  and is default when using 
8529 \emph on
8530 -mds390
8531 \emph default
8532 .
8533  In this mode, the stack is located in the lower 1K of the internal RAM,
8534  which is mapped to 0x400000.
8535  Note that the support is incomplete, since it still uses a single byte
8536  as the stack pointer.
8537  This means that only the lower 256 bytes of the potential 1K stack space
8538  will actually be used.
8539  However, this does allow you to reclaim the precious 256 bytes of low RAM
8540  for use for the DATA and IDATA segments.
8541  The compiler will not generate any code to put the processor into 10 bit
8542  stack mode.
8543  It is important to ensure that the processor is in this mode before calling
8544  any re-entrant functions compiled with this option.
8545  In principle, this should work with the 
8546 \emph on
8547 -
8548 \begin_inset ERT
8549 status collapsed
8550
8551 \begin_layout Standard
8552
8553
8554 \backslash
8555 /
8556 \end_layout
8557
8558 \end_inset
8559
8560 -stack-auto
8561 \begin_inset LatexCommand \index{-\/-stack-auto}
8562
8563 \end_inset
8564
8565
8566 \emph default
8567  option, but that has not been tested.
8568  It is incompatible with the 
8569 \emph on
8570 -
8571 \begin_inset ERT
8572 status collapsed
8573
8574 \begin_layout Standard
8575
8576
8577 \backslash
8578 /
8579 \end_layout
8580
8581 \end_inset
8582
8583 -xstack
8584 \begin_inset LatexCommand \index{-\/-xstack}
8585
8586 \end_inset
8587
8588
8589 \emph default
8590  option.
8591  It also only makes sense if the processor is in 24 bit contiguous addressing
8592  mode (see the 
8593 \emph on
8594 -
8595 \begin_inset ERT
8596 status collapsed
8597
8598 \begin_layout Standard
8599
8600
8601 \backslash
8602 /
8603 \end_layout
8604
8605 \end_inset
8606
8607 -model-flat24 option
8608 \emph default
8609 ).
8610 \series bold
8611
8612 \begin_inset Note Note
8613 status collapsed
8614
8615 \begin_layout List
8616 \labelwidthstring 00.00.0000
8617
8618 \series bold
8619 -
8620 \begin_inset ERT
8621 status open
8622
8623 \begin_layout Standard
8624
8625
8626 \backslash
8627 /
8628 \end_layout
8629
8630 \end_inset
8631
8632 -stack-8-bit - switches off the 10-bit mode
8633 \end_layout
8634
8635 \end_inset
8636
8637
8638 \end_layout
8639
8640 \begin_layout List
8641 \labelwidthstring 00.00.0000
8642
8643 \series bold
8644 -
8645 \begin_inset ERT
8646 status collapsed
8647
8648 \begin_layout Standard
8649
8650
8651 \backslash
8652 /
8653 \end_layout
8654
8655 \end_inset
8656
8657 -stack-probe
8658 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8659
8660 \end_inset
8661
8662
8663 \series default
8664  insert call to function __stack_probe at each function prologue.
8665 \end_layout
8666
8667 \begin_layout List
8668 \labelwidthstring 00.00.0000
8669
8670 \series bold
8671 -
8672 \begin_inset ERT
8673 status open
8674
8675 \begin_layout Standard
8676
8677
8678 \backslash
8679 /
8680 \end_layout
8681
8682 \end_inset
8683
8684 -tini-libid
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8686
8687 \end_inset
8688
8689
8690 \series default
8691  <nnnn> LibraryID used in -mTININative.
8692  
8693 \end_layout
8694
8695 \begin_layout List
8696 \labelwidthstring 00.00.0000
8697
8698 \series bold
8699 -
8700 \begin_inset ERT
8701 status collapsed
8702
8703 \begin_layout Standard
8704
8705
8706 \backslash
8707 /
8708 \end_layout
8709
8710 \end_inset
8711
8712 -use-accelerator
8713 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8714
8715 \end_inset
8716
8717
8718 \series default
8719  generate code for DS390 Arithmetic Accelerator.
8720  
8721 \end_layout
8722
8723 \begin_layout Standard
8724 \begin_inset VSpace bigskip
8725 \end_inset
8726
8727
8728 \end_layout
8729
8730 \begin_layout Subsection
8731 Z80 Options
8732 \begin_inset LatexCommand \index{Options Z80}
8733
8734 \end_inset
8735
8736
8737 \begin_inset LatexCommand \index{Z80}
8738
8739 \end_inset
8740
8741
8742 \end_layout
8743
8744 \begin_layout List
8745 \labelwidthstring 00.00.0000
8746
8747 \series bold
8748 -
8749 \begin_inset ERT
8750 status collapsed
8751
8752 \begin_layout Standard
8753
8754
8755 \backslash
8756 /
8757 \end_layout
8758
8759 \end_inset
8760
8761 -callee-saves-bc
8762 \series default
8763
8764 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8765
8766 \end_inset
8767
8768
8769 \size large
8770 \emph on
8771  
8772 \size default
8773 \emph default
8774 Force a called function to always save BC.
8775 \end_layout
8776
8777 \begin_layout List
8778 \labelwidthstring 00.00.0000
8779
8780 \series bold
8781 -
8782 \begin_inset ERT
8783 status collapsed
8784
8785 \begin_layout Standard
8786
8787
8788 \backslash
8789 /
8790 \end_layout
8791
8792 \end_inset
8793
8794 -no-std-crt0
8795 \series default
8796
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8798
8799 \end_inset
8800
8801  When linking, skip the standard crt0.o object file.
8802  You must provide your own crt0.o for your system when linking.
8803 \end_layout
8804
8805 \begin_layout List
8806 \labelwidthstring 00.00.0000
8807
8808 \series bold
8809 -
8810 \begin_inset ERT
8811 status collapsed
8812
8813 \begin_layout Standard
8814
8815
8816 \backslash
8817 /
8818 \end_layout
8819
8820 \end_inset
8821
8822 -portmode=
8823 \series default
8824 <Value>
8825 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8826
8827 \end_inset
8828
8829  Determinate PORT I/O mode (<Value> is z80 or z180).
8830 \end_layout
8831
8832 \begin_layout List
8833 \labelwidthstring 00.00.0000
8834
8835 \series bold
8836 -
8837 \begin_inset ERT
8838 status collapsed
8839
8840 \begin_layout Standard
8841
8842
8843 \backslash
8844 /
8845 \end_layout
8846
8847 \end_inset
8848
8849 -asm=
8850 \series default
8851 <Value>
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8853
8854 \end_inset
8855
8856  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8857 \end_layout
8858
8859 \begin_layout List
8860 \labelwidthstring 00.00.0000
8861
8862 \series bold
8863 -
8864 \begin_inset ERT
8865 status collapsed
8866
8867 \begin_layout Standard
8868
8869
8870 \backslash
8871 /
8872 \end_layout
8873
8874 \end_inset
8875
8876 -codeseg
8877 \series default
8878 \InsetSpace ~
8879 <Value>
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8881
8882 \end_inset
8883
8884  Use <Value> for the code segment name.
8885 \end_layout
8886
8887 \begin_layout List
8888 \labelwidthstring 00.00.0000
8889
8890 \series bold
8891 -
8892 \begin_inset ERT
8893 status collapsed
8894
8895 \begin_layout Standard
8896
8897
8898 \backslash
8899 /
8900 \end_layout
8901
8902 \end_inset
8903
8904 -constseg
8905 \series default
8906 \InsetSpace ~
8907 <Value>
8908 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8909
8910 \end_inset
8911
8912  Use <Value> for the const segment name.
8913 \end_layout
8914
8915 \begin_layout List
8916 \labelwidthstring 00.00.0000
8917 \begin_inset VSpace bigskip
8918 \end_inset
8919
8920
8921 \end_layout
8922
8923 \begin_layout Subsection
8924 GBZ80 Options
8925 \begin_inset LatexCommand \index{Options GBZ80}
8926
8927 \end_inset
8928
8929
8930 \begin_inset LatexCommand \index{GBZ80}
8931
8932 \end_inset
8933
8934
8935 \end_layout
8936
8937 \begin_layout List
8938 \labelwidthstring 00.00.0000
8939
8940 \series bold
8941 -
8942 \begin_inset ERT
8943 status collapsed
8944
8945 \begin_layout Standard
8946
8947
8948 \backslash
8949 /
8950 \end_layout
8951
8952 \end_inset
8953
8954 -callee-saves-bc
8955 \series default
8956
8957 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8958
8959 \end_inset
8960
8961
8962 \size large
8963 \emph on
8964  
8965 \size default
8966 \emph default
8967 Force a called function to always save BC.
8968 \end_layout
8969
8970 \begin_layout List
8971 \labelwidthstring 00.00.0000
8972
8973 \series bold
8974 -bo
8975 \series default
8976 \InsetSpace ~
8977 <Num>
8978 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8979
8980 \end_inset
8981
8982  Use code bank <Num>.
8983 \end_layout
8984
8985 \begin_layout List
8986 \labelwidthstring 00.00.0000
8987
8988 \series bold
8989 -ba
8990 \series default
8991 \InsetSpace ~
8992 <Num>
8993 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8994
8995 \end_inset
8996
8997  Use data bank <Num>.
8998 \end_layout
8999
9000 \begin_layout List
9001 \labelwidthstring 00.00.0000
9002
9003 \series bold
9004 -
9005 \begin_inset ERT
9006 status collapsed
9007
9008 \begin_layout Standard
9009
9010
9011 \backslash
9012 /
9013 \end_layout
9014
9015 \end_inset
9016
9017 -codeseg
9018 \series default
9019 \InsetSpace ~
9020 <Value>
9021 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9022
9023 \end_inset
9024
9025  Use <Value> for the code segment name.
9026 \end_layout
9027
9028 \begin_layout List
9029 \labelwidthstring 00.00.0000
9030
9031 \series bold
9032 -
9033 \begin_inset ERT
9034 status collapsed
9035
9036 \begin_layout Standard
9037
9038
9039 \backslash
9040 /
9041 \end_layout
9042
9043 \end_inset
9044
9045 -constseg
9046 \series default
9047 \InsetSpace ~
9048 <Value>
9049 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9050
9051 \end_inset
9052
9053  Use <Value> for the const segment name.
9054 \end_layout
9055
9056 \begin_layout Standard
9057 \begin_inset VSpace bigskip
9058 \end_inset
9059
9060
9061 \end_layout
9062
9063 \begin_layout Subsection
9064 Optimization Options
9065 \begin_inset LatexCommand \index{Options optimization}
9066
9067 \end_inset
9068
9069
9070 \begin_inset LatexCommand \index{Optimization options}
9071
9072 \end_inset
9073
9074
9075 \end_layout
9076
9077 \begin_layout List
9078 \labelwidthstring 00.00.0000
9079
9080 \series bold
9081 -
9082 \begin_inset ERT
9083 status collapsed
9084
9085 \begin_layout Standard
9086
9087
9088 \backslash
9089 /
9090 \end_layout
9091
9092 \end_inset
9093
9094 -nogcse
9095 \begin_inset LatexCommand \index{-\/-nogcse}
9096
9097 \end_inset
9098
9099
9100 \series default
9101  Will not do global subexpression elimination, this option may be used when
9102  the compiler creates undesirably large stack/data spaces to store compiler
9103  temporaries (
9104 \emph on
9105 s
9106 \emph default
9107 pill 
9108 \emph on
9109 loc
9110 \emph default
9111 ations, sloc
9112 \begin_inset LatexCommand \index{sloc (spill location)}
9113
9114 \end_inset
9115
9116 ).
9117  A warning message will be generated when this happens and the compiler
9118  will indicate the number of extra bytes it allocated.
9119  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9120 nogcse
9121 \begin_inset LatexCommand \index{\#pragma nogcse}
9122
9123 \end_inset
9124
9125  can be used to turn off global subexpression elimination
9126 \begin_inset LatexCommand \index{Subexpression elimination}
9127
9128 \end_inset
9129
9130  for a given function only.
9131 \end_layout
9132
9133 \begin_layout List
9134 \labelwidthstring 00.00.0000
9135
9136 \series bold
9137 -
9138 \begin_inset ERT
9139 status collapsed
9140
9141 \begin_layout Standard
9142
9143
9144 \backslash
9145 /
9146 \end_layout
9147
9148 \end_inset
9149
9150 -noinvariant
9151 \begin_inset LatexCommand \index{-\/-noinvariant}
9152
9153 \end_inset
9154
9155
9156 \series default
9157  Will not do loop invariant optimizations, this may be turned off for reasons
9158  explained for the previous option.
9159  For more details of loop optimizations performed see Loop Invariants in
9160  section 
9161 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9162
9163 \end_inset
9164
9165 .
9166  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9167 noinvariant
9168 \begin_inset LatexCommand \index{\#pragma noinvariant}
9169
9170 \end_inset
9171
9172  can be used to turn off invariant optimizations for a given function only.
9173 \end_layout
9174
9175 \begin_layout List
9176 \labelwidthstring 00.00.0000
9177
9178 \series bold
9179 -
9180 \begin_inset ERT
9181 status collapsed
9182
9183 \begin_layout Standard
9184
9185
9186 \backslash
9187 /
9188 \end_layout
9189
9190 \end_inset
9191
9192 -noinduction
9193 \begin_inset LatexCommand \index{-\/-noinduction}
9194
9195 \end_inset
9196
9197
9198 \series default
9199  Will not do loop induction optimizations, see section strength reduction
9200  for more details.
9201  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9202 noinduction
9203 \begin_inset LatexCommand \index{\#pragma noinduction}
9204
9205 \end_inset
9206
9207  can be used to turn off induction optimizations for a given function only.
9208 \end_layout
9209
9210 \begin_layout List
9211 \labelwidthstring 00.00.0000
9212
9213 \series bold
9214 -
9215 \begin_inset ERT
9216 status collapsed
9217
9218 \begin_layout Standard
9219
9220
9221 \backslash
9222 /
9223 \end_layout
9224
9225 \end_inset
9226
9227 -nojtbound
9228 \begin_inset LatexCommand \index{-\/-nojtbound}
9229
9230 \end_inset
9231
9232
9233 \size large
9234 \bar under
9235  
9236 \series default
9237 \size default
9238 \bar default
9239  Will not generate boundary condition check when switch statements
9240 \begin_inset LatexCommand \index{switch statement}
9241
9242 \end_inset
9243
9244  are implemented using jump-tables.
9245  See section 
9246 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9247
9248 \end_inset
9249
9250 \InsetSpace ~
9251 Switch Statements for more details.
9252  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9253 nojtbound
9254 \begin_inset LatexCommand \index{\#pragma nojtbound}
9255
9256 \end_inset
9257
9258  can be used to turn off boundary checking for jump tables for a given function
9259  only.
9260 \end_layout
9261
9262 \begin_layout List
9263 \labelwidthstring 00.00.0000
9264
9265 \series bold
9266 -
9267 \begin_inset ERT
9268 status collapsed
9269
9270 \begin_layout Standard
9271
9272
9273 \backslash
9274 /
9275 \end_layout
9276
9277 \end_inset
9278
9279 -noloopreverse
9280 \begin_inset LatexCommand \index{-\/-noloopreverse}
9281
9282 \end_inset
9283
9284
9285 \series default
9286 \size large
9287  
9288 \size default
9289 Will not do loop reversal 
9290 \begin_inset LatexCommand \index{Loop reversing}
9291
9292 \end_inset
9293
9294 optimization.
9295 \end_layout
9296
9297 \begin_layout List
9298 \labelwidthstring 00.00.0000
9299 -
9300 \begin_inset ERT
9301 status collapsed
9302
9303 \begin_layout Standard
9304
9305
9306 \backslash
9307 /
9308 \end_layout
9309
9310 \end_inset
9311
9312 -
9313 \series bold
9314 nolabelopt
9315 \series default
9316  
9317 \begin_inset LatexCommand \index{-\/-nolabelopt }
9318
9319 \end_inset
9320
9321 Will not optimize labels (makes the dumpfiles more readable).
9322 \end_layout
9323
9324 \begin_layout List
9325 \labelwidthstring 00.00.0000
9326
9327 \series bold
9328 -
9329 \begin_inset ERT
9330 status collapsed
9331
9332 \begin_layout Standard
9333
9334
9335 \backslash
9336 /
9337 \end_layout
9338
9339 \end_inset
9340
9341 -no-xinit-opt
9342 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9343
9344 \end_inset
9345
9346
9347 \series default
9348  Will not memcpy initialized data from code space into xdata space.
9349  This saves a few bytes in code space if you don't have initialized data
9350 \begin_inset LatexCommand \index{Variable initialization}
9351
9352 \end_inset
9353
9354 .
9355 \end_layout
9356
9357 \begin_layout List
9358 \labelwidthstring 00.00.0000
9359
9360 \series bold
9361 -
9362 \begin_inset ERT
9363 status collapsed
9364
9365 \begin_layout Standard
9366
9367
9368 \backslash
9369 /
9370 \end_layout
9371
9372 \end_inset
9373
9374 -nooverlay
9375 \begin_inset LatexCommand \index{-\/-nooverlay}
9376
9377 \end_inset
9378
9379
9380 \series default
9381   The compiler will not overlay parameters and local variables of any function,
9382  see section Parameters and local variables for more details.
9383 \end_layout
9384
9385 \begin_layout List
9386 \labelwidthstring 00.00.0000
9387
9388 \series bold
9389 -
9390 \begin_inset ERT
9391 status collapsed
9392
9393 \begin_layout Standard
9394
9395
9396 \backslash
9397 /
9398 \end_layout
9399
9400 \end_inset
9401
9402 -no-peep
9403 \begin_inset LatexCommand \index{-\/-no-peep}
9404
9405 \end_inset
9406
9407
9408 \series default
9409  Disable peep-hole optimization with built-in rules.
9410 \end_layout
9411
9412 \begin_layout List
9413 \labelwidthstring 00.00.0000
9414
9415 \series bold
9416 -
9417 \begin_inset ERT
9418 status collapsed
9419
9420 \begin_layout Standard
9421
9422
9423 \backslash
9424 /
9425 \end_layout
9426
9427 \end_inset
9428
9429 -peep-file
9430 \series default
9431
9432 \begin_inset LatexCommand \index{-\/-peep-file}
9433
9434 \end_inset
9435
9436 \InsetSpace ~
9437 <filename> This option can be used to use additional rules to be used by
9438  the peep hole optimizer.
9439  See section 
9440 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9441
9442 \end_inset
9443
9444 \InsetSpace ~
9445 Peep Hole optimizations for details on how to write these rules.
9446 \end_layout
9447
9448 \begin_layout List
9449 \labelwidthstring 00.00.0000
9450
9451 \series bold
9452 -
9453 \begin_inset ERT
9454 status collapsed
9455
9456 \begin_layout Standard
9457
9458
9459 \backslash
9460 /
9461 \end_layout
9462
9463 \end_inset
9464
9465 -peep-asm
9466 \begin_inset LatexCommand \index{-\/-peep-asm}
9467
9468 \end_inset
9469
9470
9471 \series default
9472  Pass the inline assembler code through the peep hole optimizer.
9473  This can cause unexpected changes to inline assembler code, please go through
9474  the peephole optimizer
9475 \begin_inset LatexCommand \index{Peephole optimizer}
9476
9477 \end_inset
9478
9479  rules defined in the source file tree '<target>/peeph.def' before using
9480  this option.
9481 \end_layout
9482
9483 \begin_layout List
9484 \labelwidthstring 00.00.0000
9485
9486 \series bold
9487 -
9488 \begin_inset ERT
9489 status collapsed
9490
9491 \begin_layout Standard
9492
9493
9494 \backslash
9495 /
9496 \end_layout
9497
9498 \end_inset
9499
9500 -opt-code-speed
9501 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9502
9503 \end_inset
9504
9505
9506 \series default
9507  The compiler will optimize code generation towards fast code, possibly
9508  at the expense of code size.
9509 \end_layout
9510
9511 \begin_layout List
9512 \labelwidthstring 00.00.0000
9513
9514 \series bold
9515 -
9516 \begin_inset ERT
9517 status collapsed
9518
9519 \begin_layout Standard
9520
9521
9522 \backslash
9523 /
9524 \end_layout
9525
9526 \end_inset
9527
9528 -opt-code-size
9529 \begin_inset LatexCommand \index{-\/-opt-code-size}
9530
9531 \end_inset
9532
9533
9534 \series default
9535  The compiler will optimize code generation towards compact code, possibly
9536  at the expense of code speed.
9537 \end_layout
9538
9539 \begin_layout Standard
9540 \begin_inset VSpace bigskip
9541 \end_inset
9542
9543
9544 \end_layout
9545
9546 \begin_layout Subsection
9547 Other Options
9548 \begin_inset LatexCommand \index{Options other}
9549
9550 \end_inset
9551
9552
9553 \end_layout
9554
9555 \begin_layout List
9556 \labelwidthstring 00.00.0000
9557
9558 \series bold
9559 -c\InsetSpace ~
9560 -
9561 \begin_inset ERT
9562 status collapsed
9563
9564 \begin_layout Standard
9565
9566
9567 \backslash
9568 /
9569 \end_layout
9570
9571 \end_inset
9572
9573 -compile-only
9574 \begin_inset LatexCommand \index{-\/-compile-only}
9575
9576 \end_inset
9577
9578
9579 \begin_inset LatexCommand \index{-c -\/-compile-only}
9580
9581 \end_inset
9582
9583
9584 \series default
9585  will compile and assemble the source, but will not call the linkage editor.
9586 \end_layout
9587
9588 \begin_layout List
9589 \labelwidthstring 00.00.0000
9590
9591 \series bold
9592 -
9593 \series default
9594
9595 \begin_inset ERT
9596 status collapsed
9597
9598 \begin_layout Standard
9599
9600
9601 \backslash
9602 /
9603 \end_layout
9604
9605 \end_inset
9606
9607
9608 \series bold
9609 -c1mode
9610 \begin_inset LatexCommand \index{-\/-c1mode}
9611
9612 \end_inset
9613
9614
9615 \series default
9616  reads the preprocessed source from standard input and compiles it.
9617  The file name for the assembler output must be specified using the -o option.
9618 \end_layout
9619
9620 \begin_layout List
9621 \labelwidthstring 00.00.0000
9622
9623 \series bold
9624 -E
9625 \begin_inset LatexCommand \index{-E}
9626
9627 \end_inset
9628
9629
9630 \series default
9631  Run only the C preprocessor.
9632  Preprocess all the C source files specified and output the results to standard
9633  output.
9634 \end_layout
9635
9636 \begin_layout List
9637 \labelwidthstring 00.00.0000
9638
9639 \series bold
9640 -o\InsetSpace ~
9641 <path/file>
9642 \begin_inset LatexCommand \index{-o <path/file>}
9643
9644 \end_inset
9645
9646  
9647 \series default
9648 The output path where everything will be placed or the file name used for
9649  all generated output files.
9650  If the parameter is a path, it must have a trailing slash (or backslash
9651  for the Windows binaries) to be recognized as a path.
9652
9653 \emph on
9654  
9655 \emph default
9656 Note for Windows users: if the path contains spaces, it should be surrounded
9657  by quotes.
9658  The trailing backslash should be doubled in order to prevent escaping the
9659  final quote, for example: 
9660 \emph on
9661 -o 
9662 \begin_inset Quotes sld
9663 \end_inset
9664
9665 F:
9666 \backslash
9667 Projects
9668 \backslash
9669 test3
9670 \backslash
9671 output 1
9672 \backslash
9673
9674 \backslash
9675
9676 \begin_inset Quotes srd
9677 \end_inset
9678
9679
9680 \emph default
9681  or put after the final quote, for example: 
9682 \emph on
9683 -o 
9684 \begin_inset Quotes sld
9685 \end_inset
9686
9687 F:
9688 \backslash
9689 Projects
9690 \backslash
9691 test3
9692 \backslash
9693 output 1
9694 \begin_inset Quotes srd
9695 \end_inset
9696
9697
9698 \backslash
9699
9700 \emph default
9701 .
9702  The path using slashes for directory delimiters can be used too, for example:
9703  
9704 \emph on
9705 -o 
9706 \begin_inset Quotes sld
9707 \end_inset
9708
9709 F:/Projects/test3/output 1/
9710 \begin_inset Quotes srd
9711 \end_inset
9712
9713
9714 \emph default
9715 .
9716 \end_layout
9717
9718 \begin_layout List
9719 \labelwidthstring 00.00.0000
9720
9721 \series bold
9722 -
9723 \begin_inset ERT
9724 status collapsed
9725
9726 \begin_layout Standard
9727
9728
9729 \backslash
9730 /
9731 \end_layout
9732
9733 \end_inset
9734
9735 -stack-auto
9736 \begin_inset LatexCommand \index{-\/-stack-auto}
9737
9738 \end_inset
9739
9740
9741 \series default
9742 \size large
9743 \emph on
9744  
9745 \size default
9746 \emph default
9747 All functions in the source file will be compiled as 
9748 \emph on
9749 reentrant
9750 \emph default
9751
9752 \begin_inset LatexCommand \index{reentrant}
9753
9754 \end_inset
9755
9756 , i.e.
9757  the parameters and local variables will be allocated on the stack
9758 \begin_inset LatexCommand \index{stack}
9759
9760 \end_inset
9761
9762 .
9763  See section 
9764 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9765
9766 \end_inset
9767
9768  Parameters and Local Variables for more details.
9769  If this option is used all source files in the project should be compiled
9770  with this option.
9771  It automatically implies -
9772 \series bold
9773
9774 \begin_inset ERT
9775 status open
9776
9777 \begin_layout Standard
9778
9779
9780 \backslash
9781 /
9782 \end_layout
9783
9784 \end_inset
9785
9786
9787 \series default
9788 -int-long-reent and -
9789 \series bold
9790
9791 \begin_inset ERT
9792 status open
9793
9794 \begin_layout Standard
9795
9796
9797 \backslash
9798 /
9799 \end_layout
9800
9801 \end_inset
9802
9803
9804 \series default
9805 -float-reent.
9806  
9807 \end_layout
9808
9809 \begin_layout List
9810 \labelwidthstring 00.00.0000
9811
9812 \series bold
9813 -
9814 \begin_inset ERT
9815 status collapsed
9816
9817 \begin_layout Standard
9818
9819
9820 \backslash
9821 /
9822 \end_layout
9823
9824 \end_inset
9825
9826 -callee-saves
9827 \begin_inset LatexCommand \index{-\/-callee-saves}
9828
9829 \end_inset
9830
9831  
9832 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9833
9834 \end_inset
9835
9836 function1[,function2][,function3]....
9837
9838 \series default
9839  The compiler by default uses a caller saves convention for register saving
9840  across function calls, however this can cause unnecessary register pushing
9841  and popping when calling small functions from larger functions.
9842  This option can be used to switch the register saving convention for the
9843  function names specified.
9844  The compiler will not save registers when calling these functions, no extra
9845  code will be generated at the entry and exit (function prologue
9846 \series bold
9847
9848 \begin_inset LatexCommand \index{function prologue}
9849
9850 \end_inset
9851
9852
9853 \series default
9854  and epilogue
9855 \series bold
9856
9857 \begin_inset LatexCommand \index{function epilogue}
9858
9859 \end_inset
9860
9861
9862 \series default
9863 ) for these functions to save and restore the registers used by these functions,
9864  this can SUBSTANTIALLY reduce code and improve run time performance of
9865  the generated code.
9866  In the future the compiler (with inter procedural analysis) will be able
9867  to determine the appropriate scheme to use for each function call.
9868  DO NOT use this option for built-in functions such as _mulint..., if this
9869  option is used for a library function the appropriate library function
9870  needs to be recompiled with the same option.
9871  If the project consists of multiple source files then all the source file
9872  should be compiled with the same -
9873 \begin_inset ERT
9874 status collapsed
9875
9876 \begin_layout Standard
9877
9878
9879 \backslash
9880 /
9881 \end_layout
9882
9883 \end_inset
9884
9885 -callee-saves option string.
9886  Also see #pragma\InsetSpace ~
9887 callee_saves 
9888 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9889
9890 \end_inset
9891
9892  
9893 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9894
9895 \end_inset
9896
9897 .
9898 \end_layout
9899
9900 \begin_layout List
9901 \labelwidthstring 00.00.0000
9902
9903 \series bold
9904 -
9905 \begin_inset ERT
9906 status collapsed
9907
9908 \begin_layout Standard
9909
9910
9911 \backslash
9912 /
9913 \end_layout
9914
9915 \end_inset
9916
9917 -all-callee-saves
9918 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9919
9920 \end_inset
9921
9922  
9923 \series default
9924 Function of
9925 \series bold
9926  
9927 \series default
9928 -
9929 \begin_inset ERT
9930 status collapsed
9931
9932 \begin_layout Standard
9933
9934
9935 \backslash
9936 /
9937 \end_layout
9938
9939 \end_inset
9940
9941 -callee-saves will be applied to all functions by default.
9942 \end_layout
9943
9944 \begin_layout List
9945 \labelwidthstring 00.00.0000
9946
9947 \series bold
9948 -
9949 \begin_inset ERT
9950 status collapsed
9951
9952 \begin_layout Standard
9953
9954
9955 \backslash
9956 /
9957 \end_layout
9958
9959 \end_inset
9960
9961 -debug
9962 \begin_inset LatexCommand \index{-\/-debug}
9963
9964 \end_inset
9965
9966
9967 \bar under
9968  
9969 \series default
9970 \bar default
9971 When this option is used the compiler will generate debug information.
9972  The debug information collected in a file with .cdb extension can be used
9973  with the SDCDB.
9974  For more information see documentation for SDCDB.
9975  Another file with no extension contains debug information in AOMF or AOMF51
9976 \begin_inset LatexCommand \index{AOMF, AOMF51}
9977
9978 \end_inset
9979
9980  format which is commonly used by third party tools.
9981 \end_layout
9982
9983 \begin_layout List
9984 \labelwidthstring 00.00.0000
9985
9986 \series bold
9987 -S
9988 \begin_inset LatexCommand \index{-S}
9989
9990 \end_inset
9991
9992
9993 \size large
9994 \bar under
9995  
9996 \series default
9997 \size default
9998 \bar default
9999 Stop after the stage of compilation proper; do not assemble.
10000  The output is an assembler code file for the input file specified.
10001 \end_layout
10002
10003 \begin_layout List
10004 \labelwidthstring 00.00.0000
10005
10006 \series bold
10007 -
10008 \begin_inset ERT
10009 status collapsed
10010
10011 \begin_layout Standard
10012
10013
10014 \backslash
10015 /
10016 \end_layout
10017
10018 \end_inset
10019
10020 -int-long-reent
10021 \begin_inset LatexCommand \index{-\/-int-long-reent}
10022
10023 \end_inset
10024
10025
10026 \series default
10027  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10028  Note by default these libraries are compiled as non-reentrant.
10029  See section Installation for more details.
10030 \end_layout
10031
10032 \begin_layout List
10033 \labelwidthstring 00.00.0000
10034
10035 \series bold
10036 -
10037 \begin_inset ERT
10038 status collapsed
10039
10040 \begin_layout Standard
10041
10042
10043 \backslash
10044 /
10045 \end_layout
10046
10047 \end_inset
10048
10049 -cyclomatic
10050 \begin_inset LatexCommand \index{-\/-cyclomatic}
10051
10052 \end_inset
10053
10054
10055 \bar under
10056  
10057 \series default
10058 \bar default
10059 This option will cause the compiler to generate an information message for
10060  each function in the source file.
10061  The message contains some 
10062 \emph on
10063 important
10064 \emph default
10065  information about the function.
10066  The number of edges and nodes the compiler detected in the control flow
10067  graph of the function, and most importantly the 
10068 \emph on
10069 cyclomatic complexity
10070 \begin_inset LatexCommand \index{Cyclomatic complexity}
10071
10072 \end_inset
10073
10074
10075 \emph default
10076  see section on Cyclomatic Complexity for more details.
10077 \end_layout
10078
10079 \begin_layout List
10080 \labelwidthstring 00.00.0000
10081
10082 \series bold
10083 -
10084 \begin_inset ERT
10085 status collapsed
10086
10087 \begin_layout Standard
10088
10089
10090 \backslash
10091 /
10092 \end_layout
10093
10094 \end_inset
10095
10096 -float-reent
10097 \begin_inset LatexCommand \index{-\/-float-reent}
10098
10099 \end_inset
10100
10101
10102 \series default
10103  Floating point library is compiled as reentrant
10104 \begin_inset LatexCommand \index{reentrant}
10105
10106 \end_inset
10107
10108 .
10109  See section Installation for more details.
10110 \end_layout
10111
10112 \begin_layout List
10113 \labelwidthstring 00.00.0000
10114
10115 \series bold
10116 -
10117 \begin_inset ERT
10118 status collapsed
10119
10120 \begin_layout Standard
10121
10122
10123 \backslash
10124 /
10125 \end_layout
10126
10127 \end_inset
10128
10129 -funsigned-char
10130 \begin_inset LatexCommand \index{-\/-funsigned-char}
10131
10132 \end_inset
10133
10134
10135 \series default
10136  The default signedness for every type is
10137 \family typewriter
10138  signed
10139 \family default
10140 .
10141  In some embedded environments the default signedness of
10142 \family typewriter
10143  char
10144 \family default
10145  is
10146 \family typewriter
10147  unsigned
10148 \family default
10149 .
10150  To set the signess for characters to unsigned, use the option -
10151 \series bold
10152
10153 \begin_inset ERT
10154 status open
10155
10156 \begin_layout Standard
10157
10158
10159 \backslash
10160 /
10161 \end_layout
10162
10163 \end_inset
10164
10165
10166 \series default
10167 -funsigned-char.
10168  If this option is set and no signedness keyword (unsigned/signed) is given,
10169  a char will be signed.
10170  All other types are unaffected.
10171 \end_layout
10172
10173 \begin_layout List
10174 \labelwidthstring 00.00.0000
10175
10176 \series bold
10177 -
10178 \begin_inset ERT
10179 status collapsed
10180
10181 \begin_layout Standard
10182
10183
10184 \backslash
10185 /
10186 \end_layout
10187
10188 \end_inset
10189
10190 -main-return
10191 \begin_inset LatexCommand \index{-\/-main-return}
10192
10193 \end_inset
10194
10195
10196 \series default
10197  This option can be used if the code generated is called by a monitor program
10198  or if the main routine includes an endless loop.
10199  This option results in slightly smaller code and saves two bytes of stack
10200  space.
10201  The return from the 'main'
10202 \begin_inset LatexCommand \index{main return}
10203
10204 \end_inset
10205
10206  function will return to the function calling main.
10207  The default setting is to lock up i.e.
10208  generate a '
10209 \family typewriter
10210 sjmp .
10211 \family default
10212 '.
10213 \end_layout
10214
10215 \begin_layout List
10216 \labelwidthstring 00.00.0000
10217
10218 \series bold
10219 -
10220 \begin_inset ERT
10221 status collapsed
10222
10223 \begin_layout Standard
10224
10225
10226 \backslash
10227 /
10228 \end_layout
10229
10230 \end_inset
10231
10232 -nostdinc
10233 \begin_inset LatexCommand \index{-\/-nostdinc}
10234
10235 \end_inset
10236
10237
10238 \series default
10239  This will prevent the compiler from passing on the default include path
10240  to the preprocessor.
10241 \end_layout
10242
10243 \begin_layout List
10244 \labelwidthstring 00.00.0000
10245
10246 \series bold
10247 -
10248 \begin_inset ERT
10249 status collapsed
10250
10251 \begin_layout Standard
10252
10253
10254 \backslash
10255 /
10256 \end_layout
10257
10258 \end_inset
10259
10260 -nostdlib
10261 \begin_inset LatexCommand \index{-\/-nostdlib}
10262
10263 \end_inset
10264
10265
10266 \series default
10267  This will prevent the compiler from passing on the default library
10268 \begin_inset LatexCommand \index{Libraries}
10269
10270 \end_inset
10271
10272  path to the linker.
10273 \end_layout
10274
10275 \begin_layout List
10276 \labelwidthstring 00.00.0000
10277
10278 \series bold
10279 -
10280 \begin_inset ERT
10281 status collapsed
10282
10283 \begin_layout Standard
10284
10285
10286 \backslash
10287 /
10288 \end_layout
10289
10290 \end_inset
10291
10292 -verbose
10293 \begin_inset LatexCommand \index{-\/-verbose}
10294
10295 \end_inset
10296
10297
10298 \series default
10299  Shows the various actions the compiler is performing.
10300 \end_layout
10301
10302 \begin_layout List
10303 \labelwidthstring 00.00.0000
10304
10305 \series bold
10306 -V
10307 \begin_inset LatexCommand \index{-V}
10308
10309 \end_inset
10310
10311
10312 \series default
10313  Shows the actual commands the compiler is executing.
10314 \end_layout
10315
10316 \begin_layout List
10317 \labelwidthstring 00.00.0000
10318
10319 \series bold
10320 -
10321 \begin_inset ERT
10322 status collapsed
10323
10324 \begin_layout Standard
10325
10326
10327 \backslash
10328 /
10329 \end_layout
10330
10331 \end_inset
10332
10333 -no-c-code-in-asm
10334 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10335
10336 \end_inset
10337
10338
10339 \series default
10340  Hides your ugly and inefficient c-code from the asm file, so you can always
10341  blame the compiler :)
10342 \end_layout
10343
10344 \begin_layout List
10345 \labelwidthstring 00.00.0000
10346
10347 \series bold
10348 -
10349 \begin_inset ERT
10350 status collapsed
10351
10352 \begin_layout Standard
10353
10354
10355 \backslash
10356 /
10357 \end_layout
10358
10359 \end_inset
10360
10361 -fverbose-asm
10362 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10363
10364 \end_inset
10365
10366
10367 \series default
10368  Include code generator and peep-hole comments in the generated asm files.
10369 \end_layout
10370
10371 \begin_layout List
10372 \labelwidthstring 00.00.0000
10373
10374 \series bold
10375 -
10376 \begin_inset ERT
10377 status collapsed
10378
10379 \begin_layout Standard
10380
10381
10382 \backslash
10383 /
10384 \end_layout
10385
10386 \end_inset
10387
10388 -no-peep-comments
10389 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10390
10391 \end_inset
10392
10393
10394 \series default
10395  Don't include peep-hole comments in the generated asm files even if -
10396 \series bold
10397
10398 \begin_inset ERT
10399 status open
10400
10401 \begin_layout Standard
10402
10403
10404 \backslash
10405 /
10406 \end_layout
10407
10408 \end_inset
10409
10410
10411 \series default
10412 -fverbose-asm option is specified.
10413 \end_layout
10414
10415 \begin_layout List
10416 \labelwidthstring 00.00.0000
10417
10418 \series bold
10419 -
10420 \begin_inset ERT
10421 status collapsed
10422
10423 \begin_layout Standard
10424
10425
10426 \backslash
10427 /
10428 \end_layout
10429
10430 \end_inset
10431
10432 -i-code-in-asm
10433 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10434
10435 \end_inset
10436
10437
10438 \series default
10439  Include i-codes in the asm file.
10440  Sounds like noise but is most helpful for debugging the compiler itself.
10441 \end_layout
10442
10443 \begin_layout List
10444 \labelwidthstring 00.00.0000
10445
10446 \series bold
10447 -
10448 \begin_inset ERT
10449 status collapsed
10450
10451 \begin_layout Standard
10452
10453
10454 \backslash
10455 /
10456 \end_layout
10457
10458 \end_inset
10459
10460 -less-pedantic
10461 \begin_inset LatexCommand \index{pedantic}
10462
10463 \end_inset
10464
10465
10466 \begin_inset LatexCommand \index{-\/-less-pedantic}
10467
10468 \end_inset
10469
10470
10471 \series default
10472
10473 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10474
10475 \end_inset
10476
10477  Disable some of the more pedantic warnings
10478 \begin_inset LatexCommand \index{Warnings}
10479
10480 \end_inset
10481
10482 .
10483  For more details, see the less_pedantic pragma 
10484 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10485
10486 \end_inset
10487
10488 .
10489 \end_layout
10490
10491 \begin_layout List
10492 \labelwidthstring 00.00.0000
10493
10494 \series bold
10495 -
10496 \begin_inset ERT
10497 status collapsed
10498
10499 \begin_layout Standard
10500
10501
10502 \backslash
10503 /
10504 \end_layout
10505
10506 \end_inset
10507
10508 -disable-warning\InsetSpace ~
10509 <nnnn>
10510 \begin_inset LatexCommand \index{-\/-disable-warning}
10511
10512 \end_inset
10513
10514
10515 \series default
10516  Disable specific warning with number <nnnn>.
10517 \end_layout
10518
10519 \begin_layout List
10520 \labelwidthstring 00.00.0000
10521
10522 \series bold
10523 -
10524 \begin_inset ERT
10525 status collapsed
10526
10527 \begin_layout Standard
10528
10529
10530 \backslash
10531 /
10532 \end_layout
10533
10534 \end_inset
10535
10536 -Werror
10537 \begin_inset LatexCommand \index{-\/-Werror}
10538
10539 \end_inset
10540
10541
10542 \series default
10543  Treat all warnings as errors.
10544 \end_layout
10545
10546 \begin_layout List
10547 \labelwidthstring 00.00.0000
10548
10549 \series bold
10550 -
10551 \begin_inset ERT
10552 status collapsed
10553
10554 \begin_layout Standard
10555
10556
10557 \backslash
10558 /
10559 \end_layout
10560
10561 \end_inset
10562
10563 -print-search-dirs
10564 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10565
10566 \end_inset
10567
10568
10569 \series default
10570  Display the directories in the compiler's search path
10571 \end_layout
10572
10573 \begin_layout List
10574 \labelwidthstring 00.00.0000
10575
10576 \series bold
10577 -
10578 \begin_inset ERT
10579 status collapsed
10580
10581 \begin_layout Standard
10582
10583
10584 \backslash
10585 /
10586 \end_layout
10587
10588 \end_inset
10589
10590 -vc
10591 \begin_inset LatexCommand \index{-\/-vc}
10592
10593 \end_inset
10594
10595
10596 \series default
10597  Display errors and warnings using MSVC style, so you can use SDCC with
10598  the visual studio IDE
10599 \begin_inset LatexCommand \index{IDE}
10600
10601 \end_inset
10602
10603 .
10604  With SDCC both offering a GCC-like (the default) and a MSVC-like
10605 \begin_inset LatexCommand \index{MSVC output style}
10606
10607 \end_inset
10608
10609  output style, integration into most programming editors should be straightforwa
10610 rd.
10611 \end_layout
10612
10613 \begin_layout List
10614 \labelwidthstring 00.00.0000
10615
10616 \series bold
10617 -
10618 \begin_inset ERT
10619 status collapsed
10620
10621 \begin_layout Standard
10622
10623
10624 \backslash
10625 /
10626 \end_layout
10627
10628 \end_inset
10629
10630 -use-stdout
10631 \begin_inset LatexCommand \index{-\/-use-stdout}
10632
10633 \end_inset
10634
10635
10636 \series default
10637  Send errors and warnings to stdout instead of stderr.
10638 \end_layout
10639
10640 \begin_layout List
10641 \labelwidthstring 00.00.0000
10642
10643 \series bold
10644 -Wa\InsetSpace ~
10645 asmOption[,asmOption]
10646 \series default
10647
10648 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10649
10650 \end_inset
10651
10652 ...
10653  Pass the asmOption to the assembler
10654 \begin_inset LatexCommand \index{Options assembler}
10655
10656 \end_inset
10657
10658
10659 \begin_inset LatexCommand \index{Assembler options}
10660
10661 \end_inset
10662
10663 .
10664  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10665 \end_layout
10666
10667 \begin_layout List
10668 \labelwidthstring 00.00.0000
10669
10670 \series bold
10671 -
10672 \begin_inset ERT
10673 status collapsed
10674
10675 \begin_layout Standard
10676
10677
10678 \backslash
10679 /
10680 \end_layout
10681
10682 \end_inset
10683
10684 -std-sdcc89
10685 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10686
10687 \end_inset
10688
10689
10690 \series default
10691  Generally follow the C89 standard, but allow SDCC features that conflict
10692  with the standard (default).
10693 \end_layout
10694
10695 \begin_layout List
10696 \labelwidthstring 00.00.0000
10697
10698 \series bold
10699 -
10700 \begin_inset ERT
10701 status collapsed
10702
10703 \begin_layout Standard
10704
10705
10706 \backslash
10707 /
10708 \end_layout
10709
10710 \end_inset
10711
10712 -std-c89
10713 \begin_inset LatexCommand \index{-\/-std-c89}
10714
10715 \end_inset
10716
10717
10718 \series default
10719  Follow the C89 standard and disable SDCC features that conflict with the
10720  standard.
10721 \end_layout
10722
10723 \begin_layout List
10724 \labelwidthstring 00.00.0000
10725
10726 \series bold
10727 -
10728 \begin_inset ERT
10729 status collapsed
10730
10731 \begin_layout Standard
10732
10733
10734 \backslash
10735 /
10736 \end_layout
10737
10738 \end_inset
10739
10740 -std-sdcc99
10741 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10742
10743 \end_inset
10744
10745
10746 \series default
10747  Generally follow the C99 standard, but allow SDCC features that conflict
10748  with the standard (incomplete support).
10749 \end_layout
10750
10751 \begin_layout List
10752 \labelwidthstring 00.00.0000
10753
10754 \series bold
10755 -
10756 \begin_inset ERT
10757 status collapsed
10758
10759 \begin_layout Standard
10760
10761
10762 \backslash
10763 /
10764 \end_layout
10765
10766 \end_inset
10767
10768 -std-c99
10769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10770
10771 \end_inset
10772
10773
10774 \series default
10775  Follow the C99 standard and disable SDCC features that conflict with the
10776  standard (incomplete support).
10777 \end_layout
10778
10779 \begin_layout List
10780 \labelwidthstring 00.00.0000
10781
10782 \series bold
10783 -
10784 \begin_inset ERT
10785 status collapsed
10786
10787 \begin_layout Standard
10788
10789
10790 \backslash
10791 /
10792 \end_layout
10793
10794 \end_inset
10795
10796 -codeseg
10797 \series default
10798
10799 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10800
10801 \end_inset
10802
10803 \InsetSpace ~
10804 <Name> The name to be used for the code
10805 \begin_inset LatexCommand \index{code}
10806
10807 \end_inset
10808
10809  segment, default CSEG.
10810  This is useful if you need to tell the compiler to put the code in a special
10811  segment so you can later on tell the linker to put this segment in a special
10812  place in memory.
10813  Can be used for instance when using bank switching to put the code in a
10814  bank.
10815 \end_layout
10816
10817 \begin_layout List
10818 \labelwidthstring 00.00.0000
10819
10820 \series bold
10821 -
10822 \begin_inset ERT
10823 status collapsed
10824
10825 \begin_layout Standard
10826
10827
10828 \backslash
10829 /
10830 \end_layout
10831
10832 \end_inset
10833
10834 -constseg
10835 \series default
10836
10837 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10838
10839 \end_inset
10840
10841 \InsetSpace ~
10842 <Name> The name to be used for the const
10843 \begin_inset LatexCommand \index{const}
10844
10845 \end_inset
10846
10847  segment, default CONST.
10848  This is useful if you need to tell the compiler to put the const data in
10849  a special segment so you can later on tell the linker to put this segment
10850  in a special place in memory.
10851  Can be used for instance when using bank switching to put the const data
10852  in a bank.
10853 \end_layout
10854
10855 \begin_layout List
10856 \labelwidthstring 00.00.0000
10857
10858 \series bold
10859 -
10860 \begin_inset ERT
10861 status collapsed
10862
10863 \begin_layout Standard
10864
10865
10866 \backslash
10867 /
10868 \end_layout
10869
10870 \end_inset
10871
10872 -fdollars-in-identifiers
10873 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10874
10875 \end_inset
10876
10877
10878 \series default
10879  Permit '$' as an identifier character.
10880 \end_layout
10881
10882 \begin_layout List
10883 \labelwidthstring 00.00.0000
10884
10885 \series bold
10886 -
10887 \begin_inset ERT
10888 status collapsed
10889
10890 \begin_layout Standard
10891
10892
10893 \backslash
10894 /
10895 \end_layout
10896
10897 \end_inset
10898
10899 -more-pedantic
10900 \series default
10901
10902 \begin_inset LatexCommand \index{-\/-more-pedantic}
10903
10904 \end_inset
10905
10906
10907 \begin_inset LatexCommand \index{pedantic}
10908
10909 \end_inset
10910
10911  Actually this is 
10912 \series bold
10913 \emph on
10914 not
10915 \series default
10916 \emph default
10917  a SDCC compiler option but if you want 
10918 \emph on
10919 more
10920 \emph default
10921  warnings you can use a separate tool dedicated to syntax checking like
10922  splint
10923 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10924
10925 \end_inset
10926
10927
10928 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10929
10930 \end_inset
10931
10932  
10933 \begin_inset LatexCommand \url{http://www.splint.org}
10934
10935 \end_inset
10936
10937 .
10938  To make your source files parseable by splint you will have to include
10939  
10940 \family sans
10941 lint.h
10942 \family default
10943
10944 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10945
10946 \end_inset
10947
10948  in your source file and add brackets around extended keywords (like 
10949 \family sans
10950
10951 \begin_inset Quotes sld
10952 \end_inset
10953
10954 __at\InsetSpace ~
10955
10956 \series bold
10957 (
10958 \series default
10959 0xab
10960 \series bold
10961 )
10962 \series default
10963
10964 \begin_inset Quotes srd
10965 \end_inset
10966
10967
10968 \family default
10969  and 
10970 \family sans
10971
10972 \begin_inset Quotes sld
10973 \end_inset
10974
10975 __interrupt\InsetSpace ~
10976 (2)
10977 \begin_inset Quotes srd
10978 \end_inset
10979
10980
10981 \family default
10982 ).
10983  
10984 \newline
10985 Splint has an excellent on line manual at 
10986 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10987
10988 \end_inset
10989
10990  and it's capabilities go beyond pure syntax checking.
10991  You'll need to tell splint the location of SDCC's include files so a typical
10992  command line could look like this: 
10993 \newline
10994
10995 \family sans
10996 splint\InsetSpace ~
10997 -I\InsetSpace ~
10998 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10999 \InsetSpace ~
11000 myprogram.c
11001 \end_layout
11002
11003 \begin_layout List
11004 \labelwidthstring 00.00.0000
11005
11006 \series bold
11007 -
11008 \begin_inset ERT
11009 status collapsed
11010
11011 \begin_layout Standard
11012
11013
11014 \backslash
11015 /
11016 \end_layout
11017
11018 \end_inset
11019
11020 -short-is-8bits
11021 \series default
11022
11023 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11024
11025 \end_inset
11026
11027
11028 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11029
11030 \end_inset
11031
11032  Treat short as 8-bit (for backward compatibility with older versions of
11033  compiler - see section 
11034 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11035
11036 \end_inset
11037
11038 )
11039 \end_layout
11040
11041 \begin_layout Standard
11042 \begin_inset VSpace bigskip
11043 \end_inset
11044
11045
11046 \end_layout
11047
11048 \begin_layout Subsection
11049 Intermediate Dump Options
11050 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11051
11052 \end_inset
11053
11054
11055 \begin_inset LatexCommand \index{Options intermediate dump}
11056
11057 \end_inset
11058
11059
11060 \begin_inset LatexCommand \index{Intermediate dump options}
11061
11062 \end_inset
11063
11064
11065 \end_layout
11066
11067 \begin_layout Standard
11068 The following options are provided for the purpose of retargetting and debugging
11069  the compiler.
11070  They provide a means to dump the intermediate code (iCode
11071 \begin_inset LatexCommand \index{iCode}
11072
11073 \end_inset
11074
11075 ) generated by the compiler in human readable form at various stages of
11076  the compilation process.
11077  More on iCodes see chapter 
11078 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11079
11080 \end_inset
11081
11082  
11083 \begin_inset Quotes srd
11084 \end_inset
11085
11086 The anatomy of the compiler
11087 \begin_inset Quotes srd
11088 \end_inset
11089
11090 .
11091 \end_layout
11092
11093 \begin_layout List
11094 \labelwidthstring 00.00.0000
11095
11096 \series bold
11097 -
11098 \begin_inset ERT
11099 status collapsed
11100
11101 \begin_layout Standard
11102
11103
11104 \backslash
11105 /
11106 \end_layout
11107
11108 \end_inset
11109
11110 -dumpraw
11111 \begin_inset LatexCommand \index{-\/-dumpraw}
11112
11113 \end_inset
11114
11115
11116 \series default
11117  This option will cause the compiler to dump the intermediate code into
11118  a file of named 
11119 \emph on
11120 <source filename>.dumpraw
11121 \emph default
11122  just after the intermediate code has been generated for a function, i.e.
11123  before any optimizations are done.
11124  The basic blocks
11125 \begin_inset LatexCommand \index{Basic blocks}
11126
11127 \end_inset
11128
11129  at this stage ordered in the depth first number, so they may not be in
11130  sequence of execution.
11131 \end_layout
11132
11133 \begin_layout List
11134 \labelwidthstring 00.00.0000
11135
11136 \series bold
11137 -
11138 \begin_inset ERT
11139 status collapsed
11140
11141 \begin_layout Standard
11142
11143
11144 \backslash
11145 /
11146 \end_layout
11147
11148 \end_inset
11149
11150 -dumpgcse
11151 \begin_inset LatexCommand \index{-\/-dumpgcse}
11152
11153 \end_inset
11154
11155
11156 \series default
11157  Will create a dump of iCodes, after global subexpression elimination
11158 \begin_inset LatexCommand \index{Global subexpression elimination}
11159
11160 \end_inset
11161
11162 , into a file named 
11163 \emph on
11164 <source filename>.dumpgcse.
11165 \end_layout
11166
11167 \begin_layout List
11168 \labelwidthstring 00.00.0000
11169
11170 \series bold
11171 -
11172 \begin_inset ERT
11173 status collapsed
11174
11175 \begin_layout Standard
11176
11177
11178 \backslash
11179 /
11180 \end_layout
11181
11182 \end_inset
11183
11184 -dumpdeadcode
11185 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11186
11187 \end_inset
11188
11189
11190 \series default
11191  Will create a dump of iCodes, after deadcode elimination
11192 \begin_inset LatexCommand \index{Dead-code elimination}
11193
11194 \end_inset
11195
11196 , into a file named 
11197 \emph on
11198 <source filename>.dumpdeadcode.
11199 \end_layout
11200
11201 \begin_layout List
11202 \labelwidthstring 00.00.0000
11203
11204 \series bold
11205 -
11206 \begin_inset ERT
11207 status collapsed
11208
11209 \begin_layout Standard
11210
11211
11212 \backslash
11213 /
11214 \end_layout
11215
11216 \end_inset
11217
11218 -dumploop
11219 \begin_inset LatexCommand \index{-\/-dumploop}
11220
11221 \end_inset
11222
11223
11224 \series default
11225 \size large
11226  
11227 \size default
11228 Will create a dump of iCodes, after loop optimizations
11229 \begin_inset LatexCommand \index{Loop optimization}
11230
11231 \end_inset
11232
11233 , into a file named 
11234 \emph on
11235 <source filename>.dumploop.
11236 \end_layout
11237
11238 \begin_layout List
11239 \labelwidthstring 00.00.0000
11240
11241 \series bold
11242 -
11243 \begin_inset ERT
11244 status collapsed
11245
11246 \begin_layout Standard
11247
11248
11249 \backslash
11250 /
11251 \end_layout
11252
11253 \end_inset
11254
11255 -dumprange
11256 \begin_inset LatexCommand \index{-\/-dumprange}
11257
11258 \end_inset
11259
11260
11261 \series default
11262 \size large
11263  
11264 \size default
11265 Will create a dump of iCodes, after live range analysis
11266 \begin_inset LatexCommand \index{Live range analysis}
11267
11268 \end_inset
11269
11270 , into a file named 
11271 \emph on
11272 <source filename>.dumprange.
11273 \end_layout
11274
11275 \begin_layout List
11276 \labelwidthstring 00.00.0000
11277
11278 \series bold
11279 -
11280 \begin_inset ERT
11281 status collapsed
11282
11283 \begin_layout Standard
11284
11285
11286 \backslash
11287 /
11288 \end_layout
11289
11290 \end_inset
11291
11292 -dumlrange
11293 \begin_inset LatexCommand \index{-\/-dumlrange}
11294
11295 \end_inset
11296
11297
11298 \series default
11299  Will dump the life ranges
11300 \begin_inset LatexCommand \index{Live range analysis}
11301
11302 \end_inset
11303
11304  for all symbols.
11305 \end_layout
11306
11307 \begin_layout List
11308 \labelwidthstring 00.00.0000
11309
11310 \series bold
11311 -
11312 \begin_inset ERT
11313 status collapsed
11314
11315 \begin_layout Standard
11316
11317
11318 \backslash
11319 /
11320 \end_layout
11321
11322 \end_inset
11323
11324 -dumpregassign
11325 \begin_inset LatexCommand \index{-\/-dumpregassign}
11326
11327 \end_inset
11328
11329
11330 \bar under
11331  
11332 \series default
11333 \bar default
11334 Will create a dump of iCodes, after register assignment
11335 \begin_inset LatexCommand \index{Register assignment}
11336
11337 \end_inset
11338
11339 , into a file named 
11340 \emph on
11341 <source filename>.dumprassgn.
11342 \end_layout
11343
11344 \begin_layout List
11345 \labelwidthstring 00.00.0000
11346
11347 \series bold
11348 -
11349 \begin_inset ERT
11350 status collapsed
11351
11352 \begin_layout Standard
11353
11354
11355 \backslash
11356 /
11357 \end_layout
11358
11359 \end_inset
11360
11361 -dumplrange
11362 \begin_inset LatexCommand \index{-\/-dumplrange}
11363
11364 \end_inset
11365
11366
11367 \series default
11368  Will create a dump of the live ranges of iTemp's
11369 \end_layout
11370
11371 \begin_layout List
11372 \labelwidthstring 00.00.0000
11373
11374 \series bold
11375 -
11376 \begin_inset ERT
11377 status collapsed
11378
11379 \begin_layout Standard
11380
11381
11382 \backslash
11383 /
11384 \end_layout
11385
11386 \end_inset
11387
11388 -dumpall
11389 \begin_inset LatexCommand \index{-\/-dumpall}
11390
11391 \end_inset
11392
11393
11394 \size large
11395 \bar under
11396  
11397 \series default
11398 \size default
11399 \bar default
11400 Will cause all the above mentioned dumps to be created.
11401 \end_layout
11402
11403 \begin_layout Standard
11404 \begin_inset VSpace bigskip
11405 \end_inset
11406
11407
11408 \end_layout
11409
11410 \begin_layout Subsection
11411 Redirecting output on Windows Shells
11412 \end_layout
11413
11414 \begin_layout Standard
11415 By default SDCC writes its error messages to 
11416 \begin_inset Quotes sld
11417 \end_inset
11418
11419 standard error
11420 \begin_inset Quotes srd
11421 \end_inset
11422
11423 .
11424  To force all messages to 
11425 \begin_inset Quotes sld
11426 \end_inset
11427
11428 standard output
11429 \begin_inset Quotes srd
11430 \end_inset
11431
11432  use 
11433 \series bold
11434 -
11435 \series default
11436 \emph on
11437
11438 \begin_inset ERT
11439 status collapsed
11440
11441 \begin_layout Standard
11442
11443
11444 \backslash
11445 /
11446 \end_layout
11447
11448 \end_inset
11449
11450
11451 \series bold
11452 \emph default
11453 -
11454 \series default
11455 use-stdout
11456 \begin_inset LatexCommand \index{-\/-use-stdout}
11457
11458 \end_inset
11459
11460 .
11461  Additionally, if you happen to have visual studio installed in your windows
11462  machine, you can use it to compile your sources using a custom build and
11463  the SDCC -
11464 \emph on
11465
11466 \begin_inset ERT
11467 status collapsed
11468
11469 \begin_layout Standard
11470
11471
11472 \backslash
11473 /
11474 \end_layout
11475
11476 \end_inset
11477
11478
11479 \emph default
11480 -vc
11481 \begin_inset LatexCommand \index{-\/-vc}
11482
11483 \end_inset
11484
11485  option.
11486  Something like this should work:
11487 \newline
11488
11489 \newline
11490
11491 \series bold
11492 c:
11493 \backslash
11494 sdcc
11495 \backslash
11496 bin
11497 \backslash
11498 sdcc.exe -
11499 \series default
11500 \emph on
11501
11502 \begin_inset ERT
11503 status collapsed
11504
11505 \begin_layout Standard
11506
11507
11508 \backslash
11509 /
11510 \end_layout
11511
11512 \end_inset
11513
11514
11515 \series bold
11516 \emph default
11517 -vc -
11518 \series default
11519 \emph on
11520
11521 \begin_inset ERT
11522 status collapsed
11523
11524 \begin_layout Standard
11525
11526
11527 \backslash
11528 /
11529 \end_layout
11530
11531 \end_inset
11532
11533
11534 \series bold
11535 \emph default
11536 -model-large -c $(InputPath)
11537 \series default
11538
11539 \begin_inset VSpace bigskip
11540 \end_inset
11541
11542
11543 \end_layout
11544
11545 \begin_layout Section
11546 Environment variables
11547 \begin_inset LatexCommand \index{Environment variables}
11548
11549 \end_inset
11550
11551
11552 \end_layout
11553
11554 \begin_layout Standard
11555 SDCC recognizes the following environment variables:
11556 \end_layout
11557
11558 \begin_layout List
11559 \labelwidthstring 00.00.0000
11560
11561 \series bold
11562 SDCC_LEAVE_SIGNALS
11563 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11564
11565 \end_inset
11566
11567
11568 \series default
11569  SDCC installs a signal handler
11570 \begin_inset LatexCommand \index{signal handler}
11571
11572 \end_inset
11573
11574  to be able to delete temporary files after an user break (^C) or an exception.
11575  If this environment variable is set, SDCC won't install the signal handler
11576  in order to be able to debug SDCC.
11577 \end_layout
11578
11579 \begin_layout List
11580 \labelwidthstring 00.00.0000
11581
11582 \series bold
11583 TMP,\InsetSpace ~
11584 TEMP,\InsetSpace ~
11585 TMPDIR
11586 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11587
11588 \end_inset
11589
11590
11591 \series default
11592  Path, where temporary files will be created.
11593  The order of the variables is the search order.
11594  In a standard *nix environment these variables are not set, and there's
11595  no need to set them.
11596  On Windows it's recommended to set one of them.
11597 \end_layout
11598
11599 \begin_layout List
11600 \labelwidthstring 00.00.0000
11601
11602 \series bold
11603 SDCC_HOME
11604 \begin_inset LatexCommand \index{SDCC\_HOME}
11605
11606 \end_inset
11607
11608
11609 \series default
11610  Path, see section 
11611 \begin_inset LatexCommand \ref{sub:Install-paths}
11612
11613 \end_inset
11614
11615 \InsetSpace ~
11616
11617 \begin_inset Quotes sld
11618 \end_inset
11619
11620  Install Paths
11621 \begin_inset Quotes srd
11622 \end_inset
11623
11624 .
11625 \end_layout
11626
11627 \begin_layout List
11628 \labelwidthstring 00.00.0000
11629
11630 \series bold
11631 SDCC_INCLUDE
11632 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11633
11634 \end_inset
11635
11636
11637 \series default
11638  Path, see section 
11639 \begin_inset LatexCommand \ref{sub:Search-Paths}
11640
11641 \end_inset
11642
11643 \InsetSpace ~
11644
11645 \begin_inset Quotes sld
11646 \end_inset
11647
11648 Search Paths
11649 \begin_inset Quotes srd
11650 \end_inset
11651
11652 .
11653 \end_layout
11654
11655 \begin_layout List
11656 \labelwidthstring 00.00.0000
11657
11658 \series bold
11659 SDCC_LIB
11660 \begin_inset LatexCommand \index{SDCC\_LIB}
11661
11662 \end_inset
11663
11664
11665 \series default
11666  Path, see section 
11667 \begin_inset LatexCommand \ref{sub:Search-Paths}
11668
11669 \end_inset
11670
11671 \InsetSpace ~
11672
11673 \begin_inset Quotes sld
11674 \end_inset
11675
11676 Search Paths
11677 \begin_inset Quotes srd
11678 \end_inset
11679
11680 ..
11681 \end_layout
11682
11683 \begin_layout Standard
11684 There are some more environment variables recognized by SDCC, but these
11685  are solely used for debugging purposes.
11686  They can change or disappear very quickly, and will never be documented.
11687 \begin_inset VSpace bigskip
11688 \end_inset
11689
11690
11691 \end_layout
11692
11693 \begin_layout Section
11694 Storage Class Language Extensions
11695 \end_layout
11696
11697 \begin_layout Subsection
11698 MCS51/DS390 Storage Class
11699 \begin_inset LatexCommand \index{Storage class}
11700
11701 \end_inset
11702
11703  Language Extensions
11704 \end_layout
11705
11706 \begin_layout Standard
11707 In addition to the ANSI storage classes SDCC allows the following MCS51
11708  specific storage classes:
11709 \end_layout
11710
11711 \begin_layout Subsubsection
11712 data
11713 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11714
11715 \end_inset
11716
11717
11718 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11719
11720 \end_inset
11721
11722  / near
11723 \begin_inset LatexCommand \index{near (storage class)}
11724
11725 \end_inset
11726
11727
11728 \begin_inset LatexCommand \index{\_\_near (storage class)}
11729
11730 \end_inset
11731
11732
11733 \end_layout
11734
11735 \begin_layout Standard
11736 This is the 
11737 \series bold
11738 default
11739 \series default
11740  storage class for the Small Memory model (
11741 \emph on
11742 data
11743 \emph default
11744  and 
11745 \emph on
11746 near
11747 \emph default
11748  or the more ANSI-C compliant forms 
11749 \emph on
11750 __data
11751 \emph default
11752  and 
11753 \emph on
11754 __near
11755 \emph default
11756  can be used synonymously).
11757  Variables declared with this storage class will be allocated in the directly
11758  addressable portion of the internal RAM of a 8051, e.g.:
11759 \end_layout
11760
11761 \begin_layout Verse
11762
11763 \family typewriter
11764 __data unsigned char test_data;
11765 \end_layout
11766
11767 \begin_layout Standard
11768 Writing 0x01 to this variable generates the assembly code:
11769 \end_layout
11770
11771 \begin_layout Verse
11772
11773 \family typewriter
11774 75*00 01\InsetSpace ~
11775 \InsetSpace ~
11776 \InsetSpace ~
11777 mov\InsetSpace ~
11778 \InsetSpace ~
11779 _test_data,#0x01
11780 \end_layout
11781
11782 \begin_layout Subsubsection
11783 xdata
11784 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11785
11786 \end_inset
11787
11788
11789 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11790
11791 \end_inset
11792
11793  / far
11794 \begin_inset LatexCommand \index{far (storage class)}
11795
11796 \end_inset
11797
11798
11799 \begin_inset LatexCommand \index{\_\_far (storage class)}
11800
11801 \end_inset
11802
11803
11804 \end_layout
11805
11806 \begin_layout Standard
11807 Variables declared with this storage class will be placed in the external
11808  RAM.
11809  This is the 
11810 \series bold
11811 default
11812 \series default
11813  storage class for the Large Memory model, e.g.:
11814 \end_layout
11815
11816 \begin_layout Verse
11817
11818 \family typewriter
11819 __xdata unsigned char test_xdata;
11820 \end_layout
11821
11822 \begin_layout Standard
11823 Writing 0x01 to this variable generates the assembly code:
11824 \end_layout
11825
11826 \begin_layout Verse
11827
11828 \family typewriter
11829 90s00r00\InsetSpace ~
11830 \InsetSpace ~
11831 \InsetSpace ~
11832 mov\InsetSpace ~
11833 \InsetSpace ~
11834 dptr,#_test_xdata 
11835 \newline
11836 74\InsetSpace ~
11837 01\InsetSpace ~
11838 \InsetSpace ~
11839 \InsetSpace ~
11840 \InsetSpace ~
11841 \InsetSpace ~
11842 \InsetSpace ~
11843 mov\InsetSpace ~
11844 \InsetSpace ~
11845 a,#0x01 
11846 \newline
11847 F0\InsetSpace ~
11848 \InsetSpace ~
11849 \InsetSpace ~
11850 \InsetSpace ~
11851 \InsetSpace ~
11852 \InsetSpace ~
11853 \InsetSpace ~
11854 \InsetSpace ~
11855 \InsetSpace ~
11856 movx\InsetSpace ~
11857 @dptr,a 
11858 \end_layout
11859
11860 \begin_layout Subsubsection
11861 idata
11862 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11863
11864 \end_inset
11865
11866
11867 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11868
11869 \end_inset
11870
11871
11872 \end_layout
11873
11874 \begin_layout Standard
11875 Variables declared with this storage class will be allocated into the indirectly
11876  addressable portion of the internal ram of a 8051, e.g.:
11877 \end_layout
11878
11879 \begin_layout Verse
11880
11881 \family typewriter
11882 __idata unsigned char test_idata;
11883 \end_layout
11884
11885 \begin_layout Standard
11886 Writing 0x01 to this variable generates the assembly code:
11887 \end_layout
11888
11889 \begin_layout Verse
11890
11891 \family typewriter
11892 78r00\InsetSpace ~
11893 \InsetSpace ~
11894 \InsetSpace ~
11895 \InsetSpace ~
11896 \InsetSpace ~
11897 \InsetSpace ~
11898 \InsetSpace ~
11899 mov\InsetSpace ~
11900 \InsetSpace ~
11901 r0,#_test_idata
11902 \newline
11903 76\InsetSpace ~
11904 01\InsetSpace ~
11905 \InsetSpace ~
11906 \InsetSpace ~
11907 \InsetSpace ~
11908 \InsetSpace ~
11909 \InsetSpace ~
11910 \InsetSpace ~
11911 mov\InsetSpace ~
11912 \InsetSpace ~
11913 @r0,#0x01
11914 \end_layout
11915
11916 \begin_layout Standard
11917 Please note, the first 128 byte of idata physically access the same RAM
11918  as the data memory.
11919  The original 8051 had 128 byte idata memory, nowadays most devices have
11920  256 byte idata memory.
11921  The stack
11922 \begin_inset LatexCommand \index{stack}
11923
11924 \end_inset
11925
11926  is located in idata memory.
11927 \end_layout
11928
11929 \begin_layout Subsubsection
11930 pdata
11931 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11932
11933 \end_inset
11934
11935
11936 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11937
11938 \end_inset
11939
11940
11941 \end_layout
11942
11943 \begin_layout Standard
11944 Paged xdata access is just as straightforward as using the other addressing
11945  modes of a 8051.
11946  It is typically located at the start of xdata and has a maximum size of
11947  256 bytes.
11948  The following example writes 0x01 to the pdata variable.
11949  Please note, pdata access physically accesses xdata memory.
11950  The high byte of the address is determined by port P2 
11951 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11952
11953 \end_inset
11954
11955 (or in case of some 8051 variants by a separate Special Function Register,
11956  see section 
11957 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11958
11959 \end_inset
11960
11961 ).
11962  This is the 
11963 \series bold
11964 default
11965 \series default
11966  storage class for the Medium Memory model, e.g.:
11967 \end_layout
11968
11969 \begin_layout Verse
11970
11971 \family typewriter
11972 __pdata unsigned char test_pdata;
11973 \end_layout
11974
11975 \begin_layout Standard
11976 Writing 0x01 to this variable generates the assembly code:
11977 \end_layout
11978
11979 \begin_layout Verse
11980
11981 \family typewriter
11982 78r00\InsetSpace ~
11983 \InsetSpace ~
11984 \InsetSpace ~
11985 \InsetSpace ~
11986 \InsetSpace ~
11987 \InsetSpace ~
11988 mov r0,#_test_pdata
11989 \newline
11990 74 01\InsetSpace ~
11991 \InsetSpace ~
11992 \InsetSpace ~
11993 \InsetSpace ~
11994 \InsetSpace ~
11995 \InsetSpace ~
11996 mov a,#0x01 
11997 \newline
11998 F2\InsetSpace ~
11999 \InsetSpace ~
12000 \InsetSpace ~
12001 \InsetSpace ~
12002 \InsetSpace ~
12003 \InsetSpace ~
12004 \InsetSpace ~
12005 \InsetSpace ~
12006 \InsetSpace ~
12007 movx @r0,a
12008 \end_layout
12009
12010 \begin_layout Standard
12011 If the -
12012 \begin_inset ERT
12013 status collapsed
12014
12015 \begin_layout Standard
12016
12017
12018 \backslash
12019 /
12020 \end_layout
12021
12022 \end_inset
12023
12024 -xstack
12025 \begin_inset LatexCommand \index{-\/-xstack}
12026
12027 \end_inset
12028
12029  option is used the pdata memory area is followed by the xstack memory area
12030  and the sum of their sizes is limited to 256 bytes.
12031 \end_layout
12032
12033 \begin_layout Subsubsection
12034 code
12035 \begin_inset LatexCommand \index{code}
12036
12037 \end_inset
12038
12039
12040 \begin_inset LatexCommand \index{\_\_code}
12041
12042 \end_inset
12043
12044
12045 \end_layout
12046
12047 \begin_layout Standard
12048 'Variables' declared with this storage class will be placed in the code
12049  memory:
12050 \end_layout
12051
12052 \begin_layout Verse
12053
12054 \family typewriter
12055 __code unsigned char test_code;
12056 \end_layout
12057
12058 \begin_layout Standard
12059 Read access to this variable generates the assembly code:
12060 \end_layout
12061
12062 \begin_layout Verse
12063
12064 \family typewriter
12065 90s00r6F\InsetSpace ~
12066 \InsetSpace ~
12067 \InsetSpace ~
12068 mov dptr,#_test_code
12069 \newline
12070 E4\InsetSpace ~
12071 \InsetSpace ~
12072 \InsetSpace ~
12073 \InsetSpace ~
12074 \InsetSpace ~
12075 \InsetSpace ~
12076 \InsetSpace ~
12077 \InsetSpace ~
12078 \InsetSpace ~
12079 clr a
12080 \newline
12081 93\InsetSpace ~
12082 \InsetSpace ~
12083 \InsetSpace ~
12084 \InsetSpace ~
12085 \InsetSpace ~
12086 \InsetSpace ~
12087 \InsetSpace ~
12088 \InsetSpace ~
12089 \InsetSpace ~
12090 movc a,@a+dptr 
12091 \end_layout
12092
12093 \begin_layout Standard
12094
12095 \family typewriter
12096 char
12097 \family default
12098  indexed arrays of characters in code memory can be accessed efficiently:
12099 \end_layout
12100
12101 \begin_layout Verse
12102
12103 \family typewriter
12104 __code char test_array[] = {'c','h','e','a','p'}; 
12105 \end_layout
12106
12107 \begin_layout Standard
12108 Read access to this array using an 8-bit unsigned index generates the assembly
12109  code:
12110 \end_layout
12111
12112 \begin_layout Verse
12113
12114 \family typewriter
12115 E5*00\InsetSpace ~
12116 \InsetSpace ~
12117 \InsetSpace ~
12118 \InsetSpace ~
12119 \InsetSpace ~
12120 \InsetSpace ~
12121 mov a,_index 
12122 \end_layout
12123
12124 \begin_layout Verse
12125
12126 \family typewriter
12127 90s00r41\InsetSpace ~
12128 \InsetSpace ~
12129 \InsetSpace ~
12130 mov dptr,#_test_array
12131 \end_layout
12132
12133 \begin_layout Verse
12134
12135 \family typewriter
12136 93\InsetSpace ~
12137 \InsetSpace ~
12138 \InsetSpace ~
12139 \InsetSpace ~
12140 \InsetSpace ~
12141 \InsetSpace ~
12142 \InsetSpace ~
12143 \InsetSpace ~
12144 \InsetSpace ~
12145 movc a,@a+dptr 
12146 \end_layout
12147
12148 \begin_layout Subsubsection
12149 bit
12150 \begin_inset LatexCommand \index{bit}
12151
12152 \end_inset
12153
12154
12155 \begin_inset LatexCommand \index{\_\_bit}
12156
12157 \end_inset
12158
12159
12160 \end_layout
12161
12162 \begin_layout Standard
12163 This is a data-type and a storage class specifier.
12164  When a variable is declared as a bit, it is allocated into the bit addressable
12165  memory of 8051, e.g.:
12166 \end_layout
12167
12168 \begin_layout Verse
12169
12170 \family typewriter
12171 __bit test_bit;
12172 \end_layout
12173
12174 \begin_layout Standard
12175 Writing 1 to this variable generates the assembly code:
12176 \end_layout
12177
12178 \begin_layout Verse
12179
12180 \family typewriter
12181 D2*00\InsetSpace ~
12182 \InsetSpace ~
12183 \InsetSpace ~
12184 \InsetSpace ~
12185 \InsetSpace ~
12186 \InsetSpace ~
12187 \InsetSpace ~
12188 setb\InsetSpace ~
12189 _test_bit
12190 \end_layout
12191
12192 \begin_layout Standard
12193 The bit addressable memory consists of 128 bits which are located from 0x20
12194  to 0x2f in data memory.
12195  
12196 \newline
12197 Apart from this 8051 specific storage class most architectures support
12198  ANSI-C bitfields
12199 \begin_inset LatexCommand \index{bitfields}
12200
12201 \end_inset
12202
12203
12204 \begin_inset Foot
12205 status open
12206
12207 \begin_layout Standard
12208 Not really meant as examples, but nevertheless showing what bitfields are
12209  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12210 \end_layout
12211
12212 \end_inset
12213
12214 .
12215  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12216  signed modifier are implemented as unsigned.
12217 \end_layout
12218
12219 \begin_layout Subsubsection
12220 sfr
12221 \begin_inset LatexCommand \index{sfr}
12222
12223 \end_inset
12224
12225
12226 \begin_inset LatexCommand \index{\_\_sfr}
12227
12228 \end_inset
12229
12230  / sfr16
12231 \begin_inset LatexCommand \index{sfr16}
12232
12233 \end_inset
12234
12235
12236 \begin_inset LatexCommand \index{\_\_sfr16}
12237
12238 \end_inset
12239
12240  / sfr32
12241 \begin_inset LatexCommand \index{sfr32}
12242
12243 \end_inset
12244
12245
12246 \begin_inset LatexCommand \index{\_\_sfr32}
12247
12248 \end_inset
12249
12250  / sbit
12251 \begin_inset LatexCommand \index{\_\_sbit}
12252
12253 \end_inset
12254
12255
12256 \begin_inset LatexCommand \index{sbit}
12257
12258 \end_inset
12259
12260
12261 \end_layout
12262
12263 \begin_layout Standard
12264 Like the bit keyword, 
12265 \emph on
12266 sfr / sfr16 / sfr32 / sbit 
12267 \emph default
12268 signify both a data-type and storage class, they are used to describe the
12269  
12270 \emph on
12271 s
12272 \emph default
12273 pecial 
12274 \emph on
12275 f
12276 \emph default
12277 unction 
12278 \emph on
12279 r
12280 \emph default
12281 egisters and 
12282 \emph on
12283 s
12284 \emph default
12285 pecial 
12286 \emph on
12287 bit
12288 \emph default
12289  variables of a 8051, eg:
12290 \end_layout
12291
12292 \begin_layout Verse
12293
12294 \family typewriter
12295 __sfr __at
12296 \begin_inset LatexCommand \index{at}
12297
12298 \end_inset
12299
12300
12301 \begin_inset LatexCommand \index{\_\_at}
12302
12303 \end_inset
12304
12305  (0x80) P0;\InsetSpace ~
12306  /* special function register P0 at location 0x80 */
12307 \newline
12308
12309 \newline
12310 /* 16 bit
12311  special function register combination for timer 0
12312 \newline
12313 \InsetSpace ~
12314 \InsetSpace ~
12315  with the high byte at
12316  location 0x8C and the low byte at location 0x8A */
12317 \newline
12318 __sfr16 __at (0x8C8A)
12319  TMR0;
12320 \newline
12321
12322 \newline
12323 __sbit __at
12324 \begin_inset LatexCommand \index{at}
12325
12326 \end_inset
12327
12328
12329 \begin_inset LatexCommand \index{\_\_at}
12330
12331 \end_inset
12332
12333  (0xd7) CY;\InsetSpace ~
12334  /* CY (Carry Flag
12335 \begin_inset LatexCommand \index{Flags}
12336
12337 \end_inset
12338
12339
12340 \begin_inset LatexCommand \index{Carry flag}
12341
12342 \end_inset
12343
12344 ) */
12345 \end_layout
12346
12347 \begin_layout Standard
12348 Special function registers which are located on an address dividable by
12349  8 are bit-addressable, an
12350 \emph on
12351  sbit
12352 \emph default
12353  addresses a specific bit within these sfr.
12354 \newline
12355 16 Bit and 32 bit special function
12356  register combinations which require a certain access order are better not
12357  declared using 
12358 \emph on
12359 sfr16
12360 \emph default
12361  or 
12362 \emph on
12363 sfr32.
12364
12365 \emph default
12366  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12367  this is not guaranteed.
12368 \newline
12369
12370 \end_layout
12371
12372 \begin_layout Standard
12373 Please note, if you use a header file which was written for another compiler
12374  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12375  likely be 
12376 \emph on
12377 not 
12378 \emph default
12379 compatible.
12380  Specifically the syntax 
12381 \family typewriter
12382 \InsetSpace ~
12383 sfr P0 = 0x80;\InsetSpace ~
12384
12385 \family default
12386  is compiled 
12387 \emph on
12388 without warning
12389 \emph default
12390  by SDCC to an assignment of 0x80 to a variable called P0 
12391 \family typewriter
12392
12393 \begin_inset Marginal
12394 status collapsed
12395
12396 \begin_layout Standard
12397
12398 \series bold
12399 \InsetSpace ~
12400 !
12401 \end_layout
12402
12403 \end_inset
12404
12405 .
12406  
12407 \family default
12408 Nevertheless it is possible to write header files
12409 \begin_inset LatexCommand \index{Header files}
12410
12411 \end_inset
12412
12413
12414 \begin_inset LatexCommand \index{Include files}
12415
12416 \end_inset
12417
12418  which can be shared among different compilers (see section 
12419 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12420
12421 \end_inset
12422
12423 ).
12424  
12425 \end_layout
12426
12427 \begin_layout Subsubsection
12428 Pointers
12429 \begin_inset LatexCommand \index{Pointer}
12430
12431 \end_inset
12432
12433  to MCS51/DS390 specific memory spaces
12434 \end_layout
12435
12436 \begin_layout Standard
12437 SDCC allows (via language extensions) pointers to explicitly point to any
12438  of the memory spaces
12439 \begin_inset LatexCommand \index{Memory model}
12440
12441 \end_inset
12442
12443  of the 8051.
12444  In addition to the explicit pointers, the compiler uses (by default) generic
12445  pointers which can be used to point to any of the memory spaces.
12446 \newline
12447
12448 \newline
12449 Pointer
12450  declaration examples:
12451 \end_layout
12452
12453 \begin_layout Verse
12454
12455 \family typewriter
12456 /* pointer physically in internal ram pointing to object in external ram
12457  */ 
12458 \newline
12459 __xdata unsigned char * __data p;
12460 \newline
12461
12462 \newline
12463 /* pointer physically in external ram
12464  pointing to object in internal ram */ 
12465 \newline
12466 __data unsigned char * __xdata p;
12467 \newline
12468
12469 \newline
12470 /*
12471  pointer physically in code rom pointing to data in xdata space */ 
12472 \newline
12473 __xdata
12474  unsigned char * __code p;
12475 \newline
12476
12477 \newline
12478 /* pointer physically in code space pointing to
12479  data in code space */ 
12480 \newline
12481 __code unsigned char * __code p;
12482 \newline
12483
12484 \newline
12485 /* generic pointer
12486  physically located in xdata space */
12487 \newline
12488 unsigned char * __xdata p;
12489 \newline
12490
12491 \newline
12492 /* generic
12493  pointer physically located in default memory space */
12494 \newline
12495 unsigned char * p;
12496 \newline
12497
12498 \newline
12499 /*
12500  the following is a function pointer
12501 \begin_inset LatexCommand \index{function pointer}
12502
12503 \end_inset
12504
12505  physically located in data space */
12506 \newline
12507 char (* __data fp)(void);
12508 \end_layout
12509
12510 \begin_layout Standard
12511 Well you get the idea.
12512  
12513 \newline
12514
12515 \newline
12516 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12517 \emph on
12518 generic
12519 \emph default
12520  pointers.
12521  
12522 \size small
12523
12524 \newline
12525
12526 \newline
12527
12528 \size default
12529 The highest order byte of the 
12530 \emph on
12531 generic
12532 \emph default
12533  pointers contains the data space information.
12534  Assembler support routines are called whenever data is stored or retrieved
12535  using 
12536 \emph on
12537 generic
12538 \emph default
12539  pointers.
12540  These are useful for developing reusable library
12541 \begin_inset LatexCommand \index{Libraries}
12542
12543 \end_inset
12544
12545  routines.
12546  Explicitly specifying the pointer
12547 \begin_inset LatexCommand \index{pointer}
12548
12549 \end_inset
12550
12551  type will generate the most efficient code.
12552 \end_layout
12553
12554 \begin_layout Subsubsection
12555 Notes on MCS51 memory
12556 \begin_inset LatexCommand \index{MCS51 memory}
12557
12558 \end_inset
12559
12560  layout
12561 \end_layout
12562
12563 \begin_layout Standard
12564 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12565  RAM memory which is structured as follows:
12566 \newline
12567
12568 \newline
12569 - Bytes 00-1F - 32 bytes to hold
12570  up to 4 banks of the registers R0 to R7, 
12571 \newline
12572 - Bytes 20-2F - 16 bytes to hold
12573  128 bit
12574 \begin_inset LatexCommand \index{bit}
12575
12576 \end_inset
12577
12578  variables and, 
12579 \newline
12580 - Bytes 30-7F - 80 bytes for general purpose use.
12581 \newline
12582
12583 \end_layout
12584
12585 \begin_layout Standard
12586 Additionally some members of the MCS51 family may have up to 128 bytes of
12587  additional, indirectly addressable, internal RAM memory (
12588 \emph on
12589 idata
12590 \emph default
12591
12592 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12593
12594 \end_inset
12595
12596
12597 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12598
12599 \end_inset
12600
12601 ).
12602  Furthermore, some chips may have some built in external memory (
12603 \emph on
12604 xdata
12605 \emph default
12606
12607 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12608
12609 \end_inset
12610
12611
12612 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12613
12614 \end_inset
12615
12616 ) which should not be confused with the internal, directly addressable RAM
12617  memory (
12618 \emph on
12619 data
12620 \emph default
12621
12622 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12623
12624 \end_inset
12625
12626
12627 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12628
12629 \end_inset
12630
12631 ).
12632  Sometimes this built in 
12633 \emph on
12634 xdata
12635 \emph default
12636  memory has to be activated before using it (you can probably find this
12637  information on the datasheet of the microcontroller your are using, see
12638  also section 
12639 \begin_inset LatexCommand \ref{sub:Startup-Code}
12640
12641 \end_inset
12642
12643 \InsetSpace ~
12644 Startup-Code).
12645 \end_layout
12646
12647 \begin_layout Standard
12648 Normally SDCC will only use the first bank
12649 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12650
12651 \end_inset
12652
12653  of registers (register bank 0), but it is possible to specify that other
12654  banks of registers (keyword 
12655 \emph on
12656 using
12657 \emph default
12658  
12659 \emph on
12660
12661 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12662
12663 \end_inset
12664
12665
12666 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12667
12668 \end_inset
12669
12670
12671 \emph default
12672 ) should be used for example in interrupt
12673 \begin_inset LatexCommand \index{interrupt}
12674
12675 \end_inset
12676
12677
12678 \begin_inset LatexCommand \index{\_\_interrupt}
12679
12680 \end_inset
12681
12682  routines.
12683  By default, the compiler will place the stack after the last byte of allocated
12684  memory for variables.
12685  For example, if the first 2 banks of registers are used, and only four
12686  bytes are used for 
12687 \emph on
12688 data
12689 \emph default
12690  variables, it will position the base of the internal stack at address 20
12691  (0x14).
12692  This implies that as the stack
12693 \begin_inset LatexCommand \index{stack}
12694
12695 \end_inset
12696
12697  grows, it will use up the remaining register banks, and the 16 bytes used
12698  by the 128 bit variables, and 80 bytes for general purpose use.
12699  If any bit variables are used, the data variables will be placed in unused
12700  register banks and after the byte holding the last bit variable.
12701  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12702  (two bytes used), 
12703 \emph on
12704 data
12705 \emph default
12706  variables will be placed starting from address 0x10 to 0x20 and continue
12707  at address 0x22.
12708  You can also use -
12709 \begin_inset ERT
12710 status collapsed
12711
12712 \begin_layout Standard
12713
12714
12715 \backslash
12716 /
12717 \end_layout
12718
12719 \end_inset
12720
12721 -data-loc
12722 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12723
12724 \end_inset
12725
12726  to specify the start address of the 
12727 \emph on
12728 data
12729 \emph default
12730  and -
12731 \begin_inset ERT
12732 status collapsed
12733
12734 \begin_layout Standard
12735
12736
12737 \backslash
12738 /
12739 \end_layout
12740
12741 \end_inset
12742
12743 -iram-size
12744 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12745
12746 \end_inset
12747
12748  to specify the size of the total internal RAM (
12749 \emph on
12750 data
12751 \emph default
12752 +
12753 \emph on
12754 idata
12755 \emph default
12756 ).
12757  
12758 \newline
12759
12760 \end_layout
12761
12762 \begin_layout Standard
12763 By default the 8051 linker will place the stack after the last byte of (i)data
12764  variables.
12765  Option -
12766 \begin_inset ERT
12767 status collapsed
12768
12769 \begin_layout Standard
12770
12771
12772 \backslash
12773 /
12774 \end_layout
12775
12776 \end_inset
12777
12778 -stack-loc
12779 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12780
12781 \end_inset
12782
12783  allows you to specify the start of the stack, i.e.
12784  you could start it after any data in the general purpose area.
12785  If your microcontroller has additional indirectly addressable internal
12786  RAM (
12787 \emph on
12788 idata
12789 \emph default
12790 ) you can place the stack on it.
12791  You may also need to use -
12792 \begin_inset ERT
12793 status collapsed
12794
12795 \begin_layout Standard
12796
12797
12798 \backslash
12799 /
12800 \end_layout
12801
12802 \end_inset
12803
12804 -xdata-loc
12805 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12806
12807 \end_inset
12808
12809  to set the start address of the external RAM (
12810 \emph on
12811 xdata
12812 \emph default
12813 ) and -
12814 \begin_inset ERT
12815 status collapsed
12816
12817 \begin_layout Standard
12818
12819
12820 \backslash
12821 /
12822 \end_layout
12823
12824 \end_inset
12825
12826 -xram-size
12827 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12828
12829 \end_inset
12830
12831  to specify its size.
12832  Same goes for the code memory, using -
12833 \begin_inset ERT
12834 status collapsed
12835
12836 \begin_layout Standard
12837
12838
12839 \backslash
12840 /
12841 \end_layout
12842
12843 \end_inset
12844
12845 -code-loc
12846 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12847
12848 \end_inset
12849
12850  and -
12851 \begin_inset ERT
12852 status collapsed
12853
12854 \begin_layout Standard
12855
12856
12857 \backslash
12858 /
12859 \end_layout
12860
12861 \end_inset
12862
12863 -code-size
12864 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12865
12866 \end_inset
12867
12868 .
12869  If in doubt, don't specify any options and see if the resulting memory
12870  layout is appropriate, then you can adjust it.
12871 \end_layout
12872
12873 \begin_layout Standard
12874 The linker generates two files with memory allocation information.
12875  The first, with extension .map
12876 \begin_inset LatexCommand \index{<file>.map}
12877
12878 \end_inset
12879
12880  shows all the variables and segments.
12881  The second with extension .mem
12882 \begin_inset LatexCommand \index{<file>.mem}
12883
12884 \end_inset
12885
12886  shows the final memory layout.
12887  The linker will complain either if memory segments overlap, there is not
12888  enough memory, or there is not enough space for stack.
12889  If you get any linking warnings and/or errors related to stack or segments
12890  allocation, take a look at either the .map or .mem files to find out what
12891  the problem is.
12892  The .mem file may even suggest a solution to the problem.
12893 \begin_inset VSpace bigskip
12894 \end_inset
12895
12896
12897 \end_layout
12898
12899 \begin_layout Subsection
12900 Z80/Z180 Storage Class
12901 \begin_inset LatexCommand \index{Z80!Storage class}
12902
12903 \end_inset
12904
12905  Language Extensions
12906 \end_layout
12907
12908 \begin_layout Subsubsection
12909 sfr
12910 \begin_inset LatexCommand \index{sfr}
12911
12912 \end_inset
12913
12914
12915 \begin_inset LatexCommand \index{\_\_sfr}
12916
12917 \end_inset
12918
12919  (in/out to 8-bit addresses)
12920 \end_layout
12921
12922 \begin_layout Standard
12923 The Z80
12924 \begin_inset LatexCommand \index{Z80}
12925
12926 \end_inset
12927
12928  family has separate address spaces for memory and 
12929 \emph on
12930 i
12931 \emph default
12932 nput/
12933 \emph on
12934 o
12935 \emph default
12936 utput memory.
12937  I/O memory
12938 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12939
12940 \end_inset
12941
12942
12943 \begin_inset LatexCommand \index{Z80!I/O memory}
12944
12945 \end_inset
12946
12947
12948 \begin_inset LatexCommand \index{Z180!I/O memory}
12949
12950 \end_inset
12951
12952  is accessed with special instructions, e.g.:
12953 \end_layout
12954
12955 \begin_layout Verse
12956
12957 \family typewriter
12958 sfr at 0x78 IoPort;\InsetSpace ~
12959 \InsetSpace ~
12960 /* define a var in I/O space at 78h called IoPort */
12961  
12962 \end_layout
12963
12964 \begin_layout Standard
12965 Writing 0x01 to this variable generates the assembly code:
12966 \end_layout
12967
12968 \begin_layout Verse
12969
12970 \family typewriter
12971 3E 01\InsetSpace ~
12972 \InsetSpace ~
12973 \InsetSpace ~
12974 \InsetSpace ~
12975 \InsetSpace ~
12976 \InsetSpace ~
12977 ld a,#0x01
12978 \newline
12979 D3 78\InsetSpace ~
12980 \InsetSpace ~
12981 \InsetSpace ~
12982 \InsetSpace ~
12983 \InsetSpace ~
12984 \InsetSpace ~
12985 out (_IoPort),a 
12986 \end_layout
12987
12988 \begin_layout Subsubsection
12989 banked sfr
12990 \begin_inset LatexCommand \index{sfr}
12991
12992 \end_inset
12993
12994
12995 \begin_inset LatexCommand \index{\_\_sfr}
12996
12997 \end_inset
12998
12999  (in/out to 16-bit addresses)
13000 \end_layout
13001
13002 \begin_layout Standard
13003 The keyword 
13004 \emph on
13005 banked
13006 \emph default
13007  is used to support 16 bit addresses in I/O memory e.g.:
13008 \end_layout
13009
13010 \begin_layout Verse
13011
13012 \family typewriter
13013 sfr banked at
13014 \begin_inset LatexCommand \index{at}
13015
13016 \end_inset
13017
13018
13019 \begin_inset LatexCommand \index{\_\_at}
13020
13021 \end_inset
13022
13023  0x123 IoPort; 
13024 \end_layout
13025
13026 \begin_layout Standard
13027 Writing 0x01 to this variable generates the assembly code:
13028 \end_layout
13029
13030 \begin_layout Verse
13031
13032 \family typewriter
13033 01 23 01\InsetSpace ~
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 ld bc,#_IoPort
13037 \newline
13038 3E 01\InsetSpace ~
13039 \InsetSpace ~
13040 \InsetSpace ~
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 ld a,#0x01 
13045 \newline
13046 ED 79\InsetSpace ~
13047 \InsetSpace ~
13048 \InsetSpace ~
13049 \InsetSpace ~
13050 \InsetSpace ~
13051 \InsetSpace ~
13052 out (c),a 
13053 \end_layout
13054
13055 \begin_layout Subsubsection
13056 sfr
13057 \begin_inset LatexCommand \index{sfr}
13058
13059 \end_inset
13060
13061
13062 \begin_inset LatexCommand \index{\_\_sfr}
13063
13064 \end_inset
13065
13066  (in0/out0 to 8 bit addresses on Z180
13067 \begin_inset LatexCommand \index{Z180}
13068
13069 \end_inset
13070
13071 /HD64180
13072 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13073
13074 \end_inset
13075
13076 )
13077 \end_layout
13078
13079 \begin_layout Standard
13080 The compiler option -
13081 \begin_inset ERT
13082 status collapsed
13083
13084 \begin_layout Standard
13085
13086
13087 \backslash
13088 /
13089 \end_layout
13090
13091 \end_inset
13092
13093 -portmode
13094 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13095
13096 \end_inset
13097
13098 =180 (80) and a compiler #pragma\InsetSpace ~
13099 portmode
13100 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13101
13102 \end_inset
13103
13104  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13105 ns 
13106 \family typewriter
13107 in0/out0
13108 \family default
13109  instead of 
13110 \family typewriter
13111 in/out
13112 \family default
13113 .
13114  If you include the file z180.h this will be set automatically.
13115 \begin_inset VSpace bigskip
13116 \end_inset
13117
13118
13119 \end_layout
13120
13121 \begin_layout Subsection
13122 HC08 Storage Class
13123 \begin_inset LatexCommand \index{HC08!Storage class}
13124
13125 \end_inset
13126
13127  Language Extensions
13128 \end_layout
13129
13130 \begin_layout Subsubsection
13131 data
13132 \begin_inset LatexCommand \index{data (hc08 storage class)}
13133
13134 \end_inset
13135
13136
13137 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13138
13139 \end_inset
13140
13141  
13142 \end_layout
13143
13144 \begin_layout Standard
13145 The data storage class declares a variable that resides in the first 256
13146  bytes of memory (the direct page).
13147  The HC08
13148 \begin_inset LatexCommand \index{HC08}
13149
13150 \end_inset
13151
13152  is most efficient at accessing variables (especially pointers) stored here.
13153 \end_layout
13154
13155 \begin_layout Subsubsection
13156 xdata
13157 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13158
13159 \end_inset
13160
13161
13162 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13163
13164 \end_inset
13165
13166  
13167 \end_layout
13168
13169 \begin_layout Standard
13170 The xdata storage class declares a variable that can reside anywhere in
13171  memory.
13172  This is the default if no storage class is specified.
13173  
13174 \begin_inset VSpace bigskip
13175 \end_inset
13176
13177
13178 \end_layout
13179
13180 \begin_layout Section
13181 Absolute Addressing
13182 \begin_inset LatexCommand \index{Absolute addressing}
13183
13184 \end_inset
13185
13186
13187 \end_layout
13188
13189 \begin_layout Standard
13190 Data items can be assigned an absolute address with the 
13191 \emph on
13192 at
13193 \begin_inset LatexCommand \index{at}
13194
13195 \end_inset
13196
13197
13198 \begin_inset LatexCommand \index{\_\_at}
13199
13200 \end_inset
13201
13202  <address>
13203 \emph default
13204  keyword, in addition to a storage class, e.g.:
13205 \end_layout
13206
13207 \begin_layout Verse
13208
13209 \family typewriter
13210 xdata
13211 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13212
13213 \end_inset
13214
13215
13216 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13217
13218 \end_inset
13219
13220  at
13221 \begin_inset LatexCommand \index{at}
13222
13223 \end_inset
13224
13225
13226 \begin_inset LatexCommand \index{\_\_at}
13227
13228 \end_inset
13229
13230  0x7ffe unsigned int chksum;
13231 \end_layout
13232
13233 \begin_layout Standard
13234 or, better conforming to ISO/IEC 9899 C:
13235 \end_layout
13236
13237 \begin_layout Verse
13238
13239 \family typewriter
13240 __xdata __at (0x7ffe) unsigned int chksum;
13241 \end_layout
13242
13243 \begin_layout Standard
13244 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13245  of the external ram.
13246  The compiler does 
13247 \emph on
13248 not
13249 \emph default
13250  reserve any space for variables declared in this way
13251 \begin_inset Marginal
13252 status collapsed
13253
13254 \begin_layout Standard
13255
13256 \series bold
13257 \InsetSpace ~
13258 !
13259 \end_layout
13260
13261 \end_inset
13262
13263  (they are implemented with an equate in the assembler).
13264  Thus it is left to the programmer to make sure there are no overlaps with
13265  other variables that are declared without the absolute address.
13266  The assembler listing file (.lst
13267 \begin_inset LatexCommand \index{<file>.lst}
13268
13269 \end_inset
13270
13271 ) and the linker output files (.rst
13272 \begin_inset LatexCommand \index{<file>.rst}
13273
13274 \end_inset
13275
13276 ) and (.map
13277 \begin_inset LatexCommand \index{<file>.map}
13278
13279 \end_inset
13280
13281 ) are good places to look for such overlaps.
13282 \end_layout
13283
13284 \begin_layout Standard
13285 If however you provide an initializer
13286 \begin_inset LatexCommand \index{Variable initialization}
13287
13288 \end_inset
13289
13290  actual memory allocation will take place and overlaps will be detected
13291  by the linker.
13292  E.g.:
13293 \end_layout
13294
13295 \begin_layout Verse
13296
13297 \family typewriter
13298 __code __at (0x7ff0) char Id[5] = 
13299 \begin_inset Quotes sld
13300 \end_inset
13301
13302 SDCC
13303 \begin_inset Quotes srd
13304 \end_inset
13305
13306 ;
13307 \end_layout
13308
13309 \begin_layout Standard
13310 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13311  in code memory.
13312 \end_layout
13313
13314 \begin_layout Standard
13315 In case of memory mapped I/O devices the keyword 
13316 \emph on
13317 volatile
13318 \emph default
13319  has to be used to tell the compiler that accesses might not be removed:
13320 \end_layout
13321
13322 \begin_layout Verse
13323
13324 \family typewriter
13325 volatile
13326 \begin_inset LatexCommand \index{volatile}
13327
13328 \end_inset
13329
13330  __xdata
13331 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13332
13333 \end_inset
13334
13335  __at
13336 \begin_inset LatexCommand \index{at}
13337
13338 \end_inset
13339
13340  (0x8000) unsigned char PORTA_8255;
13341 \end_layout
13342
13343 \begin_layout Standard
13344 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13345 r) array
13346 \family typewriter
13347 \size footnotesize
13348
13349 \begin_inset LatexCommand \index{Aligned array}
13350
13351 \end_inset
13352
13353
13354 \family default
13355 \size default
13356  starts at a block (256 byte) boundary
13357 \begin_inset LatexCommand \index{block boundary}
13358
13359 \end_inset
13360
13361  (section 
13362 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13363
13364 \end_inset
13365
13366  has an example).
13367 \newline
13368 Absolute addresses can be specified for variables in all
13369  storage classes, e.g.:
13370 \end_layout
13371
13372 \begin_layout Verse
13373
13374 \family typewriter
13375 __bit
13376 \begin_inset LatexCommand \index{bit}
13377
13378 \end_inset
13379
13380  __at
13381 \begin_inset LatexCommand \index{at}
13382
13383 \end_inset
13384
13385  (0x02) bvar;
13386 \end_layout
13387
13388 \begin_layout Standard
13389 The above example will allocate the variable at offset 0x02 in the bit-addressab
13390 le space.
13391  There is no real advantage to assigning absolute addresses to variables
13392  in this manner, unless you want strict control over all the variables allocated.
13393  One possible use would be to write hardware portable code.
13394  For example, if you have a routine that uses one or more of the microcontroller
13395  I/O pins, and such pins are different for two different hardwares, you
13396  can declare the I/O pins in your routine using:
13397 \end_layout
13398
13399 \begin_layout Verse
13400
13401 \family typewriter
13402 extern volatile
13403 \begin_inset LatexCommand \index{volatile}
13404
13405 \end_inset
13406
13407  __bit MOSI;\InsetSpace ~
13408 \InsetSpace ~
13409 \InsetSpace ~
13410 \InsetSpace ~
13411 /* master out, slave in */
13412 \newline
13413 extern volatile __bit MISO;\InsetSpace ~
13414 \InsetSpace ~
13415 \InsetSpace ~
13416 \InsetSpace ~
13417 /* master
13418  in, slave out */
13419 \newline
13420 extern volatile __bit MCLK;\InsetSpace ~
13421 \InsetSpace ~
13422 \InsetSpace ~
13423 \InsetSpace ~
13424 /* master clock */
13425 \newline
13426
13427 \newline
13428 /* Input and
13429  Output of a byte on a 3-wire serial bus.
13430 \newline
13431 \InsetSpace ~
13432 \InsetSpace ~
13433 \InsetSpace ~
13434 If needed adapt polarity of clock,
13435  polarity of data and bit order
13436 \newline
13437 \InsetSpace ~
13438 */
13439 \newline
13440 unsigned char spi_io(unsigned char out_byte)
13441  
13442 \newline
13443
13444 \newline
13445 \InsetSpace ~
13446 \InsetSpace ~
13447 \InsetSpace ~
13448 \InsetSpace ~
13449 unsigned char i=8;
13450 \newline
13451 \InsetSpace ~
13452 \InsetSpace ~
13453 \InsetSpace ~
13454 \InsetSpace ~
13455 do { 
13456 \newline
13457 \InsetSpace ~
13458 \InsetSpace ~
13459 \InsetSpace ~
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 \InsetSpace ~
13463 \InsetSpace ~
13464 \InsetSpace ~
13465 MOSI = out_byte & 0x80; 
13466 \newline
13467 \InsetSpace ~
13468 \InsetSpace ~
13469 \InsetSpace ~
13470 \InsetSpace ~
13471 \InsetSpace ~
13472 \InsetSpace ~
13473 \InsetSpace ~
13474 \InsetSpace ~
13475 out_byte <<= 1;
13476 \newline
13477 \InsetSpace ~
13478 \InsetSpace ~
13479 \InsetSpace ~
13480 \InsetSpace ~
13481 \InsetSpace ~
13482 \InsetSpace ~
13483 \InsetSpace ~
13484 \InsetSpace ~
13485 MCLK =
13486  1; 
13487 \newline
13488 \InsetSpace ~
13489 \InsetSpace ~
13490 \InsetSpace ~
13491 \InsetSpace ~
13492 \InsetSpace ~
13493 \InsetSpace ~
13494 \InsetSpace ~
13495 \InsetSpace ~
13496 /* _asm nop _endasm; */\InsetSpace ~
13497 \InsetSpace ~
13498 \InsetSpace ~
13499 \InsetSpace ~
13500 \InsetSpace ~
13501 \InsetSpace ~
13502 \InsetSpace ~
13503 \InsetSpace ~
13504 /* for slow peripherals */
13505 \newline
13506 \InsetSpace ~
13507 \InsetSpace ~
13508 \InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 \InsetSpace ~
13512 \InsetSpace ~
13513 \InsetSpace ~
13514 if(MISO) 
13515 \newline
13516 \InsetSpace ~
13517 \InsetSpace ~
13518 \InsetSpace ~
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 \InsetSpace ~
13523 \InsetSpace ~
13524 \InsetSpace ~
13525 \InsetSpace ~
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 out_byte +=
13529  1; 
13530 \newline
13531 \InsetSpace ~
13532 \InsetSpace ~
13533 \InsetSpace ~
13534 \InsetSpace ~
13535 \InsetSpace ~
13536 \InsetSpace ~
13537 \InsetSpace ~
13538 \InsetSpace ~
13539 MCLK = 0; 
13540 \newline
13541 \InsetSpace ~
13542 \InsetSpace ~
13543 \InsetSpace ~
13544 \InsetSpace ~
13545 } while(--i);
13546 \newline
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 \InsetSpace ~
13550 \InsetSpace ~
13551 return out_byte; 
13552 \newline
13553 }
13554 \end_layout
13555
13556 \begin_layout Standard
13557 Then, someplace in the code for the first hardware you would use
13558 \end_layout
13559
13560 \begin_layout Verse
13561
13562 \family typewriter
13563 __bit __at
13564 \begin_inset LatexCommand \index{at}
13565
13566 \end_inset
13567
13568
13569 \begin_inset LatexCommand \index{\_\_at}
13570
13571 \end_inset
13572
13573  (0x80) MOSI;\InsetSpace ~
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 /* I/O port 0, bit 0 */
13578 \newline
13579 __bit __at (0x81) MISO;\InsetSpace ~
13580 \InsetSpace ~
13581 \InsetSpace ~
13582 \InsetSpace ~
13583 /* I/O port 0,
13584  bit 1 */
13585 \newline
13586 __bit __at (0x82) MCLK;\InsetSpace ~
13587 \InsetSpace ~
13588 \InsetSpace ~
13589 \InsetSpace ~
13590 /* I/O port 0, bit 2 */
13591 \end_layout
13592
13593 \begin_layout Standard
13594 Similarly, for the second hardware you would use
13595 \end_layout
13596
13597 \begin_layout Verse
13598
13599 \family typewriter
13600 __bit __at (0x83) MOSI;\InsetSpace ~
13601 \InsetSpace ~
13602 \InsetSpace ~
13603 \InsetSpace ~
13604 /* I/O port 0, bit 3 */
13605 \newline
13606 __bit __at (0x91) MISO;\InsetSpace ~
13607 \InsetSpace ~
13608 \InsetSpace ~
13609 \InsetSpace ~
13610 /*
13611  I/O port 1, bit 1 */
13612 \newline
13613 __bit
13614 \begin_inset LatexCommand \index{bit}
13615
13616 \end_inset
13617
13618  __at (0x92) MCLK;\InsetSpace ~
13619 \InsetSpace ~
13620 \InsetSpace ~
13621 \InsetSpace ~
13622 /* I/O port 1, bit 2 */
13623 \end_layout
13624
13625 \begin_layout Standard
13626 and you can use the same hardware dependent routine without changes, as
13627  for example in a library.
13628  This is somehow similar to sbit, but only one absolute address has to be
13629  specified in the whole project.
13630 \begin_inset VSpace bigskip
13631 \end_inset
13632
13633
13634 \end_layout
13635
13636 \begin_layout Section
13637 Parameters
13638 \begin_inset LatexCommand \index{Parameters}
13639
13640 \end_inset
13641
13642
13643 \begin_inset LatexCommand \index{function parameter}
13644
13645 \end_inset
13646
13647  & Local Variables
13648 \begin_inset LatexCommand \index{local variables}
13649
13650 \end_inset
13651
13652
13653 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13654
13655 \end_inset
13656
13657
13658 \end_layout
13659
13660 \begin_layout Standard
13661 Automatic (local) variables and parameters to functions can either be placed
13662  on the stack or in data-space.
13663  The default action of the compiler is to place these variables in the internal
13664  RAM (for small model) or external RAM (for medium or large model).
13665  This in fact makes them similar to 
13666 \emph on
13667 static
13668 \begin_inset LatexCommand \index{static}
13669
13670 \end_inset
13671
13672
13673 \emph default
13674  so by default functions are non-reentrant
13675 \begin_inset LatexCommand \index{reentrant}
13676
13677 \end_inset
13678
13679 .
13680  
13681 \newline
13682
13683 \newline
13684 They can be placed on the stack
13685 \begin_inset LatexCommand \index{stack}
13686
13687 \end_inset
13688
13689  by using the
13690 \emph on
13691  -
13692 \begin_inset ERT
13693 status collapsed
13694
13695 \begin_layout Standard
13696
13697
13698 \backslash
13699 /
13700 \end_layout
13701
13702 \end_inset
13703
13704 -stack-auto
13705 \begin_inset LatexCommand \index{-\/-stack-auto}
13706
13707 \end_inset
13708
13709
13710 \emph default
13711  option, by using 
13712 \emph on
13713 #pragma\InsetSpace ~
13714 stackauto
13715 \emph default
13716
13717 \begin_inset LatexCommand \index{\#pragma stackauto}
13718
13719 \end_inset
13720
13721  or by using the 
13722 \emph on
13723 reentrant
13724 \begin_inset LatexCommand \index{reentrant}
13725
13726 \end_inset
13727
13728
13729 \emph default
13730  keyword in the function declaration, e.g.:
13731 \end_layout
13732
13733 \begin_layout Verse
13734
13735 \family typewriter
13736 unsigned char foo(char i) __reentrant 
13737 \newline
13738
13739 \newline
13740 \InsetSpace ~
13741 \InsetSpace ~
13742 \InsetSpace ~
13743 \InsetSpace ~
13744 ...
13745  
13746 \newline
13747 }
13748 \end_layout
13749
13750 \begin_layout Standard
13751 Since stack space on 8051 is limited, the 
13752 \emph on
13753 reentrant 
13754 \emph default
13755 keyword or the
13756 \emph on
13757  -
13758 \begin_inset ERT
13759 status collapsed
13760
13761 \begin_layout Standard
13762
13763
13764 \backslash
13765 /
13766 \end_layout
13767
13768 \end_inset
13769
13770 -stack-auto
13771 \emph default
13772  option should be used sparingly.
13773  Note that the reentrant keyword just means that the parameters & local
13774  variables will be allocated to the stack, it 
13775 \emph on
13776 does not
13777 \emph default
13778  mean that the function is register bank
13779 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13780
13781 \end_inset
13782
13783  independent.
13784 \newline
13785
13786 \newline
13787 Local variables
13788 \begin_inset LatexCommand \index{local variables}
13789
13790 \end_inset
13791
13792  can be assigned storage classes and absolute
13793 \begin_inset LatexCommand \index{Absolute addressing}
13794
13795 \end_inset
13796
13797  addresses, e.g.: 
13798 \end_layout
13799
13800 \begin_layout Verse
13801
13802 \family typewriter
13803 unsigned char foo() 
13804 \newline
13805 {
13806 \newline
13807 \InsetSpace ~
13808 \InsetSpace ~
13809 \InsetSpace ~
13810 \InsetSpace ~
13811 __xdata unsigned char i;
13812 \newline
13813 \InsetSpace ~
13814 \InsetSpace ~
13815 \InsetSpace ~
13816 \InsetSpace ~
13817 __bit bvar;
13818 \newline
13819 \InsetSpace ~
13820 \InsetSpace ~
13821 \InsetSpace ~
13822 \InsetSpace ~
13823 __data __at
13824 \begin_inset LatexCommand \index{at}
13825
13826 \end_inset
13827
13828  (0x31) unsigned char j;
13829 \newline
13830 \InsetSpace ~
13831 \InsetSpace ~
13832 \InsetSpace ~
13833 \InsetSpace ~
13834 ...
13835  
13836 \newline
13837 }
13838 \end_layout
13839
13840 \begin_layout Standard
13841 In the above example the variable 
13842 \emph on
13843 i
13844 \emph default
13845  will be allocated in the external ram, 
13846 \emph on
13847 bvar
13848 \emph default
13849  in bit addressable space and
13850 \emph on
13851  j
13852 \emph default
13853  in internal ram.
13854  When compiled with 
13855 \emph on
13856 -
13857 \begin_inset ERT
13858 status collapsed
13859
13860 \begin_layout Standard
13861
13862
13863 \backslash
13864 /
13865 \end_layout
13866
13867 \end_inset
13868
13869 -stack-auto
13870 \emph default
13871  or when a function is declared as 
13872 \emph on
13873 reentrant
13874 \emph default
13875  this should only be done for static variables.
13876 \end_layout
13877
13878 \begin_layout Standard
13879 Parameters
13880 \begin_inset LatexCommand \index{function parameter}
13881
13882 \end_inset
13883
13884  however are not allowed any storage class
13885 \begin_inset LatexCommand \index{Storage class}
13886
13887 \end_inset
13888
13889 , (storage classes for parameters will be ignored), their allocation is
13890  governed by the memory model in use, and the reentrancy options.
13891 \end_layout
13892
13893 \begin_layout Standard
13894 It is however allowed to use bit parameters in reentrant functions and also
13895  non-static local bit variables are supported.
13896  Efficient use is limited to 8 semi-bitregisters in bit space.
13897  They are pushed and popped to stack
13898 \begin_inset LatexCommand \index{stack}
13899
13900 \end_inset
13901
13902  as a single byte just like the normal registers.
13903 \end_layout
13904
13905 \begin_layout Section
13906 Overlaying
13907 \begin_inset LatexCommand \label{sub:Overlaying}
13908
13909 \end_inset
13910
13911
13912 \begin_inset LatexCommand \index{Overlaying}
13913
13914 \end_inset
13915
13916
13917 \end_layout
13918
13919 \begin_layout Standard
13920 For non-reentrant
13921 \begin_inset LatexCommand \index{reentrant}
13922
13923 \end_inset
13924
13925  functions SDCC will try to reduce internal ram space usage by overlaying
13926  parameters and local variables of a function (if possible).
13927  Parameters and local variables
13928 \begin_inset LatexCommand \index{local variables}
13929
13930 \end_inset
13931
13932  of a function will be allocated to an overlayable segment if the function
13933  has 
13934 \emph on
13935 no other function calls and the function is non-reentrant and the memory
13936  model
13937 \begin_inset LatexCommand \index{Memory model}
13938
13939 \end_inset
13940
13941  is small.
13942
13943 \emph default
13944  If an explicit storage class
13945 \begin_inset LatexCommand \index{Storage class}
13946
13947 \end_inset
13948
13949  is specified for a local variable, it will NOT be overlayed.
13950 \end_layout
13951
13952 \begin_layout Standard
13953 Note that the compiler (not the linkage editor) makes the decision for overlayin
13954 g the data items.
13955  Functions that are called from an interrupt service routine
13956 \begin_inset Marginal
13957 status collapsed
13958
13959 \begin_layout Standard
13960
13961 \series bold
13962 !
13963 \end_layout
13964
13965 \end_inset
13966
13967  should be preceded by a #pragma\InsetSpace ~
13968 nooverlay
13969 \begin_inset LatexCommand \index{\#pragma nooverlay}
13970
13971 \end_inset
13972
13973  if they are not reentrant.
13974 \end_layout
13975
13976 \begin_layout Standard
13977 Also note that the compiler does not do any processing of inline assembler
13978  code, so the compiler might incorrectly assign local variables and parameters
13979  of a function into the overlay segment if the inline assembler code calls
13980  other c-functions that might use the overlay.
13981  In that case the #pragma\InsetSpace ~
13982 nooverlay should be used.
13983 \end_layout
13984
13985 \begin_layout Standard
13986 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13987 tion
13988 \begin_inset LatexCommand \index{Multiplication}
13989
13990 \end_inset
13991
13992  or division
13993 \begin_inset LatexCommand \index{Division}
13994
13995 \end_inset
13996
13997  will NOT be overlayed since these are implemented using external functions,
13998  e.g.:
13999 \end_layout
14000
14001 \begin_layout Verse
14002
14003 \family typewriter
14004 #pragma save 
14005 \newline
14006 #pragma nooverlay
14007 \begin_inset LatexCommand \index{\#pragma nooverlay}
14008
14009 \end_inset
14010
14011  
14012 \newline
14013 void set_error(unsigned char errcd) 
14014 \newline
14015 {
14016 \newline
14017 \InsetSpace ~
14018 \InsetSpace ~
14019 \InsetSpace ~
14020 \InsetSpace ~
14021 P3 = errcd;
14022 \newline
14023
14024 \newline
14025 #pragma restore 
14026 \newline
14027
14028 \newline
14029 void
14030  some_isr () __interrupt
14031 \begin_inset LatexCommand \index{interrupt}
14032
14033 \end_inset
14034
14035  (2)
14036 \newline
14037 {
14038 \newline
14039 \InsetSpace ~
14040 \InsetSpace ~
14041 \InsetSpace ~
14042 \InsetSpace ~
14043 ...
14044 \newline
14045 \InsetSpace ~
14046 \InsetSpace ~
14047 \InsetSpace ~
14048 \InsetSpace ~
14049 set_error(10);
14050 \newline
14051 \InsetSpace ~
14052 \InsetSpace ~
14053 \InsetSpace ~
14054 \InsetSpace ~
14055 ...
14056  
14057 \newline
14058 }
14059 \end_layout
14060
14061 \begin_layout Standard
14062 In the above example the parameter 
14063 \emph on
14064 errcd
14065 \emph default
14066  for the function 
14067 \emph on
14068 set_error
14069 \emph default
14070  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14071 nooverlay was
14072  not present, this could cause unpredictable runtime behavior when called
14073  from an interrupt service routine.
14074  The #pragma\InsetSpace ~
14075 nooverlay ensures that the parameters and local variables for
14076  the function are NOT overlayed.
14077 \begin_inset VSpace bigskip
14078 \end_inset
14079
14080
14081 \end_layout
14082
14083 \begin_layout Section
14084 Interrupt Service Routines
14085 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14086
14087 \end_inset
14088
14089
14090 \end_layout
14091
14092 \begin_layout Subsection
14093 General Information
14094 \end_layout
14095
14096 \begin_layout Standard
14097 SDCC allows 
14098 \emph on
14099 i
14100 \emph default
14101 nterrupt 
14102 \emph on
14103 s
14104 \emph default
14105 ervice 
14106 \emph on
14107 r
14108 \emph default
14109 outines to be coded in C, with some extended keywords.
14110 \end_layout
14111
14112 \begin_layout Verse
14113
14114 \family typewriter
14115 void timer_isr (void) __interrupt (1) __using (1) 
14116 \newline
14117
14118 \newline
14119 \InsetSpace ~
14120 \InsetSpace ~
14121 \InsetSpace ~
14122 \InsetSpace ~
14123 ...
14124  
14125 \newline
14126 }
14127 \end_layout
14128
14129 \begin_layout Standard
14130 The optional number following the 
14131 \emph on
14132 interrupt
14133 \begin_inset LatexCommand \index{interrupt}
14134
14135 \end_inset
14136
14137
14138 \begin_inset LatexCommand \index{\_\_interrupt}
14139
14140 \end_inset
14141
14142
14143 \emph default
14144  keyword is the interrupt number this routine will service.
14145  When present, the compiler will insert a call to this routine in the interrupt
14146  vector table
14147 \begin_inset LatexCommand \index{interrupt vector table}
14148
14149 \end_inset
14150
14151  for the interrupt number specified.
14152  If you have multiple source files in your project, interrupt service routines
14153  can be present in any of them, but a prototype of the isr MUST be present
14154  or included in the file that contains the function 
14155 \emph on
14156 main
14157 \emph default
14158 .
14159  The optional (8051 specific) keyword 
14160 \emph on
14161 using
14162 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14163
14164 \end_inset
14165
14166
14167 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14168
14169 \end_inset
14170
14171
14172 \emph default
14173  can be used to tell the compiler to use the specified register bank when
14174  generating code for this function.
14175  
14176 \newline
14177 Interrupt service routines open the door for some very interesting bugs:
14178 \end_layout
14179
14180 \begin_layout Subsubsection
14181 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14182
14183 \end_inset
14184
14185 Common interrupt pitfall: variable not declared 
14186 \emph on
14187 volatile
14188 \end_layout
14189
14190 \begin_layout Standard
14191 If an interrupt service routine changes variables which are accessed by
14192  other functions these variables have to be declared 
14193 \emph on
14194 volatile
14195 \emph default
14196
14197 \begin_inset LatexCommand \index{volatile}
14198
14199 \end_inset
14200
14201 .
14202  See 
14203 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14204
14205 \end_inset
14206
14207  .
14208 \end_layout
14209
14210 \begin_layout Subsubsection
14211 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14212
14213 \end_inset
14214
14215 Common interrupt pitfall: 
14216 \emph on
14217 non-atomic access
14218 \end_layout
14219
14220 \begin_layout Standard
14221 If the access to these variables is not 
14222 \emph on
14223 atomic
14224 \begin_inset LatexCommand \index{atomic}
14225
14226 \end_inset
14227
14228
14229 \emph default
14230  (i.e.
14231  the processor needs more than one instruction for the access and could
14232  be interrupted while accessing the variable) the interrupt must be disabled
14233  during the access to avoid inconsistent data.
14234  
14235 \newline
14236 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14237  and should be protected by disabling interrupts.
14238  You're not automatically on the safe side if you use 8 bit variables though.
14239  We need an example here: f.e.
14240  on the 8051 the harmless looking 
14241 \begin_inset Quotes srd
14242 \end_inset
14243
14244
14245 \family typewriter
14246 flags\InsetSpace ~
14247 |=\InsetSpace ~
14248 0x80;
14249 \family default
14250
14251 \begin_inset Quotes sld
14252 \end_inset
14253
14254  is not atomic if 
14255 \family typewriter
14256 flags
14257 \family default
14258  resides in xdata.
14259  Setting 
14260 \begin_inset Quotes srd
14261 \end_inset
14262
14263
14264 \family typewriter
14265 flags\InsetSpace ~
14266 |=\InsetSpace ~
14267 0x40;
14268 \family default
14269
14270 \begin_inset Quotes sld
14271 \end_inset
14272
14273  from within an interrupt routine might get lost if the interrupt occurs
14274  at the wrong time.
14275  
14276 \begin_inset Quotes sld
14277 \end_inset
14278
14279
14280 \family typewriter
14281 counter\InsetSpace ~
14282 +=\InsetSpace ~
14283 8;
14284 \family default
14285
14286 \begin_inset Quotes srd
14287 \end_inset
14288
14289  is not atomic on the 8051 even if 
14290 \family typewriter
14291 counter
14292 \family default
14293  is located in data memory.
14294 \newline
14295 Bugs like these are hard to reproduce and can
14296  cause a lot of trouble.
14297  
14298 \end_layout
14299
14300 \begin_layout Subsubsection
14301 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14302
14303 \end_inset
14304
14305 Common interrupt pitfall: 
14306 \emph on
14307 stack overflow
14308 \end_layout
14309
14310 \begin_layout Standard
14311 The return address and the registers used in the interrupt service routine
14312  are saved on the stack
14313 \begin_inset LatexCommand \index{stack}
14314
14315 \end_inset
14316
14317  so there must be sufficient stack space.
14318  If there isn't variables or registers (or even the return address itself)
14319  will be corrupted.
14320  This 
14321 \emph on
14322 stack overflow
14323 \emph default
14324
14325 \begin_inset LatexCommand \index{stack overflow}
14326
14327 \end_inset
14328
14329  is most likely to happen if the interrupt occurs during the 
14330 \begin_inset Quotes sld
14331 \end_inset
14332
14333 deepest
14334 \begin_inset Quotes srd
14335 \end_inset
14336
14337  subroutine when the stack is already in use for f.e.
14338  many return addresses.
14339 \end_layout
14340
14341 \begin_layout Subsubsection
14342 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14343
14344 \end_inset
14345
14346 Common interrupt pitfall: 
14347 \emph on
14348 use of non-reentrant functions
14349 \end_layout
14350
14351 \begin_layout Standard
14352 A special note here, int (16 bit) and long (32 bit) integer division
14353 \begin_inset LatexCommand \index{Division}
14354
14355 \end_inset
14356
14357 , multiplication
14358 \begin_inset LatexCommand \index{Multiplication}
14359
14360 \end_inset
14361
14362  & modulus
14363 \begin_inset LatexCommand \index{Modulus}
14364
14365 \end_inset
14366
14367  and floating-point
14368 \begin_inset LatexCommand \index{Floating point support}
14369
14370 \end_inset
14371
14372  operations are implemented using external support routines.
14373  If an interrupt service routine needs to do any of these operations then
14374  the support routines (as mentioned in a following section) will have to
14375  be recompiled using the
14376 \emph on
14377  -
14378 \begin_inset ERT
14379 status collapsed
14380
14381 \begin_layout Standard
14382
14383
14384 \backslash
14385 /
14386 \end_layout
14387
14388 \end_inset
14389
14390 -stack-auto
14391 \begin_inset LatexCommand \index{-\/-stack-auto}
14392
14393 \end_inset
14394
14395
14396 \emph default
14397  option and the source file will need to be compiled using the 
14398 \emph on
14399 -
14400 \begin_inset ERT
14401 status collapsed
14402
14403 \begin_layout Standard
14404
14405
14406 \backslash
14407 /
14408 \end_layout
14409
14410 \end_inset
14411
14412 -int-long-reent
14413 \emph default
14414
14415 \begin_inset LatexCommand \index{-\/-int-long-reent}
14416
14417 \end_inset
14418
14419  compiler option.
14420  
14421 \newline
14422 Note, the type promotion
14423 \begin_inset LatexCommand \index{type promotion}
14424
14425 \end_inset
14426
14427  required by ANSI C can cause 16 bit routines to be used
14428 \begin_inset Marginal
14429 status collapsed
14430
14431 \begin_layout Standard
14432
14433 \series bold
14434 \InsetSpace ~
14435 !
14436 \end_layout
14437
14438 \end_inset
14439
14440  without the programmer being aware of it.
14441  See f.e.
14442  the cast 
14443 \family typewriter
14444 (unsigned char)(tail-1)
14445 \family default
14446  within the if clause in section 
14447 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14448
14449 \end_inset
14450
14451 .
14452 \end_layout
14453
14454 \begin_layout Standard
14455 Calling other functions from an interrupt service routine is not recommended,
14456  avoid it if possible.
14457  Note that when some function is called from an interrupt service routine
14458  it should be preceded by a #pragma\InsetSpace ~
14459 nooverlay
14460 \begin_inset LatexCommand \index{\#pragma nooverlay}
14461
14462 \end_inset
14463
14464  if it is not reentrant.
14465  Furthermore nonreentrant functions should not be called from the main program
14466  while the interrupt service routine might be active.
14467  They also must not be called from low priority interrupt service routines
14468  while a high priority interrupt service routine might be active.
14469  You could use semaphores or make the function
14470 \emph on
14471  critical
14472 \emph default
14473  if all parameters are passed in registers.
14474 \newline
14475  Also see section 
14476 \begin_inset LatexCommand \ref{sub:Overlaying}
14477
14478 \end_inset
14479
14480 \InsetSpace ~
14481 about Overlaying and section 
14482 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14483
14484 \end_inset
14485
14486 \InsetSpace ~
14487 about Functions using private register banks.
14488 \begin_inset VSpace bigskip
14489 \end_inset
14490
14491
14492 \end_layout
14493
14494 \begin_layout Subsection
14495 MCS51/DS390 Interrupt Service Routines
14496 \end_layout
14497
14498 \begin_layout Standard
14499 Interrupt
14500 \begin_inset LatexCommand \index{interrupt}
14501
14502 \end_inset
14503
14504  numbers and the corresponding address & descriptions for the Standard 8051/8052
14505  are listed below.
14506  SDCC will automatically adjust the 
14507 \begin_inset LatexCommand \index{interrupt vector table}
14508
14509 \end_inset
14510
14511  to the maximum interrupt number specified.
14512 \newline
14513
14514 \end_layout
14515
14516 \begin_layout Standard
14517 \align center
14518 \begin_inset Tabular
14519 <lyxtabular version="3" rows="9" columns="3">
14520 <features>
14521 <column alignment="center" valignment="top" leftline="true" width="0in">
14522 <column alignment="left" valignment="top" leftline="true" width="0in">
14523 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14524 <row topline="true" bottomline="true">
14525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14526 \begin_inset Text
14527
14528 \begin_layout Standard
14529 Interrupt #
14530 \end_layout
14531
14532 \end_inset
14533 </cell>
14534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14535 \begin_inset Text
14536
14537 \begin_layout Standard
14538 Description
14539 \end_layout
14540
14541 \end_inset
14542 </cell>
14543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14544 \begin_inset Text
14545
14546 \begin_layout Standard
14547 Vector Address
14548 \end_layout
14549
14550 \end_inset
14551 </cell>
14552 </row>
14553 <row topline="true">
14554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14555 \begin_inset Text
14556
14557 \begin_layout Standard
14558 0
14559 \end_layout
14560
14561 \end_inset
14562 </cell>
14563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14564 \begin_inset Text
14565
14566 \begin_layout Standard
14567 External 0
14568 \end_layout
14569
14570 \end_inset
14571 </cell>
14572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14573 \begin_inset Text
14574
14575 \begin_layout Standard
14576 0x0003
14577 \end_layout
14578
14579 \end_inset
14580 </cell>
14581 </row>
14582 <row topline="true">
14583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14584 \begin_inset Text
14585
14586 \begin_layout Standard
14587 1
14588 \end_layout
14589
14590 \end_inset
14591 </cell>
14592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14593 \begin_inset Text
14594
14595 \begin_layout Standard
14596 Timer 0
14597 \end_layout
14598
14599 \end_inset
14600 </cell>
14601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14602 \begin_inset Text
14603
14604 \begin_layout Standard
14605 0x000b
14606 \end_layout
14607
14608 \end_inset
14609 </cell>
14610 </row>
14611 <row topline="true">
14612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14613 \begin_inset Text
14614
14615 \begin_layout Standard
14616 2
14617 \end_layout
14618
14619 \end_inset
14620 </cell>
14621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14622 \begin_inset Text
14623
14624 \begin_layout Standard
14625 External 1
14626 \end_layout
14627
14628 \end_inset
14629 </cell>
14630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14631 \begin_inset Text
14632
14633 \begin_layout Standard
14634 0x0013
14635 \end_layout
14636
14637 \end_inset
14638 </cell>
14639 </row>
14640 <row topline="true">
14641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14642 \begin_inset Text
14643
14644 \begin_layout Standard
14645 3
14646 \end_layout
14647
14648 \end_inset
14649 </cell>
14650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14651 \begin_inset Text
14652
14653 \begin_layout Standard
14654 Timer 1
14655 \end_layout
14656
14657 \end_inset
14658 </cell>
14659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14660 \begin_inset Text
14661
14662 \begin_layout Standard
14663 0x001b
14664 \end_layout
14665
14666 \end_inset
14667 </cell>
14668 </row>
14669 <row topline="true">
14670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14671 \begin_inset Text
14672
14673 \begin_layout Standard
14674 4
14675 \end_layout
14676
14677 \end_inset
14678 </cell>
14679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14680 \begin_inset Text
14681
14682 \begin_layout Standard
14683 Serial
14684 \end_layout
14685
14686 \end_inset
14687 </cell>
14688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14689 \begin_inset Text
14690
14691 \begin_layout Standard
14692 0x0023
14693 \end_layout
14694
14695 \end_inset
14696 </cell>
14697 </row>
14698 <row topline="true">
14699 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14700 \begin_inset Text
14701
14702 \begin_layout Standard
14703 5
14704 \end_layout
14705
14706 \end_inset
14707 </cell>
14708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14709 \begin_inset Text
14710
14711 \begin_layout Standard
14712 Timer 2 (8052)
14713 \end_layout
14714
14715 \end_inset
14716 </cell>
14717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14718 \begin_inset Text
14719
14720 \begin_layout Standard
14721 0x002b
14722 \end_layout
14723
14724 \end_inset
14725 </cell>
14726 </row>
14727 <row topline="true">
14728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14729 \begin_inset Text
14730
14731 \begin_layout Standard
14732 ...
14733 \end_layout
14734
14735 \end_inset
14736 </cell>
14737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14738 \begin_inset Text
14739
14740 \begin_layout Standard
14741
14742 \end_layout
14743
14744 \end_inset
14745 </cell>
14746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14747 \begin_inset Text
14748
14749 \begin_layout Standard
14750 ...
14751 \end_layout
14752
14753 \end_inset
14754 </cell>
14755 </row>
14756 <row topline="true" bottomline="true">
14757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14758 \begin_inset Text
14759
14760 \begin_layout Standard
14761 n
14762 \end_layout
14763
14764 \end_inset
14765 </cell>
14766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14767 \begin_inset Text
14768
14769 \begin_layout Standard
14770
14771 \end_layout
14772
14773 \end_inset
14774 </cell>
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14776 \begin_inset Text
14777
14778 \begin_layout Standard
14779 0x0003 + 8*n
14780 \end_layout
14781
14782 \end_inset
14783 </cell>
14784 </row>
14785 </lyxtabular>
14786
14787 \end_inset
14788
14789
14790 \newline
14791
14792 \end_layout
14793
14794 \begin_layout Standard
14795 If the interrupt service routine is defined without 
14796 \emph on
14797 using
14798 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14799
14800 \end_inset
14801
14802
14803 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14804
14805 \end_inset
14806
14807
14808 \emph default
14809  a register bank or with register bank 0 (
14810 \emph on
14811 using
14812 \emph default
14813  0), the compiler will save the registers used by itself on the stack upon
14814  entry and restore them at exit, however if such an interrupt service routine
14815  calls another function then the entire register bank will be saved on the
14816  stack.
14817  This scheme may be advantageous for small interrupt service routines which
14818  have low register usage.
14819 \end_layout
14820
14821 \begin_layout Standard
14822 If the interrupt service routine is defined to be using a specific register
14823  bank then only 
14824 \emph on
14825 a, b, dptr
14826 \emph default
14827  & psw are saved and restored, if such an interrupt service routine calls
14828  another function (using another register bank) then the entire register
14829  bank of the called function will be saved on the stack
14830 \begin_inset LatexCommand \index{stack}
14831
14832 \end_inset
14833
14834 .
14835  This scheme is recommended for larger interrupt service routines.
14836 \begin_inset VSpace bigskip
14837 \end_inset
14838
14839
14840 \end_layout
14841
14842 \begin_layout Subsection
14843 HC08
14844 \begin_inset LatexCommand \index{HC08}
14845
14846 \end_inset
14847
14848  Interrupt Service Routines
14849 \end_layout
14850
14851 \begin_layout Standard
14852 Since the number of interrupts
14853 \begin_inset LatexCommand \index{HC08!interrupt}
14854
14855 \end_inset
14856
14857  available is chip specific and the interrupt vector table always ends at
14858  the last byte of memory, the interrupt numbers corresponds to the interrupt
14859  vectors in reverse order of address.
14860  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14861  2 will use the interrupt vector at 0xfffa, and so on.
14862  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14863  this way; instead see section 
14864 \begin_inset LatexCommand \ref{sub:Startup-Code}
14865
14866 \end_inset
14867
14868  for details on customizing startup.
14869 \begin_inset VSpace bigskip
14870 \end_inset
14871
14872
14873 \end_layout
14874
14875 \begin_layout Subsection
14876 Z80 Interrupt Service Routines
14877 \end_layout
14878
14879 \begin_layout Standard
14880 The Z80
14881 \begin_inset LatexCommand \index{Z80}
14882
14883 \end_inset
14884
14885  uses several different methods for determining the correct interrupt
14886 \begin_inset LatexCommand \index{Z80!interrupt}
14887
14888 \end_inset
14889
14890  vector depending on the hardware implementation.
14891  Therefore, SDCC ignores the optional interrupt number and does not attempt
14892  to generate an interrupt vector table.
14893 \end_layout
14894
14895 \begin_layout Standard
14896 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14897  instruction to return from the interrupt.
14898  To write an interrupt handler for the non-maskable interrupt, which needs
14899  a RETN instruction instead, add the 
14900 \emph on
14901 critical
14902 \emph default
14903  keyword:
14904 \end_layout
14905
14906 \begin_layout Verse
14907
14908 \family typewriter
14909 void nmi_isr (void) critical interrupt
14910 \newline
14911
14912 \newline
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 ...
14918  
14919 \newline
14920 }
14921 \end_layout
14922
14923 \begin_layout Standard
14924 However if you need to create a non-interruptable interrupt service routine
14925  you would also require the 
14926 \emph on
14927 critical
14928 \emph default
14929  keyword.
14930  To distinguish between this and an nmi_isr you must provide an interrupt
14931  number.
14932 \begin_inset VSpace bigskip
14933 \end_inset
14934
14935
14936 \end_layout
14937
14938 \begin_layout Section
14939 Enabling and Disabling Interrupts
14940 \end_layout
14941
14942 \begin_layout Subsection
14943 Critical Functions and Critical Statements
14944 \end_layout
14945
14946 \begin_layout Standard
14947 A special keyword may be associated with a block or a function declaring
14948  it as 
14949 \emph on
14950 critical
14951 \emph default
14952 .
14953  SDCC will generate code to disable all interrupts
14954 \begin_inset LatexCommand \index{interrupt}
14955
14956 \end_inset
14957
14958  upon entry to a critical function and restore the interrupt enable to the
14959  previous state before returning.
14960  Nesting critical functions will need one additional byte on the stack
14961 \begin_inset LatexCommand \index{stack}
14962
14963 \end_inset
14964
14965  for each call.
14966 \end_layout
14967
14968 \begin_layout Verse
14969
14970 \family typewriter
14971 int foo () __critical
14972 \begin_inset LatexCommand \index{critical}
14973
14974 \end_inset
14975
14976
14977 \begin_inset LatexCommand \index{\_\_critical}
14978
14979 \end_inset
14980
14981  
14982 \newline
14983
14984 \newline
14985 \InsetSpace ~
14986 \InsetSpace ~
14987 \InsetSpace ~
14988 \InsetSpace ~
14989 ...
14990  
14991 \newline
14992 \InsetSpace ~
14993 \InsetSpace ~
14994 \InsetSpace ~
14995 \InsetSpace ~
14996 ...
14997  
14998 \newline
14999 }
15000 \end_layout
15001
15002 \begin_layout Standard
15003 The critical attribute maybe used with other attributes like 
15004 \emph on
15005 reentrant.
15006 \emph default
15007
15008 \newline
15009 The keyword 
15010 \emph on
15011 critical
15012 \emph default
15013  may also be used to disable interrupts more locally:
15014 \end_layout
15015
15016 \begin_layout Verse
15017
15018 \family typewriter
15019 __critical{ i++; }
15020 \end_layout
15021
15022 \begin_layout Standard
15023 More than one statement could have been included in the block.
15024 \end_layout
15025
15026 \begin_layout Subsection
15027 Enabling and Disabling Interrupts directly
15028 \end_layout
15029
15030 \begin_layout Standard
15031 Interrupts
15032 \begin_inset LatexCommand \index{interrupt}
15033
15034 \end_inset
15035
15036  can also be disabled and enabled directly (8051):
15037 \end_layout
15038
15039 \begin_layout Verse
15040
15041 \family typewriter
15042 EA = 0;\InsetSpace ~
15043 \InsetSpace ~
15044 \InsetSpace ~
15045 \InsetSpace ~
15046 \InsetSpace ~
15047 \InsetSpace ~
15048 \InsetSpace ~
15049 \InsetSpace ~
15050 \InsetSpace ~
15051 \InsetSpace ~
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 or:\InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 \InsetSpace ~
15059 \InsetSpace ~
15060 \InsetSpace ~
15061 \InsetSpace ~
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 EA_SAVE = EA;
15066 \end_layout
15067
15068 \begin_layout Verse
15069
15070 \family typewriter
15071 ...\InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 \InsetSpace ~
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 \InsetSpace ~
15093 \InsetSpace ~
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 EA = 0;
15102 \end_layout
15103
15104 \begin_layout Verse
15105
15106 \family typewriter
15107 EA = 1;\InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 \InsetSpace ~
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 \InsetSpace ~
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 ...
15134 \end_layout
15135
15136 \begin_layout Verse
15137
15138 \family typewriter
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 \InsetSpace ~
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 EA = EA_SAVE;
15173 \end_layout
15174
15175 \begin_layout Standard
15176 On other architectures which have seperate opcodes for enabling and disabling
15177  interrupts you might want to make use of defines with inline assembly
15178 \begin_inset LatexCommand \index{Assembler routines}
15179
15180 \end_inset
15181
15182  (HC08
15183 \begin_inset LatexCommand \index{HC08!interrupt}
15184
15185 \end_inset
15186
15187 ):
15188 \end_layout
15189
15190 \begin_layout Verse
15191
15192 \family typewriter
15193 #define CLI _asm
15194 \begin_inset LatexCommand \index{\_asm}
15195
15196 \end_inset
15197
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 cli\InsetSpace ~
15201 \InsetSpace ~
15202 _endasm
15203 \begin_inset LatexCommand \index{\_endasm}
15204
15205 \end_inset
15206
15207
15208 \end_layout
15209
15210 \begin_layout Verse
15211
15212 \family typewriter
15213 #define SEI _asm\InsetSpace ~
15214 \InsetSpace ~
15215 sei\InsetSpace ~
15216 \InsetSpace ~
15217 _endasm; 
15218 \end_layout
15219
15220 \begin_layout Verse
15221
15222 \family typewriter
15223 ...
15224 \end_layout
15225
15226 \begin_layout Standard
15227 Note: it is sometimes sufficient to disable only a specific interrupt source
15228  like f.e.
15229  a timer or serial interrupt by manipulating an 
15230 \emph on
15231 interrupt mask
15232 \begin_inset LatexCommand \index{interrupt mask}
15233
15234 \end_inset
15235
15236
15237 \emph default
15238  register.
15239  
15240 \end_layout
15241
15242 \begin_layout Standard
15243 Usually the time during which interrupts are disabled should be kept as
15244  short as possible.
15245  This minimizes both 
15246 \emph on
15247 interrupt latency
15248 \emph default
15249
15250 \begin_inset LatexCommand \index{interrupt latency}
15251
15252 \end_inset
15253
15254  (the time between the occurrence of the interrupt and the execution of
15255  the first code in the interrupt routine) and 
15256 \emph on
15257 interrupt jitter
15258 \emph default
15259
15260 \begin_inset LatexCommand \index{interrupt jitter}
15261
15262 \end_inset
15263
15264  (the difference between the shortest and the longest interrupt latency).
15265  These really are something different, f.e.
15266  a serial interrupt has to be served before its buffer overruns so it cares
15267  for the maximum interrupt latency, whereas it does not care about jitter.
15268  On a loudspeaker driven via a digital to analog converter which is fed
15269  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15270  a much smaller jitter will be very audible.
15271 \end_layout
15272
15273 \begin_layout Standard
15274 You can reenable interrupts within an interrupt routine and on some architecture
15275 s you can make use of two (or more) levels of 
15276 \emph on
15277 interrupt priorities
15278 \emph default
15279
15280 \begin_inset LatexCommand \index{interrupt priority}
15281
15282 \end_inset
15283
15284 .
15285  On some architectures which don't support interrupt priorities these can
15286  be implemented by manipulating the interrupt mask and reenabling interrupts
15287  within the interrupt routine.
15288  Check there is sufficient space on the stack
15289 \begin_inset LatexCommand \index{stack}
15290
15291 \end_inset
15292
15293  and don't add complexity unless you have to.
15294  
15295 \end_layout
15296
15297 \begin_layout Subsection
15298 Semaphore
15299 \begin_inset LatexCommand \index{semaphore}
15300
15301 \end_inset
15302
15303  locking (mcs51/ds390)
15304 \end_layout
15305
15306 \begin_layout Standard
15307 Some architectures (mcs51/ds390) have an atomic
15308 \begin_inset LatexCommand \index{atomic}
15309
15310 \end_inset
15311
15312  bit test and
15313 \emph on
15314  
15315 \emph default
15316 clear
15317 \emph on
15318  
15319 \emph default
15320 instruction.
15321  These type of instructions are typically used in preemptive multitasking
15322  systems, where a routine f.e.
15323  claims the use of a data structure ('acquires a lock
15324 \begin_inset LatexCommand \index{lock}
15325
15326 \end_inset
15327
15328  on it'), makes some modifications and then releases the lock when the data
15329  structure is consistent again.
15330  The instruction may also be used if interrupt and non-interrupt code have
15331  to compete for a resource.
15332  With the atomic bit test and clear instruction interrupts
15333 \begin_inset LatexCommand \index{interrupt}
15334
15335 \end_inset
15336
15337  don't have to be disabled for the locking operation.
15338  
15339 \end_layout
15340
15341 \begin_layout Standard
15342 SDCC generates this instruction if the source follows this pattern:
15343 \end_layout
15344
15345 \begin_layout Verse
15346
15347 \family typewriter
15348 volatile
15349 \begin_inset LatexCommand \index{volatile}
15350
15351 \end_inset
15352
15353  bit resource_is_free; 
15354 \newline
15355
15356 \newline
15357 if (resource_is_free) 
15358 \newline
15359 \InsetSpace ~
15360 \InsetSpace ~
15361
15362 \newline
15363 \InsetSpace ~
15364 \InsetSpace ~
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 resource_is_free=0; 
15368 \newline
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 ...
15374  
15375 \newline
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 resource_is_free=1;
15381 \newline
15382 \InsetSpace ~
15383 \InsetSpace ~
15384
15385 \end_layout
15386
15387 \begin_layout Standard
15388 Note, mcs51 and ds390 support only an atomic
15389 \begin_inset LatexCommand \index{atomic}
15390
15391 \end_inset
15392
15393  bit test and 
15394 \emph on
15395 clear
15396 \emph default
15397  instruction (as opposed to atomic bit test and 
15398 \emph on
15399 set).
15400 \end_layout
15401
15402 \begin_layout Section
15403 Functions using private register banks
15404 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15405
15406 \end_inset
15407
15408  (mcs51/ds390)
15409 \end_layout
15410
15411 \begin_layout Standard
15412 Some architectures have support for quickly changing register sets.
15413  SDCC supports this feature with the 
15414 \emph on
15415 using
15416 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15417
15418 \end_inset
15419
15420
15421 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15422
15423 \end_inset
15424
15425
15426 \emph default
15427  attribute (which tells the compiler to use a register bank
15428 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15429
15430 \end_inset
15431
15432  other than the default bank zero).
15433  It should only be applied to 
15434 \emph on
15435 interrupt
15436 \begin_inset LatexCommand \index{interrupt}
15437
15438 \end_inset
15439
15440
15441 \emph default
15442  functions (see footnote below).
15443  This will in most circumstances make the generated ISR code more efficient
15444  since it will not have to save registers on the stack.
15445 \end_layout
15446
15447 \begin_layout Standard
15448 The 
15449 \emph on
15450 using
15451 \emph default
15452  attribute will have no effect on the generated code for a 
15453 \emph on
15454 non-interrupt
15455 \emph default
15456  function (but may occasionally be useful anyway
15457 \begin_inset Foot
15458 status open
15459
15460 \begin_layout Standard
15461 possible exception: if a function is called ONLY from 'interrupt' functions
15462  using a particular bank, it can be declared with the same 'using' attribute
15463  as the calling 'interrupt' functions.
15464  For instance, if you have several ISRs using bank one, and all of them
15465  call memcpy(), it might make sense to create a specialized version of memcpy()
15466  'using 1', since this would prevent the ISR from having to save bank zero
15467  to the stack on entry and switch to bank zero before calling the function
15468 \end_layout
15469
15470 \end_inset
15471
15472 ).
15473 \newline
15474
15475 \emph on
15476 (pending: Note, nowadays the 
15477 \emph default
15478 using
15479 \emph on
15480  attribute has an effect on
15481 \emph default
15482  
15483 \emph on
15484 the generated code for a 
15485 \emph default
15486 non-interrupt
15487 \emph on
15488  function
15489 \emph default
15490 .
15491 \emph on
15492 )
15493 \end_layout
15494
15495 \begin_layout Standard
15496 An 
15497 \emph on
15498 interrupt
15499 \emph default
15500  function using a non-zero bank will assume that it can trash that register
15501  bank, and will not save it.
15502  Since high-priority interrupts
15503 \begin_inset LatexCommand \index{interrupts}
15504
15505 \end_inset
15506
15507
15508 \begin_inset LatexCommand \index{interrupt priority}
15509
15510 \end_inset
15511
15512  can interrupt low-priority ones on the 8051 and friends, this means that
15513  if a high-priority ISR 
15514 \emph on
15515 using
15516 \emph default
15517  a particular bank occurs while processing a low-priority ISR 
15518 \emph on
15519 using
15520 \emph default
15521  the same bank, terrible and bad things can happen.
15522  To prevent this, no single register bank should be 
15523 \emph on
15524 used
15525 \emph default
15526  by both a high priority and a low priority ISR.
15527  This is probably most easily done by having all high priority ISRs use
15528  one bank and all low priority ISRs use another.
15529  If you have an ISR which can change priority at runtime, you're on your
15530  own: I suggest using the default bank zero and taking the small performance
15531  hit.
15532 \end_layout
15533
15534 \begin_layout Standard
15535 It is most efficient if your ISR calls no other functions.
15536  If your ISR must call other functions, it is most efficient if those functions
15537  use the same bank as the ISR (see note 1 below); the next best is if the
15538  called functions use bank zero.
15539  It is very inefficient to call a function using a different, non-zero bank
15540  from an ISR.
15541  
15542 \begin_inset VSpace bigskip
15543 \end_inset
15544
15545
15546 \end_layout
15547
15548 \begin_layout Section
15549 Startup Code
15550 \begin_inset LatexCommand \label{sub:Startup-Code}
15551
15552 \end_inset
15553
15554
15555 \begin_inset LatexCommand \index{Startup code}
15556
15557 \end_inset
15558
15559
15560 \end_layout
15561
15562 \begin_layout Subsection
15563 MCS51/DS390 Startup Code
15564 \end_layout
15565
15566 \begin_layout Standard
15567 The compiler triggers the linker to link certain initialization modules
15568  from the runtime library
15569 \begin_inset LatexCommand \index{Runtime library}
15570
15571 \end_inset
15572
15573  called crt<something>.
15574  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15575  GSINIT5) is not linked unless the -
15576 \series bold
15577
15578 \begin_inset ERT
15579 status open
15580
15581 \begin_layout Standard
15582
15583
15584 \backslash
15585 /
15586 \end_layout
15587
15588 \end_inset
15589
15590
15591 \series default
15592 -xstack option is used.
15593  These modules are highly entangled by the use of special segments/areas,
15594  but a common layout is shown below:
15595 \end_layout
15596
15597 \begin_layout Verse
15598
15599 \family typewriter
15600 \series bold
15601 \size footnotesize
15602 (main.asm)
15603 \end_layout
15604
15605 \begin_layout Verse
15606
15607 \family typewriter
15608 \size footnotesize
15609 \InsetSpace ~
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 .area HOME (CODE)
15618 \newline
15619 __interrupt_vect:
15620 \newline
15621 \InsetSpace ~
15622 \InsetSpace ~
15623 \InsetSpace ~
15624 \InsetSpace ~
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 \InsetSpace ~
15628 \InsetSpace ~
15629 ljmp __sdcc_gsinit_startup
15630 \end_layout
15631
15632 \begin_layout Verse
15633
15634 \family typewriter
15635 \series bold
15636 \size footnotesize
15637 (crtstart.asm)
15638 \end_layout
15639
15640 \begin_layout Verse
15641
15642 \family typewriter
15643 \size footnotesize
15644 \InsetSpace ~
15645 \InsetSpace ~
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 .area GSINIT0 (CODE)
15653 \newline
15654 __sdcc_gsinit_startup::
15655 \newline
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 mov sp,#__start__stack - 1
15665 \end_layout
15666
15667 \begin_layout Verse
15668
15669 \family typewriter
15670 \series bold
15671 \size footnotesize
15672 (crtxstack.asm)
15673 \end_layout
15674
15675 \begin_layout Verse
15676
15677 \family typewriter
15678 \size footnotesize
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 .area GSINIT1 (CODE)
15688 \newline
15689 __sdcc_init_xstack::
15690 \newline
15691 ; Need to initialize in GSINIT1 in
15692  case the user's __sdcc_external_startup uses the xstack.
15693 \newline
15694 \InsetSpace ~
15695 \InsetSpace ~
15696 \InsetSpace ~
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 mov __XPAGE,#(__start__x
15703 stack >> 8)
15704 \newline
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 mov _spx,#__start__xstack
15714 \end_layout
15715
15716 \begin_layout Verse
15717
15718 \family typewriter
15719 \series bold
15720 \size footnotesize
15721 (crtstart.asm)
15722 \end_layout
15723
15724 \begin_layout Verse
15725
15726 \family typewriter
15727 \size footnotesize
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 .area GSINIT2 (CODE)
15737 \newline
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 \InsetSpace ~
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 lcall __sdcc_external_startup
15747 \newline
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 \InsetSpace ~
15751 \InsetSpace ~
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 mov a,dpl
15757 \newline
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 \InsetSpace ~
15766 jz __sdcc_init_data
15767 \newline
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 \InsetSpace ~
15775 \InsetSpace ~
15776 ljmp
15777  __sdcc_program_startup
15778 \newline
15779 __sdcc_init_data:
15780 \end_layout
15781
15782 \begin_layout Verse
15783
15784 \family typewriter
15785 \series bold
15786 \size footnotesize
15787 (crtxinit.asm)
15788 \end_layout
15789
15790 \begin_layout Verse
15791
15792 \family typewriter
15793 \size footnotesize
15794 \InsetSpace ~
15795 \InsetSpace ~
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 .area GSINIT3 (CODE)
15803 \newline
15804 __mcs51_genXINIT::
15805 \newline
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 mov r1,#l_XINIT
15815 \newline
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 \InsetSpace ~
15819 \InsetSpace ~
15820 \InsetSpace ~
15821 \InsetSpace ~
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 mov a,r1
15825 \newline
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 \InsetSpace ~
15831 \InsetSpace ~
15832 \InsetSpace ~
15833 \InsetSpace ~
15834 orl a,#(l_XINIT
15835  >> 8)
15836 \newline
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 \InsetSpace ~
15843 \InsetSpace ~
15844 \InsetSpace ~
15845 jz 00003$
15846 \newline
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 \InsetSpace ~
15854 \InsetSpace ~
15855 mov r2,#((l_XINIT+255) >> 8)
15856 \newline
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 mov dptr,#s_XINIT
15866 \newline
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 mov r0,#s_XISEG
15876 \newline
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 mov
15886  __XPAGE,#(s_XISEG >> 8)
15887 \newline
15888 00001$:\InsetSpace ~
15889 clr a
15890 \newline
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 movc a,@a+dptr
15900 \newline
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 movx @r0,a
15910 \newline
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 inc dptr
15920 \newline
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 inc
15930  r0
15931 \newline
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 cjne r0,#0,00002$
15941 \newline
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 inc __XPAGE
15951 \newline
15952 00002$:\InsetSpace ~
15953 djnz r1,00001$
15954 \newline
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 \InsetSpace ~
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 djnz r2,00001$
15964 \newline
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 mov __XPAGE,#0
15974 xFF
15975 \newline
15976 00003$:
15977 \end_layout
15978
15979 \begin_layout Verse
15980
15981 \family typewriter
15982 \series bold
15983 \size footnotesize
15984 (crtclear.asm)
15985 \end_layout
15986
15987 \begin_layout Verse
15988
15989 \family typewriter
15990 \size footnotesize
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 .area GSINIT4 (CODE)
16000 \newline
16001 __mcs51_genRAMCLEAR::
16002 \newline
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 clr a
16012 \newline
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 mov r0,#(l_IRAM-1)
16022 \newline
16023 00004$:\InsetSpace ~
16024 mov
16025  @r0,a
16026 \newline
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 djnz r0,00004$
16036 \newline
16037 ; _mcs51_genRAMCLEAR() end
16038 \end_layout
16039
16040 \begin_layout Verse
16041
16042 \family typewriter
16043 \series bold
16044 \size footnotesize
16045 (crtxclear.asm)
16046 \end_layout
16047
16048 \begin_layout Verse
16049
16050 \family typewriter
16051 \size footnotesize
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 \InsetSpace ~
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 .area GSINIT4 (CODE)
16061 \newline
16062 __mcs51_genXRAMCLEAR::
16063 \newline
16064 \InsetSpace ~
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 mov r0,#l_PSEG
16073 \newline
16074 \InsetSpace ~
16075 \InsetSpace ~
16076 \InsetSpace ~
16077 \InsetSpace ~
16078 \InsetSpace ~
16079 \InsetSpace ~
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 mov a,r0
16083 \newline
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 \InsetSpace ~
16089 \InsetSpace ~
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 orl a,#(l_PSEG
16093  >> 8)
16094 \newline
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 \InsetSpace ~
16101 \InsetSpace ~
16102 \InsetSpace ~
16103 jz 00006$
16104 \newline
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 \InsetSpace ~
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 mov r1,#s_PSEG
16114 \newline
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 \InsetSpace ~
16121 \InsetSpace ~
16122 \InsetSpace ~
16123 mov __XPAGE,#(s_PSEG >> 8)
16124 \newline
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 \InsetSpace ~
16131 \InsetSpace ~
16132 \InsetSpace ~
16133 clr a
16134 \newline
16135 00005$:\InsetSpace ~
16136 movx
16137  @r1,a
16138 \newline
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 \InsetSpace ~
16142 \InsetSpace ~
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 inc r1
16148 \newline
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 \InsetSpace ~
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 djnz r0,00005$
16158 \newline
16159 00006$:
16160 \newline
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 mov r0,#l_XSEG
16170 \newline
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 mov a,r0
16180 \newline
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 \InsetSpace ~
16186 \InsetSpace ~
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 orl a,#(l_XSEG >>
16190  8)
16191 \newline
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 jz 00008$
16201 \newline
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 mov r1,#((l_XSEG + 255) >> 8)
16211 \newline
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 mov dptr,#s_XSEG
16221 \newline
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 clr a
16231 \newline
16232 00007$:\InsetSpace ~
16233 movx
16234  @dptr,a
16235 \newline
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 inc dptr
16245 \newline
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 djnz r0,00007$
16255 \newline
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 \InsetSpace ~
16263 \InsetSpace ~
16264 djnz r1,00007$
16265 \newline
16266 00008$:
16267 \end_layout
16268
16269 \begin_layout Verse
16270
16271 \family typewriter
16272 \series bold
16273 \size footnotesize
16274 (crtxstack.asm)
16275 \end_layout
16276
16277 \begin_layout Verse
16278
16279 \family typewriter
16280 \size footnotesize
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 \InsetSpace ~
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 .area GSINIT5 (CODE)
16290 \newline
16291 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16292  modifies __XPAGE
16293 \newline
16294 ; and __mcs51_genRAMCLEAR modifies _spx.
16295 \newline
16296 \InsetSpace ~
16297 \InsetSpace ~
16298 \InsetSpace ~
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 mov __XPAGE,#(__start__x
16305 stack >> 8)
16306 \newline
16307 \InsetSpace ~
16308 \InsetSpace ~
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 \InsetSpace ~
16314 \InsetSpace ~
16315 mov _spx,#__start__xstack
16316 \end_layout
16317
16318 \begin_layout Verse
16319
16320 \family typewriter
16321 \series bold
16322 \size footnotesize
16323 (application modules)
16324 \end_layout
16325
16326 \begin_layout Verse
16327
16328 \family typewriter
16329 \size footnotesize
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 .area GSINIT (CODE)
16339 \end_layout
16340
16341 \begin_layout Verse
16342
16343 \family typewriter
16344 \series bold
16345 \size footnotesize
16346 (main.asm)
16347 \end_layout
16348
16349 \begin_layout Verse
16350
16351 \family typewriter
16352 \size footnotesize
16353 \InsetSpace ~
16354 \InsetSpace ~
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 .area GSFINAL (CODE)
16362 \newline
16363 \InsetSpace ~
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 \InsetSpace ~
16367 \InsetSpace ~
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 ljmp __sdcc_program_startup
16372 \newline
16373 ;---------------------------------
16374 -----------------------
16375 \newline
16376 ; Home
16377 \newline
16378 ;--------------------------------------------------
16379 ------
16380 \newline
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 \InsetSpace ~
16389 .area HOME (CODE)
16390 \newline
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 .area CSEG (CODE)
16400 \newline
16401 __sdcc_program_startup:
16402 \newline
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 lcall _main
16412 \newline
16413 ;
16414  return from main will lock up
16415 \newline
16416 \InsetSpace ~
16417 \InsetSpace ~
16418 \InsetSpace ~
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 sjmp .
16425 \end_layout
16426
16427 \begin_layout Standard
16428 One of these modules (crtstart.asm) contains a call to the C routine 
16429 \emph on
16430 _sdcc_external_startup()
16431 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16432
16433 \end_inset
16434
16435
16436 \series bold
16437 \emph default
16438  
16439 \series default
16440 at the start of the CODE area.
16441  This routine is also in the runtime library
16442 \begin_inset LatexCommand \index{Runtime library}
16443
16444 \end_inset
16445
16446  and returns 0 by default.
16447  If this routine returns a non-zero value, the static & global variable
16448  initialization will be skipped and the function main will be invoked.
16449  Otherwise static & global variables will be initialized before the function
16450  main is invoked.
16451  You could add an 
16452 \emph on
16453 _sdcc_external_startup()
16454 \emph default
16455  routine to your program to override the default if you need to setup hardware
16456  or perform some other critical operation prior to static & global variable
16457  initialization
16458 \begin_inset LatexCommand \index{Variable initialization}
16459
16460 \end_inset
16461
16462 .
16463  On some mcs51 variants xdata
16464 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16465
16466 \end_inset
16467
16468  memory has to be explicitly enabled before it can be accessed or if the
16469  watchdog
16470 \begin_inset LatexCommand \index{watchdog}
16471
16472 \end_inset
16473
16474  needs to be disabled, this is the place to do it.
16475  The startup code clears all internal data memory, 256 bytes by default,
16476  but from 0 to n-1 if 
16477 \emph on
16478 -
16479 \begin_inset ERT
16480 status collapsed
16481
16482 \begin_layout Standard
16483
16484
16485 \backslash
16486 /
16487 \end_layout
16488
16489 \end_inset
16490
16491 -iram-size
16492 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16493
16494 \end_inset
16495
16496 n
16497 \emph default
16498  is used.
16499  (recommended for Chipcon CC1010).
16500 \end_layout
16501
16502 \begin_layout Standard
16503 See also the compiler options 
16504 \emph on
16505 -
16506 \begin_inset ERT
16507 status collapsed
16508
16509 \begin_layout Standard
16510
16511
16512 \backslash
16513 /
16514 \end_layout
16515
16516 \end_inset
16517
16518 -no-xinit
16519 \emph default
16520 -
16521 \emph on
16522 opt
16523 \emph default
16524
16525 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16526
16527 \end_inset
16528
16529
16530 \emph on
16531 -
16532 \begin_inset ERT
16533 status collapsed
16534
16535 \begin_layout Standard
16536
16537
16538 \backslash
16539 /
16540 \end_layout
16541
16542 \end_inset
16543
16544 -main-return
16545 \emph default
16546
16547 \begin_inset LatexCommand \index{-\/-main-return}
16548
16549 \end_inset
16550
16551  and section 
16552 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16553
16554 \end_inset
16555
16556  about MCS51-variants.
16557 \newline
16558
16559 \end_layout
16560
16561 \begin_layout Standard
16562 While these initialization modules are meant as generic startup code there
16563  might be the need for customization.
16564  Let's assume the return value of 
16565 \emph on
16566 _sdcc_external_startup()
16567 \emph default
16568  in 
16569 \emph on
16570 crtstart.asm
16571 \emph default
16572  should not be checked (or 
16573 \emph on
16574 _sdcc_external_startup()
16575 \emph default
16576  should not be called at all).
16577  The recommended way would be to copy 
16578 \emph on
16579 crtstart.asm
16580 \emph default
16581  (f.e.
16582  from 
16583 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16584
16585 \end_inset
16586
16587 ) into the source directory, adapt it there, then assemble it with 
16588 \emph on
16589 asx8051 -plosgff
16590 \begin_inset Foot
16591 status open
16592
16593 \begin_layout Standard
16594 \begin_inset Quotes sld
16595 \end_inset
16596
16597 -plosgff
16598 \begin_inset Quotes srd
16599 \end_inset
16600
16601  are the assembler options used in 
16602 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16603
16604 \end_inset
16605
16606
16607 \end_layout
16608
16609 \end_inset
16610
16611  crtstart.asm
16612 \emph default
16613  and when linking your project explicitely specify 
16614 \emph on
16615 crtstart.rel
16616 \emph default
16617 .
16618  As a bonus a listing of the relocated object file 
16619 \emph on
16620 crtstart.rst
16621 \emph default
16622  is generated.
16623 \end_layout
16624
16625 \begin_layout Standard
16626 \begin_inset VSpace bigskip
16627 \end_inset
16628
16629
16630 \end_layout
16631
16632 \begin_layout Subsection
16633 HC08 Startup Code
16634 \end_layout
16635
16636 \begin_layout Standard
16637 The HC08
16638 \begin_inset LatexCommand \index{HC08}
16639
16640 \end_inset
16641
16642  startup code follows the same scheme as the MCS51 startup code.
16643 \begin_inset VSpace bigskip
16644 \end_inset
16645
16646
16647 \end_layout
16648
16649 \begin_layout Subsection
16650 Z80 Startup Code
16651 \end_layout
16652
16653 \begin_layout Standard
16654 On the Z80
16655 \begin_inset LatexCommand \index{Z80}
16656
16657 \end_inset
16658
16659  the startup code is inserted by linking with crt0.o which is generated from
16660  sdcc/device/lib/z80/crt0.s.
16661  If you need a different startup code you can use the compiler option 
16662 \emph on
16663 -
16664 \series bold
16665 \emph default
16666
16667 \begin_inset ERT
16668 status collapsed
16669
16670 \begin_layout Standard
16671
16672
16673 \backslash
16674 /
16675 \end_layout
16676
16677 \end_inset
16678
16679
16680 \series default
16681 \emph on
16682 -no-std-crt0
16683 \emph default
16684
16685 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16686
16687 \end_inset
16688
16689  and provide your own crt0.o.
16690  
16691 \begin_inset VSpace bigskip
16692 \end_inset
16693
16694
16695 \end_layout
16696
16697 \begin_layout Section
16698 Inline Assembler Code
16699 \begin_inset LatexCommand \index{Assembler routines}
16700
16701 \end_inset
16702
16703
16704 \end_layout
16705
16706 \begin_layout Subsection
16707 A Step by Step Introduction
16708 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16709
16710 \end_inset
16711
16712
16713 \end_layout
16714
16715 \begin_layout Standard
16716 Starting from a small snippet of c-code this example shows for the MCS51
16717  how to use inline assembly, access variables, a function parameter and
16718  an array in xdata memory.
16719  The example uses an MCS51 here but is easily adapted for other architectures.
16720  This is a buffer routine which should be optimized:
16721 \end_layout
16722
16723 \begin_layout Verse
16724
16725 \family typewriter
16726 \size footnotesize
16727 unsigned char __far
16728 \begin_inset LatexCommand \index{far (storage class)}
16729
16730 \end_inset
16731
16732
16733 \begin_inset LatexCommand \index{\_\_far (storage class)}
16734
16735 \end_inset
16736
16737  __at
16738 \begin_inset LatexCommand \index{at}
16739
16740 \end_inset
16741
16742
16743 \begin_inset LatexCommand \index{\_\_at}
16744
16745 \end_inset
16746
16747 (0x7f00) buf[0x100];
16748 \begin_inset LatexCommand \index{Aligned array}
16749
16750 \end_inset
16751
16752
16753 \newline
16754 unsigned char head, tail;\InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 /* if interrupts
16772 \begin_inset LatexCommand \index{interrupt}
16773
16774 \end_inset
16775
16776  are involved see
16777 \newline
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 \InsetSpace ~
16800 \InsetSpace ~
16801 \InsetSpace ~
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 section 
16824 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16825
16826 \end_inset
16827
16828  about
16829 \series bold
16830  volatile
16831 \series default
16832  */
16833 \newline
16834
16835 \newline
16836 void to_buffer( unsigned char c ) 
16837 \newline
16838 {
16839 \newline
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 if( head != (unsigned char)(tail-1)
16845  )\InsetSpace ~
16846 /* cast 
16847 \series bold
16848 needed
16849 \series default
16850  to avoid promotion
16851 \begin_inset LatexCommand \index{promotion to signed int}
16852
16853 \end_inset
16854
16855
16856 \begin_inset LatexCommand \index{type promotion}
16857
16858 \end_inset
16859
16860  to integer */
16861 \begin_inset Marginal
16862 status collapsed
16863
16864 \begin_layout Standard
16865
16866 \series bold
16867 \InsetSpace ~
16868 !
16869 \end_layout
16870
16871 \end_inset
16872
16873
16874 \newline
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 \InsetSpace ~
16883 buf[ head++ ] = c;\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 /* access to a 256 byte aligned array */
16900 \newline
16901
16902 \end_layout
16903
16904 \begin_layout Standard
16905 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16906  then a corresponding buffer.asm file is generated.
16907  We define a new function 
16908 \family typewriter
16909 to_buffer_asm()
16910 \family default
16911  in file buffer.c in which we cut and paste the generated code, removing
16912  unwanted comments and some ':'.
16913  Then add 
16914 \begin_inset Quotes sld
16915 \end_inset
16916
16917
16918 \series bold
16919 _asm
16920 \series default
16921
16922 \begin_inset Quotes srd
16923 \end_inset
16924
16925  and 
16926 \begin_inset Quotes sld
16927 \end_inset
16928
16929
16930 \series bold
16931 _endasm;
16932 \series default
16933
16934 \begin_inset Quotes srd
16935 \end_inset
16936
16937
16938 \begin_inset Foot
16939 status open
16940
16941 \begin_layout Standard
16942 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16943  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16944  has to be used.
16945  The latter is also used in the library functions.
16946 \end_layout
16947
16948 \end_inset
16949
16950  to the beginning and the end of the function body:
16951 \end_layout
16952
16953 \begin_layout Verse
16954
16955 \family typewriter
16956 \size footnotesize
16957 /* With a cut and paste from the .asm file, we have something to start with.
16958 \newline
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 The
16963  function is not yet OK! (registers aren't saved) */ 
16964 \newline
16965 void to_buffer_asm(
16966  unsigned char c ) 
16967 \newline
16968
16969 \newline
16970 \InsetSpace ~
16971 \InsetSpace ~
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 _asm
16975 \begin_inset LatexCommand \index{\_asm}
16976
16977 \end_inset
16978
16979
16980 \begin_inset LatexCommand \index{\_\_asm}
16981
16982 \end_inset
16983
16984
16985 \newline
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 mov\InsetSpace ~
16991 \InsetSpace ~
16992 r2,dpl 
16993 \newline
16994 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16995 /* cast 
16996 \series bold
16997 needed
16998 \series default
16999  to avoid promotion
17000 \begin_inset LatexCommand \index{promotion to signed int}
17001
17002 \end_inset
17003
17004
17005 \begin_inset LatexCommand \index{type promotion}
17006
17007 \end_inset
17008
17009  to integer */
17010 \newline
17011 \InsetSpace ~
17012 \InsetSpace ~
17013 \InsetSpace ~
17014 \InsetSpace ~
17015 mov\InsetSpace ~
17016 \InsetSpace ~
17017 a,_tail 
17018 \newline
17019 \InsetSpace ~
17020 \InsetSpace ~
17021 \InsetSpace ~
17022 \InsetSpace ~
17023 dec\InsetSpace ~
17024 \InsetSpace ~
17025
17026 \newline
17027 \InsetSpace ~
17028 \InsetSpace ~
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 mov\InsetSpace ~
17032 \InsetSpace ~
17033 r3,a 
17034 \newline
17035 \InsetSpace ~
17036 \InsetSpace ~
17037 \InsetSpace ~
17038 \InsetSpace ~
17039 mov\InsetSpace ~
17040 \InsetSpace ~
17041 a,_head 
17042 \newline
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 cjne a,ar3,00106$ 
17048 \newline
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 \InsetSpace ~
17052 \InsetSpace ~
17053 ret
17054 \newline
17055 00106$:
17056  
17057 \newline
17058 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17059 \begin_inset LatexCommand \index{Aligned array}
17060
17061 \end_inset
17062
17063
17064 \newline
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 mov\InsetSpace ~
17070 \InsetSpace ~
17071 r3,_head 
17072 \newline
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 \InsetSpace ~
17077 inc\InsetSpace ~
17078 \InsetSpace ~
17079 _head 
17080 \newline
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 mov\InsetSpace ~
17086 \InsetSpace ~
17087 dpl,r3 
17088 \newline
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 \InsetSpace ~
17093 mov\InsetSpace ~
17094 \InsetSpace ~
17095 dph,#(_buf >> 8) 
17096 \newline
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 \InsetSpace ~
17101 mov\InsetSpace ~
17102 \InsetSpace ~
17103 a,r2 
17104 \newline
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 movx @dptr,a
17110  
17111 \newline
17112 00103$: 
17113 \newline
17114 \InsetSpace ~
17115 \InsetSpace ~
17116 \InsetSpace ~
17117 \InsetSpace ~
17118 ret
17119 \newline
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 _endasm
17125 \begin_inset LatexCommand \index{\_endasm}
17126
17127 \end_inset
17128
17129
17130 \begin_inset LatexCommand \index{\_\_endasm}
17131
17132 \end_inset
17133
17134 ;
17135 \newline
17136
17137 \end_layout
17138
17139 \begin_layout Standard
17140 The new file buffer.c should compile with only one warning about the unreferenced
17141  function argument 'c'.
17142  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17143  (1) and finally have:
17144 \end_layout
17145
17146 \begin_layout Verse
17147
17148 \family typewriter
17149 \size footnotesize
17150 unsigned char __far __at(0x7f00) buf[0x100];
17151 \newline
17152 unsigned char head, tail;
17153 \newline
17154 #define
17155  USE_ASSEMBLY (1)
17156 \newline
17157
17158 \newline
17159 #if !USE_ASSEMBLY
17160 \newline
17161
17162 \newline
17163 void to_buffer( unsigned char c )
17164 \newline
17165 {
17166 \newline
17167 \InsetSpace ~
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 if(
17172  head != (unsigned char)(tail-1) )
17173 \newline
17174 \InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 buf[ head++ ] = c;
17183 \newline
17184 }
17185 \newline
17186
17187 \newline
17188 #else
17189 \newline
17190
17191 \newline
17192 void to_buffer(
17193  unsigned char c )
17194 \newline
17195 {
17196 \newline
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 c; // to avoid warning: unreferenced function argument
17202 \newline
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 _asm
17208 \begin_inset LatexCommand \index{\_asm}
17209
17210 \end_inset
17211
17212
17213 \begin_inset LatexCommand \index{\_\_asm}
17214
17215 \end_inset
17216
17217
17218 \newline
17219 \InsetSpace ~
17220 \InsetSpace ~
17221 \InsetSpace ~
17222 \InsetSpace ~
17223 \InsetSpace ~
17224 \InsetSpace ~
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 ; save used registers here.
17228  
17229 \newline
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 ; If we were still using r2,r3 we would have to push them here.
17239  
17240 \newline
17241 ; if( head != (unsigned char)(tail-1) )
17242 \newline
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 \InsetSpace ~
17246 \InsetSpace ~
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 mov\InsetSpace ~
17252  a,_tail
17253 \newline
17254 \InsetSpace ~
17255 \InsetSpace ~
17256 \InsetSpace ~
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 dec\InsetSpace ~
17263  a
17264 \newline
17265 \InsetSpace ~
17266 \InsetSpace ~
17267 \InsetSpace ~
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 \InsetSpace ~
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 xrl\InsetSpace ~
17274  a,_head
17275 \newline
17276 \InsetSpace ~
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 \InsetSpace ~
17280 \InsetSpace ~
17281 \InsetSpace ~
17282 \InsetSpace ~
17283 \InsetSpace ~
17284 ; we
17285  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17286 \newline
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 \InsetSpace ~
17290 \InsetSpace ~
17291 \InsetSpace ~
17292 \InsetSpace ~
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 jz\InsetSpace ~
17296 \InsetSpace ~
17297  t_b_end$
17298 \newline
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 \InsetSpace ~
17302 \InsetSpace ~
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 ;
17308 \newline
17309 ;
17310  buf[ head++ ] = c;
17311 \newline
17312 \InsetSpace ~
17313 \InsetSpace ~
17314 \InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 mov\InsetSpace ~
17321  a,dpl \InsetSpace ~
17322 \InsetSpace ~
17323 \InsetSpace ~
17324 \InsetSpace ~
17325 \InsetSpace ~
17326 \InsetSpace ~
17327 \InsetSpace ~
17328 ; dpl holds lower byte of function argument
17329 \newline
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 \InsetSpace ~
17334 \InsetSpace ~
17335 \InsetSpace ~
17336 \InsetSpace ~
17337 \InsetSpace ~
17338 mov\InsetSpace ~
17339
17340  dpl,_head \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 ; buf is 0x100 byte aligned so head can be used directly
17344 \newline
17345 \InsetSpace ~
17346 \InsetSpace ~
17347 \InsetSpace ~
17348 \InsetSpace ~
17349 \InsetSpace ~
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 mov\InsetSpace ~
17354  dph,#(_bu
17355 f>>8)
17356 \newline
17357 \InsetSpace ~
17358 \InsetSpace ~
17359 \InsetSpace ~
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 movx @dptr,a
17366 \newline
17367 \InsetSpace ~
17368 \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 \InsetSpace ~
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 inc \InsetSpace ~
17376 _head
17377 \newline
17378 \InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 \InsetSpace ~
17382 \InsetSpace ~
17383 \InsetSpace ~
17384 \InsetSpace ~
17385 \InsetSpace ~
17386 ; we could do an ANL _head,#0x0f here to use a
17387  smaller buffer (see above)
17388 \newline
17389 t_b_end$:
17390 \newline
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 \InsetSpace ~
17394 \InsetSpace ~
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 ; restore used registers here 
17400 \newline
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 \InsetSpace ~
17404 \InsetSpace ~
17405 _endasm
17406 \begin_inset LatexCommand \index{\_endasm}
17407
17408 \end_inset
17409
17410
17411 \begin_inset LatexCommand \index{\_\_endasm}
17412
17413 \end_inset
17414
17415 ;
17416 \newline
17417 }
17418 \newline
17419 #endif
17420 \end_layout
17421
17422 \begin_layout Standard
17423 The inline assembler code can contain any valid code understood by the assembler
17424 , this includes any assembler directives and comment lines.
17425  The assembler does not like some characters like ':' or ''' in comments.
17426  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17427 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17428
17429 \end_inset
17430
17431
17432 \begin_inset LatexCommand \index{Assembler documentation}
17433
17434 \end_inset
17435
17436  or online at 
17437 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17438
17439 \end_inset
17440
17441 \InsetSpace ~
17442 .
17443 \end_layout
17444
17445 \begin_layout Standard
17446 The compiler does not do any validation of the code within the 
17447 \family typewriter
17448 _asm
17449 \begin_inset LatexCommand \index{\_asm}
17450
17451 \end_inset
17452
17453
17454 \begin_inset LatexCommand \index{\_\_asm}
17455
17456 \end_inset
17457
17458  ...
17459  _endasm
17460 \size footnotesize
17461
17462 \begin_inset LatexCommand \index{\_endasm}
17463
17464 \end_inset
17465
17466
17467 \begin_inset LatexCommand \index{\_\_endasm}
17468
17469 \end_inset
17470
17471
17472 \size default
17473 ;
17474 \family default
17475  keyword pair.
17476  Specifically it will not know which registers are used and thus register
17477  pushing/popping
17478 \begin_inset LatexCommand \index{push/pop}
17479
17480 \end_inset
17481
17482  has to be done manually.
17483  
17484 \end_layout
17485
17486 \begin_layout Standard
17487 It is recommended that each assembly instruction (including labels) be placed
17488  in a separate line (as the example shows).
17489  When the -
17490 \begin_inset ERT
17491 status collapsed
17492
17493 \begin_layout Standard
17494
17495
17496 \backslash
17497 /
17498 \end_layout
17499
17500 \end_inset
17501
17502 -
17503 \emph on
17504 peep-asm
17505 \begin_inset LatexCommand \index{-\/-peep-asm}
17506
17507 \end_inset
17508
17509
17510 \emph default
17511  command line option is used, the inline assembler code will be passed through
17512  the peephole optimizer
17513 \begin_inset LatexCommand \index{Peephole optimizer}
17514
17515 \end_inset
17516
17517 .
17518  There are only a few (if any) cases where this option makes sense, it might
17519  cause some unexpected changes in the inline assembler code.
17520  Please go through the peephole optimizer rules defined in file 
17521 \emph on
17522 SDCCpeeph.def
17523 \emph default
17524  before using this option.
17525 \end_layout
17526
17527 \begin_layout Subsection
17528 Naked Functions
17529 \begin_inset LatexCommand \label{sub:Naked-Functions}
17530
17531 \end_inset
17532
17533
17534 \begin_inset LatexCommand \index{Naked functions}
17535
17536 \end_inset
17537
17538
17539 \end_layout
17540
17541 \begin_layout Standard
17542 A special keyword may be associated with a function declaring it as 
17543 \emph on
17544 _naked
17545 \begin_inset LatexCommand \index{\_naked}
17546
17547 \end_inset
17548
17549
17550 \begin_inset LatexCommand \index{\_\_naked}
17551
17552 \end_inset
17553
17554 .
17555  
17556 \emph default
17557 The 
17558 \emph on
17559 _naked
17560 \emph default
17561  function modifier attribute prevents the compiler from generating prologue
17562 \begin_inset LatexCommand \index{function prologue}
17563
17564 \end_inset
17565
17566  and epilogue
17567 \begin_inset LatexCommand \index{function epilogue}
17568
17569 \end_inset
17570
17571  code for that function.
17572  This means that the user is entirely responsible for such things as saving
17573  any registers that may need to be preserved, selecting the proper register
17574  bank, generating the 
17575 \emph on
17576 return
17577 \emph default
17578  instruction at the end, etc.
17579  Practically, this means that the contents of the function must be written
17580  in inline assembler.
17581  This is particularly useful for interrupt functions, which can have a large
17582  (and often unnecessary) prologue/epilogue.
17583  For example, compare the code generated by these two functions:
17584 \end_layout
17585
17586 \begin_layout Verse
17587
17588 \family typewriter
17589 volatile
17590 \begin_inset LatexCommand \index{volatile}
17591
17592 \end_inset
17593
17594  data unsigned char counter;
17595 \newline
17596
17597 \newline
17598 void simpleInterrupt(void) __interrupt
17599 \begin_inset LatexCommand \index{interrupt}
17600
17601 \end_inset
17602
17603
17604 \begin_inset LatexCommand \index{\_\_interrupt}
17605
17606 \end_inset
17607
17608  (1)
17609 \newline
17610 {
17611 \newline
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 \InsetSpace ~
17616 counter++;
17617 \newline
17618 }
17619 \newline
17620
17621 \newline
17622 void nakedInterrupt(void) __interrupt (2) __naked
17623 \newline
17624 {
17625 \newline
17626 \InsetSpace ~
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 _asm
17631 \begin_inset LatexCommand \index{\_asm}
17632
17633 \end_inset
17634
17635
17636 \begin_inset LatexCommand \index{\_\_asm}
17637
17638 \end_inset
17639
17640
17641 \newline
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 \InsetSpace ~
17645 \InsetSpace ~
17646 \InsetSpace ~
17647 \InsetSpace ~
17648 inc\InsetSpace ~
17649 \InsetSpace ~
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 \InsetSpace ~
17653 _counter ; does not change flags, no need to save psw
17654 \newline
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 \InsetSpace ~
17659 \InsetSpace ~
17660 \InsetSpace ~
17661 reti\InsetSpace ~
17662 \InsetSpace ~
17663 \InsetSpace ~
17664 \InsetSpace ~
17665 ; MUST explicitly
17666  include ret or reti in _naked function.
17667 \newline
17668 \InsetSpace ~
17669 \InsetSpace ~
17670 \InsetSpace ~
17671 \InsetSpace ~
17672 _endasm
17673 \begin_inset LatexCommand \index{\_endasm}
17674
17675 \end_inset
17676
17677
17678 \begin_inset LatexCommand \index{\_\_endasm}
17679
17680 \end_inset
17681
17682 ;
17683 \newline
17684 }
17685 \end_layout
17686
17687 \begin_layout Standard
17688 For an 8051 target, the generated simpleInterrupt looks like:
17689 \end_layout
17690
17691 \begin_layout Verse
17692
17693 \family typewriter
17694 Note, this is an 
17695 \emph on
17696 outdated
17697 \emph default
17698  example, recent versions of SDCC generate
17699 \newline
17700 the 
17701 \emph on
17702 same
17703 \emph default
17704  code for simpleInterrupt() and nakedInterrupt()!
17705 \newline
17706
17707 \newline
17708 _simpleInterrupt:
17709 \newline
17710 \InsetSpace ~
17711 \InsetSpace ~
17712 \InsetSpace ~
17713 \InsetSpace ~
17714 push\InsetSpace ~
17715 \InsetSpace ~
17716 \InsetSpace ~
17717 \InsetSpace ~
17718 acc
17719 \newline
17720 \InsetSpace ~
17721 \InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 push\InsetSpace ~
17725 \InsetSpace ~
17726 \InsetSpace ~
17727 \InsetSpace ~
17728 b
17729 \newline
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 pu
17735 sh\InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 \InsetSpace ~
17739 dpl
17740 \newline
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 push\InsetSpace ~
17746 \InsetSpace ~
17747 \InsetSpace ~
17748 \InsetSpace ~
17749 dph
17750 \newline
17751 \InsetSpace ~
17752 \InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 push\InsetSpace ~
17756 \InsetSpace ~
17757 \InsetSpace ~
17758 \InsetSpace ~
17759 psw
17760 \newline
17761 \InsetSpace ~
17762 \InsetSpace ~
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 mov\InsetSpace ~
17766 \InsetSpace ~
17767 \InsetSpace ~
17768 \InsetSpace ~
17769 \InsetSpace ~
17770 psw,#0x00
17771 \newline
17772 \InsetSpace ~
17773 \InsetSpace ~
17774 \InsetSpace ~
17775 \InsetSpace ~
17776 inc\InsetSpace ~
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 _counter
17782 \newline
17783 \InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 pop\InsetSpace ~
17788 \InsetSpace ~
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 psw
17793 \newline
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 \InsetSpace ~
17798 pop\InsetSpace ~
17799 \InsetSpace ~
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 dph
17804 \newline
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 pop\InsetSpace ~
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 dpl
17815 \newline
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 \InsetSpace ~
17820 pop\InsetSpace ~
17821 \InsetSpace ~
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 b
17826 \newline
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 pop\InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 acc
17837 \newline
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 reti
17843 \end_layout
17844
17845 \begin_layout Standard
17846 whereas nakedInterrupt looks like:
17847 \end_layout
17848
17849 \begin_layout Verse
17850
17851 \family typewriter
17852 _nakedInterrupt:
17853 \newline
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 inc\InsetSpace ~
17859 \InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 _counter ; does not change flags, no need to save psw
17863 \newline
17864 \InsetSpace ~
17865 \InsetSpace ~
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 reti\InsetSpace ~
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 \InsetSpace ~
17873 \InsetSpace ~
17874 \InsetSpace ~
17875 \InsetSpace ~
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 ;
17881  MUST explicitly include ret or reti in _naked function
17882 \end_layout
17883
17884 \begin_layout Standard
17885 The related directive #pragma exclude
17886 \begin_inset LatexCommand \index{\#pragma exclude}
17887
17888 \end_inset
17889
17890  allows a more fine grained control over pushing & popping
17891 \begin_inset LatexCommand \index{push/pop}
17892
17893 \end_inset
17894
17895  the registers.
17896 \end_layout
17897
17898 \begin_layout Standard
17899 While there is nothing preventing you from writing C code inside a 
17900 \family typewriter
17901 _naked
17902 \family default
17903  function, there are many ways to shoot yourself in the foot doing this,
17904  and it is recommended that you stick to inline assembler.
17905 \end_layout
17906
17907 \begin_layout Subsection
17908 Use of Labels within Inline Assembler
17909 \end_layout
17910
17911 \begin_layout Standard
17912 SDCC allows the use of in-line assembler with a few restrictions regarding
17913  labels.
17914  All labels defined within inline assembler code have to be of the form
17915  
17916 \emph on
17917 nnnnn$
17918 \emph default
17919  where nnnnn is a number less than 100 (which implies a limit of utmost
17920  100 inline assembler labels 
17921 \emph on
17922 per function
17923 \emph default
17924 \noun on
17925 )
17926 \noun default
17927 .
17928 \begin_inset Foot
17929 status open
17930
17931 \begin_layout Standard
17932 This is a slightly more stringent rule than absolutely necessary, but stays
17933  always on the safe side.
17934  Labels in the form of nnnnn$ are local labels in the assembler, locality
17935  of which is confined within two labels of the standard form.
17936  The compiler uses the same form for labels within a function (but starting
17937  from nnnnn=00100); and places always a standard label at the beginning
17938  of a function, thus limiting the locality of labels within the scope of
17939  the function.
17940  So, if the inline assembler part would be embedded into C-code, an improperly
17941  placed non-local label in the assembler would break up the reference space
17942  for labels created by the compiler for the C-code, leading to an assembling
17943  error.
17944 \end_layout
17945
17946 \begin_layout Standard
17947 The numeric part of local labels does not need to have 5 digits (although
17948  this is the form of labels output by the compiler), any valid integer will
17949  do.
17950  Please refer to the assemblers documentation for further details.
17951 \end_layout
17952
17953 \end_inset
17954
17955  
17956 \end_layout
17957
17958 \begin_layout Verse
17959
17960 \family typewriter
17961 _asm
17962 \begin_inset LatexCommand \index{\_asm}
17963
17964 \end_inset
17965
17966
17967 \begin_inset LatexCommand \index{\_\_asm}
17968
17969 \end_inset
17970
17971  
17972 \newline
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 \InsetSpace ~
17976 \InsetSpace ~
17977 mov\InsetSpace ~
17978 \InsetSpace ~
17979 \InsetSpace ~
17980 \InsetSpace ~
17981 \InsetSpace ~
17982 b,#10 
17983 \newline
17984 00001$: 
17985 \newline
17986 \InsetSpace ~
17987 \InsetSpace ~
17988 \InsetSpace ~
17989 \InsetSpace ~
17990 djnz\InsetSpace ~
17991 \InsetSpace ~
17992 \InsetSpace ~
17993 \InsetSpace ~
17994 b,00001$ 
17995 \newline
17996 _endasm
17997 \begin_inset LatexCommand \index{\_endasm}
17998
17999 \end_inset
18000
18001
18002 \begin_inset LatexCommand \index{\_\_endasm}
18003
18004 \end_inset
18005
18006  ;
18007 \end_layout
18008
18009 \begin_layout Standard
18010 Inline assembler code cannot reference any C-labels, however it can reference
18011  labels
18012 \begin_inset LatexCommand \index{Labels}
18013
18014 \end_inset
18015
18016  defined by the inline assembler, e.g.:
18017 \end_layout
18018
18019 \begin_layout Verse
18020
18021 \family typewriter
18022 foo() { 
18023 \newline
18024 \InsetSpace ~
18025 \InsetSpace ~
18026 \InsetSpace ~
18027 \InsetSpace ~
18028 /* some c code */ 
18029 \newline
18030 \InsetSpace ~
18031 \InsetSpace ~
18032 \InsetSpace ~
18033 \InsetSpace ~
18034 _asm 
18035 \newline
18036 \InsetSpace ~
18037 \InsetSpace ~
18038 \InsetSpace ~
18039 \InsetSpace ~
18040 \InsetSpace ~
18041 \InsetSpace ~
18042 ; some assembler code 
18043 \newline
18044 \InsetSpace ~
18045 \InsetSpace ~
18046 \InsetSpace ~
18047 \InsetSpace ~
18048 \InsetSpace ~
18049 \InsetSpace ~
18050 ljmp 0003$ 
18051 \newline
18052 \InsetSpace ~
18053 \InsetSpace ~
18054 \InsetSpace ~
18055 \InsetSpace ~
18056 _endasm;
18057  
18058 \newline
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 \InsetSpace ~
18062 \InsetSpace ~
18063 /* some more c code */ 
18064 \newline
18065 clabel:\InsetSpace ~
18066 \InsetSpace ~
18067 /* inline assembler cannot reference this
18068  label */ 
18069 \begin_inset Foot
18070 status open
18071
18072 \begin_layout Standard
18073 Here, the C-label 
18074 \family typewriter
18075 clabel
18076 \family default
18077  is translated by the compiler into a local label, so the locality of labels
18078  within the function is not broken.
18079 \end_layout
18080
18081 \end_inset
18082
18083
18084 \newline
18085 \InsetSpace ~
18086 \InsetSpace ~
18087 \InsetSpace ~
18088 \InsetSpace ~
18089 _asm
18090 \newline
18091 \InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 \InsetSpace ~
18095 0003$: ;label (can be referenced by inline assembler only) 
18096 \newline
18097 \InsetSpace ~
18098 \InsetSpace ~
18099 \InsetSpace ~
18100 \InsetSpace ~
18101 _endasm
18102 \begin_inset LatexCommand \index{\_endasm}
18103
18104 \end_inset
18105
18106
18107 \begin_inset LatexCommand \index{\_\_endasm}
18108
18109 \end_inset
18110
18111  ; 
18112 \newline
18113 \InsetSpace ~
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 /* some more c code */
18118 \newline
18119 }
18120 \end_layout
18121
18122 \begin_layout Standard
18123 In other words inline assembly code can access labels defined in inline
18124  assembly within the scope of the function.
18125  The same goes the other way, i.e.
18126  labels defines in inline assembly can not be accessed by C statements.
18127 \end_layout
18128
18129 \begin_layout Section
18130 Interfacing with Assembler Code
18131 \begin_inset LatexCommand \index{Assembler routines}
18132
18133 \end_inset
18134
18135
18136 \end_layout
18137
18138 \begin_layout Subsection
18139 Global Registers used for Parameter Passing
18140 \begin_inset LatexCommand \index{Parameter passing}
18141
18142 \end_inset
18143
18144
18145 \end_layout
18146
18147 \begin_layout Standard
18148 The compiler always uses the global registers 
18149 \emph on
18150 DPL, DPH
18151 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18152
18153 \end_inset
18154
18155
18156 \begin_inset LatexCommand \index{DPTR}
18157
18158 \end_inset
18159
18160 , B
18161 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18162
18163 \end_inset
18164
18165  
18166 \emph default
18167 and
18168 \emph on
18169  ACC
18170 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18171
18172 \end_inset
18173
18174
18175 \emph default
18176  to pass the first (non-bit) parameter to a function, and also to pass the
18177  return value 
18178 \begin_inset LatexCommand \index{return value}
18179
18180 \end_inset
18181
18182 of function; according to the following scheme: one byte return value in
18183  
18184 \emph on
18185 DPL
18186 \emph default
18187 , two byte value in 
18188 \emph on
18189 DPL
18190 \emph default
18191  (LSB) and 
18192 \emph on
18193 DPH
18194 \emph default
18195  (MSB).
18196  three byte values (generic pointers) in 
18197 \emph on
18198 DPH
18199 \emph default
18200
18201 \emph on
18202 DPL
18203 \emph default
18204  and 
18205 \emph on
18206 B
18207 \emph default
18208 , and four byte values in 
18209 \emph on
18210 DPH
18211 \emph default
18212
18213 \emph on
18214 DPL
18215 \emph default
18216 ,
18217 \emph on
18218  B
18219 \emph default
18220  and 
18221 \emph on
18222 ACC
18223 \emph default
18224 .
18225  Generic pointers
18226 \begin_inset LatexCommand \index{generic pointer}
18227
18228 \end_inset
18229
18230  contain type of accessed memory in 
18231 \emph on
18232 B
18233 \emph default
18234
18235 \series bold
18236 0x00
18237 \series default
18238  -- xdata/far, 
18239 \series bold
18240 0x40
18241 \series default
18242  -- idata/near -- , 
18243 \series bold
18244 0x60
18245 \series default
18246  -- pdata, 
18247 \series bold
18248 0x80
18249 \series default
18250  -- code
18251 \begin_inset Note Note
18252 status collapsed
18253
18254 \begin_layout Standard
18255 This might not be the case of certain memory models (medium???)
18256 \end_layout
18257
18258 \end_inset
18259
18260 .
18261 \end_layout
18262
18263 \begin_layout Standard
18264 The second parameter onwards is either allocated on the stack (for reentrant
18265  routines or if -
18266 \begin_inset ERT
18267 status collapsed
18268
18269 \begin_layout Standard
18270
18271
18272 \backslash
18273 /
18274 \end_layout
18275
18276 \end_inset
18277
18278 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18279 \end_layout
18280
18281 \begin_layout Standard
18282 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18283  space for reentrant functions or allocated directly in bit memory otherwise.
18284 \end_layout
18285
18286 \begin_layout Standard
18287 Functions (with two or more parameters or bit parameters) that are called
18288  through function pointers
18289 \begin_inset LatexCommand \index{function pointers}
18290
18291 \end_inset
18292
18293  must therefor be reentrant so the compiler knows how to pass the parameters.
18294 \end_layout
18295
18296 \begin_layout Subsection
18297 Registers usage
18298 \end_layout
18299
18300 \begin_layout Standard
18301 Unless the called function is declared as 
18302 \family typewriter
18303 _naked
18304 \family default
18305
18306 \begin_inset LatexCommand \index{naked}
18307
18308 \end_inset
18309
18310 , or the -
18311 \begin_inset ERT
18312 status collapsed
18313
18314 \begin_layout Standard
18315
18316
18317 \backslash
18318 /
18319 \end_layout
18320
18321 \end_inset
18322
18323 -callee-saves
18324 \begin_inset LatexCommand \index{-\/-callee-saves}
18325
18326 \end_inset
18327
18328 /-
18329 \begin_inset ERT
18330 status collapsed
18331
18332 \begin_layout Standard
18333
18334
18335 \backslash
18336 /
18337 \end_layout
18338
18339 \end_inset
18340
18341 -all-callee-saves command line option or the corresponding callee_saves
18342  pragma are used, the caller will save the registers (
18343 \emph on
18344 R0-R7
18345 \emph default
18346 ) around the call, so the called function can destroy they content freely.
18347 \end_layout
18348
18349 \begin_layout Standard
18350 If the called function is not declared as 
18351 \family typewriter
18352 _naked
18353 \family default
18354 , the caller will swap register banks around the call, if caller and callee
18355  use different register banks (having them defined by the 
18356 \family typewriter
18357 _using
18358 \family default
18359  modifier).
18360  
18361 \end_layout
18362
18363 \begin_layout Standard
18364 The called function can also use 
18365 \emph on
18366 DPL
18367 \emph default
18368
18369 \emph on
18370 DPH
18371 \emph default
18372
18373 \emph on
18374 B
18375 \emph default
18376  and 
18377 \emph on
18378 ACC
18379 \emph default
18380  observing that they are used for parameter/return value passing.
18381 \end_layout
18382
18383 \begin_layout Subsection
18384 Assembler Routine (non-reentrant)
18385 \end_layout
18386
18387 \begin_layout Standard
18388 In the following example
18389 \begin_inset LatexCommand \index{reentrant}
18390
18391 \end_inset
18392
18393
18394 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18395
18396 \end_inset
18397
18398  the function c_func calls an assembler routine asm_func, which takes two
18399  parameters
18400 \begin_inset LatexCommand \index{function parameter}
18401
18402 \end_inset
18403
18404 .
18405 \end_layout
18406
18407 \begin_layout Verse
18408
18409 \family typewriter
18410 extern int asm_func(unsigned char, unsigned char);
18411 \newline
18412
18413 \newline
18414 int c_func (unsigned char
18415  i, unsigned char j)
18416 \newline
18417 {
18418 \newline
18419 \InsetSpace ~
18420 \InsetSpace ~
18421 \InsetSpace ~
18422 \InsetSpace ~
18423 return asm_func(i,j);
18424 \newline
18425 }
18426 \newline
18427
18428 \newline
18429 int main()
18430 \newline
18431 {
18432 \newline
18433 \InsetSpace ~
18434 \InsetSpace ~
18435 \InsetSpace ~
18436 \InsetSpace ~
18437 return c_func(10,9);
18438 \newline
18439 }
18440 \end_layout
18441
18442 \begin_layout Standard
18443 The corresponding assembler function is:
18444 \end_layout
18445
18446 \begin_layout Verse
18447
18448 \family typewriter
18449 .globl _asm_func_PARM_2 
18450 \newline
18451 \InsetSpace ~
18452 \InsetSpace ~
18453 \InsetSpace ~
18454 \InsetSpace ~
18455 \InsetSpace ~
18456 \InsetSpace ~
18457 \InsetSpace ~
18458 \InsetSpace ~
18459 .globl _asm_func 
18460 \newline
18461 \InsetSpace ~
18462 \InsetSpace ~
18463 \InsetSpace ~
18464 \InsetSpace ~
18465 \InsetSpace ~
18466 \InsetSpace ~
18467 \InsetSpace ~
18468 \InsetSpace ~
18469 .area OSEG 
18470 \newline
18471 _asm_func_PARM_2:
18472 \newline
18473 \InsetSpace ~
18474 \InsetSpace ~
18475 \InsetSpace ~
18476 \InsetSpace ~
18477 \InsetSpace ~
18478 \InsetSpace ~
18479 \InsetSpace ~
18480 \InsetSpace ~
18481 .ds   
18482  1 
18483 \newline
18484 \InsetSpace ~
18485 \InsetSpace ~
18486 \InsetSpace ~
18487 \InsetSpace ~
18488 \InsetSpace ~
18489 \InsetSpace ~
18490 \InsetSpace ~
18491 \InsetSpace ~
18492 .area CSEG 
18493 \newline
18494 _asm_func: 
18495 \newline
18496 \InsetSpace ~
18497 \InsetSpace ~
18498 \InsetSpace ~
18499 \InsetSpace ~
18500 \InsetSpace ~
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 mov\InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 a,dpl 
18509 \newline
18510 \InsetSpace ~
18511 \InsetSpace ~
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 add\InsetSpace ~
18519 \InsetSpace ~
18520 \InsetSpace ~
18521 \InsetSpace ~
18522 a,_asm_func_PARM_2 
18523 \newline
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 mov\InsetSpace ~
18533 \InsetSpace ~
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 dpl,a 
18537 \newline
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 \InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 mov\InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 dph
18551 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18552
18553 \end_inset
18554
18555 ,#0x00 
18556 \newline
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 \InsetSpace ~
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 ret
18566 \end_layout
18567
18568 \begin_layout Standard
18569 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18570  the parameter number starting from 1, and counting from the left.
18571  The first parameter is passed in 
18572 \emph on
18573 DPH
18574 \emph default
18575
18576 \emph on
18577 DPL
18578 \emph default
18579
18580 \emph on
18581 B
18582 \emph default
18583  and 
18584 \emph on
18585 ACC
18586 \emph default
18587  according to the description above.
18588  The variable name for the second parameter will be _<function_name>_PARM_2.
18589 \newline
18590
18591 \newline
18592 Assem
18593 ble the assembler routine with the following command:
18594 \newline
18595
18596 \newline
18597
18598 \family sans
18599 \series bold
18600 asx8051 -losg asmfunc.asm
18601 \newline
18602
18603 \newline
18604
18605 \family default
18606 \series default
18607 Then compile and link the assembler routine to the C source file with the
18608  following command:
18609 \newline
18610
18611 \newline
18612
18613 \family sans
18614 \series bold
18615 sdcc cfunc.c asmfunc.rel
18616 \end_layout
18617
18618 \begin_layout Subsection
18619 Assembler Routine (reentrant)
18620 \end_layout
18621
18622 \begin_layout Standard
18623 In this case
18624 \begin_inset LatexCommand \index{reentrant}
18625
18626 \end_inset
18627
18628
18629 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18630
18631 \end_inset
18632
18633  the second parameter
18634 \begin_inset LatexCommand \index{function parameter}
18635
18636 \end_inset
18637
18638  onwards will be passed on the stack, the parameters are pushed from right
18639  to left i.e.
18640  before the call the second leftmost parameter will be on the top of the
18641  stack (the leftmost parameter is passed in registers).
18642  Here is an example:
18643 \end_layout
18644
18645 \begin_layout Verse
18646
18647 \family typewriter
18648 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18649 \newline
18650
18651 \newline
18652 int
18653  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18654 \newline
18655 {
18656  
18657 \newline
18658 \InsetSpace ~
18659 \InsetSpace ~
18660 \InsetSpace ~
18661 \InsetSpace ~
18662 return asm_func(i,j,k); 
18663 \newline
18664
18665 \newline
18666
18667 \newline
18668 int main() 
18669 \newline
18670
18671 \newline
18672 \InsetSpace ~
18673 \InsetSpace ~
18674 \InsetSpace ~
18675 \InsetSpace ~
18676 return c_func(10,9,8); 
18677 \newline
18678 }
18679 \end_layout
18680
18681 \begin_layout Standard
18682 The corresponding (unoptimized) assembler routine is:
18683 \end_layout
18684
18685 \begin_layout Verse
18686
18687 \family typewriter
18688 .globl _asm_func 
18689 \newline
18690 _asm_func: 
18691 \newline
18692 \InsetSpace ~
18693 \InsetSpace ~
18694 \InsetSpace ~
18695 \InsetSpace ~
18696 push\InsetSpace ~
18697 _bp 
18698 \newline
18699 \InsetSpace ~
18700 \InsetSpace ~
18701 \InsetSpace ~
18702 \InsetSpace ~
18703 mov\InsetSpace ~
18704 \InsetSpace ~
18705 _bp,sp\InsetSpace ~
18706 \InsetSpace ~
18707 \InsetSpace ~
18708 \InsetSpace ~
18709 \InsetSpace ~
18710 \InsetSpace ~
18711 ;stack contains: _bp, return
18712  address, second parameter, third parameter
18713 \newline
18714 \InsetSpace ~
18715 \InsetSpace ~
18716 \InsetSpace ~
18717 \InsetSpace ~
18718 mov\InsetSpace ~
18719 \InsetSpace ~
18720 r2,dpl
18721 \newline
18722 \InsetSpace ~
18723 \InsetSpace ~
18724 \InsetSpace ~
18725 \InsetSpace ~
18726 mov\InsetSpace ~
18727 \InsetSpace ~
18728 a,_bp
18729 \newline
18730 \InsetSpace ~
18731 \InsetSpace ~
18732 \InsetSpace ~
18733 \InsetSpace ~
18734 add\InsetSpace ~
18735 \InsetSpace ~
18736 a,#0xfd\InsetSpace ~
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 \InsetSpace ~
18740 \InsetSpace ~
18741 ;calculate
18742  pointer to the second parameter
18743 \newline
18744 \InsetSpace ~
18745 \InsetSpace ~
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 mov\InsetSpace ~
18749 \InsetSpace ~
18750 r0,a 
18751 \newline
18752 \InsetSpace ~
18753 \InsetSpace ~
18754 \InsetSpace ~
18755 \InsetSpace ~
18756 mov\InsetSpace ~
18757 \InsetSpace ~
18758 a,_bp 
18759 \newline
18760 \InsetSpace ~
18761 \InsetSpace ~
18762 \InsetSpace ~
18763 \InsetSpace ~
18764 add\InsetSpace ~
18765 \InsetSpace ~
18766 a,#0xfc\InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 \InsetSpace ~
18770 \InsetSpace ~
18771 ;calculate pointer
18772  to the rightmost parameter
18773 \newline
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 \InsetSpace ~
18777 \InsetSpace ~
18778 mov\InsetSpace ~
18779 \InsetSpace ~
18780 r1,a 
18781 \newline
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 \InsetSpace ~
18785 \InsetSpace ~
18786 mov\InsetSpace ~
18787 \InsetSpace ~
18788 a,@r0
18789 \newline
18790 \InsetSpace ~
18791 \InsetSpace ~
18792 \InsetSpace ~
18793 \InsetSpace ~
18794 add\InsetSpace ~
18795 \InsetSpace ~
18796 a,@r1
18797 \newline
18798 \InsetSpace ~
18799 \InsetSpace ~
18800 \InsetSpace ~
18801 \InsetSpace ~
18802 add\InsetSpace ~
18803 \InsetSpace ~
18804 a,r2\InsetSpace ~
18805 \InsetSpace ~
18806 \InsetSpace ~
18807 \InsetSpace ~
18808 \InsetSpace ~
18809 \InsetSpace ~
18810 \InsetSpace ~
18811 \InsetSpace ~
18812 ;calculate the
18813  result (= sum of all three parameters)
18814 \newline
18815 \InsetSpace ~
18816 \InsetSpace ~
18817 \InsetSpace ~
18818 \InsetSpace ~
18819 mov\InsetSpace ~
18820 \InsetSpace ~
18821 dpl,a\InsetSpace ~
18822 \InsetSpace ~
18823 \InsetSpace ~
18824 \InsetSpace ~
18825 \InsetSpace ~
18826 \InsetSpace ~
18827 \InsetSpace ~
18828 ;return value goes into dptr
18829  (cast into int)
18830 \newline
18831 \InsetSpace ~
18832 \InsetSpace ~
18833 \InsetSpace ~
18834 \InsetSpace ~
18835 mov\InsetSpace ~
18836 \InsetSpace ~
18837 dph,#0x00 
18838 \newline
18839 \InsetSpace ~
18840 \InsetSpace ~
18841 \InsetSpace ~
18842 \InsetSpace ~
18843 mov\InsetSpace ~
18844 \InsetSpace ~
18845 sp,_bp 
18846 \newline
18847 \InsetSpace ~
18848 \InsetSpace ~
18849 \InsetSpace ~
18850 \InsetSpace ~
18851 pop\InsetSpace ~
18852 \InsetSpace ~
18853 _bp 
18854 \newline
18855 \InsetSpace ~
18856 \InsetSpace ~
18857 \InsetSpace ~
18858 \InsetSpace ~
18859 ret
18860 \end_layout
18861
18862 \begin_layout Standard
18863 The compiling and linking procedure remains the same, however note the extra
18864  entry & exit linkage required for the assembler code, _bp is the stack
18865  frame pointer and is used to compute the offset into the stack for parameters
18866  and local variables.
18867 \begin_inset VSpace bigskip
18868 \end_inset
18869
18870
18871 \end_layout
18872
18873 \begin_layout Section
18874 int (16 bit)
18875 \begin_inset LatexCommand \index{int (16 bit)}
18876
18877 \end_inset
18878
18879  and long (32 bit)
18880 \begin_inset LatexCommand \index{long (32 bit)}
18881
18882 \end_inset
18883
18884  Support
18885 \end_layout
18886
18887 \begin_layout Standard
18888 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18889  multiplication and modulus operations are implemented by support routines.
18890  These support routines are all developed in ANSI-C to facilitate porting
18891  to other MCUs, although some model specific assembler optimizations are
18892  used.
18893  The following files contain the described routines, all of them can be
18894  found in <installdir>/share/sdcc/lib.
18895 \newline
18896
18897 \end_layout
18898
18899 \begin_layout Standard
18900 \align center
18901 \begin_inset Tabular
18902 <lyxtabular version="3" rows="11" columns="2">
18903 <features>
18904 <column alignment="left" valignment="top" leftline="true" width="0">
18905 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18906 <row topline="true" bottomline="true">
18907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18908 \begin_inset Text
18909
18910 \begin_layout Standard
18911
18912 \series bold
18913 Function
18914 \end_layout
18915
18916 \end_inset
18917 </cell>
18918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18919 \begin_inset Text
18920
18921 \begin_layout Standard
18922
18923 \series bold
18924 Description
18925 \end_layout
18926
18927 \end_inset
18928 </cell>
18929 </row>
18930 <row topline="true">
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18932 \begin_inset Text
18933
18934 \begin_layout Standard
18935 _mulint.c 
18936 \end_layout
18937
18938 \end_inset
18939 </cell>
18940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18941 \begin_inset Text
18942
18943 \begin_layout Standard
18944 16 bit multiplication
18945 \end_layout
18946
18947 \end_inset
18948 </cell>
18949 </row>
18950 <row topline="true">
18951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18952 \begin_inset Text
18953
18954 \begin_layout Standard
18955 _divsint.c 
18956 \end_layout
18957
18958 \end_inset
18959 </cell>
18960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18961 \begin_inset Text
18962
18963 \begin_layout Standard
18964  signed 16 bit division (calls _divuint)
18965 \end_layout
18966
18967 \end_inset
18968 </cell>
18969 </row>
18970 <row topline="true">
18971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18972 \begin_inset Text
18973
18974 \begin_layout Standard
18975 _divuint.c 
18976 \end_layout
18977
18978 \end_inset
18979 </cell>
18980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18981 \begin_inset Text
18982
18983 \begin_layout Standard
18984  unsigned 16 bit division
18985 \end_layout
18986
18987 \end_inset
18988 </cell>
18989 </row>
18990 <row topline="true">
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18992 \begin_inset Text
18993
18994 \begin_layout Standard
18995 _modsint.c
18996 \end_layout
18997
18998 \end_inset
18999 </cell>
19000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19001 \begin_inset Text
19002
19003 \begin_layout Standard
19004 signed 16 bit modulus (calls _moduint)
19005 \end_layout
19006
19007 \end_inset
19008 </cell>
19009 </row>
19010 <row topline="true">
19011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19012 \begin_inset Text
19013
19014 \begin_layout Standard
19015 _moduint.c
19016 \end_layout
19017
19018 \end_inset
19019 </cell>
19020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19021 \begin_inset Text
19022
19023 \begin_layout Standard
19024 unsigned 16 bit modulus
19025 \end_layout
19026
19027 \end_inset
19028 </cell>
19029 </row>
19030 <row topline="true">
19031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19032 \begin_inset Text
19033
19034 \begin_layout Standard
19035 _mullong.c
19036 \end_layout
19037
19038 \end_inset
19039 </cell>
19040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19041 \begin_inset Text
19042
19043 \begin_layout Standard
19044 32 bit multiplication
19045 \end_layout
19046
19047 \end_inset
19048 </cell>
19049 </row>
19050 <row topline="true">
19051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19052 \begin_inset Text
19053
19054 \begin_layout Standard
19055 _divslong.c 
19056 \end_layout
19057
19058 \end_inset
19059 </cell>
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19061 \begin_inset Text
19062
19063 \begin_layout Standard
19064  signed 32 division (calls _divulong)
19065 \end_layout
19066
19067 \end_inset
19068 </cell>
19069 </row>
19070 <row topline="true">
19071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19072 \begin_inset Text
19073
19074 \begin_layout Standard
19075 _divulong.c 
19076 \end_layout
19077
19078 \end_inset
19079 </cell>
19080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19081 \begin_inset Text
19082
19083 \begin_layout Standard
19084 unsigned 32 division
19085 \end_layout
19086
19087 \end_inset
19088 </cell>
19089 </row>
19090 <row topline="true">
19091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19092 \begin_inset Text
19093
19094 \begin_layout Standard
19095 _modslong.c
19096 \end_layout
19097
19098 \end_inset
19099 </cell>
19100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19101 \begin_inset Text
19102
19103 \begin_layout Standard
19104  signed 32 bit modulus (calls _modulong)
19105 \end_layout
19106
19107 \end_inset
19108 </cell>
19109 </row>
19110 <row topline="true" bottomline="true">
19111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19112 \begin_inset Text
19113
19114 \begin_layout Standard
19115 _modulong.c
19116 \end_layout
19117
19118 \end_inset
19119 </cell>
19120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19121 \begin_inset Text
19122
19123 \begin_layout Standard
19124 unsigned 32 bit modulus
19125 \end_layout
19126
19127 \end_inset
19128 </cell>
19129 </row>
19130 </lyxtabular>
19131
19132 \end_inset
19133
19134
19135 \newline
19136
19137 \end_layout
19138
19139 \begin_layout Standard
19140 Since they are compiled as 
19141 \emph on
19142 non-reentrant
19143 \emph default
19144
19145 \begin_inset LatexCommand \index{reentrant}
19146
19147 \end_inset
19148
19149 , interrupt
19150 \begin_inset LatexCommand \index{interrupt}
19151
19152 \end_inset
19153
19154  service routines should not do any of the above operations.
19155  If this is unavoidable then the above routines will need to be compiled
19156  with the 
19157 \emph on
19158 -
19159 \begin_inset ERT
19160 status collapsed
19161
19162 \begin_layout Standard
19163
19164
19165 \backslash
19166 /
19167 \end_layout
19168
19169 \end_inset
19170
19171 -stack-auto
19172 \begin_inset LatexCommand \index{-\/-stack-auto}
19173
19174 \end_inset
19175
19176
19177 \emph default
19178  option, after which the source program will have to be compiled with 
19179 \emph on
19180 -
19181 \begin_inset ERT
19182 status collapsed
19183
19184 \begin_layout Standard
19185
19186
19187 \backslash
19188 /
19189 \end_layout
19190
19191 \end_inset
19192
19193 -int-long-reent
19194 \begin_inset LatexCommand \index{-\/-int-long-reent}
19195
19196 \end_inset
19197
19198
19199 \emph default
19200  option.
19201  Notice that you don't have to call these routines directly.
19202  The compiler will use them automatically every time an integer operation
19203  is required.
19204 \end_layout
19205
19206 \begin_layout Section
19207 Floating Point Support
19208 \begin_inset LatexCommand \index{Floating point support}
19209
19210 \end_inset
19211
19212
19213 \end_layout
19214
19215 \begin_layout Standard
19216 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19217  The floating point support routines are derived from gcc's floatlib.c and
19218  consist of the following routines:
19219 \newline
19220
19221 \end_layout
19222
19223 \begin_layout Standard
19224 \align center
19225
19226 \size footnotesize
19227 \begin_inset Tabular
19228 <lyxtabular version="3" rows="17" columns="2">
19229 <features>
19230 <column alignment="left" valignment="top" leftline="true" width="0">
19231 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19232 <row topline="true" bottomline="true">
19233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19234 \begin_inset Text
19235
19236 \begin_layout Standard
19237
19238 \family roman
19239 \series medium
19240 \shape up
19241 \size normal
19242 \emph off
19243 \bar no
19244 \noun off
19245 \color none
19246 Function 
19247 \end_layout
19248
19249 \end_inset
19250 </cell>
19251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19252 \begin_inset Text
19253
19254 \begin_layout Standard
19255 Description
19256 \end_layout
19257
19258 \end_inset
19259 </cell>
19260 </row>
19261 <row topline="true">
19262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19263 \begin_inset Text
19264
19265 \begin_layout Standard
19266
19267 \family roman
19268 \series medium
19269 \shape up
19270 \size normal
19271 \emph off
19272 \bar no
19273 \noun off
19274 \color none
19275 _fsadd.c
19276 \end_layout
19277
19278 \end_inset
19279 </cell>
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19281 \begin_inset Text
19282
19283 \begin_layout Standard
19284
19285 \family roman
19286 \series medium
19287 \shape up
19288 \size normal
19289 \emph off
19290 \bar no
19291 \noun off
19292 \color none
19293 add floating point numbers
19294 \end_layout
19295
19296 \end_inset
19297 </cell>
19298 </row>
19299 <row topline="true">
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19301 \begin_inset Text
19302
19303 \begin_layout Standard
19304
19305 \family roman
19306 \series medium
19307 \shape up
19308 \size normal
19309 \emph off
19310 \bar no
19311 \noun off
19312 \color none
19313 _fssub.c 
19314 \end_layout
19315
19316 \end_inset
19317 </cell>
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19319 \begin_inset Text
19320
19321 \begin_layout Standard
19322
19323 \family roman
19324 \series medium
19325 \shape up
19326 \size normal
19327 \emph off
19328 \bar no
19329 \noun off
19330 \color none
19331 subtract floating point numbers 
19332 \end_layout
19333
19334 \end_inset
19335 </cell>
19336 </row>
19337 <row topline="true">
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19339 \begin_inset Text
19340
19341 \begin_layout Standard
19342
19343 \family roman
19344 \series medium
19345 \shape up
19346 \size normal
19347 \emph off
19348 \bar no
19349 \noun off
19350 \color none
19351 _fsdiv.c 
19352 \end_layout
19353
19354 \end_inset
19355 </cell>
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19357 \begin_inset Text
19358
19359 \begin_layout Standard
19360
19361 \family roman
19362 \series medium
19363 \shape up
19364 \size normal
19365 \emph off
19366 \bar no
19367 \noun off
19368 \color none
19369 divide floating point numbers 
19370 \end_layout
19371
19372 \end_inset
19373 </cell>
19374 </row>
19375 <row topline="true">
19376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19377 \begin_inset Text
19378
19379 \begin_layout Standard
19380
19381 \family roman
19382 \series medium
19383 \shape up
19384 \size normal
19385 \emph off
19386 \bar no
19387 \noun off
19388 \color none
19389 _fsmul.c 
19390 \end_layout
19391
19392 \end_inset
19393 </cell>
19394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19395 \begin_inset Text
19396
19397 \begin_layout Standard
19398
19399 \family roman
19400 \series medium
19401 \shape up
19402 \size normal
19403 \emph off
19404 \bar no
19405 \noun off
19406 \color none
19407 multiply floating point numbers 
19408 \end_layout
19409
19410 \end_inset
19411 </cell>
19412 </row>
19413 <row topline="true">
19414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19415 \begin_inset Text
19416
19417 \begin_layout Standard
19418
19419 \family roman
19420 \series medium
19421 \shape up
19422 \size normal
19423 \emph off
19424 \bar no
19425 \noun off
19426 \color none
19427 _fs2uchar.c
19428 \end_layout
19429
19430 \end_inset
19431 </cell>
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19433 \begin_inset Text
19434
19435 \begin_layout Standard
19436
19437 \family roman
19438 \series medium
19439 \shape up
19440 \size normal
19441 \emph off
19442 \bar no
19443 \noun off
19444 \color none
19445 convert floating point to unsigned char
19446 \end_layout
19447
19448 \end_inset
19449 </cell>
19450 </row>
19451 <row topline="true">
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19453 \begin_inset Text
19454
19455 \begin_layout Standard
19456
19457 \family roman
19458 \series medium
19459 \shape up
19460 \size normal
19461 \emph off
19462 \bar no
19463 \noun off
19464 \color none
19465 _fs2char.c
19466 \end_layout
19467
19468 \end_inset
19469 </cell>
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19471 \begin_inset Text
19472
19473 \begin_layout Standard
19474
19475 \family roman
19476 \series medium
19477 \shape up
19478 \size normal
19479 \emph off
19480 \bar no
19481 \noun off
19482 \color none
19483 convert floating point to signed char
19484 \end_layout
19485
19486 \end_inset
19487 </cell>
19488 </row>
19489 <row topline="true">
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19491 \begin_inset Text
19492
19493 \begin_layout Standard
19494
19495 \family roman
19496 \series medium
19497 \shape up
19498 \size normal
19499 \emph off
19500 \bar no
19501 \noun off
19502 \color none
19503 _fs2uint.c
19504 \end_layout
19505
19506 \end_inset
19507 </cell>
19508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19509 \begin_inset Text
19510
19511 \begin_layout Standard
19512
19513 \family roman
19514 \series medium
19515 \shape up
19516 \size normal
19517 \emph off
19518 \bar no
19519 \noun off
19520 \color none
19521 convert floating point to unsigned int
19522 \end_layout
19523
19524 \end_inset
19525 </cell>
19526 </row>
19527 <row topline="true">
19528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19529 \begin_inset Text
19530
19531 \begin_layout Standard
19532
19533 \family roman
19534 \series medium
19535 \shape up
19536 \size normal
19537 \emph off
19538 \bar no
19539 \noun off
19540 \color none
19541 _fs2int.c
19542 \end_layout
19543
19544 \end_inset
19545 </cell>
19546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19547 \begin_inset Text
19548
19549 \begin_layout Standard
19550
19551 \family roman
19552 \series medium
19553 \shape up
19554 \size normal
19555 \emph off
19556 \bar no
19557 \noun off
19558 \color none
19559 convert floating point to signed int
19560 \end_layout
19561
19562 \end_inset
19563 </cell>
19564 </row>
19565 <row topline="true">
19566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19567 \begin_inset Text
19568
19569 \begin_layout Standard
19570
19571 \family roman
19572 \series medium
19573 \shape up
19574 \size normal
19575 \emph off
19576 \bar no
19577 \noun off
19578 \color none
19579 _fs2ulong.
19580 \family default
19581 \series default
19582 \shape default
19583 \size default
19584 \emph default
19585 \bar default
19586 \noun default
19587 c
19588 \end_layout
19589
19590 \end_inset
19591 </cell>
19592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19593 \begin_inset Text
19594
19595 \begin_layout Standard
19596
19597 \family roman
19598 \series medium
19599 \shape up
19600 \size normal
19601 \emph off
19602 \bar no
19603 \noun off
19604 \color none
19605 convert floating point to unsigned long
19606 \end_layout
19607
19608 \end_inset
19609 </cell>
19610 </row>
19611 <row topline="true">
19612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19613 \begin_inset Text
19614
19615 \begin_layout Standard
19616
19617 \family roman
19618 \series medium
19619 \shape up
19620 \size normal
19621 \emph off
19622 \bar no
19623 \noun off
19624 \color none
19625 _fs2long.c
19626 \end_layout
19627
19628 \end_inset
19629 </cell>
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19631 \begin_inset Text
19632
19633 \begin_layout Standard
19634
19635 \family roman
19636 \series medium
19637 \shape up
19638 \size normal
19639 \emph off
19640 \bar no
19641 \noun off
19642 \color none
19643 convert floating point to signed long
19644 \end_layout
19645
19646 \end_inset
19647 </cell>
19648 </row>
19649 <row topline="true">
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19651 \begin_inset Text
19652
19653 \begin_layout Standard
19654
19655 \family roman
19656 \series medium
19657 \shape up
19658 \size normal
19659 \emph off
19660 \bar no
19661 \noun off
19662 \color none
19663 _uchar2fs.c
19664 \end_layout
19665
19666 \end_inset
19667 </cell>
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19669 \begin_inset Text
19670
19671 \begin_layout Standard
19672
19673 \family roman
19674 \series medium
19675 \shape up
19676 \size normal
19677 \emph off
19678 \bar no
19679 \noun off
19680 \color none
19681 convert unsigned char to floating point
19682 \end_layout
19683
19684 \end_inset
19685 </cell>
19686 </row>
19687 <row topline="true">
19688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19689 \begin_inset Text
19690
19691 \begin_layout Standard
19692
19693 \family roman
19694 \series medium
19695 \shape up
19696 \size normal
19697 \emph off
19698 \bar no
19699 \noun off
19700 \color none
19701 _char2fs.c
19702 \end_layout
19703
19704 \end_inset
19705 </cell>
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19707 \begin_inset Text
19708
19709 \begin_layout Standard
19710
19711 \family roman
19712 \series medium
19713 \shape up
19714 \size normal
19715 \emph off
19716 \bar no
19717 \noun off
19718 \color none
19719 convert char to floating point number
19720 \end_layout
19721
19722 \end_inset
19723 </cell>
19724 </row>
19725 <row topline="true">
19726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19727 \begin_inset Text
19728
19729 \begin_layout Standard
19730
19731 \family roman
19732 \series medium
19733 \shape up
19734 \size normal
19735 \emph off
19736 \bar no
19737 \noun off
19738 \color none
19739 _uint2fs.c
19740 \end_layout
19741
19742 \end_inset
19743 </cell>
19744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19745 \begin_inset Text
19746
19747 \begin_layout Standard
19748
19749 \family roman
19750 \series medium
19751 \shape up
19752 \size normal
19753 \emph off
19754 \bar no
19755 \noun off
19756 \color none
19757 convert unsigned int to floating point
19758 \end_layout
19759
19760 \end_inset
19761 </cell>
19762 </row>
19763 <row topline="true">
19764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19765 \begin_inset Text
19766
19767 \begin_layout Standard
19768
19769 \family roman
19770 \series medium
19771 \shape up
19772 \size normal
19773 \emph off
19774 \bar no
19775 \noun off
19776 \color none
19777 _int2fs.c
19778 \end_layout
19779
19780 \end_inset
19781 </cell>
19782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19783 \begin_inset Text
19784
19785 \begin_layout Standard
19786
19787 \family roman
19788 \series medium
19789 \shape up
19790 \size normal
19791 \emph off
19792 \bar no
19793 \noun off
19794 \color none
19795 convert int to floating point numbers
19796 \end_layout
19797
19798 \end_inset
19799 </cell>
19800 </row>
19801 <row topline="true">
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \begin_layout Standard
19806
19807 \family roman
19808 \series medium
19809 \shape up
19810 \size normal
19811 \emph off
19812 \bar no
19813 \noun off
19814 \color none
19815 _ulong2fs.c
19816 \end_layout
19817
19818 \end_inset
19819 </cell>
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19821 \begin_inset Text
19822
19823 \begin_layout Standard
19824
19825 \family roman
19826 \series medium
19827 \shape up
19828 \size normal
19829 \emph off
19830 \bar no
19831 \noun off
19832 \color none
19833 convert unsigned long to floating point number
19834 \end_layout
19835
19836 \end_inset
19837 </cell>
19838 </row>
19839 <row topline="true" bottomline="true">
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19841 \begin_inset Text
19842
19843 \begin_layout Standard
19844
19845 \family roman
19846 \series medium
19847 \shape up
19848 \size normal
19849 \emph off
19850 \bar no
19851 \noun off
19852 \color none
19853 _long2fs.c
19854 \end_layout
19855
19856 \end_inset
19857 </cell>
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19859 \begin_inset Text
19860
19861 \begin_layout Standard
19862
19863 \family roman
19864 \series medium
19865 \shape up
19866 \size normal
19867 \emph off
19868 \bar no
19869 \noun off
19870 \color none
19871 convert long to floating point number
19872 \end_layout
19873
19874 \end_inset
19875 </cell>
19876 </row>
19877 </lyxtabular>
19878
19879 \end_inset
19880
19881
19882 \newline
19883
19884 \end_layout
19885
19886 \begin_layout Standard
19887 These support routines are developed in ANSI-C so there is room for space
19888  and speed improvement
19889 \begin_inset Foot
19890 status open
19891
19892 \begin_layout Standard
19893 These floating point routines (
19894 \emph on
19895 not
19896 \emph default
19897  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19898  
19899 \end_layout
19900
19901 \end_inset
19902
19903 .
19904  Note if all these routines are used simultaneously the data space might
19905  overflow.
19906  For serious floating point usage the large model might be needed.
19907  Also notice that you don't have to call this routines directly.
19908  The compiler will use them automatically every time a floating point operation
19909  is required.
19910 \begin_inset VSpace bigskip
19911 \end_inset
19912
19913
19914 \end_layout
19915
19916 \begin_layout Section
19917 Library Routines
19918 \begin_inset LatexCommand \index{Libraries}
19919
19920 \end_inset
19921
19922
19923 \end_layout
19924
19925 \begin_layout Standard
19926
19927 \emph on
19928 <pending: this is messy and incomplete - a little more information is in
19929  sdcc/doc/libdoc.txt
19930 \emph default
19931  >
19932 \end_layout
19933
19934 \begin_layout Subsection
19935 Compiler support routines (_gptrget, _mulint etc.)
19936 \end_layout
19937
19938 \begin_layout Subsection
19939 Stdclib functions (puts, printf, strcat etc.)
19940 \end_layout
19941
19942 \begin_layout Subsubsection
19943 <stdio.h>
19944 \end_layout
19945
19946 \begin_layout Paragraph
19947 getchar(), putchar()
19948 \end_layout
19949
19950 \begin_layout Standard
19951 \begin_inset LatexCommand \index{<stdio.h>}
19952
19953 \end_inset
19954
19955 As usual on embedded systems you have to provide your own 
19956 \family typewriter
19957 getchar()
19958 \begin_inset LatexCommand \index{getchar()}
19959
19960 \end_inset
19961
19962  
19963 \family default
19964 and 
19965 \family typewriter
19966 putchar()
19967 \begin_inset LatexCommand \index{putchar()}
19968
19969 \end_inset
19970
19971
19972 \family default
19973  routines.
19974  SDCC does not know whether the system connects to a serial line with or
19975  without handshake, LCD, keyboard or other device.
19976  And whether a 
19977 \family typewriter
19978 lf
19979 \family default
19980  to 
19981 \family typewriter
19982 crlf
19983 \family default
19984  conversion within 
19985 \family typewriter
19986 putchar()
19987 \family default
19988  is intended.
19989  You'll find examples for serial routines f.e.
19990  in sdcc/device/lib.
19991  For the mcs51 this minimalistic polling 
19992 \family typewriter
19993 putchar()
19994 \family default
19995  routine might be a start:
19996 \end_layout
19997
19998 \begin_layout Verse
19999
20000 \family typewriter
20001 void putchar (char c) { 
20002 \newline
20003 \InsetSpace ~
20004 \InsetSpace ~
20005 \InsetSpace ~
20006 \InsetSpace ~
20007 while (!TI)\InsetSpace ~
20008 \InsetSpace ~
20009 \InsetSpace ~
20010  /* assumes UART is initialized */
20011 \newline
20012 \InsetSpace ~
20013 \InsetSpace ~
20014 \InsetSpace ~
20015 \InsetSpace ~
20016 \InsetSpace ~
20017 \InsetSpace ~
20018 \InsetSpace ~
20019 \InsetSpace ~
20020 ;
20021 \newline
20022 \InsetSpace ~
20023 \InsetSpace ~
20024 \InsetSpace ~
20025 \InsetSpace ~
20026 TI
20027  = 0;
20028 \newline
20029 \InsetSpace ~
20030 \InsetSpace ~
20031 \InsetSpace ~
20032 \InsetSpace ~
20033 SBUF = c;
20034 \newline
20035 }
20036 \end_layout
20037
20038 \begin_layout Paragraph
20039 printf()
20040 \end_layout
20041
20042 \begin_layout Standard
20043 The default
20044 \family typewriter
20045  printf()
20046 \begin_inset LatexCommand \index{printf()}
20047
20048 \end_inset
20049
20050
20051 \family default
20052  implementation in
20053 \family typewriter
20054  printf_large.c
20055 \family default
20056  does not support float (except on ds390).
20057  To enable this recompile it with the option 
20058 \emph on
20059 -
20060 \begin_inset ERT
20061 status collapsed
20062
20063 \begin_layout Standard
20064
20065
20066 \backslash
20067 /
20068 \end_layout
20069
20070 \end_inset
20071
20072 DUSE_FLOATS=1
20073 \begin_inset LatexCommand \index{USE\_FLOATS}
20074
20075 \end_inset
20076
20077
20078 \emph default
20079  on the command line.
20080  Use
20081 \emph on
20082  -
20083 \begin_inset ERT
20084 status collapsed
20085
20086 \begin_layout Standard
20087
20088
20089 \backslash
20090 /
20091 \end_layout
20092
20093 \end_inset
20094
20095 -model-large
20096 \begin_inset LatexCommand \index{-\/-model-large}
20097
20098 \end_inset
20099
20100
20101 \emph default
20102  for the mcs51 port, since this uses a lot of memory.
20103 \end_layout
20104
20105 \begin_layout Standard
20106 If you're short on code memory you might want to use 
20107 \family typewriter
20108 printf_small()
20109 \begin_inset LatexCommand \index{printf\_small()}
20110
20111 \end_inset
20112
20113
20114 \family default
20115  
20116 \emph on
20117 instead
20118 \emph default
20119  of
20120 \family typewriter
20121  printf().
20122
20123 \family default
20124  For the mcs51 there additionally are assembly versions 
20125 \family typewriter
20126 printf_tiny()
20127 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20128
20129 \end_inset
20130
20131
20132 \family default
20133  (subset of printf using less than 270 bytes) and 
20134 \family typewriter
20135 printf_fast()
20136 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20137
20138 \end_inset
20139
20140  
20141 \family default
20142 and
20143 \family typewriter
20144  printf_fast_f()
20145 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20146
20147 \end_inset
20148
20149
20150 \family default
20151  (floating-point aware version of printf_fast) which should fit the requirements
20152  of many embedded systems (printf_fast() can be customized by unsetting
20153  #defines to 
20154 \emph on
20155 not
20156 \emph default
20157  support long variables and field widths).
20158  Be sure to use only one of these printf options within a project.
20159 \newline
20160
20161 \end_layout
20162
20163 \begin_layout Standard
20164 Feature matrix of different 
20165 \emph on
20166 printf
20167 \emph default
20168  options on mcs51.
20169 \end_layout
20170
20171 \begin_layout Standard
20172 \begin_inset Tabular
20173 <lyxtabular version="3" rows="14" columns="7">
20174 <features islongtable="true">
20175 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20176 <column alignment="center" valignment="top" leftline="true" width="0">
20177 <column alignment="center" valignment="top" leftline="true" width="12col%">
20178 <column alignment="center" valignment="top" leftline="true" width="10col%">
20179 <column alignment="center" valignment="top" leftline="true" width="0">
20180 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20181 <column alignment="center" valignment="top" rightline="true" width="0">
20182 <row topline="true" bottomline="true" endhead="true">
20183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20184 \begin_inset Text
20185
20186 \begin_layout Standard
20187
20188 \series bold
20189 \size large
20190 mcs51
20191 \end_layout
20192
20193 \end_inset
20194 </cell>
20195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20196 \begin_inset Text
20197
20198 \begin_layout Standard
20199 printf
20200 \begin_inset LatexCommand \index{printf}
20201
20202 \end_inset
20203
20204
20205 \end_layout
20206
20207 \end_inset
20208 </cell>
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20210 \begin_inset Text
20211
20212 \begin_layout Standard
20213 printf 
20214 \size scriptsize
20215 USE_FLOATS=1
20216 \end_layout
20217
20218 \end_inset
20219 </cell>
20220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20221 \begin_inset Text
20222
20223 \begin_layout Standard
20224 printf_small
20225 \end_layout
20226
20227 \end_inset
20228 </cell>
20229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20230 \begin_inset Text
20231
20232 \begin_layout Standard
20233 printf_fast
20234 \end_layout
20235
20236 \end_inset
20237 </cell>
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20239 \begin_inset Text
20240
20241 \begin_layout Standard
20242 printf_fast_f
20243 \end_layout
20244
20245 \end_inset
20246 </cell>
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20248 \begin_inset Text
20249
20250 \begin_layout Standard
20251 printf_tiny
20252 \end_layout
20253
20254 \end_inset
20255 </cell>
20256 </row>
20257 <row topline="true" endhead="true">
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20259 \begin_inset Text
20260
20261 \begin_layout Standard
20262 filename
20263 \end_layout
20264
20265 \end_inset
20266 </cell>
20267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20268 \begin_inset Text
20269
20270 \begin_layout Standard
20271
20272 \size scriptsize
20273 printf_large.c
20274 \end_layout
20275
20276 \end_inset
20277 </cell>
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20279 \begin_inset Text
20280
20281 \begin_layout Standard
20282
20283 \size scriptsize
20284 printf_large.c
20285 \end_layout
20286
20287 \end_inset
20288 </cell>
20289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20290 \begin_inset Text
20291
20292 \begin_layout Standard
20293
20294 \size scriptsize
20295 printfl.c
20296 \end_layout
20297
20298 \end_inset
20299 </cell>
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \begin_layout Standard
20304
20305 \size scriptsize
20306 printf_fast.c
20307 \end_layout
20308
20309 \end_inset
20310 </cell>
20311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20312 \begin_inset Text
20313
20314 \begin_layout Standard
20315
20316 \size scriptsize
20317 printf_fast_f.c
20318 \end_layout
20319
20320 \end_inset
20321 </cell>
20322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20323 \begin_inset Text
20324
20325 \begin_layout Standard
20326
20327 \size scriptsize
20328 printf_tiny.c
20329 \end_layout
20330
20331 \end_inset
20332 </cell>
20333 </row>
20334 <row topline="true" endhead="true">
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20336 \begin_inset Text
20337
20338 \begin_layout Standard
20339 \begin_inset Quotes sld
20340 \end_inset
20341
20342 Hello World
20343 \begin_inset Quotes srd
20344 \end_inset
20345
20346  size
20347 \end_layout
20348
20349 \begin_layout Standard
20350 small / large
20351 \end_layout
20352
20353 \end_inset
20354 </cell>
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_inset Text
20357
20358 \begin_layout Standard
20359 1.7k / 2.4k
20360 \end_layout
20361
20362 \end_inset
20363 </cell>
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_inset Text
20366
20367 \begin_layout Standard
20368 4.3k / 5.6k
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 1.2k / 1.8k
20378 \end_layout
20379
20380 \end_inset
20381 </cell>
20382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20383 \begin_inset Text
20384
20385 \begin_layout Standard
20386 1.3k / 1.3k
20387 \end_layout
20388
20389 \end_inset
20390 </cell>
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20392 \begin_inset Text
20393
20394 \begin_layout Standard
20395 1.9k / 1.9k
20396 \end_layout
20397
20398 \end_inset
20399 </cell>
20400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20401 \begin_inset Text
20402
20403 \begin_layout Standard
20404 0.44k / 0.44k
20405 \end_layout
20406
20407 \end_inset
20408 </cell>
20409 </row>
20410 <row topline="true" endhead="true">
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20412 \begin_inset Text
20413
20414 \begin_layout Standard
20415 code size
20416 \end_layout
20417
20418 \begin_layout Standard
20419 small / large
20420 \end_layout
20421
20422 \end_inset
20423 </cell>
20424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20425 \begin_inset Text
20426
20427 \begin_layout Standard
20428 1.4k / 2.0k
20429 \end_layout
20430
20431 \end_inset
20432 </cell>
20433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20434 \begin_inset Text
20435
20436 \begin_layout Standard
20437 2.8k / 3.7k
20438 \end_layout
20439
20440 \end_inset
20441 </cell>
20442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20443 \begin_inset Text
20444
20445 \begin_layout Standard
20446 0.45k / 0.47k (+ _ltoa)
20447 \end_layout
20448
20449 \end_inset
20450 </cell>
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20452 \begin_inset Text
20453
20454 \begin_layout Standard
20455 1.2k / 1.2k
20456 \end_layout
20457
20458 \end_inset
20459 </cell>
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20461 \begin_inset Text
20462
20463 \begin_layout Standard
20464 1.6k / 1.6k
20465 \end_layout
20466
20467 \end_inset
20468 </cell>
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20470 \begin_inset Text
20471
20472 \begin_layout Standard
20473 0.26k / 0.26k
20474 \end_layout
20475
20476 \end_inset
20477 </cell>
20478 </row>
20479 <row topline="true">
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20481 \begin_inset Text
20482
20483 \begin_layout Standard
20484 formats
20485 \end_layout
20486
20487 \end_inset
20488 </cell>
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20490 \begin_inset Text
20491
20492 \begin_layout Standard
20493 cdi
20494 \emph on
20495 o
20496 \emph default
20497 psux
20498 \end_layout
20499
20500 \end_inset
20501 </cell>
20502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20503 \begin_inset Text
20504
20505 \begin_layout Standard
20506
20507 \family roman
20508 \series medium
20509 \shape up
20510 \size normal
20511 \emph off
20512 \bar no
20513 \noun off
20514 \color none
20515 cd
20516 \family default
20517 \series default
20518 \shape default
20519 \size default
20520 \emph default
20521 \bar default
20522 \noun default
20523 f
20524 \family roman
20525 \series medium
20526 \shape up
20527 \size normal
20528 \emph off
20529 \bar no
20530 \noun off
20531 i
20532 \family default
20533 \series default
20534 \shape default
20535 \size default
20536 \emph on
20537 \bar default
20538 \noun default
20539 o
20540 \family roman
20541 \series medium
20542 \shape up
20543 \size normal
20544 \emph off
20545 \bar no
20546 \noun off
20547 psux
20548 \end_layout
20549
20550 \end_inset
20551 </cell>
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20553 \begin_inset Text
20554
20555 \begin_layout Standard
20556 c
20557 \family roman
20558 \series medium
20559 \shape up
20560 \size normal
20561 \emph off
20562 \bar no
20563 \noun off
20564 \color none
20565 d
20566 \family default
20567 \series default
20568 \shape default
20569 \size default
20570 \emph on
20571 \bar default
20572 \noun default
20573 o
20574 \family roman
20575 \series medium
20576 \shape up
20577 \size normal
20578 \emph off
20579 \bar no
20580 \noun off
20581 s
20582 \family default
20583 \series default
20584 \shape default
20585 \size default
20586 \emph default
20587 \bar default
20588 \noun default
20589 x
20590 \end_layout
20591
20592 \end_inset
20593 </cell>
20594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20595 \begin_inset Text
20596
20597 \begin_layout Standard
20598 cdsux
20599 \end_layout
20600
20601 \end_inset
20602 </cell>
20603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20604 \begin_inset Text
20605
20606 \begin_layout Standard
20607 cdfsux
20608 \end_layout
20609
20610 \end_inset
20611 </cell>
20612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20613 \begin_inset Text
20614
20615 \begin_layout Standard
20616 cdsux
20617 \end_layout
20618
20619 \end_inset
20620 </cell>
20621 </row>
20622 <row topline="true">
20623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20624 \begin_inset Text
20625
20626 \begin_layout Standard
20627 long (32 bit) support
20628 \end_layout
20629
20630 \end_inset
20631 </cell>
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20633 \begin_inset Text
20634
20635 \begin_layout Standard
20636 x
20637 \end_layout
20638
20639 \end_inset
20640 </cell>
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20642 \begin_inset Text
20643
20644 \begin_layout Standard
20645 x
20646 \end_layout
20647
20648 \end_inset
20649 </cell>
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20651 \begin_inset Text
20652
20653 \begin_layout Standard
20654 x
20655 \end_layout
20656
20657 \end_inset
20658 </cell>
20659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20660 \begin_inset Text
20661
20662 \begin_layout Standard
20663 x
20664 \end_layout
20665
20666 \end_inset
20667 </cell>
20668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20669 \begin_inset Text
20670
20671 \begin_layout Standard
20672
20673 \family roman
20674 \series medium
20675 \shape up
20676 \size normal
20677 \emph off
20678 \bar no
20679 \noun off
20680 \color none
20681 x
20682 \end_layout
20683
20684 \end_inset
20685 </cell>
20686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20687 \begin_inset Text
20688
20689 \begin_layout Standard
20690 -
20691 \end_layout
20692
20693 \end_inset
20694 </cell>
20695 </row>
20696 <row topline="true">
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20698 \begin_inset Text
20699
20700 \begin_layout Standard
20701 byte arguments on stack
20702 \end_layout
20703
20704 \end_inset
20705 </cell>
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20707 \begin_inset Text
20708
20709 \begin_layout Standard
20710 b
20711 \end_layout
20712
20713 \end_inset
20714 </cell>
20715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20716 \begin_inset Text
20717
20718 \begin_layout Standard
20719 b
20720 \end_layout
20721
20722 \end_inset
20723 </cell>
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20725 \begin_inset Text
20726
20727 \begin_layout Standard
20728 -
20729 \end_layout
20730
20731 \end_inset
20732 </cell>
20733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20734 \begin_inset Text
20735
20736 \begin_layout Standard
20737 -
20738 \end_layout
20739
20740 \end_inset
20741 </cell>
20742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20743 \begin_inset Text
20744
20745 \begin_layout Standard
20746 -
20747 \end_layout
20748
20749 \end_inset
20750 </cell>
20751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20752 \begin_inset Text
20753
20754 \begin_layout Standard
20755 -
20756 \end_layout
20757
20758 \end_inset
20759 </cell>
20760 </row>
20761 <row topline="true">
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20763 \begin_inset Text
20764
20765 \begin_layout Standard
20766 float format
20767 \begin_inset LatexCommand \index{Floating point support}
20768
20769 \end_inset
20770
20771
20772 \end_layout
20773
20774 \end_inset
20775 </cell>
20776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20777 \begin_inset Text
20778
20779 \begin_layout Standard
20780 -
20781 \end_layout
20782
20783 \end_inset
20784 </cell>
20785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20786 \begin_inset Text
20787
20788 \begin_layout Standard
20789 %f
20790 \end_layout
20791
20792 \end_inset
20793 </cell>
20794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20795 \begin_inset Text
20796
20797 \begin_layout Standard
20798 -
20799 \end_layout
20800
20801 \end_inset
20802 </cell>
20803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20804 \begin_inset Text
20805
20806 \begin_layout Standard
20807 -
20808 \end_layout
20809
20810 \end_inset
20811 </cell>
20812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20813 \begin_inset Text
20814
20815 \begin_layout Standard
20816 %f
20817 \begin_inset Foot
20818 status collapsed
20819
20820 \begin_layout Standard
20821 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20822 \end_layout
20823
20824 \end_inset
20825
20826
20827 \end_layout
20828
20829 \end_inset
20830 </cell>
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20832 \begin_inset Text
20833
20834 \begin_layout Standard
20835 -
20836 \end_layout
20837
20838 \end_inset
20839 </cell>
20840 </row>
20841 <row topline="true">
20842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20843 \begin_inset Text
20844
20845 \begin_layout Standard
20846 float formats %e %g
20847 \end_layout
20848
20849 \end_inset
20850 </cell>
20851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20852 \begin_inset Text
20853
20854 \begin_layout Standard
20855 -
20856 \end_layout
20857
20858 \end_inset
20859 </cell>
20860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20861 \begin_inset Text
20862
20863 \begin_layout Standard
20864 -
20865 \end_layout
20866
20867 \end_inset
20868 </cell>
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20870 \begin_inset Text
20871
20872 \begin_layout Standard
20873 -
20874 \end_layout
20875
20876 \end_inset
20877 </cell>
20878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20879 \begin_inset Text
20880
20881 \begin_layout Standard
20882 -
20883 \end_layout
20884
20885 \end_inset
20886 </cell>
20887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20888 \begin_inset Text
20889
20890 \begin_layout Standard
20891 -
20892 \end_layout
20893
20894 \end_inset
20895 </cell>
20896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20897 \begin_inset Text
20898
20899 \begin_layout Standard
20900 -
20901 \end_layout
20902
20903 \end_inset
20904 </cell>
20905 </row>
20906 <row topline="true" bottomline="true">
20907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20908 \begin_inset Text
20909
20910 \begin_layout Standard
20911 field width
20912 \end_layout
20913
20914 \end_inset
20915 </cell>
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20917 \begin_inset Text
20918
20919 \begin_layout Standard
20920 x
20921 \end_layout
20922
20923 \end_inset
20924 </cell>
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20926 \begin_inset Text
20927
20928 \begin_layout Standard
20929 x
20930 \end_layout
20931
20932 \end_inset
20933 </cell>
20934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20935 \begin_inset Text
20936
20937 \begin_layout Standard
20938 -
20939 \end_layout
20940
20941 \end_inset
20942 </cell>
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20944 \begin_inset Text
20945
20946 \begin_layout Standard
20947 x
20948 \end_layout
20949
20950 \end_inset
20951 </cell>
20952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20953 \begin_inset Text
20954
20955 \begin_layout Standard
20956 x
20957 \end_layout
20958
20959 \end_inset
20960 </cell>
20961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20962 \begin_inset Text
20963
20964 \begin_layout Standard
20965 -
20966 \end_layout
20967
20968 \end_inset
20969 </cell>
20970 </row>
20971 <row bottomline="true">
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20973 \begin_inset Text
20974
20975 \begin_layout Standard
20976 string speed
20977 \begin_inset Foot
20978 status collapsed
20979
20980 \begin_layout Standard
20981 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20982 \backslash
20983 r', '
20984 \backslash
20985 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20986 \end_layout
20987
20988 \end_inset
20989
20990 ,
20991 \end_layout
20992
20993 \begin_layout Standard
20994 small / large
20995 \end_layout
20996
20997 \end_inset
20998 </cell>
20999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21000 \begin_inset Text
21001
21002 \begin_layout Standard
21003 1.52 / 2.59 ms
21004 \end_layout
21005
21006 \end_inset
21007 </cell>
21008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21009 \begin_inset Text
21010
21011 \begin_layout Standard
21012 1.53 / 2.62 ms
21013 \end_layout
21014
21015 \end_inset
21016 </cell>
21017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21018 \begin_inset Text
21019
21020 \begin_layout Standard
21021 0.92 / 0.93 ms
21022 \end_layout
21023
21024 \end_inset
21025 </cell>
21026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21027 \begin_inset Text
21028
21029 \begin_layout Standard
21030 0.45 / 0.45 ms
21031 \end_layout
21032
21033 \end_inset
21034 </cell>
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21036 \begin_inset Text
21037
21038 \begin_layout Standard
21039 0.46 / 0.46 ms
21040 \end_layout
21041
21042 \end_inset
21043 </cell>
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21045 \begin_inset Text
21046
21047 \begin_layout Standard
21048 0.45 / 0.45 ms
21049 \end_layout
21050
21051 \end_inset
21052 </cell>
21053 </row>
21054 <row bottomline="true">
21055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21056 \begin_inset Text
21057
21058 \begin_layout Standard
21059 int speed
21060 \begin_inset Foot
21061 status collapsed
21062
21063 \begin_layout Standard
21064 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21065  putchar()
21066 \end_layout
21067
21068 \end_inset
21069
21070 ,
21071 \end_layout
21072
21073 \begin_layout Standard
21074 small / large
21075 \end_layout
21076
21077 \end_inset
21078 </cell>
21079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21080 \begin_inset Text
21081
21082 \begin_layout Standard
21083 3.01 / 3.61 ms
21084 \end_layout
21085
21086 \end_inset
21087 </cell>
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21089 \begin_inset Text
21090
21091 \begin_layout Standard
21092 3.01 / 3.61 ms
21093 \end_layout
21094
21095 \end_inset
21096 </cell>
21097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21098 \begin_inset Text
21099
21100 \begin_layout Standard
21101 3.51 / 18.13 ms
21102 \end_layout
21103
21104 \end_inset
21105 </cell>
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21107 \begin_inset Text
21108
21109 \begin_layout Standard
21110 0.22 / 0.22 ms
21111 \end_layout
21112
21113 \end_inset
21114 </cell>
21115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21116 \begin_inset Text
21117
21118 \begin_layout Standard
21119 0.23 / 0.23 ms
21120 \end_layout
21121
21122 \end_inset
21123 </cell>
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21125 \begin_inset Text
21126
21127 \begin_layout Standard
21128 0.25 / 0.25 ms
21129 \begin_inset Foot
21130 status collapsed
21131
21132 \begin_layout Standard
21133 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21134 \end_layout
21135
21136 \end_inset
21137
21138
21139 \end_layout
21140
21141 \end_inset
21142 </cell>
21143 </row>
21144 <row bottomline="true">
21145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21146 \begin_inset Text
21147
21148 \begin_layout Standard
21149 long speed
21150 \begin_inset Foot
21151 status collapsed
21152
21153 \begin_layout Standard
21154 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21155  empty putchar()
21156 \end_layout
21157
21158 \end_inset
21159
21160 ,
21161 \end_layout
21162
21163 \begin_layout Standard
21164 small / large
21165 \end_layout
21166
21167 \end_inset
21168 </cell>
21169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21170 \begin_inset Text
21171
21172 \begin_layout Standard
21173 5.37 / 6.31 ms
21174 \end_layout
21175
21176 \end_inset
21177 </cell>
21178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21179 \begin_inset Text
21180
21181 \begin_layout Standard
21182 5.37 / 6.31 ms
21183 \end_layout
21184
21185 \end_inset
21186 </cell>
21187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21188 \begin_inset Text
21189
21190 \begin_layout Standard
21191 8.71 / 40.65 ms
21192 \end_layout
21193
21194 \end_inset
21195 </cell>
21196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21197 \begin_inset Text
21198
21199 \begin_layout Standard
21200 0.40 / 0.40 ms
21201 \end_layout
21202
21203 \end_inset
21204 </cell>
21205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21206 \begin_inset Text
21207
21208 \begin_layout Standard
21209 0.40 / 0.40 ms
21210 \end_layout
21211
21212 \end_inset
21213 </cell>
21214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21215 \begin_inset Text
21216
21217 \begin_layout Standard
21218 -
21219 \end_layout
21220
21221 \end_inset
21222 </cell>
21223 </row>
21224 <row bottomline="true">
21225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21226 \begin_inset Text
21227
21228 \begin_layout Standard
21229 float speed
21230 \begin_inset Foot
21231 status collapsed
21232
21233 \begin_layout Standard
21234 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21235  empty putchar()
21236 \end_layout
21237
21238 \end_inset
21239
21240 ,
21241 \end_layout
21242
21243 \begin_layout Standard
21244 small / large
21245 \end_layout
21246
21247 \end_inset
21248 </cell>
21249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21250 \begin_inset Text
21251
21252 \begin_layout Standard
21253 -
21254 \end_layout
21255
21256 \end_inset
21257 </cell>
21258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21259 \begin_inset Text
21260
21261 \begin_layout Standard
21262 7.49 / 22.47 ms
21263 \end_layout
21264
21265 \end_inset
21266 </cell>
21267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21268 \begin_inset Text
21269
21270 \begin_layout Standard
21271 -
21272 \end_layout
21273
21274 \end_inset
21275 </cell>
21276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21277 \begin_inset Text
21278
21279 \begin_layout Standard
21280 -
21281 \end_layout
21282
21283 \end_inset
21284 </cell>
21285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21286 \begin_inset Text
21287
21288 \begin_layout Standard
21289 1.04 / 1.04 ms
21290 \end_layout
21291
21292 \end_inset
21293 </cell>
21294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21295 \begin_inset Text
21296
21297 \begin_layout Standard
21298 -
21299 \end_layout
21300
21301 \end_inset
21302 </cell>
21303 </row>
21304 </lyxtabular>
21305
21306 \end_inset
21307
21308
21309 \end_layout
21310
21311 \begin_layout Subsubsection
21312 <malloc.h>
21313 \begin_inset LatexCommand \index{malloc.h}
21314
21315 \end_inset
21316
21317
21318 \end_layout
21319
21320 \begin_layout Standard
21321 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21322  using dynamic memory allocation
21323 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21324
21325 \end_inset
21326
21327  and a default heap
21328 \begin_inset LatexCommand \index{heap (malloc)}
21329
21330 \end_inset
21331
21332  space of 1024 bytes is provided for malloc to allocate memory from.
21333  If you need a different heap size you need to recompile _heap.c with the
21334  required size defined in HEAP_SIZE.
21335  It is recommended to make a copy of this file into your project directory
21336  and compile it there with:
21337 \end_layout
21338
21339 \begin_layout Verse
21340
21341 \family typewriter
21342 sdcc -c _heap.c -D HEAD_SIZE=2048
21343 \end_layout
21344
21345 \begin_layout Standard
21346 And then link it with:
21347 \end_layout
21348
21349 \begin_layout Verse
21350
21351 \family typewriter
21352 sdcc main.rel _heap.rel
21353 \end_layout
21354
21355 \begin_layout Subsection
21356 Math functions (sinf, powf, sqrtf etc.)
21357 \end_layout
21358
21359 \begin_layout Subsubsection
21360 <math.h>
21361 \end_layout
21362
21363 \begin_layout Standard
21364 See definitions in file <math.h>.
21365 \end_layout
21366
21367 \begin_layout Subsection
21368 Other libraries
21369 \end_layout
21370
21371 \begin_layout Standard
21372 Libraries
21373 \begin_inset LatexCommand \index{Libraries}
21374
21375 \end_inset
21376
21377  included in SDCC should have a license at least as liberal as the GNU Lesser
21378  General Public License
21379 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21380
21381 \end_inset
21382
21383  
21384 \emph on
21385 LGPL
21386 \emph default
21387 .
21388 \end_layout
21389
21390 \begin_layout Standard
21391 \begin_inset Note Note
21392 status collapsed
21393
21394 \begin_layout Standard
21395 license statements for the libraries are missing.
21396  sdcc/device/lib/ser_ir.c
21397 \end_layout
21398
21399 \begin_layout Standard
21400 or _decdptr f.e.
21401  come with a GPL (as opposed to LGPL) License - this will not be liberal
21402  enough for many embedded programmers.
21403 \end_layout
21404
21405 \end_inset
21406
21407
21408 \end_layout
21409
21410 \begin_layout Standard
21411 If you have ported some library or want to share experience about some code
21412  which f.e.
21413  falls into any of these categories Busses (I
21414 \begin_inset Formula $^{\textrm{2}}$
21415 \end_inset
21416
21417 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21418  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21419  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21420 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21421
21422 \end_inset
21423
21424 \InsetSpace ~
21425 would certainly like to hear about it.
21426 \end_layout
21427
21428 \begin_layout Standard
21429 Programmers coding for embedded systems are not especially famous for being
21430  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21431 e these references are very valuable.
21432  Let's help to create a climate where information is shared.
21433 \begin_inset VSpace bigskip
21434 \end_inset
21435
21436
21437 \end_layout
21438
21439 \begin_layout Section
21440 Memory Models
21441 \end_layout
21442
21443 \begin_layout Subsection
21444 MCS51 Memory Models
21445 \begin_inset LatexCommand \index{Memory model}
21446
21447 \end_inset
21448
21449
21450 \begin_inset LatexCommand \index{MCS51 memory model}
21451
21452 \end_inset
21453
21454
21455 \end_layout
21456
21457 \begin_layout Subsubsection
21458 Small, Medium and Large
21459 \end_layout
21460
21461 \begin_layout Standard
21462 SDCC allows three memory models for MCS51 code, 
21463 \shape slanted
21464 small, medium
21465 \shape default
21466  and 
21467 \shape slanted
21468 large
21469 \shape default
21470 .
21471  Modules compiled with different memory models should 
21472 \emph on
21473 never
21474 \emph default
21475  be combined together or the results would be unpredictable.
21476  The library routines supplied with the compiler are compiled as small,
21477  medium and large.
21478  The compiled library modules are contained in separate directories as small,
21479  medium and large so that you can link to the appropriate set.
21480 \end_layout
21481
21482 \begin_layout Standard
21483 When the medium or large model is used all variables declared without a
21484  storage class will be allocated into the external ram, this includes all
21485  parameters and local variables (for non-reentrant
21486 \begin_inset LatexCommand \index{reentrant}
21487
21488 \end_inset
21489
21490  functions).
21491  When the small model is used variables without storage class are allocated
21492  in the internal ram.
21493 \end_layout
21494
21495 \begin_layout Standard
21496 Judicious usage of the processor specific storage classes
21497 \begin_inset LatexCommand \index{Storage class}
21498
21499 \end_inset
21500
21501  and the 'reentrant' function type will yield much more efficient code,
21502  than using the large model.
21503  Several optimizations are disabled when the program is compiled using the
21504  large model, it is therefore recommended that the small model be used unless
21505  absolutely required.
21506 \end_layout
21507
21508 \begin_layout Subsubsection
21509 External Stack
21510 \begin_inset LatexCommand \label{sub:External-Stack}
21511
21512 \end_inset
21513
21514
21515 \begin_inset LatexCommand \index{stack}
21516
21517 \end_inset
21518
21519
21520 \begin_inset LatexCommand \index{External stack (mcs51)}
21521
21522 \end_inset
21523
21524
21525 \end_layout
21526
21527 \begin_layout Standard
21528 The external stack (-
21529 \begin_inset ERT
21530 status collapsed
21531
21532 \begin_layout Standard
21533
21534
21535 \backslash
21536 /
21537 \end_layout
21538
21539 \end_inset
21540
21541 -xstack option
21542 \begin_inset LatexCommand \index{-\/-xstack}
21543
21544 \end_inset
21545
21546 ) is located in pdata
21547 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21548
21549 \end_inset
21550
21551  memory (usually at the start of the external ram segment) and uses all
21552  unused space in pdata (max.
21553  256 bytes).
21554  When -
21555 \begin_inset ERT
21556 status collapsed
21557
21558 \begin_layout Standard
21559
21560
21561 \backslash
21562 /
21563 \end_layout
21564
21565 \end_inset
21566
21567 -xstack option is used to compile the program, the parameters and local
21568  variables
21569 \begin_inset LatexCommand \index{local variables}
21570
21571 \end_inset
21572
21573  of all reentrant functions are allocated in this area.
21574  This option is provided for programs with large stack space requirements.
21575  When used with the -
21576 \begin_inset ERT
21577 status collapsed
21578
21579 \begin_layout Standard
21580
21581
21582 \backslash
21583 /
21584 \end_layout
21585
21586 \end_inset
21587
21588 -stack-auto
21589 \begin_inset LatexCommand \index{-\/-stack-auto}
21590
21591 \end_inset
21592
21593  option, all parameters and local variables are allocated on the external
21594  stack (note: support libraries will need to be recompiled with the same
21595  options.
21596  There is a predefined target in the library makefile).
21597 \end_layout
21598
21599 \begin_layout Standard
21600 The compiler outputs the higher order address byte of the external ram segment
21601  into port P2
21602 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21603
21604 \end_inset
21605
21606  (see also section 
21607 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21608
21609 \end_inset
21610
21611 ), therefore when using the External Stack option, this port 
21612 \emph on
21613 may not
21614 \emph default
21615  be used by the application program.
21616 \end_layout
21617
21618 \begin_layout Subsection
21619 DS390 Memory Model
21620 \begin_inset LatexCommand \index{Memory model}
21621
21622 \end_inset
21623
21624
21625 \begin_inset LatexCommand \index{DS390 memory model}
21626
21627 \end_inset
21628
21629
21630 \end_layout
21631
21632 \begin_layout Standard
21633 The only model supported is Flat 24
21634 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21635
21636 \end_inset
21637
21638 .
21639  This generates code for the 24 bit contiguous addressing mode of the Dallas
21640  DS80C390 part.
21641  In this mode, up to four meg of external RAM or code space can be directly
21642  addressed.
21643  See the data sheets at www.dalsemi.com for further information on this part.
21644 \newline
21645
21646 \newline
21647 Note
21648  that the compiler does not generate any code to place the processor into
21649  24 bitmode (although 
21650 \emph on
21651 tinibios
21652 \emph default
21653  in the ds390 libraries will do that for you).
21654  If you don't use 
21655 \emph on
21656 tinibios
21657 \emph default
21658
21659 \begin_inset LatexCommand \index{Tinibios (DS390)}
21660
21661 \end_inset
21662
21663 , the boot loader or similar code must ensure that the processor is in 24
21664  bit contiguous addressing mode before calling the SDCC startup code.
21665 \newline
21666
21667 \newline
21668 Like
21669  the 
21670 \emph on
21671 -
21672 \begin_inset ERT
21673 status collapsed
21674
21675 \begin_layout Standard
21676
21677
21678 \backslash
21679 /
21680 \end_layout
21681
21682 \end_inset
21683
21684 -model-large
21685 \emph default
21686  option, variables will by default be placed into the XDATA segment.
21687  
21688 \newline
21689
21690 \newline
21691 Segments may be placed anywhere in the 4 meg address space using the usual
21692  -
21693 \begin_inset ERT
21694 status collapsed
21695
21696 \begin_layout Standard
21697
21698
21699 \backslash
21700 /
21701 \end_layout
21702
21703 \end_inset
21704
21705 -*-loc options.
21706  Note that if any segments are located above 64K, the -r flag must be passed
21707  to the linker to generate the proper segment relocations, and the Intel
21708  HEX output format must be used.
21709  The -r flag can be passed to the linker by using the option 
21710 \emph on
21711 -Wl-r
21712 \emph default
21713  on the SDCC command line.
21714  However, currently the linker can not handle code segments > 64k.
21715 \end_layout
21716
21717 \begin_layout Section
21718 Pragmas
21719 \begin_inset LatexCommand \label{sec:Pragmas}
21720
21721 \end_inset
21722
21723
21724 \begin_inset LatexCommand \index{Pragmas}
21725
21726 \end_inset
21727
21728
21729 \end_layout
21730
21731 \begin_layout Standard
21732 Pragmas are used to turn on and/or off certain compiler options.
21733  Some of them are closely related to corresponding command-line options
21734  (see section 
21735 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21736
21737 \end_inset
21738
21739 ).
21740 \newline
21741 Pragmas should be placed before and/or after a function, placing pragmas
21742  inside a function body could have unpredictable results.
21743 \newline
21744
21745 \newline
21746 SDCC supports the
21747  following #pragma directives:
21748 \end_layout
21749
21750 \begin_layout Itemize
21751
21752 \series bold
21753 save
21754 \series default
21755
21756 \begin_inset LatexCommand \index{\#pragma save}
21757
21758 \end_inset
21759
21760  - this will save most current options to the save/restore stack.
21761  See #pragma\InsetSpace ~
21762 restore.
21763 \end_layout
21764
21765 \begin_layout Itemize
21766
21767 \series bold
21768 restore
21769 \series default
21770
21771 \begin_inset LatexCommand \index{\#pragma restore}
21772
21773 \end_inset
21774
21775  - will restore saved options from the last save.
21776  saves & restores can be nested.
21777  SDCC uses a save/restore stack: save pushes current options to the stack,
21778  restore pulls current options from the stack.
21779  See #pragma\InsetSpace ~
21780 save.
21781 \newline
21782
21783 \end_layout
21784
21785 \begin_layout Itemize
21786
21787 \series bold
21788 callee_saves
21789 \series default
21790
21791 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21792
21793 \end_inset
21794
21795
21796 \begin_inset LatexCommand \index{function prologue}
21797
21798 \end_inset
21799
21800  function1[,function2[,function3...]] 
21801 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21802
21803 \end_inset
21804
21805 - The compiler by default uses a caller saves convention for register saving
21806  across function calls, however this can cause unnecessary register pushing
21807  and popping
21808 \begin_inset LatexCommand \index{push/pop}
21809
21810 \end_inset
21811
21812  when calling small functions from larger functions.
21813  This option can be used to switch off the register saving convention for
21814  the function names specified.
21815  The compiler will not save registers when calling these functions, extra
21816  code need to be manually inserted at the entry and exit for these functions
21817  to save and restore the registers used by these functions, this can SUBSTANTIAL
21818 LY reduce code and improve run time performance of the generated code.
21819  In the future the compiler (with inter procedural analysis) may be able
21820  to determine the appropriate scheme to use for each function call.
21821  If -
21822 \begin_inset ERT
21823 status collapsed
21824
21825 \begin_layout Standard
21826
21827
21828 \backslash
21829 /
21830 \end_layout
21831
21832 \end_inset
21833
21834 -callee-saves command line option is used (see page 
21835 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21836
21837 \end_inset
21838
21839 ), the function names specified in #pragma\InsetSpace ~
21840 callee_saves
21841 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21842
21843 \end_inset
21844
21845  is appended to the list of functions specified in the command line.
21846 \end_layout
21847
21848 \begin_layout Itemize
21849
21850 \series bold
21851 exclude
21852 \series default
21853
21854 \begin_inset LatexCommand \index{\#pragma exclude}
21855
21856 \end_inset
21857
21858  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21859  of pairs of push/pop
21860 \begin_inset LatexCommand \index{push/pop}
21861
21862 \end_inset
21863
21864  instructions in 
21865 \emph on
21866 I
21867 \emph default
21868 nterrupt
21869 \begin_inset LatexCommand \index{interrupt}
21870
21871 \end_inset
21872
21873  
21874 \emph on
21875 S
21876 \emph default
21877 ervice 
21878 \emph on
21879 R
21880 \emph default
21881 outines.
21882  The directive should be placed immediately before the ISR function definition
21883  and it affects ALL ISR functions following it.
21884  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21885 exclude\InsetSpace ~
21886 none
21887 \begin_inset LatexCommand \index{\#pragma exclude}
21888
21889 \end_inset
21890
21891 .
21892  See also the related keyword _naked
21893 \begin_inset LatexCommand \index{\_naked}
21894
21895 \end_inset
21896
21897
21898 \begin_inset LatexCommand \index{\_\_naked}
21899
21900 \end_inset
21901
21902 .
21903 \end_layout
21904
21905 \begin_layout Itemize
21906
21907 \series bold
21908 less_pedantic
21909 \series default
21910
21911 \begin_inset LatexCommand \index{pedantic}
21912
21913 \end_inset
21914
21915
21916 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21917
21918 \end_inset
21919
21920  
21921 \begin_inset LatexCommand \label{ite:less_pedantic}
21922
21923 \end_inset
21924
21925 - the compiler will not warn you anymore for obvious mistakes, you're on
21926  your own now ;-( .
21927  See also the command line option -
21928 \begin_inset ERT
21929 status collapsed
21930
21931 \begin_layout Standard
21932
21933
21934 \backslash
21935 /
21936 \end_layout
21937
21938 \end_inset
21939
21940 -less-pedantic 
21941 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21942
21943 \end_inset
21944
21945 .
21946  
21947 \newline
21948 More specifically, the following warnings will be disabled: 
21949 \shape italic
21950 comparison is always [true/false] due to limited range of data type
21951 \shape default
21952  (94); 
21953 \shape italic
21954 overflow in implicit constant conversion
21955 \shape default
21956  (158); [the (in)famous] 
21957 \shape italic
21958 conditional flow changed by optimizer: so said EVELYN the modified DOG
21959 \shape default
21960  (110); 
21961 \shape italic
21962 function '[function name]' must return value
21963 \shape default
21964  (59).
21965  
21966 \newline
21967 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21968  level) are disabled, too, namely: 
21969 \shape italic
21970 constant value '[
21971 \begin_inset Note Note
21972 status collapsed
21973
21974 \begin_layout Standard
21975 dunno what comes here - this warning appears to be unused altogether
21976 \end_layout
21977
21978 \end_inset
21979
21980 ]', out of range
21981 \shape default
21982  (81); 
21983 \shape italic
21984 [left/right] shifting more than size of object changed to zero
21985 \shape default
21986  (116); 
21987 \shape italic
21988 unreachable code
21989 \shape default
21990  (126); 
21991 \shape italic
21992 integer overflow in expression
21993 \shape default
21994  (165); 
21995 \shape italic
21996 unmatched #pragma save and #pragma restore
21997 \shape default
21998  (170); 
21999 \shape italic
22000 comparison of 'signed char' with 'unsigned char' requires promotion to int
22001 \shape default
22002  (185); 
22003 \shape italic
22004 ISO C90 does not support flexible array members
22005 \shape default
22006  (187); 
22007 \shape italic
22008 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22009 nam
22010 e]':\InsetSpace ~
22011 [
22012 \begin_inset Note Note
22013 status collapsed
22014
22015 \begin_layout Standard
22016 appears to be always blank - what was supposed to be here?
22017 \end_layout
22018
22019 \end_inset
22020
22021 ]
22022 \shape default
22023  (114); 
22024 \shape italic
22025 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22026  complexity [number]
22027 \shape default
22028  (121).
22029 \end_layout
22030
22031 \begin_layout Itemize
22032
22033 \series bold
22034 disable_warning
22035 \series default
22036  <nnnn>
22037 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22038
22039 \end_inset
22040
22041  - the compiler will not warn you anymore about warning number <nnnn>.
22042 \end_layout
22043
22044 \begin_layout Itemize
22045
22046 \series bold
22047 nogcse
22048 \series default
22049
22050 \begin_inset LatexCommand \index{\#pragma nogcse}
22051
22052 \end_inset
22053
22054  - will stop global common subexpression elimination.
22055 \end_layout
22056
22057 \begin_layout Itemize
22058
22059 \series bold
22060 noinduction
22061 \series default
22062
22063 \begin_inset LatexCommand \index{\#pragma noinduction}
22064
22065 \end_inset
22066
22067  - will stop loop induction optimizations.
22068 \end_layout
22069
22070 \begin_layout Itemize
22071
22072 \series bold
22073 noinvariant
22074 \series default
22075
22076 \begin_inset LatexCommand \index{\#pragma noinvariant}
22077
22078 \end_inset
22079
22080  - will not do loop invariant optimizations.
22081  For more details see Loop Invariants in section
22082 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22083
22084 \end_inset
22085
22086 .
22087 \end_layout
22088
22089 \begin_layout Itemize
22090
22091 \series bold
22092 noiv
22093 \series default
22094
22095 \begin_inset LatexCommand \index{\#pragma noiv}
22096
22097 \end_inset
22098
22099  - Do not generate interrupt
22100 \begin_inset LatexCommand \index{interrupt}
22101
22102 \end_inset
22103
22104  vector table
22105 \begin_inset LatexCommand \index{interrupt vector table}
22106
22107 \end_inset
22108
22109  entries for all ISR functions defined after the pragma.
22110  This is useful in cases where the interrupt vector table must be defined
22111  manually, or when there is a secondary, manually defined interrupt vector
22112  table (e.g.
22113  for the autovector feature of the Cypress EZ-USB FX2).
22114  More elegantly this can be achieved by obmitting the optional interrupt
22115  number after the interrupt keyword, see section 
22116 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22117
22118 \end_inset
22119
22120 \InsetSpace ~
22121 about interrupts.
22122 \end_layout
22123
22124 \begin_layout Itemize
22125
22126 \series bold
22127 nojtbound
22128 \series default
22129
22130 \begin_inset LatexCommand \index{\#pragma nojtbound}
22131
22132 \end_inset
22133
22134  - will not generate code for boundary value checking, when switch statements
22135  are turned into jump-tables (dangerous).
22136  For more details see section 
22137 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22138
22139 \end_inset
22140
22141 .
22142 \end_layout
22143
22144 \begin_layout Itemize
22145
22146 \series bold
22147 noloopreverse
22148 \series default
22149
22150 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22151
22152 \end_inset
22153
22154  - Will not do loop reversal optimization
22155 \end_layout
22156
22157 \begin_layout Itemize
22158
22159 \series bold
22160 nooverlay
22161 \series default
22162
22163 \begin_inset LatexCommand \index{\#pragma nooverlay}
22164
22165 \end_inset
22166
22167  - the compiler will not overlay the parameters and local variables of a
22168  function.
22169 \end_layout
22170
22171 \begin_layout Itemize
22172
22173 \series bold
22174 stackauto
22175 \series default
22176
22177 \begin_inset LatexCommand \index{\#pragma stackauto}
22178
22179 \end_inset
22180
22181 - See option -
22182 \begin_inset ERT
22183 status collapsed
22184
22185 \begin_layout Standard
22186
22187
22188 \backslash
22189 /
22190 \end_layout
22191
22192 \end_inset
22193
22194 -stack-auto
22195 \begin_inset LatexCommand \index{-\/-stack-auto}
22196
22197 \end_inset
22198
22199  and section 
22200 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22201
22202 \end_inset
22203
22204  Parameters and Local Variables.
22205 \end_layout
22206
22207 \begin_layout Itemize
22208
22209 \series bold
22210 opt_code_speed
22211 \series default
22212  
22213 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22214
22215 \end_inset
22216
22217 - The compiler will optimize code generation towards fast code, possibly
22218  at the expense of code size.
22219  Currently this has little effect.
22220 \end_layout
22221
22222 \begin_layout Itemize
22223
22224 \series bold
22225 opt_code_size
22226 \series default
22227  
22228 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22229
22230 \end_inset
22231
22232 - The compiler will optimize code generation towards compact code, possibly
22233  at the expense of code speed.
22234  Currently this has little effect.
22235 \end_layout
22236
22237 \begin_layout Itemize
22238
22239 \series bold
22240 opt_code_balanced
22241 \series default
22242  
22243 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22244
22245 \end_inset
22246
22247 - The compiler will attempt to generate code that is both compact and fast,
22248  as long as meeting one goal is not a detriment to the other (this is the
22249  default).
22250  
22251 \end_layout
22252
22253 \begin_layout Itemize
22254
22255 \series bold
22256 std_sdcc89
22257 \series default
22258  
22259 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22260
22261 \end_inset
22262
22263 - Generally follow the C89 standard, but allow SDCC features that conflict
22264  with the standard (default).
22265 \end_layout
22266
22267 \begin_layout Itemize
22268
22269 \series bold
22270 std_c89
22271 \series default
22272  
22273 \begin_inset LatexCommand \index{\#pragma std\_c89}
22274
22275 \end_inset
22276
22277 - Follow the C89 standard and disable SDCC features that conflict with the
22278  standard.
22279 \end_layout
22280
22281 \begin_layout Itemize
22282
22283 \series bold
22284 std_sdcc99
22285 \series default
22286  
22287 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22288
22289 \end_inset
22290
22291 - Generally follow the C99 standard, but allow SDCC features that conflict
22292  with the standard (incomplete support).
22293 \end_layout
22294
22295 \begin_layout Itemize
22296
22297 \series bold
22298 std_c99
22299 \series default
22300  
22301 \begin_inset LatexCommand \index{\#pragma std\_c99}
22302
22303 \end_inset
22304
22305 - Follow the C99 standard and disable SDCC features that conflict with the
22306  standard (incomplete support).
22307 \end_layout
22308
22309 \begin_layout Itemize
22310
22311 \series bold
22312 codeseg
22313 \series default
22314  <name>
22315 \begin_inset LatexCommand \index{\#pragma codeseg}
22316
22317 \end_inset
22318
22319 - Use this name (max.
22320  8 characters) for the code segment.
22321  See option -
22322 \begin_inset ERT
22323 status collapsed
22324
22325 \begin_layout Standard
22326
22327
22328 \backslash
22329 /
22330 \end_layout
22331
22332 \end_inset
22333
22334 -codeseg.
22335 \end_layout
22336
22337 \begin_layout Itemize
22338
22339 \series bold
22340 constseg
22341 \series default
22342  <name>
22343 \begin_inset LatexCommand \index{\#pragma constseg}
22344
22345 \end_inset
22346
22347 - Use this name (max.
22348  8 characters) for the const segment.
22349  See option -
22350 \begin_inset ERT
22351 status collapsed
22352
22353 \begin_layout Standard
22354
22355
22356 \backslash
22357 /
22358 \end_layout
22359
22360 \end_inset
22361
22362 -constseg.
22363 \end_layout
22364
22365 \begin_layout Standard
22366 The preprocessor SDCPP
22367 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22368
22369 \end_inset
22370
22371  supports the following #pragma directives:
22372 \end_layout
22373
22374 \begin_layout Itemize
22375
22376 \series bold
22377 pedantic_parse_number
22378 \series default
22379
22380 \begin_inset LatexCommand \index{pedantic}
22381
22382 \end_inset
22383
22384
22385 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22386
22387 \end_inset
22388
22389  (+ | -) 
22390 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22391
22392 \end_inset
22393
22394 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22395  properly and the macro LO_B(3) gets expanded.
22396  Default is off.
22397  See also the -
22398 \begin_inset ERT
22399 status collapsed
22400
22401 \begin_layout Standard
22402
22403
22404 \backslash
22405 /
22406 \end_layout
22407
22408 \end_inset
22409
22410 -pedantic-parse-number command line option 
22411 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22412
22413 \end_inset
22414
22415 .
22416  
22417 \newline
22418 Below is an example on how to use this pragma.
22419
22420 \emph on
22421  Note: this functionality is not in conformance with standard!
22422 \end_layout
22423
22424 \begin_layout Verse
22425
22426 \family typewriter
22427 #pragma pedantic_parse_number +
22428 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22429
22430 \end_inset
22431
22432
22433 \newline
22434
22435 \newline
22436 #define LO_B(x) ((x) & 0xff)
22437 \newline
22438
22439 \newline
22440 unsigned char foo(void)
22441 \newline
22442 {
22443 \newline
22444 \InsetSpace ~
22445 \InsetSpace ~
22446 \InsetSpace ~
22447 unsigned char c=0xfe-LO_B(3)
22448 ;
22449 \newline
22450
22451 \newline
22452 \InsetSpace ~
22453 \InsetSpace ~
22454 \InsetSpace ~
22455 return c;
22456 \newline
22457 }
22458 \newline
22459
22460 \end_layout
22461
22462 \begin_layout Itemize
22463
22464 \series bold
22465 preproc_asm
22466 \series default
22467
22468 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22469
22470 \end_inset
22471
22472  (+ | -) - switch _asm _endasm block preprocessing on / off.
22473  Default is on.
22474  You use this prama to define multilines of assembly code.
22475  This will prevent the preprocessor from changing the formating required
22476  by assembly code.
22477  Below is an example on how to use this pragma.
22478 \end_layout
22479
22480 \begin_layout Verse
22481
22482 \family typewriter
22483 #pragma preproc_asm -
22484 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22485
22486 \end_inset
22487
22488
22489 \newline
22490 #define MYDELAY _asm
22491 \newline
22492 \InsetSpace ~
22493 \InsetSpace ~
22494 \InsetSpace ~
22495 nop ;my assembly comment...
22496 \newline
22497 \InsetSpace ~
22498 \InsetSpace ~
22499 \InsetSpace ~
22500 nop
22501 \newline
22502 \InsetSpace ~
22503 \InsetSpace ~
22504 \InsetSpace ~
22505 nop
22506 \newline
22507 _endasm
22508 \newline
22509 #pragma preproc_asm
22510  +
22511 \newline
22512
22513 \newline
22514 void foo (void) 
22515 \newline
22516
22517 \newline
22518 \InsetSpace ~
22519 \InsetSpace ~
22520 \InsetSpace ~
22521  ...
22522  
22523 \newline
22524 \InsetSpace ~
22525 \InsetSpace ~
22526 \InsetSpace ~
22527  MYDELAY;
22528 \newline
22529 \InsetSpace ~
22530 \InsetSpace ~
22531 \InsetSpace ~
22532  ...
22533  
22534 \newline
22535
22536 \newline
22537
22538 \end_layout
22539
22540 \begin_layout Itemize
22541
22542 \series bold
22543 sdcc_hash
22544 \series default
22545
22546 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22547
22548 \end_inset
22549
22550  (+ | -) - Allow "naked" hash in macro definition, for example:
22551 \newline
22552
22553 \family typewriter
22554 #define DIR_LO(x) #(x & 0xff)
22555 \family default
22556
22557 \newline
22558 Default is off.
22559  Below is an example on how to use this pragma.
22560 \end_layout
22561
22562 \begin_layout Verse
22563
22564 \family typewriter
22565 #pragma preproc_asm +
22566 \newline
22567 #pragma sdcc_hash +
22568 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22569
22570 \end_inset
22571
22572
22573 \newline
22574
22575 \newline
22576 #define ROMCALL(x) 
22577 \backslash
22578
22579 \newline
22580 \InsetSpace ~
22581 \InsetSpace ~
22582 \InsetSpace ~
22583 mov R6_B3, #(x & 0xff) 
22584 \backslash
22585
22586 \newline
22587 \InsetSpace ~
22588 \InsetSpace ~
22589 \InsetSpace ~
22590 mov R7_B3, #((x >> 8) & 0xff) 
22591 \backslash
22592
22593 \newline
22594 \InsetSpace ~
22595 \InsetSpace ~
22596 \InsetSpace ~
22597 lcall __romcall
22598 \newline
22599
22600 \newline
22601 ...
22602 \newline
22603 _asm
22604 \newline
22605 ROMCALL(72)
22606 \newline
22607 _endasm;
22608 \newline
22609 ...
22610 \newline
22611
22612 \end_layout
22613
22614 \begin_layout Standard
22615 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22616 ons which might cause the compiler to generate extra stack and/or data space
22617  to store compiler generated temporary variables.
22618  This usually happens in large functions.
22619  Pragma directives should be used as shown in the following example, they
22620  are used to control options and optimizations for a given function.
22621  
22622 \end_layout
22623
22624 \begin_layout Verse
22625
22626 \family typewriter
22627 #pragma save
22628 \begin_inset LatexCommand \index{\#pragma save}
22629
22630 \end_inset
22631
22632  \InsetSpace ~
22633 \InsetSpace ~
22634 \InsetSpace ~
22635 \InsetSpace ~
22636 \InsetSpace ~
22637 \InsetSpace ~
22638 \InsetSpace ~
22639 /* save the current settings */ 
22640 \newline
22641 #pragma nogcse
22642 \begin_inset LatexCommand \index{\#pragma nogcse}
22643
22644 \end_inset
22645
22646  \InsetSpace ~
22647 \InsetSpace ~
22648 \InsetSpace ~
22649 \InsetSpace ~
22650 \InsetSpace ~
22651 /* turnoff global subexpression elimination */ 
22652 \newline
22653 #pragma noinduction
22654 \begin_inset LatexCommand \index{\#pragma noinduction}
22655
22656 \end_inset
22657
22658  /* turn off induction optimizations */ 
22659 \newline
22660 int foo () 
22661 \newline
22662
22663 \newline
22664 \InsetSpace ~
22665  \InsetSpace ~
22666  ...
22667  
22668 \newline
22669 \InsetSpace ~
22670  \InsetSpace ~
22671  /* large code */ 
22672 \newline
22673 \InsetSpace ~
22674  \InsetSpace ~
22675  ...
22676  
22677 \newline
22678
22679 \newline
22680 #pragma restore
22681 \begin_inset LatexCommand \index{\#pragma restore}
22682
22683 \end_inset
22684
22685  /* turn the optimizations back on */
22686 \end_layout
22687
22688 \begin_layout Standard
22689 The compiler will generate a warning message when extra space is allocated.
22690  It is strongly recommended that the save and restore pragmas be used when
22691  changing options for a function.
22692 \newline
22693
22694 \newline
22695
22696 \newline
22697
22698 \end_layout
22699
22700 \begin_layout Section
22701 Defines Created by the Compiler
22702 \end_layout
22703
22704 \begin_layout Standard
22705 The compiler creates the following #defines
22706 \begin_inset LatexCommand \index{\#defines}
22707
22708 \end_inset
22709
22710
22711 \begin_inset LatexCommand \index{Defines created by the compiler}
22712
22713 \end_inset
22714
22715 :
22716 \newline
22717
22718 \end_layout
22719
22720 \begin_layout Standard
22721 \begin_inset Tabular
22722 <lyxtabular version="3" rows="15" columns="2">
22723 <features>
22724 <column alignment="left" valignment="top" leftline="true" width="3in">
22725 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22726 <row topline="true" bottomline="true">
22727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22728 \begin_inset Text
22729
22730 \begin_layout Standard
22731
22732 \series bold
22733 #define
22734 \end_layout
22735
22736 \end_inset
22737 </cell>
22738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22739 \begin_inset Text
22740
22741 \begin_layout Standard
22742
22743 \series bold
22744 Description
22745 \end_layout
22746
22747 \end_inset
22748 </cell>
22749 </row>
22750 <row topline="true">
22751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22752 \begin_inset Text
22753
22754 \begin_layout Standard
22755 SDCC
22756 \begin_inset LatexCommand \index{SDCC}
22757
22758 \end_inset
22759
22760  
22761 \end_layout
22762
22763 \end_inset
22764 </cell>
22765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22766 \begin_inset Text
22767
22768 \begin_layout Standard
22769 Always defined.
22770  Since version 2.5.6 the version number as an int (ex.
22771  256)
22772 \end_layout
22773
22774 \end_inset
22775 </cell>
22776 </row>
22777 <row topline="true">
22778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22779 \begin_inset Text
22780
22781 \begin_layout Standard
22782 SDCC_mcs51
22783 \begin_inset LatexCommand \index{SDCC\_mcs51}
22784
22785 \end_inset
22786
22787  or SDCC_ds390
22788 \begin_inset LatexCommand \index{SDCC\_ds390}
22789
22790 \end_inset
22791
22792  or SDCC_z80
22793 \begin_inset LatexCommand \index{SDCC\_z80}
22794
22795 \end_inset
22796
22797 , etc.
22798 \end_layout
22799
22800 \end_inset
22801 </cell>
22802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22803 \begin_inset Text
22804
22805 \begin_layout Standard
22806 depending on the model used (e.g.: -mds390)
22807 \end_layout
22808
22809 \end_inset
22810 </cell>
22811 </row>
22812 <row topline="true">
22813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22814 \begin_inset Text
22815
22816 \begin_layout Standard
22817 __mcs51
22818 \begin_inset LatexCommand \index{\_\_mcs51}
22819
22820 \end_inset
22821
22822 , __ds390
22823 \begin_inset LatexCommand \index{\_\_ds390}
22824
22825 \end_inset
22826
22827 , __hc08
22828 \begin_inset LatexCommand \index{\_\_hc08}
22829
22830 \end_inset
22831
22832 , __z80
22833 \begin_inset LatexCommand \index{\_\_z80}
22834
22835 \end_inset
22836
22837 , etc
22838 \end_layout
22839
22840 \end_inset
22841 </cell>
22842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22843 \begin_inset Text
22844
22845 \begin_layout Standard
22846 depending on the model used (e.g.
22847  -mz80)
22848 \end_layout
22849
22850 \end_inset
22851 </cell>
22852 </row>
22853 <row topline="true">
22854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22855 \begin_inset Text
22856
22857 \begin_layout Standard
22858 SDCC_STACK_AUTO
22859 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22860
22861 \end_inset
22862
22863
22864 \end_layout
22865
22866 \end_inset
22867 </cell>
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22869 \begin_inset Text
22870
22871 \begin_layout Standard
22872 when 
22873 \emph on
22874 -
22875 \begin_inset ERT
22876 status collapsed
22877
22878 \begin_layout Standard
22879
22880
22881 \backslash
22882 /
22883 \end_layout
22884
22885 \end_inset
22886
22887 -stack-auto
22888 \emph default
22889  option is used
22890 \end_layout
22891
22892 \end_inset
22893 </cell>
22894 </row>
22895 <row topline="true">
22896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22897 \begin_inset Text
22898
22899 \begin_layout Standard
22900 SDCC_MODEL_SMALL
22901 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22902
22903 \end_inset
22904
22905
22906 \end_layout
22907
22908 \end_inset
22909 </cell>
22910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22911 \begin_inset Text
22912
22913 \begin_layout Standard
22914 when 
22915 \emph on
22916 -
22917 \begin_inset ERT
22918 status collapsed
22919
22920 \begin_layout Standard
22921
22922
22923 \backslash
22924 /
22925 \end_layout
22926
22927 \end_inset
22928
22929 -model-small
22930 \emph default
22931  is used
22932 \end_layout
22933
22934 \end_inset
22935 </cell>
22936 </row>
22937 <row topline="true">
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22939 \begin_inset Text
22940
22941 \begin_layout Standard
22942 SDCC_MODEL_MEDIUM
22943 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22944
22945 \end_inset
22946
22947
22948 \end_layout
22949
22950 \end_inset
22951 </cell>
22952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22953 \begin_inset Text
22954
22955 \begin_layout Standard
22956 when 
22957 \emph on
22958 -
22959 \begin_inset ERT
22960 status collapsed
22961
22962 \begin_layout Standard
22963
22964
22965 \backslash
22966 /
22967 \end_layout
22968
22969 \end_inset
22970
22971 -model-medium
22972 \emph default
22973  is used
22974 \end_layout
22975
22976 \end_inset
22977 </cell>
22978 </row>
22979 <row topline="true">
22980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22981 \begin_inset Text
22982
22983 \begin_layout Standard
22984 SDCC_MODEL_LARGE
22985 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22986
22987 \end_inset
22988
22989
22990 \end_layout
22991
22992 \end_inset
22993 </cell>
22994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22995 \begin_inset Text
22996
22997 \begin_layout Standard
22998 when 
22999 \emph on
23000 -
23001 \begin_inset ERT
23002 status collapsed
23003
23004 \begin_layout Standard
23005
23006
23007 \backslash
23008 /
23009 \end_layout
23010
23011 \end_inset
23012
23013 -model-large
23014 \emph default
23015  is used
23016 \end_layout
23017
23018 \end_inset
23019 </cell>
23020 </row>
23021 <row topline="true">
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23023 \begin_inset Text
23024
23025 \begin_layout Standard
23026 SDCC_USE_XSTACK
23027 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23028
23029 \end_inset
23030
23031
23032 \end_layout
23033
23034 \end_inset
23035 </cell>
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23037 \begin_inset Text
23038
23039 \begin_layout Standard
23040 when 
23041 \emph on
23042 -
23043 \begin_inset ERT
23044 status collapsed
23045
23046 \begin_layout Standard
23047
23048
23049 \backslash
23050 /
23051 \end_layout
23052
23053 \end_inset
23054
23055 -xstack
23056 \emph default
23057  option is used
23058 \end_layout
23059
23060 \end_inset
23061 </cell>
23062 </row>
23063 <row topline="true">
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \begin_layout Standard
23068 SDCC_STACK_TENBIT
23069 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23070
23071 \end_inset
23072
23073  
23074 \end_layout
23075
23076 \end_inset
23077 </cell>
23078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23079 \begin_inset Text
23080
23081 \begin_layout Standard
23082 when 
23083 \emph on
23084 -mds390
23085 \emph default
23086  is used
23087 \end_layout
23088
23089 \end_inset
23090 </cell>
23091 </row>
23092 <row topline="true">
23093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23094 \begin_inset Text
23095
23096 \begin_layout Standard
23097 SDCC_MODEL_FLAT24
23098 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23099
23100 \end_inset
23101
23102
23103 \end_layout
23104
23105 \end_inset
23106 </cell>
23107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23108 \begin_inset Text
23109
23110 \begin_layout Standard
23111 when 
23112 \emph on
23113 -mds390
23114 \emph default
23115  is used
23116 \end_layout
23117
23118 \end_inset
23119 </cell>
23120 </row>
23121 <row topline="true">
23122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23123 \begin_inset Text
23124
23125 \begin_layout Standard
23126 SDCC_REVISION
23127 \begin_inset LatexCommand \index{SDCC\_REVISION}
23128
23129 \end_inset
23130
23131
23132 \end_layout
23133
23134 \end_inset
23135 </cell>
23136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23137 \begin_inset Text
23138
23139 \begin_layout Standard
23140 Always defined.
23141  SDCC svn revision number
23142 \end_layout
23143
23144 \end_inset
23145 </cell>
23146 </row>
23147 <row topline="true">
23148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23149 \begin_inset Text
23150
23151 \begin_layout Standard
23152 SDCC_PARMS_IN_BANK1
23153 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23154
23155 \end_inset
23156
23157
23158 \end_layout
23159
23160 \end_inset
23161 </cell>
23162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23163 \begin_inset Text
23164
23165 \begin_layout Standard
23166 when 
23167 \emph on
23168 -
23169 \begin_inset ERT
23170 status collapsed
23171
23172 \begin_layout Standard
23173
23174
23175 \backslash
23176 /
23177 \end_layout
23178
23179 \end_inset
23180
23181 -parms-in-bank1
23182 \emph default
23183  is used
23184 \end_layout
23185
23186 \end_inset
23187 </cell>
23188 </row>
23189 <row topline="true">
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23191 \begin_inset Text
23192
23193 \begin_layout Standard
23194 SDCC_FLOAT_REENT
23195 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23196
23197 \end_inset
23198
23199
23200 \end_layout
23201
23202 \end_inset
23203 </cell>
23204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23205 \begin_inset Text
23206
23207 \begin_layout Standard
23208 when 
23209 \emph on
23210 -
23211 \begin_inset ERT
23212 status collapsed
23213
23214 \begin_layout Standard
23215
23216
23217 \backslash
23218 /
23219 \end_layout
23220
23221 \end_inset
23222
23223 -float-reent
23224 \emph default
23225  is used
23226 \end_layout
23227
23228 \end_inset
23229 </cell>
23230 </row>
23231 <row topline="true" bottomline="true">
23232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23233 \begin_inset Text
23234
23235 \begin_layout Standard
23236 SDCC_INT_LONG_REENT
23237 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23238
23239 \end_inset
23240
23241
23242 \end_layout
23243
23244 \end_inset
23245 </cell>
23246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23247 \begin_inset Text
23248
23249 \begin_layout Standard
23250 when 
23251 \emph on
23252 -
23253 \begin_inset ERT
23254 status collapsed
23255
23256 \begin_layout Standard
23257
23258
23259 \backslash
23260 /
23261 \end_layout
23262
23263 \end_inset
23264
23265 -int-long-reent
23266 \emph default
23267  is used
23268 \end_layout
23269
23270 \end_inset
23271 </cell>
23272 </row>
23273 </lyxtabular>
23274
23275 \end_inset
23276
23277
23278 \end_layout
23279
23280 \begin_layout Chapter
23281 Notes on supported Processors
23282 \end_layout
23283
23284 \begin_layout Section
23285 MCS51 variants
23286 \begin_inset LatexCommand \label{sub:MCS51-variants}
23287
23288 \end_inset
23289
23290
23291 \begin_inset LatexCommand \index{MCS51 variants}
23292
23293 \end_inset
23294
23295
23296 \end_layout
23297
23298 \begin_layout Standard
23299 MCS51 processors are available from many vendors and come in many different
23300  flavours.
23301  While they might differ considerably in respect to Special Function Registers
23302  the core MCS51 is usually not modified or is kept compatible.
23303  
23304 \end_layout
23305
23306 \begin_layout Subsection
23307 pdata access by SFR 
23308 \end_layout
23309
23310 \begin_layout Standard
23311 With the upcome of devices with internal xdata and flash memory devices
23312  using port P2
23313 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23314
23315 \end_inset
23316
23317  as dedicated I/O port is becoming more popular.
23318  Switching the high byte for pdata
23319 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23320
23321 \end_inset
23322
23323  access which was formerly done by port P2 is then achieved by a Special
23324  Function Register
23325 \begin_inset LatexCommand \index{sfr}
23326
23327 \end_inset
23328
23329 .
23330  In well-established MCS51 tradition the address of this 
23331 \emph on
23332 sfr
23333 \emph default
23334  is where the chip designers decided to put it.
23335  Needless to say that they didn't agree on a common name either.
23336  So that the startup code can correctly initialize xdata variables, you
23337  should define an sfr with the name _XPAGE
23338 \family typewriter
23339
23340 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23341
23342 \end_inset
23343
23344
23345 \family default
23346  at the appropriate location if the default, port P2, is not used for this.
23347  Some examples are:
23348 \end_layout
23349
23350 \begin_layout Verse
23351
23352 \family typewriter
23353 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23354  MPAGE */
23355 \end_layout
23356
23357 \begin_layout Verse
23358
23359 \family typewriter
23360 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23361  a.k.a.
23362  MPAGE */
23363 \end_layout
23364
23365 \begin_layout Verse
23366
23367 \family typewriter
23368 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23369  XPAGE */
23370 \end_layout
23371
23372 \begin_layout Verse
23373
23374 \family typewriter
23375 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23376  EMI0CN */
23377 \end_layout
23378
23379 \begin_layout Verse
23380
23381 \family typewriter
23382 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23383  EMI0CN */
23384 \end_layout
23385
23386 \begin_layout Standard
23387 For more exotic implementations further customizations may be needed.
23388  See section 
23389 \begin_inset LatexCommand \ref{sub:Startup-Code}
23390
23391 \end_inset
23392
23393  for other possibilities.
23394 \end_layout
23395
23396 \begin_layout Subsection
23397 Other Features available by SFR
23398 \end_layout
23399
23400 \begin_layout Standard
23401 Some MCS51 variants offer features like Double DPTR
23402 \begin_inset LatexCommand \index{DPTR}
23403
23404 \end_inset
23405
23406 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23407  These are currently not used for the MCS51 port.
23408  If you absolutely need them you can fall back to inline assembly or submit
23409  a patch to SDCC.
23410 \begin_inset VSpace bigskip
23411 \end_inset
23412
23413
23414 \end_layout
23415
23416 \begin_layout Section
23417 DS400 port
23418 \end_layout
23419
23420 \begin_layout Standard
23421 The DS80C400
23422 \begin_inset LatexCommand \index{DS80C400}
23423
23424 \end_inset
23425
23426
23427 \begin_inset LatexCommand \index{DS400}
23428
23429 \end_inset
23430
23431  microcontroller has a rich set of peripherals.
23432  In its built-in ROM library it includes functions to access some of the
23433  features, among them is a TCP stack with IP4 and IP6 support.
23434  Library headers (currently in beta status) and other files are provided
23435  at 
23436 \size footnotesize
23437
23438 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23439
23440 \end_inset
23441
23442 .
23443  
23444 \begin_inset VSpace bigskip
23445 \end_inset
23446
23447
23448 \end_layout
23449
23450 \begin_layout Section
23451 The Z80 and gbz80 port
23452 \end_layout
23453
23454 \begin_layout Standard
23455 SDCC can target both the Zilog Z80
23456 \begin_inset LatexCommand \index{Z80}
23457
23458 \end_inset
23459
23460  and the Nintendo Gameboy's Z80-like gbz80
23461 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23462
23463 \end_inset
23464
23465 .
23466  The Z80 port is passed through the same 
23467 \emph on
23468 regressions tests
23469 \begin_inset LatexCommand \index{Regression test}
23470
23471 \end_inset
23472
23473
23474 \emph default
23475  (see section 
23476 \begin_inset LatexCommand \ref{sec:Quality-control}
23477
23478 \end_inset
23479
23480 ) as the MCS51 and DS390 ports, so floating point support, support for long
23481  variables and bitfield support is fine.
23482  See mailing lists and forums about interrupt routines.
23483 \end_layout
23484
23485 \begin_layout Standard
23486 As always, the code is the authoritative reference - see z80/ralloc.c and
23487  z80/gen.c.
23488  The stack
23489 \begin_inset LatexCommand \index{Z80!stack}
23490
23491 \end_inset
23492
23493  frame is similar to that generated by the IAR Z80 compiler.
23494  IX is used as the base pointer, HL and IY are used as a temporary registers,
23495  and BC and DE are available for holding variables.
23496  Return values
23497 \begin_inset LatexCommand \index{Z80!return value}
23498
23499 \end_inset
23500
23501  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23502  bytes).
23503  The gbz80 port use the same set of registers for the return values, but
23504  in a different order of significance: E (one byte), DE (two bytes), or
23505  HLDE (four bytes).
23506 \begin_inset VSpace bigskip
23507 \end_inset
23508
23509
23510 \end_layout
23511
23512 \begin_layout Section
23513 The HC08 port
23514 \end_layout
23515
23516 \begin_layout Standard
23517 The port to the Freescale/Motorola HC08
23518 \begin_inset LatexCommand \index{HC08}
23519
23520 \end_inset
23521
23522  family has been added in October 2003, and is still undergoing some basic
23523  development.
23524  The code generator is complete, but the register allocation is still quite
23525  unoptimized.
23526  Some of the SDCC's standard C library functions have embedded non-HC08
23527  inline assembly and so are not yet usable.
23528 \end_layout
23529
23530 \begin_layout Standard
23531 The HC08 port passes the regression test suite (see section 
23532 \begin_inset LatexCommand \ref{sec:Quality-control}
23533
23534 \end_inset
23535
23536 ).
23537 \begin_inset VSpace bigskip
23538 \end_inset
23539
23540
23541 \newpage
23542
23543 \end_layout
23544
23545 \begin_layout Section
23546 The PIC14
23547 \begin_inset LatexCommand \index{PIC14}
23548
23549 \end_inset
23550
23551  port
23552 \end_layout
23553
23554 \begin_layout Standard
23555 The PIC14 port adds support for Microchip
23556 \begin_inset LatexCommand \index{Microchip}
23557
23558 \end_inset
23559
23560
23561 \begin_inset Formula $^{\text{TM}}$
23562 \end_inset
23563
23564  PIC
23565 \begin_inset LatexCommand \index{PIC14}
23566
23567 \end_inset
23568
23569
23570 \begin_inset Formula $^{\text{TM}}$
23571 \end_inset
23572
23573  MCUs with 14 bit wide instructions.
23574  This port is not yet mature and still lacks many features.
23575  However, it can work for simple code.
23576 \end_layout
23577
23578 \begin_layout Standard
23579 Currently supported devices include:
23580 \end_layout
23581
23582 \begin_layout Standard
23583 12F: 629, 635, 675, 683
23584 \end_layout
23585
23586 \begin_layout Standard
23587 16C: 432, 433
23588 \end_layout
23589
23590 \begin_layout Standard
23591 16C: 554, 557, 558
23592 \end_layout
23593
23594 \begin_layout Standard
23595 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23596 \end_layout
23597
23598 \begin_layout Standard
23599 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23600  781, 782
23601 \end_layout
23602
23603 \begin_layout Standard
23604 16C: 925, 926
23605 \end_layout
23606
23607 \begin_layout Standard
23608 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23609  689, 690
23610 \end_layout
23611
23612 \begin_layout Standard
23613 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23614 \end_layout
23615
23616 \begin_layout Standard
23617 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23618  877, 877a, 88
23619 \end_layout
23620
23621 \begin_layout Standard
23622 16F: 913, 914, 916, 917
23623 \end_layout
23624
23625 \begin_layout Standard
23626 An up-to-date list of currently supported devices can be obtained via 
23627 \family typewriter
23628 sdcc -mpic14 -phelp foo.c
23629 \family default
23630  (foo.c must exist...).
23631 \end_layout
23632
23633 \begin_layout Subsection
23634 PIC Code Pages
23635 \begin_inset LatexCommand \index{code page (pic14)}
23636
23637 \end_inset
23638
23639  and Memory Banks
23640 \begin_inset LatexCommand \index{Memory bank (pic14)}
23641
23642 \end_inset
23643
23644
23645 \end_layout
23646
23647 \begin_layout Standard
23648 The linker organizes allocation for the code page and RAM banks.
23649  It does not have intimate knowledge of the code flow.
23650  It will put all the code section of a single .asm file into a single code
23651  page.
23652  In order to make use of multiple code pages, separate asm files must be
23653  used.
23654  The compiler assigns all 
23655 \emph on
23656 static
23657 \emph default
23658  functions of a single .c file into the same code page.
23659 \newline
23660
23661 \newline
23662 To get the best results,
23663  follow these guidelines:
23664 \end_layout
23665
23666 \begin_layout Enumerate
23667 Make local functions static, as non static functions require code page selection
23668  overhead.
23669 \newline
23670 Due to the way sdcc handles functions, place called functions prior
23671  to calling functions in the file wherever possible: Otherwise sdcc will
23672  insert unneccessary pagesel directives around the call, believing that
23673  the called function is externally defined.
23674 \end_layout
23675
23676 \begin_layout Enumerate
23677 For devices that have multiple code pages it is more efficient to use the
23678  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23679  but only 2 files for the 16F874.
23680  This way the linker can put the code for each file into different code
23681  pages and there will be less page selection overhead.
23682 \end_layout
23683
23684 \begin_layout Enumerate
23685 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23686  instruction set), use `unsigned char' wherever possible instead of `int'.
23687 \end_layout
23688
23689 \begin_layout Subsection
23690 Adding New Devices to the Port 
23691 \end_layout
23692
23693 \begin_layout Standard
23694 Adding support for a new 14
23695 \begin_inset ERT
23696 status open
23697
23698 \begin_layout Standard
23699
23700
23701 \backslash
23702 ,
23703 \end_layout
23704
23705 \end_inset
23706
23707 bit PIC MCU requires the following steps:
23708 \end_layout
23709
23710 \begin_layout Enumerate
23711 Create a new device description.
23712 \newline
23713 Each device is described in two files: pic16f*.h
23714  and pic16f*.c.
23715  These files primarily define SFRs, structs to access their bits, and symbolic
23716  configuration options.
23717  Both files can be generated from gputils' .inc files using the perl script
23718  
23719 \family typewriter
23720 support/scripts/inc2h.pl
23721 \family default
23722 .
23723  This file also contains further instructions on how to proceed.
23724 \end_layout
23725
23726 \begin_layout Enumerate
23727 Copy the .h file into SDCC's include path and either add the .c file to your
23728  project or copy it to 
23729 \family typewriter
23730 device/lib/pic/libdev
23731 \family default
23732 .
23733  Afterwards, rebuild and install the libraries.
23734 \end_layout
23735
23736 \begin_layout Enumerate
23737 Edit pic14devices.txt in SDCC's include path (
23738 \family typewriter
23739 device/include/pic/
23740 \family default
23741  in the source tree or 
23742 \family typewriter
23743 /usr/local/share/sdcc/include/pic
23744 \family default
23745  after installation).
23746 \newline
23747 You need to add a device specification here to make
23748  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23749  the compiler.
23750  Probably you can copy and modify an existing entry.
23751  The file format is documented at the top of the file.
23752 \end_layout
23753
23754 \begin_layout Subsection
23755 Interrupt Code
23756 \end_layout
23757
23758 \begin_layout Standard
23759 For the interrupt function, use the keyword `__interrupt'
23760 \begin_inset LatexCommand \index{PIC14!interrupt}
23761
23762 \end_inset
23763
23764  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23765  there to avoid a syntax error - it ought to be fixed).
23766  E.g.:
23767 \end_layout
23768
23769 \begin_layout Verse
23770
23771 \family typewriter
23772 void Intr(void) __interrupt 0
23773 \newline
23774 {
23775 \newline
23776 \InsetSpace ~
23777 \InsetSpace ~
23778 T0IF = 0; /* Clear timer interrupt */
23779 \newline
23780 }
23781 \end_layout
23782
23783 \begin_layout Subsection
23784 Linking and Assembling
23785 \end_layout
23786
23787 \begin_layout Standard
23788 For assembling you can use either GPUTILS'
23789 \begin_inset LatexCommand \index{gputils (pic tools)}
23790
23791 \end_inset
23792
23793  gpasm.exe or MPLAB's mpasmwin.exe.
23794  GPUTILS are available from 
23795 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23796
23797 \end_inset
23798
23799 .
23800  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23801  If you use MPLAB and an interrupt function then the linker script file
23802  vectors section will need to be enlarged to link with mplink.
23803 \newline
23804
23805 \newline
23806 Here is a 
23807 \family typewriter
23808 Makefile
23809 \family default
23810  using GPUTILS:
23811 \end_layout
23812
23813 \begin_layout Verse
23814
23815 \family typewriter
23816 .c.o:
23817 \newline
23818 \InsetSpace ~
23819 \InsetSpace ~
23820 \InsetSpace ~
23821 \InsetSpace ~
23822 \InsetSpace ~
23823 \InsetSpace ~
23824 \InsetSpace ~
23825 \InsetSpace ~
23826 sdcc -V -mpic14 -p16f877 -c $< 
23827 \newline
23828
23829 \newline
23830 $(PRJ).hex: $(OBJS) 
23831 \newline
23832 \InsetSpace ~
23833 \InsetSpace ~
23834 \InsetSpace ~
23835 \InsetSpace ~
23836 \InsetSpace ~
23837 \InsetSpace ~
23838 \InsetSpace ~
23839 \InsetSpace ~
23840 gplink -m -s $(PRJ).lkr
23841  -o $(PRJ).hex $(OBJS) libsdcc.lib
23842 \end_layout
23843
23844 \begin_layout Standard
23845 Here is a 
23846 \family typewriter
23847 Makefile
23848 \family default
23849  using MPLAB:
23850 \end_layout
23851
23852 \begin_layout Verse
23853
23854 \family typewriter
23855 .c.o: 
23856 \newline
23857 \InsetSpace ~
23858 \InsetSpace ~
23859 \InsetSpace ~
23860 \InsetSpace ~
23861 \InsetSpace ~
23862 \InsetSpace ~
23863 \InsetSpace ~
23864 \InsetSpace ~
23865 sdcc -S -V -mpic14 -p16f877 $< 
23866 \newline
23867 \InsetSpace ~
23868 \InsetSpace ~
23869 \InsetSpace ~
23870 \InsetSpace ~
23871 \InsetSpace ~
23872 \InsetSpace ~
23873 \InsetSpace ~
23874 \InsetSpace ~
23875 mpasmwin /q /o $*.asm
23876 \newline
23877
23878 \newline
23879 $(PRJ).hex: $(OBJS)
23880  
23881 \newline
23882 \InsetSpace ~
23883 \InsetSpace ~
23884 \InsetSpace ~
23885 \InsetSpace ~
23886 \InsetSpace ~
23887 \InsetSpace ~
23888 \InsetSpace ~
23889 \InsetSpace ~
23890 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23891 \end_layout
23892
23893 \begin_layout Standard
23894 Please note that indentations within a
23895 \family typewriter
23896  Makefile
23897 \family default
23898  have to be done with a tabulator character.
23899 \end_layout
23900
23901 \begin_layout Subsection
23902 Command-Line Options
23903 \end_layout
23904
23905 \begin_layout Standard
23906 Besides the switches common to all SDCC backends, the PIC14 port accepts
23907  the following options (for an updated list see sdcc -
23908 \begin_inset ERT
23909 status collapsed
23910
23911 \begin_layout Standard
23912
23913
23914 \backslash
23915 /
23916 \end_layout
23917
23918 \end_inset
23919
23920 -help):
23921 \end_layout
23922
23923 \begin_layout Description
23924 -
23925 \begin_inset ERT
23926 status collapsed
23927
23928 \begin_layout Standard
23929
23930
23931 \backslash
23932 /
23933 \end_layout
23934
23935 \end_inset
23936
23937 -debug-xtra
23938 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23939
23940 \end_inset
23941
23942  emit debug info in assembly output
23943 \end_layout
23944
23945 \begin_layout Description
23946 -
23947 \begin_inset ERT
23948 status collapsed
23949
23950 \begin_layout Standard
23951
23952
23953 \backslash
23954 /
23955 \end_layout
23956
23957 \end_inset
23958
23959 -no-pcode-opt
23960 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23961
23962 \end_inset
23963
23964  disable (slightly faulty) optimization on pCode
23965 \end_layout
23966
23967 \begin_layout Description
23968 -
23969 \begin_inset ERT
23970 status collapsed
23971
23972 \begin_layout Standard
23973
23974
23975 \backslash
23976 /
23977 \end_layout
23978
23979 \end_inset
23980
23981 -stack-loc
23982 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23983
23984 \end_inset
23985
23986  sets the lowest address of the argument passing stack (defaults to a suitably
23987  large shared databank to reduce BANKSEL overhead)
23988 \end_layout
23989
23990 \begin_layout Description
23991 -
23992 \begin_inset ERT
23993 status collapsed
23994
23995 \begin_layout Standard
23996
23997
23998 \backslash
23999 /
24000 \end_layout
24001
24002 \end_inset
24003
24004 -stack-size
24005 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24006
24007 \end_inset
24008
24009  sets the size if the argument passing stack (default: 16, minimum: 4)
24010 \end_layout
24011
24012 \begin_layout Subsection
24013 Environment Variables
24014 \end_layout
24015
24016 \begin_layout Standard
24017 The PIC14 port recognizes the following environment variables:
24018 \end_layout
24019
24020 \begin_layout Description
24021 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24022  register (the ones called r0xNNNN) in a section of its own.
24023  By default (if this variable is unset), sdcc tries to cluster registers
24024  in sections in order to reduce the BANKSEL overhead when accessing them.
24025 \end_layout
24026
24027 \begin_layout Subsection
24028 The Library
24029 \end_layout
24030
24031 \begin_layout Standard
24032 The PIC14 library currently only contains support routines required by the
24033  compiler to implement multiplication, division, and floating point support.
24034  No libc-like replacement is available at the moment, though many of the
24035  common sdcc library sources (in 
24036 \family typewriter
24037 device/lib
24038 \family default
24039 ) should also compile with the PIC14 port.
24040 \end_layout
24041
24042 \begin_layout Subsubsection
24043 error: missing definition for symbol ``__gptrget1''
24044 \end_layout
24045
24046 \begin_layout Standard
24047 The PIC14 port uses library routines to provide more complex operations
24048  like multiplication, division/modulus and (generic) pointer dereferencing.
24049  In order to add these routines to your project, you must link with PIC14's
24050  
24051 \family typewriter
24052 libsdcc.lib
24053 \family default
24054 .
24055  For single source file projects this is done automatically, more complex
24056  projects must add 
24057 \family typewriter
24058 libsdcc.lib
24059 \family default
24060  to the linker's arguments.
24061  Make sure you also add an include path for the library (using the -I switch
24062  to the linker)!
24063 \end_layout
24064
24065 \begin_layout Subsubsection
24066 Processor mismatch in file ``XXX''.
24067 \end_layout
24068
24069 \begin_layout Standard
24070 This warning can usually be ignored due to the very good compatibility amongst
24071  14
24072 \begin_inset ERT
24073 status open
24074
24075 \begin_layout Standard
24076
24077
24078 \backslash
24079 ,
24080 \end_layout
24081
24082 \end_inset
24083
24084 bit PIC
24085 \begin_inset LatexCommand \index{PIC14}
24086
24087 \end_inset
24088
24089  devices.
24090 \end_layout
24091
24092 \begin_layout Standard
24093 You might also consider recompiling the library for your specific device
24094  by changing the ARCH=p16f877 (default target) entry in 
24095 \family typewriter
24096 device/lib/pic/Makefile.in
24097 \family default
24098  and 
24099 \family typewriter
24100 device/lib/pic/Makefile
24101 \family default
24102  to reflect your device.
24103  This might even improve performance for smaller devices as unneccesary
24104  BANKSELs might be removed.
24105 \end_layout
24106
24107 \begin_layout Subsection
24108 Known Bugs
24109 \end_layout
24110
24111 \begin_layout Subsubsection
24112 Function arguments
24113 \end_layout
24114
24115 \begin_layout Standard
24116 Functions with variable argument lists (like printf) are not yet supported.
24117  Similarly, taking the argument of the first argument passed into a function
24118  does not work: It is currently passed in WREG and has no address...
24119 \end_layout
24120
24121 \begin_layout Subsubsection
24122 Regression tests fail
24123 \end_layout
24124
24125 \begin_layout Standard
24126 Though the small subset of regression tests in src/regression passes, SDCC
24127  regression test suite does not, indicating that there are still major bugs
24128  in the port.
24129  However, many smaller projects have successfully used SDCC in the past...
24130 \end_layout
24131
24132 \begin_layout Standard
24133
24134 \size footnotesize
24135
24136 \newpage
24137
24138 \end_layout
24139
24140 \begin_layout Section
24141 The PIC16
24142 \begin_inset LatexCommand \index{PIC16}
24143
24144 \end_inset
24145
24146  port
24147 \end_layout
24148
24149 \begin_layout Standard
24150 The PIC16 port adds support for Microchip
24151 \begin_inset LatexCommand \index{Microchip}
24152
24153 \end_inset
24154
24155
24156 \begin_inset Formula $^{\text{TM}}$
24157 \end_inset
24158
24159  PIC
24160 \begin_inset LatexCommand \index{PIC}
24161
24162 \end_inset
24163
24164
24165 \begin_inset Formula $^{\text{TM}}$
24166 \end_inset
24167
24168  MCUs with 16 bit wide instructions.
24169  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24170 ; devices supported by the port include:
24171 \end_layout
24172
24173 \begin_layout Standard
24174 18F: 242, 248, 252, 258, 442, 448, 452, 458
24175 \end_layout
24176
24177 \begin_layout Standard
24178 18F: 1220, 1320
24179 \end_layout
24180
24181 \begin_layout Standard
24182 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24183  2620
24184 \end_layout
24185
24186 \begin_layout Standard
24187 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24188  45j10, 4620
24189 \end_layout
24190
24191 \begin_layout Standard
24192 18F: 6520, 6620, 6680, 6720
24193 \end_layout
24194
24195 \begin_layout Standard
24196 18F: 8520, 8620, 8680, 8720
24197 \end_layout
24198
24199 \begin_layout Subsection
24200 Global Options
24201 \end_layout
24202
24203 \begin_layout Standard
24204 PIC16 port supports the standard command line arguments as supposed, with
24205  the exception of certain cases that will be mentioned in the following
24206  list:
24207 \end_layout
24208
24209 \begin_layout Description
24210 -
24211 \begin_inset ERT
24212 status collapsed
24213
24214 \begin_layout Standard
24215
24216
24217 \backslash
24218 /
24219 \end_layout
24220
24221 \end_inset
24222
24223 -callee-saves
24224 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24225
24226 \end_inset
24227
24228  See -
24229 \begin_inset ERT
24230 status collapsed
24231
24232 \begin_layout Standard
24233
24234
24235 \backslash
24236 /
24237 \end_layout
24238
24239 \end_inset
24240
24241 -all-callee-saves
24242 \end_layout
24243
24244 \begin_layout Description
24245 -
24246 \begin_inset ERT
24247 status collapsed
24248
24249 \begin_layout Standard
24250
24251
24252 \backslash
24253 /
24254 \end_layout
24255
24256 \end_inset
24257
24258 -fommit-frame-pointer
24259 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24260
24261 \end_inset
24262
24263  Frame pointer will be omitted when the function uses no local variables.
24264 \end_layout
24265
24266 \begin_layout Subsection
24267 Port Specific Options
24268 \begin_inset LatexCommand \index{Options PIC16}
24269
24270 \end_inset
24271
24272
24273 \end_layout
24274
24275 \begin_layout Standard
24276 The port specific options appear after the global options in the sdcc -
24277 \begin_inset ERT
24278 status collapsed
24279
24280 \begin_layout Standard
24281
24282
24283 \backslash
24284 /
24285 \end_layout
24286
24287 \end_inset
24288
24289 -help output.
24290 \end_layout
24291
24292 \begin_layout Subsubsection
24293 Code Generation Options
24294 \end_layout
24295
24296 \begin_layout Standard
24297 These options influence the generated assembler code.
24298 \end_layout
24299
24300 \begin_layout Description
24301 -
24302 \begin_inset ERT
24303 status collapsed
24304
24305 \begin_layout Standard
24306
24307
24308 \backslash
24309 /
24310 \end_layout
24311
24312 \end_inset
24313
24314 -pstack-model=[model] Used in conjuction with the command above.
24315  Defines the stack model to be used, valid stack models are:
24316 \end_layout
24317
24318 \begin_deeper
24319 \begin_layout List
24320 \labelwidthstring 00.00.0000
24321
24322 \emph on
24323 small
24324 \emph default
24325  Selects small stack model.
24326  8 bit stack and frame pointers.
24327  Supports 256 bytes stack size.
24328 \end_layout
24329
24330 \begin_layout List
24331 \labelwidthstring 00.00.0000
24332
24333 \emph on
24334 large
24335 \emph default
24336  Selects large stack model.
24337  16 bit stack and frame pointers.
24338  Supports 65536 bytes stack size.
24339 \end_layout
24340
24341 \end_deeper
24342 \begin_layout Description
24343 -
24344 \begin_inset ERT
24345 status collapsed
24346
24347 \begin_layout Standard
24348
24349
24350 \backslash
24351 /
24352 \end_layout
24353
24354 \end_inset
24355
24356 -pno-banksel Do not generate BANKSEL assembler directives.
24357 \end_layout
24358
24359 \begin_layout Description
24360 -
24361 \begin_inset ERT
24362 status collapsed
24363
24364 \begin_layout Standard
24365
24366
24367 \backslash
24368 /
24369 \end_layout
24370
24371 \end_inset
24372
24373 -extended Enable extended instruction set/literal offset addressing mode.
24374  Use with care!
24375 \end_layout
24376
24377 \begin_layout Subsubsection
24378 Optimization Options
24379 \end_layout
24380
24381 \begin_layout Description
24382 -
24383 \begin_inset ERT
24384 status collapsed
24385
24386 \begin_layout Standard
24387
24388
24389 \backslash
24390 /
24391 \end_layout
24392
24393 \end_inset
24394
24395 -obanksel=n Set optimization level for inserting BANKSELs.
24396 \newline
24397
24398 \end_layout
24399
24400 \begin_deeper
24401 \begin_layout List
24402 \labelwidthstring 00.00.0000
24403 0 no optimization
24404 \end_layout
24405
24406 \begin_layout List
24407 \labelwidthstring 00.00.0000
24408 1 checks previous used register and if it is the same then does not emit
24409  BANKSEL, accounts only for labels.
24410 \end_layout
24411
24412 \begin_layout List
24413 \labelwidthstring 00.00.0000
24414 2 tries to check the location of (even different) symbols and removes BANKSELs
24415  if they are in the same bank.
24416  
24417 \newline
24418
24419 \emph on
24420 Important: There might be problems if the linker script has data sections
24421  across bank borders!
24422 \end_layout
24423
24424 \end_deeper
24425 \begin_layout Description
24426 -
24427 \begin_inset ERT
24428 status collapsed
24429
24430 \begin_layout Standard
24431
24432
24433 \backslash
24434 /
24435 \end_layout
24436
24437 \end_inset
24438
24439 -denable-peeps Force the usage of peepholes.
24440  Use with care.
24441 \end_layout
24442
24443 \begin_layout Description
24444 -
24445 \begin_inset ERT
24446 status collapsed
24447
24448 \begin_layout Standard
24449
24450
24451 \backslash
24452 /
24453 \end_layout
24454
24455 \end_inset
24456
24457 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24458 \end_layout
24459
24460 \begin_layout Description
24461 -
24462 \begin_inset ERT
24463 status collapsed
24464
24465 \begin_layout Standard
24466
24467
24468 \backslash
24469 /
24470 \end_layout
24471
24472 \end_inset
24473
24474 -optimize-cmp Try to optimize some compares.
24475 \end_layout
24476
24477 \begin_layout Description
24478 -
24479 \begin_inset ERT
24480 status collapsed
24481
24482 \begin_layout Standard
24483
24484
24485 \backslash
24486 /
24487 \end_layout
24488
24489 \end_inset
24490
24491 -optimize-df Analyze the dataflow of the generated code and improve it.
24492 \end_layout
24493
24494 \begin_layout Subsubsection
24495 Assembling Options
24496 \end_layout
24497
24498 \begin_layout Description
24499 -
24500 \begin_inset ERT
24501 status collapsed
24502
24503 \begin_layout Standard
24504
24505
24506 \backslash
24507 /
24508 \end_layout
24509
24510 \end_inset
24511
24512 -asm= Sets the full path and name of an external assembler to call.
24513 \end_layout
24514
24515 \begin_layout Description
24516 -
24517 \begin_inset ERT
24518 status collapsed
24519
24520 \begin_layout Standard
24521
24522
24523 \backslash
24524 /
24525 \end_layout
24526
24527 \end_inset
24528
24529 -mplab-comp MPLAB
24530 \begin_inset LatexCommand \index{PIC16!MPLAB}
24531
24532 \end_inset
24533
24534  compatibility option.
24535  Currently only suppresses special gpasm directives.
24536 \end_layout
24537
24538 \begin_layout Subsubsection
24539 Linking Options
24540 \end_layout
24541
24542 \begin_layout Description
24543 -
24544 \begin_inset ERT
24545 status collapsed
24546
24547 \begin_layout Standard
24548
24549
24550 \backslash
24551 /
24552 \end_layout
24553
24554 \end_inset
24555
24556 -link= Sets the full path and name of an external linker to call.
24557 \end_layout
24558
24559 \begin_layout Description
24560 -
24561 \begin_inset ERT
24562 status collapsed
24563
24564 \begin_layout Standard
24565
24566
24567 \backslash
24568 /
24569 \end_layout
24570
24571 \end_inset
24572
24573 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24574  unitialized data variables with [kword].
24575  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24576 \end_layout
24577
24578 \begin_layout Description
24579 -
24580 \begin_inset ERT
24581 status collapsed
24582
24583 \begin_layout Standard
24584
24585
24586 \backslash
24587 /
24588 \end_layout
24589
24590 \end_inset
24591
24592 -ivt-loc=n Place the interrupt vector table at address 
24593 \emph on
24594 n
24595 \emph default
24596 .
24597  Useful for bootloaders.
24598 \end_layout
24599
24600 \begin_layout Description
24601 -
24602 \begin_inset ERT
24603 status collapsed
24604
24605 \begin_layout Standard
24606
24607
24608 \backslash
24609 /
24610 \end_layout
24611
24612 \end_inset
24613
24614 -nodefaultlibs Do not link default libraries when linking.
24615 \end_layout
24616
24617 \begin_layout Description
24618 -
24619 \begin_inset ERT
24620 status collapsed
24621
24622 \begin_layout Standard
24623
24624
24625 \backslash
24626 /
24627 \end_layout
24628
24629 \end_inset
24630
24631 -use-crt= Use a custom run-time module instead of the defaults.
24632 \end_layout
24633
24634 \begin_layout Description
24635 -
24636 \begin_inset ERT
24637 status collapsed
24638
24639 \begin_layout Standard
24640
24641
24642 \backslash
24643 /
24644 \end_layout
24645
24646 \end_inset
24647
24648 -no-crt Don't link the default run-time modules
24649 \end_layout
24650
24651 \begin_layout Subsubsection
24652 Debugging Options
24653 \end_layout
24654
24655 \begin_layout Standard
24656 Debugging options enable extra debugging information in the output files.
24657 \end_layout
24658
24659 \begin_layout Description
24660 -
24661 \begin_inset ERT
24662 status collapsed
24663
24664 \begin_layout Standard
24665
24666
24667 \backslash
24668 /
24669 \end_layout
24670
24671 \end_inset
24672
24673 -debug-xtra Similar to -
24674 \begin_inset ERT
24675 status collapsed
24676
24677 \begin_layout Standard
24678
24679
24680 \backslash
24681 /
24682 \end_layout
24683
24684 \end_inset
24685
24686 -debug
24687 \begin_inset LatexCommand \index{-\/-debug}
24688
24689 \end_inset
24690
24691 , but dumps more information.
24692 \end_layout
24693
24694 \begin_layout Description
24695 -
24696 \begin_inset ERT
24697 status collapsed
24698
24699 \begin_layout Standard
24700
24701
24702 \backslash
24703 /
24704 \end_layout
24705
24706 \end_inset
24707
24708 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24709  information.
24710  <source> is the name of the file being compiled.
24711 \end_layout
24712
24713 \begin_layout Description
24714 -
24715 \begin_inset ERT
24716 status collapsed
24717
24718 \begin_layout Standard
24719
24720
24721 \backslash
24722 /
24723 \end_layout
24724
24725 \end_inset
24726
24727 -pcode-verbose Enable pcode debugging information in translation.
24728 \end_layout
24729
24730 \begin_layout Description
24731 -
24732 \begin_inset ERT
24733 status collapsed
24734
24735 \begin_layout Standard
24736
24737
24738 \backslash
24739 /
24740 \end_layout
24741
24742 \end_inset
24743
24744 -calltree Dump call tree in .calltree file.
24745 \end_layout
24746
24747 \begin_layout Description
24748 -
24749 \begin_inset ERT
24750 status collapsed
24751
24752 \begin_layout Standard
24753
24754
24755 \backslash
24756 /
24757 \end_layout
24758
24759 \end_inset
24760
24761 -gstack Trace push/pops for stack pointer overflow.
24762 \end_layout
24763
24764 \begin_layout Subsection
24765 Enviroment Variables
24766 \end_layout
24767
24768 \begin_layout Standard
24769 There is a number of enviromental variables that can be used when running
24770  SDCC to enable certain optimizations or force a specific program behaviour.
24771  these variables are primarily for debugging purposes so they can be enabled/dis
24772 abled at will.
24773 \end_layout
24774
24775 \begin_layout Standard
24776 Currently there is only two such variables available:
24777 \end_layout
24778
24779 \begin_layout Description
24780 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24781  bitfields is optimized by directly loading FSR0 with the address of the
24782  bitfield structure.
24783  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24784  then load FSR0.
24785  This step saves data ram and code space for functions that make heavy use
24786  of bitfields.
24787  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24788  option).
24789  
24790 \end_layout
24791
24792 \begin_layout Description
24793 NO_REG_OPT Do not perform pCode registers optimization.
24794  This should be used for debugging purposes.
24795  If bugs in the pcode optimizer are found, users can benefit from temporarily
24796  disabling the optimizer until the bug is fixed.
24797 \end_layout
24798
24799 \begin_layout Subsection
24800 Preprocessor Macros
24801 \end_layout
24802
24803 \begin_layout Standard
24804 PIC16
24805 \begin_inset LatexCommand \index{PIC16}
24806
24807 \end_inset
24808
24809  port defines the following preprocessor macros while translating a source.
24810 \end_layout
24811
24812 \begin_layout Standard
24813 \align center
24814 \begin_inset Tabular
24815 <lyxtabular version="3" rows="6" columns="2">
24816 <features>
24817 <column alignment="center" valignment="top" leftline="true" width="0">
24818 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24819 <row topline="true" bottomline="true">
24820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24821 \begin_inset Text
24822
24823 \begin_layout Standard
24824 Macro
24825 \end_layout
24826
24827 \end_inset
24828 </cell>
24829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24830 \begin_inset Text
24831
24832 \begin_layout Standard
24833 Description
24834 \end_layout
24835
24836 \end_inset
24837 </cell>
24838 </row>
24839 <row topline="true">
24840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24841 \begin_inset Text
24842
24843 \begin_layout Standard
24844 SDCC_pic16
24845 \end_layout
24846
24847 \end_inset
24848 </cell>
24849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24850 \begin_inset Text
24851
24852 \begin_layout Standard
24853 Port identification
24854 \end_layout
24855
24856 \end_inset
24857 </cell>
24858 </row>
24859 <row topline="true">
24860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24861 \begin_inset Text
24862
24863 \begin_layout Standard
24864 _
24865 \begin_inset ERT
24866 status collapsed
24867
24868 \begin_layout Standard
24869
24870
24871 \backslash
24872 /
24873 \end_layout
24874
24875 \end_inset
24876
24877 _pic16
24878 \end_layout
24879
24880 \end_inset
24881 </cell>
24882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24883 \begin_inset Text
24884
24885 \begin_layout Standard
24886 Port identification (same as above)
24887 \end_layout
24888
24889 \end_inset
24890 </cell>
24891 </row>
24892 <row topline="true">
24893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24894 \begin_inset Text
24895
24896 \begin_layout Standard
24897 pic18fxxxx
24898 \end_layout
24899
24900 \end_inset
24901 </cell>
24902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24903 \begin_inset Text
24904
24905 \begin_layout Standard
24906 MCU Identification.
24907  
24908 \emph on
24909 xxxx
24910 \emph default
24911  is the microcontrol identification number, i.e.
24912  452, 6620, etc
24913 \end_layout
24914
24915 \end_inset
24916 </cell>
24917 </row>
24918 <row topline="true">
24919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24920 \begin_inset Text
24921
24922 \begin_layout Standard
24923 _
24924 \begin_inset ERT
24925 status collapsed
24926
24927 \begin_layout Standard
24928
24929
24930 \backslash
24931 /
24932 \end_layout
24933
24934 \end_inset
24935
24936 _18Fxxxx
24937 \end_layout
24938
24939 \end_inset
24940 </cell>
24941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24942 \begin_inset Text
24943
24944 \begin_layout Standard
24945 MCU Identification (same as above)
24946 \end_layout
24947
24948 \end_inset
24949 </cell>
24950 </row>
24951 <row topline="true" bottomline="true">
24952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24953 \begin_inset Text
24954
24955 \begin_layout Standard
24956 STACK_MODEL_nnn
24957 \end_layout
24958
24959 \end_inset
24960 </cell>
24961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24962 \begin_inset Text
24963
24964 \begin_layout Standard
24965 nnn = SMALL or LARGE respectively according to the stack model used
24966 \end_layout
24967
24968 \end_inset
24969 </cell>
24970 </row>
24971 </lyxtabular>
24972
24973 \end_inset
24974
24975
24976 \end_layout
24977
24978 \begin_layout Standard
24979 In addition the following macros are defined when calling assembler:
24980 \end_layout
24981
24982 \begin_layout Standard
24983 \align center
24984 \begin_inset Tabular
24985 <lyxtabular version="3" rows="4" columns="2">
24986 <features>
24987 <column alignment="center" valignment="top" leftline="true" width="0">
24988 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24989 <row topline="true" bottomline="true">
24990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24991 \begin_inset Text
24992
24993 \begin_layout Standard
24994 Macro
24995 \end_layout
24996
24997 \end_inset
24998 </cell>
24999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25000 \begin_inset Text
25001
25002 \begin_layout Standard
25003 Description
25004 \end_layout
25005
25006 \end_inset
25007 </cell>
25008 </row>
25009 <row topline="true">
25010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25011 \begin_inset Text
25012
25013 \begin_layout Standard
25014 __18Fxxxx
25015 \end_layout
25016
25017 \end_inset
25018 </cell>
25019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25020 \begin_inset Text
25021
25022 \begin_layout Standard
25023 MCU Identification.
25024  
25025 \emph on
25026 xxxx
25027 \emph default
25028  is the microcontrol identification number, i.e.
25029  452, 6620, etc
25030 \end_layout
25031
25032 \end_inset
25033 </cell>
25034 </row>
25035 <row topline="true">
25036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25037 \begin_inset Text
25038
25039 \begin_layout Standard
25040 SDCC_MODEL_nnn
25041 \end_layout
25042
25043 \end_inset
25044 </cell>
25045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25046 \begin_inset Text
25047
25048 \begin_layout Standard
25049 nnn = SMALL or LARGE respectively according to the memory model used for
25050  SDCC
25051 \end_layout
25052
25053 \end_inset
25054 </cell>
25055 </row>
25056 <row topline="true" bottomline="true">
25057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25058 \begin_inset Text
25059
25060 \begin_layout Standard
25061 STACK_MODEL_nnn
25062 \end_layout
25063
25064 \end_inset
25065 </cell>
25066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25067 \begin_inset Text
25068
25069 \begin_layout Standard
25070 nnn = SMALL or LARGE respectively according to the stack model used
25071 \end_layout
25072
25073 \end_inset
25074 </cell>
25075 </row>
25076 </lyxtabular>
25077
25078 \end_inset
25079
25080
25081 \end_layout
25082
25083 \begin_layout Subsection
25084 Directories
25085 \end_layout
25086
25087 \begin_layout Standard
25088 PIC16
25089 \begin_inset LatexCommand \index{PIC16}
25090
25091 \end_inset
25092
25093  port uses the following directories for searching header files and libraries.
25094 \end_layout
25095
25096 \begin_layout Standard
25097 \align center
25098 \begin_inset Tabular
25099 <lyxtabular version="3" rows="3" columns="4">
25100 <features>
25101 <column alignment="center" valignment="top" leftline="true" width="0">
25102 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25103 <column alignment="center" valignment="top" width="0">
25104 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25105 <row topline="true" bottomline="true">
25106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25107 \begin_inset Text
25108
25109 \begin_layout Standard
25110 Directory
25111 \end_layout
25112
25113 \end_inset
25114 </cell>
25115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25116 \begin_inset Text
25117
25118 \begin_layout Standard
25119 Description
25120 \end_layout
25121
25122 \end_inset
25123 </cell>
25124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25125 \begin_inset Text
25126
25127 \begin_layout Standard
25128 Target
25129 \end_layout
25130
25131 \end_inset
25132 </cell>
25133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25134 \begin_inset Text
25135
25136 \begin_layout Standard
25137 Command prefix
25138 \end_layout
25139
25140 \end_inset
25141 </cell>
25142 </row>
25143 <row topline="true">
25144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25145 \begin_inset Text
25146
25147 \begin_layout Standard
25148 PREFIX/sdcc/include/pic16
25149 \end_layout
25150
25151 \end_inset
25152 </cell>
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25154 \begin_inset Text
25155
25156 \begin_layout Standard
25157 PIC16 specific headers
25158 \end_layout
25159
25160 \end_inset
25161 </cell>
25162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25163 \begin_inset Text
25164
25165 \begin_layout Standard
25166 Compiler
25167 \end_layout
25168
25169 \end_inset
25170 </cell>
25171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25172 \begin_inset Text
25173
25174 \begin_layout Standard
25175 -I
25176 \end_layout
25177
25178 \end_inset
25179 </cell>
25180 </row>
25181 <row topline="true" bottomline="true">
25182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25183 \begin_inset Text
25184
25185 \begin_layout Standard
25186 PREFIX/sdcc/lib/pic16
25187 \end_layout
25188
25189 \end_inset
25190 </cell>
25191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25192 \begin_inset Text
25193
25194 \begin_layout Standard
25195 PIC16 specific libraries
25196 \end_layout
25197
25198 \end_inset
25199 </cell>
25200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25201 \begin_inset Text
25202
25203 \begin_layout Standard
25204 Linker
25205 \end_layout
25206
25207 \end_inset
25208 </cell>
25209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25210 \begin_inset Text
25211
25212 \begin_layout Standard
25213 -L
25214 \end_layout
25215
25216 \end_inset
25217 </cell>
25218 </row>
25219 </lyxtabular>
25220
25221 \end_inset
25222
25223
25224 \end_layout
25225
25226 \begin_layout Subsection
25227 Pragmas
25228 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25229
25230 \end_inset
25231
25232
25233 \end_layout
25234
25235 \begin_layout Standard
25236 The PIC16
25237 \begin_inset LatexCommand \index{PIC16}
25238
25239 \end_inset
25240
25241  port currently supports the following pragmas:
25242 \end_layout
25243
25244 \begin_layout Description
25245 stack
25246 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25247
25248 \end_inset
25249
25250  This forces the code generator to initialize the stack & frame pointers
25251  at a specific address.
25252  This is an ad hoc solution for cases where no STACK directive is available
25253  in the linker script or gplink is not instructed to create a stack section.
25254 \newline
25255 The
25256  stack pragma should be used only once in a project.
25257  Multiple pragmas may result in indeterminate behaviour of the program.
25258 \begin_inset Foot
25259 status open
25260
25261 \begin_layout Standard
25262 The old format (ie.
25263  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25264  cross page boundaries (or even exceed the available data RAM) and crash
25265  the program.
25266  Make sure that stack does not cross page boundaries when using the SMALL
25267  stack model.
25268 \end_layout
25269
25270 \end_inset
25271
25272
25273 \newline
25274 The format is as follows:
25275 \newline
25276
25277 \end_layout
25278
25279 \begin_layout LyX-Code
25280 #pragma stack bottom_address [stack_size]
25281 \newline
25282
25283 \end_layout
25284
25285 \begin_layout Standard
25286
25287 \emph on
25288 bottom_address
25289 \emph default
25290  is the lower bound of the stack section.
25291  The stack pointer initially will point at address (bottom_address+stack_size-1).
25292 \end_layout
25293
25294 \begin_layout LyX-Code
25295 Example:
25296 \end_layout
25297
25298 \begin_layout LyX-Code
25299
25300 \end_layout
25301
25302 \begin_layout LyX-Code
25303 /* initializes stack of 100 bytes at RAM address 0x200 */
25304 \end_layout
25305
25306 \begin_layout LyX-Code
25307 #pragma stack 0x200 100
25308 \end_layout
25309
25310 \begin_layout Standard
25311 If the stack_size field is omitted then a stack is created with the default
25312  size of 64.
25313  This size might be enough for most programs, but its not enough for operations
25314  with deep function nesting or excessive stack usage.
25315 \end_layout
25316
25317 \begin_layout Description
25318 code
25319 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25320
25321 \end_inset
25322
25323  Force a function to a static FLASH address.
25324 \end_layout
25325
25326 \begin_layout LyX-Code
25327 Example:
25328 \end_layout
25329
25330 \begin_layout LyX-Code
25331
25332 \end_layout
25333
25334 \begin_layout LyX-Code
25335 /* place function test_func at 0x4000 */
25336 \end_layout
25337
25338 \begin_layout LyX-Code
25339 #pragma code test_func 0x4000
25340 \end_layout
25341
25342 \begin_layout LyX-Code
25343
25344 \end_layout
25345
25346 \begin_layout Description
25347 library instructs the linker to use a library module.
25348 \newline
25349 Usage:
25350 \end_layout
25351
25352 \begin_layout LyX-Code
25353 #pragma library module_name
25354 \end_layout
25355
25356 \begin_layout Standard
25357
25358 \emph on
25359 module_name
25360 \emph default
25361  can be any library or object file (including its path).
25362  Note that there are four reserved keywords which have special meaning.
25363  These are:
25364 \end_layout
25365
25366 \begin_layout Standard
25367 \align center
25368 \begin_inset Tabular
25369 <lyxtabular version="3" rows="6" columns="3">
25370 <features>
25371 <column alignment="center" valignment="top" leftline="true" width="0">
25372 <column alignment="block" valignment="top" leftline="true" width="20page%">
25373 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25374 <row topline="true" bottomline="true">
25375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25376 \begin_inset Text
25377
25378 \begin_layout Standard
25379 Keyword
25380 \end_layout
25381
25382 \end_inset
25383 </cell>
25384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25385 \begin_inset Text
25386
25387 \begin_layout Standard
25388 Description
25389 \end_layout
25390
25391 \end_inset
25392 </cell>
25393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25394 \begin_inset Text
25395
25396 \begin_layout Standard
25397 Module to link
25398 \end_layout
25399
25400 \end_inset
25401 </cell>
25402 </row>
25403 <row topline="true">
25404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25405 \begin_inset Text
25406
25407 \begin_layout Standard
25408
25409 \series bold
25410 ignore
25411 \end_layout
25412
25413 \end_inset
25414 </cell>
25415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25416 \begin_inset Text
25417
25418 \begin_layout Standard
25419 ignore all library pragmas
25420 \end_layout
25421
25422 \end_inset
25423 </cell>
25424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25425 \begin_inset Text
25426
25427 \begin_layout Standard
25428
25429 \emph on
25430 (none)
25431 \end_layout
25432
25433 \end_inset
25434 </cell>
25435 </row>
25436 <row topline="true">
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25438 \begin_inset Text
25439
25440 \begin_layout Standard
25441
25442 \series bold
25443 c
25444 \end_layout
25445
25446 \end_inset
25447 </cell>
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25449 \begin_inset Text
25450
25451 \begin_layout Standard
25452 link the C library
25453 \end_layout
25454
25455 \end_inset
25456 </cell>
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25458 \begin_inset Text
25459
25460 \begin_layout Standard
25461
25462 \emph on
25463 libc18f
25464 \emph default
25465 .lib
25466 \end_layout
25467
25468 \end_inset
25469 </cell>
25470 </row>
25471 <row topline="true">
25472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25473 \begin_inset Text
25474
25475 \begin_layout Standard
25476
25477 \series bold
25478 math
25479 \end_layout
25480
25481 \end_inset
25482 </cell>
25483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25484 \begin_inset Text
25485
25486 \begin_layout Standard
25487 link the Math libarary
25488 \end_layout
25489
25490 \end_inset
25491 </cell>
25492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25493 \begin_inset Text
25494
25495 \begin_layout Standard
25496
25497 \emph on
25498 libm18f
25499 \emph default
25500 .lib
25501 \end_layout
25502
25503 \end_inset
25504 </cell>
25505 </row>
25506 <row topline="true">
25507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25508 \begin_inset Text
25509
25510 \begin_layout Standard
25511
25512 \series bold
25513 io
25514 \end_layout
25515
25516 \end_inset
25517 </cell>
25518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25519 \begin_inset Text
25520
25521 \begin_layout Standard
25522 link the I/O library
25523 \end_layout
25524
25525 \end_inset
25526 </cell>
25527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25528 \begin_inset Text
25529
25530 \begin_layout Standard
25531
25532 \emph on
25533 libio18f*
25534 \emph default
25535 .lib
25536 \end_layout
25537
25538 \end_inset
25539 </cell>
25540 </row>
25541 <row topline="true" bottomline="true">
25542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25543 \begin_inset Text
25544
25545 \begin_layout Standard
25546
25547 \series bold
25548 debug
25549 \end_layout
25550
25551 \end_inset
25552 </cell>
25553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25554 \begin_inset Text
25555
25556 \begin_layout Standard
25557 link the debug library
25558 \end_layout
25559
25560 \end_inset
25561 </cell>
25562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25563 \begin_inset Text
25564
25565 \begin_layout Standard
25566
25567 \emph on
25568 libdebug
25569 \emph default
25570 .lib
25571 \end_layout
25572
25573 \end_inset
25574 </cell>
25575 </row>
25576 </lyxtabular>
25577
25578 \end_inset
25579
25580
25581 \newline
25582 * is the device number, i.e.
25583  452 for PIC18F452 MCU.
25584 \end_layout
25585
25586 \begin_layout Standard
25587 This feature allows for linking with specific libraries withoug having to
25588  explicit name them in the command line.
25589  Note that the 
25590 \noun on
25591 ignore
25592 \noun default
25593  keyword will reject all modules specified by the library pragma.
25594 \end_layout
25595
25596 \begin_layout Description
25597 udata The pragma udata instructs the compiler to emit code so that linker
25598  will place a variable at a specific memory bank.
25599 \end_layout
25600
25601 \begin_layout LyX-Code
25602 Example:
25603 \end_layout
25604
25605 \begin_layout LyX-Code
25606
25607 \end_layout
25608
25609 \begin_layout LyX-Code
25610 /* places variable foo at bank2 */
25611 \end_layout
25612
25613 \begin_layout LyX-Code
25614 #pragma udata bank2 foo
25615 \end_layout
25616
25617 \begin_layout LyX-Code
25618 char foo;
25619 \end_layout
25620
25621 \begin_layout Standard
25622 In order for this pragma to work extra SECTION directives should be added
25623  in the .lkr script.
25624  In the following example a sample .lkr file is shown:
25625 \end_layout
25626
25627 \begin_layout LyX-Code
25628
25629 \end_layout
25630
25631 \begin_layout LyX-Code
25632 // Sample linker script for the PIC18F452 processor
25633 \end_layout
25634
25635 \begin_layout LyX-Code
25636 LIBPATH .
25637 \end_layout
25638
25639 \begin_layout LyX-Code
25640 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25641 \end_layout
25642
25643 \begin_layout LyX-Code
25644 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25645 \end_layout
25646
25647 \begin_layout LyX-Code
25648 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25649 \end_layout
25650
25651 \begin_layout LyX-Code
25652 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25653 \end_layout
25654
25655 \begin_layout LyX-Code
25656 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25657 \end_layout
25658
25659 \begin_layout LyX-Code
25660 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25661 \end_layout
25662
25663 \begin_layout LyX-Code
25664 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25665 \end_layout
25666
25667 \begin_layout LyX-Code
25668
25669 \end_layout
25670
25671 \begin_layout LyX-Code
25672 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25673 \end_layout
25674
25675 \begin_layout LyX-Code
25676 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25677 \end_layout
25678
25679 \begin_layout LyX-Code
25680 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25681 \end_layout
25682
25683 \begin_layout LyX-Code
25684 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25685 \end_layout
25686
25687 \begin_layout LyX-Code
25688 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25689 \end_layout
25690
25691 \begin_layout LyX-Code
25692 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25693 \end_layout
25694
25695 \begin_layout LyX-Code
25696 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25697 \end_layout
25698
25699 \begin_layout LyX-Code
25700
25701 \end_layout
25702
25703 \begin_layout LyX-Code
25704 SECTION    NAME=CONFIG     ROM=config
25705 \end_layout
25706
25707 \begin_layout LyX-Code
25708
25709 \end_layout
25710
25711 \begin_layout LyX-Code
25712 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25713 \end_layout
25714
25715 \begin_layout LyX-Code
25716 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25717 \end_layout
25718
25719 \begin_layout LyX-Code
25720 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25721 \end_layout
25722
25723 \begin_layout LyX-Code
25724 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25725 \end_layout
25726
25727 \begin_layout LyX-Code
25728 SECTION    NAME=bank4      RAM=gpr4
25729 \end_layout
25730
25731 \begin_layout LyX-Code
25732 SECTION    NAME=bank5      RAM=gpr5
25733 \end_layout
25734
25735 \begin_layout Standard
25736 The linker will recognise the section name set in the pragma statement and
25737  will position the variable at the memory bank set with the RAM field at
25738  the SECTION line in the linker script file.
25739 \end_layout
25740
25741 \begin_layout Subsection
25742 Header Files
25743 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25744
25745 \end_inset
25746
25747
25748 \end_layout
25749
25750 \begin_layout Standard
25751 There is one main header file
25752 \begin_inset LatexCommand \index{PIC16!Header files}
25753
25754 \end_inset
25755
25756  that can be included to the source files using the pic16
25757 \begin_inset LatexCommand \index{PIC16}
25758
25759 \end_inset
25760
25761  port.
25762  That file is the 
25763 \series bold
25764 pic18fregs.h
25765 \series default
25766 .
25767  This header file contains the definitions for the processor special registers,
25768  so it is necessary if the source accesses them.
25769  It can be included by adding the following line in the beginning of the
25770  file:
25771 \end_layout
25772
25773 \begin_layout LyX-Code
25774 #include <pic18fregs.h>
25775 \end_layout
25776
25777 \begin_layout Standard
25778 The specific microcontroller is selected within the pic18fregs.h automatically,
25779  so the same source can be used with a variety of devices.
25780 \end_layout
25781
25782 \begin_layout Subsection
25783 Libraries
25784 \end_layout
25785
25786 \begin_layout Standard
25787 The libraries
25788 \begin_inset LatexCommand \index{PIC16!Libraries}
25789
25790 \end_inset
25791
25792  that PIC16
25793 \begin_inset LatexCommand \index{PIC16}
25794
25795 \end_inset
25796
25797  port depends on are the microcontroller device libraries which contain
25798  the symbol definitions for the microcontroller special function registers.
25799  These libraries have the format pic18fxxxx.lib, where 
25800 \emph on
25801 xxxx
25802 \emph default
25803  is the microcontroller identification number.
25804  The specific library is selected automatically by the compiler at link
25805  stage according to the selected device.
25806 \end_layout
25807
25808 \begin_layout Standard
25809 Libraries are created with gplib which is part of the gputils package 
25810 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25811
25812 \end_inset
25813
25814 .
25815 \end_layout
25816
25817 \begin_layout Subsubsection*
25818 Building the libraries
25819 \end_layout
25820
25821 \begin_layout Standard
25822 Before using SDCC/pic16 there are some libraries that need to be compiled.
25823  This process is not done automatically by SDCC since not all users use
25824  SDCC for pic16 projects.
25825  So each user should compile the libraries separately.
25826 \end_layout
25827
25828 \begin_layout Standard
25829 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25830 \end_layout
25831
25832 \begin_layout LyX-Code
25833 cd device/lib/pic16
25834 \end_layout
25835
25836 \begin_layout LyX-Code
25837 ./configure
25838 \end_layout
25839
25840 \begin_layout LyX-Code
25841 make
25842 \end_layout
25843
25844 \begin_layout LyX-Code
25845 cd ..
25846 \end_layout
25847
25848 \begin_layout LyX-Code
25849 make model-pic16
25850 \end_layout
25851
25852 \begin_layout LyX-Code
25853 su -c 'make install'     # install the libraries, you need the root password
25854 \end_layout
25855
25856 \begin_layout Standard
25857 If you need to install the headers too, do:
25858 \end_layout
25859
25860 \begin_layout LyX-Code
25861 cd device/include
25862 \end_layout
25863
25864 \begin_layout LyX-Code
25865 su -c 'make install'     # install the headers, you need the root password
25866 \end_layout
25867
25868 \begin_layout Standard
25869 There exist a special target to build the I/O libraries.
25870  This target is not automatically build because it will build the I/O library
25871  for 
25872 \emph on
25873 every
25874 \emph default
25875  supported device.
25876  This way building will take quite a lot of time.
25877  Users are advised to edit the 
25878 \series bold
25879 device/lib/pic16/pics.build
25880 \series default
25881  file and then execute:
25882 \end_layout
25883
25884 \begin_layout LyX-Code
25885 make lib-io
25886 \end_layout
25887
25888 \begin_layout Subsection
25889 Adding New Devices to the Port
25890 \end_layout
25891
25892 \begin_layout Standard
25893 Adding support for a new 16
25894 \begin_inset ERT
25895 status open
25896
25897 \begin_layout Standard
25898
25899
25900 \backslash
25901 ,
25902 \end_layout
25903
25904 \end_inset
25905
25906 bit PIC MCU requires the following steps:
25907 \end_layout
25908
25909 \begin_layout Enumerate
25910 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25911 \newline
25912
25913 \family typewriter
25914 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25915 inc
25916 \end_layout
25917
25918 \begin_layout Enumerate
25919
25920 \family typewriter
25921 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25922 \end_layout
25923
25924 \begin_layout Enumerate
25925
25926 \family typewriter
25927 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25928 \end_layout
25929
25930 \begin_layout Enumerate
25931 Add DEVICE to 
25932 \family typewriter
25933 /path/to/sdcc/device/lib/pic16/pics.all
25934 \family default
25935  (and 
25936 \family typewriter
25937 .build
25938 \family default
25939 ).
25940 \newline
25941 Note: No 18f prefix here!
25942 \end_layout
25943
25944 \begin_layout Enumerate
25945 Adjust 
25946 \family typewriter
25947 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25948 \family default
25949
25950 \newline
25951 Add your DEVICE if it does not compile in 
25952 \family typewriter
25953 adc
25954 \family default
25955
25956 \family typewriter
25957 i2c
25958 \family default
25959 , or 
25960 \family typewriter
25961 usart
25962 \family default
25963 .
25964 \end_layout
25965
25966 \begin_layout Enumerate
25967 Edit 
25968 \family typewriter
25969 /path/to/sdcc/device/include/pic16/pic18fregs.h
25970 \family default
25971 .
25972  The file format is self-explanatory, just add
25973 \newline
25974
25975 \family typewriter
25976 #elif defined(picDEVICE)
25977 \newline
25978 # include <picDEVICE.h>
25979 \family default
25980
25981 \newline
25982 at the right place (keep it sorted).
25983 \end_layout
25984
25985 \begin_layout Enumerate
25986 Edit 
25987 \family typewriter
25988 /path/to/sdcc/src/pic16/devices.inc
25989 \family default
25990 .
25991  Copy and modify an existing entry and insert it at the correct place (keep
25992  the file sorted).
25993  The file is hardly documented, look at the entries for the 18f2221...
25994 \end_layout
25995
25996 \begin_layout Enumerate
25997 Recompile SDCC, including the pic16 libraries.
25998 \end_layout
25999
26000 \begin_layout Subsection
26001 Memory Models
26002 \end_layout
26003
26004 \begin_layout Standard
26005 The following memory models are supported by the PIC16 port:
26006 \end_layout
26007
26008 \begin_layout Itemize
26009 small model
26010 \end_layout
26011
26012 \begin_layout Itemize
26013 large model
26014 \end_layout
26015
26016 \begin_layout Standard
26017 Memory model affects the default size of pointers within the source.
26018  The sizes are shown in the next table:
26019 \end_layout
26020
26021 \begin_layout Standard
26022 \align center
26023 \begin_inset Tabular
26024 <lyxtabular version="3" rows="3" columns="3">
26025 <features>
26026 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26027 <column alignment="center" valignment="top" leftline="true" width="0">
26028 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26029 <row topline="true" bottomline="true">
26030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26031 \begin_inset Text
26032
26033 \begin_layout Standard
26034 Pointer sizes according to memory model
26035 \end_layout
26036
26037 \end_inset
26038 </cell>
26039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26040 \begin_inset Text
26041
26042 \begin_layout Standard
26043 small model
26044 \end_layout
26045
26046 \end_inset
26047 </cell>
26048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26049 \begin_inset Text
26050
26051 \begin_layout Standard
26052 large model
26053 \end_layout
26054
26055 \end_inset
26056 </cell>
26057 </row>
26058 <row topline="true" bottomline="true">
26059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26060 \begin_inset Text
26061
26062 \begin_layout Standard
26063 code pointers
26064 \end_layout
26065
26066 \end_inset
26067 </cell>
26068 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26069 \begin_inset Text
26070
26071 \begin_layout Standard
26072 16-bits
26073 \end_layout
26074
26075 \end_inset
26076 </cell>
26077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26078 \begin_inset Text
26079
26080 \begin_layout Standard
26081 24-bits
26082 \end_layout
26083
26084 \end_inset
26085 </cell>
26086 </row>
26087 <row topline="true" bottomline="true">
26088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26089 \begin_inset Text
26090
26091 \begin_layout Standard
26092 data pointers
26093 \end_layout
26094
26095 \end_inset
26096 </cell>
26097 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26098 \begin_inset Text
26099
26100 \begin_layout Standard
26101 16-bits
26102 \end_layout
26103
26104 \end_inset
26105 </cell>
26106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26107 \begin_inset Text
26108
26109 \begin_layout Standard
26110 16-bits
26111 \end_layout
26112
26113 \end_inset
26114 </cell>
26115 </row>
26116 </lyxtabular>
26117
26118 \end_inset
26119
26120
26121 \end_layout
26122
26123 \begin_layout Standard
26124 It is advisable that all sources within a project are compiled with the
26125  same memory model.
26126  If one wants to override the default memory model, this can be done by
26127  declaring a pointer as 
26128 \series bold
26129 far
26130 \series default
26131  or 
26132 \series bold
26133 near
26134 \series default
26135 .
26136  Far selects large memory model's pointers, while near selects small memory
26137  model's pointers.
26138 \end_layout
26139
26140 \begin_layout Standard
26141 The standard device libraries (see 
26142 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26143
26144 \end_inset
26145
26146 ) contain no reference to pointers, so they can be used with both memory
26147  models.
26148 \end_layout
26149
26150 \begin_layout Subsection
26151 Stack
26152 \end_layout
26153
26154 \begin_layout Standard
26155 The stack
26156 \begin_inset LatexCommand \index{PIC16!stack}
26157
26158 \end_inset
26159
26160  implementation for the PIC16 port uses two indirect registers, FSR1 and
26161  FSR2.
26162 \end_layout
26163
26164 \begin_layout Description
26165 FSR1 is assigned as stack pointer
26166 \end_layout
26167
26168 \begin_layout Description
26169 FSR2 is assigned as frame pointer
26170 \end_layout
26171
26172 \begin_layout Standard
26173 The following stack models are supported by the PIC16 port
26174 \end_layout
26175
26176 \begin_layout Itemize
26177
26178 \noun on
26179 small
26180 \noun default
26181  model
26182 \end_layout
26183
26184 \begin_layout Itemize
26185
26186 \noun on
26187 large
26188 \noun default
26189  model
26190 \end_layout
26191
26192 \begin_layout Standard
26193
26194 \noun on
26195 Small
26196 \noun default
26197  model means that only the FSRxL byte is used to access stack and frame,
26198  while 
26199 \emph on
26200 \noun on
26201 large
26202 \emph default
26203 \noun default
26204  uses both FSRxL and FSRxH registers.
26205  The following table shows the stack/frame pointers sizes according to stack
26206  model and the maximum space they can address:
26207 \end_layout
26208
26209 \begin_layout Standard
26210 \align center
26211 \begin_inset Tabular
26212 <lyxtabular version="3" rows="3" columns="3">
26213 <features>
26214 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26215 <column alignment="center" valignment="top" leftline="true" width="0">
26216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26217 <row topline="true" bottomline="true">
26218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26219 \begin_inset Text
26220
26221 \begin_layout Standard
26222 Stack & Frame pointer sizes according to stack model
26223 \end_layout
26224
26225 \end_inset
26226 </cell>
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26228 \begin_inset Text
26229
26230 \begin_layout Standard
26231 small
26232 \end_layout
26233
26234 \end_inset
26235 </cell>
26236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26237 \begin_inset Text
26238
26239 \begin_layout Standard
26240 large
26241 \end_layout
26242
26243 \end_inset
26244 </cell>
26245 </row>
26246 <row topline="true">
26247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26248 \begin_inset Text
26249
26250 \begin_layout Standard
26251 Stack pointer FSR1
26252 \end_layout
26253
26254 \end_inset
26255 </cell>
26256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26257 \begin_inset Text
26258
26259 \begin_layout Standard
26260 8-bits
26261 \end_layout
26262
26263 \end_inset
26264 </cell>
26265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26266 \begin_inset Text
26267
26268 \begin_layout Standard
26269 16-bits
26270 \end_layout
26271
26272 \end_inset
26273 </cell>
26274 </row>
26275 <row topline="true" bottomline="true">
26276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26277 \begin_inset Text
26278
26279 \begin_layout Standard
26280 Frame pointer FSR2
26281 \end_layout
26282
26283 \end_inset
26284 </cell>
26285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26286 \begin_inset Text
26287
26288 \begin_layout Standard
26289 8-bits
26290 \end_layout
26291
26292 \end_inset
26293 </cell>
26294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26295 \begin_inset Text
26296
26297 \begin_layout Standard
26298 16-bits
26299 \end_layout
26300
26301 \end_inset
26302 </cell>
26303 </row>
26304 </lyxtabular>
26305
26306 \end_inset
26307
26308
26309 \end_layout
26310
26311 \begin_layout Standard
26312
26313 \noun on
26314 Large 
26315 \noun default
26316 stack model is currently not working properly throughout the code generator.
26317  So its use is not advised.
26318  Also there are some other points that need special care:
26319 \newline
26320
26321 \end_layout
26322
26323 \begin_layout Enumerate
26324 Do not create stack sections with size more than one physical bank (that
26325  is 256 bytes)
26326 \end_layout
26327
26328 \begin_layout Enumerate
26329 Stack sections should no cross physical bank limits (i.e.
26330  #pragma stack 0x50 0x100)
26331 \end_layout
26332
26333 \begin_layout Standard
26334 These limitations are caused by the fact that only FSRxL is modified when
26335  using SMALL stack model, so no more than 256 bytes of stack can be used.
26336  This problem will disappear after LARGE model is fully implemented.
26337 \end_layout
26338
26339 \begin_layout Subsection
26340 Functions
26341 \end_layout
26342
26343 \begin_layout Standard
26344 In addition to the standard SDCC function keywords, PIC16
26345 \begin_inset LatexCommand \index{PIC16}
26346
26347 \end_inset
26348
26349  port makes available two more:
26350 \end_layout
26351
26352 \begin_layout Description
26353 wparam
26354 \begin_inset LatexCommand \index{PIC16!wparam}
26355
26356 \end_inset
26357
26358  Use the WREG to pass one byte of the first function argument.
26359  This improves speed but you may not use this for functions with arguments
26360  that are called via function pointers, otherwise the first byte of the
26361  first parameter will get lost.
26362  Usage:
26363 \end_layout
26364
26365 \begin_layout LyX-Code
26366 void func_wparam(int a) wparam
26367 \end_layout
26368
26369 \begin_layout LyX-Code
26370 {
26371 \end_layout
26372
26373 \begin_layout LyX-Code
26374     /* WREG hold the lower part of a */
26375 \end_layout
26376
26377 \begin_layout LyX-Code
26378     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26379  */
26380 \end_layout
26381
26382 \begin_layout LyX-Code
26383 ...
26384 \end_layout
26385
26386 \begin_layout LyX-Code
26387 }
26388 \end_layout
26389
26390 \begin_layout Description
26391 shadowregs
26392 \begin_inset LatexCommand \index{PIC16!shadowregs}
26393
26394 \end_inset
26395
26396  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26397  hardware shadow registers which hold the values of WREG, STATUS and BSR
26398  registers.
26399  This can be done by adding the keyword 
26400 \emph on
26401 shadowregs
26402 \emph default
26403  before the 
26404 \emph on
26405 interrupt
26406 \emph default
26407  keyword in the function's header.
26408 \end_layout
26409
26410 \begin_layout LyX-Code
26411 void isr_shadow(void) shadowregs interrupt 1
26412 \end_layout
26413
26414 \begin_layout LyX-Code
26415 {
26416 \end_layout
26417
26418 \begin_layout LyX-Code
26419 ...
26420 \end_layout
26421
26422 \begin_layout LyX-Code
26423 }
26424 \end_layout
26425
26426 \begin_layout Standard
26427
26428 \emph on
26429 shadowregs
26430 \emph default
26431  instructs the code generator not to store/restore WREG, STATUS, BSR when
26432  entering/exiting the ISR.
26433 \end_layout
26434
26435 \begin_layout Subsection
26436 Function return values
26437 \end_layout
26438
26439 \begin_layout Standard
26440 Return values from functions are placed to the appropriate registers following
26441  a modified Microchip policy optimized for SDCC.
26442  The following table shows these registers:
26443 \end_layout
26444
26445 \begin_layout Standard
26446 \align center
26447 \begin_inset Tabular
26448 <lyxtabular version="3" rows="6" columns="2">
26449 <features>
26450 <column alignment="center" valignment="top" leftline="true" width="0">
26451 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26452 <row topline="true" bottomline="true">
26453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26454 \begin_inset Text
26455
26456 \begin_layout Standard
26457 size
26458 \end_layout
26459
26460 \end_inset
26461 </cell>
26462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26463 \begin_inset Text
26464
26465 \begin_layout Standard
26466 destination register
26467 \end_layout
26468
26469 \end_inset
26470 </cell>
26471 </row>
26472 <row topline="true">
26473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26474 \begin_inset Text
26475
26476 \begin_layout Standard
26477 8 bits
26478 \end_layout
26479
26480 \end_inset
26481 </cell>
26482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26483 \begin_inset Text
26484
26485 \begin_layout Standard
26486 WREG
26487 \end_layout
26488
26489 \end_inset
26490 </cell>
26491 </row>
26492 <row topline="true">
26493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26494 \begin_inset Text
26495
26496 \begin_layout Standard
26497 16 bits
26498 \end_layout
26499
26500 \end_inset
26501 </cell>
26502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26503 \begin_inset Text
26504
26505 \begin_layout Standard
26506 PRODL:WREG
26507 \end_layout
26508
26509 \end_inset
26510 </cell>
26511 </row>
26512 <row topline="true">
26513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26514 \begin_inset Text
26515
26516 \begin_layout Standard
26517 24 bits
26518 \end_layout
26519
26520 \end_inset
26521 </cell>
26522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26523 \begin_inset Text
26524
26525 \begin_layout Standard
26526 PRODH:PRODL:WREG
26527 \end_layout
26528
26529 \end_inset
26530 </cell>
26531 </row>
26532 <row topline="true">
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26534 \begin_inset Text
26535
26536 \begin_layout Standard
26537 32 bits
26538 \end_layout
26539
26540 \end_inset
26541 </cell>
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26543 \begin_inset Text
26544
26545 \begin_layout Standard
26546 FSR0L:PRODH:PRODL:WREG
26547 \end_layout
26548
26549 \end_inset
26550 </cell>
26551 </row>
26552 <row topline="true" bottomline="true">
26553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26554 \begin_inset Text
26555
26556 \begin_layout Standard
26557 >32 bits
26558 \end_layout
26559
26560 \end_inset
26561 </cell>
26562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26563 \begin_inset Text
26564
26565 \begin_layout Standard
26566 on stack, FSR0 points to the beginning
26567 \end_layout
26568
26569 \end_inset
26570 </cell>
26571 </row>
26572 </lyxtabular>
26573
26574 \end_inset
26575
26576
26577 \end_layout
26578
26579 \begin_layout Subsection
26580 Interrupts
26581 \end_layout
26582
26583 \begin_layout Standard
26584 An interrupt
26585 \begin_inset LatexCommand \index{PIC16!interrupt}
26586
26587 \end_inset
26588
26589  service routine (ISR) is declared using the 
26590 \emph on
26591 interrupt
26592 \emph default
26593  keyword.
26594 \end_layout
26595
26596 \begin_layout LyX-Code
26597 void isr(void) interrupt 
26598 \emph on
26599 n
26600 \end_layout
26601
26602 \begin_layout LyX-Code
26603 {
26604 \end_layout
26605
26606 \begin_layout LyX-Code
26607 ...
26608 \end_layout
26609
26610 \begin_layout LyX-Code
26611 }
26612 \end_layout
26613
26614 \begin_layout Standard
26615
26616 \emph on
26617 n
26618 \emph default
26619  is the interrupt number, which for PIC18F devices can be:
26620 \end_layout
26621
26622 \begin_layout Standard
26623 \align center
26624 \begin_inset Tabular
26625 <lyxtabular version="3" rows="4" columns="3">
26626 <features>
26627 <column alignment="center" valignment="top" leftline="true" width="0">
26628 <column alignment="center" valignment="top" leftline="true" width="0">
26629 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26630 <row topline="true" bottomline="true">
26631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26632 \begin_inset Text
26633
26634 \begin_layout Standard
26635
26636 \emph on
26637 n
26638 \end_layout
26639
26640 \end_inset
26641 </cell>
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26643 \begin_inset Text
26644
26645 \begin_layout Standard
26646 Interrupt Vector
26647 \end_layout
26648
26649 \end_inset
26650 </cell>
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26652 \begin_inset Text
26653
26654 \begin_layout Standard
26655 Interrupt Vector Address
26656 \end_layout
26657
26658 \end_inset
26659 </cell>
26660 </row>
26661 <row topline="true">
26662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26663 \begin_inset Text
26664
26665 \begin_layout Standard
26666 0
26667 \end_layout
26668
26669 \end_inset
26670 </cell>
26671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26672 \begin_inset Text
26673
26674 \begin_layout Standard
26675 RESET vector
26676 \end_layout
26677
26678 \end_inset
26679 </cell>
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26681 \begin_inset Text
26682
26683 \begin_layout Standard
26684 0x000000
26685 \end_layout
26686
26687 \end_inset
26688 </cell>
26689 </row>
26690 <row topline="true">
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26692 \begin_inset Text
26693
26694 \begin_layout Standard
26695
26696 \family roman
26697 \series medium
26698 \shape up
26699 \size normal
26700 \emph off
26701 \bar no
26702 \noun off
26703 \color none
26704 1
26705 \end_layout
26706
26707 \end_inset
26708 </cell>
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26710 \begin_inset Text
26711
26712 \begin_layout Standard
26713
26714 \family roman
26715 \series medium
26716 \shape up
26717 \size normal
26718 \emph off
26719 \bar no
26720 \noun off
26721 \color none
26722 HIGH priority interrupts
26723 \end_layout
26724
26725 \end_inset
26726 </cell>
26727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26728 \begin_inset Text
26729
26730 \begin_layout Standard
26731 0x000008
26732 \end_layout
26733
26734 \end_inset
26735 </cell>
26736 </row>
26737 <row topline="true" bottomline="true">
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26739 \begin_inset Text
26740
26741 \begin_layout Standard
26742 2
26743 \end_layout
26744
26745 \end_inset
26746 </cell>
26747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26748 \begin_inset Text
26749
26750 \begin_layout Standard
26751 LOW priority interrupts
26752 \end_layout
26753
26754 \end_inset
26755 </cell>
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26757 \begin_inset Text
26758
26759 \begin_layout Standard
26760 0x000018
26761 \end_layout
26762
26763 \end_inset
26764 </cell>
26765 </row>
26766 </lyxtabular>
26767
26768 \end_inset
26769
26770
26771 \end_layout
26772
26773 \begin_layout Standard
26774 When generating assembly code for ISR the code generator places a 
26775 \noun on
26776 goto 
26777 \noun default
26778 instruction at the 
26779 \emph on
26780 Interrupt Vector Address
26781 \emph default
26782  which points at the genetated ISR.
26783  This single GOTO instruction is part of an automatically generated 
26784 \emph on
26785 interrupt entry point
26786 \emph default
26787  function.
26788  The actuall ISR code is placed as normally would in the code space.
26789  Upon interrupt request, the GOTO instruction is executed which jumps to
26790  the ISR code.
26791  When declaring interrupt functions as _naked this GOTO instruction is 
26792 \series bold
26793 not
26794 \series default
26795  generated.
26796  The whole interrupt functions is therefore placed at the Interrupt Vector
26797  Address of the specific interrupt.
26798  This is not a problem for the LOW priority interrupts, but it is a problem
26799  for the RESET and the HIGH priority interrupts because code may be written
26800  at the next interrupt's vector address and cause undeterminate program
26801  behaviour if that interrupt is raised.
26802 \begin_inset Foot
26803 status open
26804
26805 \begin_layout Standard
26806 This is not a problem when
26807 \end_layout
26808
26809 \begin_layout Enumerate
26810 this is a HIGH interrupt ISR and LOW interrupts are 
26811 \emph on
26812 disabled
26813 \emph default
26814  or not used.
26815 \end_layout
26816
26817 \begin_layout Enumerate
26818 when the ISR is small enough not to reach the next interrupt's vector address.
26819 \end_layout
26820
26821 \end_inset
26822
26823
26824 \end_layout
26825
26826 \begin_layout Standard
26827
26828 \emph on
26829 n
26830 \emph default
26831  may be omitted.
26832  This way a function is generated similar to an ISR, but it is not assigned
26833  to any interrupt.
26834 \end_layout
26835
26836 \begin_layout Standard
26837 When entering an interrupt, currently the PIC16
26838 \begin_inset LatexCommand \index{PIC16}
26839
26840 \end_inset
26841
26842  port automatically saves the following registers:
26843 \end_layout
26844
26845 \begin_layout Itemize
26846 WREG
26847 \end_layout
26848
26849 \begin_layout Itemize
26850 STATUS
26851 \end_layout
26852
26853 \begin_layout Itemize
26854 BSR
26855 \end_layout
26856
26857 \begin_layout Itemize
26858 PROD (PRODL and PRODH)
26859 \end_layout
26860
26861 \begin_layout Itemize
26862 FSR0 (FSR0L and FSR0H)
26863 \end_layout
26864
26865 \begin_layout Standard
26866 These registers are restored upon return from the interrupt routine.
26867 \begin_inset Foot
26868 status open
26869
26870 \begin_layout Standard
26871 NOTE that when the _naked attribute is specified for an interrupt routine,
26872  then NO registers are stored or restored.
26873 \end_layout
26874
26875 \end_inset
26876
26877
26878 \end_layout
26879
26880 \begin_layout Subsection
26881 Generic Pointers
26882 \end_layout
26883
26884 \begin_layout Standard
26885 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26886  There are 3 types of generic pointers currently implemented data, code
26887  and eeprom pointers.
26888  They are differentiated by the value of the 7th and 6th bits of the upper
26889  byte:
26890 \end_layout
26891
26892 \begin_layout Standard
26893 \align center
26894 \begin_inset Tabular
26895 <lyxtabular version="3" rows="5" columns="5">
26896 <features>
26897 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26898 <column alignment="center" valignment="top" width="0">
26899 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26900 <column alignment="center" valignment="top" width="0">
26901 <column alignment="left" valignment="top" rightline="true" width="0">
26902 <row topline="true" bottomline="true">
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26904 \begin_inset Text
26905
26906 \begin_layout Standard
26907 pointer type
26908 \end_layout
26909
26910 \end_inset
26911 </cell>
26912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26913 \begin_inset Text
26914
26915 \begin_layout Standard
26916 7th bit
26917 \end_layout
26918
26919 \end_inset
26920 </cell>
26921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26922 \begin_inset Text
26923
26924 \begin_layout Standard
26925 6th bit
26926 \end_layout
26927
26928 \end_inset
26929 </cell>
26930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26931 \begin_inset Text
26932
26933 \begin_layout Standard
26934 rest of the pointer
26935 \end_layout
26936
26937 \end_inset
26938 </cell>
26939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26940 \begin_inset Text
26941
26942 \begin_layout Standard
26943 description
26944 \end_layout
26945
26946 \end_inset
26947 </cell>
26948 </row>
26949 <row topline="true" bottomline="true">
26950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26951 \begin_inset Text
26952
26953 \begin_layout Standard
26954 data 
26955 \end_layout
26956
26957 \end_inset
26958 </cell>
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26960 \begin_inset Text
26961
26962 \begin_layout Standard
26963 1
26964 \end_layout
26965
26966 \end_inset
26967 </cell>
26968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26969 \begin_inset Text
26970
26971 \begin_layout Standard
26972 0
26973 \end_layout
26974
26975 \end_inset
26976 </cell>
26977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26978 \begin_inset Text
26979
26980 \begin_layout Standard
26981
26982 \family typewriter
26983 \shape slanted
26984 \emph on
26985 uuuuuu uuuuxxxx xxxxxxxx
26986 \end_layout
26987
26988 \end_inset
26989 </cell>
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26991 \begin_inset Text
26992
26993 \begin_layout Standard
26994 a 12-bit data pointer in data RAM memory
26995 \end_layout
26996
26997 \end_inset
26998 </cell>
26999 </row>
27000 <row bottomline="true">
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27002 \begin_inset Text
27003
27004 \begin_layout Standard
27005 code
27006 \end_layout
27007
27008 \end_inset
27009 </cell>
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27011 \begin_inset Text
27012
27013 \begin_layout Standard
27014 0
27015 \end_layout
27016
27017 \end_inset
27018 </cell>
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27020 \begin_inset Text
27021
27022 \begin_layout Standard
27023 0
27024 \end_layout
27025
27026 \end_inset
27027 </cell>
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27029 \begin_inset Text
27030
27031 \begin_layout Standard
27032
27033 \family typewriter
27034 \shape slanted
27035 \emph on
27036 uxxxxx xxxxxxxx xxxxxxxx
27037 \end_layout
27038
27039 \end_inset
27040 </cell>
27041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27042 \begin_inset Text
27043
27044 \begin_layout Standard
27045 a 21-bit code pointer in FLASH memory
27046 \end_layout
27047
27048 \end_inset
27049 </cell>
27050 </row>
27051 <row bottomline="true">
27052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27053 \begin_inset Text
27054
27055 \begin_layout Standard
27056 eeprom
27057 \end_layout
27058
27059 \end_inset
27060 </cell>
27061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27062 \begin_inset Text
27063
27064 \begin_layout Standard
27065 0
27066 \end_layout
27067
27068 \end_inset
27069 </cell>
27070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27071 \begin_inset Text
27072
27073 \begin_layout Standard
27074 1
27075 \end_layout
27076
27077 \end_inset
27078 </cell>
27079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27080 \begin_inset Text
27081
27082 \begin_layout Standard
27083
27084 \family typewriter
27085 \shape slanted
27086 \emph on
27087 uuuuuu uuuuuuxx xxxxxxxx
27088 \end_layout
27089
27090 \end_inset
27091 </cell>
27092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27093 \begin_inset Text
27094
27095 \begin_layout Standard
27096 a 10-bit eeprom pointer in EEPROM memory
27097 \end_layout
27098
27099 \end_inset
27100 </cell>
27101 </row>
27102 <row bottomline="true">
27103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27104 \begin_inset Text
27105
27106 \begin_layout Standard
27107 (unimplemented)
27108 \end_layout
27109
27110 \end_inset
27111 </cell>
27112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27113 \begin_inset Text
27114
27115 \begin_layout Standard
27116 1
27117 \end_layout
27118
27119 \end_inset
27120 </cell>
27121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27122 \begin_inset Text
27123
27124 \begin_layout Standard
27125 1
27126 \end_layout
27127
27128 \end_inset
27129 </cell>
27130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27131 \begin_inset Text
27132
27133 \begin_layout Standard
27134
27135 \family typewriter
27136 \shape slanted
27137 \emph on
27138 xxxxxx xxxxxxxx xxxxxxxx
27139 \end_layout
27140
27141 \end_inset
27142 </cell>
27143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27144 \begin_inset Text
27145
27146 \begin_layout Standard
27147 unimplemented pointer type
27148 \end_layout
27149
27150 \end_inset
27151 </cell>
27152 </row>
27153 </lyxtabular>
27154
27155 \end_inset
27156
27157
27158 \end_layout
27159
27160 \begin_layout Standard
27161 Generic pointer are read and written with a set of library functions which
27162  read/write 1, 2, 3, 4 bytes.
27163 \end_layout
27164
27165 \begin_layout Subsection
27166 PIC16 C Libraries
27167 \end_layout
27168
27169 \begin_layout Subsubsection
27170 Standard I/O Streams
27171 \end_layout
27172
27173 \begin_layout Standard
27174 In the 
27175 \emph on
27176 stdio.h
27177 \emph default
27178  the type FILE is defined as:
27179 \end_layout
27180
27181 \begin_layout LyX-Code
27182 typedef char * FILE;
27183 \end_layout
27184
27185 \begin_layout Standard
27186 This type is the stream type implemented I/O in the PIC18F devices.
27187  Also the standard input and output streams are declared in stdio.h:
27188 \end_layout
27189
27190 \begin_layout LyX-Code
27191 extern FILE * stdin;
27192 \end_layout
27193
27194 \begin_layout LyX-Code
27195 extern FILE * stdout;
27196 \end_layout
27197
27198 \begin_layout Standard
27199 The FILE type is actually a generic pointer which defines one more type
27200  of generic pointers, the 
27201 \emph on
27202 stream 
27203 \emph default
27204 pointer.
27205  This new type has the format:
27206 \end_layout
27207
27208 \begin_layout Standard
27209 \align center
27210 \begin_inset Tabular
27211 <lyxtabular version="3" rows="2" columns="7">
27212 <features>
27213 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27214 <column alignment="center" valignment="top" width="0">
27215 <column alignment="center" valignment="top" leftline="true" width="0">
27216 <column alignment="center" valignment="top" leftline="true" width="0">
27217 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27218 <column alignment="center" valignment="top" width="0">
27219 <column alignment="left" valignment="top" rightline="true" width="0">
27220 <row topline="true" bottomline="true">
27221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27222 \begin_inset Text
27223
27224 \begin_layout Standard
27225 pointer type
27226 \end_layout
27227
27228 \end_inset
27229 </cell>
27230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27231 \begin_inset Text
27232
27233 \begin_layout Standard
27234 <7:6>
27235 \end_layout
27236
27237 \end_inset
27238 </cell>
27239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27240 \begin_inset Text
27241
27242 \begin_layout Standard
27243 <5>
27244 \end_layout
27245
27246 \end_inset
27247 </cell>
27248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27249 \begin_inset Text
27250
27251 \begin_layout Standard
27252 <4>
27253 \end_layout
27254
27255 \end_inset
27256 </cell>
27257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27258 \begin_inset Text
27259
27260 \begin_layout Standard
27261 <3:0>
27262 \end_layout
27263
27264 \end_inset
27265 </cell>
27266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27267 \begin_inset Text
27268
27269 \begin_layout Standard
27270 rest of the pointer
27271 \end_layout
27272
27273 \end_inset
27274 </cell>
27275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27276 \begin_inset Text
27277
27278 \begin_layout Standard
27279 descrption
27280 \end_layout
27281
27282 \end_inset
27283 </cell>
27284 </row>
27285 <row topline="true" bottomline="true">
27286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27287 \begin_inset Text
27288
27289 \begin_layout Standard
27290 stream
27291 \end_layout
27292
27293 \end_inset
27294 </cell>
27295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27296 \begin_inset Text
27297
27298 \begin_layout Standard
27299 00
27300 \end_layout
27301
27302 \end_inset
27303 </cell>
27304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27305 \begin_inset Text
27306
27307 \begin_layout Standard
27308 1
27309 \end_layout
27310
27311 \end_inset
27312 </cell>
27313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27314 \begin_inset Text
27315
27316 \begin_layout Standard
27317 0
27318 \end_layout
27319
27320 \end_inset
27321 </cell>
27322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27323 \begin_inset Text
27324
27325 \begin_layout Standard
27326 nnnn
27327 \end_layout
27328
27329 \end_inset
27330 </cell>
27331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27332 \begin_inset Text
27333
27334 \begin_layout Standard
27335
27336 \family typewriter
27337 \shape slanted
27338 \emph on
27339 uuuuuuuu uuuuuuuu
27340 \end_layout
27341
27342 \end_inset
27343 </cell>
27344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27345 \begin_inset Text
27346
27347 \begin_layout Standard
27348 upper byte high nubble is 0x2n, the rest are zeroes
27349 \end_layout
27350
27351 \end_inset
27352 </cell>
27353 </row>
27354 </lyxtabular>
27355
27356 \end_inset
27357
27358
27359 \end_layout
27360
27361 \begin_layout Standard
27362 Currently implemented there are 3 types of streams defined:
27363 \end_layout
27364
27365 \begin_layout Standard
27366 \align center
27367 \begin_inset Tabular
27368 <lyxtabular version="3" rows="4" columns="4">
27369 <features>
27370 <column alignment="center" valignment="top" leftline="true" width="0">
27371 <column alignment="center" valignment="top" leftline="true" width="0">
27372 <column alignment="center" valignment="top" leftline="true" width="0">
27373 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27374 <row topline="true" bottomline="true">
27375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27376 \begin_inset Text
27377
27378 \begin_layout Standard
27379 stream type
27380 \end_layout
27381
27382 \end_inset
27383 </cell>
27384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27385 \begin_inset Text
27386
27387 \begin_layout Standard
27388 value
27389 \end_layout
27390
27391 \end_inset
27392 </cell>
27393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27394 \begin_inset Text
27395
27396 \begin_layout Standard
27397 module
27398 \end_layout
27399
27400 \end_inset
27401 </cell>
27402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27403 \begin_inset Text
27404
27405 \begin_layout Standard
27406 description
27407 \end_layout
27408
27409 \end_inset
27410 </cell>
27411 </row>
27412 <row topline="true">
27413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27414 \begin_inset Text
27415
27416 \begin_layout Standard
27417 STREAM_USART
27418 \end_layout
27419
27420 \end_inset
27421 </cell>
27422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27423 \begin_inset Text
27424
27425 \begin_layout Standard
27426
27427 \family typewriter
27428 0x200000UL
27429 \end_layout
27430
27431 \end_inset
27432 </cell>
27433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27434 \begin_inset Text
27435
27436 \begin_layout Standard
27437 USART
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 Writes/Reads characters via the USART peripheral
27447 \end_layout
27448
27449 \end_inset
27450 </cell>
27451 </row>
27452 <row topline="true">
27453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27454 \begin_inset Text
27455
27456 \begin_layout Standard
27457 STREAM_MSSP
27458 \end_layout
27459
27460 \end_inset
27461 </cell>
27462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27463 \begin_inset Text
27464
27465 \begin_layout Standard
27466
27467 \family typewriter
27468 0x210000UL
27469 \end_layout
27470
27471 \end_inset
27472 </cell>
27473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27474 \begin_inset Text
27475
27476 \begin_layout Standard
27477 MSSP
27478 \end_layout
27479
27480 \end_inset
27481 </cell>
27482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27483 \begin_inset Text
27484
27485 \begin_layout Standard
27486 Writes/Reads characters via the MSSP peripheral
27487 \end_layout
27488
27489 \end_inset
27490 </cell>
27491 </row>
27492 <row topline="true" bottomline="true">
27493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27494 \begin_inset Text
27495
27496 \begin_layout Standard
27497 STREAM_USER
27498 \end_layout
27499
27500 \end_inset
27501 </cell>
27502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27503 \begin_inset Text
27504
27505 \begin_layout Standard
27506
27507 \family typewriter
27508 0x2f0000UL
27509 \end_layout
27510
27511 \end_inset
27512 </cell>
27513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27514 \begin_inset Text
27515
27516 \begin_layout Standard
27517 (none)
27518 \end_layout
27519
27520 \end_inset
27521 </cell>
27522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27523 \begin_inset Text
27524
27525 \begin_layout Standard
27526 Writes/Reads characters via used defined functions
27527 \end_layout
27528
27529 \end_inset
27530 </cell>
27531 </row>
27532 </lyxtabular>
27533
27534 \end_inset
27535
27536
27537 \end_layout
27538
27539 \begin_layout Standard
27540 The stream identifiers are declared as macros in the stdio.h header.
27541 \end_layout
27542
27543 \begin_layout Standard
27544 In the libc library there exist the functions that are used to write to
27545  each of the above streams.
27546  These are
27547 \end_layout
27548
27549 \begin_layout Description
27550 _
27551 \begin_inset ERT
27552 status collapsed
27553
27554 \begin_layout Standard
27555
27556
27557 \backslash
27558 /
27559 \end_layout
27560
27561 \end_inset
27562
27563 _stream_usart_putchar writes a character at the USART stream
27564 \end_layout
27565
27566 \begin_layout Description
27567 _
27568 \begin_inset ERT
27569 status collapsed
27570
27571 \begin_layout Standard
27572
27573
27574 \backslash
27575 /
27576 \end_layout
27577
27578 \end_inset
27579
27580 _stream_mssp_putchar writes a character at the MSSP stream
27581 \end_layout
27582
27583 \begin_layout Description
27584 putchar dummy function.
27585  This writes a character to a user specified manner.
27586 \end_layout
27587
27588 \begin_layout Standard
27589 In order to increase performance 
27590 \emph on
27591 putchar 
27592 \emph default
27593 is declared in stdio.h as having its parameter in WREG (it has the wparam
27594  keyword).
27595  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27596  in a user-friendly way.
27597  
27598 \emph on
27599 arg
27600 \emph default
27601  is the name of the variable that holds the character to print.
27602  An example follows:
27603 \end_layout
27604
27605 \begin_layout LyX-Code
27606 #include <pic18fregs.h>
27607 \newline
27608 #include <stdio.h>
27609 \newline
27610
27611 \newline
27612 PUTCHAR( c )
27613 \end_layout
27614
27615 \begin_layout LyX-Code
27616 {
27617 \end_layout
27618
27619 \begin_layout LyX-Code
27620     PORTA = c;    /* dump character c to PORTA */
27621 \end_layout
27622
27623 \begin_layout LyX-Code
27624
27625 \newline
27626
27627 \newline
27628 void main(void)
27629 \end_layout
27630
27631 \begin_layout LyX-Code
27632 {
27633 \end_layout
27634
27635 \begin_layout LyX-Code
27636     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27637 \end_layout
27638
27639 \begin_layout LyX-Code
27640                               * by default to STREAM_USER */
27641 \end_layout
27642
27643 \begin_layout LyX-Code
27644     printf (
27645 \begin_inset Quotes sld
27646 \end_inset
27647
27648 This is a printf test
27649 \backslash
27650 n
27651 \begin_inset Quotes srd
27652 \end_inset
27653
27654 );
27655 \end_layout
27656
27657 \begin_layout LyX-Code
27658 }
27659 \end_layout
27660
27661 \begin_layout LyX-Code
27662
27663 \end_layout
27664
27665 \begin_layout Subsubsection
27666 Printing functions
27667 \end_layout
27668
27669 \begin_layout Standard
27670 PIC16 contains an implementation of the printf-family of functions.
27671  There exist the following functions:
27672 \end_layout
27673
27674 \begin_layout LyX-Code
27675 extern unsigned int sprintf(char *buf, char *fmt, ...);
27676 \end_layout
27677
27678 \begin_layout LyX-Code
27679 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27680 \end_layout
27681
27682 \begin_layout LyX-Code
27683
27684 \end_layout
27685
27686 \begin_layout LyX-Code
27687 extern unsigned int printf(char *fmt, ...);
27688 \end_layout
27689
27690 \begin_layout LyX-Code
27691 extern unsigned int vprintf(char *fmt, va_lista ap);
27692 \end_layout
27693
27694 \begin_layout LyX-Code
27695
27696 \end_layout
27697
27698 \begin_layout LyX-Code
27699 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27700 \end_layout
27701
27702 \begin_layout LyX-Code
27703 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27704 \end_layout
27705
27706 \begin_layout Standard
27707 For sprintf and vsprintf 
27708 \emph on
27709 buf 
27710 \emph default
27711 should normally be a data pointer where the resulting string will be placed.
27712  No range checking is done so the user should allocate the necessery buffer.
27713  For fprintf and vfprintf 
27714 \emph on
27715 fp
27716 \emph default
27717  should be a stream pointer (i.e.
27718  stdout, STREAM_MSSP, etc...).
27719 \end_layout
27720
27721 \begin_layout Subsubsection
27722 Signals
27723 \end_layout
27724
27725 \begin_layout Standard
27726 The PIC18F family of microcontrollers supports a number of interrupt sources.
27727  A list of these interrupts is shown in the following table:
27728 \end_layout
27729
27730 \begin_layout Standard
27731 \align center
27732 \begin_inset Tabular
27733 <lyxtabular version="3" rows="11" columns="4">
27734 <features>
27735 <column alignment="left" valignment="top" leftline="true" width="0">
27736 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27737 <column alignment="left" valignment="top" leftline="true" width="0">
27738 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27739 <row topline="true" bottomline="true">
27740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27741 \begin_inset Text
27742
27743 \begin_layout Standard
27744 signal name
27745 \end_layout
27746
27747 \end_inset
27748 </cell>
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27750 \begin_inset Text
27751
27752 \begin_layout Standard
27753 description
27754 \end_layout
27755
27756 \end_inset
27757 </cell>
27758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27759 \begin_inset Text
27760
27761 \begin_layout Standard
27762 signal name
27763 \end_layout
27764
27765 \end_inset
27766 </cell>
27767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27768 \begin_inset Text
27769
27770 \begin_layout Standard
27771 descritpion
27772 \end_layout
27773
27774 \end_inset
27775 </cell>
27776 </row>
27777 <row topline="true">
27778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27779 \begin_inset Text
27780
27781 \begin_layout Standard
27782 SIG_RB
27783 \end_layout
27784
27785 \end_inset
27786 </cell>
27787 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27788 \begin_inset Text
27789
27790 \begin_layout Standard
27791 PORTB change interrupt
27792 \end_layout
27793
27794 \end_inset
27795 </cell>
27796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27797 \begin_inset Text
27798
27799 \begin_layout Standard
27800 SIG_EE
27801 \end_layout
27802
27803 \end_inset
27804 </cell>
27805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27806 \begin_inset Text
27807
27808 \begin_layout Standard
27809 EEPROM/FLASH write complete interrupt
27810 \end_layout
27811
27812 \end_inset
27813 </cell>
27814 </row>
27815 <row topline="true">
27816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27817 \begin_inset Text
27818
27819 \begin_layout Standard
27820 SIG_INT0
27821 \end_layout
27822
27823 \end_inset
27824 </cell>
27825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27826 \begin_inset Text
27827
27828 \begin_layout Standard
27829 INT0 external interrupt
27830 \end_layout
27831
27832 \end_inset
27833 </cell>
27834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27835 \begin_inset Text
27836
27837 \begin_layout Standard
27838 SIG_BCOL
27839 \end_layout
27840
27841 \end_inset
27842 </cell>
27843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27844 \begin_inset Text
27845
27846 \begin_layout Standard
27847 Bus collision interrupt
27848 \end_layout
27849
27850 \end_inset
27851 </cell>
27852 </row>
27853 <row topline="true">
27854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27855 \begin_inset Text
27856
27857 \begin_layout Standard
27858 SIG_INT1
27859 \end_layout
27860
27861 \end_inset
27862 </cell>
27863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27864 \begin_inset Text
27865
27866 \begin_layout Standard
27867 INT1 external interrupt
27868 \end_layout
27869
27870 \end_inset
27871 </cell>
27872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27873 \begin_inset Text
27874
27875 \begin_layout Standard
27876 SIG_LVD
27877 \end_layout
27878
27879 \end_inset
27880 </cell>
27881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27882 \begin_inset Text
27883
27884 \begin_layout Standard
27885 Low voltage detect interrupt
27886 \end_layout
27887
27888 \end_inset
27889 </cell>
27890 </row>
27891 <row topline="true">
27892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27893 \begin_inset Text
27894
27895 \begin_layout Standard
27896 SIG_INT2
27897 \end_layout
27898
27899 \end_inset
27900 </cell>
27901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27902 \begin_inset Text
27903
27904 \begin_layout Standard
27905 INT2 external interrupt
27906 \end_layout
27907
27908 \end_inset
27909 </cell>
27910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27911 \begin_inset Text
27912
27913 \begin_layout Standard
27914 SIG_PSP
27915 \end_layout
27916
27917 \end_inset
27918 </cell>
27919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27920 \begin_inset Text
27921
27922 \begin_layout Standard
27923 Parallel slave port interrupt
27924 \end_layout
27925
27926 \end_inset
27927 </cell>
27928 </row>
27929 <row topline="true">
27930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27931 \begin_inset Text
27932
27933 \begin_layout Standard
27934 SIG_CCP1
27935 \end_layout
27936
27937 \end_inset
27938 </cell>
27939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27940 \begin_inset Text
27941
27942 \begin_layout Standard
27943 CCP1 module interrupt
27944 \end_layout
27945
27946 \end_inset
27947 </cell>
27948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27949 \begin_inset Text
27950
27951 \begin_layout Standard
27952 SIG_AD
27953 \end_layout
27954
27955 \end_inset
27956 </cell>
27957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27958 \begin_inset Text
27959
27960 \begin_layout Standard
27961 AD convertion complete interrupt
27962 \end_layout
27963
27964 \end_inset
27965 </cell>
27966 </row>
27967 <row topline="true">
27968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27969 \begin_inset Text
27970
27971 \begin_layout Standard
27972 SIG_CCP2
27973 \end_layout
27974
27975 \end_inset
27976 </cell>
27977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27978 \begin_inset Text
27979
27980 \begin_layout Standard
27981 CCP2 module interrupt
27982 \end_layout
27983
27984 \end_inset
27985 </cell>
27986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27987 \begin_inset Text
27988
27989 \begin_layout Standard
27990 SIG_RC
27991 \end_layout
27992
27993 \end_inset
27994 </cell>
27995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27996 \begin_inset Text
27997
27998 \begin_layout Standard
27999 USART receive interrupt
28000 \end_layout
28001
28002 \end_inset
28003 </cell>
28004 </row>
28005 <row topline="true">
28006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28007 \begin_inset Text
28008
28009 \begin_layout Standard
28010 SIG_TMR0
28011 \end_layout
28012
28013 \end_inset
28014 </cell>
28015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28016 \begin_inset Text
28017
28018 \begin_layout Standard
28019 TMR0 overflow interrupt
28020 \end_layout
28021
28022 \end_inset
28023 </cell>
28024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28025 \begin_inset Text
28026
28027 \begin_layout Standard
28028 SIG_TX
28029 \end_layout
28030
28031 \end_inset
28032 </cell>
28033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28034 \begin_inset Text
28035
28036 \begin_layout Standard
28037 USART transmit interrupt
28038 \end_layout
28039
28040 \end_inset
28041 </cell>
28042 </row>
28043 <row topline="true">
28044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28045 \begin_inset Text
28046
28047 \begin_layout Standard
28048 SIG_TMR1
28049 \end_layout
28050
28051 \end_inset
28052 </cell>
28053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28054 \begin_inset Text
28055
28056 \begin_layout Standard
28057 TMR1 overflow interrupt
28058 \end_layout
28059
28060 \end_inset
28061 </cell>
28062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28063 \begin_inset Text
28064
28065 \begin_layout Standard
28066 SIG_MSSP
28067 \end_layout
28068
28069 \end_inset
28070 </cell>
28071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28072 \begin_inset Text
28073
28074 \begin_layout Standard
28075 SSP receive/transmit interrupt
28076 \end_layout
28077
28078 \end_inset
28079 </cell>
28080 </row>
28081 <row topline="true">
28082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28083 \begin_inset Text
28084
28085 \begin_layout Standard
28086 SIG_TMR2
28087 \end_layout
28088
28089 \end_inset
28090 </cell>
28091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28092 \begin_inset Text
28093
28094 \begin_layout Standard
28095 TMR2 matches PR2 interrupt
28096 \end_layout
28097
28098 \end_inset
28099 </cell>
28100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28101 \begin_inset Text
28102
28103 \begin_layout Standard
28104
28105 \end_layout
28106
28107 \end_inset
28108 </cell>
28109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28110 \begin_inset Text
28111
28112 \begin_layout Standard
28113
28114 \end_layout
28115
28116 \end_inset
28117 </cell>
28118 </row>
28119 <row topline="true" bottomline="true">
28120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28121 \begin_inset Text
28122
28123 \begin_layout Standard
28124 SIG_TMR3
28125 \end_layout
28126
28127 \end_inset
28128 </cell>
28129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28130 \begin_inset Text
28131
28132 \begin_layout Standard
28133 TMR3 overflow interrupt
28134 \end_layout
28135
28136 \end_inset
28137 </cell>
28138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28139 \begin_inset Text
28140
28141 \begin_layout Standard
28142
28143 \end_layout
28144
28145 \end_inset
28146 </cell>
28147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28148 \begin_inset Text
28149
28150 \begin_layout Standard
28151
28152 \end_layout
28153
28154 \end_inset
28155 </cell>
28156 </row>
28157 </lyxtabular>
28158
28159 \end_inset
28160
28161
28162 \end_layout
28163
28164 \begin_layout Standard
28165 The prototypes for these names are defined in the header file 
28166 \emph on
28167 signal.h
28168 \emph default
28169  .
28170 \end_layout
28171
28172 \begin_layout Standard
28173 In order to simplify signal handling, a number of macros is provided:
28174 \end_layout
28175
28176 \begin_layout List
28177 \labelwidthstring 00.00.0000
28178 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28179  high priority interrupts.
28180  
28181 \emph on
28182 name
28183 \emph default
28184  is the function name to use.
28185 \end_layout
28186
28187 \begin_layout List
28188 \labelwidthstring 00.00.0000
28189 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28190  low priority interrupt.
28191  
28192 \emph on
28193 name
28194 \emph default
28195  is the function name to use.
28196 \end_layout
28197
28198 \begin_layout List
28199 \labelwidthstring 00.00.0000
28200 DEF_HANDLER(sig,handler) define a handler for signal 
28201 \emph on
28202 sig.
28203 \end_layout
28204
28205 \begin_layout List
28206 \labelwidthstring 00.00.0000
28207 END_DEF end the declaration of the dispatch table.
28208 \end_layout
28209
28210 \begin_layout Standard
28211 Additionally there are two more macros to simplify the declaration of the
28212  signal handler:
28213 \end_layout
28214
28215 \begin_layout List
28216 \labelwidthstring 00.00.0000
28217
28218 \series medium
28219 SIGHANDLER(handler) 
28220 \series default
28221 this declares the function prototype for the 
28222 \emph on
28223 handler
28224 \emph default
28225  function.
28226 \end_layout
28227
28228 \begin_layout List
28229 \labelwidthstring 00.00.0000
28230 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28231 \end_layout
28232
28233 \begin_layout Standard
28234 An example of using the macros above is shown below:
28235 \end_layout
28236
28237 \begin_layout LyX-Code
28238 #include <pic18fregs.h>
28239 \end_layout
28240
28241 \begin_layout LyX-Code
28242 #include <signal.h>
28243 \newline
28244
28245 \newline
28246 DEF_INTHIGH(high_int)
28247 \end_layout
28248
28249 \begin_layout LyX-Code
28250 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28251 \end_layout
28252
28253 \begin_layout LyX-Code
28254 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28255 \end_layout
28256
28257 \begin_layout LyX-Code
28258 END_DEF
28259 \newline
28260
28261 \newline
28262 SIGHANDLER(_tmr0_handler)
28263 \end_layout
28264
28265 \begin_layout LyX-Code
28266 {
28267 \end_layout
28268
28269 \begin_layout LyX-Code
28270   /* action to be taken when timer 0 overflows */
28271 \end_layout
28272
28273 \begin_layout LyX-Code
28274 }
28275 \newline
28276
28277 \newline
28278 SIGHANDLERNAKED(_bcol_handler)
28279 \end_layout
28280
28281 \begin_layout LyX-Code
28282 {
28283 \end_layout
28284
28285 \begin_layout LyX-Code
28286   _asm
28287 \end_layout
28288
28289 \begin_layout LyX-Code
28290     /* action to be taken when bus collision occurs */
28291 \end_layout
28292
28293 \begin_layout LyX-Code
28294     retfie
28295 \end_layout
28296
28297 \begin_layout LyX-Code
28298  _endasm;
28299 \end_layout
28300
28301 \begin_layout LyX-Code
28302 }
28303 \end_layout
28304
28305 \begin_layout Standard
28306
28307 \series bold
28308 NOTES:
28309 \series default
28310  Special care should be taken when using the above scheme:
28311 \end_layout
28312
28313 \begin_layout Itemize
28314 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28315 \end_layout
28316
28317 \begin_layout Itemize
28318 when declaring SIGHANDLERNAKED handler never forget to use 
28319 \emph on
28320 retfie
28321 \emph default
28322  for proper returning.
28323 \end_layout
28324
28325 \begin_layout Subsection
28326 PIC16 Port -- Tips
28327 \end_layout
28328
28329 \begin_layout Standard
28330 Here you can find some general tips for compiling programs with SDCC/pic16.
28331 \end_layout
28332
28333 \begin_layout Subsubsection
28334 Stack size
28335 \end_layout
28336
28337 \begin_layout Standard
28338 The default stack
28339 \begin_inset LatexCommand \index{PIC16!stack}
28340
28341 \end_inset
28342
28343  size (that is 64 bytes) probably is enough for many programs.
28344  One must take care that when there are many levels of function nesting,
28345  or there is excessive usage of stack, its size should be extended.
28346  An example of such a case is the printf/sprintf family of functions.
28347  If you encounter problems like not being able to print integers, then you
28348  need to set the stack size around the maximum (256 for small stack model).
28349  The following diagram shows what happens when calling printf to print an
28350  integer:
28351 \end_layout
28352
28353 \begin_layout LyX-Code
28354 printf () --> ltoa () --> ultoa () --> divschar ()
28355 \end_layout
28356
28357 \begin_layout Standard
28358 It is should be understood that stack is easily consumed when calling complicate
28359 d functions.
28360  Using command line arguments like -
28361 \begin_inset ERT
28362 status collapsed
28363
28364 \begin_layout Standard
28365
28366
28367 \backslash
28368 /
28369 \end_layout
28370
28371 \end_inset
28372
28373 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28374  stack frames.
28375  Other ways to reduce stack usage may exist.
28376 \end_layout
28377
28378 \begin_layout Subsection
28379 Known Bugs
28380 \end_layout
28381
28382 \begin_layout Standard
28383 The PIC16 Port currently does not pass SDCC's regression test
28384 \begin_inset LatexCommand \index{Regression test (PIC16)}
28385
28386 \end_inset
28387
28388  suite (see section 
28389 \begin_inset LatexCommand \ref{sec:Quality-control}
28390
28391 \end_inset
28392
28393 ) and thus the snapshot build regression tests for the PIC16 target are
28394  currently disabled for all hosts
28395 \emph on
28396 .
28397 \end_layout
28398
28399 \begin_layout Chapter
28400 Debugging
28401 \end_layout
28402
28403 \begin_layout Standard
28404 There are several approaches to debugging your code.
28405  This chapter is meant to show your options and to give detail on some of
28406  them:
28407 \newline
28408
28409 \newline
28410 When writing your code:
28411 \end_layout
28412
28413 \begin_layout Itemize
28414 write your code with debugging in mind (avoid duplicating code, put conceptually
28415  similar variables into structs, use structured code, have strategic points
28416  within your code where all variables are consistent, ...)
28417 \end_layout
28418
28419 \begin_layout Itemize
28420 run a syntax-checking tool like splint
28421 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28422
28423 \end_inset
28424
28425
28426 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28427
28428 \end_inset
28429
28430  (see -
28431 \begin_inset ERT
28432 status collapsed
28433
28434 \begin_layout Standard
28435
28436
28437 \backslash
28438 /
28439 \end_layout
28440
28441 \end_inset
28442
28443 -more-pedantic 
28444 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28445
28446 \end_inset
28447
28448 ) over the code.
28449 \end_layout
28450
28451 \begin_layout Itemize
28452 for the high level code use a C-compiler (like f.e.
28453  GCC) to compile run and debug the code on your host.
28454  See (see -
28455 \begin_inset ERT
28456 status collapsed
28457
28458 \begin_layout Standard
28459
28460
28461 \backslash
28462 /
28463 \end_layout
28464
28465 \end_inset
28466
28467 -more-pedantic 
28468 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28469
28470 \end_inset
28471
28472 ) on how to handle syntax extensions like __xdata, __at(), ...
28473  
28474 \end_layout
28475
28476 \begin_layout Itemize
28477 use another C-compiler to compile code for your target.
28478  Always an option but not recommended:) And not very likely to help you.
28479  If you seriously consider walking this path you should at least occasionally
28480  check portability of your code.
28481  Most commercial compiler vendors will offer an evaluation version so you
28482  can test compile your code or snippets of your code.
28483 \end_layout
28484
28485 \begin_layout Standard
28486 Debugging on a simulator:
28487 \end_layout
28488
28489 \begin_layout Itemize
28490 there is a separate section about SDCDB (section 
28491 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28492
28493 \end_inset
28494
28495 ) below.
28496 \end_layout
28497
28498 \begin_layout Itemize
28499 or (8051 specific) use a freeware/commercial simulator which interfaces
28500  to the AOMF
28501 \begin_inset LatexCommand \index{AOMF, AOMF51}
28502
28503 \end_inset
28504
28505  file (see 
28506 \begin_inset LatexCommand \ref{OMF file}
28507
28508 \end_inset
28509
28510 ) optionally generated by SDCC.
28511 \end_layout
28512
28513 \begin_layout Standard
28514 Debugging On-target: 
28515 \end_layout
28516
28517 \begin_layout Itemize
28518 use a MCU port pin to serially output debug data to the RS232 port of your
28519  host.
28520  You'll probably want some level shifting device typically involving a MAX232
28521  or similar IC.
28522  If the hardware serial port of the MCU is not available search for 'Software
28523  UART' in your favourite search machine.
28524 \end_layout
28525
28526 \begin_layout Itemize
28527 use an on-target monitor.
28528  In this context a monitor is a small program which usually accepts commands
28529  via a serial line and allows to set program counter, to single step through
28530  a program and read/write memory locations.
28531  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28532  
28533 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28534
28535 \end_inset
28536
28537 ).
28538 \end_layout
28539
28540 \begin_layout Itemize
28541 toggle MCU port pins at strategic points within your code and use an oscilloscop
28542 e.
28543  A 
28544 \emph on
28545 digital oscilloscope
28546 \emph default
28547
28548 \begin_inset LatexCommand \index{Oscilloscope}
28549
28550 \end_inset
28551
28552  with deep trace memory is really helpful especially if you have to debug
28553  a realtime application.
28554  If you need to monitor more pins than your oscilloscope provides you can
28555  sometimes get away with a small R-2R network.
28556  On a single channel oscilloscope you could f.e.
28557  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28558 k
28559 \begin_inset Formula $\Omega$
28560 \end_inset
28561
28562  resistor and the other one by a 5\InsetSpace ~
28563 k
28564 \begin_inset Formula $\Omega$
28565 \end_inset
28566
28567  resistor to the oscilloscope probe (check output drive capability of the
28568  pins you want to monitor).
28569  If you need to monitor many more pins a 
28570 \emph on
28571 logic analyzer
28572 \emph default
28573  will be handy.
28574 \end_layout
28575
28576 \begin_layout Itemize
28577 use an ICE (
28578 \emph on
28579 i
28580 \emph default
28581
28582 \emph on
28583 c
28584 \emph default
28585 ircuit 
28586 \emph on
28587 e
28588 \emph default
28589 mulator
28590 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28591
28592 \end_inset
28593
28594 ).
28595  Usually very expensive.
28596  And very nice to have too.
28597  And usually locks you (for years...) to the devices the ICE can emulate.
28598  
28599 \end_layout
28600
28601 \begin_layout Itemize
28602 use a remote debugger.
28603  In most 8-bit systems the symbol information is not available on the target,
28604  and a complete debugger is too bulky for the target system.
28605  Therefore usually a debugger on the host system connects to an on-target
28606  debugging stub which accepts only primitive commands.
28607  
28608 \newline
28609 Terms to enter into your favourite search engine could be 'remote debugging',
28610  'gdb stub' or 'inferior debugger'.
28611  (is there one?)
28612 \end_layout
28613
28614 \begin_layout Itemize
28615 use an on target hardware debugger.
28616  Some of the more modern MCUs include hardware support for setting break
28617  points and monitoring/changing variables by using dedicated hardware pins.
28618  This facility doesn't require additional code to run on the target and
28619  
28620 \emph on
28621 usually
28622 \emph default
28623  doesn't affect runtime behaviour until a breakpoint is hit.
28624  For the mcs51 most hardware debuggers use the AOMF
28625 \begin_inset LatexCommand \index{AOMF, AOMF51}
28626
28627 \end_inset
28628
28629  file (see 
28630 \begin_inset LatexCommand \ref{OMF file}
28631
28632 \end_inset
28633
28634 ) as input file.
28635  
28636 \end_layout
28637
28638 \begin_layout Standard
28639 Last not least:
28640 \end_layout
28641
28642 \begin_layout Itemize
28643 if you are not familiar with any of the following terms you're likely to
28644  run into problems rather sooner than later: 
28645 \emph on
28646 volatile
28647 \emph default
28648
28649 \emph on
28650 atomic
28651 \emph default
28652
28653 \emph on
28654 memory map
28655 \emph default
28656
28657 \emph on
28658 overlay
28659 \emph default
28660 .
28661  As an embedded programmer you 
28662 \emph on
28663 have
28664 \emph default
28665  to know them so why not look them up 
28666 \emph on
28667 before
28668 \emph default
28669  you have problems?)
28670 \end_layout
28671
28672 \begin_layout Itemize
28673 tell someone else about your problem (actually this is a surprisingly effective
28674  means to hunt down the bug even if the listener is not familiar with your
28675  environment).
28676  As 'failure to communicate' is probably one of the job-induced deformations
28677  of an embedded programmer this is highly encouraged.
28678 \end_layout
28679
28680 \begin_layout Section
28681 Debugging with SDCDB
28682 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28683
28684 \end_inset
28685
28686
28687 \begin_inset LatexCommand \index{SDCDB (debugger)}
28688
28689 \end_inset
28690
28691  
28692 \end_layout
28693
28694 \begin_layout Standard
28695 SDCC is distributed with a source level debugger
28696 \begin_inset LatexCommand \index{Debugger}
28697
28698 \end_inset
28699
28700 .
28701  The debugger uses a command line interface, the command repertoire of the
28702  debugger has been kept as close to gdb
28703 \begin_inset LatexCommand \index{gdb}
28704
28705 \end_inset
28706
28707  (the GNU debugger) as possible.
28708  The configuration and build process is part of the standard compiler installati
28709 on, which also builds and installs the debugger in the target directory
28710  specified during configuration.
28711  The debugger allows you debug BOTH at the C source and at the ASM source
28712  level.
28713 \end_layout
28714
28715 \begin_layout Subsection
28716 Compiling for Debugging
28717 \end_layout
28718
28719 \begin_layout Standard
28720 The -
28721 \begin_inset ERT
28722 status collapsed
28723
28724 \begin_layout Standard
28725
28726
28727 \backslash
28728 /
28729 \end_layout
28730
28731 \end_inset
28732
28733 -debug
28734 \begin_inset LatexCommand \index{-\/-debug}
28735
28736 \end_inset
28737
28738  option must be specified for all files for which debug information is to
28739  be generated.
28740  The compiler generates a .adb file for each of these files.
28741  The linker creates the .cdb
28742 \begin_inset LatexCommand \index{<file>.cdb}
28743
28744 \end_inset
28745
28746  file from the .adb
28747 \begin_inset LatexCommand \index{<file>.adb}
28748
28749 \end_inset
28750
28751  files and the address information.
28752  This .cdb is used by the debugger.
28753 \end_layout
28754
28755 \begin_layout Subsection
28756 How the Debugger Works
28757 \end_layout
28758
28759 \begin_layout Standard
28760 When the -
28761 \begin_inset ERT
28762 status collapsed
28763
28764 \begin_layout Standard
28765
28766
28767 \backslash
28768 /
28769 \end_layout
28770
28771 \end_inset
28772
28773 -debug option is specified the compiler generates extra symbol information
28774  some of which are put into the assembler source and some are put into the
28775  .adb file.
28776  Then the linker creates the .cdb file from the individual .adb files with
28777  the address information for the symbols.
28778  The debugger reads the symbolic information generated by the compiler &
28779  the address information generated by the linker.
28780  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28781  execution is controlled by the debugger.
28782  When a command is issued for the debugger, it translates it into appropriate
28783  commands for the simulator.
28784  (Currently SDCDM only connects to the simulator but 
28785 \emph on
28786 newcdb
28787 \emph default
28788  at 
28789 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28790
28791 \end_inset
28792
28793  is an effort to connect directly to the hardware.) 
28794 \end_layout
28795
28796 \begin_layout Subsection
28797 Starting the Debugger SDCDB
28798 \end_layout
28799
28800 \begin_layout Standard
28801 The debugger can be started using the following command line.
28802  (Assume the file you are debugging has the file name foo).
28803 \newline
28804
28805 \newline
28806
28807 \family sans
28808 \series bold
28809 sdcdb foo
28810 \newline
28811
28812 \family default
28813 \series default
28814
28815 \newline
28816 The debugger will look for the following files.
28817 \end_layout
28818
28819 \begin_layout Itemize
28820 foo.c - the source file.
28821 \end_layout
28822
28823 \begin_layout Itemize
28824 foo.cdb - the debugger symbol information file.
28825 \end_layout
28826
28827 \begin_layout Itemize
28828 foo.ihx - the Intel hex format
28829 \begin_inset LatexCommand \index{Intel hex format}
28830
28831 \end_inset
28832
28833  object file.
28834 \end_layout
28835
28836 \begin_layout Subsection
28837 SDCDB Command Line Options
28838 \end_layout
28839
28840 \begin_layout Itemize
28841 -
28842 \begin_inset ERT
28843 status collapsed
28844
28845 \begin_layout Standard
28846
28847
28848 \backslash
28849 /
28850 \end_layout
28851
28852 \end_inset
28853
28854 -directory=<source file directory> this option can used to specify the directory
28855  search list.
28856  The debugger will look into the directory list specified for source, cdb
28857  & ihx files.
28858  The items in the directory list must be separated by ':', e.g.
28859  if the source files can be in the directories /home/src1 and /home/src2,
28860  the -
28861 \begin_inset ERT
28862 status collapsed
28863
28864 \begin_layout Standard
28865
28866
28867 \backslash
28868 /
28869 \end_layout
28870
28871 \end_inset
28872
28873 -directory option should be -
28874 \begin_inset ERT
28875 status collapsed
28876
28877 \begin_layout Standard
28878
28879
28880 \backslash
28881 /
28882 \end_layout
28883
28884 \end_inset
28885
28886 -directory=/home/src1:/home/src2.
28887  Note there can be no spaces in the option.
28888  
28889 \end_layout
28890
28891 \begin_layout Itemize
28892 -cd <directory> - change to the <directory>.
28893 \end_layout
28894
28895 \begin_layout Itemize
28896 -fullname - used by GUI front ends.
28897 \end_layout
28898
28899 \begin_layout Itemize
28900 -cpu <cpu-type> - this argument is passed to the simulator please see the
28901  simulator docs for details.
28902 \end_layout
28903
28904 \begin_layout Itemize
28905 -X <Clock frequency > this options is passed to the simulator please see
28906  the simulator docs for details.
28907 \end_layout
28908
28909 \begin_layout Itemize
28910 -s <serial port file> passed to simulator see the simulator docs for details.
28911 \end_layout
28912
28913 \begin_layout Itemize
28914 -S <serial in,out> passed to simulator see the simulator docs for details.
28915 \end_layout
28916
28917 \begin_layout Itemize
28918 -k <port number> passed to simulator see the simulator docs for details.
28919 \end_layout
28920
28921 \begin_layout Subsection
28922 SDCDB Debugger Commands
28923 \end_layout
28924
28925 \begin_layout Standard
28926 As mentioned earlier the command interface for the debugger has been deliberatel
28927 y kept as close the GNU debugger gdb, as possible.
28928  This will help the integration with existing graphical user interfaces
28929  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28930  If you use a graphical user interface for the debugger you can skip this
28931  section.
28932 \end_layout
28933
28934 \begin_layout Subsubsection*
28935 break [line | file:line | function | file:function]
28936 \end_layout
28937
28938 \begin_layout Standard
28939 Set breakpoint at specified line or function:
28940 \newline
28941
28942 \newline
28943
28944 \family sans
28945 \series bold
28946 sdcdb>break 100 
28947 \newline
28948 sdcdb>break foo.c:100
28949 \newline
28950 sdcdb>break funcfoo
28951 \newline
28952 sdcdb>break foo.c:funcfoo
28953 \end_layout
28954
28955 \begin_layout Subsubsection*
28956 clear [line | file:line | function | file:function ]
28957 \end_layout
28958
28959 \begin_layout Standard
28960 Clear breakpoint at specified line or function:
28961 \newline
28962
28963 \newline
28964
28965 \family sans
28966 \series bold
28967 sdcdb>clear 100
28968 \newline
28969 sdcdb>clear foo.c:100
28970 \newline
28971 sdcdb>clear funcfoo
28972 \newline
28973 sdcdb>clear foo.c:funcfoo
28974 \end_layout
28975
28976 \begin_layout Subsubsection*
28977 continue
28978 \end_layout
28979
28980 \begin_layout Standard
28981 Continue program being debugged, after breakpoint.
28982 \end_layout
28983
28984 \begin_layout Subsubsection*
28985 finish
28986 \end_layout
28987
28988 \begin_layout Standard
28989 Execute till the end of the current function.
28990 \end_layout
28991
28992 \begin_layout Subsubsection*
28993 delete [n]
28994 \end_layout
28995
28996 \begin_layout Standard
28997 Delete breakpoint number 'n'.
28998  If used without any option clear ALL user defined break points.
28999 \end_layout
29000
29001 \begin_layout Subsubsection*
29002 info [break | stack | frame | registers ]
29003 \end_layout
29004
29005 \begin_layout Itemize
29006 info break - list all breakpoints
29007 \end_layout
29008
29009 \begin_layout Itemize
29010 info stack - show the function call stack.
29011 \end_layout
29012
29013 \begin_layout Itemize
29014 info frame - show information about the current execution frame.
29015 \end_layout
29016
29017 \begin_layout Itemize
29018 info registers - show content of all registers.
29019 \end_layout
29020
29021 \begin_layout Subsubsection*
29022 step
29023 \end_layout
29024
29025 \begin_layout Standard
29026 Step program until it reaches a different source line.
29027  Note: pressing <return> repeats the last command.
29028 \end_layout
29029
29030 \begin_layout Subsubsection*
29031 next
29032 \end_layout
29033
29034 \begin_layout Standard
29035 Step program, proceeding through subroutine calls.
29036 \end_layout
29037
29038 \begin_layout Subsubsection*
29039 run
29040 \end_layout
29041
29042 \begin_layout Standard
29043 Start debugged program.
29044 \end_layout
29045
29046 \begin_layout Subsubsection*
29047 ptype variable 
29048 \end_layout
29049
29050 \begin_layout Standard
29051 Print type information of the variable.
29052 \end_layout
29053
29054 \begin_layout Subsubsection*
29055 print variable
29056 \end_layout
29057
29058 \begin_layout Standard
29059 print value of variable.
29060 \end_layout
29061
29062 \begin_layout Subsubsection*
29063 file filename
29064 \end_layout
29065
29066 \begin_layout Standard
29067 load the given file name.
29068  Note this is an alternate method of loading file for debugging.
29069 \end_layout
29070
29071 \begin_layout Subsubsection*
29072 frame
29073 \end_layout
29074
29075 \begin_layout Standard
29076 print information about current frame.
29077 \end_layout
29078
29079 \begin_layout Subsubsection*
29080 set srcmode
29081 \end_layout
29082
29083 \begin_layout Standard
29084 Toggle between C source & assembly source.
29085 \end_layout
29086
29087 \begin_layout Subsubsection*
29088 ! simulator command
29089 \end_layout
29090
29091 \begin_layout Standard
29092 Send the string following '!' to the simulator, the simulator response is
29093  displayed.
29094  Note the debugger does not interpret the command being sent to the simulator,
29095  so if a command like 'go' is sent the debugger can loose its execution
29096  context and may display incorrect values.
29097 \end_layout
29098
29099 \begin_layout Subsubsection*
29100 quit
29101 \end_layout
29102
29103 \begin_layout Standard
29104 "Watch me now.
29105  Iam going Down.
29106  My name is Bobby Brown"
29107 \end_layout
29108
29109 \begin_layout Subsection
29110 Interfacing SDCDB with DDD
29111 \end_layout
29112
29113 \begin_layout Standard
29114 \begin_inset Note Note
29115 status collapsed
29116
29117 \begin_layout Standard
29118 The screenshot was converted from png to eps with: 
29119 \begin_inset Quotes sld
29120 \end_inset
29121
29122 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29123 \begin_inset Quotes srd
29124 \end_inset
29125
29126  which produces a pretty compact eps file which is free from compression
29127  artifacts.
29128 \end_layout
29129
29130 \begin_layout Standard
29131 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29132  as this broke the build system on Sourceforge (pdf-file was broken.
29133  pdflatex does not accept eps files).
29134 \end_layout
29135
29136 \end_inset
29137
29138
29139 \end_layout
29140
29141 \begin_layout Standard
29142 The 
29143 \emph on
29144 p
29145 \emph default
29146 ortable 
29147 \emph on
29148 n
29149 \emph default
29150 etwork 
29151 \emph on
29152 g
29153 \emph default
29154 raphics File 
29155 \size footnotesize
29156
29157 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29158
29159 \end_inset
29160
29161
29162 \size default
29163  shows a screenshot of a debugging session with DDD
29164 \begin_inset LatexCommand \index{DDD (debugger)}
29165
29166 \end_inset
29167
29168  (Unix only) on a simulated 8032.
29169  The debugging session might not run as smoothly as the screenshot suggests.
29170  The debugger allows setting of breakpoints, displaying and changing variables,
29171  single stepping through C and assembler code.
29172  
29173 \newline
29174 The source was compiled with 
29175 \family sans
29176 \series bold
29177
29178 \newline
29179
29180 \newline
29181 sdcc -
29182 \family default
29183 \series default
29184
29185 \begin_inset ERT
29186 status collapsed
29187
29188 \begin_layout Standard
29189
29190
29191 \backslash
29192 /
29193 \end_layout
29194
29195 \end_inset
29196
29197
29198 \family sans
29199 \series bold
29200 -debug ddd_example.c
29201 \family default
29202 \series default
29203  
29204 \family sans
29205 \series bold
29206
29207 \newline
29208
29209 \family default
29210 \series default
29211
29212 \newline
29213 and DDD was invoked with 
29214 \family sans
29215 \series bold
29216
29217 \newline
29218
29219 \newline
29220 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29221 \end_layout
29222
29223 \begin_layout Standard
29224 \begin_inset Note Note
29225 status open
29226
29227 \begin_layout Standard
29228 Check that the double quotes or an apostroph within the command line survive
29229  the LyX tool chain.
29230  Previously the apostrophs got slanted in the PDF output so a cut and paste
29231  did not work.
29232 \end_layout
29233
29234 \end_inset
29235
29236
29237 \end_layout
29238
29239 \begin_layout Subsection
29240 Interfacing SDCDB with XEmacs
29241 \begin_inset LatexCommand \index{XEmacs}
29242
29243 \end_inset
29244
29245
29246 \begin_inset LatexCommand \index{Emacs}
29247
29248 \end_inset
29249
29250
29251 \end_layout
29252
29253 \begin_layout Standard
29254 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29255  sdcdb.el and sdcdbsrc.el.
29256  These two files can be found in the $(prefix)/bin directory after the installat
29257 ion is complete.
29258  These files need to be loaded into XEmacs for the interface to work.
29259  This can be done at XEmacs startup time by inserting the following into
29260  your '.xemacs' file (which can be found in your HOME directory): 
29261 \newline
29262
29263 \newline
29264
29265 \family typewriter
29266 (load-file sdcdbsrc.el) 
29267 \family default
29268
29269 \newline
29270
29271 \newline
29272 .xemacs is a lisp file so the () around the command is REQUIRED.
29273  The files can also be loaded dynamically while XEmacs is running, set the
29274  environment variable 'EMACSLOADPATH' to the installation bin directory
29275  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29276  To start the interface enter the following command: 
29277 \newline
29278
29279 \newline
29280
29281 \family sans
29282 \series bold
29283 ESC-x sdcdbsrc
29284 \family default
29285 \series default
29286
29287 \newline
29288
29289 \newline
29290 You will prompted to enter the file name to be debugged.
29291  
29292 \newline
29293
29294 \newline
29295 The command line options that are passed to the simulator directly are
29296  bound to default values in the file sdcdbsrc.el.
29297  The variables are listed below, these values maybe changed as required.
29298 \end_layout
29299
29300 \begin_layout Itemize
29301 sdcdbsrc-cpu-type '51
29302 \end_layout
29303
29304 \begin_layout Itemize
29305 sdcdbsrc-frequency '11059200
29306 \end_layout
29307
29308 \begin_layout Itemize
29309 sdcdbsrc-serial nil
29310 \end_layout
29311
29312 \begin_layout Standard
29313 The following is a list of key mapping for the debugger interface.
29314 \end_layout
29315
29316 \begin_layout Standard
29317 \InsetSpace ~
29318
29319 \family typewriter
29320
29321 \newline
29322 ;;\InsetSpace ~
29323 Current Listing :: 
29324 \newline
29325 ;;key\InsetSpace ~
29326 \InsetSpace ~
29327 \InsetSpace ~
29328 \InsetSpace ~
29329 \InsetSpace ~
29330 \InsetSpace ~
29331 \InsetSpace ~
29332 \InsetSpace ~
29333 \InsetSpace ~
29334 \InsetSpace ~
29335 \InsetSpace ~
29336 \InsetSpace ~
29337 \InsetSpace ~
29338 \InsetSpace ~
29339 binding\InsetSpace ~
29340 \InsetSpace ~
29341 \InsetSpace ~
29342 \InsetSpace ~
29343 \InsetSpace ~
29344 \InsetSpace ~
29345 \InsetSpace ~
29346 \InsetSpace ~
29347 \InsetSpace ~
29348 \InsetSpace ~
29349 \InsetSpace ~
29350 \InsetSpace ~
29351 \InsetSpace ~
29352 \InsetSpace ~
29353 \InsetSpace ~
29354 \InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 \InsetSpace ~
29359 \InsetSpace ~
29360 \InsetSpace ~
29361 Comment 
29362 \newline
29363 ;;---\InsetSpace ~
29364 \InsetSpace ~
29365 \InsetSpace ~
29366 \InsetSpace ~
29367 \InsetSpace ~
29368 \InsetSpace ~
29369 \InsetSpace ~
29370 \InsetSpace ~
29371 \InsetSpace ~
29372 \InsetSpace ~
29373 \InsetSpace ~
29374 \InsetSpace ~
29375 \InsetSpace ~
29376 \InsetSpace ~
29377 -------\InsetSpace ~
29378 \InsetSpace ~
29379 \InsetSpace ~
29380 \InsetSpace ~
29381 \InsetSpace ~
29382 \InsetSpace ~
29383 \InsetSpace ~
29384 \InsetSpace ~
29385 \InsetSpace ~
29386 \InsetSpace ~
29387 \InsetSpace ~
29388 \InsetSpace ~
29389 \InsetSpace ~
29390 \InsetSpace ~
29391 \InsetSpace ~
29392 \InsetSpace ~
29393 \InsetSpace ~
29394 \InsetSpace ~
29395 \InsetSpace ~
29396 \InsetSpace ~
29397 \InsetSpace ~
29398 \InsetSpace ~
29399 -------
29400 \newline
29401 ;; 
29402 \newline
29403 ;;\InsetSpace ~
29404 n\InsetSpace ~
29405 \InsetSpace ~
29406 \InsetSpace ~
29407 \InsetSpace ~
29408 \InsetSpace ~
29409 \InsetSpace ~
29410 \InsetSpace ~
29411 \InsetSpace ~
29412 \InsetSpace ~
29413 \InsetSpace ~
29414 \InsetSpace ~
29415 \InsetSpace ~
29416 \InsetSpace ~
29417 \InsetSpace ~
29418 \InsetSpace ~
29419 sdcdb-next-fro
29420 m-src\InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423 \InsetSpace ~
29424 \InsetSpace ~
29425 \InsetSpace ~
29426 \InsetSpace ~
29427 \InsetSpace ~
29428 \InsetSpace ~
29429 \InsetSpace ~
29430 SDCDB next command 
29431 \newline
29432 ;;\InsetSpace ~
29433 b\InsetSpace ~
29434 \InsetSpace ~
29435 \InsetSpace ~
29436 \InsetSpace ~
29437 \InsetSpace ~
29438 \InsetSpace ~
29439 \InsetSpace ~
29440 \InsetSpace ~
29441 \InsetSpace ~
29442 \InsetSpace ~
29443 \InsetSpace ~
29444 \InsetSpace ~
29445 \InsetSpace ~
29446 \InsetSpace ~
29447 \InsetSpace ~
29448 sdcdb-back-from-src\InsetSpace ~
29449 \InsetSpace ~
29450 \InsetSpace ~
29451 \InsetSpace ~
29452 \InsetSpace ~
29453 \InsetSpace ~
29454 \InsetSpace ~
29455 \InsetSpace ~
29456 \InsetSpace ~
29457 \InsetSpace ~
29458 SDCDB back command 
29459 \newline
29460 ;;\InsetSpace ~
29461 c\InsetSpace ~
29462 \InsetSpace ~
29463 \InsetSpace ~
29464 \InsetSpace ~
29465 \InsetSpace ~
29466 \InsetSpace ~
29467 \InsetSpace ~
29468 \InsetSpace ~
29469 \InsetSpace ~
29470 \InsetSpace ~
29471 \InsetSpace ~
29472 \InsetSpace ~
29473 \InsetSpace ~
29474 \InsetSpace ~
29475 \InsetSpace ~
29476 sdcdb-cont-f
29477 rom-src\InsetSpace ~
29478 \InsetSpace ~
29479 \InsetSpace ~
29480 \InsetSpace ~
29481 \InsetSpace ~
29482 \InsetSpace ~
29483 \InsetSpace ~
29484 \InsetSpace ~
29485 \InsetSpace ~
29486 \InsetSpace ~
29487 SDCDB continue command
29488 \newline
29489 ;;\InsetSpace ~
29490 s\InsetSpace ~
29491 \InsetSpace ~
29492 \InsetSpace ~
29493 \InsetSpace ~
29494 \InsetSpace ~
29495 \InsetSpace ~
29496 \InsetSpace ~
29497 \InsetSpace ~
29498 \InsetSpace ~
29499 \InsetSpace ~
29500 \InsetSpace ~
29501 \InsetSpace ~
29502 \InsetSpace ~
29503 \InsetSpace ~
29504 \InsetSpace ~
29505 sdcdb-step-from-src\InsetSpace ~
29506 \InsetSpace ~
29507 \InsetSpace ~
29508 \InsetSpace ~
29509 \InsetSpace ~
29510 \InsetSpace ~
29511 \InsetSpace ~
29512 \InsetSpace ~
29513 \InsetSpace ~
29514 \InsetSpace ~
29515 SDCDB step command 
29516 \newline
29517 ;;\InsetSpace ~
29518 ?\InsetSpace ~
29519 \InsetSpace ~
29520 \InsetSpace ~
29521 \InsetSpace ~
29522 \InsetSpace ~
29523 \InsetSpace ~
29524 \InsetSpace ~
29525 \InsetSpace ~
29526 \InsetSpace ~
29527 \InsetSpace ~
29528 \InsetSpace ~
29529 \InsetSpace ~
29530 \InsetSpace ~
29531 \InsetSpace ~
29532 \InsetSpace ~
29533 sdcdb-w
29534 hatis-c-sexp\InsetSpace ~
29535 \InsetSpace ~
29536 \InsetSpace ~
29537 \InsetSpace ~
29538 \InsetSpace ~
29539 \InsetSpace ~
29540 \InsetSpace ~
29541 \InsetSpace ~
29542 \InsetSpace ~
29543 \InsetSpace ~
29544 SDCDB ptypecommand for data at 
29545 \newline
29546 ;;\InsetSpace ~
29547 \InsetSpace ~
29548 \InsetSpace ~
29549 \InsetSpace ~
29550 \InsetSpace ~
29551 \InsetSpace ~
29552 \InsetSpace ~
29553 \InsetSpace ~
29554 \InsetSpace ~
29555 \InsetSpace ~
29556 \InsetSpace ~
29557 \InsetSpace ~
29558 \InsetSpace ~
29559 \InsetSpace ~
29560 \InsetSpace ~
29561 \InsetSpace ~
29562 \InsetSpace ~
29563 \InsetSpace ~
29564 \InsetSpace ~
29565 \InsetSpace ~
29566 \InsetSpace ~
29567 \InsetSpace ~
29568 \InsetSpace ~
29569 \InsetSpace ~
29570 \InsetSpace ~
29571 \InsetSpace ~
29572 \InsetSpace ~
29573 \InsetSpace ~
29574 \InsetSpace ~
29575 \InsetSpace ~
29576 \InsetSpace ~
29577 \InsetSpace ~
29578 \InsetSpace ~
29579 \InsetSpace ~
29580 \InsetSpace ~
29581 \InsetSpace ~
29582 \InsetSpace ~
29583 \InsetSpace ~
29584 \InsetSpace ~
29585 \InsetSpace ~
29586 \InsetSpace ~
29587 \InsetSpace ~
29588 \InsetSpace ~
29589 \InsetSpace ~
29590 \InsetSpace ~
29591 \InsetSpace ~
29592 \InsetSpace ~
29593 buffer point 
29594 \newline
29595 ;;\InsetSpace ~
29596 x\InsetSpace ~
29597 \InsetSpace ~
29598 \InsetSpace ~
29599 \InsetSpace ~
29600 \InsetSpace ~
29601 \InsetSpace ~
29602 \InsetSpace ~
29603 \InsetSpace ~
29604 \InsetSpace ~
29605 \InsetSpace ~
29606 \InsetSpace ~
29607 \InsetSpace ~
29608 \InsetSpace ~
29609 \InsetSpace ~
29610 \InsetSpace ~
29611 sdcdbsrc-delete\InsetSpace ~
29612 \InsetSpace ~
29613 \InsetSpace ~
29614 \InsetSpace ~
29615 \InsetSpace ~
29616 \InsetSpace ~
29617 \InsetSpace ~
29618 \InsetSpace ~
29619 \InsetSpace ~
29620 \InsetSpace ~
29621 \InsetSpace ~
29622 \InsetSpace ~
29623 \InsetSpace ~
29624 \InsetSpace ~
29625 SDCD
29626 B Delete all breakpoints if no arg 
29627 \newline
29628 ;;\InsetSpace ~
29629 \InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 \InsetSpace ~
29633 \InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 \InsetSpace ~
29640 \InsetSpace ~
29641 \InsetSpace ~
29642 \InsetSpace ~
29643 \InsetSpace ~
29644 \InsetSpace ~
29645 \InsetSpace ~
29646 \InsetSpace ~
29647 \InsetSpace ~
29648 \InsetSpace ~
29649 \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 \InsetSpace ~
29656 \InsetSpace ~
29657 \InsetSpace ~
29658 \InsetSpace ~
29659 \InsetSpace ~
29660 \InsetSpace ~
29661 \InsetSpace ~
29662 \InsetSpace ~
29663 \InsetSpace ~
29664 \InsetSpace ~
29665 \InsetSpace ~
29666 \InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 \InsetSpace ~
29671 \InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 \InsetSpace ~
29675 given or delete arg (C-u arg x) 
29676 \newline
29677 ;;\InsetSpace ~
29678 m\InsetSpace ~
29679 \InsetSpace ~
29680 \InsetSpace ~
29681 \InsetSpace ~
29682 \InsetSpace ~
29683 \InsetSpace ~
29684 \InsetSpace ~
29685 \InsetSpace ~
29686 \InsetSpace ~
29687 \InsetSpace ~
29688 \InsetSpace ~
29689 \InsetSpace ~
29690 \InsetSpace ~
29691 \InsetSpace ~
29692 \InsetSpace ~
29693 sdcdbsrc
29694 -frame\InsetSpace ~
29695 \InsetSpace ~
29696 \InsetSpace ~
29697 \InsetSpace ~
29698 \InsetSpace ~
29699 \InsetSpace ~
29700 \InsetSpace ~
29701 \InsetSpace ~
29702 \InsetSpace ~
29703 \InsetSpace ~
29704 \InsetSpace ~
29705 \InsetSpace ~
29706 \InsetSpace ~
29707 \InsetSpace ~
29708 \InsetSpace ~
29709 SDCDB Display current frame if no arg, 
29710 \newline
29711 ;;\InsetSpace ~
29712 \InsetSpace ~
29713 \InsetSpace ~
29714 \InsetSpace ~
29715 \InsetSpace ~
29716 \InsetSpace ~
29717 \InsetSpace ~
29718 \InsetSpace ~
29719 \InsetSpace ~
29720 \InsetSpace ~
29721 \InsetSpace ~
29722 \InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 \InsetSpace ~
29731 \InsetSpace ~
29732 \InsetSpace ~
29733 \InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 \InsetSpace ~
29738 \InsetSpace ~
29739 \InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 \InsetSpace ~
29743 \InsetSpace ~
29744 \InsetSpace ~
29745 \InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 \InsetSpace ~
29749 \InsetSpace ~
29750 \InsetSpace ~
29751 \InsetSpace ~
29752 \InsetSpace ~
29753 \InsetSpace ~
29754 \InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \InsetSpace ~
29758 given or display frame arg
29759  
29760 \newline
29761 ;;\InsetSpace ~
29762 \InsetSpace ~
29763 \InsetSpace ~
29764 \InsetSpace ~
29765 \InsetSpace ~
29766 \InsetSpace ~
29767 \InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 \InsetSpace ~
29771 \InsetSpace ~
29772 \InsetSpace ~
29773 \InsetSpace ~
29774 \InsetSpace ~
29775 \InsetSpace ~
29776 \InsetSpace ~
29777 \InsetSpace ~
29778 \InsetSpace ~
29779 \InsetSpace ~
29780 \InsetSpace ~
29781 \InsetSpace ~
29782 \InsetSpace ~
29783 \InsetSpace ~
29784 \InsetSpace ~
29785 \InsetSpace ~
29786 \InsetSpace ~
29787 \InsetSpace ~
29788 \InsetSpace ~
29789 \InsetSpace ~
29790 \InsetSpace ~
29791 \InsetSpace ~
29792 \InsetSpace ~
29793 \InsetSpace ~
29794 \InsetSpace ~
29795 \InsetSpace ~
29796 \InsetSpace ~
29797 \InsetSpace ~
29798 \InsetSpace ~
29799 \InsetSpace ~
29800 \InsetSpace ~
29801 \InsetSpace ~
29802 \InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 \InsetSpace ~
29806 \InsetSpace ~
29807 \InsetSpace ~
29808 buffer point 
29809 \newline
29810 ;;\InsetSpace ~
29811 !\InsetSpace ~
29812 \InsetSpace ~
29813 \InsetSpace ~
29814 \InsetSpace ~
29815 \InsetSpace ~
29816 \InsetSpace ~
29817 \InsetSpace ~
29818 \InsetSpace ~
29819 \InsetSpace ~
29820 \InsetSpace ~
29821 \InsetSpace ~
29822 \InsetSpace ~
29823 \InsetSpace ~
29824 \InsetSpace ~
29825 \InsetSpace ~
29826 sdcdbsrc-goto-sdcdb\InsetSpace ~
29827 \InsetSpace ~
29828 \InsetSpace ~
29829 \InsetSpace ~
29830 \InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 \InsetSpace ~
29835 \InsetSpace ~
29836 Goto the SDCDB output buffer 
29837 \newline
29838 ;;\InsetSpace ~
29839 p\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 sdcdb-prin
29855 t-c-sexp\InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 \InsetSpace ~
29865 \InsetSpace ~
29866 SDCDB print command for data at 
29867 \newline
29868 ;;\InsetSpace ~
29869 \InsetSpace ~
29870 \InsetSpace ~
29871 \InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 \InsetSpace ~
29876 \InsetSpace ~
29877 \InsetSpace ~
29878 \InsetSpace ~
29879 \InsetSpace ~
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 \InsetSpace ~
29883 \InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 \InsetSpace ~
29887 \InsetSpace ~
29888 \InsetSpace ~
29889 \InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 \InsetSpace ~
29894 \InsetSpace ~
29895 \InsetSpace ~
29896 \InsetSpace ~
29897 \InsetSpace ~
29898 \InsetSpace ~
29899 \InsetSpace ~
29900 \InsetSpace ~
29901 \InsetSpace ~
29902 \InsetSpace ~
29903 \InsetSpace ~
29904 \InsetSpace ~
29905 \InsetSpace ~
29906 \InsetSpace ~
29907 \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911 \InsetSpace ~
29912 \InsetSpace ~
29913 \InsetSpace ~
29914 \InsetSpace ~
29915 buffer point 
29916 \newline
29917 ;;\InsetSpace ~
29918 g\InsetSpace ~
29919 \InsetSpace ~
29920 \InsetSpace ~
29921 \InsetSpace ~
29922 \InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 \InsetSpace ~
29929 \InsetSpace ~
29930 \InsetSpace ~
29931 \InsetSpace ~
29932 \InsetSpace ~
29933 sdcdbsrc-goto-sdcdb\InsetSpace ~
29934 \InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938 \InsetSpace ~
29939 \InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 Got
29944 o the SDCDB output buffer 
29945 \newline
29946 ;;\InsetSpace ~
29947 t\InsetSpace ~
29948 \InsetSpace ~
29949 \InsetSpace ~
29950 \InsetSpace ~
29951 \InsetSpace ~
29952 \InsetSpace ~
29953 \InsetSpace ~
29954 \InsetSpace ~
29955 \InsetSpace ~
29956 \InsetSpace ~
29957 \InsetSpace ~
29958 \InsetSpace ~
29959 \InsetSpace ~
29960 \InsetSpace ~
29961 \InsetSpace ~
29962 sdcdbsrc-mode\InsetSpace ~
29963 \InsetSpace ~
29964 \InsetSpace ~
29965 \InsetSpace ~
29966 \InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 \InsetSpace ~
29971 \InsetSpace ~
29972 \InsetSpace ~
29973 \InsetSpace ~
29974 \InsetSpace ~
29975 \InsetSpace ~
29976 \InsetSpace ~
29977 \InsetSpace ~
29978 Toggles Sdcdbsrc mode (turns it
29979  off) 
29980 \newline
29981 ;; 
29982 \newline
29983 ;;\InsetSpace ~
29984 C-c\InsetSpace ~
29985 C-f\InsetSpace ~
29986 \InsetSpace ~
29987 \InsetSpace ~
29988 \InsetSpace ~
29989 \InsetSpace ~
29990 \InsetSpace ~
29991 \InsetSpace ~
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 sdcdb-finish-from-src\InsetSpace ~
29995 \InsetSpace ~
29996 \InsetSpace ~
29997 \InsetSpace ~
29998 \InsetSpace ~
29999 \InsetSpace ~
30000 \InsetSpace ~
30001 \InsetSpace ~
30002 SDCDB finish command 
30003 \newline
30004 ;; 
30005 \newline
30006 ;;\InsetSpace ~
30007 C-x\InsetSpace ~
30008 SPC\InsetSpace ~
30009 \InsetSpace ~
30010 \InsetSpace ~
30011 \InsetSpace ~
30012 \InsetSpace ~
30013 \InsetSpace ~
30014 \InsetSpace ~
30015 \InsetSpace ~
30016 \InsetSpace ~
30017 sdcdb-brea
30018 k\InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 \InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 \InsetSpace ~
30029 \InsetSpace ~
30030 \InsetSpace ~
30031 \InsetSpace ~
30032 \InsetSpace ~
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036 Set break for line with point 
30037 \newline
30038 ;;\InsetSpace ~
30039 ESC\InsetSpace ~
30040 t\InsetSpace ~
30041 \InsetSpace ~
30042 \InsetSpace ~
30043 \InsetSpace ~
30044 \InsetSpace ~
30045 \InsetSpace ~
30046 \InsetSpace ~
30047 \InsetSpace ~
30048 \InsetSpace ~
30049 \InsetSpace ~
30050 \InsetSpace ~
30051 sdcdbsrc-mode\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 Toggle Sdcdbsrc mode 
30068 \newline
30069 ;;\InsetSpace ~
30070 ESC\InsetSpace ~
30071 m\InsetSpace ~
30072 \InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 \InsetSpace ~
30078 \InsetSpace ~
30079 \InsetSpace ~
30080 \InsetSpace ~
30081 \InsetSpace ~
30082 sdc
30083 dbsrc-srcmode\InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 \InsetSpace ~
30092 \InsetSpace ~
30093 \InsetSpace ~
30094 \InsetSpace ~
30095 \InsetSpace ~
30096 Toggle list mode 
30097 \newline
30098 ;; 
30099 \newline
30100
30101 \family default
30102
30103 \newpage
30104
30105 \end_layout
30106
30107 \begin_layout Chapter
30108 TIPS
30109 \end_layout
30110
30111 \begin_layout Standard
30112 Here are a few guidelines that will help the compiler generate more efficient
30113  code, some of the tips are specific to this compiler others are generally
30114  good programming practice.
30115 \end_layout
30116
30117 \begin_layout Itemize
30118 Use the smallest data type to represent your data-value.
30119  If it is known in advance that the value is going to be less than 256 then
30120  use an 'unsigned char' instead of a 'short' or 'int'.
30121  Please note, that ANSI C requires both signed and unsigned chars to be
30122  promoted to 'signed int'
30123 \begin_inset LatexCommand \index{promotion to signed int}
30124
30125 \end_inset
30126
30127
30128 \begin_inset Marginal
30129 status collapsed
30130
30131 \begin_layout Standard
30132
30133 \series bold
30134 \InsetSpace ~
30135 !
30136 \end_layout
30137
30138 \end_inset
30139
30140  before doing any operation.
30141  This promotion
30142 \begin_inset LatexCommand \index{type promotion}
30143
30144 \end_inset
30145
30146
30147 \begin_inset LatexCommand \label{type promotion}
30148
30149 \end_inset
30150
30151  can be omitted, if the result is the same.
30152  The effect of the promotion rules together with the sign-extension is often
30153  surprising:
30154 \end_layout
30155
30156 \begin_deeper
30157 \begin_layout Verse
30158
30159 \family typewriter
30160 unsigned char uc = 0xfe;
30161 \newline
30162 if (uc * uc < 0) /* this is true! */
30163 \newline
30164 {
30165 \newline
30166 \InsetSpace ~
30167 \InsetSpace ~
30168 \InsetSpace ~
30169 \InsetSpace ~
30170 ....
30171 \newline
30172 }
30173 \end_layout
30174
30175 \begin_layout Standard
30176
30177 \family typewriter
30178 uc * uc
30179 \family default
30180  is evaluated as 
30181 \family typewriter
30182 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30183 \family default
30184 .
30185  
30186 \newline
30187 Another one:
30188 \end_layout
30189
30190 \begin_layout Verse
30191
30192 \family typewriter
30193 (unsigned char) -12 / (signed char) -3 = ...
30194 \end_layout
30195
30196 \begin_layout Standard
30197 No, the result is not 4:
30198 \end_layout
30199
30200 \begin_layout Verse
30201
30202 \family typewriter
30203 (int) (unsigned char) -12 / (int) (signed char) -3 =
30204 \newline
30205 (int) (unsigned char)
30206  0xf4 / (int) (signed char) 0xfd =
30207 \newline
30208 (int) 0x00f4 / (int) 0xfffd =
30209 \newline
30210 (int) 0x00f4
30211  / (int) 0xfffd =
30212 \newline
30213 (int) 244 / (int) -3 =
30214 \newline
30215 (int) -81 = (int) 0xffaf;
30216 \end_layout
30217
30218 \begin_layout Standard
30219 Don't complain, that gcc gives you a different result.
30220  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30221  Therefore the results are different.
30222 \newline
30223 From 
30224 \begin_inset Quotes sld
30225 \end_inset
30226
30227 comp.lang.c FAQ
30228 \begin_inset Quotes srd
30229 \end_inset
30230
30231 :
30232 \end_layout
30233
30234 \begin_layout Quote
30235
30236 \emph on
30237 If well-defined overflow characteristics are important and negative values
30238  are not, or if you want to steer clear of sign-extension problems when
30239  manipulating bits or bytes, use one of the corresponding unsigned types.
30240  (Beware when mixing signed and unsigned values in expressions, though.)
30241 \newline
30242 Although
30243  character types (especially unsigned char) can be used as "tiny" integers,
30244  doing so is sometimes more trouble than it's worth, due to unpredictable
30245  sign extension and increased code size.
30246 \end_layout
30247
30248 \end_deeper
30249 \begin_layout Itemize
30250 Use unsigned when it is known in advance that the value is not going to
30251  be negative.
30252  This helps especially if you are doing division or multiplication, bit-shifting
30253  or are using an array index.
30254 \end_layout
30255
30256 \begin_layout Itemize
30257 NEVER jump into a LOOP.
30258 \end_layout
30259
30260 \begin_layout Itemize
30261 Declare the variables to be local
30262 \begin_inset LatexCommand \index{local variables}
30263
30264 \end_inset
30265
30266  whenever possible, especially loop control variables (induction).
30267 \end_layout
30268
30269 \begin_layout Itemize
30270 Have a look at the assembly listing to get a 
30271 \begin_inset Quotes sld
30272 \end_inset
30273
30274 feeling
30275 \begin_inset Quotes srd
30276 \end_inset
30277
30278  for the code generation.
30279 \end_layout
30280
30281 \begin_layout Section
30282 Porting code from or to other compilers
30283 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30284
30285 \end_inset
30286
30287
30288 \end_layout
30289
30290 \begin_layout Itemize
30291 check whether endianness of the compilers differs and adapt where needed.
30292 \end_layout
30293
30294 \begin_layout Itemize
30295 check the device specific header files
30296 \begin_inset LatexCommand \index{Header files}
30297
30298 \end_inset
30299
30300
30301 \begin_inset LatexCommand \index{Include files}
30302
30303 \end_inset
30304
30305  for compiler specific syntax.
30306  Eventually include the file <compiler.h
30307 \begin_inset LatexCommand \index{compiler.h (include file)}
30308
30309 \end_inset
30310
30311
30312 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30313
30314 \end_inset
30315
30316  to allow using common header files.
30317  (see f.e.
30318  cc2510fx.h 
30319 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30320
30321 \end_inset
30322
30323 ).
30324 \end_layout
30325
30326 \begin_layout Itemize
30327 check whether the startup code contains the correct initialization (watchdog,
30328  peripherals).
30329 \end_layout
30330
30331 \begin_layout Itemize
30332 check whether the sizes of short, int, long match.
30333 \end_layout
30334
30335 \begin_layout Itemize
30336 check if some 16 or 32 bit hardware registers require a specific addressing
30337  order (least significant or most significant byte first) and adapt if needed
30338  (
30339 \emph on
30340 first
30341 \emph default
30342  and 
30343 \emph on
30344 last
30345 \emph default
30346  relate to time and not to lower/upper memory location here, so this is
30347  
30348 \emph on
30349 not
30350 \emph default
30351  the same as endianness).
30352 \end_layout
30353
30354 \begin_layout Itemize
30355 check whether the keyword 
30356 \emph on
30357 volatile
30358 \emph default
30359  is used where needed.
30360  The compilers might differ in their optimization characteristics (as different
30361  versions of the same compiler might also use more clever optimizations
30362  this is good idea anyway).
30363  See section 
30364 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30365
30366 \end_inset
30367
30368 .
30369 \end_layout
30370
30371 \begin_layout Itemize
30372 check that the compilers are not told to supress warnings.
30373 \end_layout
30374
30375 \begin_layout Itemize
30376 check and convert compiler specific extensions (interrupts, memory areas,
30377  pragmas etc.).
30378 \end_layout
30379
30380 \begin_layout Itemize
30381 check for differences in type promotion.
30382  Especially check for math operations on 
30383 \family typewriter
30384 char
30385 \family default
30386  or 
30387 \family typewriter
30388 unsigned char
30389 \family default
30390  variables.
30391  For the sake of C99 compatibility SDCC will probably promote these to 
30392 \family typewriter
30393 int
30394 \family default
30395  more often than other compilers.
30396  Eventually insert explicit casts to 
30397 \family typewriter
30398 (char) 
30399 \family default
30400 or
30401 \family typewriter
30402  (unsigned char)
30403 \family default
30404 .
30405  Also check that the ~\InsetSpace ~
30406 operator
30407 \begin_inset LatexCommand \index{\~\/ Operator}
30408
30409 \end_inset
30410
30411  is not used on 
30412 \family typewriter
30413 bit
30414 \begin_inset LatexCommand \index{bit}
30415
30416 \end_inset
30417
30418
30419 \family default
30420  variables, use the !\InsetSpace ~
30421 operator instead.
30422  See sections 
30423 \begin_inset LatexCommand \ref{type promotion}
30424
30425 \end_inset
30426
30427  and 
30428 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30429
30430 \end_inset
30431
30432 .
30433 \end_layout
30434
30435 \begin_layout Itemize
30436 check the assembly code generated for interrupt routines (f.e.
30437  for calls to possibly non-reentrant library functions).
30438 \end_layout
30439
30440 \begin_layout Itemize
30441 check whether timing loops result in proper timing (or preferably consider
30442  a rewrite of the code with timer based delays instead).
30443 \end_layout
30444
30445 \begin_layout Itemize
30446 check for differences in printf parameters (some compilers push (va_arg
30447 \begin_inset LatexCommand \index{vararg, va\_arg}
30448
30449 \end_inset
30450
30451 ) char variables as 
30452 \family typewriter
30453 int
30454 \family default
30455  others push them as 
30456 \family typewriter
30457 char
30458 \family default
30459 .
30460  See section 
30461 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30462
30463 \end_inset
30464
30465 ).
30466 \end_layout
30467
30468 \begin_layout Itemize
30469 check the resulting memory map
30470 \begin_inset LatexCommand \index{Memory map}
30471
30472 \end_inset
30473
30474 .
30475  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30476 ly idata, pdata, xdata).
30477  Eventually check if unexpected library functions are included.
30478 \end_layout
30479
30480 \begin_layout Section
30481 Tools
30482 \begin_inset LatexCommand \index{Tools}
30483
30484 \end_inset
30485
30486  included in the distribution
30487 \end_layout
30488
30489 \begin_layout Standard
30490 \align left
30491 \begin_inset Tabular
30492 <lyxtabular version="3" rows="12" columns="3">
30493 <features>
30494 <column alignment="left" valignment="top" leftline="true" width="0pt">
30495 <column alignment="left" valignment="top" leftline="true" width="0pt">
30496 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30497 <row topline="true" bottomline="true">
30498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30499 \begin_inset Text
30500
30501 \begin_layout Standard
30502
30503 \series bold
30504 Name
30505 \end_layout
30506
30507 \end_inset
30508 </cell>
30509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30510 \begin_inset Text
30511
30512 \begin_layout Standard
30513
30514 \series bold
30515 Purpose
30516 \end_layout
30517
30518 \end_inset
30519 </cell>
30520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30521 \begin_inset Text
30522
30523 \begin_layout Standard
30524
30525 \series bold
30526 Directory
30527 \end_layout
30528
30529 \end_inset
30530 </cell>
30531 </row>
30532 <row topline="true">
30533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30534 \begin_inset Text
30535
30536 \begin_layout Standard
30537 uCsim
30538 \begin_inset LatexCommand \index{uCsim}
30539
30540 \end_inset
30541
30542
30543 \end_layout
30544
30545 \end_inset
30546 </cell>
30547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30548 \begin_inset Text
30549
30550 \begin_layout Standard
30551 Simulator for various architectures
30552 \end_layout
30553
30554 \end_inset
30555 </cell>
30556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30557 \begin_inset Text
30558
30559 \begin_layout Standard
30560 sdcc/sim/ucsim
30561 \end_layout
30562
30563 \end_inset
30564 </cell>
30565 </row>
30566 <row topline="true">
30567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30568 \begin_inset Text
30569
30570 \begin_layout Standard
30571 keil2sdcc.pl
30572 \end_layout
30573
30574 \end_inset
30575 </cell>
30576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30577 \begin_inset Text
30578
30579 \begin_layout Standard
30580 header file
30581 \begin_inset LatexCommand \index{Header files}
30582
30583 \end_inset
30584
30585
30586 \begin_inset LatexCommand \index{Include files}
30587
30588 \end_inset
30589
30590  conversion
30591 \end_layout
30592
30593 \end_inset
30594 </cell>
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30596 \begin_inset Text
30597
30598 \begin_layout Standard
30599 sdcc/support/scripts
30600 \end_layout
30601
30602 \end_inset
30603 </cell>
30604 </row>
30605 <row topline="true">
30606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30607 \begin_inset Text
30608
30609 \begin_layout Standard
30610 mh2h.c
30611 \end_layout
30612
30613 \end_inset
30614 </cell>
30615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30616 \begin_inset Text
30617
30618 \begin_layout Standard
30619 header file conversion
30620 \end_layout
30621
30622 \end_inset
30623 </cell>
30624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30625 \begin_inset Text
30626
30627 \begin_layout Standard
30628 sdcc/support/scripts
30629 \end_layout
30630
30631 \end_inset
30632 </cell>
30633 </row>
30634 <row topline="true">
30635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30636 \begin_inset Text
30637
30638 \begin_layout Standard
30639 as-gbz80
30640 \end_layout
30641
30642 \end_inset
30643 </cell>
30644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30645 \begin_inset Text
30646
30647 \begin_layout Standard
30648 Assembler
30649 \end_layout
30650
30651 \end_inset
30652 </cell>
30653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30654 \begin_inset Text
30655
30656 \begin_layout Standard
30657
30658 \family roman
30659 \series medium
30660 \shape up
30661 \size normal
30662 \emph off
30663 \bar no
30664 \noun off
30665 \color none
30666 sdcc/bin
30667 \end_layout
30668
30669 \end_inset
30670 </cell>
30671 </row>
30672 <row topline="true">
30673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30674 \begin_inset Text
30675
30676 \begin_layout Standard
30677 as-z80
30678 \end_layout
30679
30680 \end_inset
30681 </cell>
30682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30683 \begin_inset Text
30684
30685 \begin_layout Standard
30686 Assembler
30687 \end_layout
30688
30689 \end_inset
30690 </cell>
30691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30692 \begin_inset Text
30693
30694 \begin_layout Standard
30695
30696 \family roman
30697 \series medium
30698 \shape up
30699 \size normal
30700 \emph off
30701 \bar no
30702 \noun off
30703 \color none
30704 sdcc/bin
30705 \end_layout
30706
30707 \end_inset
30708 </cell>
30709 </row>
30710 <row topline="true">
30711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30712 \begin_inset Text
30713
30714 \begin_layout Standard
30715 asx8051
30716 \end_layout
30717
30718 \end_inset
30719 </cell>
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30721 \begin_inset Text
30722
30723 \begin_layout Standard
30724 Assembler
30725 \end_layout
30726
30727 \end_inset
30728 </cell>
30729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30730 \begin_inset Text
30731
30732 \begin_layout Standard
30733
30734 \family roman
30735 \series medium
30736 \shape up
30737 \size normal
30738 \emph off
30739 \bar no
30740 \noun off
30741 \color none
30742 sdcc/bin
30743 \end_layout
30744
30745 \end_inset
30746 </cell>
30747 </row>
30748 <row topline="true">
30749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30750 \begin_inset Text
30751
30752 \begin_layout Standard
30753 SDCDB
30754 \end_layout
30755
30756 \end_inset
30757 </cell>
30758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30759 \begin_inset Text
30760
30761 \begin_layout Standard
30762 Simulator
30763 \end_layout
30764
30765 \end_inset
30766 </cell>
30767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30768 \begin_inset Text
30769
30770 \begin_layout Standard
30771
30772 \family roman
30773 \series medium
30774 \shape up
30775 \size normal
30776 \emph off
30777 \bar no
30778 \noun off
30779 \color none
30780 sdcc/bin
30781 \end_layout
30782
30783 \end_inset
30784 </cell>
30785 </row>
30786 <row topline="true">
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30788 \begin_inset Text
30789
30790 \begin_layout Standard
30791 aslink
30792 \end_layout
30793
30794 \end_inset
30795 </cell>
30796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30797 \begin_inset Text
30798
30799 \begin_layout Standard
30800 Linker
30801 \end_layout
30802
30803 \end_inset
30804 </cell>
30805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30806 \begin_inset Text
30807
30808 \begin_layout Standard
30809
30810 \family roman
30811 \series medium
30812 \shape up
30813 \size normal
30814 \emph off
30815 \bar no
30816 \noun off
30817 \color none
30818 sdcc/bin
30819 \end_layout
30820
30821 \end_inset
30822 </cell>
30823 </row>
30824 <row topline="true">
30825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30826 \begin_inset Text
30827
30828 \begin_layout Standard
30829 link-z80
30830 \end_layout
30831
30832 \end_inset
30833 </cell>
30834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30835 \begin_inset Text
30836
30837 \begin_layout Standard
30838 Linker
30839 \end_layout
30840
30841 \end_inset
30842 </cell>
30843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30844 \begin_inset Text
30845
30846 \begin_layout Standard
30847
30848 \family roman
30849 \series medium
30850 \shape up
30851 \size normal
30852 \emph off
30853 \bar no
30854 \noun off
30855 \color none
30856 sdcc/bin
30857 \end_layout
30858
30859 \end_inset
30860 </cell>
30861 </row>
30862 <row topline="true">
30863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30864 \begin_inset Text
30865
30866 \begin_layout Standard
30867 link-gbz80
30868 \end_layout
30869
30870 \end_inset
30871 </cell>
30872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30873 \begin_inset Text
30874
30875 \begin_layout Standard
30876 Linker
30877 \end_layout
30878
30879 \end_inset
30880 </cell>
30881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30882 \begin_inset Text
30883
30884 \begin_layout Standard
30885
30886 \family roman
30887 \series medium
30888 \shape up
30889 \size normal
30890 \emph off
30891 \bar no
30892 \noun off
30893 \color none
30894 sdcc/bin
30895 \end_layout
30896
30897 \end_inset
30898 </cell>
30899 </row>
30900 <row topline="true" bottomline="true">
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30902 \begin_inset Text
30903
30904 \begin_layout Standard
30905 packihx
30906 \end_layout
30907
30908 \end_inset
30909 </cell>
30910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30911 \begin_inset Text
30912
30913 \begin_layout Standard
30914 Intel Hex packer 
30915 \begin_inset LatexCommand \index{packihx (tool)}
30916
30917 \end_inset
30918
30919
30920 \end_layout
30921
30922 \end_inset
30923 </cell>
30924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30925 \begin_inset Text
30926
30927 \begin_layout Standard
30928
30929 \family roman
30930 \series medium
30931 \shape up
30932 \size normal
30933 \emph off
30934 \bar no
30935 \noun off
30936 \color none
30937 sdcc/bin
30938 \end_layout
30939
30940 \end_inset
30941 </cell>
30942 </row>
30943 </lyxtabular>
30944
30945 \end_inset
30946
30947
30948 \newline
30949
30950 \end_layout
30951
30952 \begin_layout Section
30953 Documentation
30954 \begin_inset LatexCommand \index{Documentation}
30955
30956 \end_inset
30957
30958  included in the distribution
30959 \end_layout
30960
30961 \begin_layout Standard
30962 \align left
30963 \begin_inset Tabular
30964 <lyxtabular version="3" rows="10" columns="2">
30965 <features>
30966 <column alignment="block" valignment="top" leftline="true" width="40col%">
30967 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30968 <row topline="true" bottomline="true" endhead="true">
30969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30970 \begin_inset Text
30971
30972 \begin_layout Standard
30973
30974 \series bold
30975 Subject / Title
30976 \end_layout
30977
30978 \end_inset
30979 </cell>
30980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30981 \begin_inset Text
30982
30983 \begin_layout Standard
30984
30985 \series bold
30986 Filename / Where to get
30987 \end_layout
30988
30989 \end_inset
30990 </cell>
30991 </row>
30992 <row topline="true">
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30994 \begin_inset Text
30995
30996 \begin_layout Standard
30997 SDCC Compiler User Guide
30998 \end_layout
30999
31000 \end_inset
31001 </cell>
31002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31003 \begin_inset Text
31004
31005 \begin_layout Standard
31006 You're reading it right now
31007 \emph on
31008  \InsetSpace ~
31009 \InsetSpace ~
31010 \InsetSpace ~
31011
31012 \hfill
31013 online at:
31014 \emph default
31015
31016 \newline
31017
31018 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31019
31020 \end_inset
31021
31022
31023 \end_layout
31024
31025 \end_inset
31026 </cell>
31027 </row>
31028 <row topline="true">
31029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31030 \begin_inset Text
31031
31032 \begin_layout Standard
31033 Changelog of SDCC
31034 \end_layout
31035
31036 \end_inset
31037 </cell>
31038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31039 \begin_inset Text
31040
31041 \begin_layout Standard
31042 sdcc/Changelog
31043 \emph on
31044  \InsetSpace ~
31045 \InsetSpace ~
31046 \InsetSpace ~
31047
31048 \hfill
31049 online at:
31050 \emph default
31051
31052 \newline
31053
31054 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31055
31056 \end_inset
31057
31058
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 ASXXXX
31070 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31071
31072 \end_inset
31073
31074
31075 \begin_inset LatexCommand \index{Assembler documentation}
31076
31077 \end_inset
31078
31079  Assemblers and
31080 \newline
31081 ASLINK
31082 \begin_inset LatexCommand \index{aslink}
31083
31084 \end_inset
31085
31086
31087 \begin_inset LatexCommand \index{Linker documentation}
31088
31089 \end_inset
31090
31091  Relocating Linker
31092 \end_layout
31093
31094 \end_inset
31095 </cell>
31096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31097 \begin_inset Text
31098
31099 \begin_layout Standard
31100 sdcc/as/doc/asxhtm.html 
31101 \emph on
31102 \InsetSpace ~
31103 \InsetSpace ~
31104 \InsetSpace ~
31105
31106 \hfill
31107 online at:
31108 \emph default
31109
31110 \newline
31111
31112 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31113
31114 \end_inset
31115
31116
31117 \end_layout
31118
31119 \end_inset
31120 </cell>
31121 </row>
31122 <row topline="true">
31123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31124 \begin_inset Text
31125
31126 \begin_layout Standard
31127 SDCC regression test
31128 \begin_inset LatexCommand \index{Regression test}
31129
31130 \end_inset
31131
31132
31133 \end_layout
31134
31135 \end_inset
31136 </cell>
31137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31138 \begin_inset Text
31139
31140 \begin_layout Standard
31141 sdcc/doc/test_suite_spec.pdf 
31142 \emph on
31143 \InsetSpace ~
31144 \InsetSpace ~
31145 \InsetSpace ~
31146
31147 \hfill
31148 online at:
31149 \emph default
31150
31151 \newline
31152
31153 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31154
31155 \end_inset
31156
31157
31158 \end_layout
31159
31160 \end_inset
31161 </cell>
31162 </row>
31163 <row topline="true">
31164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31165 \begin_inset Text
31166
31167 \begin_layout Standard
31168 Various notes
31169 \end_layout
31170
31171 \end_inset
31172 </cell>
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31174 \begin_inset Text
31175
31176 \begin_layout Standard
31177 sdcc/doc/* 
31178 \emph on
31179 \InsetSpace ~
31180 \InsetSpace ~
31181 \InsetSpace ~
31182
31183 \hfill
31184 online at:
31185 \emph default
31186
31187 \newline
31188
31189 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31190
31191 \end_inset
31192
31193
31194 \end_layout
31195
31196 \end_inset
31197 </cell>
31198 </row>
31199 <row topline="true">
31200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31201 \begin_inset Text
31202
31203 \begin_layout Standard
31204 Notes on debugging with SDCDB
31205 \begin_inset LatexCommand \index{SDCDB (debugger)}
31206
31207 \end_inset
31208
31209
31210 \end_layout
31211
31212 \end_inset
31213 </cell>
31214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31215 \begin_inset Text
31216
31217 \begin_layout Standard
31218 sdcc/debugger/README 
31219 \emph on
31220 \InsetSpace ~
31221 \InsetSpace ~
31222 \InsetSpace ~
31223
31224 \hfill
31225 online at
31226 \emph default
31227 :
31228 \newline
31229
31230 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31231
31232 \end_inset
31233
31234
31235 \end_layout
31236
31237 \end_inset
31238 </cell>
31239 </row>
31240 <row topline="true">
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31242 \begin_inset Text
31243
31244 \begin_layout Standard
31245 uCsim
31246 \begin_inset LatexCommand \index{uCsim}
31247
31248 \end_inset
31249
31250  Software simulator for microcontrollers
31251 \end_layout
31252
31253 \end_inset
31254 </cell>
31255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31256 \begin_inset Text
31257
31258 \begin_layout Standard
31259
31260 \family roman
31261 \series medium
31262 \shape up
31263 \size normal
31264 \emph off
31265 \bar no
31266 \noun off
31267 \color none
31268 sdcc/sim/ucsim/doc
31269 \family default
31270 \series default
31271 \shape default
31272 \size default
31273 \emph default
31274 \bar default
31275 \noun default
31276 /index.html 
31277 \emph on
31278 \InsetSpace ~
31279 \InsetSpace ~
31280 \InsetSpace ~
31281
31282 \hfill
31283 online at:
31284 \emph default
31285
31286 \newline
31287
31288 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31289
31290 \end_inset
31291
31292
31293 \end_layout
31294
31295 \end_inset
31296 </cell>
31297 </row>
31298 <row topline="true">
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31300 \begin_inset Text
31301
31302 \begin_layout Standard
31303 Temporary notes on the pic16
31304 \begin_inset LatexCommand \index{PIC16}
31305
31306 \end_inset
31307
31308  port
31309 \end_layout
31310
31311 \end_inset
31312 </cell>
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31314 \begin_inset Text
31315
31316 \begin_layout Standard
31317 sdcc/src/pic16/NOTES 
31318 \emph on
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322
31323 \hfill
31324 online at:
31325 \newline
31326
31327 \emph default
31328
31329 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31330
31331 \end_inset
31332
31333
31334 \end_layout
31335
31336 \end_inset
31337 </cell>
31338 </row>
31339 <row topline="true" bottomline="true">
31340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31341 \begin_inset Text
31342
31343 \begin_layout Standard
31344 SDCC internal documentation (debugging file format)
31345 \end_layout
31346
31347 \end_inset
31348 </cell>
31349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31350 \begin_inset Text
31351
31352 \begin_layout Standard
31353 sdcc/doc/
31354 \family roman
31355 \series medium
31356 \shape up
31357 \size normal
31358 \emph off
31359 \bar no
31360 \noun off
31361 \color none
31362 cdbfileformat.pd
31363 \family default
31364 \series default
31365 \shape default
31366 \size default
31367 \emph default
31368 \bar default
31369 \noun default
31370 f
31371 \emph on
31372  \InsetSpace ~
31373 \InsetSpace ~
31374 \InsetSpace ~
31375
31376 \hfill
31377 online at:
31378 \emph default
31379
31380 \newline
31381
31382 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31383
31384 \end_inset
31385
31386
31387 \end_layout
31388
31389 \end_inset
31390 </cell>
31391 </row>
31392 </lyxtabular>
31393
31394 \end_inset
31395
31396
31397 \newline
31398
31399 \end_layout
31400
31401 \begin_layout Section
31402 Related open source tools
31403 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31404
31405 \end_inset
31406
31407
31408 \begin_inset LatexCommand \index{Related tools}
31409
31410 \end_inset
31411
31412
31413 \end_layout
31414
31415 \begin_layout Standard
31416 \align left
31417 \begin_inset Tabular
31418 <lyxtabular version="3" rows="16" columns="3">
31419 <features>
31420 <column alignment="left" valignment="top" leftline="true" width="0pt">
31421 <column alignment="block" valignment="top" leftline="true" width="30line%">
31422 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31423 <row topline="true" bottomline="true">
31424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31425 \begin_inset Text
31426
31427 \begin_layout Standard
31428
31429 \series bold
31430 Name
31431 \end_layout
31432
31433 \end_inset
31434 </cell>
31435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31436 \begin_inset Text
31437
31438 \begin_layout Standard
31439
31440 \series bold
31441 Purpose
31442 \end_layout
31443
31444 \end_inset
31445 </cell>
31446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31447 \begin_inset Text
31448
31449 \begin_layout Standard
31450
31451 \series bold
31452 Where to get
31453 \end_layout
31454
31455 \end_inset
31456 </cell>
31457 </row>
31458 <row topline="true">
31459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31460 \begin_inset Text
31461
31462 \begin_layout Standard
31463 gpsim
31464 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31465
31466 \end_inset
31467
31468
31469 \end_layout
31470
31471 \end_inset
31472 </cell>
31473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31474 \begin_inset Text
31475
31476 \begin_layout Standard
31477 PIC simulator
31478 \end_layout
31479
31480 \end_inset
31481 </cell>
31482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31483 \begin_inset Text
31484
31485 \begin_layout Standard
31486 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31487
31488 \end_inset
31489
31490
31491 \end_layout
31492
31493 \end_inset
31494 </cell>
31495 </row>
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31498 \begin_inset Text
31499
31500 \begin_layout Standard
31501 gputils
31502 \begin_inset LatexCommand \index{gputils (pic tools)}
31503
31504 \end_inset
31505
31506
31507 \end_layout
31508
31509 \end_inset
31510 </cell>
31511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31512 \begin_inset Text
31513
31514 \begin_layout Standard
31515 GNU PIC utilities
31516 \end_layout
31517
31518 \end_inset
31519 </cell>
31520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31521 \begin_inset Text
31522
31523 \begin_layout Standard
31524 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31525
31526 \end_inset
31527
31528
31529 \end_layout
31530
31531 \end_inset
31532 </cell>
31533 </row>
31534 <row topline="true">
31535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31536 \begin_inset Text
31537
31538 \begin_layout Standard
31539 flP5
31540 \end_layout
31541
31542 \end_inset
31543 </cell>
31544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31545 \begin_inset Text
31546
31547 \begin_layout Standard
31548 PIC programmer
31549 \end_layout
31550
31551 \end_inset
31552 </cell>
31553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31554 \begin_inset Text
31555
31556 \begin_layout Standard
31557 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31558
31559 \end_inset
31560
31561
31562 \end_layout
31563
31564 \end_inset
31565 </cell>
31566 </row>
31567 <row topline="true">
31568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31569 \begin_inset Text
31570
31571 \begin_layout Standard
31572 ec2drv/newcdb
31573 \end_layout
31574
31575 \end_inset
31576 </cell>
31577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31578 \begin_inset Text
31579
31580 \begin_layout Standard
31581 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31582  (Unix only)
31583 \end_layout
31584
31585 \end_inset
31586 </cell>
31587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31588 \begin_inset Text
31589
31590 \begin_layout Standard
31591 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31592
31593 \end_inset
31594
31595
31596 \end_layout
31597
31598 \end_inset
31599 </cell>
31600 </row>
31601 <row topline="true">
31602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31603 \begin_inset Text
31604
31605 \begin_layout Standard
31606 indent
31607 \begin_inset LatexCommand \index{indent (source formatting tool)}
31608
31609 \end_inset
31610
31611
31612 \end_layout
31613
31614 \end_inset
31615 </cell>
31616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31617 \begin_inset Text
31618
31619 \begin_layout Standard
31620 Formats C source - Master of the white spaces
31621 \end_layout
31622
31623 \end_inset
31624 </cell>
31625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31626 \begin_inset Text
31627
31628 \begin_layout Standard
31629 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31630
31631 \end_inset
31632
31633
31634 \end_layout
31635
31636 \end_inset
31637 </cell>
31638 </row>
31639 <row topline="true">
31640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31641 \begin_inset Text
31642
31643 \begin_layout Standard
31644 srecord
31645 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31646
31647 \end_inset
31648
31649
31650 \end_layout
31651
31652 \end_inset
31653 </cell>
31654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31655 \begin_inset Text
31656
31657 \begin_layout Standard
31658 Object file conversion, checksumming, ...
31659 \end_layout
31660
31661 \end_inset
31662 </cell>
31663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31664 \begin_inset Text
31665
31666 \begin_layout Standard
31667 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31668
31669 \end_inset
31670
31671
31672 \end_layout
31673
31674 \end_inset
31675 </cell>
31676 </row>
31677 <row topline="true">
31678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31679 \begin_inset Text
31680
31681 \begin_layout Standard
31682 objdump
31683 \begin_inset LatexCommand \index{objdump (tool)}
31684
31685 \end_inset
31686
31687
31688 \end_layout
31689
31690 \end_inset
31691 </cell>
31692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31693 \begin_inset Text
31694
31695 \begin_layout Standard
31696 Object file conversion, ...
31697 \end_layout
31698
31699 \end_inset
31700 </cell>
31701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31702 \begin_inset Text
31703
31704 \begin_layout Standard
31705 Part of binutils (should be there anyway)
31706 \end_layout
31707
31708 \end_inset
31709 </cell>
31710 </row>
31711 <row topline="true">
31712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31713 \begin_inset Text
31714
31715 \begin_layout Standard
31716 cmon51
31717 \end_layout
31718
31719 \end_inset
31720 </cell>
31721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31722 \begin_inset Text
31723
31724 \begin_layout Standard
31725 8051 monitor (hex up-/download, single step, disassemble)
31726 \end_layout
31727
31728 \end_inset
31729 </cell>
31730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31731 \begin_inset Text
31732
31733 \begin_layout Standard
31734 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31735
31736 \end_inset
31737
31738
31739 \end_layout
31740
31741 \end_inset
31742 </cell>
31743 </row>
31744 <row topline="true">
31745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31746 \begin_inset Text
31747
31748 \begin_layout Standard
31749 doxygen
31750 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31751
31752 \end_inset
31753
31754
31755 \end_layout
31756
31757 \end_inset
31758 </cell>
31759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31760 \begin_inset Text
31761
31762 \begin_layout Standard
31763 Source code documentation system
31764 \end_layout
31765
31766 \end_inset
31767 </cell>
31768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31769 \begin_inset Text
31770
31771 \begin_layout Standard
31772 \begin_inset LatexCommand \url{http://www.doxygen.org}
31773
31774 \end_inset
31775
31776
31777 \end_layout
31778
31779 \end_inset
31780 </cell>
31781 </row>
31782 <row topline="true">
31783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31784 \begin_inset Text
31785
31786 \begin_layout Standard
31787 kdevelop
31788 \end_layout
31789
31790 \end_inset
31791 </cell>
31792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31793 \begin_inset Text
31794
31795 \begin_layout Standard
31796 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31797 \end_layout
31798
31799 \end_inset
31800 </cell>
31801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31802 \begin_inset Text
31803
31804 \begin_layout Standard
31805 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31806
31807 \end_inset
31808
31809
31810 \end_layout
31811
31812 \end_inset
31813 </cell>
31814 </row>
31815 <row topline="true">
31816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31817 \begin_inset Text
31818
31819 \begin_layout Standard
31820 paulmon
31821 \end_layout
31822
31823 \end_inset
31824 </cell>
31825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31826 \begin_inset Text
31827
31828 \begin_layout Standard
31829 8051 monitor (hex up-/download, single step, disassemble)
31830 \end_layout
31831
31832 \end_inset
31833 </cell>
31834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31835 \begin_inset Text
31836
31837 \begin_layout Standard
31838 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31839
31840 \end_inset
31841
31842
31843 \end_layout
31844
31845 \end_inset
31846 </cell>
31847 </row>
31848 <row topline="true">
31849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31850 \begin_inset Text
31851
31852 \begin_layout Standard
31853 splint
31854 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31855
31856 \end_inset
31857
31858
31859 \end_layout
31860
31861 \end_inset
31862 </cell>
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31864 \begin_inset Text
31865
31866 \begin_layout Standard
31867 Statically checks c sources (see 
31868 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31869
31870 \end_inset
31871
31872 )
31873 \end_layout
31874
31875 \end_inset
31876 </cell>
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31878 \begin_inset Text
31879
31880 \begin_layout Standard
31881 \begin_inset LatexCommand \url{http://www.splint.org}
31882
31883 \end_inset
31884
31885
31886 \end_layout
31887
31888 \end_inset
31889 </cell>
31890 </row>
31891 <row topline="true" bottomline="true">
31892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31893 \begin_inset Text
31894
31895 \begin_layout Standard
31896 ddd
31897 \begin_inset LatexCommand \index{DDD (debugger)}
31898
31899 \end_inset
31900
31901
31902 \end_layout
31903
31904 \end_inset
31905 </cell>
31906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31907 \begin_inset Text
31908
31909 \begin_layout Standard
31910 Debugger, serves nicely as GUI to SDCDB
31911 \begin_inset LatexCommand \index{SDCDB (debugger)}
31912
31913 \end_inset
31914
31915  (Unix only)
31916 \end_layout
31917
31918 \end_inset
31919 </cell>
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31921 \begin_inset Text
31922
31923 \begin_layout Standard
31924 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31925
31926 \end_inset
31927
31928
31929 \end_layout
31930
31931 \end_inset
31932 </cell>
31933 </row>
31934 <row bottomline="true">
31935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31936 \begin_inset Text
31937
31938 \begin_layout Standard
31939 d52
31940 \begin_inset LatexCommand \index{d52}
31941
31942 \end_inset
31943
31944
31945 \begin_inset LatexCommand \index{d52 (disassembler)}
31946
31947 \end_inset
31948
31949
31950 \end_layout
31951
31952 \end_inset
31953 </cell>
31954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31955 \begin_inset Text
31956
31957 \begin_layout Standard
31958 Disassembler, can count instruction cycles
31959 \begin_inset LatexCommand \index{instruction cycles (count)}
31960
31961 \end_inset
31962
31963 , use with options -pnd
31964 \end_layout
31965
31966 \end_inset
31967 </cell>
31968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31969 \begin_inset Text
31970
31971 \begin_layout Standard
31972 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31973
31974 \end_inset
31975
31976
31977 \end_layout
31978
31979 \end_inset
31980 </cell>
31981 </row>
31982 <row bottomline="true">
31983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31984 \begin_inset Text
31985
31986 \begin_layout Standard
31987 cmake
31988 \begin_inset LatexCommand \index{cmake}
31989
31990 \end_inset
31991
31992
31993 \end_layout
31994
31995 \end_inset
31996 </cell>
31997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31998 \begin_inset Text
31999
32000 \begin_layout Standard
32001 Cross platform build system, generates Makefiles
32002 \begin_inset LatexCommand \index{Makefile}
32003
32004 \end_inset
32005
32006  and project workspaces
32007 \begin_inset LatexCommand \index{project workspace}
32008
32009 \end_inset
32010
32011
32012 \end_layout
32013
32014 \end_inset
32015 </cell>
32016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32017 \begin_inset Text
32018
32019 \begin_layout Standard
32020 \begin_inset LatexCommand \url{http://www.cmake.org}
32021
32022 \end_inset
32023
32024  \InsetSpace ~
32025 \InsetSpace ~
32026 \InsetSpace ~
32027 \InsetSpace ~
32028 and a dedicated wiki entry: 
32029 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32030
32031 \end_inset
32032
32033
32034 \end_layout
32035
32036 \end_inset
32037 </cell>
32038 </row>
32039 </lyxtabular>
32040
32041 \end_inset
32042
32043
32044 \newline
32045
32046 \end_layout
32047
32048 \begin_layout Section
32049 Related documentation / recommended reading
32050 \end_layout
32051
32052 \begin_layout Standard
32053 \align left
32054 \begin_inset Tabular
32055 <lyxtabular version="3" rows="7" columns="3">
32056 <features>
32057 <column alignment="left" valignment="top" leftline="true" width="0pt">
32058 <column alignment="left" valignment="top" leftline="true" width="0">
32059 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32060 <row topline="true" bottomline="true">
32061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32062 \begin_inset Text
32063
32064 \begin_layout Standard
32065
32066 \series bold
32067 Name
32068 \end_layout
32069
32070 \end_inset
32071 </cell>
32072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32073 \begin_inset Text
32074
32075 \begin_layout Standard
32076
32077 \series bold
32078 Subject / Title
32079 \end_layout
32080
32081 \end_inset
32082 </cell>
32083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32084 \begin_inset Text
32085
32086 \begin_layout Standard
32087
32088 \series bold
32089 Where to get
32090 \end_layout
32091
32092 \end_inset
32093 </cell>
32094 </row>
32095 <row topline="true">
32096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32097 \begin_inset Text
32098
32099 \begin_layout Standard
32100
32101 \family roman
32102 \series medium
32103 \shape up
32104 \size normal
32105 \emph off
32106 \bar no
32107 \noun off
32108 \color none
32109 c-refcard.pdf
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 C Reference Card
32119 \begin_inset LatexCommand \index{C Reference card}
32120
32121 \end_inset
32122
32123 , 2 pages
32124 \end_layout
32125
32126 \end_inset
32127 </cell>
32128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32129 \begin_inset Text
32130
32131 \begin_layout Standard
32132 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32133
32134 \end_inset
32135
32136
32137 \end_layout
32138
32139 \end_inset
32140 </cell>
32141 </row>
32142 <row topline="true">
32143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32144 \begin_inset Text
32145
32146 \begin_layout Standard
32147 c-faq
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 C-FAQ
32157 \begin_inset LatexCommand \index{C FAQ}
32158
32159 \end_inset
32160
32161
32162 \end_layout
32163
32164 \end_inset
32165 </cell>
32166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32167 \begin_inset Text
32168
32169 \begin_layout Standard
32170 \begin_inset LatexCommand \url{http://www.c-faq.com}
32171
32172 \end_inset
32173
32174
32175 \end_layout
32176
32177 \end_inset
32178 </cell>
32179 </row>
32180 <row topline="true">
32181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32182 \begin_inset Text
32183
32184 \begin_layout Standard
32185 ISO/IEC 9899:TC2
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 \begin_inset Quotes sld
32195 \end_inset
32196
32197 C-Standard
32198 \begin_inset Quotes srd
32199 \end_inset
32200
32201
32202 \end_layout
32203
32204 \end_inset
32205 </cell>
32206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32207 \begin_inset Text
32208
32209 \begin_layout Standard
32210
32211 \size footnotesize
32212 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32213
32214 \end_inset
32215
32216
32217 \end_layout
32218
32219 \end_inset
32220 </cell>
32221 </row>
32222 <row topline="true">
32223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32224 \begin_inset Text
32225
32226 \begin_layout Standard
32227 ISO/IEC DTR 18037
32228 \end_layout
32229
32230 \end_inset
32231 </cell>
32232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32233 \begin_inset Text
32234
32235 \begin_layout Standard
32236 \begin_inset Quotes sld
32237 \end_inset
32238
32239 Extensions for Embedded C
32240 \begin_inset Quotes srd
32241 \end_inset
32242
32243
32244 \end_layout
32245
32246 \end_inset
32247 </cell>
32248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32249 \begin_inset Text
32250
32251 \begin_layout Standard
32252
32253 \size footnotesize
32254 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32255
32256 \end_inset
32257
32258
32259 \end_layout
32260
32261 \end_inset
32262 </cell>
32263 </row>
32264 <row topline="true">
32265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32266 \begin_inset Text
32267
32268 \begin_layout Standard
32269
32270 \end_layout
32271
32272 \end_inset
32273 </cell>
32274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32275 \begin_inset Text
32276
32277 \begin_layout Standard
32278 Latest datasheet of target CPU
32279 \end_layout
32280
32281 \end_inset
32282 </cell>
32283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32284 \begin_inset Text
32285
32286 \begin_layout Standard
32287 vendor
32288 \end_layout
32289
32290 \end_inset
32291 </cell>
32292 </row>
32293 <row topline="true" bottomline="true">
32294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32295 \begin_inset Text
32296
32297 \begin_layout Standard
32298
32299 \end_layout
32300
32301 \end_inset
32302 </cell>
32303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32304 \begin_inset Text
32305
32306 \begin_layout Standard
32307 Revision history of datasheet
32308 \end_layout
32309
32310 \end_inset
32311 </cell>
32312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32313 \begin_inset Text
32314
32315 \begin_layout Standard
32316 vendor
32317 \end_layout
32318
32319 \end_inset
32320 </cell>
32321 </row>
32322 </lyxtabular>
32323
32324 \end_inset
32325
32326
32327 \newline
32328
32329 \end_layout
32330
32331 \begin_layout Section
32332 Application notes specifically for SDCC
32333 \end_layout
32334
32335 \begin_layout Standard
32336 SDCC makes no claims about the completeness of this list and about up-to-datenes
32337 s or correctness of the application notes
32338 \begin_inset LatexCommand \index{Application notes}
32339
32340 \end_inset
32341
32342 .
32343 \end_layout
32344
32345 \begin_layout Standard
32346 \align left
32347
32348 \size footnotesize
32349 \begin_inset Tabular
32350 <lyxtabular version="3" rows="7" columns="3">
32351 <features>
32352 <column alignment="block" valignment="top" leftline="true" width="17col%">
32353 <column alignment="block" valignment="top" leftline="true" width="27col%">
32354 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32355 <row topline="true" bottomline="true">
32356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32357 \begin_inset Text
32358
32359 \begin_layout Standard
32360
32361 \series bold
32362 \size footnotesize
32363 Vendor
32364 \end_layout
32365
32366 \end_inset
32367 </cell>
32368 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32369 \begin_inset Text
32370
32371 \begin_layout Standard
32372
32373 \series bold
32374 \size footnotesize
32375 Subject / Title
32376 \end_layout
32377
32378 \end_inset
32379 </cell>
32380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32381 \begin_inset Text
32382
32383 \begin_layout Standard
32384
32385 \series bold
32386 \size footnotesize
32387 Where to get
32388 \end_layout
32389
32390 \end_inset
32391 </cell>
32392 </row>
32393 <row topline="true">
32394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32395 \begin_inset Text
32396
32397 \begin_layout Standard
32398
32399 \size footnotesize
32400 Maxim / Dallas
32401 \end_layout
32402
32403 \end_inset
32404 </cell>
32405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32406 \begin_inset Text
32407
32408 \begin_layout Standard
32409
32410 \size footnotesize
32411 Using the SDCC Compiler for the DS80C400
32412 \begin_inset LatexCommand \index{DS80C400}
32413
32414 \end_inset
32415
32416
32417 \end_layout
32418
32419 \end_inset
32420 </cell>
32421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32422 \begin_inset Text
32423
32424 \begin_layout Standard
32425
32426 \size footnotesize
32427 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32428
32429 \end_inset
32430
32431
32432 \end_layout
32433
32434 \end_inset
32435 </cell>
32436 </row>
32437 <row topline="true">
32438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32439 \begin_inset Text
32440
32441 \begin_layout Standard
32442
32443 \size footnotesize
32444 Maxim / Dallas
32445 \end_layout
32446
32447 \end_inset
32448 </cell>
32449 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32450 \begin_inset Text
32451
32452 \begin_layout Standard
32453
32454 \size footnotesize
32455 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32456 \begin_inset LatexCommand \index{DS89C4x0}
32457
32458 \end_inset
32459
32460  Family of Microcontrollers
32461 \end_layout
32462
32463 \end_inset
32464 </cell>
32465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32466 \begin_inset Text
32467
32468 \begin_layout Standard
32469
32470 \size footnotesize
32471 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32472
32473 \end_inset
32474
32475
32476 \end_layout
32477
32478 \end_inset
32479 </cell>
32480 </row>
32481 <row topline="true">
32482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32483 \begin_inset Text
32484
32485 \begin_layout Standard
32486
32487 \size footnotesize
32488 Silicon Laboratories / Cygnal
32489 \end_layout
32490
32491 \end_inset
32492 </cell>
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32494 \begin_inset Text
32495
32496 \begin_layout Standard
32497
32498 \size footnotesize
32499 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32500 \begin_inset LatexCommand \index{IDE}
32501
32502 \end_inset
32503
32504
32505 \end_layout
32506
32507 \end_inset
32508 </cell>
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32510 \begin_inset Text
32511
32512 \begin_layout Standard
32513
32514 \size footnotesize
32515 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32516
32517 \end_inset
32518
32519
32520 \end_layout
32521
32522 \end_inset
32523 </cell>
32524 </row>
32525 <row topline="true">
32526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32527 \begin_inset Text
32528
32529 \begin_layout Standard
32530
32531 \size footnotesize
32532 Ramtron / Goal Semiconductor
32533 \end_layout
32534
32535 \end_inset
32536 </cell>
32537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32538 \begin_inset Text
32539
32540 \begin_layout Standard
32541
32542 \size footnotesize
32543 Interfacing SDCC to Syn and Textpad
32544 \end_layout
32545
32546 \end_inset
32547 </cell>
32548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32549 \begin_inset Text
32550
32551 \begin_layout Standard
32552
32553 \size footnotesize
32554 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32555
32556 \end_inset
32557
32558
32559 \end_layout
32560
32561 \end_inset
32562 </cell>
32563 </row>
32564 <row topline="true">
32565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32566 \begin_inset Text
32567
32568 \begin_layout Standard
32569
32570 \size footnotesize
32571 Ramtron / Goal Semiconductor
32572 \end_layout
32573
32574 \end_inset
32575 </cell>
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32577 \begin_inset Text
32578
32579 \begin_layout Standard
32580
32581 \size footnotesize
32582 Installing and Configuring SDCC and Crimson Editor 
32583 \end_layout
32584
32585 \end_inset
32586 </cell>
32587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32588 \begin_inset Text
32589
32590 \begin_layout Standard
32591
32592 \size footnotesize
32593 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32594
32595 \end_inset
32596
32597
32598 \end_layout
32599
32600 \end_inset
32601 </cell>
32602 </row>
32603 <row topline="true" bottomline="true">
32604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32605 \begin_inset Text
32606
32607 \begin_layout Standard
32608
32609 \size footnotesize
32610 Texas Instruments
32611 \end_layout
32612
32613 \end_inset
32614 </cell>
32615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32616 \begin_inset Text
32617
32618 \begin_layout Standard
32619
32620 \size footnotesize
32621 MSC12xx Programming with SDCC
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
32631 \size footnotesize
32632 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32633
32634 \end_inset
32635
32636
32637 \end_layout
32638
32639 \end_inset
32640 </cell>
32641 </row>
32642 </lyxtabular>
32643
32644 \end_inset
32645
32646
32647 \end_layout
32648
32649 \begin_layout Section
32650 Some Questions
32651 \end_layout
32652
32653 \begin_layout Standard
32654 Some questions answered, some pointers given - it might be time to in turn
32655  ask 
32656 \emph on
32657 you
32658 \emph default
32659  some questions: 
32660 \end_layout
32661
32662 \begin_layout Itemize
32663 can you solve your project with the selected microcontroller? Would you
32664  find out early or rather late that your target is too small/slow/whatever?
32665  Can you switch to a slightly better device if it doesn't fit?
32666 \end_layout
32667
32668 \begin_layout Itemize
32669 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32670  and/or another programming language be more adequate? Would an operating
32671  system on the target device help?
32672 \end_layout
32673
32674 \begin_layout Itemize
32675 if you solved the problem, will the marketing department be happy?
32676 \end_layout
32677
32678 \begin_layout Itemize
32679 if the marketing department is happy, will customers be happy?
32680 \end_layout
32681
32682 \begin_layout Itemize
32683 if you're the project manager, marketing department and maybe even the customer
32684  in one person, have you tried to see the project from the outside?
32685 \end_layout
32686
32687 \begin_layout Itemize
32688 is the project done if you think it is done? Or is just that other interface/pro
32689 tocol/feature/configuration/option missing? How about website, manual(s),
32690  internationali(z|s)ation, packaging, labels, 2nd source for components,
32691  electromagnetic compatability/interference, documentation for production,
32692  production test software, update mechanism, patent issues?
32693 \end_layout
32694
32695 \begin_layout Itemize
32696 is your project adequately positioned in that magic triangle: fame, fortune,
32697  fun?
32698 \end_layout
32699
32700 \begin_layout Standard
32701 Maybe not all answers to these questions are known and some answers may
32702  even be 
32703 \emph on
32704 no
32705 \emph default
32706 , nevertheless knowing these questions may help you to avoid burnout
32707 \begin_inset Foot
32708 status open
32709
32710 \begin_layout Standard
32711 burnout is bad for electronic devices, programmers and motorcycle tyres
32712 \end_layout
32713
32714 \end_inset
32715
32716 .
32717  Chances are you didn't want to hear some of them...
32718 \end_layout
32719
32720 \begin_layout Chapter
32721 Support
32722 \begin_inset LatexCommand \index{Support}
32723
32724 \end_inset
32725
32726
32727 \end_layout
32728
32729 \begin_layout Standard
32730 SDCC has grown to be a large project.
32731  The compiler alone (without the preprocessor, assembler and linker) is
32732  well over 150,000 lines of code (blank stripped).
32733  The open source nature of this project is a key to its continued growth
32734  and support.
32735  You gain the benefit and support of many active software developers and
32736  end users.
32737  Is SDCC perfect? No, that's why we need your help.
32738  The developers take pride in fixing reported bugs.
32739  You can help by reporting the bugs and helping other SDCC users.
32740  There are lots of ways to contribute, and we encourage you to take part
32741  in making SDCC a great software package.
32742  
32743 \end_layout
32744
32745 \begin_layout Standard
32746 The SDCC project is hosted on the SDCC sourceforge site at 
32747 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32748
32749 \end_inset
32750
32751 .
32752  You'll find the complete set of mailing lists
32753 \begin_inset LatexCommand \index{Mailing list(s)}
32754
32755 \end_inset
32756
32757 , forums, bug reporting system, patch submission
32758 \begin_inset LatexCommand \index{Patch submission}
32759
32760 \end_inset
32761
32762  system, download
32763 \begin_inset LatexCommand \index{download}
32764
32765 \end_inset
32766
32767  area and Subversion code repository
32768 \begin_inset LatexCommand \index{Subversion code repository}
32769
32770 \end_inset
32771
32772  there.
32773 \end_layout
32774
32775 \begin_layout Section
32776 Reporting Bugs
32777 \begin_inset LatexCommand \index{Bug reporting}
32778
32779 \end_inset
32780
32781
32782 \begin_inset LatexCommand \index{Reporting bugs}
32783
32784 \end_inset
32785
32786
32787 \end_layout
32788
32789 \begin_layout Standard
32790 The recommended way of reporting bugs is using the infrastructure of the
32791  sourceforge site.
32792  You can follow the status of bug reports there and have an overview about
32793  the known bugs.
32794 \end_layout
32795
32796 \begin_layout Standard
32797 Bug reports are automatically forwarded to the developer mailing list and
32798  will be fixed ASAP.
32799  When reporting a bug, it is very useful to include a small test program
32800  (the smaller the better) which reproduces the problem.
32801  If you can isolate the problem by looking at the generated assembly code,
32802  this can be very helpful.
32803  Compiling your program with the -
32804 \begin_inset ERT
32805 status collapsed
32806
32807 \begin_layout Standard
32808
32809
32810 \backslash
32811 /
32812 \end_layout
32813
32814 \end_inset
32815
32816 -dumpall
32817 \begin_inset LatexCommand \index{-\/-dumpall}
32818
32819 \end_inset
32820
32821  option can sometimes be useful in locating optimization problems.
32822  When reporting a bug please make sure you:
32823 \end_layout
32824
32825 \begin_layout Enumerate
32826 Attach the code you are compiling with SDCC.
32827  
32828 \end_layout
32829
32830 \begin_layout Enumerate
32831 Specify the exact command you use to run SDCC, or attach your Makefile.
32832  
32833 \end_layout
32834
32835 \begin_layout Enumerate
32836 Specify the SDCC version (type "
32837 \family sans
32838 \series bold
32839 sdcc -v
32840 \family default
32841 \series default
32842 "), your platform, and operating system.
32843  
32844 \end_layout
32845
32846 \begin_layout Enumerate
32847 Provide an exact copy of any error message or incorrect output.
32848  
32849 \end_layout
32850
32851 \begin_layout Enumerate
32852 Put something meaningful in the subject of your message.
32853 \end_layout
32854
32855 \begin_layout Standard
32856 Please attempt to include these 5 important parts, as applicable, in all
32857  requests for support or when reporting any problems or bugs with SDCC.
32858  Though this will make your message lengthy, it will greatly improve your
32859  chance that SDCC users and developers will be able to help you.
32860  Some SDCC developers are frustrated by bug reports without code provided
32861  that they can use to reproduce and ultimately fix the problem, so please
32862  be sure to provide sample code if you are reporting a bug! 
32863 \end_layout
32864
32865 \begin_layout Standard
32866 Please have a short check that you are using a recent version of SDCC and
32867  the bug is not yet known.
32868  This is the link for reporting bugs: 
32869 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32870
32871 \end_inset
32872
32873 .
32874  With SDCC on average having more than 200 downloads
32875 \begin_inset LatexCommand \index{download}
32876
32877 \end_inset
32878
32879  on sourceforge per day
32880 \begin_inset Foot
32881 status open
32882
32883 \begin_layout Standard
32884 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32885  between 2002 and 2005.
32886  This does not include other methods of distribution.
32887 \end_layout
32888
32889 \end_inset
32890
32891  there must be some users.
32892  So it's not exactly easy to find a new bug.
32893  If you find one we need it: 
32894 \emph on
32895 reporting bugs is good
32896 \emph default
32897 .
32898 \end_layout
32899
32900 \begin_layout Section
32901 Requesting Features
32902 \begin_inset LatexCommand \label{sub:Requesting-Features}
32903
32904 \end_inset
32905
32906
32907 \begin_inset LatexCommand \index{Feature request}
32908
32909 \end_inset
32910
32911
32912 \begin_inset LatexCommand \index{Requesting features}
32913
32914 \end_inset
32915
32916
32917 \end_layout
32918
32919 \begin_layout Standard
32920 Like bug reports feature requests are forwarded to the developer mailing
32921  list.
32922  This is the link for requesting features: 
32923 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32924
32925 \end_inset
32926
32927 .
32928 \end_layout
32929
32930 \begin_layout Section
32931 Submitting patches
32932 \end_layout
32933
32934 \begin_layout Standard
32935 Like bug reports contributed patches are forwarded to the developer mailing
32936  list.
32937  This is the link for submitting patches
32938 \begin_inset LatexCommand \index{Patch submission}
32939
32940 \end_inset
32941
32942
32943 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32944
32945 \end_inset
32946
32947 .
32948 \end_layout
32949
32950 \begin_layout Standard
32951 You need to specify some parameters to the 
32952 \family typewriter
32953 diff
32954 \family default
32955  command for the patches to be useful.
32956  If you modified more than one file a patch created f.e.
32957  with 
32958 \family sans
32959 \series bold
32960
32961 \begin_inset Quotes sld
32962 \end_inset
32963
32964 diff -Naur unmodified_directory modified_directory >my_changes.patch
32965 \begin_inset Quotes srd
32966 \end_inset
32967
32968
32969 \family default
32970 \series default
32971  will be fine, otherwise 
32972 \family sans
32973 \series bold
32974
32975 \begin_inset Quotes sld
32976 \end_inset
32977
32978 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32979 \begin_inset Quotes srd
32980 \end_inset
32981
32982
32983 \series default
32984  
32985 \family default
32986 will do.
32987 \end_layout
32988
32989 \begin_layout Section
32990 Getting Help
32991 \end_layout
32992
32993 \begin_layout Standard
32994 These links should take you directly to the 
32995 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32996
32997 \end_inset
32998
32999
33000 \begin_inset Foot
33001 status open
33002
33003 \begin_layout Standard
33004 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33005  automated messages (mid 2003)
33006 \end_layout
33007
33008 \end_inset
33009
33010  and the 
33011 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33012
33013 \end_inset
33014
33015 , lists
33016 \begin_inset LatexCommand \index{Mailing list(s)}
33017
33018 \end_inset
33019
33020  and forums are archived and searchable so if you are lucky someone already
33021  had a similar problem.
33022  While mails to the lists themselves are delivered promptly their web front
33023  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33024  if you're seriously using SDCC please consider subscribing to the lists.
33025 \end_layout
33026
33027 \begin_layout Section
33028 ChangeLog
33029 \end_layout
33030
33031 \begin_layout Standard
33032 You can follow the status of the Subversion version
33033 \begin_inset LatexCommand \index{version}
33034
33035 \end_inset
33036
33037  of SDCC by watching the Changelog
33038 \begin_inset LatexCommand \index{Changelog}
33039
33040 \end_inset
33041
33042  in the Subversion repository
33043 \size footnotesize
33044  
33045 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33046
33047 \end_inset
33048
33049 .
33050 \end_layout
33051
33052 \begin_layout Section
33053 Subversion Source Code Repository
33054 \end_layout
33055
33056 \begin_layout Standard
33057 The output of 
33058 \family sans
33059 \series bold
33060 sdcc -
33061 \family default
33062
33063 \begin_inset ERT
33064 status open
33065
33066 \begin_layout Standard
33067
33068
33069 \backslash
33070 /
33071 \end_layout
33072
33073 \end_inset
33074
33075
33076 \family sans
33077 -version
33078 \family default
33079 \series default
33080  or the filenames of the snapshot versions of SDCC include date and its
33081  Subversion
33082 \begin_inset LatexCommand \index{Subversion code repository}
33083
33084 \end_inset
33085
33086  number.
33087  Subversion allows to download the source of recent or previous versions
33088  
33089 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33090
33091 \end_inset
33092
33093  (by number or by date).
33094  An on-line source code browser and detailled instructions are also available
33095  there.
33096  SDCC versions starting from 1999 up to now are available (currently the
33097  versions prior to the conversion from cvs
33098 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33099
33100 \end_inset
33101
33102  to Subversion (April 2006) are either by accessible by Subversion or by
33103  cvs).
33104 \end_layout
33105
33106 \begin_layout Section
33107 Release policy
33108 \begin_inset LatexCommand \index{Release policy}
33109
33110 \end_inset
33111
33112
33113 \end_layout
33114
33115 \begin_layout Standard
33116 Historically there often were long delays between official releases and
33117  the sourceforge download area tends to get not updated at all.
33118  Excuses in the past might have referred to problems with live range analysis,
33119  but as this was fixed a while ago, the current problem is that another
33120  excuse has to be found.
33121  Kidding aside, we have to get better there! On the other hand there are
33122  daily snapshots available at 
33123 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33124
33125 \end_inset
33126
33127 , and you can always build the very last version (hopefully with many bugs
33128  fixed, and features added) from the source code available at 
33129 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33130
33131 \end_inset
33132
33133 .
33134  The SDCC Wiki
33135 \begin_inset LatexCommand \index{wiki}
33136
33137 \end_inset
33138
33139
33140 \begin_inset LatexCommand \index{SDCC Wiki}
33141
33142 \end_inset
33143
33144  at 
33145 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33146
33147 \end_inset
33148
33149  also holds some information about past and future releases.
33150 \end_layout
33151
33152 \begin_layout Section
33153 Examples
33154 \begin_inset LatexCommand \index{Examples}
33155
33156 \end_inset
33157
33158
33159 \end_layout
33160
33161 \begin_layout Standard
33162 You'll find some small examples in the directory 
33163 \emph on
33164 sdcc/device/examples/.
33165  
33166 \emph default
33167 More examples and libraries are available at
33168 \emph on
33169  The SDCC Open Knowledge Resource 
33170 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33171
33172 \end_inset
33173
33174  
33175 \emph default
33176 web site or at 
33177 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33178
33179 \end_inset
33180
33181 .
33182 \end_layout
33183
33184 \begin_layout Standard
33185 \begin_inset Note Note
33186 status collapsed
33187
33188 \begin_layout Standard
33189 I did insert a reference to Paul's web site here although it seems rather
33190  dedicated to a specific 8032 board (I think it's okay because it f.e.
33191  shows LCD/Harddisc interface and has a free 8051 monitor.
33192  Independent 8032 board vendors face hard competition of heavily subsidized
33193  development boards anyway).
33194 \end_layout
33195
33196 \begin_layout Standard
33197 Maybe we should include some links to real world applications.
33198  Preferably pointer to pointers (one for each architecture) so this stays
33199  manageable here?
33200 \end_layout
33201
33202 \end_inset
33203
33204
33205 \end_layout
33206
33207 \begin_layout Section
33208 Quality control
33209 \begin_inset LatexCommand \label{sec:Quality-control}
33210
33211 \end_inset
33212
33213
33214 \begin_inset LatexCommand \index{Quality control}
33215
33216 \end_inset
33217
33218
33219 \end_layout
33220
33221 \begin_layout Standard
33222 The compiler is passed through snaphot build compile and build checks.
33223  The so called 
33224 \shape italic
33225 regression tests
33226 \shape default
33227
33228 \begin_inset LatexCommand \index{Regression test}
33229
33230 \end_inset
33231
33232  check that SDCC itself compiles flawlessly on several host platforms (i386,
33233  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33234  and checks the quality of the code generated by SDCC by running the code
33235  for several target platforms through simulators.
33236  The regression test suite comprises more than 100 files which expand to
33237  more than 500 test cases which include more than 4500 tests.
33238  The results of these tests are published daily on SDCC's snapshot page
33239  (click on the red or green symbols on the right side of 
33240 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33241
33242 \end_inset
33243
33244 ).
33245 \end_layout
33246
33247 \begin_layout Standard
33248 There is a separate document 
33249 \shape italic
33250 test_suite.pdf 
33251 \begin_inset LatexCommand \index{Test suite}
33252
33253 \end_inset
33254
33255
33256 \shape default
33257  
33258 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33259
33260 \end_inset
33261
33262  about the regression test suite.
33263 \end_layout
33264
33265 \begin_layout Standard
33266 You'll find the test code in the directory 
33267 \shape italic
33268 sdcc/support/regression
33269 \shape default
33270 .
33271  You can run these tests manually by running 
33272 \family sans
33273 make
33274 \family default
33275  in this directory (or f.e.
33276  
33277 \family sans
33278 \series bold
33279
33280 \begin_inset Quotes sld
33281 \end_inset
33282
33283 make test-mcs51
33284 \begin_inset Quotes srd
33285 \end_inset
33286
33287
33288 \family default
33289 \series default
33290  if you don't want to run the complete tests).
33291  The test code might also be interesting if you want to look for examples
33292 \begin_inset LatexCommand \index{Examples}
33293
33294 \end_inset
33295
33296  checking corner cases of SDCC or if you plan to submit patches
33297 \begin_inset LatexCommand \index{Patch submission}
33298
33299 \end_inset
33300
33301 .
33302 \end_layout
33303
33304 \begin_layout Standard
33305 The PIC14 port uses a different set of regression tests 
33306 \begin_inset LatexCommand \index{Regression test (PIC14)}
33307
33308 \end_inset
33309
33310 , you'll find them in the directory 
33311 \shape italic
33312 sdcc/src/regression
33313 \shape default
33314 .
33315 \end_layout
33316
33317 \begin_layout Section
33318 Use of SDCC in Education
33319 \end_layout
33320
33321 \begin_layout Standard
33322 In short: 
33323 \emph on
33324 highly
33325 \emph default
33326  encouraged
33327 \begin_inset Foot
33328 status open
33329
33330 \begin_layout Standard
33331 the phrase "use in education" might evoke the association "
33332 \emph on
33333 only
33334 \emph default
33335  fit for use in education".
33336  This connotation is not intended but nevertheless risked as the licensing
33337  of SDCC makes it difficult to offer educational discounts
33338 \end_layout
33339
33340 \end_inset
33341
33342 .
33343  If your rationales are to:
33344 \end_layout
33345
33346 \begin_layout Enumerate
33347 give students a chance to understand the 
33348 \emph on
33349 complete
33350 \emph default
33351  steps of code generation
33352 \end_layout
33353
33354 \begin_layout Enumerate
33355 have a curriculum that can be extended for years.
33356  Then you could use an fpga board as target and your curriculum will seamlessly
33357  extend from logic synthesis (
33358 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33359
33360 \end_inset
33361
33362
33363 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33364
33365 \end_inset
33366
33367 ), over assembly programming, to C to FPGA compilers (
33368 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33369
33370 \end_inset
33371
33372 ) and to C.
33373 \end_layout
33374
33375 \begin_layout Enumerate
33376 be able to insert excursions about skills like using a revision control
33377  system, submitting/applying patches, using a type-setting (as opposed to
33378  word-processing) engine LyX/LaTeX, using 
33379 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33380
33381 \end_inset
33382
33383 , following some 
33384 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33385
33386 \end_inset
33387
33388 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33389  Source Software, CPU simulation, compiler regression tests
33390 \begin_inset LatexCommand \index{Regression test}
33391
33392 \end_inset
33393
33394 .
33395  
33396 \newline
33397 And if there should be a shortage of ideas then you can always point students
33398  to the ever-growing feature request list 
33399 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33400
33401 \end_inset
33402
33403 .
33404 \end_layout
33405
33406 \begin_layout Enumerate
33407 not tie students to a specific host platform and instead allow them to use
33408  a host platform of 
33409 \emph on
33410 their
33411 \emph default
33412  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33413  and eventually 
33414 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33415
33416 \end_inset
33417
33418 )
33419 \end_layout
33420
33421 \begin_layout Enumerate
33422 not encourage students to use illegal copies of educational software
33423 \end_layout
33424
33425 \begin_layout Enumerate
33426 be immune to licensing/availability/price changes of the chosen tool chain
33427 \end_layout
33428
33429 \begin_layout Enumerate
33430 be able to change to a new target platform without having to adopt a new
33431  tool chain
33432 \end_layout
33433
33434 \begin_layout Enumerate
33435 have complete control over and insight into the tool chain
33436 \end_layout
33437
33438 \begin_layout Enumerate
33439 make your students aware about the pros and cons of open source software
33440  development
33441 \end_layout
33442
33443 \begin_layout Enumerate
33444 give back to the public as you are probably at least partially publically
33445  funded
33446 \end_layout
33447
33448 \begin_layout Enumerate
33449 give students a chance to publically prove their skills and to possibly
33450  see a world wide impact
33451 \end_layout
33452
33453 \begin_layout Standard
33454 then SDCC is probably among the first choices.
33455  Well, probably SDCC might be the only choice.
33456 \newpage
33457
33458 \end_layout
33459
33460 \begin_layout Chapter
33461 SDCC Technical Data
33462 \end_layout
33463
33464 \begin_layout Section
33465 Optimizations
33466 \begin_inset LatexCommand \index{Optimizations}
33467
33468 \end_inset
33469
33470
33471 \end_layout
33472
33473 \begin_layout Standard
33474 SDCC performs a host of standard optimizations in addition to some MCU specific
33475  optimizations.
33476  
33477 \end_layout
33478
33479 \begin_layout Subsection
33480 Sub-expression Elimination
33481 \begin_inset LatexCommand \index{Subexpression elimination}
33482
33483 \end_inset
33484
33485
33486 \end_layout
33487
33488 \begin_layout Standard
33489 The compiler does local and 
33490 \emph on
33491 g
33492 \emph default
33493 lobal 
33494 \emph on
33495 c
33496 \emph default
33497 ommon 
33498 \emph on
33499 s
33500 \emph default
33501 ubexpression 
33502 \emph on
33503 e
33504 \emph default
33505 limination, e.g.: 
33506 \end_layout
33507
33508 \begin_layout Verse
33509
33510 \family typewriter
33511 i = x + y + 1; 
33512 \newline
33513 j = x + y;
33514 \end_layout
33515
33516 \begin_layout Standard
33517 will be translated to
33518 \end_layout
33519
33520 \begin_layout Verse
33521
33522 \family typewriter
33523 iTemp = x + y; 
33524 \newline
33525 i = iTemp + 1; 
33526 \newline
33527 j = iTemp;
33528 \end_layout
33529
33530 \begin_layout Standard
33531 Some subexpressions are not as obvious as the above example, e.g.:
33532 \end_layout
33533
33534 \begin_layout Verse
33535
33536 \family typewriter
33537 a->b[i].c = 10; 
33538 \newline
33539 a->b[i].d = 11;
33540 \end_layout
33541
33542 \begin_layout Standard
33543 In this case the address arithmetic a->b[i] will be computed only once;
33544  the equivalent code in C would be.
33545 \end_layout
33546
33547 \begin_layout Verse
33548
33549 \family typewriter
33550 iTemp = a->b[i]; 
33551 \newline
33552 iTemp.c = 10; 
33553 \newline
33554 iTemp.d = 11;
33555 \end_layout
33556
33557 \begin_layout Standard
33558 The compiler will try to keep these temporary variables in registers.
33559 \end_layout
33560
33561 \begin_layout Subsection
33562 Dead-Code Elimination
33563 \begin_inset LatexCommand \index{Dead-code elimination}
33564
33565 \end_inset
33566
33567
33568 \end_layout
33569
33570 \begin_layout Verse
33571
33572 \family typewriter
33573 int global;
33574 \newline
33575
33576 \newline
33577 void f () { 
33578 \newline
33579 \InsetSpace ~
33580 \InsetSpace ~
33581 int i; 
33582 \newline
33583 \InsetSpace ~
33584 \InsetSpace ~
33585 i = 1; \InsetSpace ~
33586 \InsetSpace ~
33587 \InsetSpace ~
33588 \InsetSpace ~
33589 \InsetSpace ~
33590 /* dead store */ 
33591 \newline
33592 \InsetSpace ~
33593 \InsetSpace ~
33594 global = 1;\InsetSpace ~
33595 /* dead
33596  store */ 
33597 \newline
33598 \InsetSpace ~
33599 \InsetSpace ~
33600 global = 2; 
33601 \newline
33602 \InsetSpace ~
33603 \InsetSpace ~
33604 return; 
33605 \newline
33606 \InsetSpace ~
33607 \InsetSpace ~
33608 global = 3;\InsetSpace ~
33609 /* unreachable */ 
33610 \newline
33611 }
33612 \end_layout
33613
33614 \begin_layout Standard
33615 will be changed to
33616 \end_layout
33617
33618 \begin_layout Verse
33619
33620 \family typewriter
33621 int global;
33622 \newline
33623
33624 \newline
33625 void f () {
33626 \newline
33627 \InsetSpace ~
33628 \InsetSpace ~
33629 global = 2; 
33630 \newline
33631 }
33632 \end_layout
33633
33634 \begin_layout Subsection
33635 Copy-Propagation
33636 \begin_inset LatexCommand \index{Copy propagation}
33637
33638 \end_inset
33639
33640
33641 \end_layout
33642
33643 \begin_layout Verse
33644
33645 \family typewriter
33646 int f() { 
33647 \newline
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 int i, j; 
33651 \newline
33652 \InsetSpace ~
33653 \InsetSpace ~
33654 i = 10; 
33655 \newline
33656 \InsetSpace ~
33657 \InsetSpace ~
33658 j = i; 
33659 \newline
33660 \InsetSpace ~
33661 \InsetSpace ~
33662 return j; 
33663 \newline
33664 }
33665 \end_layout
33666
33667 \begin_layout Standard
33668 will be changed to 
33669 \end_layout
33670
33671 \begin_layout Verse
33672
33673 \family typewriter
33674 int f() { 
33675 \newline
33676 \InsetSpace ~
33677 \InsetSpace ~
33678 int i, j; 
33679 \newline
33680 \InsetSpace ~
33681 \InsetSpace ~
33682 i = 10; 
33683 \newline
33684 \InsetSpace ~
33685 \InsetSpace ~
33686 j = 10; 
33687 \newline
33688 \InsetSpace ~
33689 \InsetSpace ~
33690 return 10; 
33691 \newline
33692 }
33693 \end_layout
33694
33695 \begin_layout Standard
33696 Note: the dead stores created by this copy propagation will be eliminated
33697  by dead-code elimination.
33698 \end_layout
33699
33700 \begin_layout Subsection
33701 Loop Optimizations
33702 \begin_inset LatexCommand \index{Loop optimization}
33703
33704 \end_inset
33705
33706
33707 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33708
33709 \end_inset
33710
33711
33712 \end_layout
33713
33714 \begin_layout Standard
33715 Two types of loop optimizations are done by SDCC 
33716 \emph on
33717 loop invariant
33718 \emph default
33719  lifting and
33720 \emph on
33721  strength reduction
33722 \emph default
33723  of loop induction variables.
33724  In addition to the strength reduction the optimizer marks the induction
33725  variables and the register allocator tries to keep the induction variables
33726  in registers for the duration of the loop.
33727  Because of this preference of the register allocator
33728 \begin_inset LatexCommand \index{Register allocation}
33729
33730 \end_inset
33731
33732 , loop induction optimization causes an increase in register pressure, which
33733  may cause unwanted spilling of other temporary variables into the stack
33734 \begin_inset LatexCommand \index{stack}
33735
33736 \end_inset
33737
33738  / data space.
33739  The compiler will generate a warning message when it is forced to allocate
33740  extra space either on the stack or data space.
33741  If this extra space allocation is undesirable then induction optimization
33742  can be eliminated either for the entire source file (with -
33743 \begin_inset ERT
33744 status collapsed
33745
33746 \begin_layout Standard
33747
33748
33749 \backslash
33750 /
33751 \end_layout
33752
33753 \end_inset
33754
33755 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33756 noinduction
33757 \begin_inset LatexCommand \index{\#pragma noinduction}
33758
33759 \end_inset
33760
33761 .
33762 \newline
33763
33764 \newline
33765 Loop Invariant:
33766 \end_layout
33767
33768 \begin_layout Verse
33769
33770 \family typewriter
33771 for (i = 0 ; i < 100 ; i ++) 
33772 \newline
33773 \InsetSpace ~
33774 \InsetSpace ~
33775 \InsetSpace ~
33776 \InsetSpace ~
33777 f += k + l;
33778 \end_layout
33779
33780 \begin_layout Standard
33781 changed to
33782 \end_layout
33783
33784 \begin_layout Verse
33785
33786 \family typewriter
33787 itemp = k + l; 
33788 \newline
33789 for (i = 0; i < 100; i++) 
33790 \newline
33791 \InsetSpace ~
33792 \InsetSpace ~
33793 \InsetSpace ~
33794 \InsetSpace ~
33795 f += itemp;
33796 \end_layout
33797
33798 \begin_layout Standard
33799 As mentioned previously some loop invariants are not as apparent, all static
33800  address computations are also moved out of the loop.
33801 \newline
33802
33803 \newline
33804 Strength Reduction
33805 \begin_inset LatexCommand \index{Strength reduction}
33806
33807 \end_inset
33808
33809 , this optimization substitutes an expression by a cheaper expression:
33810 \end_layout
33811
33812 \begin_layout Verse
33813
33814 \family typewriter
33815 for (i=0;i < 100; i++)
33816 \newline
33817 \InsetSpace ~
33818 \InsetSpace ~
33819 \InsetSpace ~
33820 \InsetSpace ~
33821 ar[i*5] = i*3;
33822 \end_layout
33823
33824 \begin_layout Standard
33825 changed to
33826 \end_layout
33827
33828 \begin_layout Verse
33829
33830 \family typewriter
33831 itemp1 = 0; 
33832 \newline
33833 itemp2 = 0; 
33834 \newline
33835 for (i=0;i< 100;i++) { 
33836 \newline
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 ar[itemp1] = itemp2; 
33842 \newline
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 \InsetSpace ~
33847 itemp1
33848  += 5; 
33849 \newline
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 itemp2 += 3; 
33855 \newline
33856 }
33857 \end_layout
33858
33859 \begin_layout Standard
33860 The more expensive multiplication
33861 \begin_inset LatexCommand \index{Multiplication}
33862
33863 \end_inset
33864
33865  is changed to a less expensive addition.
33866 \end_layout
33867
33868 \begin_layout Subsection
33869 Loop Reversing
33870 \begin_inset LatexCommand \index{Loop reversing}
33871
33872 \end_inset
33873
33874
33875 \end_layout
33876
33877 \begin_layout Standard
33878 This optimization is done to reduce the overhead of checking loop boundaries
33879  for every iteration.
33880  Some simple loops can be reversed and implemented using a 
33881 \begin_inset Quotes eld
33882 \end_inset
33883
33884 decrement and jump if not zero
33885 \begin_inset Quotes erd
33886 \end_inset
33887
33888  instruction.
33889  SDCC checks for the following criterion to determine if a loop is reversible
33890  (note: more sophisticated compilers use data-dependency analysis to make
33891  this determination, SDCC uses a more simple minded analysis).
33892 \end_layout
33893
33894 \begin_layout Itemize
33895 The 'for' loop is of the form 
33896 \newline
33897
33898 \newline
33899
33900 \family typewriter
33901 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33902  += 1])
33903 \newline
33904 \InsetSpace ~
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 <for body>
33909 \end_layout
33910
33911 \begin_layout Itemize
33912 The <for body> does not contain 
33913 \begin_inset Quotes eld
33914 \end_inset
33915
33916 continue
33917 \begin_inset Quotes erd
33918 \end_inset
33919
33920  or 'break
33921 \begin_inset Quotes erd
33922 \end_inset
33923
33924 .
33925 \end_layout
33926
33927 \begin_layout Itemize
33928 All goto's are contained within the loop.
33929 \end_layout
33930
33931 \begin_layout Itemize
33932 No function calls within the loop.
33933 \end_layout
33934
33935 \begin_layout Itemize
33936 The loop control variable <sym> is not assigned any value within the loop
33937 \end_layout
33938
33939 \begin_layout Itemize
33940 The loop control variable does NOT participate in any arithmetic operation
33941  within the loop.
33942 \end_layout
33943
33944 \begin_layout Itemize
33945 There are NO switch statements in the loop.
33946 \end_layout
33947
33948 \begin_layout Subsection
33949 Algebraic Simplifications
33950 \end_layout
33951
33952 \begin_layout Standard
33953 SDCC does numerous algebraic simplifications, the following is a small sub-set
33954  of these optimizations.
33955 \end_layout
33956
33957 \begin_layout Verse
33958
33959 \family typewriter
33960 i = j + 0;\InsetSpace ~
33961 \InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964  /* changed to: */\InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968  i = j; 
33969 \newline
33970 i /= 2;\InsetSpace ~
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977  /* changed to: */\InsetSpace ~
33978 \InsetSpace ~
33979 \InsetSpace ~
33980 \InsetSpace ~
33981  i >>= 1; 
33982 \newline
33983 i
33984  = j - j;\InsetSpace ~
33985 \InsetSpace ~
33986 \InsetSpace ~
33987 \InsetSpace ~
33988  /* changed to: */\InsetSpace ~
33989 \InsetSpace ~
33990 \InsetSpace ~
33991 \InsetSpace ~
33992  i = 0; 
33993 \newline
33994 i = j / 1;\InsetSpace ~
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 \InsetSpace ~
33998  /* changed to: */\InsetSpace ~
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 \InsetSpace ~
34002  i = j;
34003 \end_layout
34004
34005 \begin_layout Standard
34006 Note the subexpressions
34007 \begin_inset LatexCommand \index{Subexpression}
34008
34009 \end_inset
34010
34011  given above are generally introduced by macro expansions or as a result
34012  of copy/constant propagation.
34013 \end_layout
34014
34015 \begin_layout Subsection
34016 'switch' Statements
34017 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34018
34019 \end_inset
34020
34021
34022 \begin_inset LatexCommand \index{switch statement}
34023
34024 \end_inset
34025
34026
34027 \end_layout
34028
34029 \begin_layout Standard
34030 SDCC can optimize switch statements to jump tables
34031 \begin_inset LatexCommand \index{jump tables}
34032
34033 \end_inset
34034
34035 .
34036  It makes the decision based on an estimate of the generated code size.
34037  SDCC is quite liberal in the requirements for jump table generation: 
34038 \end_layout
34039
34040 \begin_layout Itemize
34041 The labels need not be in order, and the starting number need not be one
34042  or zero, the case labels are in numerical sequence or not too many case
34043  labels are missing.
34044 \end_layout
34045
34046 \begin_deeper
34047 \begin_layout Verse
34048
34049 \family typewriter
34050 switch(i) {\InsetSpace ~
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 \InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 \InsetSpace ~
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 switch (i) { 
34077 \newline
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 case 4: ...\InsetSpace ~
34082 \InsetSpace ~
34083 \InsetSpace ~
34084 \InsetSpace ~
34085 \InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089 \InsetSpace ~
34090 \InsetSpace ~
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 \InsetSpace ~
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 case 0: ...
34108  
34109 \newline
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 case 5: ...\InsetSpace ~
34114 \InsetSpace ~
34115 \InsetSpace ~
34116 \InsetSpace ~
34117 \InsetSpace ~
34118 \InsetSpace ~
34119 \InsetSpace ~
34120 \InsetSpace ~
34121 \InsetSpace ~
34122 \InsetSpace ~
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 \InsetSpace ~
34128 \InsetSpace ~
34129 \InsetSpace ~
34130 \InsetSpace ~
34131 \InsetSpace ~
34132 \InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139 case 1: ...
34140  
34141 \newline
34142 \InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 case 3: ...\InsetSpace ~
34146 \InsetSpace ~
34147 \InsetSpace ~
34148 \InsetSpace ~
34149 \InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 \InsetSpace ~
34157 \InsetSpace ~
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 \InsetSpace ~
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 \InsetSpace ~
34171
34172 \newline
34173 \InsetSpace ~
34174 \InsetSpace ~
34175 \InsetSpace ~
34176 case 6: ...\InsetSpace ~
34177 \InsetSpace ~
34178 \InsetSpace ~
34179 \InsetSpace ~
34180 \InsetSpace ~
34181 \InsetSpace ~
34182 \InsetSpace ~
34183 \InsetSpace ~
34184 \InsetSpace ~
34185 \InsetSpace ~
34186 \InsetSpace ~
34187 \InsetSpace ~
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202 case 3: ...
34203  
34204 \newline
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 case 7: ...\InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 \InsetSpace ~
34213 \InsetSpace ~
34214 \InsetSpace ~
34215 \InsetSpace ~
34216 \InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 case 4: ...
34235  
34236 \newline
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 case 8: ...\InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243 \InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261 \InsetSpace ~
34262 \InsetSpace ~
34263 \InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 case 5: ...
34267  
34268 \newline
34269 \InsetSpace ~
34270 \InsetSpace ~
34271 \InsetSpace ~
34272 case 9: ...\InsetSpace ~
34273 \InsetSpace ~
34274 \InsetSpace ~
34275 \InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280 \InsetSpace ~
34281 \InsetSpace ~
34282 \InsetSpace ~
34283 \InsetSpace ~
34284 \InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289 \InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297 \InsetSpace ~
34298 case 6: ...
34299  
34300 \newline
34301 \InsetSpace ~
34302 \InsetSpace ~
34303 \InsetSpace ~
34304 case 10: ...\InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307 \InsetSpace ~
34308 \InsetSpace ~
34309 \InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 case 7: ...
34330  
34331 \newline
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 case 11: ...\InsetSpace ~
34336 \InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 case 8: ...
34361  
34362 \newline
34363 }\InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374 \InsetSpace ~
34375 \InsetSpace ~
34376 \InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 }
34400 \end_layout
34401
34402 \begin_layout Standard
34403 Both the above switch statements will be implemented using a jump-table.
34404  The example to the right side is slightly more efficient as the check for
34405  the lower boundary of the jump-table is not needed.
34406 \end_layout
34407
34408 \end_deeper
34409 \begin_layout Itemize
34410 The number of case labels is not larger than supported by the target architectur
34411 e.
34412 \end_layout
34413
34414 \begin_layout Itemize
34415 If the case labels are not in numerical sequence ('gaps' between cases)
34416  SDCC checks whether a jump table with additionally inserted dummy cases
34417  is still attractive.
34418  
34419 \end_layout
34420
34421 \begin_layout Itemize
34422 If the starting number is not zero and a check for the lower boundary of
34423  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34424  ...
34425  .
34426 \end_layout
34427
34428 \begin_layout Standard
34429 Switch statements which have large gaps in the numeric sequence or those
34430  that have too many case labels can be split into more than one switch statement
34431  for efficient code generation, e.g.:
34432 \end_layout
34433
34434 \begin_layout Verse
34435
34436 \family typewriter
34437 switch (i) { 
34438 \newline
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 case 1: ...
34442  
34443 \newline
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 case 2: ...
34447  
34448 \newline
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 case 3: ...
34452  
34453 \newline
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 case 4: ...
34457  
34458 \newline
34459 \InsetSpace ~
34460 \InsetSpace ~
34461 case 5: ...
34462  
34463 \newline
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 case 6: ...
34467  
34468 \newline
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 case 7: ...
34472  
34473 \newline
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 case 101: ...
34477  
34478 \newline
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 case 102: ...
34482  
34483 \newline
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 case 103: ...
34487  
34488 \newline
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 case 104: ...
34492  
34493 \newline
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 case 105: ...
34497  
34498 \newline
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 case 106: ...
34502  
34503 \newline
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 case 107: ...
34507  
34508 \newline
34509 }
34510 \end_layout
34511
34512 \begin_layout Standard
34513 If the above switch statement is broken down into two switch statements
34514 \end_layout
34515
34516 \begin_layout Verse
34517
34518 \family typewriter
34519 switch (i) { 
34520 \newline
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 case 1: ...
34524  
34525 \newline
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 case 2: ...
34529  
34530 \newline
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 case 3: ...
34534  
34535 \newline
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 case 4: ...
34539  
34540 \newline
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 case 5: ...
34544  
34545 \newline
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 case 6: ...
34549  
34550 \newline
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 case 7: ...
34554  
34555 \newline
34556 }
34557 \end_layout
34558
34559 \begin_layout Standard
34560 and
34561 \end_layout
34562
34563 \begin_layout Verse
34564
34565 \family typewriter
34566 switch (i) { 
34567 \newline
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 case 101: ...
34571  
34572 \newline
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 case 102: ...
34576  
34577 \newline
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 case 103: ...
34581  
34582 \newline
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 case 104: ...
34586  
34587 \newline
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 case 105: ...
34591  
34592 \newline
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 case 106: ...
34596  
34597 \newline
34598 \InsetSpace ~
34599 \InsetSpace ~
34600 case 107: ...
34601  
34602 \newline
34603 }
34604 \end_layout
34605
34606 \begin_layout Standard
34607 then both the switch statements will be implemented using jump-tables whereas
34608  the unmodified switch statement will not be.
34609 \end_layout
34610
34611 \begin_layout Standard
34612 \begin_inset Note Note
34613 status collapsed
34614
34615 \begin_layout Standard
34616 There might be reasons which SDCC cannot know about to either favour or
34617  not favour jump tables.
34618  If the target system has to be as quick for the last switch case as for
34619  the first (pro jump table), or if the switch argument is known to be zero
34620  in the majority of the cases (contra jump table).
34621 \end_layout
34622
34623 \end_inset
34624
34625
34626 \end_layout
34627
34628 \begin_layout Standard
34629 The pragma nojtbound
34630 \begin_inset LatexCommand \index{\#pragma nojtbound}
34631
34632 \end_inset
34633
34634  can be used to turn off checking the 
34635 \emph on
34636 j
34637 \emph default
34638 ump 
34639 \emph on
34640 t
34641 \emph default
34642 able 
34643 \emph on
34644 bound
34645 \emph default
34646 aries.
34647  It has no effect if a default label is supplied.
34648  Use of this pragma is dangerous: if the switch
34649 \begin_inset LatexCommand \index{switch statement}
34650
34651 \end_inset
34652
34653  argument is not matched by a case statement the processor will happily
34654  jump into Nirvana.
34655 \end_layout
34656
34657 \begin_layout Subsection
34658 Bit-shifting Operations
34659 \begin_inset LatexCommand \index{Bit shifting}
34660
34661 \end_inset
34662
34663 .
34664 \end_layout
34665
34666 \begin_layout Standard
34667 Bit shifting is one of the most frequently used operation in embedded programmin
34668 g.
34669  SDCC tries to implement bit-shift operations in the most efficient way
34670  possible, e.g.:
34671 \end_layout
34672
34673 \begin_layout Verse
34674
34675 \family typewriter
34676 unsigned char i;
34677 \newline
34678 ...
34679  
34680 \newline
34681 i >>= 4; 
34682 \newline
34683 ...
34684 \end_layout
34685
34686 \begin_layout Standard
34687 generates the following code:
34688 \end_layout
34689
34690 \begin_layout Verse
34691
34692 \family typewriter
34693 mov\InsetSpace ~
34694  a,_i 
34695 \newline
34696 swap a 
34697 \newline
34698 anl\InsetSpace ~
34699  a,#0x0f 
34700 \newline
34701 mov\InsetSpace ~
34702  _i,a
34703 \end_layout
34704
34705 \begin_layout Standard
34706 In general SDCC will never setup a loop if the shift count is known.
34707  Another example:
34708 \end_layout
34709
34710 \begin_layout Verse
34711
34712 \family typewriter
34713 unsigned int i; 
34714 \newline
34715 ...
34716  
34717 \newline
34718 i >>= 9; 
34719 \newline
34720 ...
34721 \end_layout
34722
34723 \begin_layout Standard
34724 will generate:
34725 \end_layout
34726
34727 \begin_layout Verse
34728
34729 \family typewriter
34730 mov\InsetSpace ~
34731 \InsetSpace ~
34732 a,(_i + 1) 
34733 \newline
34734 mov\InsetSpace ~
34735 \InsetSpace ~
34736 (_i + 1),#0x00 
34737 \newline
34738 clr\InsetSpace ~
34739 \InsetSpace ~
34740
34741 \newline
34742 rrc\InsetSpace ~
34743 \InsetSpace ~
34744
34745 \newline
34746 mov\InsetSpace ~
34747 \InsetSpace ~
34748 _i,a
34749 \end_layout
34750
34751 \begin_layout Subsection
34752 Bit-rotation
34753 \begin_inset LatexCommand \index{Bit rotation}
34754
34755 \end_inset
34756
34757
34758 \end_layout
34759
34760 \begin_layout Standard
34761 A special case of the bit-shift operation is bit rotation
34762 \begin_inset LatexCommand \index{rotating bits}
34763
34764 \end_inset
34765
34766 , SDCC recognizes the following expression to be a left bit-rotation:
34767 \end_layout
34768
34769 \begin_layout Verse
34770
34771 \family typewriter
34772 \series bold
34773 unsigned
34774 \series default
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 char i;\InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 /* unsigned is needed for rotation */ 
34789 \newline
34790 ...
34791  
34792 \newline
34793 i = ((i << 1) | (i >> 7)); 
34794 \family default
34795
34796 \newline
34797
34798 \family typewriter
34799 ...
34800 \end_layout
34801
34802 \begin_layout Standard
34803 will generate the following code:
34804 \end_layout
34805
34806 \begin_layout Verse
34807
34808 \family typewriter
34809 mov\InsetSpace ~
34810 \InsetSpace ~
34811 a,_i 
34812 \newline
34813 rl\InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816
34817 \newline
34818 mov\InsetSpace ~
34819 \InsetSpace ~
34820 _i,a
34821 \end_layout
34822
34823 \begin_layout Standard
34824 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34825 ns of this case will also be recognized as bit-rotation, i.e.: 
34826 \end_layout
34827
34828 \begin_layout Verse
34829
34830 \family typewriter
34831 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34832 \end_layout
34833
34834 \begin_layout Subsection
34835 Nibble and Byte Swapping
34836 \end_layout
34837
34838 \begin_layout Standard
34839 Other special cases of the bit-shift operations are nibble or byte swapping
34840 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34841
34842 \end_inset
34843
34844 , SDCC recognizes the following expressions:
34845 \end_layout
34846
34847 \begin_layout Verse
34848
34849 \family typewriter
34850 \series bold
34851 unsigned
34852 \series default
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 char i; 
34856 \newline
34857
34858 \series bold
34859 unsigned
34860 \series default
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 int j; 
34864 \newline
34865 ...
34866  
34867 \newline
34868 i = ((i << 4) | (i >> 4)); 
34869 \family default
34870
34871 \newline
34872
34873 \family typewriter
34874 j = ((j << 8) | (j >> 8)); 
34875 \end_layout
34876
34877 \begin_layout Standard
34878 and generates a swap instruction for the nibble swapping
34879 \begin_inset LatexCommand \index{Nibble swapping}
34880
34881 \end_inset
34882
34883  or move instructions for the byte swapping
34884 \begin_inset LatexCommand \index{Byte swapping}
34885
34886 \end_inset
34887
34888 .
34889  The 
34890 \begin_inset Quotes sld
34891 \end_inset
34892
34893 j
34894 \begin_inset Quotes srd
34895 \end_inset
34896
34897  example can be used to convert from little to big-endian or vice versa.
34898  If you want to change the endianness of a 
34899 \emph on
34900 signed
34901 \emph default
34902  integer you have to cast to 
34903 \family typewriter
34904 (unsigned int)
34905 \family default
34906  first.
34907 \end_layout
34908
34909 \begin_layout Standard
34910 Note that SDCC stores numbers in little-endian
34911 \begin_inset Foot
34912 status open
34913
34914 \begin_layout Standard
34915 Usually 8-bit processors don't care much about endianness.
34916  This is not the case for the standard 8051 which only has an instruction
34917  to increment its 
34918 \emph on
34919 dptr
34920 \emph default
34921
34922 \begin_inset LatexCommand \index{DPTR}
34923
34924 \end_inset
34925
34926 -datapointer
34927 \emph on
34928  
34929 \emph default
34930 so little-endian is the more efficient byte order.
34931 \end_layout
34932
34933 \end_inset
34934
34935
34936 \begin_inset LatexCommand \index{little-endian}
34937
34938 \end_inset
34939
34940
34941 \begin_inset LatexCommand \index{Endianness}
34942
34943 \end_inset
34944
34945  format (i.e.
34946  lowest order first).
34947 \end_layout
34948
34949 \begin_layout Subsection
34950 Highest Order Bit
34951 \begin_inset LatexCommand \index{Highest Order Bit}
34952
34953 \end_inset
34954
34955  / Any Order Bit
34956 \begin_inset LatexCommand \index{Any Order Bit}
34957
34958 \end_inset
34959
34960
34961 \end_layout
34962
34963 \begin_layout Standard
34964 It is frequently required to obtain the highest order bit of an integral
34965  type (long, int, short or char types).
34966  Also obtaining any other order bit is not uncommon.
34967  SDCC recognizes the following expressions to yield the highest order bit
34968  and generates optimized code for it, e.g.:
34969 \end_layout
34970
34971 \begin_layout Verse
34972
34973 \family typewriter
34974 unsigned int gint; 
34975 \newline
34976
34977 \newline
34978 foo () { 
34979 \newline
34980 \InsetSpace ~
34981 \InsetSpace ~
34982 unsigned char hob1, aob1; 
34983 \newline
34984 \InsetSpace ~
34985 \InsetSpace ~
34986 bit hob2, hob3, aob2,
34987  aob3; 
34988 \newline
34989 \InsetSpace ~
34990 \InsetSpace ~
34991 ...
34992  
34993 \newline
34994 \InsetSpace ~
34995 \InsetSpace ~
34996 hob1 = (gint >> 15) & 1; 
34997 \newline
34998 \InsetSpace ~
34999 \InsetSpace ~
35000 hob2 = (gint >> 15) & 1; 
35001 \newline
35002 \InsetSpace ~
35003 \InsetSpace ~
35004 hob3 = gint & 0x8000;
35005  
35006 \newline
35007 \InsetSpace ~
35008 \InsetSpace ~
35009 aob1 = (gint >> 9) & 1; 
35010 \newline
35011 \InsetSpace ~
35012 \InsetSpace ~
35013 aob2 = (gint >> 8) & 1; 
35014 \newline
35015 \InsetSpace ~
35016 \InsetSpace ~
35017 aob3 = gint & 0x0800; 
35018 \newline
35019 \InsetSpace ~
35020 \InsetSpace ~
35021 ..
35022  
35023 \newline
35024 }
35025 \end_layout
35026
35027 \begin_layout Standard
35028 will generate the following code:
35029 \end_layout
35030
35031 \begin_layout Verse
35032
35033 \family typewriter
35034 \InsetSpace ~
35035 \InsetSpace ~
35036 \InsetSpace ~
35037 \InsetSpace ~
35038 \InsetSpace ~
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 \InsetSpace ~
35042 \InsetSpace ~
35043 \InsetSpace ~
35044 \InsetSpace ~
35045 \InsetSpace ~
35046 \InsetSpace ~
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 \InsetSpace ~
35050 \InsetSpace ~
35051 \InsetSpace ~
35052 \InsetSpace ~
35053 \InsetSpace ~
35054 \InsetSpace ~
35055 \InsetSpace ~
35056 \InsetSpace ~
35057 \InsetSpace ~
35058 \InsetSpace ~
35059  61 ;\InsetSpace ~
35060  hob.c 7 
35061 \newline
35062 000A E5*01\InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 \InsetSpace ~
35069 \InsetSpace ~
35070 \InsetSpace ~
35071 \InsetSpace ~
35072 \InsetSpace ~
35073 \InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077  62\InsetSpace ~
35078 \InsetSpace ~
35079 \InsetSpace ~
35080 \InsetSpace ~
35081 \InsetSpace ~
35082 \InsetSpace ~
35083 \InsetSpace ~
35084 \InsetSpace ~
35085  mov\InsetSpace ~
35086 \InsetSpace ~
35087  a,(_gint + 1) 
35088 \newline
35089 000C 23\InsetSpace ~
35090 \InsetSpace ~
35091 \InsetSpace ~
35092 \InsetSpace ~
35093 \InsetSpace ~
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 \InsetSpace ~
35097 \InsetSpace ~
35098 \InsetSpace ~
35099 \InsetSpace ~
35100 \InsetSpace ~
35101 \InsetSpace ~
35102 \InsetSpace ~
35103 \InsetSpace ~
35104 \InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107  63\InsetSpace ~
35108 \InsetSpace ~
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 \InsetSpace ~
35112 \InsetSpace ~
35113 \InsetSpace ~
35114 \InsetSpace ~
35115  rl\InsetSpace ~
35116 \InsetSpace ~
35117 \InsetSpace ~
35118  a 
35119 \newline
35120 000D 54 01\InsetSpace ~
35121 \InsetSpace ~
35122 \InsetSpace ~
35123 \InsetSpace ~
35124 \InsetSpace ~
35125 \InsetSpace ~
35126 \InsetSpace ~
35127 \InsetSpace ~
35128 \InsetSpace ~
35129 \InsetSpace ~
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135
35136  64\InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 \InsetSpace ~
35142 \InsetSpace ~
35143 \InsetSpace ~
35144  anl\InsetSpace ~
35145 \InsetSpace ~
35146  a,#0x01 
35147 \newline
35148 000F F5*02\InsetSpace ~
35149 \InsetSpace ~
35150 \InsetSpace ~
35151 \InsetSpace ~
35152 \InsetSpace ~
35153 \InsetSpace ~
35154 \InsetSpace ~
35155 \InsetSpace ~
35156 \InsetSpace ~
35157 \InsetSpace ~
35158 \InsetSpace ~
35159 \InsetSpace ~
35160 \InsetSpace ~
35161 \InsetSpace ~
35162 \InsetSpace ~
35163  65\InsetSpace ~
35164 \InsetSpace ~
35165 \InsetSpace ~
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171  mov\InsetSpace ~
35172 \InsetSpace ~
35173  _foo_hob1_1_1,a 
35174 \newline
35175 \InsetSpace ~
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 \InsetSpace ~
35179 \InsetSpace ~
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 \InsetSpace ~
35183 \InsetSpace ~
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 \InsetSpace ~
35187 \InsetSpace ~
35188 \InsetSpace ~
35189 \InsetSpace ~
35190 \InsetSpace ~
35191 \InsetSpace ~
35192 \InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196 \InsetSpace ~
35197 \InsetSpace ~
35198 \InsetSpace ~
35199 \InsetSpace ~
35200  66 ;\InsetSpace ~
35201  hob.c 8 
35202 \newline
35203 0011 E5*01\InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209 \InsetSpace ~
35210 \InsetSpace ~
35211 \InsetSpace ~
35212 \InsetSpace ~
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217 \InsetSpace ~
35218
35219  67\InsetSpace ~
35220 \InsetSpace ~
35221 \InsetSpace ~
35222 \InsetSpace ~
35223 \InsetSpace ~
35224 \InsetSpace ~
35225 \InsetSpace ~
35226 \InsetSpace ~
35227  mov\InsetSpace ~
35228 \InsetSpace ~
35229  a,(_gint + 1) 
35230 \newline
35231 0013 33\InsetSpace ~
35232 \InsetSpace ~
35233 \InsetSpace ~
35234 \InsetSpace ~
35235 \InsetSpace ~
35236 \InsetSpace ~
35237 \InsetSpace ~
35238 \InsetSpace ~
35239 \InsetSpace ~
35240 \InsetSpace ~
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 \InsetSpace ~
35244 \InsetSpace ~
35245 \InsetSpace ~
35246 \InsetSpace ~
35247 \InsetSpace ~
35248 \InsetSpace ~
35249  68\InsetSpace ~
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 \InsetSpace ~
35253 \InsetSpace ~
35254 \InsetSpace ~
35255 \InsetSpace ~
35256 \InsetSpace ~
35257  rlc\InsetSpace ~
35258 \InsetSpace ~
35259  a 
35260 \newline
35261 0014 92*00\InsetSpace ~
35262 \InsetSpace ~
35263 \InsetSpace ~
35264 \InsetSpace ~
35265 \InsetSpace ~
35266 \InsetSpace ~
35267 \InsetSpace ~
35268 \InsetSpace ~
35269 \InsetSpace ~
35270 \InsetSpace ~
35271 \InsetSpace ~
35272 \InsetSpace ~
35273 \InsetSpace ~
35274 \InsetSpace ~
35275 \InsetSpace ~
35276  69\InsetSpace ~
35277 \InsetSpace ~
35278 \InsetSpace ~
35279 \InsetSpace ~
35280 \InsetSpace ~
35281 \InsetSpace ~
35282 \InsetSpace ~
35283 \InsetSpace ~
35284  mov\InsetSpace ~
35285 \InsetSpace ~
35286  _foo_hob2_1_1,c
35287  
35288 \newline
35289 \InsetSpace ~
35290 \InsetSpace ~
35291 \InsetSpace ~
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 \InsetSpace ~
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 \InsetSpace ~
35301 \InsetSpace ~
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 \InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 \InsetSpace ~
35312 \InsetSpace ~
35313 \InsetSpace ~
35314  66 ;\InsetSpace ~
35315  hob.c 9 
35316 \newline
35317 0016 E5*01\InsetSpace ~
35318 \InsetSpace ~
35319 \InsetSpace ~
35320 \InsetSpace ~
35321 \InsetSpace ~
35322 \InsetSpace ~
35323 \InsetSpace ~
35324 \InsetSpace ~
35325 \InsetSpace ~
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 \InsetSpace ~
35329 \InsetSpace ~
35330 \InsetSpace ~
35331 \InsetSpace ~
35332  67\InsetSpace ~
35333 \InsetSpace ~
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 \InsetSpace ~
35339 \InsetSpace ~
35340  mov\InsetSpace ~
35341 \InsetSpace ~
35342  a,(_gint + 1) 
35343 \newline
35344 0018 33\InsetSpace ~
35345 \InsetSpace ~
35346 \InsetSpace ~
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 \InsetSpace ~
35350 \InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362  68\InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 \InsetSpace ~
35370  rlc\InsetSpace ~
35371 \InsetSpace ~
35372  a 
35373 \newline
35374 0019 92*01\InsetSpace ~
35375 \InsetSpace ~
35376 \InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 \InsetSpace ~
35380 \InsetSpace ~
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 \InsetSpace ~
35389
35390  69\InsetSpace ~
35391 \InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398  mov\InsetSpace ~
35399 \InsetSpace ~
35400  _foo_hob3_1_1,c 
35401 \newline
35402 \InsetSpace ~
35403 \InsetSpace ~
35404 \InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427  70 ;\InsetSpace ~
35428  hob.c 10 
35429 \newline
35430 001B E5*01\InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445  71\InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453  mov\InsetSpace ~
35454 \InsetSpace ~
35455  a,(_gint + 1) 
35456 \newline
35457 001D
35458  03\InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473 \InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476  72\InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482 \InsetSpace ~
35483 \InsetSpace ~
35484  rr\InsetSpace ~
35485 \InsetSpace ~
35486 \InsetSpace ~
35487  a 
35488 \newline
35489 001E 54 01\InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504  73\InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512  anl\InsetSpace ~
35513 \InsetSpace ~
35514  a,#0x01 
35515 \newline
35516 0020 F5*03\InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523 \InsetSpace ~
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531  74\InsetSpace ~
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539  mov\InsetSpace ~
35540 \InsetSpace ~
35541  _foo_aob1_1_1,a
35542  
35543 \newline
35544 \InsetSpace ~
35545 \InsetSpace ~
35546 \InsetSpace ~
35547 \InsetSpace ~
35548 \InsetSpace ~
35549 \InsetSpace ~
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569  75 ;\InsetSpace ~
35570  hob.c 11 
35571 \newline
35572 0022 E5*01\InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579 \InsetSpace ~
35580 \InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587  76\InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595  mov\InsetSpace ~
35596 \InsetSpace ~
35597  a,(_gint + 1) 
35598 \newline
35599 0024 13\InsetSpace ~
35600 \InsetSpace ~
35601 \InsetSpace ~
35602 \InsetSpace ~
35603 \InsetSpace ~
35604 \InsetSpace ~
35605 \InsetSpace ~
35606 \InsetSpace ~
35607 \InsetSpace ~
35608 \InsetSpace ~
35609 \InsetSpace ~
35610 \InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613 \InsetSpace ~
35614 \InsetSpace ~
35615 \InsetSpace ~
35616 \InsetSpace ~
35617  77\InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625  rrc\InsetSpace ~
35626 \InsetSpace ~
35627  a 
35628 \newline
35629 0025 92*02\InsetSpace ~
35630 \InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637 \InsetSpace ~
35638 \InsetSpace ~
35639 \InsetSpace ~
35640 \InsetSpace ~
35641 \InsetSpace ~
35642 \InsetSpace ~
35643 \InsetSpace ~
35644
35645  78\InsetSpace ~
35646 \InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653  mov\InsetSpace ~
35654 \InsetSpace ~
35655  _foo_aob2_1_1,c 
35656 \newline
35657 \InsetSpace ~
35658 \InsetSpace ~
35659 \InsetSpace ~
35660 \InsetSpace ~
35661 \InsetSpace ~
35662 \InsetSpace ~
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672 \InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682  79 ;\InsetSpace ~
35683  hob.c 12 
35684 \newline
35685 0027 E5*01\InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700  80\InsetSpace ~
35701 \InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708  mov\InsetSpace ~
35709 \InsetSpace ~
35710  a,(_gint + 1) 
35711 \newline
35712 0029
35713  A2 E3\InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716 \InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727 \InsetSpace ~
35728  81\InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736  mov\InsetSpace ~
35737 \InsetSpace ~
35738  c,acc[3] 
35739 \newline
35740 002B 92*03\InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743 \InsetSpace ~
35744 \InsetSpace ~
35745 \InsetSpace ~
35746 \InsetSpace ~
35747 \InsetSpace ~
35748 \InsetSpace ~
35749 \InsetSpace ~
35750 \InsetSpace ~
35751 \InsetSpace ~
35752 \InsetSpace ~
35753 \InsetSpace ~
35754 \InsetSpace ~
35755  82\InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760 \InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763  mov\InsetSpace ~
35764 \InsetSpace ~
35765  _foo_aob3_1_1,c 
35766 \end_layout
35767
35768 \begin_layout Standard
35769 Other variations of these cases however will 
35770 \emph on
35771 not
35772 \emph default
35773  be recognized.
35774  They are standard C expressions, so I heartily recommend these be the only
35775  way to get the highest order bit, (it is portable).
35776  Of course it will be recognized even if it is embedded in other expressions,
35777  e.g.:
35778 \end_layout
35779
35780 \begin_layout Verse
35781
35782 \family typewriter
35783 xyz = gint + ((gint >> 15) & 1);
35784 \end_layout
35785
35786 \begin_layout Standard
35787 will still be recognized.
35788 \end_layout
35789
35790 \begin_layout Subsection
35791 Higher Order Byte
35792 \begin_inset LatexCommand \index{Higher Order Byte}
35793
35794 \end_inset
35795
35796  / Higher Order Word
35797 \begin_inset LatexCommand \index{Higher Order Word}
35798
35799 \end_inset
35800
35801
35802 \end_layout
35803
35804 \begin_layout Standard
35805 It is also frequently required to obtain a higher order byte or word of
35806  a larger integral type (long, int or short types).
35807  SDCC recognizes the following expressions to yield the higher order byte
35808  or word and generates optimized code for it, e.g.:
35809 \end_layout
35810
35811 \begin_layout Verse
35812
35813 \family typewriter
35814 unsigned int gint; 
35815 \newline
35816 unsigned long int glong; 
35817 \newline
35818
35819 \newline
35820 foo () { 
35821 \newline
35822 \InsetSpace ~
35823 \InsetSpace ~
35824 unsigned char hob1,
35825  hob2; 
35826 \newline
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 unsigned int how1, how2; 
35830 \newline
35831 \InsetSpace ~
35832 \InsetSpace ~
35833 ...
35834  
35835 \newline
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 hob1 = (gint >> 8) & 0xFF; 
35839 \newline
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 hob2 = glong >> 24; 
35843 \newline
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 how1 = (glong >> 16) & 0xFFFF;
35847  
35848 \newline
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 how2 = glong >> 8; 
35852 \newline
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 ..
35856  
35857 \newline
35858 }
35859 \end_layout
35860
35861 \begin_layout Standard
35862 will generate the following code:
35863 \end_layout
35864
35865 \begin_layout Verse
35866
35867 \family typewriter
35868 \InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893  91 ;\InsetSpace ~
35894  hob.c 15 
35895 \newline
35896 0037 85*01*06\InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908  92\InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916  mov\InsetSpace ~
35917 \InsetSpace ~
35918  _foo_hob1_1_1,(_gint + 1) 
35919 \newline
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944 \InsetSpace ~
35945  93 ;\InsetSpace ~
35946  hob.c
35947  16 
35948 \newline
35949 003A 85*05*07\InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961  94\InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969  mov\InsetSpace ~
35970 \InsetSpace ~
35971  _foo_hob2_1_1,(_glong + 3) 
35972 \newline
35973 \InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997 \InsetSpace ~
35998  95 ;\InsetSpace ~
35999  hob.c 17 
36000 \newline
36001 003D 85*04*08\InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013
36014  96\InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022  mov\InsetSpace ~
36023 \InsetSpace ~
36024  _foo_how1_1_1,(_glong + 2) 
36025 \newline
36026 0040 85*05*09\InsetSpace ~
36027 \InsetSpace ~
36028 \InsetSpace ~
36029 \InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038  97\InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046  mov\InsetSpace ~
36047 \InsetSpace ~
36048  (_foo_how1_1_1 +
36049  1),(_glong + 3) 
36050 \newline
36051 0043 85*03*0A\InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 \InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063  98\InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070 \InsetSpace ~
36071  mov\InsetSpace ~
36072 \InsetSpace ~
36073  _foo_how2_1_1,(_glong + 1) 
36074 \newline
36075 0046 85*04*0B\InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 \InsetSpace ~
36086 \InsetSpace ~
36087
36088  99\InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096  mov\InsetSpace ~
36097 \InsetSpace ~
36098  (_foo_how2_1_1 + 1),(_glong + 2) 
36099 \end_layout
36100
36101 \begin_layout Standard
36102 Again, variations of these cases may 
36103 \emph on
36104 not
36105 \emph default
36106  be recognized.
36107  They are standard C expressions, so I heartily recommend these be the only
36108  way to get the higher order byte/word, (it is portable).
36109  Of course it will be recognized even if it is embedded in other expressions,
36110  e.g.:
36111 \end_layout
36112
36113 \begin_layout Verse
36114
36115 \family typewriter
36116 xyz = gint + ((gint >> 8) & 0xFF);
36117 \end_layout
36118
36119 \begin_layout Standard
36120 will still be recognized.
36121 \end_layout
36122
36123 \begin_layout Subsection
36124 Peephole Optimizer
36125 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36126
36127 \end_inset
36128
36129
36130 \begin_inset LatexCommand \index{Peephole optimizer}
36131
36132 \end_inset
36133
36134
36135 \end_layout
36136
36137 \begin_layout Standard
36138 The compiler uses a rule based, pattern matching and re-writing mechanism
36139  for peep-hole optimization.
36140  It is inspired by 
36141 \emph on
36142 copt
36143 \emph default
36144  a peep-hole optimizer by Christopher W.
36145  Fraser (cwfraser\InsetSpace ~
36146 @\InsetSpace ~
36147 microsoft.com).
36148  A default set of rules are compiled into the compiler, additional rules
36149  may be added with the 
36150 \emph on
36151 -
36152 \begin_inset ERT
36153 status collapsed
36154
36155 \begin_layout Standard
36156
36157
36158 \backslash
36159 /
36160 \end_layout
36161
36162 \end_inset
36163
36164 -peep-file
36165 \begin_inset LatexCommand \index{-\/-peep-file}
36166
36167 \end_inset
36168
36169  <filename>
36170 \emph default
36171  option.
36172  The rule language is best illustrated with examples.
36173 \end_layout
36174
36175 \begin_layout Verse
36176
36177 \family typewriter
36178 replace { 
36179 \newline
36180 \InsetSpace ~
36181 \InsetSpace ~
36182 mov %1,a 
36183 \newline
36184 \InsetSpace ~
36185 \InsetSpace ~
36186 mov a,%1
36187 \newline
36188 } by {
36189 \newline
36190 \InsetSpace ~
36191 \InsetSpace ~
36192 mov %1,a
36193 \newline
36194 }
36195 \end_layout
36196
36197 \begin_layout Standard
36198 The above rule will change the following assembly
36199 \begin_inset LatexCommand \index{Assembler routines}
36200
36201 \end_inset
36202
36203  sequence:
36204 \end_layout
36205
36206 \begin_layout Verse
36207
36208 \family typewriter
36209 mov r1,a 
36210 \newline
36211 mov a,r1
36212 \end_layout
36213
36214 \begin_layout Standard
36215 to
36216 \end_layout
36217
36218 \begin_layout Verse
36219
36220 \family typewriter
36221 mov r1,a
36222 \end_layout
36223
36224 \begin_layout Standard
36225 Note: All occurrences of a 
36226 \emph on
36227 %n
36228 \emph default
36229  (pattern variable) must denote the same string.
36230  With the above rule, the assembly sequence:
36231 \end_layout
36232
36233 \begin_layout Verse
36234
36235 \family typewriter
36236 mov r1,a 
36237 \newline
36238 mov a,r2
36239 \end_layout
36240
36241 \begin_layout Standard
36242 will remain unmodified.
36243 \newline
36244
36245 \newline
36246 Other special case optimizations may be added by the
36247  user (via 
36248 \emph on
36249 -
36250 \begin_inset ERT
36251 status collapsed
36252
36253 \begin_layout Standard
36254
36255
36256 \backslash
36257 /
36258 \end_layout
36259
36260 \end_inset
36261
36262 -peep-file option
36263 \emph default
36264 ).
36265  E.g.
36266  some variants of the 8051 MCU
36267 \begin_inset LatexCommand \index{MCS51 variants}
36268
36269 \end_inset
36270
36271  allow only 
36272 \family typewriter
36273 ajmp
36274 \family default
36275  and 
36276 \family typewriter
36277 acall
36278 \family default
36279 .
36280  The following two rules will change all 
36281 \family typewriter
36282 ljmp
36283 \family default
36284  and 
36285 \family typewriter
36286 lcall
36287 \family default
36288  to 
36289 \family typewriter
36290 ajmp
36291 \family default
36292  and 
36293 \family typewriter
36294 acall
36295 \end_layout
36296
36297 \begin_layout Verse
36298
36299 \family typewriter
36300 replace { lcall %1 } by { acall %1 } 
36301 \newline
36302 replace { ljmp %1 } by { ajmp %1 }
36303 \end_layout
36304
36305 \begin_layout Standard
36306 (NOTE: from version 2.7.3 on, you can use option -
36307 \emph on
36308
36309 \begin_inset ERT
36310 status collapsed
36311
36312 \begin_layout Standard
36313
36314
36315 \backslash
36316 /
36317 \end_layout
36318
36319 \end_inset
36320
36321
36322 \emph default
36323 -acall-ajmp
36324 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36325
36326 \end_inset
36327
36328 , which also takes care of aligning the interrupt vectors properly.)
36329 \newline
36330
36331 \end_layout
36332
36333 \begin_layout Standard
36334 The 
36335 \emph on
36336 inline-assembler code
36337 \emph default
36338  is also passed through the peep hole optimizer, thus the peephole optimizer
36339  can also be used as an assembly level macro expander.
36340  The rules themselves are MCU dependent whereas the rule language infra-structur
36341 e is MCU independent.
36342  Peephole optimization rules for other MCU can be easily programmed using
36343  the rule language.
36344 \newline
36345
36346 \newline
36347 The syntax for a rule is as follows:
36348 \end_layout
36349
36350 \begin_layout Verse
36351
36352 \family typewriter
36353 rule := replace [ restart ] '{' <assembly sequence> '
36354 \backslash
36355 n' 
36356 \newline
36357 \InsetSpace ~
36358  \InsetSpace ~
36359  \InsetSpace ~
36360  \InsetSpace ~
36361  \InsetSpace ~
36362  \InsetSpace ~
36363  \InsetSpace ~
36364  \InsetSpace ~
36365  \InsetSpace ~
36366  \InsetSpace ~
36367  \InsetSpace ~
36368  \InsetSpace ~
36369  \InsetSpace ~
36370  \InsetSpace ~
36371  '}' by '{' '
36372 \backslash
36373 n' 
36374 \newline
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  <assembly sequence> '
36392 \backslash
36393 n' 
36394 \newline
36395 \InsetSpace ~
36396  \InsetSpace ~
36397  \InsetSpace ~
36398  \InsetSpace ~
36399  \InsetSpace ~
36400  \InsetSpace ~
36401  \InsetSpace ~
36402  \InsetSpace ~
36403  \InsetSpace ~
36404  \InsetSpace ~
36405  \InsetSpace ~
36406  \InsetSpace ~
36407  \InsetSpace ~
36408  \InsetSpace ~
36409  '}' [if <functionName> ] '
36410 \backslash
36411 n' 
36412 \end_layout
36413
36414 \begin_layout Standard
36415 <assembly sequence> := assembly instruction (each instruction including
36416  labels must be on a separate line).
36417 \newline
36418
36419 \newline
36420 The optimizer will apply to the rules
36421  one by one from the top in the sequence of their appearance, it will terminate
36422  when all rules are exhausted.
36423  If the 'restart' option is specified, then the optimizer will start matching
36424  the rules again from the top, this option for a rule is expensive (performance)
36425 , it is intended to be used in situations where a transformation will trigger
36426  the same rule again.
36427  An example of this (not a good one, it has side effects) is the following
36428  rule:
36429 \end_layout
36430
36431 \begin_layout Verse
36432
36433 \family typewriter
36434 replace restart { 
36435 \newline
36436 \InsetSpace ~
36437 \InsetSpace ~
36438 pop %1 
36439 \newline
36440 \InsetSpace ~
36441 \InsetSpace ~
36442 push %1 } by { 
36443 \newline
36444 \InsetSpace ~
36445 \InsetSpace ~
36446 ; nop 
36447 \newline
36448 }
36449 \end_layout
36450
36451 \begin_layout Standard
36452 Note that the replace pattern cannot be a blank, but can be a comment line.
36453  Without the 'restart' option only the innermost 'pop' 'push' pair would
36454  be eliminated, i.e.:
36455 \end_layout
36456
36457 \begin_layout Verse
36458
36459 \family typewriter
36460 pop ar1 
36461 \newline
36462 pop ar2 
36463 \newline
36464 push ar2 
36465 \newline
36466 push ar1
36467 \end_layout
36468
36469 \begin_layout Standard
36470 would result in:
36471 \end_layout
36472
36473 \begin_layout Verse
36474
36475 \family typewriter
36476 pop ar1 
36477 \newline
36478 ; nop 
36479 \newline
36480 push ar1
36481 \end_layout
36482
36483 \begin_layout Standard
36484
36485 \emph on
36486 with
36487 \emph default
36488  the restart option the rule will be applied again to the resulting code
36489  and then all the pop-push pairs will be eliminated to yield:
36490 \end_layout
36491
36492 \begin_layout Verse
36493
36494 \family typewriter
36495 ; nop 
36496 \newline
36497 ; nop
36498 \end_layout
36499
36500 \begin_layout Standard
36501 A conditional function can be attached to a rule.
36502  Attaching rules are somewhat more involved, let me illustrate this with
36503  an example.
36504 \end_layout
36505
36506 \begin_layout Verse
36507
36508 \family typewriter
36509 replace { 
36510 \newline
36511 \InsetSpace ~
36512  \InsetSpace ~
36513  \InsetSpace ~
36514 ljmp %5 
36515 \newline
36516 %2:
36517 \newline
36518 } by { 
36519 \newline
36520 \InsetSpace ~
36521  \InsetSpace ~
36522  \InsetSpace ~
36523 sjmp %5 
36524 \newline
36525 %2:
36526 \newline
36527 } if labelInRange
36528 \end_layout
36529
36530 \begin_layout Standard
36531 The optimizer does a look-up of a function name table defined in function
36532  
36533 \emph on
36534 callFuncByName
36535 \emph default
36536  in the source file SDCCpeeph.c, with the name 
36537 \emph on
36538 labelInRange
36539 \emph default
36540 .
36541  If it finds a corresponding entry the function is called.
36542  Note there can be no parameters specified for these functions, in this
36543  case the use of 
36544 \emph on
36545 %5
36546 \emph default
36547  is crucial, since the function 
36548 \emph on
36549 labelInRange
36550 \emph default
36551  expects to find the label in that particular variable (the hash table containin
36552 g the variable bindings is passed as a parameter).
36553  If you want to code more such functions, take a close look at the function
36554  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36555  Currently implemented are 
36556 \emph on
36557 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36558  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36559 \emph default
36560 and
36561 \emph on
36562  notVolatile
36563 \emph default
36564 .
36565 \end_layout
36566
36567 \begin_layout Standard
36568 I know this whole thing is a little kludgey, but maybe some day we will
36569  have some better means.
36570  If you are looking at this file, you will see the default rules that are
36571  compiled into the compiler, you can add your own rules in the default set
36572  there if you get tired of specifying the -
36573 \begin_inset ERT
36574 status collapsed
36575
36576 \begin_layout Standard
36577
36578
36579 \backslash
36580 /
36581 \end_layout
36582
36583 \end_inset
36584
36585 -peep-file option.
36586 \end_layout
36587
36588 \begin_layout Section
36589 ANSI-Compliance
36590 \begin_inset LatexCommand \index{ANSI-compliance}
36591
36592 \end_inset
36593
36594
36595 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36596
36597 \end_inset
36598
36599
36600 \end_layout
36601
36602 \begin_layout Standard
36603 The latest publically available version of the standard 
36604 \emph on
36605 ISO/IEC 9899 - Programming languages - C
36606 \emph default
36607  should be available at: 
36608 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36609
36610 \end_inset
36611
36612 .
36613 \newline
36614
36615 \end_layout
36616
36617 \begin_layout Standard
36618 Deviations from the compliance:
36619 \end_layout
36620
36621 \begin_layout Itemize
36622 functions are not reentrant
36623 \begin_inset LatexCommand \index{reentrant}
36624
36625 \end_inset
36626
36627  unless explicitly declared as such or the 
36628 \series bold
36629 -
36630 \begin_inset ERT
36631 status collapsed
36632
36633 \begin_layout Standard
36634
36635
36636 \backslash
36637 /
36638 \end_layout
36639
36640 \end_inset
36641
36642 -stack-auto
36643 \begin_inset LatexCommand \index{-\/-stack-auto}
36644
36645 \end_inset
36646
36647
36648 \series default
36649  command line option is specified.
36650 \end_layout
36651
36652 \begin_layout Itemize
36653 structures
36654 \begin_inset LatexCommand \index{struct}
36655
36656 \end_inset
36657
36658  and unions
36659 \begin_inset LatexCommand \index{union}
36660
36661 \end_inset
36662
36663  cannot be assigned values directly, cannot be passed as function parameters
36664  or assigned to each other and cannot be a return value
36665 \begin_inset LatexCommand \index{return value}
36666
36667 \end_inset
36668
36669  from a function, e.g.:
36670 \end_layout
36671
36672 \begin_deeper
36673 \begin_layout Verse
36674
36675 \family typewriter
36676 struct s { ...
36677  }; 
36678 \newline
36679 struct s s1, s2; 
36680 \newline
36681 foo() 
36682 \newline
36683
36684 \newline
36685 \InsetSpace ~
36686 \InsetSpace ~
36687 \InsetSpace ~
36688 \InsetSpace ~
36689 ...
36690  
36691 \newline
36692 \InsetSpace ~
36693 \InsetSpace ~
36694 \InsetSpace ~
36695 \InsetSpace ~
36696 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36697 \newline
36698 \InsetSpace ~
36699 \InsetSpace ~
36700 \InsetSpace ~
36701 \InsetSpace ~
36702 ...
36703  
36704 \newline
36705 }
36706 \newline
36707
36708 \series bold
36709 struct
36710 \series default
36711  s foo1 (
36712 \series bold
36713 struct
36714 \series default
36715  s parms) /* invalid in SDCC although allowed in ANSI */
36716 \newline
36717
36718 \newline
36719 \InsetSpace ~
36720 \InsetSpace ~
36721 \InsetSpace ~
36722 \InsetSpace ~
36723 struct s rets;
36724  
36725 \newline
36726 \InsetSpace ~
36727 \InsetSpace ~
36728 \InsetSpace ~
36729 \InsetSpace ~
36730 ...
36731  
36732 \newline
36733 \InsetSpace ~
36734 \InsetSpace ~
36735 \InsetSpace ~
36736 \InsetSpace ~
36737 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36738 \newline
36739 }
36740 \end_layout
36741
36742 \end_deeper
36743 \begin_layout Itemize
36744 initialization of structure arrays must be fully braced.
36745 \end_layout
36746
36747 \begin_deeper
36748 \begin_layout Verse
36749
36750 \family typewriter
36751 struct s { char x } a[] = {1, 2};\InsetSpace ~
36752 \InsetSpace ~
36753 \InsetSpace ~
36754 \InsetSpace ~
36755 \InsetSpace ~
36756 /* invalid in SDCC */
36757 \newline
36758 struct s { char x
36759  } a[] = {{1}, {2}}; /* OK */
36760 \end_layout
36761
36762 \end_deeper
36763 \begin_layout Itemize
36764 'long long
36765 \begin_inset LatexCommand \index{long long (not supported)}
36766
36767 \end_inset
36768
36769 ' (64 bit integers
36770 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36771
36772 \end_inset
36773
36774 ) not supported.
36775 \end_layout
36776
36777 \begin_layout Itemize
36778 'double
36779 \begin_inset LatexCommand \index{double (not supported)}
36780
36781 \end_inset
36782
36783 ' precision floating point 
36784 \begin_inset LatexCommand \index{Floating point support}
36785
36786 \end_inset
36787
36788 not supported.
36789 \end_layout
36790
36791 \begin_layout Itemize
36792 Old K&R style
36793 \begin_inset LatexCommand \index{K\&R style}
36794
36795 \end_inset
36796
36797  function declarations are NOT allowed.
36798 \end_layout
36799
36800 \begin_deeper
36801 \begin_layout Verse
36802
36803 \family typewriter
36804 foo(i,j) /* this old style of function declarations */ 
36805 \newline
36806 int i,j; /* is valid
36807  in ANSI but not valid in SDCC */ 
36808 \newline
36809
36810 \newline
36811 \InsetSpace ~
36812 \InsetSpace ~
36813 \InsetSpace ~
36814 \InsetSpace ~
36815 ...
36816  
36817 \newline
36818 }
36819 \end_layout
36820
36821 \end_deeper
36822 \begin_layout Itemize
36823 Most enhancements in C99 are not supported, e.g.:
36824 \end_layout
36825
36826 \begin_deeper
36827 \begin_layout Verse
36828
36829 \family typewriter
36830 for (
36831 \series bold
36832 int
36833 \series default
36834  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36835 \end_layout
36836
36837 \end_deeper
36838 \begin_layout Itemize
36839 But some have been added recently in SDCC 2.7.0.
36840  They must be considered alpha quality however.
36841 \end_layout
36842
36843 \begin_deeper
36844 \begin_layout Verse
36845
36846 \family typewriter
36847 \series bold
36848 inline
36849 \begin_inset LatexCommand \index{inline (not supported)}
36850
36851 \end_inset
36852
36853
36854 \series default
36855  int increment (int a) { return a+1; } /* inlines the increment without
36856  function call overhead */
36857 \newline
36858 int * 
36859 \series bold
36860 restrict
36861 \begin_inset LatexCommand \index{inline (not supported)}
36862
36863 \end_inset
36864
36865
36866 \series default
36867  p; /* accepted but ignored */
36868 \end_layout
36869
36870 \end_deeper
36871 \begin_layout Itemize
36872 Certain words that are valid identifiers in the standard may be reserved
36873  words in SDCC unless the 
36874 \series bold
36875 -
36876 \begin_inset ERT
36877 status collapsed
36878
36879 \begin_layout Standard
36880
36881
36882 \backslash
36883 /
36884 \end_layout
36885
36886 \end_inset
36887
36888 -std-c89
36889 \begin_inset LatexCommand \index{-\/-std-c89}
36890
36891 \end_inset
36892
36893  
36894 \series default
36895 or
36896 \series bold
36897  -
36898 \begin_inset ERT
36899 status collapsed
36900
36901 \begin_layout Standard
36902
36903
36904 \backslash
36905 /
36906 \end_layout
36907
36908 \end_inset
36909
36910 -std-c99
36911 \begin_inset LatexCommand \index{-\/-std-c99}
36912
36913 \end_inset
36914
36915
36916 \series default
36917  command line options are used.
36918  These may include (depending on the selected processor): 'at', 'banked',
36919  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36920 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36921  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36922  '_naked'.
36923  Compliant equivalents of these keywords are always available in a form
36924  that begin with two underscores
36925 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36926
36927 \end_inset
36928
36929 , f.e.
36930  '__data' instead of 'data'.
36931 \end_layout
36932
36933 \begin_layout Itemize
36934 Integer promotion of variable arguments is not performed if the argument
36935  is explicitly taypecasted unless the
36936 \series bold
36937  -
36938 \begin_inset ERT
36939 status collapsed
36940
36941 \begin_layout Standard
36942
36943
36944 \backslash
36945 /
36946 \end_layout
36947
36948 \end_inset
36949
36950 -std-c89
36951 \begin_inset LatexCommand \index{-\/-std-c89}
36952
36953 \end_inset
36954
36955  
36956 \series default
36957 or
36958 \series bold
36959  -
36960 \begin_inset ERT
36961 status collapsed
36962
36963 \begin_layout Standard
36964
36965
36966 \backslash
36967 /
36968 \end_layout
36969
36970 \end_inset
36971
36972 -std-c99
36973 \begin_inset LatexCommand \index{-\/-std-c99}
36974
36975 \end_inset
36976
36977
36978 \series default
36979  command line options are used.
36980 \end_layout
36981
36982 \begin_deeper
36983 \begin_layout Verse
36984
36985 \family typewriter
36986 void vararg_func (char *str, ...) { str; }
36987 \newline
36988
36989 \newline
36990 void main (void)
36991 \newline
36992 {
36993 \newline
36994 \InsetSpace ~
36995 \InsetSpace ~
36996 char c = 10;
36997 \newline
36998
36999 \newline
37000 \InsetSpace ~
37001 \InsetSpace ~
37002 /* argument
37003  u is promoted to int before
37004 \newline
37005 \InsetSpace ~
37006 \InsetSpace ~
37007 \InsetSpace ~
37008 * passing to function */
37009 \newline
37010 \InsetSpace ~
37011 \InsetSpace ~
37012 vararg_func ("%c", c);
37013 \newline
37014
37015 \newline
37016 \InsetSpace ~
37017 \InsetSpace ~
37018 /*
37019  argument u is not promoted to int,
37020 \newline
37021 \InsetSpace ~
37022 \InsetSpace ~
37023 \InsetSpace ~
37024 * it is passed as char to function
37025 \newline
37026 \InsetSpace ~
37027 \InsetSpace ~
37028 \InsetSpace ~
37029 * if
37030  --std-cXX is not defined;
37031 \newline
37032 \InsetSpace ~
37033 \InsetSpace ~
37034 \InsetSpace ~
37035 * is promoted to int before passing
37036 \newline
37037 \InsetSpace ~
37038 \InsetSpace ~
37039 \InsetSpace ~
37040 * to function
37041  if --std-cXX is defined */
37042 \newline
37043 \InsetSpace ~
37044 \InsetSpace ~
37045 vararg_func ("%bc", (char)u);
37046 \newline
37047 }
37048 \end_layout
37049
37050 \end_deeper
37051 \begin_layout Section
37052 Cyclomatic Complexity
37053 \begin_inset LatexCommand \index{Cyclomatic complexity}
37054
37055 \end_inset
37056
37057
37058 \end_layout
37059
37060 \begin_layout Standard
37061 Cyclomatic complexity of a function is defined as the number of independent
37062  paths the program can take during execution of the function.
37063  This is an important number since it defines the number test cases you
37064  have to generate to validate the function.
37065  The accepted industry standard for complexity number is 10, if the cyclomatic
37066  complexity reported by SDCC exceeds 10 you should think about simplification
37067  of the function logic.
37068  Note that the complexity level is not related to the number of lines of
37069  code in a function.
37070  Large functions can have low complexity, and small functions can have large
37071  complexity levels.
37072  
37073 \newline
37074
37075 \newline
37076 SDCC uses the following formula to compute the complexity:
37077 \newline
37078
37079 \end_layout
37080
37081 \begin_layout Standard
37082 complexity = (number of edges in control flow graph) - (number of nodes
37083  in control flow graph) + 2;
37084 \newline
37085
37086 \newline
37087 Having said that the industry standard is 10,
37088  you should be aware that in some cases it be may unavoidable to have a
37089  complexity level of less than 10.
37090  For example if you have switch statement with more than 10 case labels,
37091  each case label adds one to the complexity level.
37092  The complexity level is by no means an absolute measure of the algorithmic
37093  complexity of the function, it does however provide a good starting point
37094  for which functions you might look at for further optimization.
37095 \end_layout
37096
37097 \begin_layout Section
37098 Retargetting for other Processors
37099 \end_layout
37100
37101 \begin_layout Standard
37102 The issues for retargetting the compiler are far too numerous to be covered
37103  by this document.
37104  What follows is a brief description of each of the seven phases of the
37105  compiler and its MCU dependency.
37106 \end_layout
37107
37108 \begin_layout Itemize
37109 Parsing the source and building the annotated parse tree.
37110  This phase is largely MCU independent (except for the language extensions).
37111  Syntax & semantic checks are also done in this phase, along with some initial
37112  optimizations like back patching labels and the pattern matching optimizations
37113  like bit-rotation etc.
37114 \end_layout
37115
37116 \begin_layout Itemize
37117 The second phase involves generating an intermediate code which can be easy
37118  manipulated during the later phases.
37119  This phase is entirely MCU independent.
37120  The intermediate code generation assumes the target machine has unlimited
37121  number of registers, and designates them with the name iTemp.
37122  The compiler can be made to dump a human readable form of the code generated
37123  by using the -
37124 \begin_inset ERT
37125 status collapsed
37126
37127 \begin_layout Standard
37128
37129
37130 \backslash
37131 /
37132 \end_layout
37133
37134 \end_inset
37135
37136 -dumpraw option.
37137 \end_layout
37138
37139 \begin_layout Itemize
37140 This phase does the bulk of the standard optimizations and is also MCU independe
37141 nt.
37142  This phase can be broken down into several sub-phases:
37143 \newline
37144
37145 \newline
37146 Break down intermediate
37147  code (iCode) into basic blocks.
37148 \newline
37149 Do control flow & data flow analysis on the
37150  basic blocks.
37151 \newline
37152 Do local common subexpression elimination, then global subexpressio
37153 n elimination
37154 \newline
37155 Dead code elimination
37156 \newline
37157 Loop optimizations
37158 \newline
37159 If loop optimizations
37160  caused any changes then do 'global subexpression elimination' and 'dead
37161  code elimination' again.
37162 \end_layout
37163
37164 \begin_layout Itemize
37165 This phase determines the live-ranges; by live range I mean those iTemp
37166  variables defined by the compiler that still survive after all the optimization
37167 s.
37168  Live range analysis
37169 \begin_inset LatexCommand \index{Live range analysis}
37170
37171 \end_inset
37172
37173  is essential for register allocation, since these computation determines
37174  which of these iTemps will be assigned to registers, and for how long.
37175 \end_layout
37176
37177 \begin_layout Itemize
37178 Phase five is register allocation.
37179  There are two parts to this process.
37180 \newline
37181
37182 \newline
37183 The first part I call 'register packing'
37184  (for lack of a better term).
37185  In this case several MCU specific expression folding is done to reduce
37186  register pressure.
37187 \newline
37188
37189 \newline
37190 The second part is more MCU independent and deals with
37191  allocating registers to the remaining live ranges.
37192  A lot of MCU specific code does creep into this phase because of the limited
37193  number of index registers available in the 8051.
37194 \end_layout
37195
37196 \begin_layout Itemize
37197 The Code generation phase is (unhappily), entirely MCU dependent and very
37198  little (if any at all) of this code can be reused for other MCU.
37199  However the scheme for allocating a homogenized assembler operand for each
37200  iCode operand may be reused.
37201 \end_layout
37202
37203 \begin_layout Itemize
37204 As mentioned in the optimization section the peep-hole optimizer is rule
37205  based system, which can reprogrammed for other MCUs.
37206 \end_layout
37207
37208 \begin_layout Standard
37209 More information is available on SDCC Wiki
37210 \begin_inset LatexCommand \index{wiki}
37211
37212 \end_inset
37213
37214  (preliminary link 
37215 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37216
37217 \end_inset
37218
37219 ) and in the thread 
37220 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37221
37222 \end_inset
37223
37224  .
37225 \end_layout
37226
37227 \begin_layout Chapter
37228 Compiler internals
37229 \begin_inset LatexCommand \index{Compiler internals}
37230
37231 \end_inset
37232
37233
37234 \end_layout
37235
37236 \begin_layout Section
37237 The anatomy of the compiler
37238 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37239
37240 \end_inset
37241
37242
37243 \end_layout
37244
37245 \begin_layout Standard
37246
37247 \shape italic
37248 This is an excerpt from an article published in Circuit Cellar Magazine
37249  in 
37250 \series bold
37251 August 2000
37252 \series default
37253 .
37254  It's a little outdated (the compiler is much more efficient now and user/develo
37255 per friendly), but pretty well exposes the guts of it all.
37256 \shape default
37257
37258 \newline
37259
37260 \newline
37261 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37262  It is fairly easy to retarget for other 8-bit MCU.
37263  Here we take a look at some of the internals of the compiler.
37264  
37265 \end_layout
37266
37267 \begin_layout Paragraph*
37268 Parsing
37269 \begin_inset LatexCommand \index{Parsing}
37270
37271 \end_inset
37272
37273  
37274 \end_layout
37275
37276 \begin_layout Standard
37277 Parsing the input source file and creating an AST (Annotated Syntax Tree
37278 \begin_inset LatexCommand \index{Annotated syntax tree}
37279
37280 \end_inset
37281
37282 ).
37283  This phase also involves propagating types (annotating each node of the
37284  parse tree with type information) and semantic analysis.
37285  There are some MCU specific parsing rules.
37286  For example the storage classes, the extended storage classes are MCU specific
37287  while there may be a xdata storage class for 8051 there is no such storage
37288  class for z80 or Atmel AVR.
37289  SDCC allows MCU specific storage class extensions, i.e.
37290  xdata will be treated as a storage class specifier when parsing 8051 C
37291  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37292  C code.
37293 \end_layout
37294
37295 \begin_layout Paragraph*
37296 Generating iCode
37297 \begin_inset LatexCommand \index{iCode}
37298
37299 \end_inset
37300
37301
37302 \end_layout
37303
37304 \begin_layout Standard
37305 Intermediate code generation.
37306  In this phase the AST is broken down into three-operand form (iCode).
37307  These three operand forms are represented as doubly linked lists.
37308  ICode is the term given to the intermediate form generated by the compiler.
37309  ICode example section shows some examples of iCode generated for some simple
37310  C source functions.
37311 \end_layout
37312
37313 \begin_layout Paragraph*
37314 Optimizations
37315 \begin_inset LatexCommand \index{Optimizations}
37316
37317 \end_inset
37318
37319 .
37320 \end_layout
37321
37322 \begin_layout Standard
37323 Bulk of the target independent optimizations is performed in this phase.
37324  The optimizations include constant propagation, common sub-expression eliminati
37325 on, loop invariant code movement, strength reduction of loop induction variables
37326  and dead-code elimination.
37327 \end_layout
37328
37329 \begin_layout Paragraph*
37330 Live range analysis
37331 \begin_inset LatexCommand \index{Live range analysis}
37332
37333 \end_inset
37334
37335
37336 \end_layout
37337
37338 \begin_layout Standard
37339 During intermediate code generation phase, the compiler assumes the target
37340  machine has infinite number of registers and generates a lot of temporary
37341  variables.
37342  The live range computation determines the lifetime of each of these compiler-ge
37343 nerated temporaries.
37344  A picture speaks a thousand words.
37345  ICode example sections show the live range annotations for each of the
37346  operand.
37347  It is important to note here, each iCode is assigned a number in the order
37348  of its execution in the function.
37349  The live ranges are computed in terms of these numbers.
37350  The from number is the number of the iCode which first defines the operand
37351  and the to number signifies the iCode which uses this operand last.
37352 \end_layout
37353
37354 \begin_layout Paragraph*
37355 Register Allocation
37356 \begin_inset LatexCommand \index{Register allocation}
37357
37358 \end_inset
37359
37360
37361 \end_layout
37362
37363 \begin_layout Standard
37364 The register allocation determines the type and number of registers needed
37365  by each operand.
37366  In most MCUs only a few registers can be used for indirect addressing.
37367  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37368  address the internal ram and DPTR to indirectly address the external ram.
37369  The compiler will try to allocate the appropriate register to pointer variables
37370  if it can.
37371  ICode example section shows the operands annotated with the registers assigned
37372  to them.
37373  The compiler will try to keep operands in registers as much as possible;
37374  there are several schemes the compiler uses to do achieve this.
37375  When the compiler runs out of registers the compiler will check to see
37376  if there are any live operands which is not used or defined in the current
37377  basic block being processed, if there are any found then it will push that
37378  operand and use the registers in this block, the operand will then be popped
37379  at the end of the basic block.
37380  
37381 \end_layout
37382
37383 \begin_layout Standard
37384 There are other MCU specific considerations in this phase.
37385  Some MCUs have an accumulator; very short-lived operands could be assigned
37386  to the accumulator instead of a general-purpose register.
37387 \end_layout
37388
37389 \begin_layout Paragraph*
37390 Code generation
37391 \end_layout
37392
37393 \begin_layout Standard
37394 Figure II gives a table of iCode
37395 \begin_inset LatexCommand \index{iCode}
37396
37397 \end_inset
37398
37399  operations supported by the compiler.
37400  The code generation involves translating these operations into corresponding
37401  assembly code for the processor.
37402  This sounds overly simple but that is the essence of code generation.
37403  Some of the iCode operations are generated on a MCU specific manner for
37404  example, the z80 port does not use registers to pass parameters so the
37405  SEND and RECV iCode operations will not be generated, and it also does
37406  not support JUMPTABLES.
37407  
37408 \newline
37409
37410 \end_layout
37411
37412 \begin_layout Standard
37413
37414 \size footnotesize
37415 Figure II 
37416 \begin_inset Tabular
37417 <lyxtabular version="3" rows="39" columns="4">
37418 <features islongtable="true" headBottomDL="true">
37419 <column alignment="block" valignment="top" leftline="true" width="13col%">
37420 <column alignment="left" valignment="top" leftline="true" width="13col%">
37421 <column alignment="block" valignment="top" leftline="true" width="22col%">
37422 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37423 <row topline="true" bottomline="true" endhead="true">
37424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37425 \begin_inset Text
37426
37427 \begin_layout Standard
37428
37429 \series bold
37430 iCode
37431 \series default
37432
37433 \begin_inset LatexCommand \index{iCode}
37434
37435 \end_inset
37436
37437
37438 \end_layout
37439
37440 \end_inset
37441 </cell>
37442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37443 \begin_inset Text
37444
37445 \begin_layout Standard
37446
37447 \series bold
37448 Operands
37449 \end_layout
37450
37451 \end_inset
37452 </cell>
37453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37454 \begin_inset Text
37455
37456 \begin_layout Standard
37457
37458 \series bold
37459 Description
37460 \end_layout
37461
37462 \end_inset
37463 </cell>
37464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37465 \begin_inset Text
37466
37467 \begin_layout Standard
37468
37469 \series bold
37470 C Equivalent
37471 \end_layout
37472
37473 \end_inset
37474 </cell>
37475 </row>
37476 <row topline="true">
37477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37478 \begin_inset Text
37479
37480 \begin_layout Standard
37481
37482 \size footnotesize
37483 '!'
37484 \end_layout
37485
37486 \end_inset
37487 </cell>
37488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37489 \begin_inset Text
37490
37491 \begin_layout Standard
37492
37493 \size footnotesize
37494 IC_LEFT() IC_RESULT()
37495 \end_layout
37496
37497 \end_inset
37498 </cell>
37499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37500 \begin_inset Text
37501
37502 \begin_layout Standard
37503
37504 \size footnotesize
37505 NOT operation 
37506 \end_layout
37507
37508 \end_inset
37509 </cell>
37510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37511 \begin_inset Text
37512
37513 \begin_layout Standard
37514
37515 \size footnotesize
37516 IC_RESULT = ! IC_LEFT;
37517 \end_layout
37518
37519 \end_inset
37520 </cell>
37521 </row>
37522 <row topline="true">
37523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37524 \begin_inset Text
37525
37526 \begin_layout Standard
37527
37528 \size footnotesize
37529 '~'
37530 \end_layout
37531
37532 \end_inset
37533 </cell>
37534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37535 \begin_inset Text
37536
37537 \begin_layout Standard
37538
37539 \size footnotesize
37540 IC_LEFT() IC_RESULT()
37541 \end_layout
37542
37543 \end_inset
37544 </cell>
37545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37546 \begin_inset Text
37547
37548 \begin_layout Standard
37549
37550 \size footnotesize
37551 Bitwise complement of 
37552 \end_layout
37553
37554 \end_inset
37555 </cell>
37556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37557 \begin_inset Text
37558
37559 \begin_layout Standard
37560
37561 \size footnotesize
37562 IC_RESULT = ~IC_LEFT;
37563 \end_layout
37564
37565 \end_inset
37566 </cell>
37567 </row>
37568 <row topline="true">
37569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37570 \begin_inset Text
37571
37572 \begin_layout Standard
37573
37574 \size footnotesize
37575 RRC
37576 \end_layout
37577
37578 \end_inset
37579 </cell>
37580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37581 \begin_inset Text
37582
37583 \begin_layout Standard
37584
37585 \size footnotesize
37586 IC_LEFT() IC_RESULT()
37587 \end_layout
37588
37589 \end_inset
37590 </cell>
37591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37592 \begin_inset Text
37593
37594 \begin_layout Standard
37595
37596 \size footnotesize
37597 Rotate right with carry
37598 \end_layout
37599
37600 \end_inset
37601 </cell>
37602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37603 \begin_inset Text
37604
37605 \begin_layout Standard
37606
37607 \size footnotesize
37608 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37609 \end_layout
37610
37611 \end_inset
37612 </cell>
37613 </row>
37614 <row topline="true">
37615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37616 \begin_inset Text
37617
37618 \begin_layout Standard
37619
37620 \size footnotesize
37621 RLC
37622 \end_layout
37623
37624 \end_inset
37625 </cell>
37626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37627 \begin_inset Text
37628
37629 \begin_layout Standard
37630
37631 \size footnotesize
37632 IC_LEFT() IC_RESULT()
37633 \end_layout
37634
37635 \end_inset
37636 </cell>
37637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37638 \begin_inset Text
37639
37640 \begin_layout Standard
37641
37642 \size footnotesize
37643 Rotate left with carry
37644 \end_layout
37645
37646 \end_inset
37647 </cell>
37648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37649 \begin_inset Text
37650
37651 \begin_layout Standard
37652
37653 \size footnotesize
37654 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37655 \end_layout
37656
37657 \end_inset
37658 </cell>
37659 </row>
37660 <row topline="true">
37661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37662 \begin_inset Text
37663
37664 \begin_layout Standard
37665
37666 \size footnotesize
37667 GETHBIT
37668 \end_layout
37669
37670 \end_inset
37671 </cell>
37672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37673 \begin_inset Text
37674
37675 \begin_layout Standard
37676
37677 \size footnotesize
37678 IC_LEFT() IC_RESULT()
37679 \end_layout
37680
37681 \end_inset
37682 </cell>
37683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37684 \begin_inset Text
37685
37686 \begin_layout Standard
37687
37688 \size footnotesize
37689 Get the highest order bit of IC_LEFT
37690 \end_layout
37691
37692 \end_inset
37693 </cell>
37694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37695 \begin_inset Text
37696
37697 \begin_layout Standard
37698
37699 \size footnotesize
37700 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37701 \end_layout
37702
37703 \end_inset
37704 </cell>
37705 </row>
37706 <row topline="true">
37707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37708 \begin_inset Text
37709
37710 \begin_layout Standard
37711
37712 \size footnotesize
37713 UNARYMINUS
37714 \end_layout
37715
37716 \end_inset
37717 </cell>
37718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37719 \begin_inset Text
37720
37721 \begin_layout Standard
37722
37723 \size footnotesize
37724 IC_LEFT() IC_RESULT()
37725 \end_layout
37726
37727 \end_inset
37728 </cell>
37729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37730 \begin_inset Text
37731
37732 \begin_layout Standard
37733
37734 \size footnotesize
37735 Unary minus
37736 \end_layout
37737
37738 \end_inset
37739 </cell>
37740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37741 \begin_inset Text
37742
37743 \begin_layout Standard
37744
37745 \size footnotesize
37746 IC_RESULT = - IC_LEFT;
37747 \end_layout
37748
37749 \end_inset
37750 </cell>
37751 </row>
37752 <row topline="true">
37753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37754 \begin_inset Text
37755
37756 \begin_layout Standard
37757
37758 \size footnotesize
37759 IPUSH
37760 \end_layout
37761
37762 \end_inset
37763 </cell>
37764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37765 \begin_inset Text
37766
37767 \begin_layout Standard
37768
37769 \size footnotesize
37770 IC_LEFT()
37771 \end_layout
37772
37773 \end_inset
37774 </cell>
37775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37776 \begin_inset Text
37777
37778 \begin_layout Standard
37779
37780 \size footnotesize
37781 Push the operand into stack
37782 \end_layout
37783
37784 \end_inset
37785 </cell>
37786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37787 \begin_inset Text
37788
37789 \begin_layout Standard
37790
37791 \size footnotesize
37792 NONE
37793 \end_layout
37794
37795 \end_inset
37796 </cell>
37797 </row>
37798 <row topline="true">
37799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37800 \begin_inset Text
37801
37802 \begin_layout Standard
37803
37804 \size footnotesize
37805 IPOP
37806 \end_layout
37807
37808 \end_inset
37809 </cell>
37810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37811 \begin_inset Text
37812
37813 \begin_layout Standard
37814
37815 \size footnotesize
37816 IC_LEFT()
37817 \end_layout
37818
37819 \end_inset
37820 </cell>
37821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37822 \begin_inset Text
37823
37824 \begin_layout Standard
37825
37826 \size footnotesize
37827 Pop the operand from the stack 
37828 \end_layout
37829
37830 \end_inset
37831 </cell>
37832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37833 \begin_inset Text
37834
37835 \begin_layout Standard
37836
37837 \size footnotesize
37838 NONE
37839 \end_layout
37840
37841 \end_inset
37842 </cell>
37843 </row>
37844 <row topline="true">
37845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37846 \begin_inset Text
37847
37848 \begin_layout Standard
37849
37850 \size footnotesize
37851 CALL
37852 \end_layout
37853
37854 \end_inset
37855 </cell>
37856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37857 \begin_inset Text
37858
37859 \begin_layout Standard
37860
37861 \size footnotesize
37862 IC_LEFT() IC_RESULT()
37863 \end_layout
37864
37865 \end_inset
37866 </cell>
37867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37868 \begin_inset Text
37869
37870 \begin_layout Standard
37871
37872 \size footnotesize
37873 Call the function represented by IC_LEFT 
37874 \end_layout
37875
37876 \end_inset
37877 </cell>
37878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37879 \begin_inset Text
37880
37881 \begin_layout Standard
37882
37883 \size footnotesize
37884 IC_RESULT = IC_LEFT();
37885 \end_layout
37886
37887 \end_inset
37888 </cell>
37889 </row>
37890 <row topline="true">
37891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37892 \begin_inset Text
37893
37894 \begin_layout Standard
37895
37896 \size footnotesize
37897 PCALL
37898 \end_layout
37899
37900 \end_inset
37901 </cell>
37902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37903 \begin_inset Text
37904
37905 \begin_layout Standard
37906
37907 \size footnotesize
37908 IC_LEFT() IC_RESULT()
37909 \end_layout
37910
37911 \end_inset
37912 </cell>
37913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37914 \begin_inset Text
37915
37916 \begin_layout Standard
37917
37918 \size footnotesize
37919 Call via function pointer
37920 \end_layout
37921
37922 \end_inset
37923 </cell>
37924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37925 \begin_inset Text
37926
37927 \begin_layout Standard
37928
37929 \size footnotesize
37930 IC_RESULT = (*IC_LEFT)();
37931 \end_layout
37932
37933 \end_inset
37934 </cell>
37935 </row>
37936 <row topline="true">
37937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37938 \begin_inset Text
37939
37940 \begin_layout Standard
37941
37942 \size footnotesize
37943 RETURN
37944 \end_layout
37945
37946 \end_inset
37947 </cell>
37948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37949 \begin_inset Text
37950
37951 \begin_layout Standard
37952
37953 \size footnotesize
37954 IC_LEFT()
37955 \end_layout
37956
37957 \end_inset
37958 </cell>
37959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37960 \begin_inset Text
37961
37962 \begin_layout Standard
37963
37964 \size footnotesize
37965 Return the value in operand IC_LEFT 
37966 \end_layout
37967
37968 \end_inset
37969 </cell>
37970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37971 \begin_inset Text
37972
37973 \begin_layout Standard
37974
37975 \size footnotesize
37976 return IC_LEFT;
37977 \end_layout
37978
37979 \end_inset
37980 </cell>
37981 </row>
37982 <row topline="true">
37983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37984 \begin_inset Text
37985
37986 \begin_layout Standard
37987
37988 \size footnotesize
37989 LABEL
37990 \end_layout
37991
37992 \end_inset
37993 </cell>
37994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37995 \begin_inset Text
37996
37997 \begin_layout Standard
37998
37999 \size footnotesize
38000 IC_LABEL() 
38001 \end_layout
38002
38003 \end_inset
38004 </cell>
38005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38006 \begin_inset Text
38007
38008 \begin_layout Standard
38009
38010 \size footnotesize
38011 Label
38012 \end_layout
38013
38014 \end_inset
38015 </cell>
38016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38017 \begin_inset Text
38018
38019 \begin_layout Standard
38020
38021 \size footnotesize
38022 IC_LABEL:
38023 \end_layout
38024
38025 \end_inset
38026 </cell>
38027 </row>
38028 <row topline="true">
38029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38030 \begin_inset Text
38031
38032 \begin_layout Standard
38033
38034 \size footnotesize
38035 GOTO
38036 \end_layout
38037
38038 \end_inset
38039 </cell>
38040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38041 \begin_inset Text
38042
38043 \begin_layout Standard
38044
38045 \size footnotesize
38046 IC_LABEL() 
38047 \end_layout
38048
38049 \end_inset
38050 </cell>
38051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38052 \begin_inset Text
38053
38054 \begin_layout Standard
38055
38056 \size footnotesize
38057 Goto label
38058 \end_layout
38059
38060 \end_inset
38061 </cell>
38062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38063 \begin_inset Text
38064
38065 \begin_layout Standard
38066
38067 \size footnotesize
38068 goto IC_LABEL();
38069 \end_layout
38070
38071 \end_inset
38072 </cell>
38073 </row>
38074 <row topline="true">
38075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38076 \begin_inset Text
38077
38078 \begin_layout Standard
38079
38080 \size footnotesize
38081 '+'
38082 \end_layout
38083
38084 \end_inset
38085 </cell>
38086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38087 \begin_inset Text
38088
38089 \begin_layout Standard
38090
38091 \size footnotesize
38092 IC_LEFT() IC_RIGHT() IC_RESULT()
38093 \end_layout
38094
38095 \end_inset
38096 </cell>
38097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38098 \begin_inset Text
38099
38100 \begin_layout Standard
38101
38102 \size footnotesize
38103 Addition
38104 \end_layout
38105
38106 \end_inset
38107 </cell>
38108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38109 \begin_inset Text
38110
38111 \begin_layout Standard
38112
38113 \size footnotesize
38114 IC_RESULT = IC_LEFT + IC_RIGHT
38115 \end_layout
38116
38117 \end_inset
38118 </cell>
38119 </row>
38120 <row topline="true">
38121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38122 \begin_inset Text
38123
38124 \begin_layout Standard
38125
38126 \size footnotesize
38127 '-'
38128 \end_layout
38129
38130 \end_inset
38131 </cell>
38132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38133 \begin_inset Text
38134
38135 \begin_layout Standard
38136
38137 \size footnotesize
38138 IC_LEFT() IC_RIGHT() IC_RESULT()
38139 \end_layout
38140
38141 \end_inset
38142 </cell>
38143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38144 \begin_inset Text
38145
38146 \begin_layout Standard
38147
38148 \size footnotesize
38149 Subtraction
38150 \end_layout
38151
38152 \end_inset
38153 </cell>
38154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38155 \begin_inset Text
38156
38157 \begin_layout Standard
38158
38159 \size footnotesize
38160 IC_RESULT = IC_LEFT - IC_RIGHT 
38161 \end_layout
38162
38163 \end_inset
38164 </cell>
38165 </row>
38166 <row topline="true">
38167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38168 \begin_inset Text
38169
38170 \begin_layout Standard
38171
38172 \size footnotesize
38173 '*'
38174 \end_layout
38175
38176 \end_inset
38177 </cell>
38178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38179 \begin_inset Text
38180
38181 \begin_layout Standard
38182
38183 \size footnotesize
38184 IC_LEFT() IC_RIGHT() IC_RESULT()
38185 \end_layout
38186
38187 \end_inset
38188 </cell>
38189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38190 \begin_inset Text
38191
38192 \begin_layout Standard
38193
38194 \size footnotesize
38195 Multiplication 
38196 \end_layout
38197
38198 \end_inset
38199 </cell>
38200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38201 \begin_inset Text
38202
38203 \begin_layout Standard
38204
38205 \size footnotesize
38206 IC_RESULT = IC_LEFT * IC_RIGHT;
38207 \end_layout
38208
38209 \end_inset
38210 </cell>
38211 </row>
38212 <row topline="true">
38213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38214 \begin_inset Text
38215
38216 \begin_layout Standard
38217
38218 \size footnotesize
38219 '/'
38220 \end_layout
38221
38222 \end_inset
38223 </cell>
38224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38225 \begin_inset Text
38226
38227 \begin_layout Standard
38228
38229 \size footnotesize
38230 IC_LEFT() IC_RIGHT() IC_RESULT()
38231 \end_layout
38232
38233 \end_inset
38234 </cell>
38235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38236 \begin_inset Text
38237
38238 \begin_layout Standard
38239
38240 \size footnotesize
38241 Division
38242 \end_layout
38243
38244 \end_inset
38245 </cell>
38246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38247 \begin_inset Text
38248
38249 \begin_layout Standard
38250
38251 \size footnotesize
38252 IC_RESULT = IC_LEFT / IC_RIGHT;
38253 \end_layout
38254
38255 \end_inset
38256 </cell>
38257 </row>
38258 <row topline="true">
38259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38260 \begin_inset Text
38261
38262 \begin_layout Standard
38263
38264 \size footnotesize
38265 '%'
38266 \end_layout
38267
38268 \end_inset
38269 </cell>
38270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38271 \begin_inset Text
38272
38273 \begin_layout Standard
38274
38275 \size footnotesize
38276 IC_LEFT() IC_RIGHT() IC_RESULT()
38277 \end_layout
38278
38279 \end_inset
38280 </cell>
38281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38282 \begin_inset Text
38283
38284 \begin_layout Standard
38285
38286 \size footnotesize
38287 Modulus
38288 \end_layout
38289
38290 \end_inset
38291 </cell>
38292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38293 \begin_inset Text
38294
38295 \begin_layout Standard
38296
38297 \size footnotesize
38298 IC_RESULT = IC_LEFT % IC_RIGHT;
38299 \end_layout
38300
38301 \end_inset
38302 </cell>
38303 </row>
38304 <row topline="true">
38305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38306 \begin_inset Text
38307
38308 \begin_layout Standard
38309
38310 \size footnotesize
38311 '<'
38312 \end_layout
38313
38314 \end_inset
38315 </cell>
38316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38317 \begin_inset Text
38318
38319 \begin_layout Standard
38320
38321 \size footnotesize
38322 IC_LEFT() IC_RIGHT() IC_RESULT()
38323 \end_layout
38324
38325 \end_inset
38326 </cell>
38327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38328 \begin_inset Text
38329
38330 \begin_layout Standard
38331
38332 \size footnotesize
38333 Less than
38334 \end_layout
38335
38336 \end_inset
38337 </cell>
38338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38339 \begin_inset Text
38340
38341 \begin_layout Standard
38342
38343 \size footnotesize
38344 IC_RESULT = IC_LEFT < IC_RIGHT;
38345 \end_layout
38346
38347 \end_inset
38348 </cell>
38349 </row>
38350 <row topline="true">
38351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38352 \begin_inset Text
38353
38354 \begin_layout Standard
38355
38356 \size footnotesize
38357 '>'
38358 \end_layout
38359
38360 \end_inset
38361 </cell>
38362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38363 \begin_inset Text
38364
38365 \begin_layout Standard
38366
38367 \size footnotesize
38368 IC_LEFT() IC_RIGHT() IC_RESULT()
38369 \end_layout
38370
38371 \end_inset
38372 </cell>
38373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38374 \begin_inset Text
38375
38376 \begin_layout Standard
38377
38378 \size footnotesize
38379 Greater than 
38380 \end_layout
38381
38382 \end_inset
38383 </cell>
38384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38385 \begin_inset Text
38386
38387 \begin_layout Standard
38388
38389 \size footnotesize
38390 IC_RESULT = IC_LEFT > IC_RIGHT;
38391 \end_layout
38392
38393 \end_inset
38394 </cell>
38395 </row>
38396 <row topline="true">
38397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38398 \begin_inset Text
38399
38400 \begin_layout Standard
38401
38402 \size footnotesize
38403 EQ_OP
38404 \end_layout
38405
38406 \end_inset
38407 </cell>
38408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38409 \begin_inset Text
38410
38411 \begin_layout Standard
38412
38413 \size footnotesize
38414 IC_LEFT() IC_RIGHT() IC_RESULT()
38415 \end_layout
38416
38417 \end_inset
38418 </cell>
38419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38420 \begin_inset Text
38421
38422 \begin_layout Standard
38423
38424 \size footnotesize
38425 Equal to 
38426 \end_layout
38427
38428 \end_inset
38429 </cell>
38430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38431 \begin_inset Text
38432
38433 \begin_layout Standard
38434
38435 \size footnotesize
38436 IC_RESULT = IC_LEFT == IC_RIGHT;
38437 \end_layout
38438
38439 \end_inset
38440 </cell>
38441 </row>
38442 <row topline="true">
38443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38444 \begin_inset Text
38445
38446 \begin_layout Standard
38447
38448 \size footnotesize
38449 AND_OP
38450 \end_layout
38451
38452 \end_inset
38453 </cell>
38454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38455 \begin_inset Text
38456
38457 \begin_layout Standard
38458
38459 \size footnotesize
38460 IC_LEFT() IC_RIGHT() IC_RESULT() 
38461 \end_layout
38462
38463 \end_inset
38464 </cell>
38465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38466 \begin_inset Text
38467
38468 \begin_layout Standard
38469
38470 \size footnotesize
38471 Logical and operation
38472 \end_layout
38473
38474 \end_inset
38475 </cell>
38476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38477 \begin_inset Text
38478
38479 \begin_layout Standard
38480
38481 \size footnotesize
38482 IC_RESULT = IC_LEFT && IC_RIGHT; 
38483 \end_layout
38484
38485 \end_inset
38486 </cell>
38487 </row>
38488 <row topline="true">
38489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38490 \begin_inset Text
38491
38492 \begin_layout Standard
38493
38494 \size footnotesize
38495 OR_OP
38496 \end_layout
38497
38498 \end_inset
38499 </cell>
38500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38501 \begin_inset Text
38502
38503 \begin_layout Standard
38504
38505 \size footnotesize
38506 IC_LEFT() IC_RIGHT() IC_RESULT() 
38507 \end_layout
38508
38509 \end_inset
38510 </cell>
38511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38512 \begin_inset Text
38513
38514 \begin_layout Standard
38515
38516 \size footnotesize
38517 Logical or operation 
38518 \end_layout
38519
38520 \end_inset
38521 </cell>
38522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38523 \begin_inset Text
38524
38525 \begin_layout Standard
38526
38527 \size footnotesize
38528 IC_RESULT = IC_LEFT || IC_RIGHT; 
38529 \end_layout
38530
38531 \end_inset
38532 </cell>
38533 </row>
38534 <row topline="true">
38535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38536 \begin_inset Text
38537
38538 \begin_layout Standard
38539
38540 \size footnotesize
38541 '^'
38542 \end_layout
38543
38544 \end_inset
38545 </cell>
38546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38547 \begin_inset Text
38548
38549 \begin_layout Standard
38550
38551 \size footnotesize
38552 IC_LEFT() IC_RIGHT() IC_RESULT() 
38553 \end_layout
38554
38555 \end_inset
38556 </cell>
38557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38558 \begin_inset Text
38559
38560 \begin_layout Standard
38561
38562 \size footnotesize
38563 Exclusive OR
38564 \end_layout
38565
38566 \end_inset
38567 </cell>
38568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38569 \begin_inset Text
38570
38571 \begin_layout Standard
38572
38573 \size footnotesize
38574 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38575 \end_layout
38576
38577 \end_inset
38578 </cell>
38579 </row>
38580 <row topline="true">
38581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38582 \begin_inset Text
38583
38584 \begin_layout Standard
38585
38586 \size footnotesize
38587 '|'
38588 \end_layout
38589
38590 \end_inset
38591 </cell>
38592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38593 \begin_inset Text
38594
38595 \begin_layout Standard
38596
38597 \size footnotesize
38598 IC_LEFT() IC_RIGHT() IC_RESULT() 
38599 \end_layout
38600
38601 \end_inset
38602 </cell>
38603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38604 \begin_inset Text
38605
38606 \begin_layout Standard
38607
38608 \size footnotesize
38609 Bitwise OR 
38610 \end_layout
38611
38612 \end_inset
38613 </cell>
38614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38615 \begin_inset Text
38616
38617 \begin_layout Standard
38618
38619 \size footnotesize
38620 IC_RESULT = IC_LEFT | IC_RIGHT;
38621 \end_layout
38622
38623 \end_inset
38624 </cell>
38625 </row>
38626 <row topline="true">
38627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38628 \begin_inset Text
38629
38630 \begin_layout Standard
38631
38632 \size footnotesize
38633 BITWISEAND
38634 \end_layout
38635
38636 \end_inset
38637 </cell>
38638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38639 \begin_inset Text
38640
38641 \begin_layout Standard
38642
38643 \size footnotesize
38644 IC_LEFT() IC_RIGHT() IC_RESULT()
38645 \end_layout
38646
38647 \end_inset
38648 </cell>
38649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38650 \begin_inset Text
38651
38652 \begin_layout Standard
38653
38654 \size footnotesize
38655 Bitwise AND 
38656 \end_layout
38657
38658 \end_inset
38659 </cell>
38660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38661 \begin_inset Text
38662
38663 \begin_layout Standard
38664
38665 \size footnotesize
38666 IC_RESULT = IC_LEFT & IC_RIGHT;
38667 \end_layout
38668
38669 \end_inset
38670 </cell>
38671 </row>
38672 <row topline="true">
38673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38674 \begin_inset Text
38675
38676 \begin_layout Standard
38677
38678 \size footnotesize
38679 LEFT_OP
38680 \end_layout
38681
38682 \end_inset
38683 </cell>
38684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38685 \begin_inset Text
38686
38687 \begin_layout Standard
38688
38689 \size footnotesize
38690 IC_LEFT() IC_RIGHT() IC_RESULT()
38691 \end_layout
38692
38693 \end_inset
38694 </cell>
38695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38696 \begin_inset Text
38697
38698 \begin_layout Standard
38699
38700 \size footnotesize
38701 Left shift 
38702 \end_layout
38703
38704 \end_inset
38705 </cell>
38706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38707 \begin_inset Text
38708
38709 \begin_layout Standard
38710
38711 \size footnotesize
38712 IC_RESULT = IC_LEFT << IC_RIGHT 
38713 \end_layout
38714
38715 \end_inset
38716 </cell>
38717 </row>
38718 <row topline="true">
38719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38720 \begin_inset Text
38721
38722 \begin_layout Standard
38723
38724 \size footnotesize
38725 RIGHT_OP
38726 \end_layout
38727
38728 \end_inset
38729 </cell>
38730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38731 \begin_inset Text
38732
38733 \begin_layout Standard
38734
38735 \size footnotesize
38736 IC_LEFT() IC_RIGHT() IC_RESULT()
38737 \end_layout
38738
38739 \end_inset
38740 </cell>
38741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38742 \begin_inset Text
38743
38744 \begin_layout Standard
38745
38746 \size footnotesize
38747 Right shift
38748 \end_layout
38749
38750 \end_inset
38751 </cell>
38752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38753 \begin_inset Text
38754
38755 \begin_layout Standard
38756
38757 \size footnotesize
38758 IC_RESULT = IC_LEFT >> IC_RIGHT 
38759 \end_layout
38760
38761 \end_inset
38762 </cell>
38763 </row>
38764 <row topline="true">
38765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38766 \begin_inset Text
38767
38768 \begin_layout Standard
38769
38770 \size footnotesize
38771 GET_VALUE_
38772 \newline
38773 AT_ ADDRESS
38774 \end_layout
38775
38776 \end_inset
38777 </cell>
38778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38779 \begin_inset Text
38780
38781 \begin_layout Standard
38782
38783 \size footnotesize
38784 IC_LEFT() IC_RESULT()
38785 \end_layout
38786
38787 \end_inset
38788 </cell>
38789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38790 \begin_inset Text
38791
38792 \begin_layout Standard
38793
38794 \size footnotesize
38795 Indirect fetch 
38796 \end_layout
38797
38798 \end_inset
38799 </cell>
38800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38801 \begin_inset Text
38802
38803 \begin_layout Standard
38804
38805 \size footnotesize
38806 IC_RESULT = (*IC_LEFT);
38807 \end_layout
38808
38809 \end_inset
38810 </cell>
38811 </row>
38812 <row topline="true">
38813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38814 \begin_inset Text
38815
38816 \begin_layout Standard
38817
38818 \size footnotesize
38819 POINTER_SET
38820 \end_layout
38821
38822 \end_inset
38823 </cell>
38824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38825 \begin_inset Text
38826
38827 \begin_layout Standard
38828
38829 \size footnotesize
38830 IC_RIGHT() IC_RESULT() 
38831 \end_layout
38832
38833 \end_inset
38834 </cell>
38835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38836 \begin_inset Text
38837
38838 \begin_layout Standard
38839
38840 \size footnotesize
38841 Indirect set
38842 \end_layout
38843
38844 \end_inset
38845 </cell>
38846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38847 \begin_inset Text
38848
38849 \begin_layout Standard
38850
38851 \size footnotesize
38852 (*IC_RESULT) = IC_RIGHT;
38853 \end_layout
38854
38855 \end_inset
38856 </cell>
38857 </row>
38858 <row topline="true">
38859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38860 \begin_inset Text
38861
38862 \begin_layout Standard
38863
38864 \size footnotesize
38865 '='
38866 \end_layout
38867
38868 \end_inset
38869 </cell>
38870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38871 \begin_inset Text
38872
38873 \begin_layout Standard
38874
38875 \size footnotesize
38876 IC_RIGHT() IC_RESULT()
38877 \end_layout
38878
38879 \end_inset
38880 </cell>
38881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38882 \begin_inset Text
38883
38884 \begin_layout Standard
38885
38886 \size footnotesize
38887 Assignment
38888 \end_layout
38889
38890 \end_inset
38891 </cell>
38892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38893 \begin_inset Text
38894
38895 \begin_layout Standard
38896
38897 \size footnotesize
38898 IC_RESULT = IC_RIGHT;
38899 \end_layout
38900
38901 \end_inset
38902 </cell>
38903 </row>
38904 <row topline="true">
38905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38906 \begin_inset Text
38907
38908 \begin_layout Standard
38909
38910 \size footnotesize
38911 IFX
38912 \end_layout
38913
38914 \end_inset
38915 </cell>
38916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38917 \begin_inset Text
38918
38919 \begin_layout Standard
38920
38921 \size footnotesize
38922 IC_COND IC_TRUE IC_LABEL
38923 \end_layout
38924
38925 \end_inset
38926 </cell>
38927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38928 \begin_inset Text
38929
38930 \begin_layout Standard
38931
38932 \size footnotesize
38933 Conditional jump.
38934  If true label is present then jump to true label if condition is true else
38935  jump to false label if condition is false 
38936 \end_layout
38937
38938 \end_inset
38939 </cell>
38940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38941 \begin_inset Text
38942
38943 \begin_layout Standard
38944
38945 \size footnotesize
38946 if (IC_COND) goto IC_TRUE; 
38947 \newline
38948 \InsetSpace ~
38949 \InsetSpace ~
38950 Or 
38951 \newline
38952 If (!IC_COND) goto IC_FALSE;
38953 \end_layout
38954
38955 \end_inset
38956 </cell>
38957 </row>
38958 <row topline="true">
38959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38960 \begin_inset Text
38961
38962 \begin_layout Standard
38963
38964 \size footnotesize
38965 ADDRESS_OF
38966 \end_layout
38967
38968 \end_inset
38969 </cell>
38970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38971 \begin_inset Text
38972
38973 \begin_layout Standard
38974
38975 \size footnotesize
38976 IC_LEFT() IC_RESULT()
38977 \end_layout
38978
38979 \end_inset
38980 </cell>
38981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38982 \begin_inset Text
38983
38984 \begin_layout Standard
38985
38986 \size footnotesize
38987 Address of 
38988 \end_layout
38989
38990 \end_inset
38991 </cell>
38992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38993 \begin_inset Text
38994
38995 \begin_layout Standard
38996
38997 \size footnotesize
38998 IC_RESULT = &IC_LEFT();
38999 \end_layout
39000
39001 \end_inset
39002 </cell>
39003 </row>
39004 <row topline="true">
39005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39006 \begin_inset Text
39007
39008 \begin_layout Standard
39009
39010 \size footnotesize
39011 JUMPTABLE
39012 \end_layout
39013
39014 \end_inset
39015 </cell>
39016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39017 \begin_inset Text
39018
39019 \begin_layout Standard
39020
39021 \size footnotesize
39022 IC_JTCOND IC_JTLABELS
39023 \end_layout
39024
39025 \end_inset
39026 </cell>
39027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39028 \begin_inset Text
39029
39030 \begin_layout Standard
39031
39032 \size footnotesize
39033 Jump to list of labels depending on the value of JTCOND
39034 \end_layout
39035
39036 \end_inset
39037 </cell>
39038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39039 \begin_inset Text
39040
39041 \begin_layout Standard
39042
39043 \size footnotesize
39044 Switch statement
39045 \end_layout
39046
39047 \end_inset
39048 </cell>
39049 </row>
39050 <row topline="true">
39051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39052 \begin_inset Text
39053
39054 \begin_layout Standard
39055
39056 \size footnotesize
39057 CAST
39058 \end_layout
39059
39060 \end_inset
39061 </cell>
39062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39063 \begin_inset Text
39064
39065 \begin_layout Standard
39066
39067 \size footnotesize
39068 IC_RIGHT() IC_LEFT() IC_RESULT()
39069 \end_layout
39070
39071 \end_inset
39072 </cell>
39073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39074 \begin_inset Text
39075
39076 \begin_layout Standard
39077
39078 \size footnotesize
39079 Cast types 
39080 \end_layout
39081
39082 \end_inset
39083 </cell>
39084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39085 \begin_inset Text
39086
39087 \begin_layout Standard
39088
39089 \size footnotesize
39090 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39091 \end_layout
39092
39093 \end_inset
39094 </cell>
39095 </row>
39096 <row topline="true">
39097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39098 \begin_inset Text
39099
39100 \begin_layout Standard
39101
39102 \size footnotesize
39103 SEND
39104 \end_layout
39105
39106 \end_inset
39107 </cell>
39108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39109 \begin_inset Text
39110
39111 \begin_layout Standard
39112
39113 \size footnotesize
39114 IC_LEFT()
39115 \end_layout
39116
39117 \end_inset
39118 </cell>
39119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39120 \begin_inset Text
39121
39122 \begin_layout Standard
39123
39124 \size footnotesize
39125 This is used for passing parameters in registers; 
39126 \newline
39127 move IC_LEFT to the next
39128  available parameter register.
39129 \end_layout
39130
39131 \end_inset
39132 </cell>
39133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39134 \begin_inset Text
39135
39136 \begin_layout Standard
39137
39138 \size footnotesize
39139 None
39140 \end_layout
39141
39142 \end_inset
39143 </cell>
39144 </row>
39145 <row topline="true">
39146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39147 \begin_inset Text
39148
39149 \begin_layout Standard
39150
39151 \size footnotesize
39152 RECV
39153 \end_layout
39154
39155 \end_inset
39156 </cell>
39157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39158 \begin_inset Text
39159
39160 \begin_layout Standard
39161
39162 \size footnotesize
39163 IC_RESULT()
39164 \end_layout
39165
39166 \end_inset
39167 </cell>
39168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39169 \begin_inset Text
39170
39171 \begin_layout Standard
39172
39173 \size footnotesize
39174 This is used for receiving parameters passed in registers;
39175 \newline
39176 Move the values
39177  in the next parameter register to IC_RESULT 
39178 \end_layout
39179
39180 \end_inset
39181 </cell>
39182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39183 \begin_inset Text
39184
39185 \begin_layout Standard
39186
39187 \size footnotesize
39188 None
39189 \end_layout
39190
39191 \end_inset
39192 </cell>
39193 </row>
39194 <row topline="true" bottomline="true">
39195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39196 \begin_inset Text
39197
39198 \begin_layout Standard
39199
39200 \shape slanted
39201 \size footnotesize
39202 (some more have been added)
39203 \end_layout
39204
39205 \end_inset
39206 </cell>
39207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39208 \begin_inset Text
39209
39210 \begin_layout Standard
39211
39212 \end_layout
39213
39214 \end_inset
39215 </cell>
39216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39217 \begin_inset Text
39218
39219 \begin_layout Standard
39220
39221 \end_layout
39222
39223 \end_inset
39224 </cell>
39225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39226 \begin_inset Text
39227
39228 \begin_layout Standard
39229
39230 \shape slanted
39231 \size footnotesize
39232 see f.e.
39233  
39234 \family typewriter
39235 gen51Code()
39236 \family default
39237  in 
39238 \family typewriter
39239 src/mcs51/gen.c
39240 \end_layout
39241
39242 \end_inset
39243 </cell>
39244 </row>
39245 </lyxtabular>
39246
39247 \end_inset
39248
39249
39250 \end_layout
39251
39252 \begin_layout Standard
39253 \begin_inset Note Note
39254 status collapsed
39255
39256 \begin_layout Standard
39257 In the original article Figure II was announced to be downloadable on 
39258 \shape italic
39259 Circuit Cellar
39260 \shape default
39261 's web site.
39262  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39263 \end_layout
39264
39265 \end_inset
39266
39267
39268 \end_layout
39269
39270 \begin_layout Paragraph*
39271 ICode Example
39272 \begin_inset LatexCommand \index{iCode}
39273
39274 \end_inset
39275
39276
39277 \end_layout
39278
39279 \begin_layout Standard
39280 This section shows some details of iCode.
39281  The example C code does not do anything useful; it is used as an example
39282  to illustrate the intermediate code generated by the compiler.
39283 \end_layout
39284
39285 \begin_layout Verse
39286
39287 \family typewriter
39288 1.\InsetSpace ~
39289 xdata int * p;
39290 \newline
39291 2.\InsetSpace ~
39292 int gint;
39293 \newline
39294 3.\InsetSpace ~
39295 /* This function does nothing useful.
39296  It is used
39297 \newline
39298 4.\InsetSpace ~
39299 \InsetSpace ~
39300 \InsetSpace ~
39301 \InsetSpace ~
39302 for the purpose of explaining iCode */
39303 \newline
39304 5.\InsetSpace ~
39305 short function (data
39306  int *x)
39307 \newline
39308 6.\InsetSpace ~
39309 {
39310 \newline
39311 7.\InsetSpace ~
39312 \InsetSpace ~
39313 \InsetSpace ~
39314 short i=10; \InsetSpace ~
39315 \InsetSpace ~
39316 /* dead initialization eliminated */
39317 \newline
39318 8.\InsetSpace ~
39319 \InsetSpace ~
39320 \InsetSpace ~
39321 short sum=10;
39322  /* dead initialization eliminated */
39323 \newline
39324 9.\InsetSpace ~
39325 \InsetSpace ~
39326 \InsetSpace ~
39327 short mul;
39328 \newline
39329 10.\InsetSpace ~
39330 \InsetSpace ~
39331 int j ;
39332 \newline
39333 11.\InsetSpace ~
39334 \InsetSpace ~
39335 while (*x) *x++
39336  = *p++; 
39337 \newline
39338 12.\InsetSpace ~
39339 \InsetSpace ~
39340 \InsetSpace ~
39341 \InsetSpace ~
39342 sum = 0 ; 
39343 \newline
39344 13.\InsetSpace ~
39345 \InsetSpace ~
39346 mul = 0;
39347 \newline
39348 14.\InsetSpace ~
39349 \InsetSpace ~
39350 /* compiler detects i,j to be induction
39351  variables */
39352 \newline
39353 15.\InsetSpace ~
39354 \InsetSpace ~
39355 for (i = 0, j = 10 ; i < 10 ; i++, j
39356 \family default
39357 -
39358 \begin_inset ERT
39359 status collapsed
39360
39361 \begin_layout Standard
39362
39363
39364 \backslash
39365 /
39366 \end_layout
39367
39368 \end_inset
39369
39370 -
39371 \family typewriter
39372 ) {
39373 \newline
39374 16.\InsetSpace ~
39375 \InsetSpace ~
39376 \InsetSpace ~
39377 \InsetSpace ~
39378 sum += i;
39379 \newline
39380 17.\InsetSpace ~
39381 \InsetSpace ~
39382 \InsetSpace ~
39383 \InsetSpace ~
39384 mul += i * 3; \InsetSpace ~
39385 \InsetSpace ~
39386 /* this multiplication remains */
39387 \newline
39388 18.\InsetSpace ~
39389 \InsetSpace ~
39390 \InsetSpace ~
39391 \InsetSpace ~
39392 gint +=
39393  j * 3;\InsetSpace ~
39394 \InsetSpace ~
39395 /* this multiplication changed to addition */
39396 \newline
39397 19.\InsetSpace ~
39398 \InsetSpace ~
39399 }
39400 \newline
39401 20.\InsetSpace ~
39402 \InsetSpace ~
39403 return sum+mul;
39404 \newline
39405 21.\InsetSpace ~
39406 }
39407 \end_layout
39408
39409 \begin_layout Standard
39410 In addition to the operands each iCode contains information about the filename
39411  and line it corresponds to in the source file.
39412  The first field in the listing should be interpreted as follows:
39413 \newline
39414
39415 \shape italic
39416 \size footnotesize
39417 Filename(linenumber: iCode Execution sequence number : ICode hash table
39418  key : loop depth of the iCode).
39419 \shape default
39420 \size default
39421
39422 \newline
39423 Then follows the human readable form of the ICode operation.
39424  Each operand of this triplet form can be of three basic types a) compiler
39425  generated temporary b) user defined variable c) a constant value.
39426  Note that local variables and parameters are replaced by compiler generated
39427  temporaries.
39428  Live ranges
39429 \begin_inset LatexCommand \index{Live range analysis}
39430
39431 \end_inset
39432
39433  are computed only for temporaries (i.e.
39434  live ranges are not computed for global variables).
39435  Registers
39436 \begin_inset LatexCommand \index{Register allocation}
39437
39438 \end_inset
39439
39440  are allocated for temporaries only.
39441  Operands are formatted in the following manner:
39442 \newline
39443
39444 \shape italic
39445 \size footnotesize
39446 Operand Name [lr live-from : live-to ] { type information } [ registers
39447  allocated ].
39448 \shape default
39449 \size default
39450
39451 \newline
39452 As mentioned earlier the live ranges are computed in terms of the execution
39453  sequence number of the iCodes, for example 
39454 \newline
39455 the iTemp0 is live from (i.e.
39456  first defined in iCode with execution sequence number 3, and is last used
39457  in the iCode with sequence number 5).
39458  For induction variables such as iTemp21 the live range computation extends
39459  the lifetime from the start to the end of the loop.
39460 \newline
39461 The register allocator
39462  used the live range information to allocate registers, the same registers
39463  may be used for different temporaries if their live ranges do not overlap,
39464  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39465  ranges do not overlap.
39466  In addition the allocator also takes into consideration the type and usage
39467  of a temporary, for example itemp6 is a pointer to near space and is used
39468  as to fetch data from (i.e.
39469  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39470  Some short lived temporaries are allocated to special registers which have
39471  meaning to the code generator e.g.
39472  iTemp13 is allocated to a pseudo register CC which tells the back end that
39473  the temporary is used only for a conditional jump the code generation makes
39474  use of this information to optimize a compare and jump ICode.
39475 \newline
39476 There are several
39477  loop optimizations
39478 \begin_inset LatexCommand \index{Loop optimization}
39479
39480 \end_inset
39481
39482  performed by the compiler.
39483  It can detect induction variables iTemp21(i) and iTemp23(j).
39484  Also note the compiler does selective strength reduction
39485 \begin_inset LatexCommand \index{Strength reduction}
39486
39487 \end_inset
39488
39489 , i.e.
39490  the multiplication of an induction variable in line 18 (gint = j * 3) is
39491  changed to addition, a new temporary iTemp17 is allocated and assigned
39492  a initial value, a constant 3 is then added for each iteration of the loop.
39493  The compiler does not change the multiplication
39494 \begin_inset LatexCommand \index{Multiplication}
39495
39496 \end_inset
39497
39498  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39499 \newline
39500
39501 Note the dead code elimination
39502 \begin_inset LatexCommand \index{Dead-code elimination}
39503
39504 \end_inset
39505
39506  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39507  respectively.
39508 \newline
39509
39510 \end_layout
39511
39512 \begin_layout Standard
39513
39514 \size footnotesize
39515 Sample.c (5:1:0:0) _entry($9) :
39516 \end_layout
39517
39518 \begin_layout Standard
39519
39520 \size footnotesize
39521 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39522 \end_layout
39523
39524 \begin_layout Standard
39525
39526 \size footnotesize
39527 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39528 \end_layout
39529
39530 \begin_layout Standard
39531
39532 \size footnotesize
39533 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39534 \end_layout
39535
39536 \begin_layout Standard
39537
39538 \size footnotesize
39539 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39540  * int}[r2]
39541 \end_layout
39542
39543 \begin_layout Standard
39544
39545 \size footnotesize
39546 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39547 \end_layout
39548
39549 \begin_layout Standard
39550
39551 \size footnotesize
39552 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39553  int}[r0]]
39554 \end_layout
39555
39556 \begin_layout Standard
39557
39558 \size footnotesize
39559 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39560 \end_layout
39561
39562 \begin_layout Standard
39563
39564 \size footnotesize
39565 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39566  * int}
39567 \end_layout
39568
39569 \begin_layout Standard
39570
39571 \size footnotesize
39572 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39573  {short}
39574 \end_layout
39575
39576 \begin_layout Standard
39577
39578 \size footnotesize
39579 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39580  * int}[DPTR]]
39581 \end_layout
39582
39583 \begin_layout Standard
39584
39585 \size footnotesize
39586 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39587 }[r2 r3]
39588 \end_layout
39589
39590 \begin_layout Standard
39591
39592 \size footnotesize
39593 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39594  * int}[r0] + 0x2 {short}
39595 \end_layout
39596
39597 \begin_layout Standard
39598
39599 \size footnotesize
39600 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39601 \end_layout
39602
39603 \begin_layout Standard
39604
39605 \size footnotesize
39606 Sample.c(11:17:21:0)_whilebreak_0($3) :
39607 \end_layout
39608
39609 \begin_layout Standard
39610
39611 \size footnotesize
39612 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39613 \end_layout
39614
39615 \begin_layout Standard
39616
39617 \size footnotesize
39618 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39619 \end_layout
39620
39621 \begin_layout Standard
39622
39623 \size footnotesize
39624 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39625 \end_layout
39626
39627 \begin_layout Standard
39628
39629 \size footnotesize
39630 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39631 \end_layout
39632
39633 \begin_layout Standard
39634
39635 \size footnotesize
39636 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39637 \end_layout
39638
39639 \begin_layout Standard
39640
39641 \size footnotesize
39642 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39643 \end_layout
39644
39645 \begin_layout Standard
39646
39647 \size footnotesize
39648 Sample.c(15:24:26:1)_forcond_0($4) :
39649 \end_layout
39650
39651 \begin_layout Standard
39652
39653 \size footnotesize
39654 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39655  < 0xa {short}
39656 \end_layout
39657
39658 \begin_layout Standard
39659
39660 \size footnotesize
39661 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39662 \end_layout
39663
39664 \begin_layout Standard
39665
39666 \size footnotesize
39667 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39668  + ITemp21 [lr21:38]{short}[r4]
39669 \end_layout
39670
39671 \begin_layout Standard
39672
39673 \size footnotesize
39674 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39675  * 0x3 {short}
39676 \end_layout
39677
39678 \begin_layout Standard
39679
39680 \size footnotesize
39681 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39682  + iTemp15 [lr29:30]{short}[r1]
39683 \end_layout
39684
39685 \begin_layout Standard
39686
39687 \size footnotesize
39688 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39689  r0]- 0x3 {short}
39690 \end_layout
39691
39692 \begin_layout Standard
39693
39694 \size footnotesize
39695 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39696 int}[r7 r0]
39697 \end_layout
39698
39699 \begin_layout Standard
39700
39701 \size footnotesize
39702 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39703  + 0x1 {short}
39704 \end_layout
39705
39706 \begin_layout Standard
39707
39708 \size footnotesize
39709 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39710  r6]- 0x1 {short}
39711 \end_layout
39712
39713 \begin_layout Standard
39714
39715 \size footnotesize
39716 Sample.c(19:38:47:1) goto _forcond_0($4)
39717 \end_layout
39718
39719 \begin_layout Standard
39720
39721 \size footnotesize
39722 Sample.c(19:39:48:0)_forbreak_0($7) :
39723 \end_layout
39724
39725 \begin_layout Standard
39726
39727 \size footnotesize
39728 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39729  + ITemp11 [lr19:40]{short}[r3]
39730 \end_layout
39731
39732 \begin_layout Standard
39733
39734 \size footnotesize
39735 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39736 \end_layout
39737
39738 \begin_layout Standard
39739
39740 \size footnotesize
39741 Sample.c(20:42:51:0)_return($8) :
39742 \end_layout
39743
39744 \begin_layout Standard
39745
39746 \size footnotesize
39747 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39748 \size default
39749
39750 \newline
39751
39752 \newline
39753 Finally the code generated for this function:
39754 \newline
39755
39756 \end_layout
39757
39758 \begin_layout Standard
39759
39760 \size footnotesize
39761 .area DSEG (DATA)
39762 \end_layout
39763
39764 \begin_layout Standard
39765
39766 \size footnotesize
39767 _p::
39768 \end_layout
39769
39770 \begin_layout Standard
39771
39772 \size footnotesize
39773 \InsetSpace ~
39774 \InsetSpace ~
39775 .ds 2
39776 \end_layout
39777
39778 \begin_layout Standard
39779
39780 \size footnotesize
39781 _gint::
39782 \end_layout
39783
39784 \begin_layout Standard
39785
39786 \size footnotesize
39787 \InsetSpace ~
39788 \InsetSpace ~
39789 .ds 2
39790 \end_layout
39791
39792 \begin_layout Standard
39793
39794 \size footnotesize
39795 ; sample.c 5
39796 \end_layout
39797
39798 \begin_layout Standard
39799
39800 \size footnotesize
39801 ; ----------------------------------------------
39802 \end_layout
39803
39804 \begin_layout Standard
39805
39806 \size footnotesize
39807 ; function function
39808 \end_layout
39809
39810 \begin_layout Standard
39811
39812 \size footnotesize
39813 ; ----------------------------------------------
39814 \end_layout
39815
39816 \begin_layout Standard
39817
39818 \size footnotesize
39819 _function:
39820 \end_layout
39821
39822 \begin_layout Standard
39823
39824 \size footnotesize
39825 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
39826 \end_layout
39827
39828 \begin_layout Standard
39829
39830 \size footnotesize
39831 \InsetSpace ~
39832 \InsetSpace ~
39833 mov r2,dpl
39834 \end_layout
39835
39836 \begin_layout Standard
39837
39838 \size footnotesize
39839 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39840 \end_layout
39841
39842 \begin_layout Standard
39843
39844 \size footnotesize
39845 \InsetSpace ~
39846 \InsetSpace ~
39847 mov ar0,r2
39848 \end_layout
39849
39850 \begin_layout Standard
39851
39852 \size footnotesize
39853 ;_whilecontinue_0($1) :
39854 \end_layout
39855
39856 \begin_layout Standard
39857
39858 \size footnotesize
39859 00101$:
39860 \end_layout
39861
39862 \begin_layout Standard
39863
39864 \size footnotesize
39865 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39866 \end_layout
39867
39868 \begin_layout Standard
39869
39870 \size footnotesize
39871 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39872 \end_layout
39873
39874 \begin_layout Standard
39875
39876 \size footnotesize
39877 \InsetSpace ~
39878 \InsetSpace ~
39879 mov ar2,@r0
39880 \end_layout
39881
39882 \begin_layout Standard
39883
39884 \size footnotesize
39885 \InsetSpace ~
39886 \InsetSpace ~
39887 inc r0
39888 \end_layout
39889
39890 \begin_layout Standard
39891
39892 \size footnotesize
39893 \InsetSpace ~
39894 \InsetSpace ~
39895 mov ar3,@r0
39896 \end_layout
39897
39898 \begin_layout Standard
39899
39900 \size footnotesize
39901 \InsetSpace ~
39902 \InsetSpace ~
39903 dec r0
39904 \end_layout
39905
39906 \begin_layout Standard
39907
39908 \size footnotesize
39909 \InsetSpace ~
39910 \InsetSpace ~
39911 mov a,r2
39912 \end_layout
39913
39914 \begin_layout Standard
39915
39916 \size footnotesize
39917 \InsetSpace ~
39918 \InsetSpace ~
39919 orl a,r3
39920 \end_layout
39921
39922 \begin_layout Standard
39923
39924 \size footnotesize
39925 \InsetSpace ~
39926 \InsetSpace ~
39927 jz 00103$
39928 \end_layout
39929
39930 \begin_layout Standard
39931
39932 \size footnotesize
39933 00114$:
39934 \end_layout
39935
39936 \begin_layout Standard
39937
39938 \size footnotesize
39939 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39940 \end_layout
39941
39942 \begin_layout Standard
39943
39944 \size footnotesize
39945 \InsetSpace ~
39946 \InsetSpace ~
39947 mov dpl,_p
39948 \end_layout
39949
39950 \begin_layout Standard
39951
39952 \size footnotesize
39953 \InsetSpace ~
39954 \InsetSpace ~
39955 mov dph,(_p + 1)
39956 \end_layout
39957
39958 \begin_layout Standard
39959
39960 \size footnotesize
39961 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39962 \end_layout
39963
39964 \begin_layout Standard
39965
39966 \size footnotesize
39967 \InsetSpace ~
39968 \InsetSpace ~
39969 mov a,#0x02
39970 \end_layout
39971
39972 \begin_layout Standard
39973
39974 \size footnotesize
39975 \InsetSpace ~
39976 \InsetSpace ~
39977 add a,_p
39978 \end_layout
39979
39980 \begin_layout Standard
39981
39982 \size footnotesize
39983 \InsetSpace ~
39984 \InsetSpace ~
39985 mov _p,a
39986 \end_layout
39987
39988 \begin_layout Standard
39989
39990 \size footnotesize
39991 \InsetSpace ~
39992 \InsetSpace ~
39993 clr a
39994 \end_layout
39995
39996 \begin_layout Standard
39997
39998 \size footnotesize
39999 \InsetSpace ~
40000 \InsetSpace ~
40001 addc a,(_p + 1)
40002 \end_layout
40003
40004 \begin_layout Standard
40005
40006 \size footnotesize
40007 \InsetSpace ~
40008 \InsetSpace ~
40009 mov (_p + 1),a
40010 \end_layout
40011
40012 \begin_layout Standard
40013
40014 \size footnotesize
40015 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40016 \end_layout
40017
40018 \begin_layout Standard
40019
40020 \size footnotesize
40021 \InsetSpace ~
40022 \InsetSpace ~
40023 movx a,@dptr
40024 \end_layout
40025
40026 \begin_layout Standard
40027
40028 \size footnotesize
40029 \InsetSpace ~
40030 \InsetSpace ~
40031 mov r2,a
40032 \end_layout
40033
40034 \begin_layout Standard
40035
40036 \size footnotesize
40037 \InsetSpace ~
40038 \InsetSpace ~
40039 inc dptr
40040 \end_layout
40041
40042 \begin_layout Standard
40043
40044 \size footnotesize
40045 \InsetSpace ~
40046 \InsetSpace ~
40047 movx a,@dptr
40048 \end_layout
40049
40050 \begin_layout Standard
40051
40052 \size footnotesize
40053 \InsetSpace ~
40054 \InsetSpace ~
40055 mov r3,a
40056 \end_layout
40057
40058 \begin_layout Standard
40059
40060 \size footnotesize
40061 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40062 \end_layout
40063
40064 \begin_layout Standard
40065
40066 \size footnotesize
40067 \InsetSpace ~
40068 \InsetSpace ~
40069 mov @r0,ar2
40070 \end_layout
40071
40072 \begin_layout Standard
40073
40074 \size footnotesize
40075 \InsetSpace ~
40076 \InsetSpace ~
40077 inc r0
40078 \end_layout
40079
40080 \begin_layout Standard
40081
40082 \size footnotesize
40083 \InsetSpace ~
40084 \InsetSpace ~
40085 mov @r0,ar3
40086 \end_layout
40087
40088 \begin_layout Standard
40089
40090 \size footnotesize
40091 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40092 \end_layout
40093
40094 \begin_layout Standard
40095
40096 \size footnotesize
40097 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40098 \end_layout
40099
40100 \begin_layout Standard
40101
40102 \size footnotesize
40103 ; 0x2 {short}
40104 \end_layout
40105
40106 \begin_layout Standard
40107
40108 \size footnotesize
40109 \InsetSpace ~
40110 \InsetSpace ~
40111 inc r0
40112 \end_layout
40113
40114 \begin_layout Standard
40115
40116 \size footnotesize
40117 ; goto _whilecontinue_0($1)
40118 \end_layout
40119
40120 \begin_layout Standard
40121
40122 \size footnotesize
40123 \InsetSpace ~
40124 \InsetSpace ~
40125 sjmp 00101$
40126 \end_layout
40127
40128 \begin_layout Standard
40129
40130 \size footnotesize
40131 ; _whilebreak_0($3) :
40132 \end_layout
40133
40134 \begin_layout Standard
40135
40136 \size footnotesize
40137 00103$:
40138 \end_layout
40139
40140 \begin_layout Standard
40141
40142 \size footnotesize
40143 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40144 \end_layout
40145
40146 \begin_layout Standard
40147
40148 \size footnotesize
40149 \InsetSpace ~
40150 \InsetSpace ~
40151 mov r2,#0x00
40152 \end_layout
40153
40154 \begin_layout Standard
40155
40156 \size footnotesize
40157 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40158 \end_layout
40159
40160 \begin_layout Standard
40161
40162 \size footnotesize
40163 \InsetSpace ~
40164 \InsetSpace ~
40165 mov r3,#0x00
40166 \end_layout
40167
40168 \begin_layout Standard
40169
40170 \size footnotesize
40171 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40172 \end_layout
40173
40174 \begin_layout Standard
40175
40176 \size footnotesize
40177 \InsetSpace ~
40178 \InsetSpace ~
40179 mov r4,#0x00
40180 \end_layout
40181
40182 \begin_layout Standard
40183
40184 \size footnotesize
40185 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40186 \end_layout
40187
40188 \begin_layout Standard
40189
40190 \size footnotesize
40191 \InsetSpace ~
40192 \InsetSpace ~
40193 mov r5,#0x0A
40194 \end_layout
40195
40196 \begin_layout Standard
40197
40198 \size footnotesize
40199 \InsetSpace ~
40200 \InsetSpace ~
40201 mov r6,#0x00
40202 \end_layout
40203
40204 \begin_layout Standard
40205
40206 \size footnotesize
40207 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40208 \end_layout
40209
40210 \begin_layout Standard
40211
40212 \size footnotesize
40213 \InsetSpace ~
40214 \InsetSpace ~
40215 mov r7,#0x1E
40216 \end_layout
40217
40218 \begin_layout Standard
40219
40220 \size footnotesize
40221 \InsetSpace ~
40222 \InsetSpace ~
40223 mov r0,#0x00
40224 \end_layout
40225
40226 \begin_layout Standard
40227
40228 \size footnotesize
40229 ; _forcond_0($4) :
40230 \end_layout
40231
40232 \begin_layout Standard
40233
40234 \size footnotesize
40235 00104$:
40236 \end_layout
40237
40238 \begin_layout Standard
40239
40240 \size footnotesize
40241 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40242 \end_layout
40243
40244 \begin_layout Standard
40245
40246 \size footnotesize
40247 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40248 \end_layout
40249
40250 \begin_layout Standard
40251
40252 \size footnotesize
40253 \InsetSpace ~
40254 \InsetSpace ~
40255 clr c
40256 \end_layout
40257
40258 \begin_layout Standard
40259
40260 \size footnotesize
40261 \InsetSpace ~
40262 \InsetSpace ~
40263 mov a,r4
40264 \end_layout
40265
40266 \begin_layout Standard
40267
40268 \size footnotesize
40269 \InsetSpace ~
40270 \InsetSpace ~
40271 xrl a,#0x80
40272 \end_layout
40273
40274 \begin_layout Standard
40275
40276 \size footnotesize
40277 \InsetSpace ~
40278 \InsetSpace ~
40279 subb a,#0x8a
40280 \end_layout
40281
40282 \begin_layout Standard
40283
40284 \size footnotesize
40285 \InsetSpace ~
40286 \InsetSpace ~
40287 jnc 00107$
40288 \end_layout
40289
40290 \begin_layout Standard
40291
40292 \size footnotesize
40293 00115$:
40294 \end_layout
40295
40296 \begin_layout Standard
40297
40298 \size footnotesize
40299 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40300 \end_layout
40301
40302 \begin_layout Standard
40303
40304 \size footnotesize
40305 ; iTemp21 [lr21:38]{short}[r4]
40306 \end_layout
40307
40308 \begin_layout Standard
40309
40310 \size footnotesize
40311 \InsetSpace ~
40312 \InsetSpace ~
40313 mov a,r4
40314 \end_layout
40315
40316 \begin_layout Standard
40317
40318 \size footnotesize
40319 \InsetSpace ~
40320 \InsetSpace ~
40321 add a,r2
40322 \end_layout
40323
40324 \begin_layout Standard
40325
40326 \size footnotesize
40327 \InsetSpace ~
40328 \InsetSpace ~
40329 mov r2,a
40330 \end_layout
40331
40332 \begin_layout Standard
40333
40334 \size footnotesize
40335 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40336 \end_layout
40337
40338 \begin_layout Standard
40339
40340 \size footnotesize
40341 \InsetSpace ~
40342 \InsetSpace ~
40343 mov b,#0x03
40344 \end_layout
40345
40346 \begin_layout Standard
40347
40348 \size footnotesize
40349 \InsetSpace ~
40350 \InsetSpace ~
40351 mov a,r4
40352 \end_layout
40353
40354 \begin_layout Standard
40355
40356 \size footnotesize
40357 \InsetSpace ~
40358 \InsetSpace ~
40359 mul ab
40360 \end_layout
40361
40362 \begin_layout Standard
40363
40364 \size footnotesize
40365 \InsetSpace ~
40366 \InsetSpace ~
40367 mov r1,a
40368 \end_layout
40369
40370 \begin_layout Standard
40371
40372 \size footnotesize
40373 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40374 \end_layout
40375
40376 \begin_layout Standard
40377
40378 \size footnotesize
40379 ; iTemp15 [lr29:30]{short}[r1]
40380 \end_layout
40381
40382 \begin_layout Standard
40383
40384 \size footnotesize
40385 \InsetSpace ~
40386 \InsetSpace ~
40387 add a,r3
40388 \end_layout
40389
40390 \begin_layout Standard
40391
40392 \size footnotesize
40393 \InsetSpace ~
40394 \InsetSpace ~
40395 mov r3,a
40396 \end_layout
40397
40398 \begin_layout Standard
40399
40400 \size footnotesize
40401 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40402 \end_layout
40403
40404 \begin_layout Standard
40405
40406 \size footnotesize
40407 \InsetSpace ~
40408 \InsetSpace ~
40409 mov a,r7
40410 \end_layout
40411
40412 \begin_layout Standard
40413
40414 \size footnotesize
40415 \InsetSpace ~
40416 \InsetSpace ~
40417 add a,#0xfd
40418 \end_layout
40419
40420 \begin_layout Standard
40421
40422 \size footnotesize
40423 \InsetSpace ~
40424 \InsetSpace ~
40425 mov r7,a
40426 \end_layout
40427
40428 \begin_layout Standard
40429
40430 \size footnotesize
40431 \InsetSpace ~
40432 \InsetSpace ~
40433 mov a,r0
40434 \end_layout
40435
40436 \begin_layout Standard
40437
40438 \size footnotesize
40439 \InsetSpace ~
40440 \InsetSpace ~
40441 addc a,#0xff
40442 \end_layout
40443
40444 \begin_layout Standard
40445
40446 \size footnotesize
40447 \InsetSpace ~
40448 \InsetSpace ~
40449 mov r0,a
40450 \end_layout
40451
40452 \begin_layout Standard
40453
40454 \size footnotesize
40455 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40456 \end_layout
40457
40458 \begin_layout Standard
40459
40460 \size footnotesize
40461 \InsetSpace ~
40462 \InsetSpace ~
40463 mov a,r7
40464 \end_layout
40465
40466 \begin_layout Standard
40467
40468 \size footnotesize
40469 \InsetSpace ~
40470 \InsetSpace ~
40471 add a,_gint
40472 \end_layout
40473
40474 \begin_layout Standard
40475
40476 \size footnotesize
40477 \InsetSpace ~
40478 \InsetSpace ~
40479 mov _gint,a
40480 \end_layout
40481
40482 \begin_layout Standard
40483
40484 \size footnotesize
40485 \InsetSpace ~
40486 \InsetSpace ~
40487 mov a,r0
40488 \end_layout
40489
40490 \begin_layout Standard
40491
40492 \size footnotesize
40493 \InsetSpace ~
40494 \InsetSpace ~
40495 addc a,(_gint + 1)
40496 \end_layout
40497
40498 \begin_layout Standard
40499
40500 \size footnotesize
40501 \InsetSpace ~
40502 \InsetSpace ~
40503 mov (_gint + 1),a
40504 \end_layout
40505
40506 \begin_layout Standard
40507
40508 \size footnotesize
40509 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40510 \end_layout
40511
40512 \begin_layout Standard
40513
40514 \size footnotesize
40515 \InsetSpace ~
40516 \InsetSpace ~
40517 inc r4
40518 \end_layout
40519
40520 \begin_layout Standard
40521
40522 \size footnotesize
40523 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40524 \end_layout
40525
40526 \begin_layout Standard
40527
40528 \size footnotesize
40529 \InsetSpace ~
40530 \InsetSpace ~
40531 dec r5
40532 \end_layout
40533
40534 \begin_layout Standard
40535
40536 \size footnotesize
40537 \InsetSpace ~
40538 \InsetSpace ~
40539 cjne r5,#0xff,00104$
40540 \end_layout
40541
40542 \begin_layout Standard
40543
40544 \size footnotesize
40545 \InsetSpace ~
40546 \InsetSpace ~
40547 dec r6
40548 \end_layout
40549
40550 \begin_layout Standard
40551
40552 \size footnotesize
40553 ; goto _forcond_0($4)
40554 \end_layout
40555
40556 \begin_layout Standard
40557
40558 \size footnotesize
40559 \InsetSpace ~
40560 \InsetSpace ~
40561 sjmp 00104$
40562 \end_layout
40563
40564 \begin_layout Standard
40565
40566 \size footnotesize
40567 ; _forbreak_0($7) :
40568 \end_layout
40569
40570 \begin_layout Standard
40571
40572 \size footnotesize
40573 00107$:
40574 \end_layout
40575
40576 \begin_layout Standard
40577
40578 \size footnotesize
40579 ; ret iTemp24 [lr40:41]{short}
40580 \end_layout
40581
40582 \begin_layout Standard
40583
40584 \size footnotesize
40585 \InsetSpace ~
40586 \InsetSpace ~
40587 mov a,r3
40588 \end_layout
40589
40590 \begin_layout Standard
40591
40592 \size footnotesize
40593 \InsetSpace ~
40594 \InsetSpace ~
40595 add a,r2
40596 \end_layout
40597
40598 \begin_layout Standard
40599
40600 \size footnotesize
40601 \InsetSpace ~
40602 \InsetSpace ~
40603 mov dpl,a
40604 \end_layout
40605
40606 \begin_layout Standard
40607
40608 \size footnotesize
40609 ; _return($8) :
40610 \end_layout
40611
40612 \begin_layout Standard
40613
40614 \size footnotesize
40615 00108$:
40616 \end_layout
40617
40618 \begin_layout Standard
40619
40620 \size footnotesize
40621 \InsetSpace ~
40622 \InsetSpace ~
40623 ret
40624 \newline
40625
40626 \end_layout
40627
40628 \begin_layout Section
40629 A few words about basic block successors, predecessors and dominators
40630 \end_layout
40631
40632 \begin_layout Standard
40633 Successors are basic blocks
40634 \begin_inset LatexCommand \index{Basic blocks}
40635
40636 \end_inset
40637
40638  that might execute after this basic block.
40639 \newline
40640 Predecessors are basic blocks
40641  that might execute before reaching this basic block.
40642 \newline
40643 Dominators are basic
40644  blocks that WILL execute before reaching this basic block.
40645 \newline
40646
40647 \end_layout
40648
40649 \begin_layout Standard
40650 [basic block 1]
40651 \end_layout
40652
40653 \begin_layout Standard
40654 if (something)
40655 \end_layout
40656
40657 \begin_layout Standard
40658 \InsetSpace ~
40659 \InsetSpace ~
40660 \InsetSpace ~
40661 \InsetSpace ~
40662 [basic block 2]
40663 \end_layout
40664
40665 \begin_layout Standard
40666 else
40667 \end_layout
40668
40669 \begin_layout Standard
40670 \InsetSpace ~
40671 \InsetSpace ~
40672 \InsetSpace ~
40673 \InsetSpace ~
40674 [basic block 3]
40675 \end_layout
40676
40677 \begin_layout Standard
40678 [basic block 4]
40679 \newline
40680
40681 \end_layout
40682
40683 \begin_layout Standard
40684 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40685 \end_layout
40686
40687 \begin_layout Standard
40688 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40689 \end_layout
40690
40691 \begin_layout Standard
40692 c) domVect of [BB4] = BB1 ...
40693  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40694  was executed.
40695 \end_layout
40696
40697 \begin_layout Chapter
40698 Acknowledgments
40699 \end_layout
40700
40701 \begin_layout Standard
40702 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40703
40704 \end_inset
40705
40706
40707 \newline
40708
40709 \newline
40710
40711 \emph on
40712 Thanks to all the other volunteer developers who have helped with coding,
40713  testing, web-page creation, distribution sets, etc.
40714  You know who you are :-)
40715 \emph default
40716
40717 \newline
40718
40719 \newline
40720
40721 \emph on
40722 Thanks to Sourceforge 
40723 \begin_inset LatexCommand \url{http://www.sf.net}
40724
40725 \end_inset
40726
40727  which has hosted the project since 1999 and donates significant download
40728  bandwidth.
40729 \emph default
40730
40731 \newline
40732
40733 \newline
40734
40735 \emph on
40736 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40737  cycles and bandwidth for snapshot builds.
40738 \newline
40739
40740 \end_layout
40741
40742 \begin_layout Standard
40743 This document was initially written by Sandeep Dutta
40744 \end_layout
40745
40746 \begin_layout Standard
40747 All product names mentioned herein may be trademarks
40748 \begin_inset LatexCommand \index{Trademarks}
40749
40750 \end_inset
40751
40752  of their respective companies.
40753  
40754 \end_layout
40755
40756 \begin_layout Section*
40757 Alphabetical index
40758 \end_layout
40759
40760 \begin_layout Standard
40761 To avoid confusion, the installation and building options for SDCC itself
40762  (chapter 2) are not part of the index.
40763 \end_layout
40764
40765 \begin_layout Standard
40766 \begin_inset LatexCommand \printindex{}
40767
40768 \end_inset
40769
40770
40771 \end_layout
40772
40773 \end_body
40774 \end_document