* doc/sdccman.lyx: added description of --no-std-crt0 gbz80 command line option
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.5 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes would otherwise result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.8.0
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc.) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the -
840 \begin_inset ERT
841 status collapsed
842
843 \begin_layout Standard
844
845
846 \backslash
847 /
848 \end_layout
849
850 \end_inset
851
852 -short-is-8bits commandline option (see 
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
854
855 \end_inset
856
857 ).
858 \end_layout
859
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862  files are stored is now in /usr/local/share.
863 \end_layout
864
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
868
869 \end_inset
870
871  functions are casted to int unless explicitly casted and 
872 \series bold
873 -
874 \begin_inset ERT
875 status collapsed
876
877 \begin_layout Standard
878
879
880 \backslash
881 /
882 \end_layout
883
884 \end_inset
885
886 -std-c89
887 \begin_inset LatexCommand \index{-\/-std-c89}
888
889 \end_inset
890
891  
892 \series default
893 and
894 \series bold
895  -
896 \begin_inset ERT
897 status collapsed
898
899 \begin_layout Standard
900
901
902 \backslash
903 /
904 \end_layout
905
906 \end_inset
907
908 -std-c99
909 \begin_inset LatexCommand \index{-\/-std-c99}
910
911 \end_inset
912
913
914 \series default
915  command line option are not defined 
916 \begin_inset Marginal
917 status collapsed
918
919 \begin_layout Standard
920
921 \series bold
922 \InsetSpace ~
923 !
924 \end_layout
925
926 \end_inset
927
928 , e.g.: 
929 \newline
930
931 \family typewriter
932 \InsetSpace ~
933 \InsetSpace ~
934 char a=3;
935 \newline
936 \InsetSpace ~
937 \InsetSpace ~
938 printf ("%d %c
939 \backslash
940 n", a, (char)a);
941 \family default
942
943 \newline
944  will push a as an int and as a char resp if
945 \series bold
946  -
947 \begin_inset ERT
948 status collapsed
949
950 \begin_layout Standard
951
952
953 \backslash
954 /
955 \end_layout
956
957 \end_inset
958
959 -std-c89
960 \begin_inset LatexCommand \index{-\/-std-c89}
961
962 \end_inset
963
964  
965 \series default
966 and
967 \series bold
968  -
969 \begin_inset ERT
970 status collapsed
971
972 \begin_layout Standard
973
974
975 \backslash
976 /
977 \end_layout
978
979 \end_inset
980
981 -std-c99
982 \begin_inset LatexCommand \index{-\/-std-c99}
983
984 \end_inset
985
986
987 \series default
988  command line options are not defined,
989 \newline
990  will push a as two ints if
991 \series bold
992  -
993 \begin_inset ERT
994 status collapsed
995
996 \begin_layout Standard
997
998
999 \backslash
1000 /
1001 \end_layout
1002
1003 \end_inset
1004
1005 -std-c89
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1007
1008 \end_inset
1009
1010  
1011 \series default
1012 or
1013 \series bold
1014  -
1015 \begin_inset ERT
1016 status collapsed
1017
1018 \begin_layout Standard
1019
1020
1021 \backslash
1022 /
1023 \end_layout
1024
1025 \end_inset
1026
1027 -std-c99
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1029
1030 \end_inset
1031
1032
1033 \series default
1034  command line option is defined.
1035 \end_layout
1036
1037 \begin_layout Itemize
1038 option -
1039 \begin_inset ERT
1040 status collapsed
1041
1042 \begin_layout Standard
1043
1044
1045 \backslash
1046 /
1047 \end_layout
1048
1049 \end_inset
1050
1051 -regextend has been removed.
1052 \end_layout
1053
1054 \begin_layout Itemize
1055 option -
1056 \begin_inset ERT
1057 status collapsed
1058
1059 \begin_layout Standard
1060
1061
1062 \backslash
1063 /
1064 \end_layout
1065
1066 \end_inset
1067
1068 -noregparms has been removed.
1069 \end_layout
1070
1071 \begin_layout Itemize
1072 option -
1073 \begin_inset ERT
1074 status collapsed
1075
1076 \begin_layout Standard
1077
1078
1079 \backslash
1080 /
1081 \end_layout
1082
1083 \end_inset
1084
1085 -stack-after-data has been removed.
1086 \end_layout
1087
1088 \begin_layout Itemize
1089 bit
1090 \begin_inset LatexCommand \index{bit}
1091
1092 \end_inset
1093
1094  and sbit
1095 \begin_inset LatexCommand \index{sbit}
1096
1097 \end_inset
1098
1099
1100 \begin_inset LatexCommand \index{\_\_sbit}
1101
1102 \end_inset
1103
1104  types now consistently behave like the C99 _Bool type with respect to type
1105  conversion
1106 \begin_inset LatexCommand \index{type conversion}
1107
1108 \end_inset
1109
1110
1111 \begin_inset LatexCommand \index{type promotion}
1112
1113 \end_inset
1114
1115 .
1116  The most common incompatibility resulting from this change is related to
1117  bit toggling
1118 \begin_inset LatexCommand \index{Bit toggling}
1119
1120 \end_inset
1121
1122  idioms, e.g.:
1123 \newline
1124
1125 \family typewriter
1126 \InsetSpace ~
1127 \InsetSpace ~
1128 bit b;
1129 \newline
1130 \InsetSpace ~
1131 \InsetSpace ~
1132 b = ~
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1134
1135 \end_inset
1136
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1139 status collapsed
1140
1141 \begin_layout Standard
1142
1143 \series bold
1144 \InsetSpace ~
1145 !
1146 \end_layout
1147
1148 \end_inset
1149
1150
1151 \newline
1152 \InsetSpace ~
1153 \InsetSpace ~
1154 b = !b; /* toggles b */
1155 \newline
1156
1157 \family default
1158 In previous versions, both forms would have toggled the bit.
1159 \end_layout
1160
1161 \begin_layout Standard
1162
1163 \emph on
1164 <pending: more incompatibilities?>
1165 \end_layout
1166
1167 \begin_layout Section
1168 System Requirements
1169 \end_layout
1170
1171 \begin_layout Standard
1172 What do you need before you start installation of SDCC? A computer, and
1173  a desire to compute.
1174  The preferred method of installation is to compile SDCC from source using
1175  GNU gcc and make.
1176  For Windows some pre-compiled binary distributions are available for your
1177  convenience.
1178  You should have some experience with command line tools and compiler use.
1179 \end_layout
1180
1181 \begin_layout Section
1182 Other Resources
1183 \end_layout
1184
1185 \begin_layout Standard
1186 The SDCC home page at 
1187 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1188
1189 \end_inset
1190
1191  is a great place to find distribution sets.
1192  You can also find links to the user mailing lists that offer help or discuss
1193  SDCC with other SDCC users.
1194  Web links to other SDCC related sites can also be found here.
1195  This document can be found in the DOC directory of the source package as
1196  a text or HTML file.
1197  A pdf version of this document is available at 
1198 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1199
1200 \end_inset
1201
1202 .
1203  Some of the other tools (simulator and assembler) included with SDCC contain
1204  their own documentation and can be found in the source distribution.
1205  If you want the latest unreleased software, the complete source package
1206  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1207 sdcc/trunk/sdcc.
1208 \end_layout
1209
1210 \begin_layout Section
1211 Wishes for the future
1212 \end_layout
1213
1214 \begin_layout Standard
1215 There are (and always will be) some things that could be done.
1216  Here are some I can think of:
1217 \newline
1218
1219 \end_layout
1220
1221 \begin_layout Standard
1222
1223 \family typewriter
1224 char KernelFunction3(char p) at 0x340;
1225 \newline
1226
1227 \end_layout
1228
1229 \begin_layout Standard
1230
1231 \family typewriter
1232 better code banking
1233 \begin_inset LatexCommand \index{code banking (limited support)}
1234
1235 \end_inset
1236
1237  support for mcs51
1238 \newline
1239
1240 \newline
1241
1242 \family default
1243 If you can think of some more, please see the section 
1244 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1245
1246 \end_inset
1247
1248  about filing feature requests
1249 \begin_inset LatexCommand \index{Requesting features}
1250
1251 \end_inset
1252
1253
1254 \begin_inset LatexCommand \index{Feature request}
1255
1256 \end_inset
1257
1258 .
1259 \newline
1260
1261 \end_layout
1262
1263 \begin_layout Chapter
1264 Installing SDCC
1265 \begin_inset LatexCommand \index{Installation}
1266
1267 \end_inset
1268
1269
1270 \end_layout
1271
1272 \begin_layout Standard
1273 For most users it is sufficient to skip to either section 
1274 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1275
1276 \end_inset
1277
1278  (Unix) or section 
1279 \begin_inset LatexCommand \ref{sub:Windows-Install}
1280
1281 \end_inset
1282
1283  (Windows).
1284  More detailed instructions follow below.
1285 \end_layout
1286
1287 \begin_layout Section
1288 Configure Options
1289 \begin_inset LatexCommand \index{Options SDCC configuration}
1290
1291 \end_inset
1292
1293
1294 \end_layout
1295
1296 \begin_layout Standard
1297 The install paths, search paths and other options are defined when running
1298  'configure'.
1299  The defaults can be overridden by:
1300 \end_layout
1301
1302 \begin_layout List
1303 \labelwidthstring 00.00.0000
1304 -
1305 \begin_inset ERT
1306 status collapsed
1307
1308 \begin_layout Standard
1309
1310
1311 \backslash
1312 /
1313 \end_layout
1314
1315 \end_inset
1316
1317 -prefix see table below
1318 \end_layout
1319
1320 \begin_layout List
1321 \labelwidthstring 00.00.0000
1322 -
1323 \begin_inset ERT
1324 status collapsed
1325
1326 \begin_layout Standard
1327
1328
1329 \backslash
1330 /
1331 \end_layout
1332
1333 \end_inset
1334
1335 -exec_prefix see table below
1336 \end_layout
1337
1338 \begin_layout List
1339 \labelwidthstring 00.00.0000
1340 -
1341 \begin_inset ERT
1342 status collapsed
1343
1344 \begin_layout Standard
1345
1346
1347 \backslash
1348 /
1349 \end_layout
1350
1351 \end_inset
1352
1353 -bindir see table below
1354 \end_layout
1355
1356 \begin_layout List
1357 \labelwidthstring 00.00.0000
1358 -
1359 \begin_inset ERT
1360 status collapsed
1361
1362 \begin_layout Standard
1363
1364
1365 \backslash
1366 /
1367 \end_layout
1368
1369 \end_inset
1370
1371 -datadir see table below
1372 \end_layout
1373
1374 \begin_layout List
1375 \labelwidthstring 00.00.0000
1376 -
1377 \begin_inset ERT
1378 status collapsed
1379
1380 \begin_layout Standard
1381
1382
1383 \backslash
1384 /
1385 \end_layout
1386
1387 \end_inset
1388
1389 -datarootdir see table below
1390 \newline
1391
1392 \end_layout
1393
1394 \begin_layout List
1395 \labelwidthstring 00.00.0000
1396 \InsetSpace ~
1397 \InsetSpace ~
1398 docdir environment variable, see table below
1399 \end_layout
1400
1401 \begin_layout List
1402 \labelwidthstring 00.00.0000
1403 \InsetSpace ~
1404 \InsetSpace ~
1405 include_dir_suffix environment variable, see table below
1406 \end_layout
1407
1408 \begin_layout List
1409 \labelwidthstring 00.00.0000
1410 \InsetSpace ~
1411 \InsetSpace ~
1412 lib_dir_suffix environment variable, see table below
1413 \end_layout
1414
1415 \begin_layout List
1416 \labelwidthstring 00.00.0000
1417 \InsetSpace ~
1418 \InsetSpace ~
1419 sdccconf_h_dir_separator environment variable, either / or 
1420 \backslash
1421
1422 \backslash
1423  makes sense here.
1424  This character will only be used in sdccconf.h; don't forget it's a C-header,
1425  therefore a double-backslash is needed there.
1426 \newline
1427
1428 \end_layout
1429
1430 \begin_layout List
1431 \labelwidthstring 00.00.0000
1432 -
1433 \begin_inset ERT
1434 status collapsed
1435
1436 \begin_layout Standard
1437
1438
1439 \backslash
1440 /
1441 \end_layout
1442
1443 \end_inset
1444
1445 -disable-mcs51-port Excludes the Intel mcs51 port
1446 \end_layout
1447
1448 \begin_layout List
1449 \labelwidthstring 00.00.0000
1450 -
1451 \begin_inset ERT
1452 status collapsed
1453
1454 \begin_layout Standard
1455
1456
1457 \backslash
1458 /
1459 \end_layout
1460
1461 \end_inset
1462
1463 -disable-gbz80-port Excludes the Gameboy gbz80 port
1464 \end_layout
1465
1466 \begin_layout List
1467 \labelwidthstring 00.00.0000
1468 -
1469 \begin_inset ERT
1470 status collapsed
1471
1472 \begin_layout Standard
1473
1474
1475 \backslash
1476 /
1477 \end_layout
1478
1479 \end_inset
1480
1481 -disable-z80-port Excludes the z80 port
1482 \end_layout
1483
1484 \begin_layout List
1485 \labelwidthstring 00.00.0000
1486 -
1487 \begin_inset ERT
1488 status collapsed
1489
1490 \begin_layout Standard
1491
1492
1493 \backslash
1494 /
1495 \end_layout
1496
1497 \end_inset
1498
1499 -disable-avr-port Excludes the AVR port
1500 \end_layout
1501
1502 \begin_layout List
1503 \labelwidthstring 00.00.0000
1504 -
1505 \begin_inset ERT
1506 status collapsed
1507
1508 \begin_layout Standard
1509
1510
1511 \backslash
1512 /
1513 \end_layout
1514
1515 \end_inset
1516
1517 -disable-ds390-port Excludes the DS390 port
1518 \end_layout
1519
1520 \begin_layout List
1521 \labelwidthstring 00.00.0000
1522 -
1523 \begin_inset ERT
1524 status collapsed
1525
1526 \begin_layout Standard
1527
1528
1529 \backslash
1530 /
1531 \end_layout
1532
1533 \end_inset
1534
1535 -disable-hc08-port Excludes the HC08 port
1536 \end_layout
1537
1538 \begin_layout List
1539 \labelwidthstring 00.00.0000
1540 -
1541 \begin_inset ERT
1542 status collapsed
1543
1544 \begin_layout Standard
1545
1546
1547 \backslash
1548 /
1549 \end_layout
1550
1551 \end_inset
1552
1553 -disable-pic-port Excludes the PIC14 port
1554 \end_layout
1555
1556 \begin_layout List
1557 \labelwidthstring 00.00.0000
1558 -
1559 \begin_inset ERT
1560 status collapsed
1561
1562 \begin_layout Standard
1563
1564
1565 \backslash
1566 /
1567 \end_layout
1568
1569 \end_inset
1570
1571 -disable-pic16-port Excludes the PIC16 port
1572 \end_layout
1573
1574 \begin_layout List
1575 \labelwidthstring 00.00.0000
1576 -
1577 \begin_inset ERT
1578 status collapsed
1579
1580 \begin_layout Standard
1581
1582
1583 \backslash
1584 /
1585 \end_layout
1586
1587 \end_inset
1588
1589 -disable-xa51-port Excludes the XA51 port
1590 \end_layout
1591
1592 \begin_layout List
1593 \labelwidthstring 00.00.0000
1594 -
1595 \begin_inset ERT
1596 status collapsed
1597
1598 \begin_layout Standard
1599
1600
1601 \backslash
1602 /
1603 \end_layout
1604
1605 \end_inset
1606
1607 -disable-ucsim Disables configuring and building of ucsim
1608 \end_layout
1609
1610 \begin_layout List
1611 \labelwidthstring 00.00.0000
1612 -
1613 \begin_inset ERT
1614 status collapsed
1615
1616 \begin_layout Standard
1617
1618
1619 \backslash
1620 /
1621 \end_layout
1622
1623 \end_inset
1624
1625 -disable-device-lib Disables automatically building device libraries
1626 \end_layout
1627
1628 \begin_layout List
1629 \labelwidthstring 00.00.0000
1630 -
1631 \begin_inset ERT
1632 status collapsed
1633
1634 \begin_layout Standard
1635
1636
1637 \backslash
1638 /
1639 \end_layout
1640
1641 \end_inset
1642
1643 -disable-packihx Disables building packihx
1644 \newline
1645
1646 \end_layout
1647
1648 \begin_layout List
1649 \labelwidthstring 00.00.0000
1650 -
1651 \begin_inset ERT
1652 status collapsed
1653
1654 \begin_layout Standard
1655
1656
1657 \backslash
1658 /
1659 \end_layout
1660
1661 \end_inset
1662
1663 -enable-doc Build pdf, html and txt files from the lyx sources
1664 \end_layout
1665
1666 \begin_layout List
1667 \labelwidthstring 00.00.0000
1668 -
1669 \begin_inset ERT
1670 status collapsed
1671
1672 \begin_layout Standard
1673
1674
1675 \backslash
1676 /
1677 \end_layout
1678
1679 \end_inset
1680
1681 -enable-libgc Use the Bohem memory allocator.
1682  Lower runtime footprint.
1683 \end_layout
1684
1685 \begin_layout Standard
1686 Furthermore the environment variables CC, CFLAGS, ...
1687  the tools and their arguments can be influenced.
1688  Please see `configure -
1689 \begin_inset ERT
1690 status collapsed
1691
1692 \begin_layout Standard
1693
1694
1695 \backslash
1696 /
1697 \end_layout
1698
1699 \end_inset
1700
1701 -help' and the man/info pages of `configure' for details.
1702 \newline
1703
1704 \newline
1705 The names of the
1706  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1707 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1708  SDCC_LIB_NAME are defined by `configure' too.
1709  At the moment it's not possible to change the default settings (it was
1710  simply never required).
1711 \newline
1712
1713 \newline
1714 These configure options are compiled into the binaries,
1715  and can only be changed by rerunning 'configure' and recompiling SDCC.
1716  The configure options are written in 
1717 \emph on
1718 italics
1719 \emph default
1720  to distinguish them from run time environment variables (see section search
1721  paths).
1722 \newline
1723
1724 \newline
1725 The settings for 
1726 \begin_inset Quotes sld
1727 \end_inset
1728
1729 Win32 builds
1730 \begin_inset Quotes srd
1731 \end_inset
1732
1733  are used by the SDCC team to build the official Win32 binaries.
1734  The SDCC team uses Mingw32 to build the official Windows binaries, because
1735  it's
1736 \end_layout
1737
1738 \begin_layout Enumerate
1739 open source, 
1740 \end_layout
1741
1742 \begin_layout Enumerate
1743 a gcc compiler and last but not least
1744 \end_layout
1745
1746 \begin_layout Enumerate
1747 the binaries can be built by cross compiling on SDCC Distributed Compile
1748  Farm.
1749 \end_layout
1750
1751 \begin_layout Standard
1752 See the examples, how to pass the Win32 settings to 'configure'.
1753  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1754  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1755  for Win32.
1756 \newline
1757
1758 \newline
1759 These defaults are:
1760 \newline
1761
1762 \end_layout
1763
1764 \begin_layout Standard
1765 \align center
1766 \begin_inset Tabular
1767 <lyxtabular version="3" rows="9" columns="3">
1768 <features>
1769 <column alignment="block" valignment="top" leftline="true" width="0in">
1770 <column alignment="block" valignment="top" leftline="true" width="0in">
1771 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1772 <row topline="true" bottomline="true">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 \begin_inset Text
1775
1776 \begin_layout Standard
1777 Variable
1778 \end_layout
1779
1780 \end_inset
1781 </cell>
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786 default
1787 \end_layout
1788
1789 \end_inset
1790 </cell>
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1792 \begin_inset Text
1793
1794 \begin_layout Standard
1795 Win32 builds
1796 \end_layout
1797
1798 \end_inset
1799 </cell>
1800 </row>
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1803 \begin_inset Text
1804
1805 \begin_layout Standard
1806
1807 \emph on
1808 PREFIX
1809 \end_layout
1810
1811 \end_inset
1812 </cell>
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_inset Text
1815
1816 \begin_layout Standard
1817 /usr/local
1818 \end_layout
1819
1820 \end_inset
1821 </cell>
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1823 \begin_inset Text
1824
1825 \begin_layout Standard
1826
1827 \backslash
1828 sdcc
1829 \end_layout
1830
1831 \end_inset
1832 </cell>
1833 </row>
1834 <row topline="true">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1836 \begin_inset Text
1837
1838 \begin_layout Standard
1839
1840 \emph on
1841 EXEC_PREFIX
1842 \end_layout
1843
1844 \end_inset
1845 </cell>
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1847 \begin_inset Text
1848
1849 \begin_layout Standard
1850
1851 \emph on
1852 $PREFIX
1853 \end_layout
1854
1855 \end_inset
1856 </cell>
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1858 \begin_inset Text
1859
1860 \begin_layout Standard
1861
1862 \emph on
1863 $PREFIX
1864 \end_layout
1865
1866 \end_inset
1867 </cell>
1868 </row>
1869 <row topline="true">
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 \begin_inset Text
1872
1873 \begin_layout Standard
1874
1875 \emph on
1876 BINDIR
1877 \end_layout
1878
1879 \end_inset
1880 </cell>
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1882 \begin_inset Text
1883
1884 \begin_layout Standard
1885
1886 \emph on
1887 $EXEC_PREFIX
1888 \emph default
1889 /bin
1890 \end_layout
1891
1892 \end_inset
1893 </cell>
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1895 \begin_inset Text
1896
1897 \begin_layout Standard
1898
1899 \emph on
1900 $EXEC_PREFIX
1901 \emph default
1902
1903 \backslash
1904 bin
1905 \end_layout
1906
1907 \end_inset
1908 </cell>
1909 </row>
1910 <row topline="true">
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915
1916 \emph on
1917 DATADIR
1918 \end_layout
1919
1920 \end_inset
1921 </cell>
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1923 \begin_inset Text
1924
1925 \begin_layout Standard
1926
1927 \emph on
1928 $DATAROOTDIR
1929 \end_layout
1930
1931 \end_inset
1932 </cell>
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1934 \begin_inset Text
1935
1936 \begin_layout Standard
1937
1938 \emph on
1939 $DATAROOTDIR
1940 \end_layout
1941
1942 \end_inset
1943 </cell>
1944 </row>
1945 <row topline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1947 \begin_inset Text
1948
1949 \begin_layout Standard
1950
1951 \emph on
1952 DATAROOTDIR
1953 \end_layout
1954
1955 \end_inset
1956 </cell>
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961
1962 \emph on
1963 $PREFIX
1964 \emph default
1965 /share
1966 \end_layout
1967
1968 \end_inset
1969 </cell>
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1971 \begin_inset Text
1972
1973 \begin_layout Standard
1974
1975 \emph on
1976 $PREFIX
1977 \end_layout
1978
1979 \end_inset
1980 </cell>
1981 </row>
1982 <row topline="true">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1984 \begin_inset Text
1985
1986 \begin_layout Standard
1987
1988 \emph on
1989 DOCDIR
1990 \end_layout
1991
1992 \end_inset
1993 </cell>
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1995 \begin_inset Text
1996
1997 \begin_layout Standard
1998
1999 \emph on
2000 $DATAROOTDIR
2001 \emph default
2002 /sdcc/doc
2003 \end_layout
2004
2005 \end_inset
2006 </cell>
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 $DATAROOTDIR
2014 \emph default
2015
2016 \backslash
2017 doc
2018 \end_layout
2019
2020 \end_inset
2021 </cell>
2022 </row>
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \begin_layout Standard
2028
2029 \emph on
2030 INCLUDE_DIR_SUFFIX
2031 \end_layout
2032
2033 \end_inset
2034 </cell>
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 \begin_inset Text
2037
2038 \begin_layout Standard
2039 sdcc/include
2040 \end_layout
2041
2042 \end_inset
2043 </cell>
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \begin_layout Standard
2048 include
2049 \end_layout
2050
2051 \end_inset
2052 </cell>
2053 </row>
2054 <row topline="true" bottomline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 \begin_inset Text
2057
2058 \begin_layout Standard
2059
2060 \emph on
2061 LIB_DIR_SUFFIX
2062 \end_layout
2063
2064 \end_inset
2065 </cell>
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2067 \begin_inset Text
2068
2069 \begin_layout Standard
2070 sdcc/lib
2071 \end_layout
2072
2073 \end_inset
2074 </cell>
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2076 \begin_inset Text
2077
2078 \begin_layout Standard
2079 lib
2080 \end_layout
2081
2082 \end_inset
2083 </cell>
2084 </row>
2085 </lyxtabular>
2086
2087 \end_inset
2088
2089
2090 \newline
2091
2092 \end_layout
2093
2094 \begin_layout Standard
2095 \noindent
2096 'configure' also computes relative paths.
2097  This is needed for full relocatability of a binary package and to complete
2098  search paths (see section search paths below):
2099 \newline
2100  
2101 \end_layout
2102
2103 \begin_layout Standard
2104 \align center
2105 \begin_inset Tabular
2106 <lyxtabular version="3" rows="4" columns="3">
2107 <features>
2108 <column alignment="block" valignment="top" leftline="true" width="0in">
2109 <column alignment="block" valignment="top" leftline="true" width="0in">
2110 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2113 \begin_inset Text
2114
2115 \begin_layout Standard
2116 Variable (computed)
2117 \end_layout
2118
2119 \end_inset
2120 </cell>
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2122 \begin_inset Text
2123
2124 \begin_layout Standard
2125 default
2126 \end_layout
2127
2128 \end_inset
2129 </cell>
2130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2131 \begin_inset Text
2132
2133 \begin_layout Standard
2134 Win32 builds
2135 \end_layout
2136
2137 \end_inset
2138 </cell>
2139 </row>
2140 <row topline="true" bottomline="true">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 \begin_inset Text
2143
2144 \begin_layout Standard
2145
2146 \emph on
2147 BIN2DATA_DIR
2148 \end_layout
2149
2150 \end_inset
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \begin_layout Standard
2156 ../share
2157 \end_layout
2158
2159 \end_inset
2160 </cell>
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2162 \begin_inset Text
2163
2164 \begin_layout Standard
2165 ..
2166 \end_layout
2167
2168 \end_inset
2169 </cell>
2170 </row>
2171 <row bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_inset Text
2174
2175 \begin_layout Standard
2176
2177 \emph on
2178 PREFIX2BIN_DIR
2179 \end_layout
2180
2181 \end_inset
2182 </cell>
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2184 \begin_inset Text
2185
2186 \begin_layout Standard
2187 bin
2188 \end_layout
2189
2190 \end_inset
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \begin_layout Standard
2196 bin
2197 \end_layout
2198
2199 \end_inset
2200 </cell>
2201 </row>
2202 <row bottomline="true">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2204 \begin_inset Text
2205
2206 \begin_layout Standard
2207
2208 \emph on
2209 PREFIX2DATA_DIR
2210 \end_layout
2211
2212 \end_inset
2213 </cell>
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2215 \begin_inset Text
2216
2217 \begin_layout Standard
2218 share/sdcc
2219 \end_layout
2220
2221 \end_inset
2222 </cell>
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2224 \begin_inset Text
2225
2226 \begin_layout Standard
2227
2228 \end_layout
2229
2230 \end_inset
2231 </cell>
2232 </row>
2233 </lyxtabular>
2234
2235 \end_inset
2236
2237
2238 \newline
2239
2240 \end_layout
2241
2242 \begin_layout Standard
2243 \noindent
2244 Examples:
2245 \end_layout
2246
2247 \begin_layout LyX-Code
2248 ./configure
2249 \newline
2250 ./configure -
2251 \begin_inset ERT
2252 status collapsed
2253
2254 \begin_layout Standard
2255
2256
2257 \backslash
2258 /
2259 \end_layout
2260
2261 \end_inset
2262
2263 -prefix=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267 /usr/bin
2268 \begin_inset Quotes srd
2269 \end_inset
2270
2271  -
2272 \begin_inset ERT
2273 status collapsed
2274
2275 \begin_layout Standard
2276
2277
2278 \backslash
2279 /
2280 \end_layout
2281
2282 \end_inset
2283
2284 -datarootdir=
2285 \begin_inset Quotes srd
2286 \end_inset
2287
2288 /usr/share
2289 \begin_inset Quotes srd
2290 \end_inset
2291
2292
2293 \newline
2294 ./configure -
2295 \begin_inset ERT
2296 status collapsed
2297
2298 \begin_layout Standard
2299
2300
2301 \backslash
2302 /
2303 \end_layout
2304
2305 \end_inset
2306
2307 -disable-avr-port -
2308 \begin_inset ERT
2309 status collapsed
2310
2311 \begin_layout Standard
2312
2313
2314 \backslash
2315 /
2316 \end_layout
2317
2318 \end_inset
2319
2320 -disable-xa51-port
2321 \end_layout
2322
2323 \begin_layout Standard
2324 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2325 32'):
2326 \end_layout
2327
2328 \begin_layout LyX-Code
2329 ./configure 
2330 \backslash
2331
2332 \newline
2333 CC=
2334 \begin_inset Quotes srd
2335 \end_inset
2336
2337 i586-mingw32msvc-gcc
2338 \begin_inset Quotes srd
2339 \end_inset
2340
2341  CXX=
2342 \begin_inset Quotes srd
2343 \end_inset
2344
2345 i586-mingw32msvc-g++
2346 \begin_inset Quotes srd
2347 \end_inset
2348
2349  
2350 \backslash
2351  
2352 \newline
2353 RANLIB=
2354 \begin_inset Quotes srd
2355 \end_inset
2356
2357 i586-mingw32msvc-ranlib
2358 \begin_inset Quotes srd
2359 \end_inset
2360
2361  
2362 \backslash
2363
2364 \newline
2365 STRIP=
2366 \begin_inset Quotes srd
2367 \end_inset
2368
2369 i586-mingw32msvc-strip
2370 \begin_inset Quotes srd
2371 \end_inset
2372
2373  
2374 \backslash
2375
2376 \newline
2377 -
2378 \begin_inset ERT
2379 status collapsed
2380
2381 \begin_layout Standard
2382
2383
2384 \backslash
2385 /
2386 \end_layout
2387
2388 \end_inset
2389
2390 -prefix=
2391 \begin_inset Quotes srd
2392 \end_inset
2393
2394 /sdcc
2395 \begin_inset Quotes srd
2396 \end_inset
2397
2398  
2399 \backslash
2400
2401 \newline
2402 -
2403 \begin_inset ERT
2404 status collapsed
2405
2406 \begin_layout Standard
2407
2408
2409 \backslash
2410 /
2411 \end_layout
2412
2413 \end_inset
2414
2415 -datarootdir=
2416 \begin_inset Quotes srd
2417 \end_inset
2418
2419 /sdcc
2420 \begin_inset Quotes srd
2421 \end_inset
2422
2423  
2424 \backslash
2425
2426 \newline
2427 docdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431
2432 \backslash
2433 ${datarootdir}/doc
2434 \begin_inset Quotes srd
2435 \end_inset
2436
2437  
2438 \backslash
2439
2440 \newline
2441 include_dir_suffix=
2442 \begin_inset Quotes srd
2443 \end_inset
2444
2445 include
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451
2452 \newline
2453 lib_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 lib
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 sdccconf_h_dir_separator=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469
2470 \backslash
2471
2472 \backslash
2473
2474 \backslash
2475
2476 \backslash
2477
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481  
2482 \backslash
2483
2484 \newline
2485 -
2486 \begin_inset ERT
2487 status collapsed
2488
2489 \begin_layout Standard
2490
2491
2492 \backslash
2493 /
2494 \end_layout
2495
2496 \end_inset
2497
2498 -disable-device-lib
2499 \backslash
2500
2501 \newline
2502 -
2503 \begin_inset ERT
2504 status collapsed
2505
2506 \begin_layout Standard
2507
2508
2509 \backslash
2510 /
2511 \end_layout
2512
2513 \end_inset
2514
2515 -host=i586-mingw32msvc
2516 \backslash
2517
2518 \newline
2519 -
2520 \begin_inset ERT
2521 status collapsed
2522
2523 \begin_layout Standard
2524
2525
2526 \backslash
2527 /
2528 \end_layout
2529
2530 \end_inset
2531
2532 -build=unknown-unknown-linux-gnu
2533 \end_layout
2534
2535 \begin_layout Standard
2536 To 
2537 \begin_inset Quotes sld
2538 \end_inset
2539
2540 cross
2541 \begin_inset Quotes srd
2542 \end_inset
2543
2544 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2545 ):
2546 \end_layout
2547
2548 \begin_layout LyX-Code
2549 ./configure -C 
2550 \backslash
2551
2552 \newline
2553 -
2554 \begin_inset ERT
2555 status collapsed
2556
2557 \begin_layout Standard
2558
2559
2560 \backslash
2561 /
2562 \end_layout
2563
2564 \end_inset
2565
2566 -prefix=
2567 \begin_inset Quotes srd
2568 \end_inset
2569
2570 /sdcc
2571 \begin_inset Quotes srd
2572 \end_inset
2573
2574  
2575 \backslash
2576
2577 \newline
2578 -
2579 \begin_inset ERT
2580 status collapsed
2581
2582 \begin_layout Standard
2583
2584
2585 \backslash
2586 /
2587 \end_layout
2588
2589 \end_inset
2590
2591 -datarootdir=
2592 \begin_inset Quotes srd
2593 \end_inset
2594
2595 /sdcc
2596 \begin_inset Quotes srd
2597 \end_inset
2598
2599  
2600 \backslash
2601
2602 \newline
2603 docdir=
2604 \begin_inset Quotes srd
2605 \end_inset
2606
2607
2608 \backslash
2609 ${datarootdir}/doc
2610 \begin_inset Quotes srd
2611 \end_inset
2612
2613  
2614 \backslash
2615  
2616 \newline
2617 include_dir_suffix=
2618 \begin_inset Quotes srd
2619 \end_inset
2620
2621 include
2622 \begin_inset Quotes srd
2623 \end_inset
2624
2625  
2626 \backslash
2627
2628 \newline
2629 lib_dir_suffix=
2630 \begin_inset Quotes srd
2631 \end_inset
2632
2633 lib
2634 \begin_inset Quotes srd
2635 \end_inset
2636
2637  
2638 \backslash
2639
2640 \newline
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645
2646 \backslash
2647
2648 \backslash
2649
2650 \backslash
2651
2652 \backslash
2653
2654 \begin_inset Quotes srd
2655 \end_inset
2656
2657  
2658 \backslash
2659
2660 \newline
2661 CC=
2662 \begin_inset Quotes srd
2663 \end_inset
2664
2665 gcc -mno-cygwin
2666 \begin_inset Quotes srd
2667 \end_inset
2668
2669  
2670 \backslash
2671
2672 \newline
2673 CXX=
2674 \begin_inset Quotes srd
2675 \end_inset
2676
2677 g++ -mno-cygwin
2678 \begin_inset Quotes srd
2679 \end_inset
2680
2681  
2682 \end_layout
2683
2684 \begin_layout Standard
2685 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2686  The option '-
2687 \begin_inset ERT
2688 status collapsed
2689
2690 \begin_layout Standard
2691
2692
2693 \backslash
2694 /
2695 \end_layout
2696
2697 \end_inset
2698
2699 -C' turns on caching, which gives a little bit extra speed.
2700  However if options are changed, it can be necessary to delete the config.cache
2701  file.
2702 \end_layout
2703
2704 \begin_layout Section
2705 Install paths
2706 \begin_inset LatexCommand \label{sub:Install-paths}
2707
2708 \end_inset
2709
2710
2711 \begin_inset LatexCommand \index{Install paths}
2712
2713 \end_inset
2714
2715
2716 \end_layout
2717
2718 \begin_layout Standard
2719 \begin_inset VSpace medskip
2720 \end_inset
2721
2722
2723 \end_layout
2724
2725 \begin_layout Standard
2726 \align center
2727 \begin_inset Tabular
2728 <lyxtabular version="3" rows="5" columns="4">
2729 <features>
2730 <column alignment="left" valignment="top" leftline="true" width="0">
2731 <column alignment="left" valignment="top" leftline="true" width="0">
2732 <column alignment="left" valignment="top" leftline="true" width="0">
2733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2734 <row topline="true" bottomline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \begin_layout Standard
2739
2740 \series bold
2741 Description
2742 \end_layout
2743
2744 \end_inset
2745 </cell>
2746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_inset Text
2748
2749 \begin_layout Standard
2750
2751 \series bold
2752 Path
2753 \end_layout
2754
2755 \end_inset
2756 </cell>
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_inset Text
2759
2760 \begin_layout Standard
2761
2762 \series bold
2763 Default
2764 \end_layout
2765
2766 \end_inset
2767 </cell>
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2769 \begin_inset Text
2770
2771 \begin_layout Standard
2772
2773 \series bold
2774 Win32 builds
2775 \end_layout
2776
2777 \end_inset
2778 </cell>
2779 </row>
2780 <row topline="true">
2781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_inset Text
2783
2784 \begin_layout Standard
2785 Binary files*
2786 \end_layout
2787
2788 \end_inset
2789 </cell>
2790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_inset Text
2792
2793 \begin_layout Standard
2794
2795 \emph on
2796 $EXEC_PREFIX
2797 \end_layout
2798
2799 \end_inset
2800 </cell>
2801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_inset Text
2803
2804 \begin_layout Standard
2805 /usr/local/bin
2806 \end_layout
2807
2808 \end_inset
2809 </cell>
2810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_inset Text
2812
2813 \begin_layout Standard
2814
2815 \backslash
2816 sdcc
2817 \backslash
2818 bin
2819 \end_layout
2820
2821 \end_inset
2822 </cell>
2823 </row>
2824 <row topline="true">
2825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2826 \begin_inset Text
2827
2828 \begin_layout Standard
2829 Include files
2830 \end_layout
2831
2832 \end_inset
2833 </cell>
2834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2835 \begin_inset Text
2836
2837 \begin_layout Standard
2838
2839 \emph on
2840 $DATADIR/ $INCLUDE_DIR_SUFFIX
2841 \end_layout
2842
2843 \end_inset
2844 </cell>
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2846 \begin_inset Text
2847
2848 \begin_layout Standard
2849 /usr/local/share/sdcc/include
2850 \end_layout
2851
2852 \end_inset
2853 </cell>
2854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2855 \begin_inset Text
2856
2857 \begin_layout Standard
2858
2859 \backslash
2860 sdcc
2861 \backslash
2862 include
2863 \end_layout
2864
2865 \end_inset
2866 </cell>
2867 </row>
2868 <row topline="true">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \begin_layout Standard
2873 Library file**
2874 \end_layout
2875
2876 \end_inset
2877 </cell>
2878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2879 \begin_inset Text
2880
2881 \begin_layout Standard
2882
2883 \emph on
2884 $DATADIR/$LIB_DIR_SUFFIX
2885 \end_layout
2886
2887 \end_inset
2888 </cell>
2889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2890 \begin_inset Text
2891
2892 \begin_layout Standard
2893 /usr/local/share/sdcc/lib
2894 \end_layout
2895
2896 \end_inset
2897 </cell>
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2899 \begin_inset Text
2900
2901 \begin_layout Standard
2902
2903 \backslash
2904 sdcc
2905 \backslash
2906 lib
2907 \end_layout
2908
2909 \end_inset
2910 </cell>
2911 </row>
2912 <row topline="true" bottomline="true">
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2914 \begin_inset Text
2915
2916 \begin_layout Standard
2917 Documentation
2918 \end_layout
2919
2920 \end_inset
2921 </cell>
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2923 \begin_inset Text
2924
2925 \begin_layout Standard
2926
2927 \emph on
2928 $DOCDIR
2929 \end_layout
2930
2931 \end_inset
2932 </cell>
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2934 \begin_inset Text
2935
2936 \begin_layout Standard
2937 /usr/local/share/sdcc/doc
2938 \end_layout
2939
2940 \end_inset
2941 </cell>
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \begin_layout Standard
2946
2947 \backslash
2948 sdcc
2949 \backslash
2950 doc
2951 \end_layout
2952
2953 \end_inset
2954 </cell>
2955 </row>
2956 </lyxtabular>
2957
2958 \end_inset
2959
2960
2961 \end_layout
2962
2963 \begin_layout Verse
2964
2965 \size footnotesize
2966 *compiler, preprocessor, assembler, and linker
2967 \newline
2968 **the 
2969 \shape italic
2970 model
2971 \shape default
2972  is auto-appended by the compiler, e.g.
2973  small, large, z80, ds390 etc
2974 \end_layout
2975
2976 \begin_layout Standard
2977 \noindent
2978 The install paths can still be changed during `make install' with e.g.:
2979 \end_layout
2980
2981 \begin_layout LyX-Code
2982 make install prefix=$(HOME)/local/sdcc
2983 \end_layout
2984
2985 \begin_layout Standard
2986 Of course this doesn't change the search paths compiled into the binaries.
2987 \newline
2988
2989 \newline
2990 Moreove
2991 r the install path can be changed by defining DESTDIR
2992 \begin_inset LatexCommand \index{DESTDIR}
2993
2994 \end_inset
2995
2996 :
2997 \end_layout
2998
2999 \begin_layout LyX-Code
3000 make install DESTDIR=$(HOME)/sdcc.rpm/
3001 \end_layout
3002
3003 \begin_layout Standard
3004 Please note that DESTDIR must have a trailing slash!
3005 \end_layout
3006
3007 \begin_layout Section
3008 Search Paths
3009 \begin_inset LatexCommand \label{sub:Search-Paths}
3010
3011 \end_inset
3012
3013
3014 \begin_inset LatexCommand \index{Search path}
3015
3016 \end_inset
3017
3018
3019 \end_layout
3020
3021 \begin_layout Standard
3022 Some search paths or parts of them are determined by configure variables
3023  (in 
3024 \emph on
3025 italics
3026 \emph default
3027 , see section above).
3028  Further search paths are determined by environment variables during runtime.
3029  
3030 \newline
3031 The paths searched when running the compiler are as follows (the first
3032  catch wins):
3033 \newline
3034
3035 \newline
3036 1.
3037  Binary files (preprocessor, assembler and linker)
3038 \newline
3039
3040 \end_layout
3041
3042 \begin_layout Standard
3043 \align center
3044 \begin_inset Tabular
3045 <lyxtabular version="3" rows="4" columns="3">
3046 <features>
3047 <column alignment="block" valignment="top" leftline="true" width="0in">
3048 <column alignment="block" valignment="top" leftline="true" width="0in">
3049 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3050 <row topline="true" bottomline="true">
3051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_inset Text
3053
3054 \begin_layout Standard
3055 Search path
3056 \end_layout
3057
3058 \end_inset
3059 </cell>
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_inset Text
3062
3063 \begin_layout Standard
3064 default
3065 \end_layout
3066
3067 \end_inset
3068 </cell>
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3070 \begin_inset Text
3071
3072 \begin_layout Standard
3073 Win32 builds
3074 \end_layout
3075
3076 \end_inset
3077 </cell>
3078 </row>
3079 <row topline="true">
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \begin_layout Standard
3084 $SDCC_HOME/
3085 \emph on
3086 $PPREFIX2BIN_DIR
3087 \end_layout
3088
3089 \end_inset
3090 </cell>
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_inset Text
3093
3094 \begin_layout Standard
3095 $SDCC_HOME/bin
3096 \end_layout
3097
3098 \end_inset
3099 </cell>
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3101 \begin_inset Text
3102
3103 \begin_layout Standard
3104 $SDCC_HOME
3105 \backslash
3106 bin
3107 \end_layout
3108
3109 \end_inset
3110 </cell>
3111 </row>
3112 <row topline="true">
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 Path of argv[0] (if available)
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3123 \begin_inset Text
3124
3125 \begin_layout Standard
3126 Path of argv[0]
3127 \end_layout
3128
3129 \end_inset
3130 </cell>
3131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3132 \begin_inset Text
3133
3134 \begin_layout Standard
3135 Path of argv[0]
3136 \end_layout
3137
3138 \end_inset
3139 </cell>
3140 </row>
3141 <row topline="true" bottomline="true">
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3143 \begin_inset Text
3144
3145 \begin_layout Standard
3146 $PATH
3147 \end_layout
3148
3149 \end_inset
3150 </cell>
3151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3152 \begin_inset Text
3153
3154 \begin_layout Standard
3155 $PATH
3156 \end_layout
3157
3158 \end_inset
3159 </cell>
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3161 \begin_inset Text
3162
3163 \begin_layout Standard
3164 $PATH
3165 \end_layout
3166
3167 \end_inset
3168 </cell>
3169 </row>
3170 </lyxtabular>
3171
3172 \end_inset
3173
3174  
3175 \newline
3176
3177 \end_layout
3178
3179 \begin_layout Standard
3180 \noindent
3181 2.
3182  Include files
3183 \newline
3184
3185 \end_layout
3186
3187 \begin_layout Standard
3188 \align center
3189 \begin_inset Tabular
3190 <lyxtabular version="3" rows="6" columns="3">
3191 <features>
3192 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3193 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3194 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3195 <row topline="true" bottomline="true">
3196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3197 \begin_inset Text
3198
3199 \begin_layout Standard
3200 Search path
3201 \end_layout
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \begin_layout Standard
3209 default
3210 \end_layout
3211
3212 \end_inset
3213 </cell>
3214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3215 \begin_inset Text
3216
3217 \begin_layout Standard
3218 Win32 builds
3219 \end_layout
3220
3221 \end_inset
3222 </cell>
3223 </row>
3224 <row topline="true">
3225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3226 \begin_inset Text
3227
3228 \begin_layout Standard
3229 -
3230 \begin_inset ERT
3231 status collapsed
3232
3233 \begin_layout Standard
3234
3235
3236 \backslash
3237 /
3238 \end_layout
3239
3240 \end_inset
3241
3242 -I dir
3243 \end_layout
3244
3245 \end_inset
3246 </cell>
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3248 \begin_inset Text
3249
3250 \begin_layout Standard
3251 -
3252 \begin_inset ERT
3253 status collapsed
3254
3255 \begin_layout Standard
3256
3257
3258 \backslash
3259 /
3260 \end_layout
3261
3262 \end_inset
3263
3264 -I dir
3265 \end_layout
3266
3267 \end_inset
3268 </cell>
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 -
3274 \begin_inset ERT
3275 status collapsed
3276
3277 \begin_layout Standard
3278
3279
3280 \backslash
3281 /
3282 \end_layout
3283
3284 \end_inset
3285
3286 -I dir
3287 \end_layout
3288
3289 \end_inset
3290 </cell>
3291 </row>
3292 <row topline="true">
3293 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3294 \begin_inset Text
3295
3296 \begin_layout Standard
3297 $SDCC_INCLUDE
3298 \end_layout
3299
3300 \end_inset
3301 </cell>
3302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3303 \begin_inset Text
3304
3305 \begin_layout Standard
3306 $SDCC_INCLUDE
3307 \end_layout
3308
3309 \end_inset
3310 </cell>
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3312 \begin_inset Text
3313
3314 \begin_layout Standard
3315 $SDCC_INCLUDE
3316 \end_layout
3317
3318 \end_inset
3319 </cell>
3320 </row>
3321 <row topline="true">
3322 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3323 \begin_inset Text
3324
3325 \begin_layout Standard
3326 $SDCC_HOME/
3327 \newline
3328
3329 \emph on
3330 $PREFIX2DATA_DIR/
3331 \newline
3332 $INCLUDE_DIR_SUFFIX
3333 \end_layout
3334
3335 \end_inset
3336 </cell>
3337 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 \begin_inset Text
3339
3340 \begin_layout Standard
3341 $SDCC_ HOME/
3342 \newline
3343 share/sdcc/
3344 \newline
3345 include
3346 \end_layout
3347
3348 \end_inset
3349 </cell>
3350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3351 \begin_inset Text
3352
3353 \begin_layout Standard
3354 $SDCC_HOME
3355 \backslash
3356 include
3357 \end_layout
3358
3359 \end_inset
3360 </cell>
3361 </row>
3362 <row topline="true">
3363 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3364 \begin_inset Text
3365
3366 \begin_layout Standard
3367 path(argv[0])/
3368 \newline
3369
3370 \emph on
3371 $BIN2DATADIR/
3372 \emph default
3373
3374 \newline
3375
3376 \emph on
3377 $INCLUDE_DIR_SUFFIX
3378 \end_layout
3379
3380 \end_inset
3381 </cell>
3382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3383 \begin_inset Text
3384
3385 \begin_layout Standard
3386 path(argv[0])/
3387 \newline
3388 ../sdcc/include
3389 \newline
3390 \InsetSpace ~
3391 \InsetSpace ~
3392 \InsetSpace ~
3393 \InsetSpace ~
3394 \InsetSpace ~
3395 \InsetSpace ~
3396 \InsetSpace ~
3397 \InsetSpace ~
3398 \InsetSpace ~
3399 \InsetSpace ~
3400 \InsetSpace ~
3401 \InsetSpace ~
3402 \InsetSpace ~
3403 \InsetSpace ~
3404 \InsetSpace ~
3405 \InsetSpace ~
3406 \InsetSpace ~
3407 \InsetSpace ~
3408 \InsetSpace ~
3409 \InsetSpace ~
3410 \InsetSpace ~
3411 \InsetSpace ~
3412 \InsetSpace ~
3413 \InsetSpace ~
3414 \InsetSpace ~
3415 \InsetSpace ~
3416 \InsetSpace ~
3417 \InsetSpace ~
3418 \InsetSpace ~
3419 \InsetSpace ~
3420 \InsetSpace ~
3421 \InsetSpace ~
3422 \InsetSpace ~
3423 \InsetSpace ~
3424 \InsetSpace ~
3425 \InsetSpace ~
3426 \InsetSpace ~
3427 \InsetSpace ~
3428
3429 \end_layout
3430
3431 \end_inset
3432 </cell>
3433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3434 \begin_inset Text
3435
3436 \begin_layout Standard
3437 path(argv[0])
3438 \backslash
3439 ..
3440 \backslash
3441 include
3442 \end_layout
3443
3444 \end_inset
3445 </cell>
3446 </row>
3447 <row topline="true" bottomline="true">
3448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3449 \begin_inset Text
3450
3451 \begin_layout Standard
3452
3453 \emph on
3454 $DATADIR/
3455 \emph default
3456
3457 \newline
3458
3459 \emph on
3460 $INCLUDE_DIR_SUFFIX
3461 \end_layout
3462
3463 \end_inset
3464 </cell>
3465 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3466 \begin_inset Text
3467
3468 \begin_layout Standard
3469 /usr/local/share/sdcc/
3470 \newline
3471 include
3472 \end_layout
3473
3474 \end_inset
3475 </cell>
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3477 \begin_inset Text
3478
3479 \begin_layout Standard
3480 (not on Win32)
3481 \end_layout
3482
3483 \end_inset
3484 </cell>
3485 </row>
3486 </lyxtabular>
3487
3488 \end_inset
3489
3490  
3491 \newline
3492
3493 \end_layout
3494
3495 \begin_layout Standard
3496 \noindent
3497 The option -
3498 \begin_inset ERT
3499 status collapsed
3500
3501 \begin_layout Standard
3502
3503
3504 \backslash
3505 /
3506 \end_layout
3507
3508 \end_inset
3509
3510 -nostdinc disables the last two search paths.
3511 \newline
3512
3513 \newline
3514 3.
3515  Library files 
3516 \newline
3517
3518 \end_layout
3519
3520 \begin_layout Standard
3521 With the exception of 
3522 \begin_inset Quotes sld
3523 \end_inset
3524
3525 -
3526 \begin_inset ERT
3527 status collapsed
3528
3529 \begin_layout Standard
3530
3531
3532 \backslash
3533 /
3534 \end_layout
3535
3536 \end_inset
3537
3538 -L dir
3539 \begin_inset Quotes srd
3540 \end_inset
3541
3542  the 
3543 \shape italic
3544 model
3545 \shape default
3546  is auto-appended by the compiler (e.g.
3547  small, large, z80, ds390 etc.).
3548  
3549 \newline
3550
3551 \end_layout
3552
3553 \begin_layout Standard
3554 \align center
3555 \begin_inset Tabular
3556 <lyxtabular version="3" rows="6" columns="3">
3557 <features>
3558 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3559 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3561 <row topline="true" bottomline="true">
3562 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3563 \begin_inset Text
3564
3565 \begin_layout Standard
3566 Search path
3567 \end_layout
3568
3569 \end_inset
3570 </cell>
3571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3572 \begin_inset Text
3573
3574 \begin_layout Standard
3575 default
3576 \end_layout
3577
3578 \end_inset
3579 </cell>
3580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3581 \begin_inset Text
3582
3583 \begin_layout Standard
3584 Win32 builds
3585 \end_layout
3586
3587 \end_inset
3588 </cell>
3589 </row>
3590 <row topline="true">
3591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3592 \begin_inset Text
3593
3594 \begin_layout Standard
3595 -
3596 \begin_inset ERT
3597 status collapsed
3598
3599 \begin_layout Standard
3600
3601
3602 \backslash
3603 /
3604 \end_layout
3605
3606 \end_inset
3607
3608 -L dir
3609 \end_layout
3610
3611 \end_inset
3612 </cell>
3613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3614 \begin_inset Text
3615
3616 \begin_layout Standard
3617 -
3618 \begin_inset ERT
3619 status collapsed
3620
3621 \begin_layout Standard
3622
3623
3624 \backslash
3625 /
3626 \end_layout
3627
3628 \end_inset
3629
3630 -L dir
3631 \end_layout
3632
3633 \end_inset
3634 </cell>
3635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3636 \begin_inset Text
3637
3638 \begin_layout Standard
3639 -
3640 \begin_inset ERT
3641 status collapsed
3642
3643 \begin_layout Standard
3644
3645
3646 \backslash
3647 /
3648 \end_layout
3649
3650 \end_inset
3651
3652 -L dir
3653 \end_layout
3654
3655 \end_inset
3656 </cell>
3657 </row>
3658 <row topline="true">
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3660 \begin_inset Text
3661
3662 \begin_layout Standard
3663 $SDCC_LIB/
3664 \newline
3665
3666 \emph on
3667 <model>
3668 \end_layout
3669
3670 \end_inset
3671 </cell>
3672 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3673 \begin_inset Text
3674
3675 \begin_layout Standard
3676 $SDCC_LIB/
3677 \newline
3678
3679 \emph on
3680 <model>
3681 \end_layout
3682
3683 \end_inset
3684 </cell>
3685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3686 \begin_inset Text
3687
3688 \begin_layout Standard
3689 $SDCC_LIB
3690 \backslash
3691
3692 \newline
3693
3694 \emph on
3695 <model>
3696 \end_layout
3697
3698 \end_inset
3699 </cell>
3700 </row>
3701 <row topline="true">
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3703 \begin_inset Text
3704
3705 \begin_layout Standard
3706 $SDCC_HOME/
3707 \newline
3708
3709 \emph on
3710 $PREFIX2DATA_DIR/
3711 \newline
3712 $LIB_DIR_SUFFIX/<model>
3713 \end_layout
3714
3715 \end_inset
3716 </cell>
3717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3718 \begin_inset Text
3719
3720 \begin_layout Standard
3721 $SDCC_HOME/
3722 \newline
3723 share/sdcc/
3724 \newline
3725 lib/
3726 \emph on
3727 <model>
3728 \end_layout
3729
3730 \end_inset
3731 </cell>
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3733 \begin_inset Text
3734
3735 \begin_layout Standard
3736 $SDCC_HOME
3737 \backslash
3738 lib
3739 \backslash
3740
3741 \emph on
3742
3743 \newline
3744 <model>
3745 \end_layout
3746
3747 \end_inset
3748 </cell>
3749 </row>
3750 <row topline="true">
3751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3752 \begin_inset Text
3753
3754 \begin_layout Standard
3755 path(argv[0])/
3756 \newline
3757
3758 \emph on
3759 $BIN2DATADIR/
3760 \emph default
3761
3762 \newline
3763
3764 \emph on
3765 $LIB_DIR_SUFFIX/<model>
3766 \end_layout
3767
3768 \end_inset
3769 </cell>
3770 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3771 \begin_inset Text
3772
3773 \begin_layout Standard
3774 path(argv[0])/
3775 \newline
3776 ../sdcc/lib/
3777 \emph on
3778 <model>
3779 \newline
3780 \InsetSpace ~
3781 \InsetSpace ~
3782 \InsetSpace ~
3783 \InsetSpace ~
3784 \InsetSpace ~
3785 \InsetSpace ~
3786 \InsetSpace ~
3787 \InsetSpace ~
3788 \InsetSpace ~
3789 \InsetSpace ~
3790 \InsetSpace ~
3791 \InsetSpace ~
3792 \InsetSpace ~
3793 \InsetSpace ~
3794 \InsetSpace ~
3795 \InsetSpace ~
3796 \InsetSpace ~
3797 \InsetSpace ~
3798 \InsetSpace ~
3799 \InsetSpace ~
3800 \InsetSpace ~
3801 \InsetSpace ~
3802 \InsetSpace ~
3803 \InsetSpace ~
3804 \InsetSpace ~
3805 \InsetSpace ~
3806 \InsetSpace ~
3807 \InsetSpace ~
3808 \InsetSpace ~
3809 \InsetSpace ~
3810 \InsetSpace ~
3811 \InsetSpace ~
3812 \InsetSpace ~
3813 \InsetSpace ~
3814 \InsetSpace ~
3815 \InsetSpace ~
3816 \InsetSpace ~
3817 \InsetSpace ~
3818 \InsetSpace ~
3819
3820 \end_layout
3821
3822 \end_inset
3823 </cell>
3824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3825 \begin_inset Text
3826
3827 \begin_layout Standard
3828 path(argv[0])
3829 \backslash
3830
3831 \newline
3832 ..
3833 \backslash
3834 lib
3835 \backslash
3836
3837 \emph on
3838 <model>
3839 \newline
3840 \InsetSpace ~
3841 \InsetSpace ~
3842 \InsetSpace ~
3843 \InsetSpace ~
3844 \InsetSpace ~
3845 \InsetSpace ~
3846 \InsetSpace ~
3847 \InsetSpace ~
3848 \InsetSpace ~
3849 \InsetSpace ~
3850 \InsetSpace ~
3851 \InsetSpace ~
3852 \InsetSpace ~
3853 \InsetSpace ~
3854 \InsetSpace ~
3855 \InsetSpace ~
3856 \InsetSpace ~
3857 \InsetSpace ~
3858 \InsetSpace ~
3859 \InsetSpace ~
3860 \InsetSpace ~
3861 \InsetSpace ~
3862 \InsetSpace ~
3863 \InsetSpace ~
3864 \InsetSpace ~
3865 \InsetSpace ~
3866 \InsetSpace ~
3867 \InsetSpace ~
3868 \InsetSpace ~
3869 \InsetSpace ~
3870 \InsetSpace ~
3871 \InsetSpace ~
3872 \InsetSpace ~
3873 \InsetSpace ~
3874 \InsetSpace ~
3875
3876 \end_layout
3877
3878 \end_inset
3879 </cell>
3880 </row>
3881 <row topline="true" bottomline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3883 \begin_inset Text
3884
3885 \begin_layout Standard
3886
3887 \emph on
3888 $DATADIR/
3889 \newline
3890 $LIB_DIR_SUFFIX/<model>
3891 \end_layout
3892
3893 \end_inset
3894 </cell>
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3896 \begin_inset Text
3897
3898 \begin_layout Standard
3899 /usr/local/share/sdcc/
3900 \newline
3901 lib/
3902 \emph on
3903 <model>
3904 \end_layout
3905
3906 \end_inset
3907 </cell>
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3909 \begin_inset Text
3910
3911 \begin_layout Standard
3912 (not on Win32)
3913 \end_layout
3914
3915 \end_inset
3916 </cell>
3917 </row>
3918 </lyxtabular>
3919
3920 \end_inset
3921
3922
3923 \newline
3924
3925 \end_layout
3926
3927 \begin_layout Standard
3928 \begin_inset Note Note
3929 status collapsed
3930
3931 \begin_layout Standard
3932 Don't delete any of the stray spaces in the table above without checking
3933  the HTML output (last line)!
3934 \end_layout
3935
3936 \end_inset
3937
3938
3939 \end_layout
3940
3941 \begin_layout Standard
3942 \InsetSpace ~
3943
3944 \newline
3945 The option -
3946 \begin_inset ERT
3947 status collapsed
3948
3949 \begin_layout Standard
3950
3951
3952 \backslash
3953 /
3954 \end_layout
3955
3956 \end_inset
3957
3958 -nostdlib disables the last two search paths.
3959 \end_layout
3960
3961 \begin_layout Section
3962 Building SDCC
3963 \begin_inset LatexCommand \index{Building SDCC}
3964
3965 \end_inset
3966
3967
3968 \end_layout
3969
3970 \begin_layout Subsection
3971 Building SDCC on Linux
3972 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3973
3974 \end_inset
3975
3976
3977 \end_layout
3978
3979 \begin_layout Enumerate
3980
3981 \series medium
3982 Download the source package
3983 \series default
3984  either from the SDCC Subversion repository or from snapshot builds
3985 \series medium
3986 , it will be named something like sdcc
3987 \series default
3988 -src
3989 \series medium
3990 -yyyymmdd-rrrr.t
3991 \series default
3992 ar.
3993 \series medium
3994 bz2
3995 \series default
3996  
3997 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3998
3999 \end_inset
4000
4001 .
4002 \end_layout
4003
4004 \begin_layout Enumerate
4005
4006 \series medium
4007 Bring up a command line terminal, such as xterm.
4008 \end_layout
4009
4010 \begin_layout Enumerate
4011
4012 \series medium
4013 Unpack the file using a command like: 
4014 \family sans
4015 \series bold
4016 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4017 \begin_inset Quotes srd
4018 \end_inset
4019
4020
4021 \family default
4022 \series medium
4023 , this will create a sub-directory called sdcc with all of the sources.
4024 \end_layout
4025
4026 \begin_layout Enumerate
4027 Change directory into the main SDCC directory, for example type: 
4028 \family sans
4029 \series bold
4030 "cd sdcc
4031 \series default
4032 ".
4033 \end_layout
4034
4035 \begin_layout Enumerate
4036
4037 \series medium
4038 Type 
4039 \family sans
4040 \series bold
4041 "./configure
4042 \family default
4043 \series default
4044 ".
4045  This configures the package for compilation on your system.
4046 \end_layout
4047
4048 \begin_layout Enumerate
4049
4050 \series medium
4051 Type 
4052 \family sans
4053 \series bold
4054 "make
4055 \family default
4056 \series default
4057 "
4058 \series medium
4059 .
4060
4061 \series default
4062  All of the source packages will compile, this can take a while.
4063 \end_layout
4064
4065 \begin_layout Enumerate
4066
4067 \series medium
4068 Type 
4069 \family sans
4070 \series bold
4071 "make install"
4072 \family default
4073 \series default
4074  as root
4075 \series medium
4076 .
4077
4078 \series default
4079  This copies the binary executables, the include files, the libraries and
4080  the documentation to the install directories.
4081  Proceed with section 
4082 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4083
4084 \end_inset
4085
4086 .
4087 \end_layout
4088
4089 \begin_layout Subsection
4090 Building SDCC on Mac OS X
4091 \end_layout
4092
4093 \begin_layout Standard
4094 Follow the instruction for Linux.
4095 \newline
4096
4097 \newline
4098 On Mac OS X 10.2.x it was reported, that the
4099  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4100  Fortunately there's also gcc 2.9.x installed, which works fine.
4101  This compiler can be selected by running 'configure' with:
4102 \end_layout
4103
4104 \begin_layout LyX-Code
4105 ./configure CC=gcc2 CXX=g++2
4106 \end_layout
4107
4108 \begin_layout Standard
4109 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4110  Xcode.
4111  Run 'configure' with:
4112 \end_layout
4113
4114 \begin_layout LyX-Code
4115 ./configure 
4116 \backslash
4117
4118 \end_layout
4119
4120 \begin_layout LyX-Code
4121 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4122  ppc" 
4123 \backslash
4124
4125 \end_layout
4126
4127 \begin_layout LyX-Code
4128 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4129  ppc" 
4130 \backslash
4131
4132 \end_layout
4133
4134 \begin_layout LyX-Code
4135 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4136 \end_layout
4137
4138 \begin_layout Subsection
4139 Cross compiling SDCC on Linux for Windows
4140 \end_layout
4141
4142 \begin_layout Standard
4143 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4144  See section 'Configure Options'.
4145 \end_layout
4146
4147 \begin_layout Subsection
4148 Building SDCC using Cygwin and Mingw32
4149 \end_layout
4150
4151 \begin_layout Standard
4152 For building and installing a Cygwin executable follow the instructions
4153  for Linux.
4154 \newline
4155
4156 \newline
4157 On Cygwin a 
4158 \begin_inset Quotes sld
4159 \end_inset
4160
4161 native
4162 \begin_inset Quotes srd
4163 \end_inset
4164
4165  Win32-binary can be built, which will not need the Cygwin-DLL.
4166  For the necessary 'configure' options see section 'configure options' or
4167  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4168 \newline
4169
4170 \newline
4171 In order to install
4172  Cygwin on Windows download setup.exe from 
4173 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4174
4175 \end_inset
4176
4177 .
4178  Run it, set the 
4179 \begin_inset Quotes sld
4180 \end_inset
4181
4182 default text file type
4183 \begin_inset Quotes srd
4184 \end_inset
4185
4186  to 
4187 \begin_inset Quotes sld
4188 \end_inset
4189
4190 unix
4191 \begin_inset Quotes srd
4192 \end_inset
4193
4194  and download/install at least the following packages.
4195  Some packages are selected by default, others will be automatically selected
4196  because of dependencies with the manually selected packages.
4197  Never deselect these packages!
4198 \end_layout
4199
4200 \begin_layout Itemize
4201 flex
4202 \end_layout
4203
4204 \begin_layout Itemize
4205 bison
4206 \end_layout
4207
4208 \begin_layout Itemize
4209 gcc ; version 3.x is fine, no need to use the old 2.9x
4210 \end_layout
4211
4212 \begin_layout Itemize
4213 binutils ; selected with gcc
4214 \end_layout
4215
4216 \begin_layout Itemize
4217 make
4218 \end_layout
4219
4220 \begin_layout Itemize
4221 rxvt ; a nice console, which makes life much easier under windoze (see below)
4222 \end_layout
4223
4224 \begin_layout Itemize
4225 man ; not really needed for building SDCC, but you'll miss it sooner or
4226  later
4227 \end_layout
4228
4229 \begin_layout Itemize
4230 less ; not really needed for building SDCC, but you'll miss it sooner or
4231  later
4232 \end_layout
4233
4234 \begin_layout Itemize
4235 svn ; only if you use Subversion access
4236 \end_layout
4237
4238 \begin_layout Standard
4239 If you want to develop something you'll need:
4240 \end_layout
4241
4242 \begin_layout Itemize
4243 python ; for the regression tests
4244 \end_layout
4245
4246 \begin_layout Itemize
4247 gdb ; the gnu debugger, together with the nice GUI 
4248 \begin_inset Quotes sld
4249 \end_inset
4250
4251 insight
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255
4256 \end_layout
4257
4258 \begin_layout Itemize
4259 openssh ; to access the CF or commit changes
4260 \end_layout
4261
4262 \begin_layout Itemize
4263 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4264  use autoconf-stable!
4265 \end_layout
4266
4267 \begin_layout Standard
4268 rxvt is a nice console with history.
4269  Replace in your cygwin.bat the line
4270 \end_layout
4271
4272 \begin_layout LyX-Code
4273 bash -
4274 \begin_inset ERT
4275 status collapsed
4276
4277 \begin_layout Standard
4278
4279
4280 \backslash
4281 /
4282 \end_layout
4283
4284 \end_inset
4285
4286 -login -i 
4287 \end_layout
4288
4289 \begin_layout Standard
4290 with (one line):
4291 \end_layout
4292
4293 \begin_layout LyX-Code
4294 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4295 \end_layout
4296
4297 \begin_layout LyX-Code
4298      -bg black -fg white -geometry 100x65 -e bash -
4299 \begin_inset ERT
4300 status collapsed
4301
4302 \begin_layout Standard
4303
4304
4305 \backslash
4306 /
4307 \end_layout
4308
4309 \end_inset
4310
4311 -login
4312 \end_layout
4313
4314 \begin_layout Standard
4315 Text selected with the mouse is automatically copied to the clipboard, pasting
4316  works with shift-insert.
4317 \newline
4318
4319 \newline
4320 The other good tip is to make sure you have no //c/-styl
4321 e paths anywhere, use /cygdrive/c/ instead.
4322  Using // invokes a network lookup which is very slow.
4323  If you think 
4324 \begin_inset Quotes sld
4325 \end_inset
4326
4327 cygdrive
4328 \begin_inset Quotes srd
4329 \end_inset
4330
4331  is too long, you can change it with e.g.
4332 \end_layout
4333
4334 \begin_layout LyX-Code
4335 mount -s -u -c /mnt
4336 \end_layout
4337
4338 \begin_layout Standard
4339 SDCC sources use the unix line ending LF.
4340  Life is much easier, if you store the source tree on a drive which is mounted
4341  in binary mode.
4342  And use an editor which can handle LF-only line endings.
4343  Make sure not to commit files with windows line endings.
4344  The tabulator spacing
4345 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4346
4347 \end_inset
4348
4349  used in the project is 8.
4350  Although a tabulator spacing of 8 is a sensible choice for programmers
4351  (it's a power of 2 and allows to display 8/16 bit signed variables without
4352  loosing columns) the plan is to move towards using only spaces in the source.
4353 \end_layout
4354
4355 \begin_layout Subsection
4356 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4357 \end_layout
4358
4359 \begin_layout Standard
4360
4361 \series medium
4362 Download the source package
4363 \series default
4364  either from the SDCC Subversion repository or from the 
4365 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4366
4367 \end_inset
4368
4369
4370 \series medium
4371 , it will be named something like sdcc
4372 \series default
4373 -src
4374 \series medium
4375 -yyyymmdd-rrrr.tar.bz2.
4376
4377 \series default
4378  SDCC is distributed with all the projects, workspaces, and files you need
4379  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4380  The workspace name is 'sdcc.dsw'.
4381  Please note that as it is now, all the executables are created in a folder
4382  called sdcc
4383 \backslash
4384 bin_vc.
4385  Once built you need to copy the executables from sdcc
4386 \backslash
4387 bin_vc to sdcc
4388 \backslash
4389 bin before running SDCC.
4390  
4391 \newline
4392
4393 \newline
4394 WARNING: Visual studio is very picky with line terminations; it expects
4395  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4396  When using the Subversion repository it's easiest to configure the svn
4397  client to convert automatically for you.
4398  If however you are getting a message such as "This makefile was not generated
4399  by Developer Studio etc.
4400  etc.
4401 \begin_inset Quotes srd
4402 \end_inset
4403
4404  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4405  need to convert the Unix style line endings to DOS style line endings.
4406  To do so you can use the 
4407 \begin_inset Quotes sld
4408 \end_inset
4409
4410 unix2dos
4411 \begin_inset Quotes srd
4412 \end_inset
4413
4414  utility freely available on the internet.
4415  Doug Hawkins reported in the sdcc-user list that this works:
4416 \newline
4417
4418 \newline
4419 C:
4420 \backslash
4421 Programming
4422 \backslash
4423 SDCC> unix2dos sdcc.dsw
4424 \newline
4425 C:
4426 \backslash
4427 Programming
4428 \backslash
4429 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4430 \newline
4431
4432 \newline
4433 In order to build SDCC with MSVC
4434  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4435  One good place to get them is 
4436 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4437
4438 \end_inset
4439
4440
4441 \newline
4442
4443 \newline
4444 Download the file UnxUtils
4445 \begin_inset LatexCommand \index{UnxUtils}
4446
4447 \end_inset
4448
4449 .zip.
4450  Now you have to install the utilities and setup MSVC so it can locate the
4451  required programs.
4452  Here there are two alternatives (choose one!):
4453 \end_layout
4454
4455 \begin_layout Enumerate
4456 The easy way:
4457 \newline
4458
4459 \newline
4460 a) Extract UnxUtils.zip to your C:
4461 \backslash
4462  hard disk PRESERVING the original paths, otherwise bison won't work.
4463  (If you are using WinZip make certain that 'Use folder names' is selected)
4464 \newline
4465
4466 \newline
4467 b)
4468  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4469  'Show directories for:' select 'Executable files', and in the directories
4470  window add a new path: 'C:
4471 \backslash
4472 user
4473 \backslash
4474 local
4475 \backslash
4476 wbin', click ok.
4477 \newline
4478
4479 \newline
4480 (As a side effect, you get a bunch of Unix utilities that
4481  could be useful, such as diff and patch.)
4482 \end_layout
4483
4484 \begin_layout Enumerate
4485 A more compact way:
4486 \newline
4487
4488 \newline
4489 This one avoids extracting a bunch of files you may not
4490  use, but requires some extra work:
4491 \newline
4492
4493 \newline
4494 a) Create a directory were to put the
4495  tools needed, or use a directory already present.
4496  Say for example 'C:
4497 \backslash
4498 util'.
4499 \newline
4500
4501 \newline
4502 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4503  gawk.exe to such directory WITHOUT preserving the original paths.
4504  (If you are using WinZip make certain that 'Use folder names' is not selected)
4505 \newline
4506
4507 \newline
4508 c
4509 ) Rename bison.exe to '_bison.exe'.
4510 \newline
4511
4512 \newline
4513 d) Create a batch file 'bison.bat' in 'C:
4514 \backslash
4515 util
4516 \backslash
4517 ' and add these lines: 
4518 \newline
4519 \InsetSpace ~
4520 \InsetSpace ~
4521 set BISON_SIMPLE=C:
4522 \backslash
4523 util
4524 \backslash
4525 bison.simple 
4526 \newline
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 set BISON_HAIRY=C:
4530 \backslash
4531 util
4532 \backslash
4533 bison.hairy
4534 \newline
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4538 \newline
4539
4540 \newline
4541 Steps 'c' and 'd' are needed
4542  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4543  reside in some weird Unix directory, '/usr/local/share/' I think.
4544  So it is necessary to tell bison where those files are located if they
4545  are not in such directory.
4546  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4547 \newline
4548
4549 \newline
4550 e
4551 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4552  in 'Show directories for:' select 'Executable files', and in the directories
4553  window add a new path: 'c:
4554 \backslash
4555 util', click ok.
4556  Note that you can use any other path instead of 'c:
4557 \backslash
4558 util', even the path where the Visual C++ tools are, probably: 'C:
4559 \backslash
4560 Program Files
4561 \backslash
4562 Microsoft Visual Studio
4563 \backslash
4564 Common
4565 \backslash
4566 Tools'.
4567  So you don't have to execute step 'e' :)
4568 \end_layout
4569
4570 \begin_layout Standard
4571 That is it.
4572  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4573  the executables from sdcc
4574 \backslash
4575 bin_vc to sdcc
4576 \backslash
4577 bin, and you can compile using SDCC.
4578 \end_layout
4579
4580 \begin_layout Subsection
4581 Building SDCC Using Borland
4582 \end_layout
4583
4584 \begin_layout Enumerate
4585 From the sdcc directory, run the command "make -f Makefile.bcc".
4586  This should regenerate all the .exe files in the bin directory except for
4587  SDCDB and ucSim.
4588 \end_layout
4589
4590 \begin_layout Enumerate
4591 If you modify any source files and need to rebuild, be aware that the dependenci
4592 es may not be correctly calculated.
4593  The safest option is to delete all .obj files and run the build again.
4594  From a Cygwin BASH prompt, this can easily be done with the command (be
4595  sure you are in the sdcc directory):
4596 \newline
4597
4598 \newline
4599
4600 \family sans
4601 \series bold
4602 find .
4603  
4604 \backslash
4605 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4606 \backslash
4607 ) -print -exec rm {} 
4608 \backslash
4609 ;
4610 \family default
4611 \series default
4612
4613 \newline
4614
4615 \newline
4616 or on Windows NT/2000/XP from the command prompt with the command:
4617 \newline
4618
4619 \family sans
4620 \series bold
4621
4622 \newline
4623 del /s *.obj *.lib *.rul
4624 \family default
4625 \series default
4626  from the sdcc directory.
4627 \end_layout
4628
4629 \begin_layout Subsection
4630 Windows Install Using a ZIP Package
4631 \end_layout
4632
4633 \begin_layout Enumerate
4634 Download the binary zip package from 
4635 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4636
4637 \end_inset
4638
4639  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4640  This should unpack to a group of sub-directories.
4641  An example directory structure after unpacking the mingw32 package is:
4642  c:
4643 \backslash
4644 sdcc
4645 \backslash
4646 bin for the executables, c:
4647 \backslash
4648 sdcc
4649 \backslash
4650 include and c:
4651 \backslash
4652 sdcc
4653 \backslash
4654 lib for the include and libraries.
4655 \end_layout
4656
4657 \begin_layout Enumerate
4658 Adjust your environment variable PATH to include the location of the bin
4659  directory or start sdcc using the full path.
4660 \end_layout
4661
4662 \begin_layout Subsection
4663 Windows Install Using the Setup Program
4664 \begin_inset LatexCommand \label{sub:Windows-Install}
4665
4666 \end_inset
4667
4668
4669 \end_layout
4670
4671 \begin_layout Standard
4672 Download the setup program 
4673 \emph on
4674 sdcc-x.y.z-setup.exe
4675 \emph default
4676  for an official release from 
4677 \newline
4678
4679 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4680
4681 \end_inset
4682
4683  or a setup program for one of the snapshots 
4684 \emph on
4685 sdcc-yyyymmdd-xxxx-setup.exe
4686 \emph default
4687  from 
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4689
4690 \end_inset
4691
4692  and execute it.
4693  A windows typical installer will guide you through the installation process.
4694 \end_layout
4695
4696 \begin_layout Subsection
4697 VPATH
4698 \begin_inset LatexCommand \index{VPATH}
4699
4700 \end_inset
4701
4702  feature
4703 \end_layout
4704
4705 \begin_layout Standard
4706 SDCC supports the VPATH feature provided by configure and make.
4707  It allows to separate the source and build trees.
4708  Here's an example:
4709 \end_layout
4710
4711 \begin_layout Standard
4712
4713 \family typewriter
4714 cd ~\InsetSpace ~
4715 \InsetSpace ~
4716 \InsetSpace ~
4717 \InsetSpace ~
4718 \InsetSpace ~
4719 \InsetSpace ~
4720 \InsetSpace ~
4721 \InsetSpace ~
4722 \InsetSpace ~
4723 \InsetSpace ~
4724 \InsetSpace ~
4725 \InsetSpace ~
4726 \InsetSpace ~
4727 \InsetSpace ~
4728 \InsetSpace ~
4729 \InsetSpace ~
4730 \InsetSpace ~
4731 \InsetSpace ~
4732 \InsetSpace ~
4733 \InsetSpace ~
4734 \InsetSpace ~
4735 # cd $HOME
4736 \end_layout
4737
4738 \begin_layout Standard
4739
4740 \family typewriter
4741 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4742 # extract source to directory sdcc
4743 \end_layout
4744
4745 \begin_layout Standard
4746
4747 \family typewriter
4748 mkdir sdcc.build\InsetSpace ~
4749 \InsetSpace ~
4750 \InsetSpace ~
4751 \InsetSpace ~
4752 \InsetSpace ~
4753 \InsetSpace ~
4754 \InsetSpace ~
4755 \InsetSpace ~
4756 \InsetSpace ~
4757 # put output in sdcc.build
4758 \end_layout
4759
4760 \begin_layout Standard
4761
4762 \family typewriter
4763 cd sdcc.build
4764 \end_layout
4765
4766 \begin_layout Standard
4767
4768 \family typewriter
4769 ../sdcc/configure\InsetSpace ~
4770 \InsetSpace ~
4771 \InsetSpace ~
4772 \InsetSpace ~
4773 \InsetSpace ~
4774 \InsetSpace ~
4775 \InsetSpace ~
4776 \InsetSpace ~
4777 # configure is doing all the magic!
4778 \end_layout
4779
4780 \begin_layout Standard
4781
4782 \family typewriter
4783 make
4784 \end_layout
4785
4786 \begin_layout Standard
4787 \noindent
4788 That's it! 
4789 \series bold
4790 configure
4791 \series default
4792  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4793  It automagically computes the variables srcdir, top_srcdir and top_buildir
4794  for each directory.
4795  After running 
4796 \series bold
4797 make
4798 \series default
4799  the generated files will be in ~/sdcc.build, while the source files stay
4800  in ~/sdcc.
4801 \newline
4802 This is not only usefull for building different binaries, e.g.
4803  when cross compiling.
4804  It also gives you a much better overview in the source tree when all the
4805  generated files are not scattered between the source files.
4806  And the best thing is: if you want to change a file you can leave the original
4807  file untouched in the source directory.
4808  Simply copy it to the build directory, edit it, enter `make clean', `rm
4809  Makefile.dep' and `make'.
4810  
4811 \series bold
4812 make
4813 \series default
4814  will do the rest for you!
4815 \end_layout
4816
4817 \begin_layout Section
4818 Building the Documentation
4819 \end_layout
4820
4821 \begin_layout Standard
4822 Add -
4823 \begin_inset ERT
4824 status collapsed
4825
4826 \begin_layout Standard
4827
4828
4829 \backslash
4830 /
4831 \end_layout
4832
4833 \end_inset
4834
4835 -enable-doc to the configure arguments to build the documentation together
4836  with all the other stuff.
4837  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4838  dvips and makeindex) to get the job done.
4839  Another possibility is to change to the doc directory and to type 
4840 \family sans
4841 \series bold
4842
4843 \begin_inset Quotes srd
4844 \end_inset
4845
4846 make
4847 \begin_inset Quotes srd
4848 \end_inset
4849
4850
4851 \family default
4852 \series default
4853  there.
4854  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4855 x).
4856  Using LyX 
4857 \begin_inset LatexCommand \url{http://www.lyx.org}
4858
4859 \end_inset
4860
4861  as editor is straightforward.
4862  Prebuilt documentation in html and pdf format is available from 
4863 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4864
4865 \end_inset
4866
4867 .
4868 \end_layout
4869
4870 \begin_layout Section
4871 Reading the Documentation
4872 \begin_inset LatexCommand \index{Documentation}
4873
4874 \end_inset
4875
4876
4877 \end_layout
4878
4879 \begin_layout Standard
4880 Currently reading the document in pdf format is recommended, as for unknown
4881  reason the hyperlinks are working there whereas in the html version they
4882  are not
4883 \begin_inset Foot
4884 status open
4885
4886 \begin_layout Standard
4887 If you should know why please drop us a note
4888 \end_layout
4889
4890 \end_inset
4891
4892 .
4893  
4894 \newline
4895 You'll find the pdf version
4896 \begin_inset LatexCommand \index{PDF version of this document}
4897
4898 \end_inset
4899
4900  at 
4901 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4902
4903 \end_inset
4904
4905 .
4906  
4907 \newline
4908 A html version
4909 \begin_inset LatexCommand \index{HTML version of this document}
4910
4911 \end_inset
4912
4913  should be online at 
4914 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4915
4916 \end_inset
4917
4918 .
4919 \newline
4920 This documentation is in some aspects different from a commercial documentation:
4921  
4922 \end_layout
4923
4924 \begin_layout Itemize
4925 It tries to document SDCC for several processor architectures in one document
4926  (commercially these probably would be separate documents/products).
4927  This document
4928 \begin_inset LatexCommand \index{Status of documentation}
4929
4930 \end_inset
4931
4932  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4933 on about f.e.
4934  Z80, PIC14, PIC16 and HC08.
4935 \end_layout
4936
4937 \begin_layout Itemize
4938 There are many references pointing away from this documentation.
4939  Don't let this distract you.
4940  If there f.e.
4941  was a reference like 
4942 \begin_inset LatexCommand \url{http://www.opencores.org}
4943
4944 \end_inset
4945
4946  together with a statement 
4947 \begin_inset Quotes sld
4948 \end_inset
4949
4950 some processors which are targetted by SDCC can be implemented in a 
4951 \emph on
4952 f
4953 \emph default
4954 ield 
4955 \emph on
4956 p
4957 \emph default
4958 rogrammable 
4959 \emph on
4960 g
4961 \emph default
4962 ate 
4963 \emph on
4964 a
4965 \emph default
4966 rray
4967 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4968
4969 \end_inset
4970
4971
4972 \begin_inset Quotes srd
4973 \end_inset
4974
4975  or 
4976 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4977
4978 \end_inset
4979
4980
4981 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4982
4983 \end_inset
4984
4985  
4986 \begin_inset Quotes sld
4987 \end_inset
4988
4989 have you ever heard of an open source compiler that compiles a subset of
4990  C for an FPGA?
4991 \begin_inset Quotes srd
4992 \end_inset
4993
4994  we expect you to have a quick look there and come back.
4995  If you read this you are on the right track.
4996 \end_layout
4997
4998 \begin_layout Itemize
4999 Some sections attribute more space to problems, restrictions and warnings
5000  than to the solution.
5001 \end_layout
5002
5003 \begin_layout Itemize
5004 The installation section and the section about the debugger is intimidating.
5005 \end_layout
5006
5007 \begin_layout Itemize
5008 There are still lots of typos and there are more different writing styles
5009  than pictures.
5010 \end_layout
5011
5012 \begin_layout Section
5013 Testing the SDCC Compiler
5014 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5015
5016 \end_inset
5017
5018
5019 \end_layout
5020
5021 \begin_layout Standard
5022 The first thing you should do after installing your SDCC compiler is to
5023  see if it runs.
5024  Type 
5025 \family sans
5026 \series bold
5027 "sdcc -
5028 \begin_inset ERT
5029 status collapsed
5030
5031 \begin_layout Standard
5032
5033
5034 \backslash
5035 /
5036 \end_layout
5037
5038 \end_inset
5039
5040 -version"
5041 \begin_inset LatexCommand \index{version}
5042
5043 \end_inset
5044
5045
5046 \family default
5047 \series default
5048  at the prompt, and the program should run and output its version like:
5049  
5050 \newline
5051
5052 \family typewriter
5053 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5054  (UNIX)
5055 \end_layout
5056
5057 \begin_layout Standard
5058 If it doesn't run, or gives a message about not finding sdcc program, then
5059  you need to check over your installation.
5060  Make sure that the sdcc bin directory is in your executable search path
5061  defined by the PATH environment setting (
5062 \series medium
5063 see 
5064 \series default
5065 section 
5066 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5067
5068 \end_inset
5069
5070 \InsetSpace ~
5071
5072 \series medium
5073 Install trouble-shooting for suggestions
5074 \series default
5075 ).
5076  Make sure that the sdcc program is in the bin folder, if not perhaps something
5077  did not install correctly.
5078 \newline
5079
5080 \newline
5081
5082 \series medium
5083 SDCC 
5084 \series default
5085 is commonly installed as described in section 
5086 \begin_inset Quotes sld
5087 \end_inset
5088
5089 Install and search paths
5090 \begin_inset Quotes srd
5091 \end_inset
5092
5093 .
5094 \newline
5095
5096 \newline
5097
5098 \series medium
5099 Make sure the compiler works on a very simple example.
5100  Type in the following test.c program using your favorite 
5101 \series default
5102 ASCII 
5103 \series medium
5104 editor:
5105 \end_layout
5106
5107 \begin_layout Verse
5108
5109 \family typewriter
5110 char test;
5111 \newline
5112
5113 \newline
5114 void main(void) {
5115 \newline
5116 \InsetSpace ~
5117 \InsetSpace ~
5118 \InsetSpace ~
5119 \InsetSpace ~
5120 test=0;
5121 \newline
5122 }
5123 \end_layout
5124
5125 \begin_layout Standard
5126
5127 \series medium
5128 Compile this using the following command: 
5129 \family sans
5130 \series bold
5131 "sdcc -c test.c".
5132
5133 \family default
5134 \series default
5135  
5136 \series medium
5137 If all goes well, the compiler will generate a test.asm and test.rel file.
5138  Congratulations, you've just compiled your first program with SDCC.
5139  We used the -c option to tell SDCC not to link the generated code, just
5140  to keep things simple for this step.
5141 \series default
5142
5143 \newline
5144
5145 \newline
5146
5147 \series medium
5148 The next step is to try it with the linker.
5149  Type in 
5150 \family sans
5151 \series bold
5152 "sdcc test.c
5153 \family default
5154 \series default
5155 "
5156 \series medium
5157 .
5158  If all goes well the compiler will link with the libraries and produce
5159  a test.ihx output file.
5160  If this step fails
5161 \series default
5162  
5163 \series medium
5164 (no test.ihx, and the linker generates warnings), then the problem is most
5165  likely that 
5166 \series default
5167 SDCC
5168 \series medium
5169  cannot find the 
5170 \series default
5171 /
5172 \series medium
5173 usr/local/share/sdcc/lib directory
5174 \series default
5175  
5176 \series medium
5177 (see 
5178 \series default
5179 section 
5180 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5181
5182 \end_inset
5183
5184 \InsetSpace ~
5185
5186 \series medium
5187 Install trouble-shooting for suggestions).
5188 \series default
5189
5190 \newline
5191
5192 \newline
5193
5194 \series medium
5195 The final test is to ensure 
5196 \series default
5197 SDCC
5198 \series medium
5199  can use the 
5200 \series default
5201 standard
5202 \series medium
5203  header files and libraries.
5204  Edit test.c and change it to the following:
5205 \end_layout
5206
5207 \begin_layout Verse
5208
5209 \family typewriter
5210 #include <string.h>
5211 \newline
5212
5213 \newline
5214 char str1[10];
5215 \newline
5216
5217 \newline
5218 void main(void) {
5219 \newline
5220 \InsetSpace ~
5221 \InsetSpace ~
5222 strcpy(str1, "testing");
5223 \newline
5224 }
5225 \end_layout
5226
5227 \begin_layout Standard
5228
5229 \series medium
5230 Compile this by typing 
5231 \family sans
5232 \series bold
5233 "sdcc test.c"
5234 \family default
5235 \series medium
5236 .
5237  This should generate a test.ihx output file, and it should give no warnings
5238  such as not finding the string.h file.
5239  If it cannot find the string.h file, then the problem is that 
5240 \series default
5241 SDCC
5242 \series medium
5243  cannot find the /usr/local/share/sdcc/include directory
5244 \series default
5245  
5246 \series medium
5247 (see the 
5248 \series default
5249 section 
5250 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5251
5252 \end_inset
5253
5254 \InsetSpace ~
5255
5256 \series medium
5257 Install trouble-shooting section for suggestions).
5258
5259 \series default
5260  Use option 
5261 \series bold
5262 -
5263 \begin_inset ERT
5264 status collapsed
5265
5266 \begin_layout Standard
5267
5268
5269 \backslash
5270 /
5271 \end_layout
5272
5273 \end_inset
5274
5275 -print-search-dirs
5276 \series default
5277
5278 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5279
5280 \end_inset
5281
5282  to find exactly where SDCC is looking for the include and lib files.
5283 \end_layout
5284
5285 \begin_layout Section
5286 Install Trouble-shooting
5287 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5288
5289 \end_inset
5290
5291
5292 \begin_inset LatexCommand \index{Install trouble-shooting}
5293
5294 \end_inset
5295
5296
5297 \end_layout
5298
5299 \begin_layout Subsection
5300 If SDCC does not build correctly
5301 \end_layout
5302
5303 \begin_layout Standard
5304 A thing to try is starting from scratch by unpacking the .tgz source package
5305  again in an empty directory.
5306  Configure it like:
5307 \newline
5308
5309 \newline
5310
5311 \family sans
5312 \series bold
5313 ./configure 2>&1 | tee configure.log
5314 \family default
5315 \series default
5316
5317 \newline
5318
5319 \newline
5320 and build it like:
5321 \newline
5322
5323 \newline
5324
5325 \family sans
5326 \series bold
5327 make 2>&1 | tee make.log
5328 \family default
5329 \series default
5330
5331 \newline
5332
5333 \newline
5334 If anything goes wrong, you can review the log files to locate the problem.
5335  Or a relevant part of this can be attached to an email that could be helpful
5336  when requesting help from the mailing list.
5337 \end_layout
5338
5339 \begin_layout Subsection
5340 What the 
5341 \begin_inset Quotes sld
5342 \end_inset
5343
5344 ./configure
5345 \begin_inset Quotes srd
5346 \end_inset
5347
5348  does
5349 \end_layout
5350
5351 \begin_layout Standard
5352 The 
5353 \begin_inset Quotes sld
5354 \end_inset
5355
5356 ./configure
5357 \begin_inset Quotes srd
5358 \end_inset
5359
5360  command is a script that analyzes your system and performs some configuration
5361  to ensure the source package compiles on your system.
5362  It will take a few minutes to run, and will compile a few tests to determine
5363  what compiler features are installed.
5364 \end_layout
5365
5366 \begin_layout Subsection
5367 What the 
5368 \begin_inset Quotes sld
5369 \end_inset
5370
5371 make
5372 \begin_inset Quotes srd
5373 \end_inset
5374
5375  does
5376 \end_layout
5377
5378 \begin_layout Standard
5379 This runs the GNU make tool, which automatically compiles all the source
5380  packages into the final installed binary executables.
5381 \end_layout
5382
5383 \begin_layout Subsection
5384 What the 
5385 \begin_inset Quotes sld
5386 \end_inset
5387
5388 make install
5389 \begin_inset Quotes erd
5390 \end_inset
5391
5392  command does.
5393 \end_layout
5394
5395 \begin_layout Standard
5396 This will install the compiler, other executables libraries and include
5397  files into the appropriate directories.
5398  See sections 
5399 \begin_inset LatexCommand \ref{sub:Install-paths}
5400
5401 \end_inset
5402
5403 ,\InsetSpace ~
5404
5405 \begin_inset LatexCommand \ref{sub:Search-Paths}
5406
5407 \end_inset
5408
5409 \InsetSpace ~
5410 about install and search paths.
5411 \newline
5412 On most systems you will need super-user privilege
5413 s to do this.
5414 \end_layout
5415
5416 \begin_layout Section
5417 Components of SDCC
5418 \end_layout
5419
5420 \begin_layout Standard
5421 SDCC is not just a compiler, but a collection of tools by various developers.
5422  These include linkers, assemblers, simulators and other components.
5423  Here is a summary of some of the components.
5424  Note that the included simulator and assembler have separate documentation
5425  which you can find in the source package in their respective directories.
5426  As SDCC grows to include support for other processors, other packages from
5427  various developers are included and may have their own sets of documentation.
5428 \newline
5429
5430 \newline
5431 You
5432  might want to look at the files which are installed in <installdir>.
5433  At the time of this writing, we find the following programs for gcc-builds:
5434 \newline
5435
5436  
5437 \newline
5438 In <installdir>/bin:
5439 \end_layout
5440
5441 \begin_layout Itemize
5442 sdcc - The compiler.
5443 \end_layout
5444
5445 \begin_layout Itemize
5446 sdcpp - The C preprocessor.
5447 \end_layout
5448
5449 \begin_layout Itemize
5450 asx8051 - The assembler for 8051 type processors.
5451 \end_layout
5452
5453 \begin_layout Itemize
5454 as-z80
5455 \series bold
5456
5457 \series default
5458 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5459 \end_layout
5460
5461 \begin_layout Itemize
5462 aslink -The linker for 8051 type processors.
5463 \end_layout
5464
5465 \begin_layout Itemize
5466 link-z80
5467 \series bold
5468
5469 \series default
5470 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5471 \end_layout
5472
5473 \begin_layout Itemize
5474 s51 - The ucSim 8051 simulator.
5475 \end_layout
5476
5477 \begin_layout Itemize
5478 sdcdb - The source debugger.
5479 \end_layout
5480
5481 \begin_layout Itemize
5482 packihx - A tool to pack (compress) Intel hex files.
5483 \end_layout
5484
5485 \begin_layout Standard
5486 In <installdir>/share/sdcc/include
5487 \end_layout
5488
5489 \begin_layout Itemize
5490 the include files
5491 \end_layout
5492
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/lib
5495 \end_layout
5496
5497 \begin_layout Itemize
5498 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5499  relocatables.
5500 \end_layout
5501
5502 \begin_layout Standard
5503 In <installdir>/share/sdcc/doc
5504 \end_layout
5505
5506 \begin_layout Itemize
5507 the documentation
5508 \end_layout
5509
5510 \begin_layout Standard
5511 As development for other processors proceeds, this list will expand to include
5512  executables to support processors like AVR, PIC, etc.
5513 \end_layout
5514
5515 \begin_layout Subsection
5516 sdcc - The Compiler
5517 \end_layout
5518
5519 \begin_layout Standard
5520 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5521  the assembler and linkage editor.
5522 \end_layout
5523
5524 \begin_layout Subsection
5525 sdcpp - The C-Preprocessor
5526 \end_layout
5527
5528 \begin_layout Standard
5529 The preprocessor
5530 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5531
5532 \end_inset
5533
5534  is a modified version of the GNU cpp
5535 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5536
5537 \end_inset
5538
5539  preprocessor 
5540 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5541
5542 \end_inset
5543
5544 .
5545  The C preprocessor is used to pull in #include sources, process #ifdef
5546  statements, #defines and so on.
5547 \end_layout
5548
5549 \begin_layout Subsection
5550 as
5551 \emph on
5552 xxxx
5553 \emph default
5554 , aslink, link-
5555 \emph on
5556 xxx
5557 \emph default
5558  - The Assemblers and Linkage Editors
5559 \end_layout
5560
5561 \begin_layout Standard
5562 This is retargettable assembler & linkage editor, it was developed by Alan
5563  Baldwin.
5564  John Hartman created the version for 8051, and I (Sandeep) have made some
5565  enhancements and bug fixes for it to work properly with SDCC.
5566 \end_layout
5567
5568 \begin_layout Subsection
5569 s51 - The Simulator
5570 \end_layout
5571
5572 \begin_layout Standard
5573 S51
5574 \begin_inset LatexCommand \index{s51}
5575
5576 \end_inset
5577
5578  is a free open source simulator developed by Daniel Drotos.
5579  The simulator is built as part of the build process.
5580  For more information visit Daniel's web site at: 
5581 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5582
5583 \end_inset
5584
5585 .
5586  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5587  XA51 family.
5588 \end_layout
5589
5590 \begin_layout Subsection
5591 sdcdb - Source Level Debugger
5592 \end_layout
5593
5594 \begin_layout Standard
5595 SDCDB
5596 \begin_inset LatexCommand \index{SDCDB (debugger)}
5597
5598 \end_inset
5599
5600  is the companion source level debugger.
5601  More about SDCDB in section 
5602 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5603
5604 \end_inset
5605
5606 .
5607  The current version of the debugger uses Daniel's Simulator S51
5608 \begin_inset LatexCommand \index{s51}
5609
5610 \end_inset
5611
5612 , but can be easily changed to use other simulators.
5613 \end_layout
5614
5615 \begin_layout Chapter
5616 Using SDCC
5617 \end_layout
5618
5619 \begin_layout Section
5620 Compiling
5621 \end_layout
5622
5623 \begin_layout Subsection
5624 Single Source File Projects
5625 \end_layout
5626
5627 \begin_layout Standard
5628 For single source file 8051 projects the process is very simple.
5629  Compile your programs with the following command 
5630 \family sans
5631 \series bold
5632 "sdcc sourcefile.c".
5633
5634 \family default
5635 \series default
5636  This will compile, assemble and link your source file.
5637  Output files are as follows:
5638 \end_layout
5639
5640 \begin_layout Itemize
5641 sourcefile.asm
5642 \begin_inset LatexCommand \index{<file>.asm}
5643
5644 \end_inset
5645
5646  - Assembler source
5647 \begin_inset LatexCommand \index{Assembler source}
5648
5649 \end_inset
5650
5651  file created by the compiler
5652 \end_layout
5653
5654 \begin_layout Itemize
5655 sourcefile.lst
5656 \begin_inset LatexCommand \index{<file>.lst}
5657
5658 \end_inset
5659
5660  - Assembler listing
5661 \begin_inset LatexCommand \index{Assembler listing}
5662
5663 \end_inset
5664
5665  file created by the Assembler
5666 \end_layout
5667
5668 \begin_layout Itemize
5669 sourcefile.rst
5670 \begin_inset LatexCommand \index{<file>.rst}
5671
5672 \end_inset
5673
5674  - Assembler listing
5675 \begin_inset LatexCommand \index{Assembler listing}
5676
5677 \end_inset
5678
5679  file updated with linkedit information, created by linkage editor
5680 \end_layout
5681
5682 \begin_layout Itemize
5683 sourcefile.sym
5684 \begin_inset LatexCommand \index{<file>.sym}
5685
5686 \end_inset
5687
5688  - symbol listing
5689 \begin_inset LatexCommand \index{Symbol listing}
5690
5691 \end_inset
5692
5693  for the sourcefile, created by the assembler
5694 \end_layout
5695
5696 \begin_layout Itemize
5697 sourcefile.rel
5698 \begin_inset LatexCommand \index{<file>.rel}
5699
5700 \end_inset
5701
5702  or sourcefile.o
5703 \begin_inset LatexCommand \index{<file>.o}
5704
5705 \end_inset
5706
5707  - Object file
5708 \begin_inset LatexCommand \index{Object file}
5709
5710 \end_inset
5711
5712  created by the assembler, input to Linkage editor
5713 \end_layout
5714
5715 \begin_layout Itemize
5716 sourcefile.map
5717 \begin_inset LatexCommand \index{<file>.map}
5718
5719 \end_inset
5720
5721  - The memory map
5722 \begin_inset LatexCommand \index{Memory map}
5723
5724 \end_inset
5725
5726  for the load module, created by the Linker
5727 \end_layout
5728
5729 \begin_layout Itemize
5730 sourcefile.mem
5731 \begin_inset LatexCommand \index{<file>.mem}
5732
5733 \end_inset
5734
5735  - A file with a summary of the memory usage
5736 \end_layout
5737
5738 \begin_layout Itemize
5739 sourcefile.ihx
5740 \begin_inset LatexCommand \index{<file>.ihx}
5741
5742 \end_inset
5743
5744  - The load module in Intel hex format
5745 \begin_inset LatexCommand \index{Intel hex format}
5746
5747 \end_inset
5748
5749  (you can select the Motorola S19 format
5750 \begin_inset LatexCommand \index{Motorola S19 format}
5751
5752 \end_inset
5753
5754  with -
5755 \begin_inset ERT
5756 status collapsed
5757
5758 \begin_layout Standard
5759
5760
5761 \backslash
5762 /
5763 \end_layout
5764
5765 \end_inset
5766
5767 -out-fmt-s19
5768 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5769
5770 \end_inset
5771
5772 .
5773  If you need another format you might want to use 
5774 \family sans
5775 \shape italic
5776 objdump
5777 \family default
5778 \shape default
5779
5780 \begin_inset LatexCommand \index{objdump (tool)}
5781
5782 \end_inset
5783
5784  or
5785 \family sans
5786 \shape italic
5787  srecord
5788 \family default
5789 \shape default
5790
5791 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5792
5793 \end_inset
5794
5795
5796 \begin_inset Note Note
5797 status collapsed
5798
5799 \begin_layout Standard
5800 hyperlinks needed
5801 \end_layout
5802
5803 \end_inset
5804
5805  - see also section 
5806 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5807
5808 \end_inset
5809
5810 ).
5811  Both formats are documented in the documentation of srecord
5812 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5813
5814 \end_inset
5815
5816
5817 \end_layout
5818
5819 \begin_layout Itemize
5820 sourcefile.adb
5821 \begin_inset LatexCommand \index{<file>.adb}
5822
5823 \end_inset
5824
5825  - An intermediate file containing debug information needed to create the
5826  .cdb file (with -
5827 \begin_inset ERT
5828 status collapsed
5829
5830 \begin_layout Standard
5831
5832
5833 \backslash
5834 /
5835 \end_layout
5836
5837 \end_inset
5838
5839 -debug
5840 \begin_inset LatexCommand \index{-\/-debug}
5841
5842 \end_inset
5843
5844
5845 \end_layout
5846
5847 \begin_layout Itemize
5848 sourcefile.cdb
5849 \begin_inset LatexCommand \index{<file>.cdb}
5850
5851 \end_inset
5852
5853  - An optional file (with -
5854 \begin_inset ERT
5855 status collapsed
5856
5857 \begin_layout Standard
5858
5859
5860 \backslash
5861 /
5862 \end_layout
5863
5864 \end_inset
5865
5866 -debug) containing debug information.
5867  The format is documented in cdbfileformat.pdf
5868 \end_layout
5869
5870 \begin_layout Itemize
5871 sourcefile.
5872  - (no extension)
5873 \begin_inset LatexCommand \index{<file> (no extension)}
5874
5875 \end_inset
5876
5877  An optional AOMF or AOMF51
5878 \begin_inset LatexCommand \index{AOMF, AOMF51}
5879
5880 \end_inset
5881
5882  
5883 \begin_inset LatexCommand \label{OMF file}
5884
5885 \end_inset
5886
5887 file containing debug information (generated with option -
5888 \begin_inset ERT
5889 status collapsed
5890
5891 \begin_layout Standard
5892
5893
5894 \backslash
5895 /
5896 \end_layout
5897
5898 \end_inset
5899
5900 -debug).
5901  The (Intel)
5902 \emph on
5903  a
5904 \emph default
5905 bsolute 
5906 \emph on
5907 o
5908 \emph default
5909 bject 
5910 \emph on
5911 m
5912 \emph default
5913 odule 
5914 \emph on
5915 f
5916 \emph default
5917 ormat is a subformat of the OMF51 format and is commonly used by third party
5918  tools (debuggers
5919 \begin_inset LatexCommand \index{Debugger}
5920
5921 \end_inset
5922
5923 , simulators, emulators).
5924 \end_layout
5925
5926 \begin_layout Itemize
5927 sourcefile.dump*
5928 \begin_inset LatexCommand \index{<file>.dump*}
5929
5930 \end_inset
5931
5932  - Dump file to debug the compiler it self (generated with option -
5933 \begin_inset ERT
5934 status collapsed
5935
5936 \begin_layout Standard
5937
5938
5939 \backslash
5940 /
5941 \end_layout
5942
5943 \end_inset
5944
5945 -dumpall) (see section 
5946 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5947
5948 \end_inset
5949
5950 \InsetSpace ~
5951  and section 
5952 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5953
5954 \end_inset
5955
5956 \InsetSpace ~
5957
5958 \begin_inset Quotes sld
5959 \end_inset
5960
5961 Anatomy of the compiler
5962 \begin_inset Quotes srd
5963 \end_inset
5964
5965 ).
5966 \end_layout
5967
5968 \begin_layout Subsection
5969 Postprocessing the Intel Hex
5970 \begin_inset LatexCommand \index{Intel hex format}
5971
5972 \end_inset
5973
5974  file
5975 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5976
5977 \end_inset
5978
5979
5980 \end_layout
5981
5982 \begin_layout Standard
5983 In most cases this won't be needed but the Intel Hex file
5984 \begin_inset LatexCommand \index{<file>.ihx}
5985
5986 \end_inset
5987
5988  which is generated by SDCC might include lines of varying length and the
5989  addresses within the file are not guaranteed to be strictly ascending.
5990  If your toolchain or a bootloader does not like this you can use the tool
5991  
5992 \family typewriter
5993 packihx
5994 \family default
5995
5996 \begin_inset LatexCommand \index{packihx (tool)}
5997
5998 \end_inset
5999
6000  which is part of the SDCC distribution: 
6001 \newline
6002
6003 \newline
6004
6005 \family sans
6006 \series bold
6007  packihx sourcefile.ihx >sourcefile.hex
6008 \family default
6009 \series default
6010
6011 \newline
6012
6013 \newline
6014 The separately available
6015 \emph on
6016  srecord
6017 \emph default
6018
6019 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6020
6021 \end_inset
6022
6023  package additionally allows to set undefined locations to a predefined
6024  value, to insert checksums
6025 \begin_inset LatexCommand \index{checksum}
6026
6027 \end_inset
6028
6029  of various flavours (crc, add, xor) and to perform other manipulations
6030  (convert, split, crop, offset, ...).
6031  
6032 \newline
6033
6034 \newline
6035
6036 \family sans
6037 \series bold
6038 srec_cat\InsetSpace ~
6039 \InsetSpace ~
6040 sourcefile.ihx -intel\InsetSpace ~
6041 \InsetSpace ~
6042 -o sourcefile.hex -intel
6043 \newline
6044
6045 \newline
6046
6047 \family default
6048 \series default
6049 An example for a more complex command line
6050 \begin_inset Foot
6051 status open
6052
6053 \begin_layout Standard
6054 the command backfills
6055 \begin_inset LatexCommand \index{backfill unused memory}
6056
6057 \end_inset
6058
6059  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6060  block is zero.
6061  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6062  will be interpreted as an 
6063 \family typewriter
6064 lcall
6065 \family default
6066  to address 
6067 \family typewriter
6068 0x1212
6069 \family default
6070  (where an emergency routine could sit).
6071 \end_layout
6072
6073 \end_inset
6074
6075  could look like:
6076 \newline
6077
6078 \newline
6079
6080 \family sans
6081 \series bold
6082 \size footnotesize
6083 srec_cat\InsetSpace ~
6084 sourcefile.ihx -intel\InsetSpace ~
6085 \InsetSpace ~
6086 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6087 -little-endian-checksum-nega
6088 tive 0xfffe 0x02 0x02\InsetSpace ~
6089 \InsetSpace ~
6090 -o sourcefile.hex -intel
6091 \size default
6092
6093 \newline
6094
6095 \newline
6096
6097 \family default
6098 \series default
6099 The srecord package is available at 
6100 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6101
6102 \end_inset
6103
6104  .
6105 \end_layout
6106
6107 \begin_layout Subsection
6108 Projects with Multiple Source Files
6109 \end_layout
6110
6111 \begin_layout Standard
6112 SDCC can compile only ONE file at a time.
6113  Let us for example assume that you have a project containing the following
6114  files:
6115 \newline
6116
6117 \newline
6118 foo1.c (contains some functions)
6119 \newline
6120 foo2.c (contains some more functions)
6121 \newline
6122 foomai
6123 n.c (contains more functions and the function main)
6124 \newline
6125
6126 \size footnotesize
6127
6128 \newline
6129
6130 \size default
6131 The first two files will need to be compiled separately with the commands:
6132 \size footnotesize
6133  
6134 \size default
6135
6136 \newline
6137
6138 \newline
6139
6140 \family sans
6141 \series bold
6142 sdcc\InsetSpace ~
6143 -c\InsetSpace ~
6144 foo1.c
6145 \family default
6146 \series default
6147 \size footnotesize
6148
6149 \newline
6150
6151 \family sans
6152 \series bold
6153 \size default
6154 sdcc\InsetSpace ~
6155 -c\InsetSpace ~
6156 foo2.c
6157 \family default
6158 \series default
6159
6160 \newline
6161
6162 \newline
6163 Then compile the source file containing the 
6164 \emph on
6165 main()
6166 \emph default
6167  function and link
6168 \begin_inset LatexCommand \index{Linker}
6169
6170 \end_inset
6171
6172  the files together with the following command: 
6173 \newline
6174
6175 \newline
6176
6177 \family sans
6178 \series bold
6179 sdcc\InsetSpace ~
6180 foomain.c\InsetSpace ~
6181 foo1.rel\InsetSpace ~
6182 foo2.rel
6183 \family default
6184 \series default
6185
6186 \begin_inset LatexCommand \index{<file>.rel}
6187
6188 \end_inset
6189
6190
6191 \newline
6192
6193 \newline
6194 Alternatively, 
6195 \emph on
6196 foomain.c 
6197 \emph default
6198 can be separately compiled as well: 
6199 \family sans
6200 \series bold
6201
6202 \newline
6203
6204 \newline
6205 sdcc\InsetSpace ~
6206 -c\InsetSpace ~
6207 foomain.c
6208 \newline
6209 sdcc foomain.rel foo1.rel foo2.rel
6210 \newline
6211
6212 \newline
6213
6214 \family default
6215 \series default
6216 The file containing the 
6217 \emph on
6218 main()
6219 \emph default
6220  function
6221 \emph on
6222  
6223 \emph default
6224 \noun on
6225 must
6226 \noun default
6227  be the 
6228 \noun on
6229 first
6230 \noun default
6231  file specified in the command line, since the linkage editor processes
6232  file in the order they are presented to it.
6233  The linker is invoked from SDCC using a script file with extension .lnk
6234 \begin_inset LatexCommand \index{<file>.lnk}
6235
6236 \end_inset
6237
6238 .
6239  You can view this file to troubleshoot linking problems such as those arising
6240  from missing libraries.
6241 \end_layout
6242
6243 \begin_layout Subsection
6244 Projects with Additional Libraries
6245 \begin_inset LatexCommand \index{Libraries}
6246
6247 \end_inset
6248
6249
6250 \end_layout
6251
6252 \begin_layout Standard
6253 Some reusable routines may be compiled into a library, see the documentation
6254  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6255  for how to create a 
6256 \emph on
6257 .lib
6258 \begin_inset LatexCommand \index{<file>.lib}
6259
6260 \end_inset
6261
6262
6263 \emph default
6264  library file.
6265  Libraries created in this manner can be included in the command line.
6266  Make sure you include the -L <library-path> option to tell the linker where
6267  to look for these files if they are not in the current directory.
6268  Here is an example, assuming you have the source file 
6269 \emph on
6270 foomain.c
6271 \emph default
6272  and a library
6273 \emph on
6274  foolib.lib
6275 \emph default
6276  in the directory 
6277 \emph on
6278 mylib
6279 \emph default
6280  (if that is not the same as your current project):
6281 \newline
6282
6283 \newline
6284
6285 \family sans
6286 \series bold
6287 sdcc foomain.c foolib.lib -L mylib
6288 \newline
6289
6290 \newline
6291
6292 \family default
6293 \series default
6294 Note here that
6295 \emph on
6296  mylib
6297 \emph default
6298  must be an absolute path name.
6299 \newline
6300
6301 \newline
6302 The most efficient way to use libraries is
6303  to keep separate modules in separate source files.
6304  The lib file now should name all the modules.rel
6305 \begin_inset LatexCommand \index{<file>.rel}
6306
6307 \end_inset
6308
6309  files.
6310  For an example see the standard library file 
6311 \emph on
6312 libsdcc.lib
6313 \emph default
6314  in the directory <installdir>/share/lib/small.
6315 \end_layout
6316
6317 \begin_layout Subsection
6318 Using sdcclib to Create and Manage Libraries
6319 \begin_inset LatexCommand \index{sdcclib}
6320
6321 \end_inset
6322
6323
6324 \end_layout
6325
6326 \begin_layout Standard
6327 Alternatively, instead of having a .rel file for each entry on the library
6328  file as described in the preceding section, sdcclib can be used to embed
6329  all the modules belonging to such library in the library file itself.
6330  This results in a larger library file, but it greatly reduces the number
6331  of disk files accessed by the linker.
6332   Additionally, the packed library file contains an index of all include
6333  modules and symbols that significantly speeds up the linking process.
6334  To display a list of options supported by sdcclib type:
6335 \newline
6336
6337 \end_layout
6338
6339 \begin_layout Standard
6340
6341 \family sans
6342 \series bold
6343 sdcclib -?
6344 \begin_inset LatexCommand \index{sdcclib}
6345
6346 \end_inset
6347
6348
6349 \newline
6350
6351 \newline
6352
6353 \family default
6354 \series default
6355 To create a new library file, start by compiling all the required modules.
6356  For example:
6357 \newline
6358
6359 \end_layout
6360
6361 \begin_layout Standard
6362
6363 \family sans
6364 \series bold
6365 sdcc -c _divsint.c
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family sans
6371 \series bold
6372 sdcc -c _divuint.c
6373 \end_layout
6374
6375 \begin_layout Standard
6376
6377 \family sans
6378 \series bold
6379 sdcc -c _modsint.c
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family sans
6385 \series bold
6386 sdcc -c _moduint.c
6387 \end_layout
6388
6389 \begin_layout Standard
6390
6391 \family sans
6392 \series bold
6393 sdcc -c _mulint.c
6394 \newline
6395
6396 \end_layout
6397
6398 \begin_layout Standard
6399 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6400  and _mulint.rel.
6401  The next step is to add the .rel files to the library file:
6402 \newline
6403
6404 \end_layout
6405
6406 \begin_layout Standard
6407
6408 \family sans
6409 \series bold
6410 sdcclib libint.lib _divsint.rel
6411 \family default
6412
6413 \begin_inset LatexCommand \index{sdcclib}
6414
6415 \end_inset
6416
6417
6418 \end_layout
6419
6420 \begin_layout Standard
6421
6422 \family sans
6423 \series bold
6424 sdcclib libint.lib _divuint.rel
6425 \end_layout
6426
6427 \begin_layout Standard
6428
6429 \family sans
6430 \series bold
6431 sdcclib libint.lib _modsint.rel
6432 \end_layout
6433
6434 \begin_layout Standard
6435
6436 \family sans
6437 \series bold
6438 sdcclib libint.lib _moduint.rel
6439 \end_layout
6440
6441 \begin_layout Standard
6442
6443 \family sans
6444 \series bold
6445 sdcclib libint.lib _mulint.rel
6446 \family default
6447 \series default
6448
6449 \newline
6450
6451 \end_layout
6452
6453 \begin_layout Standard
6454 Or, if you preffer:
6455 \family sans
6456 \series bold
6457
6458 \newline
6459
6460 \end_layout
6461
6462 \begin_layout Standard
6463
6464 \family sans
6465 \series bold
6466 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6467 \family default
6468 \series default
6469
6470 \newline
6471
6472 \end_layout
6473
6474 \begin_layout Standard
6475 If the file already exists in the library, it will be replaced.
6476  If a list of .rel files is available, you can tell sdcclib to add those
6477  files to a library.
6478  For example, if the file 'myliblist.txt' contains
6479 \family sans
6480 \series bold
6481
6482 \newline
6483
6484 \end_layout
6485
6486 \begin_layout Standard
6487
6488 \family sans
6489 \series bold
6490 _divsint.rel
6491 \end_layout
6492
6493 \begin_layout Standard
6494
6495 \family sans
6496 \series bold
6497 _divuint.rel
6498 \end_layout
6499
6500 \begin_layout Standard
6501
6502 \family sans
6503 \series bold
6504 _modsint.rel
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family sans
6510 \series bold
6511 _moduint.rel
6512 \end_layout
6513
6514 \begin_layout Standard
6515
6516 \family sans
6517 \series bold
6518 _mulint.rel
6519 \family default
6520 \series default
6521
6522 \newline
6523
6524 \end_layout
6525
6526 \begin_layout Standard
6527 Use
6528 \family sans
6529 \series bold
6530
6531 \newline
6532
6533 \end_layout
6534
6535 \begin_layout Standard
6536
6537 \family sans
6538 \series bold
6539 sdcclib -l libint.lib myliblist.txt
6540 \family default
6541 \series default
6542
6543 \newline
6544
6545 \end_layout
6546
6547 \begin_layout Standard
6548 Additionally, you can instruct sdcclib to compiles the files before adding
6549  them to the library.
6550  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6551  For example:
6552 \family sans
6553 \series bold
6554
6555 \newline
6556
6557 \end_layout
6558
6559 \begin_layout Standard
6560
6561 \family sans
6562 \series bold
6563 set SDCCLIB_CC=sdcc -c
6564 \end_layout
6565
6566 \begin_layout Standard
6567
6568 \family sans
6569 \series bold
6570 sdcclib -l libint.lib myliblist.txt
6571 \family default
6572 \series default
6573
6574 \newline
6575
6576 \end_layout
6577
6578 \begin_layout Standard
6579 To see what modules and symbols are included in the library, options -s
6580  and -m are available.
6581  For example:
6582 \newline
6583
6584 \newline
6585
6586 \family sans
6587 \series bold
6588 sdcclib -s libint.lib
6589 \family default
6590
6591 \begin_inset LatexCommand \index{sdcclib}
6592
6593 \end_inset
6594
6595
6596 \newline
6597
6598 \family typewriter
6599 \series default
6600 _divsint.rel:
6601 \end_layout
6602
6603 \begin_layout Standard
6604
6605 \family typewriter
6606 __divsint_a_1_1
6607 \end_layout
6608
6609 \begin_layout Standard
6610
6611 \family typewriter
6612 __divsint_PARM_2
6613 \end_layout
6614
6615 \begin_layout Standard
6616
6617 \family typewriter
6618 __divsint
6619 \newline
6620 _divuint.rel:
6621 \end_layout
6622
6623 \begin_layout Standard
6624
6625 \family typewriter
6626 __divuint_a_1_1
6627 \end_layout
6628
6629 \begin_layout Standard
6630
6631 \family typewriter
6632 __divuint_PARM_2
6633 \end_layout
6634
6635 \begin_layout Standard
6636
6637 \family typewriter
6638 __divuint_reste_1_1
6639 \end_layout
6640
6641 \begin_layout Standard
6642
6643 \family typewriter
6644 __divuint_count_1_1
6645 \end_layout
6646
6647 \begin_layout Standard
6648
6649 \family typewriter
6650 __divuint
6651 \newline
6652 _modsint.rel:
6653 \end_layout
6654
6655 \begin_layout Standard
6656
6657 \family typewriter
6658 __modsint_a_1_1
6659 \end_layout
6660
6661 \begin_layout Standard
6662
6663 \family typewriter
6664 __modsint_PARM_2
6665 \end_layout
6666
6667 \begin_layout Standard
6668
6669 \family typewriter
6670 __modsint
6671 \newline
6672 _moduint.rel:
6673 \end_layout
6674
6675 \begin_layout Standard
6676
6677 \family typewriter
6678 __moduint_a_1_1
6679 \end_layout
6680
6681 \begin_layout Standard
6682
6683 \family typewriter
6684 __moduint_PARM_2
6685 \end_layout
6686
6687 \begin_layout Standard
6688
6689 \family typewriter
6690 __moduint_count_1_1
6691 \end_layout
6692
6693 \begin_layout Standard
6694
6695 \family typewriter
6696 __moduint
6697 \newline
6698 _mulint.rel:
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family typewriter
6704 __mulint_PARM_2
6705 \end_layout
6706
6707 \begin_layout Standard
6708
6709 \family typewriter
6710 __mulint
6711 \family default
6712 \series bold
6713
6714 \newline
6715
6716 \end_layout
6717
6718 \begin_layout Standard
6719 If the source files are compiled using -
6720 \begin_inset ERT
6721 status collapsed
6722
6723 \begin_layout Standard
6724
6725
6726 \backslash
6727 /
6728 \end_layout
6729
6730 \end_inset
6731
6732 -debug
6733 \begin_inset LatexCommand \index{-\/-debug}
6734
6735 \end_inset
6736
6737 , the corresponding debug information file .adb will be include in the library
6738  file as well.
6739  The library files created with sdcclib are plain text files, so they can
6740  be viewed with a text editor.
6741  It is not recomended to modify a library file created with sdcclib using
6742  a text editor, as there are file indexes numbers located accross the file
6743  used by the linker to quickly locate the required module to link.
6744  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6745  it can be safely deleted, since all the information required for linking
6746  is embedded in the library file itself.
6747  Library files created using sdcclib are used as described in the preceding
6748  sections.
6749 \begin_inset VSpace bigskip
6750 \end_inset
6751
6752
6753 \end_layout
6754
6755 \begin_layout Section
6756 Command Line Options
6757 \begin_inset LatexCommand \index{Command Line Options}
6758
6759 \end_inset
6760
6761
6762 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6763
6764 \end_inset
6765
6766
6767 \end_layout
6768
6769 \begin_layout Subsection
6770 Processor Selection Options
6771 \begin_inset LatexCommand \index{Options processor selection}
6772
6773 \end_inset
6774
6775
6776 \begin_inset LatexCommand \index{Processor selection options}
6777
6778 \end_inset
6779
6780
6781 \end_layout
6782
6783 \begin_layout List
6784 \labelwidthstring 00.00.0000
6785
6786 \series bold
6787 -mmcs51
6788 \begin_inset LatexCommand \index{-mmcs51}
6789
6790 \end_inset
6791
6792
6793 \series default
6794  Generate code for the Intel MCS51
6795 \begin_inset LatexCommand \index{MCS51}
6796
6797 \end_inset
6798
6799  family of processors.
6800  This is the default processor target.
6801 \end_layout
6802
6803 \begin_layout List
6804 \labelwidthstring 00.00.0000
6805
6806 \series bold
6807 -mds390
6808 \begin_inset LatexCommand \index{-mds390}
6809
6810 \end_inset
6811
6812
6813 \series default
6814  Generate code for the Dallas DS80C390
6815 \begin_inset LatexCommand \index{DS80C390}
6816
6817 \end_inset
6818
6819  processor.
6820 \end_layout
6821
6822 \begin_layout List
6823 \labelwidthstring 00.00.0000
6824
6825 \series bold
6826 -mds400
6827 \begin_inset LatexCommand \index{-mds400}
6828
6829 \end_inset
6830
6831
6832 \series default
6833  Generate code for the Dallas DS80C400
6834 \begin_inset LatexCommand \index{DS80C400}
6835
6836 \end_inset
6837
6838  processor.
6839 \end_layout
6840
6841 \begin_layout List
6842 \labelwidthstring 00.00.0000
6843
6844 \series bold
6845 -mhc08
6846 \begin_inset LatexCommand \index{-mhc08}
6847
6848 \end_inset
6849
6850
6851 \series default
6852  Generate code for the Freescale/Motorola HC08
6853 \begin_inset LatexCommand \index{HC08}
6854
6855 \end_inset
6856
6857  family of processors.
6858 \end_layout
6859
6860 \begin_layout List
6861 \labelwidthstring 00.00.0000
6862
6863 \series bold
6864 -mz80
6865 \begin_inset LatexCommand \index{-mz80}
6866
6867 \end_inset
6868
6869
6870 \series default
6871  Generate code for the Zilog Z80
6872 \begin_inset LatexCommand \index{Z80}
6873
6874 \end_inset
6875
6876  family of processors.
6877 \end_layout
6878
6879 \begin_layout List
6880 \labelwidthstring 00.00.0000
6881
6882 \series bold
6883 -mgbz80
6884 \begin_inset LatexCommand \index{-mgbz80}
6885
6886 \end_inset
6887
6888
6889 \series default
6890  Generate code for the GameBoy Z80
6891 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6892
6893 \end_inset
6894
6895  processor (Not actively maintained).
6896 \end_layout
6897
6898 \begin_layout List
6899 \labelwidthstring 00.00.0000
6900
6901 \series bold
6902 -mavr
6903 \begin_inset LatexCommand \index{-mavr}
6904
6905 \end_inset
6906
6907
6908 \series default
6909  Generate code for the Atmel AVR
6910 \begin_inset LatexCommand \index{AVR}
6911
6912 \end_inset
6913
6914  processor (Not maintained, not complete).
6915  AVR users should probably have a look at winavr 
6916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6917
6918 \end_inset
6919
6920  or 
6921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6922
6923 \end_inset
6924
6925 , which is based on AVR-port of the gcc compiler.
6926 \end_layout
6927
6928 \begin_layout Standard
6929 \begin_inset Note Note
6930 status collapsed
6931
6932 \begin_layout Standard
6933 I think it is fair to direct users there for now.
6934  Open source is also about avoiding unnecessary work .
6935  But I didn't find the 'official' link.
6936 \end_layout
6937
6938 \end_inset
6939
6940
6941 \end_layout
6942
6943 \begin_layout List
6944 \labelwidthstring 00.00.0000
6945
6946 \series bold
6947 -mpic14
6948 \begin_inset LatexCommand \index{-mpic14}
6949
6950 \end_inset
6951
6952
6953 \series default
6954  Generate code for the Microchip PIC 14
6955 \begin_inset LatexCommand \index{PIC14}
6956
6957 \end_inset
6958
6959 -bit processors (p16f84 and variants.
6960  In development, not complete).
6961 \end_layout
6962
6963 \begin_layout Standard
6964 \begin_inset Note Note
6965 status collapsed
6966
6967 \begin_layout Standard
6968 p16f627 p16f628 p16f84 p16f873 p16f877?
6969 \end_layout
6970
6971 \end_inset
6972
6973
6974 \end_layout
6975
6976 \begin_layout List
6977 \labelwidthstring 00.00.0000
6978
6979 \series bold
6980 -mpic16
6981 \begin_inset LatexCommand \index{-mpic16}
6982
6983 \end_inset
6984
6985
6986 \series default
6987  Generate code for the Microchip PIC 16
6988 \begin_inset LatexCommand \index{PIC16}
6989
6990 \end_inset
6991
6992 -bit processors (p18f452 and variants.
6993  In development, not complete).
6994 \end_layout
6995
6996 \begin_layout List
6997 \labelwidthstring 00.00.0000
6998
6999 \series bold
7000 -mtlcs900h
7001 \series default
7002  Generate code for the Toshiba TLCS-900H
7003 \begin_inset LatexCommand \index{TLCS-900H}
7004
7005 \end_inset
7006
7007  processor (Not maintained, not complete).
7008 \end_layout
7009
7010 \begin_layout List
7011 \labelwidthstring 00.00.0000
7012
7013 \series bold
7014 -mxa51
7015 \begin_inset LatexCommand \index{-mxa51}
7016
7017 \end_inset
7018
7019
7020 \series default
7021  Generate code for the Phillips XA51
7022 \begin_inset LatexCommand \index{XA51}
7023
7024 \end_inset
7025
7026  processor (Not maintained, not complete).
7027 \end_layout
7028
7029 \begin_layout Standard
7030 \begin_inset VSpace bigskip
7031 \end_inset
7032
7033
7034 \end_layout
7035
7036 \begin_layout Subsection
7037 Preprocessor Options
7038 \begin_inset LatexCommand \index{Options preprocessor}
7039
7040 \end_inset
7041
7042
7043 \begin_inset LatexCommand \index{Preprocessor options}
7044
7045 \end_inset
7046
7047
7048 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7049
7050 \end_inset
7051
7052
7053 \end_layout
7054
7055 \begin_layout List
7056 \labelwidthstring 00.00.0000
7057
7058 \series bold
7059 -I<path>
7060 \begin_inset LatexCommand \index{-I<path>}
7061
7062 \end_inset
7063
7064
7065 \series default
7066  The additional location where the preprocessor will look for <..h> or 
7067 \begin_inset Quotes eld
7068 \end_inset
7069
7070 ..h
7071 \begin_inset Quotes erd
7072 \end_inset
7073
7074  files.
7075 \end_layout
7076
7077 \begin_layout List
7078 \labelwidthstring 00.00.0000
7079
7080 \series bold
7081 -D<macro[=value]>
7082 \begin_inset LatexCommand \index{-D<macro[=value]>}
7083
7084 \end_inset
7085
7086
7087 \series default
7088  Command line definition of macros.
7089  Passed to the preprocessor.
7090 \end_layout
7091
7092 \begin_layout List
7093 \labelwidthstring 00.00.0000
7094
7095 \series bold
7096 -M
7097 \begin_inset LatexCommand \index{-M}
7098
7099 \end_inset
7100
7101
7102 \series default
7103  Tell the preprocessor to output a rule suitable for make describing the
7104  dependencies of each object file.
7105  For each source file, the preprocessor outputs one make-rule whose target
7106  is the object file name for that source file and whose dependencies are
7107  all the files `#include'd in it.
7108  This rule may be a single line or may be continued with `
7109 \backslash
7110 '-newline if it is long.
7111  The list of rules is printed on standard output instead of the preprocessed
7112  C program.
7113  `-M' implies `-E
7114 \begin_inset LatexCommand \index{-E}
7115
7116 \end_inset
7117
7118 '.
7119 \end_layout
7120
7121 \begin_layout List
7122 \labelwidthstring 00.00.0000
7123
7124 \series bold
7125 -C
7126 \begin_inset LatexCommand \index{-C}
7127
7128 \end_inset
7129
7130
7131 \series default
7132  Tell the preprocessor not to discard comments.
7133  Used with the `-E' option.
7134 \end_layout
7135
7136 \begin_layout List
7137 \labelwidthstring 00.00.0000
7138
7139 \series bold
7140 -MM
7141 \begin_inset LatexCommand \index{-MM}
7142
7143 \end_inset
7144
7145
7146 \size large
7147 \bar under
7148  
7149 \series default
7150 \size default
7151 \bar default
7152 Like `-M' but the output mentions only the user header files included with
7153  `#include 
7154 \begin_inset Quotes eld
7155 \end_inset
7156
7157 file"'.
7158  System header files included with `#include <file>' are omitted.
7159 \end_layout
7160
7161 \begin_layout List
7162 \labelwidthstring 00.00.0000
7163
7164 \series bold
7165 -Aquestion(answer)
7166 \begin_inset LatexCommand \index{-Aquestion(answer)}
7167
7168 \end_inset
7169
7170
7171 \series default
7172  Assert the answer answer for question, in case it is tested with a preprocessor
7173  conditional such as `#if #question(answer)'.
7174  `-A-' disables the standard assertions that normally describe the target
7175  machine.
7176 \end_layout
7177
7178 \begin_layout List
7179 \labelwidthstring 00.00.0000
7180
7181 \series bold
7182 -Umacro
7183 \begin_inset LatexCommand \index{-Umacro}
7184
7185 \end_inset
7186
7187
7188 \series default
7189  Undefine macro macro.
7190  `-U' options are evaluated after all `-D' options, but before any `-include'
7191  and `-imacros' options.
7192 \end_layout
7193
7194 \begin_layout List
7195 \labelwidthstring 00.00.0000
7196
7197 \series bold
7198 -dM
7199 \begin_inset LatexCommand \index{-dM}
7200
7201 \end_inset
7202
7203
7204 \series default
7205  Tell the preprocessor to output only a list of the macro definitions that
7206  are in effect at the end of preprocessing.
7207  Used with the `-E' option.
7208 \end_layout
7209
7210 \begin_layout List
7211 \labelwidthstring 00.00.0000
7212
7213 \series bold
7214 -dD
7215 \begin_inset LatexCommand \index{-dD}
7216
7217 \end_inset
7218
7219
7220 \series default
7221  Tell the preprocessor to pass all macro definitions into the output, in
7222  their proper sequence in the rest of the output.
7223 \end_layout
7224
7225 \begin_layout List
7226 \labelwidthstring 00.00.0000
7227
7228 \series bold
7229 -dN
7230 \begin_inset LatexCommand \index{-dN}
7231
7232 \end_inset
7233
7234
7235 \size large
7236 \bar under
7237  
7238 \series default
7239 \size default
7240 \bar default
7241 Like `-dD' except that the macro arguments and contents are omitted.
7242  Only `#define name' is included in the output.
7243 \end_layout
7244
7245 \begin_layout List
7246 \labelwidthstring 00.00.0000
7247
7248 \series bold
7249 -pedantic-parse-number
7250 \begin_inset LatexCommand \index{pedantic}
7251
7252 \end_inset
7253
7254
7255 \begin_inset LatexCommand \index{-pedantic-parse-number}
7256
7257 \end_inset
7258
7259
7260 \size large
7261 \bar under
7262
7263 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7264
7265 \end_inset
7266
7267  
7268 \series default
7269 \size default
7270 \bar default
7271 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7272  and the macro LO_B(3) gets expanded.
7273  See also #pragma pedantic_parse_number 
7274 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7275
7276 \end_inset
7277
7278  in section
7279 \begin_inset LatexCommand \ref{sec:Pragmas}
7280
7281 \end_inset
7282
7283  
7284 \emph on
7285 Note: this functionality is not in conformance with C99 standard!
7286 \end_layout
7287
7288 \begin_layout List
7289 \labelwidthstring 00.00.0000
7290
7291 \series bold
7292 -Wp\InsetSpace ~
7293 preprocessorOption[,preprocessorOption]
7294 \series default
7295
7296 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7297
7298 \end_inset
7299
7300 ...
7301  Pass the preprocessorOption to the preprocessor 
7302 \family typewriter
7303 sdcpp
7304 \family default
7305
7306 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7307
7308 \end_inset
7309
7310 .
7311  SDCC uses an adapted version of the preprocessor 
7312 \emph on
7313 cpp
7314 \emph default
7315  of the GNU Compiler Collection
7316 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7317
7318 \end_inset
7319
7320  (
7321 \emph on
7322 gcc
7323 \emph default
7324  
7325 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7326
7327 \end_inset
7328
7329 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7330 4.1.1\InsetSpace ~
7331 CPP\InsetSpace ~
7332 Manual
7333  at 
7334 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7335
7336 \end_inset
7337
7338 .
7339 \end_layout
7340
7341 \begin_layout Standard
7342 \begin_inset VSpace bigskip
7343 \end_inset
7344
7345
7346 \end_layout
7347
7348 \begin_layout Subsection
7349 Linker Options
7350 \begin_inset LatexCommand \index{Options linker}
7351
7352 \end_inset
7353
7354
7355 \begin_inset LatexCommand \index{Linker options}
7356
7357 \end_inset
7358
7359
7360 \end_layout
7361
7362 \begin_layout List
7363 \labelwidthstring 00.00.0000
7364
7365 \series bold
7366 -L\InsetSpace ~
7367 -
7368 \series default
7369
7370 \begin_inset ERT
7371 status collapsed
7372
7373 \begin_layout Standard
7374
7375
7376 \backslash
7377 /
7378 \end_layout
7379
7380 \end_inset
7381
7382
7383 \series bold
7384 -lib-path
7385 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7386
7387 \end_inset
7388
7389
7390 \begin_inset LatexCommand \index{-L -\/-lib-path}
7391
7392 \end_inset
7393
7394
7395 \series default
7396 \InsetSpace ~
7397 <absolute path to additional libraries> This option is passed to the linkage
7398  editor's additional libraries
7399 \begin_inset LatexCommand \index{Libraries}
7400
7401 \end_inset
7402
7403  search path.
7404  The path name must be absolute.
7405  Additional library files may be specified in the command line.
7406  See section Compiling programs for more details.
7407 \end_layout
7408
7409 \begin_layout List
7410 \labelwidthstring 00.00.0000
7411
7412 \series bold
7413 -
7414 \begin_inset ERT
7415 status collapsed
7416
7417 \begin_layout Standard
7418
7419
7420 \backslash
7421 /
7422 \end_layout
7423
7424 \end_inset
7425
7426 -xram-loc
7427 \series default
7428
7429 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7430
7431 \end_inset
7432
7433 \InsetSpace ~
7434 <Value> The start location of the external ram
7435 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7436
7437 \end_inset
7438
7439 , default value is 0.
7440  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7441 \begin_inset ERT
7442 status collapsed
7443
7444 \begin_layout Standard
7445
7446
7447 \backslash
7448 /
7449 \end_layout
7450
7451 \end_inset
7452
7453 -xram-loc 0x8000 or -
7454 \begin_inset ERT
7455 status collapsed
7456
7457 \begin_layout Standard
7458
7459
7460 \backslash
7461 /
7462 \end_layout
7463
7464 \end_inset
7465
7466 -xram-loc 32768.
7467 \end_layout
7468
7469 \begin_layout List
7470 \labelwidthstring 00.00.0000
7471
7472 \series bold
7473 -
7474 \begin_inset ERT
7475 status collapsed
7476
7477 \begin_layout Standard
7478
7479
7480 \backslash
7481 /
7482 \end_layout
7483
7484 \end_inset
7485
7486 -code-loc
7487 \series default
7488
7489 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7490
7491 \end_inset
7492
7493 \InsetSpace ~
7494 <Value> The start location of the code
7495 \begin_inset LatexCommand \index{code}
7496
7497 \end_inset
7498
7499  segment, default value 0.
7500  Note when this option is used the interrupt vector table
7501 \begin_inset LatexCommand \index{interrupt vector table}
7502
7503 \end_inset
7504
7505  is also relocated to the given address.
7506  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7507 \begin_inset ERT
7508 status collapsed
7509
7510 \begin_layout Standard
7511
7512
7513 \backslash
7514 /
7515 \end_layout
7516
7517 \end_inset
7518
7519 -code-loc 0x8000 or -
7520 \begin_inset ERT
7521 status collapsed
7522
7523 \begin_layout Standard
7524
7525
7526 \backslash
7527 /
7528 \end_layout
7529
7530 \end_inset
7531
7532 -code-loc 32768.
7533 \end_layout
7534
7535 \begin_layout List
7536 \labelwidthstring 00.00.0000
7537
7538 \series bold
7539 -
7540 \begin_inset ERT
7541 status collapsed
7542
7543 \begin_layout Standard
7544
7545
7546 \backslash
7547 /
7548 \end_layout
7549
7550 \end_inset
7551
7552 -stack-loc
7553 \series default
7554
7555 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7556
7557 \end_inset
7558
7559 \InsetSpace ~
7560 <Value> By default the stack
7561 \begin_inset LatexCommand \index{stack}
7562
7563 \end_inset
7564
7565  is placed after the data segment.
7566  Using this option the stack can be placed anywhere in the internal memory
7567  space of the 8051.
7568  The value entered can be in Hexadecimal or Decimal format, e.g.
7569  -
7570 \begin_inset ERT
7571 status collapsed
7572
7573 \begin_layout Standard
7574
7575
7576 \backslash
7577 /
7578 \end_layout
7579
7580 \end_inset
7581
7582 -stack-loc 0x20 or -
7583 \begin_inset ERT
7584 status collapsed
7585
7586 \begin_layout Standard
7587
7588
7589 \backslash
7590 /
7591 \end_layout
7592
7593 \end_inset
7594
7595 -stack-loc 32.
7596  Since the sp register is incremented before a push or call, the initial
7597  sp will be set to one byte prior the provided value.
7598  The provided value should not overlap any other memory areas such as used
7599  register banks or the data segment and with enough space for the current
7600  application.
7601  The 
7602 \series bold
7603 -
7604 \begin_inset ERT
7605 status collapsed
7606
7607 \begin_layout Standard
7608
7609
7610 \backslash
7611 /
7612 \end_layout
7613
7614 \end_inset
7615
7616 -pack-iram
7617 \series default
7618 \InsetSpace ~
7619
7620 \begin_inset LatexCommand \index{-\/-pack-iram}
7621
7622 \end_inset
7623
7624  option (which is now a default setting) will override this setting, so
7625  you should also specify the 
7626 \series bold
7627 -
7628 \begin_inset ERT
7629 status collapsed
7630
7631 \begin_layout Standard
7632
7633
7634 \backslash
7635 /
7636 \end_layout
7637
7638 \end_inset
7639
7640 -no-pack-iram
7641 \series default
7642 \InsetSpace ~
7643
7644 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7645
7646 \end_inset
7647
7648  option if you need to manually place the stack.
7649 \end_layout
7650
7651 \begin_layout List
7652 \labelwidthstring 00.00.0000
7653
7654 \series bold
7655 -
7656 \begin_inset ERT
7657 status collapsed
7658
7659 \begin_layout Standard
7660
7661
7662 \backslash
7663 /
7664 \end_layout
7665
7666 \end_inset
7667
7668 -xstack-loc
7669 \series default
7670
7671 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7672
7673 \end_inset
7674
7675 \InsetSpace ~
7676 <Value> By default the external stack
7677 \begin_inset LatexCommand \index{xstack}
7678
7679 \end_inset
7680
7681  is placed after the pdata
7682 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7683
7684 \end_inset
7685
7686  segment.
7687  Using this option the xstack can be placed anywhere in the external memory
7688  space of the 8051.
7689  The value entered can be in Hexadecimal or Decimal format, e.g.
7690  -
7691 \begin_inset ERT
7692 status collapsed
7693
7694 \begin_layout Standard
7695
7696
7697 \backslash
7698 /
7699 \end_layout
7700
7701 \end_inset
7702
7703 -xstack-loc 0x8000 or -
7704 \begin_inset ERT
7705 status collapsed
7706
7707 \begin_layout Standard
7708
7709
7710 \backslash
7711 /
7712 \end_layout
7713
7714 \end_inset
7715
7716 -stack-loc 32768.
7717  The provided value should not overlap any other memory areas such as the
7718  pdata or xdata segment and with enough space for the current application.
7719 \end_layout
7720
7721 \begin_layout List
7722 \labelwidthstring 00.00.0000
7723
7724 \series bold
7725 -
7726 \begin_inset ERT
7727 status collapsed
7728
7729 \begin_layout Standard
7730
7731
7732 \backslash
7733 /
7734 \end_layout
7735
7736 \end_inset
7737
7738 -data-loc
7739 \series default
7740
7741 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7742
7743 \end_inset
7744
7745 \InsetSpace ~
7746 <Value> The start location of the internal ram data
7747 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7748
7749 \end_inset
7750
7751  segment.
7752  The value entered can be in Hexadecimal or Decimal format, eg.
7753  -
7754 \begin_inset ERT
7755 status collapsed
7756
7757 \begin_layout Standard
7758
7759
7760 \backslash
7761 /
7762 \end_layout
7763
7764 \end_inset
7765
7766 -data-loc 0x20 or -
7767 \begin_inset ERT
7768 status collapsed
7769
7770 \begin_layout Standard
7771
7772
7773 \backslash
7774 /
7775 \end_layout
7776
7777 \end_inset
7778
7779 -data-loc 32.
7780  (By default, the start location of the internal ram data segment  is set
7781  as low as possible in memory, taking into account the used register banks
7782  and the bit segment at address 0x20.
7783  For example if register banks 0 and 1 are used without bit variables, the
7784  data segment will be set, if -
7785 \begin_inset ERT
7786 status collapsed
7787
7788 \begin_layout Standard
7789
7790
7791 \backslash
7792 /
7793 \end_layout
7794
7795 \end_inset
7796
7797 -data-loc is not used, to location 0x10.)
7798 \end_layout
7799
7800 \begin_layout List
7801 \labelwidthstring 00.00.0000
7802
7803 \series bold
7804 -
7805 \begin_inset ERT
7806 status collapsed
7807
7808 \begin_layout Standard
7809
7810
7811 \backslash
7812 /
7813 \end_layout
7814
7815 \end_inset
7816
7817 -idata-loc
7818 \series default
7819
7820 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7821
7822 \end_inset
7823
7824 \InsetSpace ~
7825 <Value> The start location of the indirectly addressable internal ram
7826 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7827
7828 \end_inset
7829
7830  of the 8051, default value is 0x80.
7831  The value entered can be in Hexadecimal or Decimal format, eg.
7832  -
7833 \begin_inset ERT
7834 status collapsed
7835
7836 \begin_layout Standard
7837
7838
7839 \backslash
7840 /
7841 \end_layout
7842
7843 \end_inset
7844
7845 -idata-loc 0x88 or -
7846 \begin_inset ERT
7847 status collapsed
7848
7849 \begin_layout Standard
7850
7851
7852 \backslash
7853 /
7854 \end_layout
7855
7856 \end_inset
7857
7858 -idata-loc 136.
7859 \end_layout
7860
7861 \begin_layout List
7862 \labelwidthstring 00.00.0000
7863
7864 \series bold
7865 -
7866 \begin_inset ERT
7867 status collapsed
7868
7869 \begin_layout Standard
7870
7871
7872 \backslash
7873 /
7874 \end_layout
7875
7876 \end_inset
7877
7878 -bit-loc
7879 \series default
7880 \InsetSpace ~
7881 <Value> The start location of the bit
7882 \begin_inset LatexCommand \index{bit}
7883
7884 \end_inset
7885
7886  addressable internal ram of the 8051.
7887  This is 
7888 \emph on
7889 not
7890 \emph default
7891  implemented yet.
7892  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7893 -bBSEG=<Value>.
7894 \end_layout
7895
7896 \begin_layout List
7897 \labelwidthstring 00.00.0000
7898
7899 \series bold
7900 -
7901 \begin_inset ERT
7902 status collapsed
7903
7904 \begin_layout Standard
7905
7906
7907 \backslash
7908 /
7909 \end_layout
7910
7911 \end_inset
7912
7913 -out-fmt-ihx
7914 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7915
7916 \end_inset
7917
7918
7919 \bar under
7920  
7921 \series default
7922 \bar default
7923 The linker output (final object code) is in Intel Hex format.
7924 \begin_inset LatexCommand \index{Intel hex format}
7925
7926 \end_inset
7927
7928  This is the default option.
7929  The format itself is documented in the documentation of srecord
7930 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7931
7932 \end_inset
7933
7934 .
7935 \end_layout
7936
7937 \begin_layout List
7938 \labelwidthstring 00.00.0000
7939
7940 \series bold
7941 -
7942 \begin_inset ERT
7943 status collapsed
7944
7945 \begin_layout Standard
7946
7947
7948 \backslash
7949 /
7950 \end_layout
7951
7952 \end_inset
7953
7954 -out-fmt-s19
7955 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7956
7957 \end_inset
7958
7959
7960 \bar under
7961  
7962 \series default
7963 \bar default
7964 The linker output (final object code) is in Motorola S19 format
7965 \begin_inset LatexCommand \index{Motorola S19 format}
7966
7967 \end_inset
7968
7969 .
7970  The format itself is documented in the documentation of srecord.
7971 \end_layout
7972
7973 \begin_layout List
7974 \labelwidthstring 00.00.0000
7975
7976 \series bold
7977 -
7978 \begin_inset ERT
7979 status collapsed
7980
7981 \begin_layout Standard
7982
7983
7984 \backslash
7985 /
7986 \end_layout
7987
7988 \end_inset
7989
7990 -out-fmt-elf
7991 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7992
7993 \end_inset
7994
7995
7996 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7997
7998 \end_inset
7999
8000
8001 \bar under
8002  
8003 \series default
8004 \bar default
8005 The linker output (final object code) is in ELF format
8006 \begin_inset LatexCommand \index{ELF format}
8007
8008 \end_inset
8009
8010 .
8011  (Currently only supported for the HC08
8012 \begin_inset LatexCommand \index{HC08}
8013
8014 \end_inset
8015
8016  processors)
8017 \end_layout
8018
8019 \begin_layout List
8020 \labelwidthstring 00.00.0000
8021
8022 \series bold
8023 -Wl\InsetSpace ~
8024 linkOption[,linkOption]
8025 \series default
8026
8027 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8028
8029 \end_inset
8030
8031 ...
8032  Pass the linkOption to the linker.
8033  If a bootloader is used an option like 
8034 \begin_inset Quotes sld
8035 \end_inset
8036
8037 -Wl\InsetSpace ~
8038 -bCSEG=0x1000
8039 \begin_inset Quotes srd
8040 \end_inset
8041
8042  would be typical to set the start of the code segment.
8043  See also #pragma constseg and #pragma codeseg in section 
8044 \begin_inset LatexCommand \ref{sec:Pragmas}
8045
8046 \end_inset
8047
8048  .
8049  File sdcc/as/doc/asxhtm.html has more on linker options.
8050 \end_layout
8051
8052 \begin_layout Standard
8053 \begin_inset VSpace bigskip
8054 \end_inset
8055
8056
8057 \end_layout
8058
8059 \begin_layout Subsection
8060 MCS51 Options
8061 \begin_inset LatexCommand \index{Options MCS51}
8062
8063 \end_inset
8064
8065
8066 \begin_inset LatexCommand \index{MCS51 options}
8067
8068 \end_inset
8069
8070
8071 \end_layout
8072
8073 \begin_layout List
8074 \labelwidthstring 00.00.0000
8075
8076 \series bold
8077 -
8078 \begin_inset ERT
8079 status collapsed
8080
8081 \begin_layout Standard
8082
8083
8084 \backslash
8085 /
8086 \end_layout
8087
8088 \end_inset
8089
8090 -model-small
8091 \begin_inset LatexCommand \index{-\/-model-small}
8092
8093 \end_inset
8094
8095
8096 \series default
8097 \size large
8098 \emph on
8099  
8100 \size default
8101 \emph default
8102 Generate code for Small Model programs, see section Memory Models for more
8103  details.
8104  This is the default model.
8105 \end_layout
8106
8107 \begin_layout List
8108 \labelwidthstring 00.00.0000
8109
8110 \series bold
8111 -
8112 \begin_inset ERT
8113 status collapsed
8114
8115 \begin_layout Standard
8116
8117
8118 \backslash
8119 /
8120 \end_layout
8121
8122 \end_inset
8123
8124 -model-medium
8125 \begin_inset LatexCommand \index{-\/-model-medium}
8126
8127 \end_inset
8128
8129
8130 \series default
8131  Generate code for Medium model programs, see section Memory Models for
8132  more details.
8133  If this option is used all source files in the project have to be compiled
8134  with this option.
8135  It must also be used when invoking the linker.
8136 \end_layout
8137
8138 \begin_layout List
8139 \labelwidthstring 00.00.0000
8140
8141 \series bold
8142 -
8143 \begin_inset ERT
8144 status collapsed
8145
8146 \begin_layout Standard
8147
8148
8149 \backslash
8150 /
8151 \end_layout
8152
8153 \end_inset
8154
8155 -model-large
8156 \begin_inset LatexCommand \index{-\/-model-large}
8157
8158 \end_inset
8159
8160
8161 \series default
8162  Generate code for Large model programs, see section Memory Models for more
8163  details.
8164  If this option is used all source files in the project have to be compiled
8165  with this option.
8166  It must also be used when invoking the linker.
8167 \end_layout
8168
8169 \begin_layout List
8170 \labelwidthstring 00.00.0000
8171
8172 \series bold
8173 -
8174 \begin_inset ERT
8175 status collapsed
8176
8177 \begin_layout Standard
8178
8179
8180 \backslash
8181 /
8182 \end_layout
8183
8184 \end_inset
8185
8186 -xstack
8187 \begin_inset LatexCommand \index{-\/-xstack}
8188
8189 \end_inset
8190
8191
8192 \series default
8193  Uses a pseudo stack in the pdata
8194 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8195
8196 \end_inset
8197
8198  area (usually the first 256 bytes in the external ram) for allocating variables
8199  and passing parameters.
8200  See section 
8201 \begin_inset LatexCommand \ref{sub:External-Stack}
8202
8203 \end_inset
8204
8205 \InsetSpace ~
8206  External Stack for more details.
8207 \end_layout
8208
8209 \begin_layout List
8210 \labelwidthstring 00.00.0000
8211
8212 \series bold
8213 -
8214 \begin_inset ERT
8215 status collapsed
8216
8217 \begin_layout Standard
8218
8219
8220 \backslash
8221 /
8222 \end_layout
8223
8224 \end_inset
8225
8226 -iram-size
8227 \series default
8228 \InsetSpace ~
8229 <Value>
8230 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8231
8232 \end_inset
8233
8234  Causes the linker to check if the internal ram usage is within limits of
8235  the given value.
8236 \end_layout
8237
8238 \begin_layout List
8239 \labelwidthstring 00.00.0000
8240
8241 \series bold
8242 -
8243 \begin_inset ERT
8244 status collapsed
8245
8246 \begin_layout Standard
8247
8248
8249 \backslash
8250 /
8251 \end_layout
8252
8253 \end_inset
8254
8255 -xram-size
8256 \series default
8257 \InsetSpace ~
8258 <Value>
8259 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8260
8261 \end_inset
8262
8263  Causes the linker to check if the external ram usage is within limits of
8264  the given value.
8265 \end_layout
8266
8267 \begin_layout List
8268 \labelwidthstring 00.00.0000
8269
8270 \series bold
8271 -
8272 \begin_inset ERT
8273 status collapsed
8274
8275 \begin_layout Standard
8276
8277
8278 \backslash
8279 /
8280 \end_layout
8281
8282 \end_inset
8283
8284 -code-size
8285 \series default
8286 \InsetSpace ~
8287 <Value>
8288 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8289
8290 \end_inset
8291
8292  Causes the linker to check if the code memory usage is within limits of
8293  the given value.
8294 \end_layout
8295
8296 \begin_layout List
8297 \labelwidthstring 00.00.0000
8298
8299 \series bold
8300 -
8301 \begin_inset ERT
8302 status collapsed
8303
8304 \begin_layout Standard
8305
8306
8307 \backslash
8308 /
8309 \end_layout
8310
8311 \end_inset
8312
8313 -stack-size
8314 \series default
8315 \InsetSpace ~
8316 <Value>
8317 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8318
8319 \end_inset
8320
8321  Causes the linker to check if there is at minimum <Value> bytes for stack.
8322 \end_layout
8323
8324 \begin_layout List
8325 \labelwidthstring 00.00.0000
8326
8327 \series bold
8328 -
8329 \begin_inset ERT
8330 status collapsed
8331
8332 \begin_layout Standard
8333
8334
8335 \backslash
8336 /
8337 \end_layout
8338
8339 \end_inset
8340
8341 -pack-iram
8342 \series default
8343 \InsetSpace ~
8344
8345 \begin_inset LatexCommand \index{-\/-pack-iram}
8346
8347 \end_inset
8348
8349  Causes the linker to use unused register banks for data variables and pack
8350  data, idata and stack together.
8351  This is the default now.
8352 \end_layout
8353
8354 \begin_layout List
8355 \labelwidthstring 00.00.0000
8356
8357 \series bold
8358 -
8359 \begin_inset ERT
8360 status collapsed
8361
8362 \begin_layout Standard
8363
8364
8365 \backslash
8366 /
8367 \end_layout
8368
8369 \end_inset
8370
8371 -no-pack-iram
8372 \series default
8373 \InsetSpace ~
8374
8375 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8376
8377 \end_inset
8378
8379  Causes the linker to use old style for allocating memory areas.
8380 \end_layout
8381
8382 \begin_layout List
8383 \labelwidthstring 00.00.0000
8384
8385 \series bold
8386 -
8387 \begin_inset ERT
8388 status collapsed
8389
8390 \begin_layout Standard
8391
8392
8393 \backslash
8394 /
8395 \end_layout
8396
8397 \end_inset
8398
8399 -acall-ajmp
8400 \series default
8401 \InsetSpace ~
8402
8403 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8404
8405 \end_inset
8406
8407  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8408  acall/ajmp.
8409  Only use this option if your code is in the same 2k block of memory.
8410  You may need to use this option for some 8051 derivatives which lack the
8411  lcall/ljmp instructions..
8412 \end_layout
8413
8414 \begin_layout Standard
8415 \begin_inset VSpace bigskip
8416 \end_inset
8417
8418
8419 \end_layout
8420
8421 \begin_layout Subsection
8422 DS390 / DS400 Options
8423 \begin_inset LatexCommand \index{Options DS390}
8424
8425 \end_inset
8426
8427
8428 \begin_inset LatexCommand \index{DS390}
8429
8430 \end_inset
8431
8432
8433 \end_layout
8434
8435 \begin_layout List
8436 \labelwidthstring 00.00.0000
8437
8438 \series bold
8439 -
8440 \begin_inset ERT
8441 status collapsed
8442
8443 \begin_layout Standard
8444
8445
8446 \backslash
8447 /
8448 \end_layout
8449
8450 \end_inset
8451
8452 -model-flat24
8453 \series default
8454
8455 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8456
8457 \end_inset
8458
8459
8460 \size large
8461 \emph on
8462  
8463 \size default
8464 \emph default
8465 Generate 24-bit flat mode code.
8466  This is the one and only that the ds390 code generator supports right now
8467  and is default when using 
8468 \emph on
8469 -mds390
8470 \emph default
8471 .
8472  See section Memory Models for more details.
8473 \end_layout
8474
8475 \begin_layout List
8476 \labelwidthstring 00.00.0000
8477
8478 \series bold
8479 -
8480 \begin_inset ERT
8481 status collapsed
8482
8483 \begin_layout Standard
8484
8485
8486 \backslash
8487 /
8488 \end_layout
8489
8490 \end_inset
8491
8492 -protect-sp-update
8493 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8494
8495 \end_inset
8496
8497
8498 \series default
8499  disable interrupts during ESP:SP updates.
8500 \end_layout
8501
8502 \begin_layout List
8503 \labelwidthstring 00.00.0000
8504
8505 \series bold
8506 -
8507 \begin_inset ERT
8508 status collapsed
8509
8510 \begin_layout Standard
8511
8512
8513 \backslash
8514 /
8515 \end_layout
8516
8517 \end_inset
8518
8519 -stack-10bit
8520 \series default
8521
8522 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8523
8524 \end_inset
8525
8526  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8527  This is the one and only that the ds390 code generator supports right now
8528  and is default when using 
8529 \emph on
8530 -mds390
8531 \emph default
8532 .
8533  In this mode, the stack is located in the lower 1K of the internal RAM,
8534  which is mapped to 0x400000.
8535  Note that the support is incomplete, since it still uses a single byte
8536  as the stack pointer.
8537  This means that only the lower 256 bytes of the potential 1K stack space
8538  will actually be used.
8539  However, this does allow you to reclaim the precious 256 bytes of low RAM
8540  for use for the DATA and IDATA segments.
8541  The compiler will not generate any code to put the processor into 10 bit
8542  stack mode.
8543  It is important to ensure that the processor is in this mode before calling
8544  any re-entrant functions compiled with this option.
8545  In principle, this should work with the 
8546 \emph on
8547 -
8548 \begin_inset ERT
8549 status collapsed
8550
8551 \begin_layout Standard
8552
8553
8554 \backslash
8555 /
8556 \end_layout
8557
8558 \end_inset
8559
8560 -stack-auto
8561 \begin_inset LatexCommand \index{-\/-stack-auto}
8562
8563 \end_inset
8564
8565
8566 \emph default
8567  option, but that has not been tested.
8568  It is incompatible with the 
8569 \emph on
8570 -
8571 \begin_inset ERT
8572 status collapsed
8573
8574 \begin_layout Standard
8575
8576
8577 \backslash
8578 /
8579 \end_layout
8580
8581 \end_inset
8582
8583 -xstack
8584 \begin_inset LatexCommand \index{-\/-xstack}
8585
8586 \end_inset
8587
8588
8589 \emph default
8590  option.
8591  It also only makes sense if the processor is in 24 bit contiguous addressing
8592  mode (see the 
8593 \emph on
8594 -
8595 \begin_inset ERT
8596 status collapsed
8597
8598 \begin_layout Standard
8599
8600
8601 \backslash
8602 /
8603 \end_layout
8604
8605 \end_inset
8606
8607 -model-flat24 option
8608 \emph default
8609 ).
8610 \series bold
8611
8612 \begin_inset Note Note
8613 status collapsed
8614
8615 \begin_layout List
8616 \labelwidthstring 00.00.0000
8617
8618 \series bold
8619 -
8620 \begin_inset ERT
8621 status open
8622
8623 \begin_layout Standard
8624
8625
8626 \backslash
8627 /
8628 \end_layout
8629
8630 \end_inset
8631
8632 -stack-8-bit - switches off the 10-bit mode
8633 \end_layout
8634
8635 \end_inset
8636
8637
8638 \end_layout
8639
8640 \begin_layout List
8641 \labelwidthstring 00.00.0000
8642
8643 \series bold
8644 -
8645 \begin_inset ERT
8646 status collapsed
8647
8648 \begin_layout Standard
8649
8650
8651 \backslash
8652 /
8653 \end_layout
8654
8655 \end_inset
8656
8657 -stack-probe
8658 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8659
8660 \end_inset
8661
8662
8663 \series default
8664  insert call to function __stack_probe at each function prologue.
8665 \end_layout
8666
8667 \begin_layout List
8668 \labelwidthstring 00.00.0000
8669
8670 \series bold
8671 -
8672 \begin_inset ERT
8673 status open
8674
8675 \begin_layout Standard
8676
8677
8678 \backslash
8679 /
8680 \end_layout
8681
8682 \end_inset
8683
8684 -tini-libid
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8686
8687 \end_inset
8688
8689
8690 \series default
8691  <nnnn> LibraryID used in -mTININative.
8692  
8693 \end_layout
8694
8695 \begin_layout List
8696 \labelwidthstring 00.00.0000
8697
8698 \series bold
8699 -
8700 \begin_inset ERT
8701 status collapsed
8702
8703 \begin_layout Standard
8704
8705
8706 \backslash
8707 /
8708 \end_layout
8709
8710 \end_inset
8711
8712 -use-accelerator
8713 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8714
8715 \end_inset
8716
8717
8718 \series default
8719  generate code for DS390 Arithmetic Accelerator.
8720  
8721 \end_layout
8722
8723 \begin_layout Standard
8724 \begin_inset VSpace bigskip
8725 \end_inset
8726
8727
8728 \end_layout
8729
8730 \begin_layout Subsection
8731 Z80 Options
8732 \begin_inset LatexCommand \index{Options Z80}
8733
8734 \end_inset
8735
8736
8737 \begin_inset LatexCommand \index{Z80}
8738
8739 \end_inset
8740
8741
8742 \end_layout
8743
8744 \begin_layout List
8745 \labelwidthstring 00.00.0000
8746
8747 \series bold
8748 -
8749 \begin_inset ERT
8750 status collapsed
8751
8752 \begin_layout Standard
8753
8754
8755 \backslash
8756 /
8757 \end_layout
8758
8759 \end_inset
8760
8761 -callee-saves-bc
8762 \series default
8763
8764 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8765
8766 \end_inset
8767
8768
8769 \size large
8770 \emph on
8771  
8772 \size default
8773 \emph default
8774 Force a called function to always save BC.
8775 \end_layout
8776
8777 \begin_layout List
8778 \labelwidthstring 00.00.0000
8779
8780 \series bold
8781 -
8782 \begin_inset ERT
8783 status collapsed
8784
8785 \begin_layout Standard
8786
8787
8788 \backslash
8789 /
8790 \end_layout
8791
8792 \end_inset
8793
8794 -no-std-crt0
8795 \series default
8796
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8798
8799 \end_inset
8800
8801  When linking, skip the standard crt0.o object file.
8802  You must provide your own crt0.o for your system when linking.
8803 \end_layout
8804
8805 \begin_layout List
8806 \labelwidthstring 00.00.0000
8807
8808 \series bold
8809 -
8810 \begin_inset ERT
8811 status collapsed
8812
8813 \begin_layout Standard
8814
8815
8816 \backslash
8817 /
8818 \end_layout
8819
8820 \end_inset
8821
8822 -portmode=
8823 \series default
8824 <Value>
8825 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8826
8827 \end_inset
8828
8829  Determinate PORT I/O mode (<Value> is z80 or z180).
8830 \end_layout
8831
8832 \begin_layout List
8833 \labelwidthstring 00.00.0000
8834
8835 \series bold
8836 -
8837 \begin_inset ERT
8838 status collapsed
8839
8840 \begin_layout Standard
8841
8842
8843 \backslash
8844 /
8845 \end_layout
8846
8847 \end_inset
8848
8849 -asm=
8850 \series default
8851 <Value>
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8853
8854 \end_inset
8855
8856  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8857 \end_layout
8858
8859 \begin_layout List
8860 \labelwidthstring 00.00.0000
8861
8862 \series bold
8863 -
8864 \begin_inset ERT
8865 status collapsed
8866
8867 \begin_layout Standard
8868
8869
8870 \backslash
8871 /
8872 \end_layout
8873
8874 \end_inset
8875
8876 -codeseg
8877 \series default
8878 \InsetSpace ~
8879 <Value>
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8881
8882 \end_inset
8883
8884  Use <Value> for the code segment name.
8885 \end_layout
8886
8887 \begin_layout List
8888 \labelwidthstring 00.00.0000
8889
8890 \series bold
8891 -
8892 \begin_inset ERT
8893 status collapsed
8894
8895 \begin_layout Standard
8896
8897
8898 \backslash
8899 /
8900 \end_layout
8901
8902 \end_inset
8903
8904 -constseg
8905 \series default
8906 \InsetSpace ~
8907 <Value>
8908 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8909
8910 \end_inset
8911
8912  Use <Value> for the const segment name.
8913 \end_layout
8914
8915 \begin_layout List
8916 \labelwidthstring 00.00.0000
8917 \begin_inset VSpace bigskip
8918 \end_inset
8919
8920
8921 \end_layout
8922
8923 \begin_layout Subsection
8924 GBZ80 Options
8925 \begin_inset LatexCommand \index{Options GBZ80}
8926
8927 \end_inset
8928
8929
8930 \begin_inset LatexCommand \index{GBZ80}
8931
8932 \end_inset
8933
8934
8935 \end_layout
8936
8937 \begin_layout List
8938 \labelwidthstring 00.00.0000
8939
8940 \series bold
8941 -
8942 \begin_inset ERT
8943 status collapsed
8944
8945 \begin_layout Standard
8946
8947
8948 \backslash
8949 /
8950 \end_layout
8951
8952 \end_inset
8953
8954 -callee-saves-bc
8955 \series default
8956
8957 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8958
8959 \end_inset
8960
8961
8962 \size large
8963 \emph on
8964  
8965 \size default
8966 \emph default
8967 Force a called function to always save BC.
8968 \end_layout
8969
8970 \begin_layout List
8971 \labelwidthstring 00.00.0000
8972
8973 \series bold
8974 -
8975 \begin_inset ERT
8976 status collapsed
8977
8978 \begin_layout Standard
8979
8980
8981 \backslash
8982 /
8983 \end_layout
8984
8985 \end_inset
8986
8987 -no-std-crt0
8988 \series default
8989
8990 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8991
8992 \end_inset
8993
8994  When linking, skip the standard crt0.o object file.
8995  You must provide your own crt0.o for your system when linking.
8996 \end_layout
8997
8998 \begin_layout List
8999 \labelwidthstring 00.00.0000
9000
9001 \series bold
9002 -bo
9003 \series default
9004 \InsetSpace ~
9005 <Num>
9006 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9007
9008 \end_inset
9009
9010  Use code bank <Num>.
9011 \end_layout
9012
9013 \begin_layout List
9014 \labelwidthstring 00.00.0000
9015
9016 \series bold
9017 -ba
9018 \series default
9019 \InsetSpace ~
9020 <Num>
9021 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9022
9023 \end_inset
9024
9025  Use data bank <Num>.
9026 \end_layout
9027
9028 \begin_layout List
9029 \labelwidthstring 00.00.0000
9030
9031 \series bold
9032 -
9033 \begin_inset ERT
9034 status collapsed
9035
9036 \begin_layout Standard
9037
9038
9039 \backslash
9040 /
9041 \end_layout
9042
9043 \end_inset
9044
9045 -codeseg
9046 \series default
9047 \InsetSpace ~
9048 <Value>
9049 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9050
9051 \end_inset
9052
9053  Use <Value> for the code segment name.
9054 \end_layout
9055
9056 \begin_layout List
9057 \labelwidthstring 00.00.0000
9058
9059 \series bold
9060 -
9061 \begin_inset ERT
9062 status collapsed
9063
9064 \begin_layout Standard
9065
9066
9067 \backslash
9068 /
9069 \end_layout
9070
9071 \end_inset
9072
9073 -constseg
9074 \series default
9075 \InsetSpace ~
9076 <Value>
9077 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9078
9079 \end_inset
9080
9081  Use <Value> for the const segment name.
9082 \end_layout
9083
9084 \begin_layout Standard
9085 \begin_inset VSpace bigskip
9086 \end_inset
9087
9088
9089 \end_layout
9090
9091 \begin_layout Subsection
9092 Optimization Options
9093 \begin_inset LatexCommand \index{Options optimization}
9094
9095 \end_inset
9096
9097
9098 \begin_inset LatexCommand \index{Optimization options}
9099
9100 \end_inset
9101
9102
9103 \end_layout
9104
9105 \begin_layout List
9106 \labelwidthstring 00.00.0000
9107
9108 \series bold
9109 -
9110 \begin_inset ERT
9111 status collapsed
9112
9113 \begin_layout Standard
9114
9115
9116 \backslash
9117 /
9118 \end_layout
9119
9120 \end_inset
9121
9122 -nogcse
9123 \begin_inset LatexCommand \index{-\/-nogcse}
9124
9125 \end_inset
9126
9127
9128 \series default
9129  Will not do global subexpression elimination, this option may be used when
9130  the compiler creates undesirably large stack/data spaces to store compiler
9131  temporaries (
9132 \emph on
9133 s
9134 \emph default
9135 pill 
9136 \emph on
9137 loc
9138 \emph default
9139 ations, sloc
9140 \begin_inset LatexCommand \index{sloc (spill location)}
9141
9142 \end_inset
9143
9144 ).
9145  A warning message will be generated when this happens and the compiler
9146  will indicate the number of extra bytes it allocated.
9147  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9148 nogcse
9149 \begin_inset LatexCommand \index{\#pragma nogcse}
9150
9151 \end_inset
9152
9153  can be used to turn off global subexpression elimination
9154 \begin_inset LatexCommand \index{Subexpression elimination}
9155
9156 \end_inset
9157
9158  for a given function only.
9159 \end_layout
9160
9161 \begin_layout List
9162 \labelwidthstring 00.00.0000
9163
9164 \series bold
9165 -
9166 \begin_inset ERT
9167 status collapsed
9168
9169 \begin_layout Standard
9170
9171
9172 \backslash
9173 /
9174 \end_layout
9175
9176 \end_inset
9177
9178 -noinvariant
9179 \begin_inset LatexCommand \index{-\/-noinvariant}
9180
9181 \end_inset
9182
9183
9184 \series default
9185  Will not do loop invariant optimizations, this may be turned off for reasons
9186  explained for the previous option.
9187  For more details of loop optimizations performed see Loop Invariants in
9188  section 
9189 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9190
9191 \end_inset
9192
9193 .
9194  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9195 noinvariant
9196 \begin_inset LatexCommand \index{\#pragma noinvariant}
9197
9198 \end_inset
9199
9200  can be used to turn off invariant optimizations for a given function only.
9201 \end_layout
9202
9203 \begin_layout List
9204 \labelwidthstring 00.00.0000
9205
9206 \series bold
9207 -
9208 \begin_inset ERT
9209 status collapsed
9210
9211 \begin_layout Standard
9212
9213
9214 \backslash
9215 /
9216 \end_layout
9217
9218 \end_inset
9219
9220 -noinduction
9221 \begin_inset LatexCommand \index{-\/-noinduction}
9222
9223 \end_inset
9224
9225
9226 \series default
9227  Will not do loop induction optimizations, see section strength reduction
9228  for more details.
9229  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9230 noinduction
9231 \begin_inset LatexCommand \index{\#pragma noinduction}
9232
9233 \end_inset
9234
9235  can be used to turn off induction optimizations for a given function only.
9236 \end_layout
9237
9238 \begin_layout List
9239 \labelwidthstring 00.00.0000
9240
9241 \series bold
9242 -
9243 \begin_inset ERT
9244 status collapsed
9245
9246 \begin_layout Standard
9247
9248
9249 \backslash
9250 /
9251 \end_layout
9252
9253 \end_inset
9254
9255 -nojtbound
9256 \begin_inset LatexCommand \index{-\/-nojtbound}
9257
9258 \end_inset
9259
9260
9261 \size large
9262 \bar under
9263  
9264 \series default
9265 \size default
9266 \bar default
9267  Will not generate boundary condition check when switch statements
9268 \begin_inset LatexCommand \index{switch statement}
9269
9270 \end_inset
9271
9272  are implemented using jump-tables.
9273  See section 
9274 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9275
9276 \end_inset
9277
9278 \InsetSpace ~
9279 Switch Statements for more details.
9280  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9281 nojtbound
9282 \begin_inset LatexCommand \index{\#pragma nojtbound}
9283
9284 \end_inset
9285
9286  can be used to turn off boundary checking for jump tables for a given function
9287  only.
9288 \end_layout
9289
9290 \begin_layout List
9291 \labelwidthstring 00.00.0000
9292
9293 \series bold
9294 -
9295 \begin_inset ERT
9296 status collapsed
9297
9298 \begin_layout Standard
9299
9300
9301 \backslash
9302 /
9303 \end_layout
9304
9305 \end_inset
9306
9307 -noloopreverse
9308 \begin_inset LatexCommand \index{-\/-noloopreverse}
9309
9310 \end_inset
9311
9312
9313 \series default
9314 \size large
9315  
9316 \size default
9317 Will not do loop reversal 
9318 \begin_inset LatexCommand \index{Loop reversing}
9319
9320 \end_inset
9321
9322 optimization.
9323 \end_layout
9324
9325 \begin_layout List
9326 \labelwidthstring 00.00.0000
9327 -
9328 \begin_inset ERT
9329 status collapsed
9330
9331 \begin_layout Standard
9332
9333
9334 \backslash
9335 /
9336 \end_layout
9337
9338 \end_inset
9339
9340 -
9341 \series bold
9342 nolabelopt
9343 \series default
9344  
9345 \begin_inset LatexCommand \index{-\/-nolabelopt }
9346
9347 \end_inset
9348
9349 Will not optimize labels (makes the dumpfiles more readable).
9350 \end_layout
9351
9352 \begin_layout List
9353 \labelwidthstring 00.00.0000
9354
9355 \series bold
9356 -
9357 \begin_inset ERT
9358 status collapsed
9359
9360 \begin_layout Standard
9361
9362
9363 \backslash
9364 /
9365 \end_layout
9366
9367 \end_inset
9368
9369 -no-xinit-opt
9370 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9371
9372 \end_inset
9373
9374
9375 \series default
9376  Will not memcpy initialized data from code space into xdata space.
9377  This saves a few bytes in code space if you don't have initialized data
9378 \begin_inset LatexCommand \index{Variable initialization}
9379
9380 \end_inset
9381
9382 .
9383 \end_layout
9384
9385 \begin_layout List
9386 \labelwidthstring 00.00.0000
9387
9388 \series bold
9389 -
9390 \begin_inset ERT
9391 status collapsed
9392
9393 \begin_layout Standard
9394
9395
9396 \backslash
9397 /
9398 \end_layout
9399
9400 \end_inset
9401
9402 -nooverlay
9403 \begin_inset LatexCommand \index{-\/-nooverlay}
9404
9405 \end_inset
9406
9407
9408 \series default
9409   The compiler will not overlay parameters and local variables of any function,
9410  see section Parameters and local variables for more details.
9411 \end_layout
9412
9413 \begin_layout List
9414 \labelwidthstring 00.00.0000
9415
9416 \series bold
9417 -
9418 \begin_inset ERT
9419 status collapsed
9420
9421 \begin_layout Standard
9422
9423
9424 \backslash
9425 /
9426 \end_layout
9427
9428 \end_inset
9429
9430 -no-peep
9431 \begin_inset LatexCommand \index{-\/-no-peep}
9432
9433 \end_inset
9434
9435
9436 \series default
9437  Disable peep-hole optimization with built-in rules.
9438 \end_layout
9439
9440 \begin_layout List
9441 \labelwidthstring 00.00.0000
9442
9443 \series bold
9444 -
9445 \begin_inset ERT
9446 status collapsed
9447
9448 \begin_layout Standard
9449
9450
9451 \backslash
9452 /
9453 \end_layout
9454
9455 \end_inset
9456
9457 -peep-file
9458 \series default
9459
9460 \begin_inset LatexCommand \index{-\/-peep-file}
9461
9462 \end_inset
9463
9464 \InsetSpace ~
9465 <filename> This option can be used to use additional rules to be used by
9466  the peep hole optimizer.
9467  See section 
9468 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9469
9470 \end_inset
9471
9472 \InsetSpace ~
9473 Peep Hole optimizations for details on how to write these rules.
9474 \end_layout
9475
9476 \begin_layout List
9477 \labelwidthstring 00.00.0000
9478
9479 \series bold
9480 -
9481 \begin_inset ERT
9482 status collapsed
9483
9484 \begin_layout Standard
9485
9486
9487 \backslash
9488 /
9489 \end_layout
9490
9491 \end_inset
9492
9493 -peep-asm
9494 \begin_inset LatexCommand \index{-\/-peep-asm}
9495
9496 \end_inset
9497
9498
9499 \series default
9500  Pass the inline assembler code through the peep hole optimizer.
9501  This can cause unexpected changes to inline assembler code, please go through
9502  the peephole optimizer
9503 \begin_inset LatexCommand \index{Peephole optimizer}
9504
9505 \end_inset
9506
9507  rules defined in the source file tree '<target>/peeph.def' before using
9508  this option.
9509 \end_layout
9510
9511 \begin_layout List
9512 \labelwidthstring 00.00.0000
9513
9514 \series bold
9515 -
9516 \begin_inset ERT
9517 status collapsed
9518
9519 \begin_layout Standard
9520
9521
9522 \backslash
9523 /
9524 \end_layout
9525
9526 \end_inset
9527
9528 -opt-code-speed
9529 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9530
9531 \end_inset
9532
9533
9534 \series default
9535  The compiler will optimize code generation towards fast code, possibly
9536  at the expense of code size.
9537 \end_layout
9538
9539 \begin_layout List
9540 \labelwidthstring 00.00.0000
9541
9542 \series bold
9543 -
9544 \begin_inset ERT
9545 status collapsed
9546
9547 \begin_layout Standard
9548
9549
9550 \backslash
9551 /
9552 \end_layout
9553
9554 \end_inset
9555
9556 -opt-code-size
9557 \begin_inset LatexCommand \index{-\/-opt-code-size}
9558
9559 \end_inset
9560
9561
9562 \series default
9563  The compiler will optimize code generation towards compact code, possibly
9564  at the expense of code speed.
9565 \end_layout
9566
9567 \begin_layout Standard
9568 \begin_inset VSpace bigskip
9569 \end_inset
9570
9571
9572 \end_layout
9573
9574 \begin_layout Subsection
9575 Other Options
9576 \begin_inset LatexCommand \index{Options other}
9577
9578 \end_inset
9579
9580
9581 \end_layout
9582
9583 \begin_layout List
9584 \labelwidthstring 00.00.0000
9585
9586 \series bold
9587 -c\InsetSpace ~
9588 -
9589 \begin_inset ERT
9590 status collapsed
9591
9592 \begin_layout Standard
9593
9594
9595 \backslash
9596 /
9597 \end_layout
9598
9599 \end_inset
9600
9601 -compile-only
9602 \begin_inset LatexCommand \index{-\/-compile-only}
9603
9604 \end_inset
9605
9606
9607 \begin_inset LatexCommand \index{-c -\/-compile-only}
9608
9609 \end_inset
9610
9611
9612 \series default
9613  will compile and assemble the source, but will not call the linkage editor.
9614 \end_layout
9615
9616 \begin_layout List
9617 \labelwidthstring 00.00.0000
9618
9619 \series bold
9620 -
9621 \series default
9622
9623 \begin_inset ERT
9624 status collapsed
9625
9626 \begin_layout Standard
9627
9628
9629 \backslash
9630 /
9631 \end_layout
9632
9633 \end_inset
9634
9635
9636 \series bold
9637 -c1mode
9638 \begin_inset LatexCommand \index{-\/-c1mode}
9639
9640 \end_inset
9641
9642
9643 \series default
9644  reads the preprocessed source from standard input and compiles it.
9645  The file name for the assembler output must be specified using the -o option.
9646 \end_layout
9647
9648 \begin_layout List
9649 \labelwidthstring 00.00.0000
9650
9651 \series bold
9652 -E
9653 \begin_inset LatexCommand \index{-E}
9654
9655 \end_inset
9656
9657
9658 \series default
9659  Run only the C preprocessor.
9660  Preprocess all the C source files specified and output the results to standard
9661  output.
9662 \end_layout
9663
9664 \begin_layout List
9665 \labelwidthstring 00.00.0000
9666
9667 \series bold
9668 -o\InsetSpace ~
9669 <path/file>
9670 \begin_inset LatexCommand \index{-o <path/file>}
9671
9672 \end_inset
9673
9674  
9675 \series default
9676 The output path where everything will be placed or the file name used for
9677  all generated output files.
9678  If the parameter is a path, it must have a trailing slash (or backslash
9679  for the Windows binaries) to be recognized as a path.
9680
9681 \emph on
9682  
9683 \emph default
9684 Note for Windows users: if the path contains spaces, it should be surrounded
9685  by quotes.
9686  The trailing backslash should be doubled in order to prevent escaping the
9687  final quote, for example: 
9688 \emph on
9689 -o 
9690 \begin_inset Quotes sld
9691 \end_inset
9692
9693 F:
9694 \backslash
9695 Projects
9696 \backslash
9697 test3
9698 \backslash
9699 output 1
9700 \backslash
9701
9702 \backslash
9703
9704 \begin_inset Quotes srd
9705 \end_inset
9706
9707
9708 \emph default
9709  or put after the final quote, for example: 
9710 \emph on
9711 -o 
9712 \begin_inset Quotes sld
9713 \end_inset
9714
9715 F:
9716 \backslash
9717 Projects
9718 \backslash
9719 test3
9720 \backslash
9721 output 1
9722 \begin_inset Quotes srd
9723 \end_inset
9724
9725
9726 \backslash
9727
9728 \emph default
9729 .
9730  The path using slashes for directory delimiters can be used too, for example:
9731  
9732 \emph on
9733 -o 
9734 \begin_inset Quotes sld
9735 \end_inset
9736
9737 F:/Projects/test3/output 1/
9738 \begin_inset Quotes srd
9739 \end_inset
9740
9741
9742 \emph default
9743 .
9744 \end_layout
9745
9746 \begin_layout List
9747 \labelwidthstring 00.00.0000
9748
9749 \series bold
9750 -
9751 \begin_inset ERT
9752 status collapsed
9753
9754 \begin_layout Standard
9755
9756
9757 \backslash
9758 /
9759 \end_layout
9760
9761 \end_inset
9762
9763 -stack-auto
9764 \begin_inset LatexCommand \index{-\/-stack-auto}
9765
9766 \end_inset
9767
9768
9769 \series default
9770 \size large
9771 \emph on
9772  
9773 \size default
9774 \emph default
9775 All functions in the source file will be compiled as 
9776 \emph on
9777 reentrant
9778 \emph default
9779
9780 \begin_inset LatexCommand \index{reentrant}
9781
9782 \end_inset
9783
9784 , i.e.
9785  the parameters and local variables will be allocated on the stack
9786 \begin_inset LatexCommand \index{stack}
9787
9788 \end_inset
9789
9790 .
9791  See section 
9792 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9793
9794 \end_inset
9795
9796  Parameters and Local Variables for more details.
9797  If this option is used all source files in the project should be compiled
9798  with this option.
9799  It automatically implies -
9800 \series bold
9801
9802 \begin_inset ERT
9803 status open
9804
9805 \begin_layout Standard
9806
9807
9808 \backslash
9809 /
9810 \end_layout
9811
9812 \end_inset
9813
9814
9815 \series default
9816 -int-long-reent and -
9817 \series bold
9818
9819 \begin_inset ERT
9820 status open
9821
9822 \begin_layout Standard
9823
9824
9825 \backslash
9826 /
9827 \end_layout
9828
9829 \end_inset
9830
9831
9832 \series default
9833 -float-reent.
9834  
9835 \end_layout
9836
9837 \begin_layout List
9838 \labelwidthstring 00.00.0000
9839
9840 \series bold
9841 -
9842 \begin_inset ERT
9843 status collapsed
9844
9845 \begin_layout Standard
9846
9847
9848 \backslash
9849 /
9850 \end_layout
9851
9852 \end_inset
9853
9854 -callee-saves
9855 \begin_inset LatexCommand \index{-\/-callee-saves}
9856
9857 \end_inset
9858
9859  
9860 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9861
9862 \end_inset
9863
9864 function1[,function2][,function3]....
9865
9866 \series default
9867  The compiler by default uses a caller saves convention for register saving
9868  across function calls, however this can cause unnecessary register pushing
9869  and popping when calling small functions from larger functions.
9870  This option can be used to switch the register saving convention for the
9871  function names specified.
9872  The compiler will not save registers when calling these functions, no extra
9873  code will be generated at the entry and exit (function prologue
9874 \series bold
9875
9876 \begin_inset LatexCommand \index{function prologue}
9877
9878 \end_inset
9879
9880
9881 \series default
9882  and epilogue
9883 \series bold
9884
9885 \begin_inset LatexCommand \index{function epilogue}
9886
9887 \end_inset
9888
9889
9890 \series default
9891 ) for these functions to save and restore the registers used by these functions,
9892  this can SUBSTANTIALLY reduce code and improve run time performance of
9893  the generated code.
9894  In the future the compiler (with inter procedural analysis) will be able
9895  to determine the appropriate scheme to use for each function call.
9896  DO NOT use this option for built-in functions such as _mulint..., if this
9897  option is used for a library function the appropriate library function
9898  needs to be recompiled with the same option.
9899  If the project consists of multiple source files then all the source file
9900  should be compiled with the same -
9901 \begin_inset ERT
9902 status collapsed
9903
9904 \begin_layout Standard
9905
9906
9907 \backslash
9908 /
9909 \end_layout
9910
9911 \end_inset
9912
9913 -callee-saves option string.
9914  Also see #pragma\InsetSpace ~
9915 callee_saves 
9916 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9917
9918 \end_inset
9919
9920  
9921 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9922
9923 \end_inset
9924
9925 .
9926 \end_layout
9927
9928 \begin_layout List
9929 \labelwidthstring 00.00.0000
9930
9931 \series bold
9932 -
9933 \begin_inset ERT
9934 status collapsed
9935
9936 \begin_layout Standard
9937
9938
9939 \backslash
9940 /
9941 \end_layout
9942
9943 \end_inset
9944
9945 -all-callee-saves
9946 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9947
9948 \end_inset
9949
9950  
9951 \series default
9952 Function of
9953 \series bold
9954  
9955 \series default
9956 -
9957 \begin_inset ERT
9958 status collapsed
9959
9960 \begin_layout Standard
9961
9962
9963 \backslash
9964 /
9965 \end_layout
9966
9967 \end_inset
9968
9969 -callee-saves will be applied to all functions by default.
9970 \end_layout
9971
9972 \begin_layout List
9973 \labelwidthstring 00.00.0000
9974
9975 \series bold
9976 -
9977 \begin_inset ERT
9978 status collapsed
9979
9980 \begin_layout Standard
9981
9982
9983 \backslash
9984 /
9985 \end_layout
9986
9987 \end_inset
9988
9989 -debug
9990 \begin_inset LatexCommand \index{-\/-debug}
9991
9992 \end_inset
9993
9994
9995 \bar under
9996  
9997 \series default
9998 \bar default
9999 When this option is used the compiler will generate debug information.
10000  The debug information collected in a file with .cdb extension can be used
10001  with the SDCDB.
10002  For more information see documentation for SDCDB.
10003  Another file with no extension contains debug information in AOMF or AOMF51
10004 \begin_inset LatexCommand \index{AOMF, AOMF51}
10005
10006 \end_inset
10007
10008  format which is commonly used by third party tools.
10009 \end_layout
10010
10011 \begin_layout List
10012 \labelwidthstring 00.00.0000
10013
10014 \series bold
10015 -S
10016 \begin_inset LatexCommand \index{-S}
10017
10018 \end_inset
10019
10020
10021 \size large
10022 \bar under
10023  
10024 \series default
10025 \size default
10026 \bar default
10027 Stop after the stage of compilation proper; do not assemble.
10028  The output is an assembler code file for the input file specified.
10029 \end_layout
10030
10031 \begin_layout List
10032 \labelwidthstring 00.00.0000
10033
10034 \series bold
10035 -
10036 \begin_inset ERT
10037 status collapsed
10038
10039 \begin_layout Standard
10040
10041
10042 \backslash
10043 /
10044 \end_layout
10045
10046 \end_inset
10047
10048 -int-long-reent
10049 \begin_inset LatexCommand \index{-\/-int-long-reent}
10050
10051 \end_inset
10052
10053
10054 \series default
10055  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10056  Note by default these libraries are compiled as non-reentrant.
10057  See section Installation for more details.
10058 \end_layout
10059
10060 \begin_layout List
10061 \labelwidthstring 00.00.0000
10062
10063 \series bold
10064 -
10065 \begin_inset ERT
10066 status collapsed
10067
10068 \begin_layout Standard
10069
10070
10071 \backslash
10072 /
10073 \end_layout
10074
10075 \end_inset
10076
10077 -cyclomatic
10078 \begin_inset LatexCommand \index{-\/-cyclomatic}
10079
10080 \end_inset
10081
10082
10083 \bar under
10084  
10085 \series default
10086 \bar default
10087 This option will cause the compiler to generate an information message for
10088  each function in the source file.
10089  The message contains some 
10090 \emph on
10091 important
10092 \emph default
10093  information about the function.
10094  The number of edges and nodes the compiler detected in the control flow
10095  graph of the function, and most importantly the 
10096 \emph on
10097 cyclomatic complexity
10098 \begin_inset LatexCommand \index{Cyclomatic complexity}
10099
10100 \end_inset
10101
10102
10103 \emph default
10104  see section on Cyclomatic Complexity for more details.
10105 \end_layout
10106
10107 \begin_layout List
10108 \labelwidthstring 00.00.0000
10109
10110 \series bold
10111 -
10112 \begin_inset ERT
10113 status collapsed
10114
10115 \begin_layout Standard
10116
10117
10118 \backslash
10119 /
10120 \end_layout
10121
10122 \end_inset
10123
10124 -float-reent
10125 \begin_inset LatexCommand \index{-\/-float-reent}
10126
10127 \end_inset
10128
10129
10130 \series default
10131  Floating point library is compiled as reentrant
10132 \begin_inset LatexCommand \index{reentrant}
10133
10134 \end_inset
10135
10136 .
10137  See section Installation for more details.
10138 \end_layout
10139
10140 \begin_layout List
10141 \labelwidthstring 00.00.0000
10142
10143 \series bold
10144 -
10145 \begin_inset ERT
10146 status collapsed
10147
10148 \begin_layout Standard
10149
10150
10151 \backslash
10152 /
10153 \end_layout
10154
10155 \end_inset
10156
10157 -funsigned-char
10158 \begin_inset LatexCommand \index{-\/-funsigned-char}
10159
10160 \end_inset
10161
10162
10163 \series default
10164  The default signedness for every type is
10165 \family typewriter
10166  signed
10167 \family default
10168 .
10169  In some embedded environments the default signedness of
10170 \family typewriter
10171  char
10172 \family default
10173  is
10174 \family typewriter
10175  unsigned
10176 \family default
10177 .
10178  To set the signess for characters to unsigned, use the option -
10179 \series bold
10180
10181 \begin_inset ERT
10182 status open
10183
10184 \begin_layout Standard
10185
10186
10187 \backslash
10188 /
10189 \end_layout
10190
10191 \end_inset
10192
10193
10194 \series default
10195 -funsigned-char.
10196  If this option is set and no signedness keyword (unsigned/signed) is given,
10197  a char will be signed.
10198  All other types are unaffected.
10199 \end_layout
10200
10201 \begin_layout List
10202 \labelwidthstring 00.00.0000
10203
10204 \series bold
10205 -
10206 \begin_inset ERT
10207 status collapsed
10208
10209 \begin_layout Standard
10210
10211
10212 \backslash
10213 /
10214 \end_layout
10215
10216 \end_inset
10217
10218 -main-return
10219 \begin_inset LatexCommand \index{-\/-main-return}
10220
10221 \end_inset
10222
10223
10224 \series default
10225  This option can be used if the code generated is called by a monitor program
10226  or if the main routine includes an endless loop.
10227  This option results in slightly smaller code and saves two bytes of stack
10228  space.
10229  The return from the 'main'
10230 \begin_inset LatexCommand \index{main return}
10231
10232 \end_inset
10233
10234  function will return to the function calling main.
10235  The default setting is to lock up i.e.
10236  generate a '
10237 \family typewriter
10238 sjmp .
10239 \family default
10240 '.
10241 \end_layout
10242
10243 \begin_layout List
10244 \labelwidthstring 00.00.0000
10245
10246 \series bold
10247 -
10248 \begin_inset ERT
10249 status collapsed
10250
10251 \begin_layout Standard
10252
10253
10254 \backslash
10255 /
10256 \end_layout
10257
10258 \end_inset
10259
10260 -nostdinc
10261 \begin_inset LatexCommand \index{-\/-nostdinc}
10262
10263 \end_inset
10264
10265
10266 \series default
10267  This will prevent the compiler from passing on the default include path
10268  to the preprocessor.
10269 \end_layout
10270
10271 \begin_layout List
10272 \labelwidthstring 00.00.0000
10273
10274 \series bold
10275 -
10276 \begin_inset ERT
10277 status collapsed
10278
10279 \begin_layout Standard
10280
10281
10282 \backslash
10283 /
10284 \end_layout
10285
10286 \end_inset
10287
10288 -nostdlib
10289 \begin_inset LatexCommand \index{-\/-nostdlib}
10290
10291 \end_inset
10292
10293
10294 \series default
10295  This will prevent the compiler from passing on the default library
10296 \begin_inset LatexCommand \index{Libraries}
10297
10298 \end_inset
10299
10300  path to the linker.
10301 \end_layout
10302
10303 \begin_layout List
10304 \labelwidthstring 00.00.0000
10305
10306 \series bold
10307 -
10308 \begin_inset ERT
10309 status collapsed
10310
10311 \begin_layout Standard
10312
10313
10314 \backslash
10315 /
10316 \end_layout
10317
10318 \end_inset
10319
10320 -verbose
10321 \begin_inset LatexCommand \index{-\/-verbose}
10322
10323 \end_inset
10324
10325
10326 \series default
10327  Shows the various actions the compiler is performing.
10328 \end_layout
10329
10330 \begin_layout List
10331 \labelwidthstring 00.00.0000
10332
10333 \series bold
10334 -V
10335 \begin_inset LatexCommand \index{-V}
10336
10337 \end_inset
10338
10339
10340 \series default
10341  Shows the actual commands the compiler is executing.
10342 \end_layout
10343
10344 \begin_layout List
10345 \labelwidthstring 00.00.0000
10346
10347 \series bold
10348 -
10349 \begin_inset ERT
10350 status collapsed
10351
10352 \begin_layout Standard
10353
10354
10355 \backslash
10356 /
10357 \end_layout
10358
10359 \end_inset
10360
10361 -no-c-code-in-asm
10362 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10363
10364 \end_inset
10365
10366
10367 \series default
10368  Hides your ugly and inefficient c-code from the asm file, so you can always
10369  blame the compiler :)
10370 \end_layout
10371
10372 \begin_layout List
10373 \labelwidthstring 00.00.0000
10374
10375 \series bold
10376 -
10377 \begin_inset ERT
10378 status collapsed
10379
10380 \begin_layout Standard
10381
10382
10383 \backslash
10384 /
10385 \end_layout
10386
10387 \end_inset
10388
10389 -fverbose-asm
10390 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10391
10392 \end_inset
10393
10394
10395 \series default
10396  Include code generator and peep-hole comments in the generated asm files.
10397 \end_layout
10398
10399 \begin_layout List
10400 \labelwidthstring 00.00.0000
10401
10402 \series bold
10403 -
10404 \begin_inset ERT
10405 status collapsed
10406
10407 \begin_layout Standard
10408
10409
10410 \backslash
10411 /
10412 \end_layout
10413
10414 \end_inset
10415
10416 -no-peep-comments
10417 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10418
10419 \end_inset
10420
10421
10422 \series default
10423  Don't include peep-hole comments in the generated asm files even if -
10424 \series bold
10425
10426 \begin_inset ERT
10427 status open
10428
10429 \begin_layout Standard
10430
10431
10432 \backslash
10433 /
10434 \end_layout
10435
10436 \end_inset
10437
10438
10439 \series default
10440 -fverbose-asm option is specified.
10441 \end_layout
10442
10443 \begin_layout List
10444 \labelwidthstring 00.00.0000
10445
10446 \series bold
10447 -
10448 \begin_inset ERT
10449 status collapsed
10450
10451 \begin_layout Standard
10452
10453
10454 \backslash
10455 /
10456 \end_layout
10457
10458 \end_inset
10459
10460 -i-code-in-asm
10461 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10462
10463 \end_inset
10464
10465
10466 \series default
10467  Include i-codes in the asm file.
10468  Sounds like noise but is most helpful for debugging the compiler itself.
10469 \end_layout
10470
10471 \begin_layout List
10472 \labelwidthstring 00.00.0000
10473
10474 \series bold
10475 -
10476 \begin_inset ERT
10477 status collapsed
10478
10479 \begin_layout Standard
10480
10481
10482 \backslash
10483 /
10484 \end_layout
10485
10486 \end_inset
10487
10488 -less-pedantic
10489 \begin_inset LatexCommand \index{pedantic}
10490
10491 \end_inset
10492
10493
10494 \begin_inset LatexCommand \index{-\/-less-pedantic}
10495
10496 \end_inset
10497
10498
10499 \series default
10500
10501 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10502
10503 \end_inset
10504
10505  Disable some of the more pedantic warnings
10506 \begin_inset LatexCommand \index{Warnings}
10507
10508 \end_inset
10509
10510 .
10511  For more details, see the less_pedantic pragma 
10512 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10513
10514 \end_inset
10515
10516 .
10517 \end_layout
10518
10519 \begin_layout List
10520 \labelwidthstring 00.00.0000
10521
10522 \series bold
10523 -
10524 \begin_inset ERT
10525 status collapsed
10526
10527 \begin_layout Standard
10528
10529
10530 \backslash
10531 /
10532 \end_layout
10533
10534 \end_inset
10535
10536 -disable-warning\InsetSpace ~
10537 <nnnn>
10538 \begin_inset LatexCommand \index{-\/-disable-warning}
10539
10540 \end_inset
10541
10542
10543 \series default
10544  Disable specific warning with number <nnnn>.
10545 \end_layout
10546
10547 \begin_layout List
10548 \labelwidthstring 00.00.0000
10549
10550 \series bold
10551 -
10552 \begin_inset ERT
10553 status collapsed
10554
10555 \begin_layout Standard
10556
10557
10558 \backslash
10559 /
10560 \end_layout
10561
10562 \end_inset
10563
10564 -Werror
10565 \begin_inset LatexCommand \index{-\/-Werror}
10566
10567 \end_inset
10568
10569
10570 \series default
10571  Treat all warnings as errors.
10572 \end_layout
10573
10574 \begin_layout List
10575 \labelwidthstring 00.00.0000
10576
10577 \series bold
10578 -
10579 \begin_inset ERT
10580 status collapsed
10581
10582 \begin_layout Standard
10583
10584
10585 \backslash
10586 /
10587 \end_layout
10588
10589 \end_inset
10590
10591 -print-search-dirs
10592 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10593
10594 \end_inset
10595
10596
10597 \series default
10598  Display the directories in the compiler's search path
10599 \end_layout
10600
10601 \begin_layout List
10602 \labelwidthstring 00.00.0000
10603
10604 \series bold
10605 -
10606 \begin_inset ERT
10607 status collapsed
10608
10609 \begin_layout Standard
10610
10611
10612 \backslash
10613 /
10614 \end_layout
10615
10616 \end_inset
10617
10618 -vc
10619 \begin_inset LatexCommand \index{-\/-vc}
10620
10621 \end_inset
10622
10623
10624 \series default
10625  Display errors and warnings using MSVC style, so you can use SDCC with
10626  the visual studio IDE
10627 \begin_inset LatexCommand \index{IDE}
10628
10629 \end_inset
10630
10631 .
10632  With SDCC both offering a GCC-like (the default) and a MSVC-like
10633 \begin_inset LatexCommand \index{MSVC output style}
10634
10635 \end_inset
10636
10637  output style, integration into most programming editors should be straightforwa
10638 rd.
10639 \end_layout
10640
10641 \begin_layout List
10642 \labelwidthstring 00.00.0000
10643
10644 \series bold
10645 -
10646 \begin_inset ERT
10647 status collapsed
10648
10649 \begin_layout Standard
10650
10651
10652 \backslash
10653 /
10654 \end_layout
10655
10656 \end_inset
10657
10658 -use-stdout
10659 \begin_inset LatexCommand \index{-\/-use-stdout}
10660
10661 \end_inset
10662
10663
10664 \series default
10665  Send errors and warnings to stdout instead of stderr.
10666 \end_layout
10667
10668 \begin_layout List
10669 \labelwidthstring 00.00.0000
10670
10671 \series bold
10672 -Wa\InsetSpace ~
10673 asmOption[,asmOption]
10674 \series default
10675
10676 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10677
10678 \end_inset
10679
10680 ...
10681  Pass the asmOption to the assembler
10682 \begin_inset LatexCommand \index{Options assembler}
10683
10684 \end_inset
10685
10686
10687 \begin_inset LatexCommand \index{Assembler options}
10688
10689 \end_inset
10690
10691 .
10692  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10693 \end_layout
10694
10695 \begin_layout List
10696 \labelwidthstring 00.00.0000
10697
10698 \series bold
10699 -
10700 \begin_inset ERT
10701 status collapsed
10702
10703 \begin_layout Standard
10704
10705
10706 \backslash
10707 /
10708 \end_layout
10709
10710 \end_inset
10711
10712 -std-sdcc89
10713 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10714
10715 \end_inset
10716
10717
10718 \series default
10719  Generally follow the C89 standard, but allow SDCC features that conflict
10720  with the standard (default).
10721 \end_layout
10722
10723 \begin_layout List
10724 \labelwidthstring 00.00.0000
10725
10726 \series bold
10727 -
10728 \begin_inset ERT
10729 status collapsed
10730
10731 \begin_layout Standard
10732
10733
10734 \backslash
10735 /
10736 \end_layout
10737
10738 \end_inset
10739
10740 -std-c89
10741 \begin_inset LatexCommand \index{-\/-std-c89}
10742
10743 \end_inset
10744
10745
10746 \series default
10747  Follow the C89 standard and disable SDCC features that conflict with the
10748  standard.
10749 \end_layout
10750
10751 \begin_layout List
10752 \labelwidthstring 00.00.0000
10753
10754 \series bold
10755 -
10756 \begin_inset ERT
10757 status collapsed
10758
10759 \begin_layout Standard
10760
10761
10762 \backslash
10763 /
10764 \end_layout
10765
10766 \end_inset
10767
10768 -std-sdcc99
10769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10770
10771 \end_inset
10772
10773
10774 \series default
10775  Generally follow the C99 standard, but allow SDCC features that conflict
10776  with the standard (incomplete support).
10777 \end_layout
10778
10779 \begin_layout List
10780 \labelwidthstring 00.00.0000
10781
10782 \series bold
10783 -
10784 \begin_inset ERT
10785 status collapsed
10786
10787 \begin_layout Standard
10788
10789
10790 \backslash
10791 /
10792 \end_layout
10793
10794 \end_inset
10795
10796 -std-c99
10797 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10798
10799 \end_inset
10800
10801
10802 \series default
10803  Follow the C99 standard and disable SDCC features that conflict with the
10804  standard (incomplete support).
10805 \end_layout
10806
10807 \begin_layout List
10808 \labelwidthstring 00.00.0000
10809
10810 \series bold
10811 -
10812 \begin_inset ERT
10813 status collapsed
10814
10815 \begin_layout Standard
10816
10817
10818 \backslash
10819 /
10820 \end_layout
10821
10822 \end_inset
10823
10824 -codeseg
10825 \series default
10826
10827 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10828
10829 \end_inset
10830
10831 \InsetSpace ~
10832 <Name> The name to be used for the code
10833 \begin_inset LatexCommand \index{code}
10834
10835 \end_inset
10836
10837  segment, default CSEG.
10838  This is useful if you need to tell the compiler to put the code in a special
10839  segment so you can later on tell the linker to put this segment in a special
10840  place in memory.
10841  Can be used for instance when using bank switching to put the code in a
10842  bank.
10843 \end_layout
10844
10845 \begin_layout List
10846 \labelwidthstring 00.00.0000
10847
10848 \series bold
10849 -
10850 \begin_inset ERT
10851 status collapsed
10852
10853 \begin_layout Standard
10854
10855
10856 \backslash
10857 /
10858 \end_layout
10859
10860 \end_inset
10861
10862 -constseg
10863 \series default
10864
10865 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10866
10867 \end_inset
10868
10869 \InsetSpace ~
10870 <Name> The name to be used for the const
10871 \begin_inset LatexCommand \index{const}
10872
10873 \end_inset
10874
10875  segment, default CONST.
10876  This is useful if you need to tell the compiler to put the const data in
10877  a special segment so you can later on tell the linker to put this segment
10878  in a special place in memory.
10879  Can be used for instance when using bank switching to put the const data
10880  in a bank.
10881 \end_layout
10882
10883 \begin_layout List
10884 \labelwidthstring 00.00.0000
10885
10886 \series bold
10887 -
10888 \begin_inset ERT
10889 status collapsed
10890
10891 \begin_layout Standard
10892
10893
10894 \backslash
10895 /
10896 \end_layout
10897
10898 \end_inset
10899
10900 -fdollars-in-identifiers
10901 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10902
10903 \end_inset
10904
10905
10906 \series default
10907  Permit '$' as an identifier character.
10908 \end_layout
10909
10910 \begin_layout List
10911 \labelwidthstring 00.00.0000
10912
10913 \series bold
10914 -
10915 \begin_inset ERT
10916 status collapsed
10917
10918 \begin_layout Standard
10919
10920
10921 \backslash
10922 /
10923 \end_layout
10924
10925 \end_inset
10926
10927 -more-pedantic
10928 \series default
10929
10930 \begin_inset LatexCommand \index{-\/-more-pedantic}
10931
10932 \end_inset
10933
10934
10935 \begin_inset LatexCommand \index{pedantic}
10936
10937 \end_inset
10938
10939  Actually this is 
10940 \series bold
10941 \emph on
10942 not
10943 \series default
10944 \emph default
10945  a SDCC compiler option but if you want 
10946 \emph on
10947 more
10948 \emph default
10949  warnings you can use a separate tool dedicated to syntax checking like
10950  splint
10951 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10952
10953 \end_inset
10954
10955
10956 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10957
10958 \end_inset
10959
10960  
10961 \begin_inset LatexCommand \url{http://www.splint.org}
10962
10963 \end_inset
10964
10965 .
10966  To make your source files parseable by splint you will have to include
10967  
10968 \family sans
10969 lint.h
10970 \family default
10971
10972 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10973
10974 \end_inset
10975
10976  in your source file and add brackets around extended keywords (like 
10977 \family sans
10978
10979 \begin_inset Quotes sld
10980 \end_inset
10981
10982 __at\InsetSpace ~
10983
10984 \series bold
10985 (
10986 \series default
10987 0xab
10988 \series bold
10989 )
10990 \series default
10991
10992 \begin_inset Quotes srd
10993 \end_inset
10994
10995
10996 \family default
10997  and 
10998 \family sans
10999
11000 \begin_inset Quotes sld
11001 \end_inset
11002
11003 __interrupt\InsetSpace ~
11004 (2)
11005 \begin_inset Quotes srd
11006 \end_inset
11007
11008
11009 \family default
11010 ).
11011  
11012 \newline
11013 Splint has an excellent on line manual at 
11014 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11015
11016 \end_inset
11017
11018  and it's capabilities go beyond pure syntax checking.
11019  You'll need to tell splint the location of SDCC's include files so a typical
11020  command line could look like this: 
11021 \newline
11022
11023 \family sans
11024 splint\InsetSpace ~
11025 -I\InsetSpace ~
11026 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11027 \InsetSpace ~
11028 myprogram.c
11029 \end_layout
11030
11031 \begin_layout List
11032 \labelwidthstring 00.00.0000
11033
11034 \series bold
11035 -
11036 \begin_inset ERT
11037 status collapsed
11038
11039 \begin_layout Standard
11040
11041
11042 \backslash
11043 /
11044 \end_layout
11045
11046 \end_inset
11047
11048 -short-is-8bits
11049 \series default
11050
11051 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11052
11053 \end_inset
11054
11055
11056 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11057
11058 \end_inset
11059
11060  Treat short as 8-bit (for backward compatibility with older versions of
11061  compiler - see section 
11062 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11063
11064 \end_inset
11065
11066 )
11067 \end_layout
11068
11069 \begin_layout Standard
11070 \begin_inset VSpace bigskip
11071 \end_inset
11072
11073
11074 \end_layout
11075
11076 \begin_layout Subsection
11077 Intermediate Dump Options
11078 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11079
11080 \end_inset
11081
11082
11083 \begin_inset LatexCommand \index{Options intermediate dump}
11084
11085 \end_inset
11086
11087
11088 \begin_inset LatexCommand \index{Intermediate dump options}
11089
11090 \end_inset
11091
11092
11093 \end_layout
11094
11095 \begin_layout Standard
11096 The following options are provided for the purpose of retargetting and debugging
11097  the compiler.
11098  They provide a means to dump the intermediate code (iCode
11099 \begin_inset LatexCommand \index{iCode}
11100
11101 \end_inset
11102
11103 ) generated by the compiler in human readable form at various stages of
11104  the compilation process.
11105  More on iCodes see chapter 
11106 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11107
11108 \end_inset
11109
11110  
11111 \begin_inset Quotes srd
11112 \end_inset
11113
11114 The anatomy of the compiler
11115 \begin_inset Quotes srd
11116 \end_inset
11117
11118 .
11119 \end_layout
11120
11121 \begin_layout List
11122 \labelwidthstring 00.00.0000
11123
11124 \series bold
11125 -
11126 \begin_inset ERT
11127 status collapsed
11128
11129 \begin_layout Standard
11130
11131
11132 \backslash
11133 /
11134 \end_layout
11135
11136 \end_inset
11137
11138 -dumpraw
11139 \begin_inset LatexCommand \index{-\/-dumpraw}
11140
11141 \end_inset
11142
11143
11144 \series default
11145  This option will cause the compiler to dump the intermediate code into
11146  a file of named 
11147 \emph on
11148 <source filename>.dumpraw
11149 \emph default
11150  just after the intermediate code has been generated for a function, i.e.
11151  before any optimizations are done.
11152  The basic blocks
11153 \begin_inset LatexCommand \index{Basic blocks}
11154
11155 \end_inset
11156
11157  at this stage ordered in the depth first number, so they may not be in
11158  sequence of execution.
11159 \end_layout
11160
11161 \begin_layout List
11162 \labelwidthstring 00.00.0000
11163
11164 \series bold
11165 -
11166 \begin_inset ERT
11167 status collapsed
11168
11169 \begin_layout Standard
11170
11171
11172 \backslash
11173 /
11174 \end_layout
11175
11176 \end_inset
11177
11178 -dumpgcse
11179 \begin_inset LatexCommand \index{-\/-dumpgcse}
11180
11181 \end_inset
11182
11183
11184 \series default
11185  Will create a dump of iCodes, after global subexpression elimination
11186 \begin_inset LatexCommand \index{Global subexpression elimination}
11187
11188 \end_inset
11189
11190 , into a file named 
11191 \emph on
11192 <source filename>.dumpgcse.
11193 \end_layout
11194
11195 \begin_layout List
11196 \labelwidthstring 00.00.0000
11197
11198 \series bold
11199 -
11200 \begin_inset ERT
11201 status collapsed
11202
11203 \begin_layout Standard
11204
11205
11206 \backslash
11207 /
11208 \end_layout
11209
11210 \end_inset
11211
11212 -dumpdeadcode
11213 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11214
11215 \end_inset
11216
11217
11218 \series default
11219  Will create a dump of iCodes, after deadcode elimination
11220 \begin_inset LatexCommand \index{Dead-code elimination}
11221
11222 \end_inset
11223
11224 , into a file named 
11225 \emph on
11226 <source filename>.dumpdeadcode.
11227 \end_layout
11228
11229 \begin_layout List
11230 \labelwidthstring 00.00.0000
11231
11232 \series bold
11233 -
11234 \begin_inset ERT
11235 status collapsed
11236
11237 \begin_layout Standard
11238
11239
11240 \backslash
11241 /
11242 \end_layout
11243
11244 \end_inset
11245
11246 -dumploop
11247 \begin_inset LatexCommand \index{-\/-dumploop}
11248
11249 \end_inset
11250
11251
11252 \series default
11253 \size large
11254  
11255 \size default
11256 Will create a dump of iCodes, after loop optimizations
11257 \begin_inset LatexCommand \index{Loop optimization}
11258
11259 \end_inset
11260
11261 , into a file named 
11262 \emph on
11263 <source filename>.dumploop.
11264 \end_layout
11265
11266 \begin_layout List
11267 \labelwidthstring 00.00.0000
11268
11269 \series bold
11270 -
11271 \begin_inset ERT
11272 status collapsed
11273
11274 \begin_layout Standard
11275
11276
11277 \backslash
11278 /
11279 \end_layout
11280
11281 \end_inset
11282
11283 -dumprange
11284 \begin_inset LatexCommand \index{-\/-dumprange}
11285
11286 \end_inset
11287
11288
11289 \series default
11290 \size large
11291  
11292 \size default
11293 Will create a dump of iCodes, after live range analysis
11294 \begin_inset LatexCommand \index{Live range analysis}
11295
11296 \end_inset
11297
11298 , into a file named 
11299 \emph on
11300 <source filename>.dumprange.
11301 \end_layout
11302
11303 \begin_layout List
11304 \labelwidthstring 00.00.0000
11305
11306 \series bold
11307 -
11308 \begin_inset ERT
11309 status collapsed
11310
11311 \begin_layout Standard
11312
11313
11314 \backslash
11315 /
11316 \end_layout
11317
11318 \end_inset
11319
11320 -dumlrange
11321 \begin_inset LatexCommand \index{-\/-dumlrange}
11322
11323 \end_inset
11324
11325
11326 \series default
11327  Will dump the life ranges
11328 \begin_inset LatexCommand \index{Live range analysis}
11329
11330 \end_inset
11331
11332  for all symbols.
11333 \end_layout
11334
11335 \begin_layout List
11336 \labelwidthstring 00.00.0000
11337
11338 \series bold
11339 -
11340 \begin_inset ERT
11341 status collapsed
11342
11343 \begin_layout Standard
11344
11345
11346 \backslash
11347 /
11348 \end_layout
11349
11350 \end_inset
11351
11352 -dumpregassign
11353 \begin_inset LatexCommand \index{-\/-dumpregassign}
11354
11355 \end_inset
11356
11357
11358 \bar under
11359  
11360 \series default
11361 \bar default
11362 Will create a dump of iCodes, after register assignment
11363 \begin_inset LatexCommand \index{Register assignment}
11364
11365 \end_inset
11366
11367 , into a file named 
11368 \emph on
11369 <source filename>.dumprassgn.
11370 \end_layout
11371
11372 \begin_layout List
11373 \labelwidthstring 00.00.0000
11374
11375 \series bold
11376 -
11377 \begin_inset ERT
11378 status collapsed
11379
11380 \begin_layout Standard
11381
11382
11383 \backslash
11384 /
11385 \end_layout
11386
11387 \end_inset
11388
11389 -dumplrange
11390 \begin_inset LatexCommand \index{-\/-dumplrange}
11391
11392 \end_inset
11393
11394
11395 \series default
11396  Will create a dump of the live ranges of iTemp's
11397 \end_layout
11398
11399 \begin_layout List
11400 \labelwidthstring 00.00.0000
11401
11402 \series bold
11403 -
11404 \begin_inset ERT
11405 status collapsed
11406
11407 \begin_layout Standard
11408
11409
11410 \backslash
11411 /
11412 \end_layout
11413
11414 \end_inset
11415
11416 -dumpall
11417 \begin_inset LatexCommand \index{-\/-dumpall}
11418
11419 \end_inset
11420
11421
11422 \size large
11423 \bar under
11424  
11425 \series default
11426 \size default
11427 \bar default
11428 Will cause all the above mentioned dumps to be created.
11429 \end_layout
11430
11431 \begin_layout Standard
11432 \begin_inset VSpace bigskip
11433 \end_inset
11434
11435
11436 \end_layout
11437
11438 \begin_layout Subsection
11439 Redirecting output on Windows Shells
11440 \end_layout
11441
11442 \begin_layout Standard
11443 By default SDCC writes its error messages to 
11444 \begin_inset Quotes sld
11445 \end_inset
11446
11447 standard error
11448 \begin_inset Quotes srd
11449 \end_inset
11450
11451 .
11452  To force all messages to 
11453 \begin_inset Quotes sld
11454 \end_inset
11455
11456 standard output
11457 \begin_inset Quotes srd
11458 \end_inset
11459
11460  use 
11461 \series bold
11462 -
11463 \series default
11464 \emph on
11465
11466 \begin_inset ERT
11467 status collapsed
11468
11469 \begin_layout Standard
11470
11471
11472 \backslash
11473 /
11474 \end_layout
11475
11476 \end_inset
11477
11478
11479 \series bold
11480 \emph default
11481 -
11482 \series default
11483 use-stdout
11484 \begin_inset LatexCommand \index{-\/-use-stdout}
11485
11486 \end_inset
11487
11488 .
11489  Additionally, if you happen to have visual studio installed in your windows
11490  machine, you can use it to compile your sources using a custom build and
11491  the SDCC -
11492 \emph on
11493
11494 \begin_inset ERT
11495 status collapsed
11496
11497 \begin_layout Standard
11498
11499
11500 \backslash
11501 /
11502 \end_layout
11503
11504 \end_inset
11505
11506
11507 \emph default
11508 -vc
11509 \begin_inset LatexCommand \index{-\/-vc}
11510
11511 \end_inset
11512
11513  option.
11514  Something like this should work:
11515 \newline
11516
11517 \newline
11518
11519 \series bold
11520 c:
11521 \backslash
11522 sdcc
11523 \backslash
11524 bin
11525 \backslash
11526 sdcc.exe -
11527 \series default
11528 \emph on
11529
11530 \begin_inset ERT
11531 status collapsed
11532
11533 \begin_layout Standard
11534
11535
11536 \backslash
11537 /
11538 \end_layout
11539
11540 \end_inset
11541
11542
11543 \series bold
11544 \emph default
11545 -vc -
11546 \series default
11547 \emph on
11548
11549 \begin_inset ERT
11550 status collapsed
11551
11552 \begin_layout Standard
11553
11554
11555 \backslash
11556 /
11557 \end_layout
11558
11559 \end_inset
11560
11561
11562 \series bold
11563 \emph default
11564 -model-large -c $(InputPath)
11565 \series default
11566
11567 \begin_inset VSpace bigskip
11568 \end_inset
11569
11570
11571 \end_layout
11572
11573 \begin_layout Section
11574 Environment variables
11575 \begin_inset LatexCommand \index{Environment variables}
11576
11577 \end_inset
11578
11579
11580 \end_layout
11581
11582 \begin_layout Standard
11583 SDCC recognizes the following environment variables:
11584 \end_layout
11585
11586 \begin_layout List
11587 \labelwidthstring 00.00.0000
11588
11589 \series bold
11590 SDCC_LEAVE_SIGNALS
11591 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11592
11593 \end_inset
11594
11595
11596 \series default
11597  SDCC installs a signal handler
11598 \begin_inset LatexCommand \index{signal handler}
11599
11600 \end_inset
11601
11602  to be able to delete temporary files after an user break (^C) or an exception.
11603  If this environment variable is set, SDCC won't install the signal handler
11604  in order to be able to debug SDCC.
11605 \end_layout
11606
11607 \begin_layout List
11608 \labelwidthstring 00.00.0000
11609
11610 \series bold
11611 TMP,\InsetSpace ~
11612 TEMP,\InsetSpace ~
11613 TMPDIR
11614 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11615
11616 \end_inset
11617
11618
11619 \series default
11620  Path, where temporary files will be created.
11621  The order of the variables is the search order.
11622  In a standard *nix environment these variables are not set, and there's
11623  no need to set them.
11624  On Windows it's recommended to set one of them.
11625 \end_layout
11626
11627 \begin_layout List
11628 \labelwidthstring 00.00.0000
11629
11630 \series bold
11631 SDCC_HOME
11632 \begin_inset LatexCommand \index{SDCC\_HOME}
11633
11634 \end_inset
11635
11636
11637 \series default
11638  Path, see section 
11639 \begin_inset LatexCommand \ref{sub:Install-paths}
11640
11641 \end_inset
11642
11643 \InsetSpace ~
11644
11645 \begin_inset Quotes sld
11646 \end_inset
11647
11648  Install Paths
11649 \begin_inset Quotes srd
11650 \end_inset
11651
11652 .
11653 \end_layout
11654
11655 \begin_layout List
11656 \labelwidthstring 00.00.0000
11657
11658 \series bold
11659 SDCC_INCLUDE
11660 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11661
11662 \end_inset
11663
11664
11665 \series default
11666  Path, see section 
11667 \begin_inset LatexCommand \ref{sub:Search-Paths}
11668
11669 \end_inset
11670
11671 \InsetSpace ~
11672
11673 \begin_inset Quotes sld
11674 \end_inset
11675
11676 Search Paths
11677 \begin_inset Quotes srd
11678 \end_inset
11679
11680 .
11681 \end_layout
11682
11683 \begin_layout List
11684 \labelwidthstring 00.00.0000
11685
11686 \series bold
11687 SDCC_LIB
11688 \begin_inset LatexCommand \index{SDCC\_LIB}
11689
11690 \end_inset
11691
11692
11693 \series default
11694  Path, see section 
11695 \begin_inset LatexCommand \ref{sub:Search-Paths}
11696
11697 \end_inset
11698
11699 \InsetSpace ~
11700
11701 \begin_inset Quotes sld
11702 \end_inset
11703
11704 Search Paths
11705 \begin_inset Quotes srd
11706 \end_inset
11707
11708 ..
11709 \end_layout
11710
11711 \begin_layout Standard
11712 There are some more environment variables recognized by SDCC, but these
11713  are solely used for debugging purposes.
11714  They can change or disappear very quickly, and will never be documented.
11715 \begin_inset VSpace bigskip
11716 \end_inset
11717
11718
11719 \end_layout
11720
11721 \begin_layout Section
11722 Storage Class Language Extensions
11723 \end_layout
11724
11725 \begin_layout Subsection
11726 MCS51/DS390 Storage Class
11727 \begin_inset LatexCommand \index{Storage class}
11728
11729 \end_inset
11730
11731  Language Extensions
11732 \end_layout
11733
11734 \begin_layout Standard
11735 In addition to the ANSI storage classes SDCC allows the following MCS51
11736  specific storage classes:
11737 \end_layout
11738
11739 \begin_layout Subsubsection
11740 data
11741 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11742
11743 \end_inset
11744
11745
11746 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11747
11748 \end_inset
11749
11750  / near
11751 \begin_inset LatexCommand \index{near (storage class)}
11752
11753 \end_inset
11754
11755
11756 \begin_inset LatexCommand \index{\_\_near (storage class)}
11757
11758 \end_inset
11759
11760
11761 \end_layout
11762
11763 \begin_layout Standard
11764 This is the 
11765 \series bold
11766 default
11767 \series default
11768  storage class for the Small Memory model (
11769 \emph on
11770 data
11771 \emph default
11772  and 
11773 \emph on
11774 near
11775 \emph default
11776  or the more ANSI-C compliant forms 
11777 \emph on
11778 __data
11779 \emph default
11780  and 
11781 \emph on
11782 __near
11783 \emph default
11784  can be used synonymously).
11785  Variables declared with this storage class will be allocated in the directly
11786  addressable portion of the internal RAM of a 8051, e.g.:
11787 \end_layout
11788
11789 \begin_layout Verse
11790
11791 \family typewriter
11792 __data unsigned char test_data;
11793 \end_layout
11794
11795 \begin_layout Standard
11796 Writing 0x01 to this variable generates the assembly code:
11797 \end_layout
11798
11799 \begin_layout Verse
11800
11801 \family typewriter
11802 75*00 01\InsetSpace ~
11803 \InsetSpace ~
11804 \InsetSpace ~
11805 mov\InsetSpace ~
11806 \InsetSpace ~
11807 _test_data,#0x01
11808 \end_layout
11809
11810 \begin_layout Subsubsection
11811 xdata
11812 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11813
11814 \end_inset
11815
11816
11817 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11818
11819 \end_inset
11820
11821  / far
11822 \begin_inset LatexCommand \index{far (storage class)}
11823
11824 \end_inset
11825
11826
11827 \begin_inset LatexCommand \index{\_\_far (storage class)}
11828
11829 \end_inset
11830
11831
11832 \end_layout
11833
11834 \begin_layout Standard
11835 Variables declared with this storage class will be placed in the external
11836  RAM.
11837  This is the 
11838 \series bold
11839 default
11840 \series default
11841  storage class for the Large Memory model, e.g.:
11842 \end_layout
11843
11844 \begin_layout Verse
11845
11846 \family typewriter
11847 __xdata unsigned char test_xdata;
11848 \end_layout
11849
11850 \begin_layout Standard
11851 Writing 0x01 to this variable generates the assembly code:
11852 \end_layout
11853
11854 \begin_layout Verse
11855
11856 \family typewriter
11857 90s00r00\InsetSpace ~
11858 \InsetSpace ~
11859 \InsetSpace ~
11860 mov\InsetSpace ~
11861 \InsetSpace ~
11862 dptr,#_test_xdata 
11863 \newline
11864 74\InsetSpace ~
11865 01\InsetSpace ~
11866 \InsetSpace ~
11867 \InsetSpace ~
11868 \InsetSpace ~
11869 \InsetSpace ~
11870 \InsetSpace ~
11871 mov\InsetSpace ~
11872 \InsetSpace ~
11873 a,#0x01 
11874 \newline
11875 F0\InsetSpace ~
11876 \InsetSpace ~
11877 \InsetSpace ~
11878 \InsetSpace ~
11879 \InsetSpace ~
11880 \InsetSpace ~
11881 \InsetSpace ~
11882 \InsetSpace ~
11883 \InsetSpace ~
11884 movx\InsetSpace ~
11885 @dptr,a 
11886 \end_layout
11887
11888 \begin_layout Subsubsection
11889 idata
11890 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11891
11892 \end_inset
11893
11894
11895 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11896
11897 \end_inset
11898
11899
11900 \end_layout
11901
11902 \begin_layout Standard
11903 Variables declared with this storage class will be allocated into the indirectly
11904  addressable portion of the internal ram of a 8051, e.g.:
11905 \end_layout
11906
11907 \begin_layout Verse
11908
11909 \family typewriter
11910 __idata unsigned char test_idata;
11911 \end_layout
11912
11913 \begin_layout Standard
11914 Writing 0x01 to this variable generates the assembly code:
11915 \end_layout
11916
11917 \begin_layout Verse
11918
11919 \family typewriter
11920 78r00\InsetSpace ~
11921 \InsetSpace ~
11922 \InsetSpace ~
11923 \InsetSpace ~
11924 \InsetSpace ~
11925 \InsetSpace ~
11926 \InsetSpace ~
11927 mov\InsetSpace ~
11928 \InsetSpace ~
11929 r0,#_test_idata
11930 \newline
11931 76\InsetSpace ~
11932 01\InsetSpace ~
11933 \InsetSpace ~
11934 \InsetSpace ~
11935 \InsetSpace ~
11936 \InsetSpace ~
11937 \InsetSpace ~
11938 \InsetSpace ~
11939 mov\InsetSpace ~
11940 \InsetSpace ~
11941 @r0,#0x01
11942 \end_layout
11943
11944 \begin_layout Standard
11945 Please note, the first 128 byte of idata physically access the same RAM
11946  as the data memory.
11947  The original 8051 had 128 byte idata memory, nowadays most devices have
11948  256 byte idata memory.
11949  The stack
11950 \begin_inset LatexCommand \index{stack}
11951
11952 \end_inset
11953
11954  is located in idata memory.
11955 \end_layout
11956
11957 \begin_layout Subsubsection
11958 pdata
11959 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11960
11961 \end_inset
11962
11963
11964 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11965
11966 \end_inset
11967
11968
11969 \end_layout
11970
11971 \begin_layout Standard
11972 Paged xdata access is just as straightforward as using the other addressing
11973  modes of a 8051.
11974  It is typically located at the start of xdata and has a maximum size of
11975  256 bytes.
11976  The following example writes 0x01 to the pdata variable.
11977  Please note, pdata access physically accesses xdata memory.
11978  The high byte of the address is determined by port P2 
11979 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11980
11981 \end_inset
11982
11983 (or in case of some 8051 variants by a separate Special Function Register,
11984  see section 
11985 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11986
11987 \end_inset
11988
11989 ).
11990  This is the 
11991 \series bold
11992 default
11993 \series default
11994  storage class for the Medium Memory model, e.g.:
11995 \end_layout
11996
11997 \begin_layout Verse
11998
11999 \family typewriter
12000 __pdata unsigned char test_pdata;
12001 \end_layout
12002
12003 \begin_layout Standard
12004 Writing 0x01 to this variable generates the assembly code:
12005 \end_layout
12006
12007 \begin_layout Verse
12008
12009 \family typewriter
12010 78r00\InsetSpace ~
12011 \InsetSpace ~
12012 \InsetSpace ~
12013 \InsetSpace ~
12014 \InsetSpace ~
12015 \InsetSpace ~
12016 mov r0,#_test_pdata
12017 \newline
12018 74 01\InsetSpace ~
12019 \InsetSpace ~
12020 \InsetSpace ~
12021 \InsetSpace ~
12022 \InsetSpace ~
12023 \InsetSpace ~
12024 mov a,#0x01 
12025 \newline
12026 F2\InsetSpace ~
12027 \InsetSpace ~
12028 \InsetSpace ~
12029 \InsetSpace ~
12030 \InsetSpace ~
12031 \InsetSpace ~
12032 \InsetSpace ~
12033 \InsetSpace ~
12034 \InsetSpace ~
12035 movx @r0,a
12036 \end_layout
12037
12038 \begin_layout Standard
12039 If the -
12040 \begin_inset ERT
12041 status collapsed
12042
12043 \begin_layout Standard
12044
12045
12046 \backslash
12047 /
12048 \end_layout
12049
12050 \end_inset
12051
12052 -xstack
12053 \begin_inset LatexCommand \index{-\/-xstack}
12054
12055 \end_inset
12056
12057  option is used the pdata memory area is followed by the xstack memory area
12058  and the sum of their sizes is limited to 256 bytes.
12059 \end_layout
12060
12061 \begin_layout Subsubsection
12062 code
12063 \begin_inset LatexCommand \index{code}
12064
12065 \end_inset
12066
12067
12068 \begin_inset LatexCommand \index{\_\_code}
12069
12070 \end_inset
12071
12072
12073 \end_layout
12074
12075 \begin_layout Standard
12076 'Variables' declared with this storage class will be placed in the code
12077  memory:
12078 \end_layout
12079
12080 \begin_layout Verse
12081
12082 \family typewriter
12083 __code unsigned char test_code;
12084 \end_layout
12085
12086 \begin_layout Standard
12087 Read access to this variable generates the assembly code:
12088 \end_layout
12089
12090 \begin_layout Verse
12091
12092 \family typewriter
12093 90s00r6F\InsetSpace ~
12094 \InsetSpace ~
12095 \InsetSpace ~
12096 mov dptr,#_test_code
12097 \newline
12098 E4\InsetSpace ~
12099 \InsetSpace ~
12100 \InsetSpace ~
12101 \InsetSpace ~
12102 \InsetSpace ~
12103 \InsetSpace ~
12104 \InsetSpace ~
12105 \InsetSpace ~
12106 \InsetSpace ~
12107 clr a
12108 \newline
12109 93\InsetSpace ~
12110 \InsetSpace ~
12111 \InsetSpace ~
12112 \InsetSpace ~
12113 \InsetSpace ~
12114 \InsetSpace ~
12115 \InsetSpace ~
12116 \InsetSpace ~
12117 \InsetSpace ~
12118 movc a,@a+dptr 
12119 \end_layout
12120
12121 \begin_layout Standard
12122
12123 \family typewriter
12124 char
12125 \family default
12126  indexed arrays of characters in code memory can be accessed efficiently:
12127 \end_layout
12128
12129 \begin_layout Verse
12130
12131 \family typewriter
12132 __code char test_array[] = {'c','h','e','a','p'}; 
12133 \end_layout
12134
12135 \begin_layout Standard
12136 Read access to this array using an 8-bit unsigned index generates the assembly
12137  code:
12138 \end_layout
12139
12140 \begin_layout Verse
12141
12142 \family typewriter
12143 E5*00\InsetSpace ~
12144 \InsetSpace ~
12145 \InsetSpace ~
12146 \InsetSpace ~
12147 \InsetSpace ~
12148 \InsetSpace ~
12149 mov a,_index 
12150 \end_layout
12151
12152 \begin_layout Verse
12153
12154 \family typewriter
12155 90s00r41\InsetSpace ~
12156 \InsetSpace ~
12157 \InsetSpace ~
12158 mov dptr,#_test_array
12159 \end_layout
12160
12161 \begin_layout Verse
12162
12163 \family typewriter
12164 93\InsetSpace ~
12165 \InsetSpace ~
12166 \InsetSpace ~
12167 \InsetSpace ~
12168 \InsetSpace ~
12169 \InsetSpace ~
12170 \InsetSpace ~
12171 \InsetSpace ~
12172 \InsetSpace ~
12173 movc a,@a+dptr 
12174 \end_layout
12175
12176 \begin_layout Subsubsection
12177 bit
12178 \begin_inset LatexCommand \index{bit}
12179
12180 \end_inset
12181
12182
12183 \begin_inset LatexCommand \index{\_\_bit}
12184
12185 \end_inset
12186
12187
12188 \end_layout
12189
12190 \begin_layout Standard
12191 This is a data-type and a storage class specifier.
12192  When a variable is declared as a bit, it is allocated into the bit addressable
12193  memory of 8051, e.g.:
12194 \end_layout
12195
12196 \begin_layout Verse
12197
12198 \family typewriter
12199 __bit test_bit;
12200 \end_layout
12201
12202 \begin_layout Standard
12203 Writing 1 to this variable generates the assembly code:
12204 \end_layout
12205
12206 \begin_layout Verse
12207
12208 \family typewriter
12209 D2*00\InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 \InsetSpace ~
12214 \InsetSpace ~
12215 \InsetSpace ~
12216 setb\InsetSpace ~
12217 _test_bit
12218 \end_layout
12219
12220 \begin_layout Standard
12221 The bit addressable memory consists of 128 bits which are located from 0x20
12222  to 0x2f in data memory.
12223  
12224 \newline
12225 Apart from this 8051 specific storage class most architectures support
12226  ANSI-C bitfields
12227 \begin_inset LatexCommand \index{bitfields}
12228
12229 \end_inset
12230
12231
12232 \begin_inset Foot
12233 status open
12234
12235 \begin_layout Standard
12236 Not really meant as examples, but nevertheless showing what bitfields are
12237  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12238 \end_layout
12239
12240 \end_inset
12241
12242 .
12243  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12244  signed modifier are implemented as unsigned.
12245 \end_layout
12246
12247 \begin_layout Subsubsection
12248 sfr
12249 \begin_inset LatexCommand \index{sfr}
12250
12251 \end_inset
12252
12253
12254 \begin_inset LatexCommand \index{\_\_sfr}
12255
12256 \end_inset
12257
12258  / sfr16
12259 \begin_inset LatexCommand \index{sfr16}
12260
12261 \end_inset
12262
12263
12264 \begin_inset LatexCommand \index{\_\_sfr16}
12265
12266 \end_inset
12267
12268  / sfr32
12269 \begin_inset LatexCommand \index{sfr32}
12270
12271 \end_inset
12272
12273
12274 \begin_inset LatexCommand \index{\_\_sfr32}
12275
12276 \end_inset
12277
12278  / sbit
12279 \begin_inset LatexCommand \index{\_\_sbit}
12280
12281 \end_inset
12282
12283
12284 \begin_inset LatexCommand \index{sbit}
12285
12286 \end_inset
12287
12288
12289 \end_layout
12290
12291 \begin_layout Standard
12292 Like the bit keyword, 
12293 \emph on
12294 sfr / sfr16 / sfr32 / sbit 
12295 \emph default
12296 signify both a data-type and storage class, they are used to describe the
12297  
12298 \emph on
12299 s
12300 \emph default
12301 pecial 
12302 \emph on
12303 f
12304 \emph default
12305 unction 
12306 \emph on
12307 r
12308 \emph default
12309 egisters and 
12310 \emph on
12311 s
12312 \emph default
12313 pecial 
12314 \emph on
12315 bit
12316 \emph default
12317  variables of a 8051, eg:
12318 \end_layout
12319
12320 \begin_layout Verse
12321
12322 \family typewriter
12323 __sfr __at
12324 \begin_inset LatexCommand \index{at}
12325
12326 \end_inset
12327
12328
12329 \begin_inset LatexCommand \index{\_\_at}
12330
12331 \end_inset
12332
12333  (0x80) P0;\InsetSpace ~
12334  /* special function register P0 at location 0x80 */
12335 \newline
12336
12337 \newline
12338 /* 16 bit
12339  special function register combination for timer 0
12340 \newline
12341 \InsetSpace ~
12342 \InsetSpace ~
12343  with the high byte at
12344  location 0x8C and the low byte at location 0x8A */
12345 \newline
12346 __sfr16 __at (0x8C8A)
12347  TMR0;
12348 \newline
12349
12350 \newline
12351 __sbit __at
12352 \begin_inset LatexCommand \index{at}
12353
12354 \end_inset
12355
12356
12357 \begin_inset LatexCommand \index{\_\_at}
12358
12359 \end_inset
12360
12361  (0xd7) CY;\InsetSpace ~
12362  /* CY (Carry Flag
12363 \begin_inset LatexCommand \index{Flags}
12364
12365 \end_inset
12366
12367
12368 \begin_inset LatexCommand \index{Carry flag}
12369
12370 \end_inset
12371
12372 ) */
12373 \end_layout
12374
12375 \begin_layout Standard
12376 Special function registers which are located on an address dividable by
12377  8 are bit-addressable, an
12378 \emph on
12379  sbit
12380 \emph default
12381  addresses a specific bit within these sfr.
12382 \newline
12383 16 Bit and 32 bit special function
12384  register combinations which require a certain access order are better not
12385  declared using 
12386 \emph on
12387 sfr16
12388 \emph default
12389  or 
12390 \emph on
12391 sfr32.
12392
12393 \emph default
12394  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12395  this is not guaranteed.
12396 \newline
12397
12398 \end_layout
12399
12400 \begin_layout Standard
12401 Please note, if you use a header file which was written for another compiler
12402  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12403  likely be 
12404 \emph on
12405 not 
12406 \emph default
12407 compatible.
12408  Specifically the syntax 
12409 \family typewriter
12410 \InsetSpace ~
12411 sfr P0 = 0x80;\InsetSpace ~
12412
12413 \family default
12414  is compiled 
12415 \emph on
12416 without warning
12417 \emph default
12418  by SDCC to an assignment of 0x80 to a variable called P0 
12419 \family typewriter
12420
12421 \begin_inset Marginal
12422 status collapsed
12423
12424 \begin_layout Standard
12425
12426 \series bold
12427 \InsetSpace ~
12428 !
12429 \end_layout
12430
12431 \end_inset
12432
12433 .
12434  
12435 \family default
12436 Nevertheless it is possible to write header files
12437 \begin_inset LatexCommand \index{Header files}
12438
12439 \end_inset
12440
12441
12442 \begin_inset LatexCommand \index{Include files}
12443
12444 \end_inset
12445
12446  which can be shared among different compilers (see section 
12447 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12448
12449 \end_inset
12450
12451 ).
12452  
12453 \end_layout
12454
12455 \begin_layout Subsubsection
12456 Pointers
12457 \begin_inset LatexCommand \index{Pointer}
12458
12459 \end_inset
12460
12461  to MCS51/DS390 specific memory spaces
12462 \end_layout
12463
12464 \begin_layout Standard
12465 SDCC allows (via language extensions) pointers to explicitly point to any
12466  of the memory spaces
12467 \begin_inset LatexCommand \index{Memory model}
12468
12469 \end_inset
12470
12471  of the 8051.
12472  In addition to the explicit pointers, the compiler uses (by default) generic
12473  pointers which can be used to point to any of the memory spaces.
12474 \newline
12475
12476 \newline
12477 Pointer
12478  declaration examples:
12479 \end_layout
12480
12481 \begin_layout Verse
12482
12483 \family typewriter
12484 /* pointer physically in internal ram pointing to object in external ram
12485  */ 
12486 \newline
12487 __xdata unsigned char * __data p;
12488 \newline
12489
12490 \newline
12491 /* pointer physically in external ram
12492  pointing to object in internal ram */ 
12493 \newline
12494 __data unsigned char * __xdata p;
12495 \newline
12496
12497 \newline
12498 /*
12499  pointer physically in code rom pointing to data in xdata space */ 
12500 \newline
12501 __xdata
12502  unsigned char * __code p;
12503 \newline
12504
12505 \newline
12506 /* pointer physically in code space pointing to
12507  data in code space */ 
12508 \newline
12509 __code unsigned char * __code p;
12510 \newline
12511
12512 \newline
12513 /* generic pointer
12514  physically located in xdata space */
12515 \newline
12516 unsigned char * __xdata p;
12517 \newline
12518
12519 \newline
12520 /* generic
12521  pointer physically located in default memory space */
12522 \newline
12523 unsigned char * p;
12524 \newline
12525
12526 \newline
12527 /*
12528  the following is a function pointer
12529 \begin_inset LatexCommand \index{function pointer}
12530
12531 \end_inset
12532
12533  physically located in data space */
12534 \newline
12535 char (* __data fp)(void);
12536 \end_layout
12537
12538 \begin_layout Standard
12539 Well you get the idea.
12540  
12541 \newline
12542
12543 \newline
12544 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12545 \emph on
12546 generic
12547 \emph default
12548  pointers.
12549  
12550 \size small
12551
12552 \newline
12553
12554 \newline
12555
12556 \size default
12557 The highest order byte of the 
12558 \emph on
12559 generic
12560 \emph default
12561  pointers contains the data space information.
12562  Assembler support routines are called whenever data is stored or retrieved
12563  using 
12564 \emph on
12565 generic
12566 \emph default
12567  pointers.
12568  These are useful for developing reusable library
12569 \begin_inset LatexCommand \index{Libraries}
12570
12571 \end_inset
12572
12573  routines.
12574  Explicitly specifying the pointer
12575 \begin_inset LatexCommand \index{pointer}
12576
12577 \end_inset
12578
12579  type will generate the most efficient code.
12580 \end_layout
12581
12582 \begin_layout Subsubsection
12583 Notes on MCS51 memory
12584 \begin_inset LatexCommand \index{MCS51 memory}
12585
12586 \end_inset
12587
12588  layout
12589 \end_layout
12590
12591 \begin_layout Standard
12592 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12593  RAM memory which is structured as follows:
12594 \newline
12595
12596 \newline
12597 - Bytes 00-1F - 32 bytes to hold
12598  up to 4 banks of the registers R0 to R7, 
12599 \newline
12600 - Bytes 20-2F - 16 bytes to hold
12601  128 bit
12602 \begin_inset LatexCommand \index{bit}
12603
12604 \end_inset
12605
12606  variables and, 
12607 \newline
12608 - Bytes 30-7F - 80 bytes for general purpose use.
12609 \newline
12610
12611 \end_layout
12612
12613 \begin_layout Standard
12614 Additionally some members of the MCS51 family may have up to 128 bytes of
12615  additional, indirectly addressable, internal RAM memory (
12616 \emph on
12617 idata
12618 \emph default
12619
12620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12621
12622 \end_inset
12623
12624
12625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12626
12627 \end_inset
12628
12629 ).
12630  Furthermore, some chips may have some built in external memory (
12631 \emph on
12632 xdata
12633 \emph default
12634
12635 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12636
12637 \end_inset
12638
12639
12640 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12641
12642 \end_inset
12643
12644 ) which should not be confused with the internal, directly addressable RAM
12645  memory (
12646 \emph on
12647 data
12648 \emph default
12649
12650 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12651
12652 \end_inset
12653
12654
12655 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12656
12657 \end_inset
12658
12659 ).
12660  Sometimes this built in 
12661 \emph on
12662 xdata
12663 \emph default
12664  memory has to be activated before using it (you can probably find this
12665  information on the datasheet of the microcontroller your are using, see
12666  also section 
12667 \begin_inset LatexCommand \ref{sub:Startup-Code}
12668
12669 \end_inset
12670
12671 \InsetSpace ~
12672 Startup-Code).
12673 \end_layout
12674
12675 \begin_layout Standard
12676 Normally SDCC will only use the first bank
12677 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12678
12679 \end_inset
12680
12681  of registers (register bank 0), but it is possible to specify that other
12682  banks of registers (keyword 
12683 \emph on
12684 using
12685 \emph default
12686  
12687 \emph on
12688
12689 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12690
12691 \end_inset
12692
12693
12694 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12695
12696 \end_inset
12697
12698
12699 \emph default
12700 ) should be used for example in interrupt
12701 \begin_inset LatexCommand \index{interrupt}
12702
12703 \end_inset
12704
12705
12706 \begin_inset LatexCommand \index{\_\_interrupt}
12707
12708 \end_inset
12709
12710  routines.
12711  By default, the compiler will place the stack after the last byte of allocated
12712  memory for variables.
12713  For example, if the first 2 banks of registers are used, and only four
12714  bytes are used for 
12715 \emph on
12716 data
12717 \emph default
12718  variables, it will position the base of the internal stack at address 20
12719  (0x14).
12720  This implies that as the stack
12721 \begin_inset LatexCommand \index{stack}
12722
12723 \end_inset
12724
12725  grows, it will use up the remaining register banks, and the 16 bytes used
12726  by the 128 bit variables, and 80 bytes for general purpose use.
12727  If any bit variables are used, the data variables will be placed in unused
12728  register banks and after the byte holding the last bit variable.
12729  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12730  (two bytes used), 
12731 \emph on
12732 data
12733 \emph default
12734  variables will be placed starting from address 0x10 to 0x20 and continue
12735  at address 0x22.
12736  You can also use -
12737 \begin_inset ERT
12738 status collapsed
12739
12740 \begin_layout Standard
12741
12742
12743 \backslash
12744 /
12745 \end_layout
12746
12747 \end_inset
12748
12749 -data-loc
12750 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12751
12752 \end_inset
12753
12754  to specify the start address of the 
12755 \emph on
12756 data
12757 \emph default
12758  and -
12759 \begin_inset ERT
12760 status collapsed
12761
12762 \begin_layout Standard
12763
12764
12765 \backslash
12766 /
12767 \end_layout
12768
12769 \end_inset
12770
12771 -iram-size
12772 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12773
12774 \end_inset
12775
12776  to specify the size of the total internal RAM (
12777 \emph on
12778 data
12779 \emph default
12780 +
12781 \emph on
12782 idata
12783 \emph default
12784 ).
12785  
12786 \newline
12787
12788 \end_layout
12789
12790 \begin_layout Standard
12791 By default the 8051 linker will place the stack after the last byte of (i)data
12792  variables.
12793  Option -
12794 \begin_inset ERT
12795 status collapsed
12796
12797 \begin_layout Standard
12798
12799
12800 \backslash
12801 /
12802 \end_layout
12803
12804 \end_inset
12805
12806 -stack-loc
12807 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12808
12809 \end_inset
12810
12811  allows you to specify the start of the stack, i.e.
12812  you could start it after any data in the general purpose area.
12813  If your microcontroller has additional indirectly addressable internal
12814  RAM (
12815 \emph on
12816 idata
12817 \emph default
12818 ) you can place the stack on it.
12819  You may also need to use -
12820 \begin_inset ERT
12821 status collapsed
12822
12823 \begin_layout Standard
12824
12825
12826 \backslash
12827 /
12828 \end_layout
12829
12830 \end_inset
12831
12832 -xdata-loc
12833 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12834
12835 \end_inset
12836
12837  to set the start address of the external RAM (
12838 \emph on
12839 xdata
12840 \emph default
12841 ) and -
12842 \begin_inset ERT
12843 status collapsed
12844
12845 \begin_layout Standard
12846
12847
12848 \backslash
12849 /
12850 \end_layout
12851
12852 \end_inset
12853
12854 -xram-size
12855 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12856
12857 \end_inset
12858
12859  to specify its size.
12860  Same goes for the code memory, using -
12861 \begin_inset ERT
12862 status collapsed
12863
12864 \begin_layout Standard
12865
12866
12867 \backslash
12868 /
12869 \end_layout
12870
12871 \end_inset
12872
12873 -code-loc
12874 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12875
12876 \end_inset
12877
12878  and -
12879 \begin_inset ERT
12880 status collapsed
12881
12882 \begin_layout Standard
12883
12884
12885 \backslash
12886 /
12887 \end_layout
12888
12889 \end_inset
12890
12891 -code-size
12892 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12893
12894 \end_inset
12895
12896 .
12897  If in doubt, don't specify any options and see if the resulting memory
12898  layout is appropriate, then you can adjust it.
12899 \end_layout
12900
12901 \begin_layout Standard
12902 The linker generates two files with memory allocation information.
12903  The first, with extension .map
12904 \begin_inset LatexCommand \index{<file>.map}
12905
12906 \end_inset
12907
12908  shows all the variables and segments.
12909  The second with extension .mem
12910 \begin_inset LatexCommand \index{<file>.mem}
12911
12912 \end_inset
12913
12914  shows the final memory layout.
12915  The linker will complain either if memory segments overlap, there is not
12916  enough memory, or there is not enough space for stack.
12917  If you get any linking warnings and/or errors related to stack or segments
12918  allocation, take a look at either the .map or .mem files to find out what
12919  the problem is.
12920  The .mem file may even suggest a solution to the problem.
12921 \begin_inset VSpace bigskip
12922 \end_inset
12923
12924
12925 \end_layout
12926
12927 \begin_layout Subsection
12928 Z80/Z180 Storage Class
12929 \begin_inset LatexCommand \index{Z80!Storage class}
12930
12931 \end_inset
12932
12933  Language Extensions
12934 \end_layout
12935
12936 \begin_layout Subsubsection
12937 sfr
12938 \begin_inset LatexCommand \index{sfr}
12939
12940 \end_inset
12941
12942
12943 \begin_inset LatexCommand \index{\_\_sfr}
12944
12945 \end_inset
12946
12947  (in/out to 8-bit addresses)
12948 \end_layout
12949
12950 \begin_layout Standard
12951 The Z80
12952 \begin_inset LatexCommand \index{Z80}
12953
12954 \end_inset
12955
12956  family has separate address spaces for memory and 
12957 \emph on
12958 i
12959 \emph default
12960 nput/
12961 \emph on
12962 o
12963 \emph default
12964 utput memory.
12965  I/O memory
12966 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12967
12968 \end_inset
12969
12970
12971 \begin_inset LatexCommand \index{Z80!I/O memory}
12972
12973 \end_inset
12974
12975
12976 \begin_inset LatexCommand \index{Z180!I/O memory}
12977
12978 \end_inset
12979
12980  is accessed with special instructions, e.g.:
12981 \end_layout
12982
12983 \begin_layout Verse
12984
12985 \family typewriter
12986 sfr at 0x78 IoPort;\InsetSpace ~
12987 \InsetSpace ~
12988 /* define a var in I/O space at 78h called IoPort */
12989  
12990 \end_layout
12991
12992 \begin_layout Standard
12993 Writing 0x01 to this variable generates the assembly code:
12994 \end_layout
12995
12996 \begin_layout Verse
12997
12998 \family typewriter
12999 3E 01\InsetSpace ~
13000 \InsetSpace ~
13001 \InsetSpace ~
13002 \InsetSpace ~
13003 \InsetSpace ~
13004 \InsetSpace ~
13005 ld a,#0x01
13006 \newline
13007 D3 78\InsetSpace ~
13008 \InsetSpace ~
13009 \InsetSpace ~
13010 \InsetSpace ~
13011 \InsetSpace ~
13012 \InsetSpace ~
13013 out (_IoPort),a 
13014 \end_layout
13015
13016 \begin_layout Subsubsection
13017 banked sfr
13018 \begin_inset LatexCommand \index{sfr}
13019
13020 \end_inset
13021
13022
13023 \begin_inset LatexCommand \index{\_\_sfr}
13024
13025 \end_inset
13026
13027  (in/out to 16-bit addresses)
13028 \end_layout
13029
13030 \begin_layout Standard
13031 The keyword 
13032 \emph on
13033 banked
13034 \emph default
13035  is used to support 16 bit addresses in I/O memory e.g.:
13036 \end_layout
13037
13038 \begin_layout Verse
13039
13040 \family typewriter
13041 sfr banked at
13042 \begin_inset LatexCommand \index{at}
13043
13044 \end_inset
13045
13046
13047 \begin_inset LatexCommand \index{\_\_at}
13048
13049 \end_inset
13050
13051  0x123 IoPort; 
13052 \end_layout
13053
13054 \begin_layout Standard
13055 Writing 0x01 to this variable generates the assembly code:
13056 \end_layout
13057
13058 \begin_layout Verse
13059
13060 \family typewriter
13061 01 23 01\InsetSpace ~
13062 \InsetSpace ~
13063 \InsetSpace ~
13064 ld bc,#_IoPort
13065 \newline
13066 3E 01\InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 \InsetSpace ~
13070 \InsetSpace ~
13071 \InsetSpace ~
13072 ld a,#0x01 
13073 \newline
13074 ED 79\InsetSpace ~
13075 \InsetSpace ~
13076 \InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 out (c),a 
13081 \end_layout
13082
13083 \begin_layout Subsubsection
13084 sfr
13085 \begin_inset LatexCommand \index{sfr}
13086
13087 \end_inset
13088
13089
13090 \begin_inset LatexCommand \index{\_\_sfr}
13091
13092 \end_inset
13093
13094  (in0/out0 to 8 bit addresses on Z180
13095 \begin_inset LatexCommand \index{Z180}
13096
13097 \end_inset
13098
13099 /HD64180
13100 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13101
13102 \end_inset
13103
13104 )
13105 \end_layout
13106
13107 \begin_layout Standard
13108 The compiler option -
13109 \begin_inset ERT
13110 status collapsed
13111
13112 \begin_layout Standard
13113
13114
13115 \backslash
13116 /
13117 \end_layout
13118
13119 \end_inset
13120
13121 -portmode
13122 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13123
13124 \end_inset
13125
13126 =180 (80) and a compiler #pragma\InsetSpace ~
13127 portmode
13128 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13129
13130 \end_inset
13131
13132  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13133 ns 
13134 \family typewriter
13135 in0/out0
13136 \family default
13137  instead of 
13138 \family typewriter
13139 in/out
13140 \family default
13141 .
13142  If you include the file z180.h this will be set automatically.
13143 \begin_inset VSpace bigskip
13144 \end_inset
13145
13146
13147 \end_layout
13148
13149 \begin_layout Subsection
13150 HC08 Storage Class
13151 \begin_inset LatexCommand \index{HC08!Storage class}
13152
13153 \end_inset
13154
13155  Language Extensions
13156 \end_layout
13157
13158 \begin_layout Subsubsection
13159 data
13160 \begin_inset LatexCommand \index{data (hc08 storage class)}
13161
13162 \end_inset
13163
13164
13165 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13166
13167 \end_inset
13168
13169  
13170 \end_layout
13171
13172 \begin_layout Standard
13173 The data storage class declares a variable that resides in the first 256
13174  bytes of memory (the direct page).
13175  The HC08
13176 \begin_inset LatexCommand \index{HC08}
13177
13178 \end_inset
13179
13180  is most efficient at accessing variables (especially pointers) stored here.
13181 \end_layout
13182
13183 \begin_layout Subsubsection
13184 xdata
13185 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13186
13187 \end_inset
13188
13189
13190 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13191
13192 \end_inset
13193
13194  
13195 \end_layout
13196
13197 \begin_layout Standard
13198 The xdata storage class declares a variable that can reside anywhere in
13199  memory.
13200  This is the default if no storage class is specified.
13201  
13202 \begin_inset VSpace bigskip
13203 \end_inset
13204
13205
13206 \end_layout
13207
13208 \begin_layout Section
13209 Absolute Addressing
13210 \begin_inset LatexCommand \index{Absolute addressing}
13211
13212 \end_inset
13213
13214
13215 \end_layout
13216
13217 \begin_layout Standard
13218 Data items can be assigned an absolute address with the 
13219 \emph on
13220 at
13221 \begin_inset LatexCommand \index{at}
13222
13223 \end_inset
13224
13225
13226 \begin_inset LatexCommand \index{\_\_at}
13227
13228 \end_inset
13229
13230  <address>
13231 \emph default
13232  keyword, in addition to a storage class, e.g.:
13233 \end_layout
13234
13235 \begin_layout Verse
13236
13237 \family typewriter
13238 xdata
13239 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13240
13241 \end_inset
13242
13243
13244 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13245
13246 \end_inset
13247
13248  at
13249 \begin_inset LatexCommand \index{at}
13250
13251 \end_inset
13252
13253
13254 \begin_inset LatexCommand \index{\_\_at}
13255
13256 \end_inset
13257
13258  0x7ffe unsigned int chksum;
13259 \end_layout
13260
13261 \begin_layout Standard
13262 or, better conforming to ISO/IEC 9899 C:
13263 \end_layout
13264
13265 \begin_layout Verse
13266
13267 \family typewriter
13268 __xdata __at (0x7ffe) unsigned int chksum;
13269 \end_layout
13270
13271 \begin_layout Standard
13272 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13273  of the external ram.
13274  The compiler does 
13275 \emph on
13276 not
13277 \emph default
13278  reserve any space for variables declared in this way
13279 \begin_inset Marginal
13280 status collapsed
13281
13282 \begin_layout Standard
13283
13284 \series bold
13285 \InsetSpace ~
13286 !
13287 \end_layout
13288
13289 \end_inset
13290
13291  (they are implemented with an equate in the assembler).
13292  Thus it is left to the programmer to make sure there are no overlaps with
13293  other variables that are declared without the absolute address.
13294  The assembler listing file (.lst
13295 \begin_inset LatexCommand \index{<file>.lst}
13296
13297 \end_inset
13298
13299 ) and the linker output files (.rst
13300 \begin_inset LatexCommand \index{<file>.rst}
13301
13302 \end_inset
13303
13304 ) and (.map
13305 \begin_inset LatexCommand \index{<file>.map}
13306
13307 \end_inset
13308
13309 ) are good places to look for such overlaps.
13310 \end_layout
13311
13312 \begin_layout Standard
13313 If however you provide an initializer
13314 \begin_inset LatexCommand \index{Variable initialization}
13315
13316 \end_inset
13317
13318  actual memory allocation will take place and overlaps will be detected
13319  by the linker.
13320  E.g.:
13321 \end_layout
13322
13323 \begin_layout Verse
13324
13325 \family typewriter
13326 __code __at (0x7ff0) char Id[5] = 
13327 \begin_inset Quotes sld
13328 \end_inset
13329
13330 SDCC
13331 \begin_inset Quotes srd
13332 \end_inset
13333
13334 ;
13335 \end_layout
13336
13337 \begin_layout Standard
13338 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13339  in code memory.
13340 \end_layout
13341
13342 \begin_layout Standard
13343 In case of memory mapped I/O devices the keyword 
13344 \emph on
13345 volatile
13346 \emph default
13347  has to be used to tell the compiler that accesses might not be removed:
13348 \end_layout
13349
13350 \begin_layout Verse
13351
13352 \family typewriter
13353 volatile
13354 \begin_inset LatexCommand \index{volatile}
13355
13356 \end_inset
13357
13358  __xdata
13359 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13360
13361 \end_inset
13362
13363  __at
13364 \begin_inset LatexCommand \index{at}
13365
13366 \end_inset
13367
13368  (0x8000) unsigned char PORTA_8255;
13369 \end_layout
13370
13371 \begin_layout Standard
13372 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13373 r) array
13374 \family typewriter
13375 \size footnotesize
13376
13377 \begin_inset LatexCommand \index{Aligned array}
13378
13379 \end_inset
13380
13381
13382 \family default
13383 \size default
13384  starts at a block (256 byte) boundary
13385 \begin_inset LatexCommand \index{block boundary}
13386
13387 \end_inset
13388
13389  (section 
13390 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13391
13392 \end_inset
13393
13394  has an example).
13395 \newline
13396 Absolute addresses can be specified for variables in all
13397  storage classes, e.g.:
13398 \end_layout
13399
13400 \begin_layout Verse
13401
13402 \family typewriter
13403 __bit
13404 \begin_inset LatexCommand \index{bit}
13405
13406 \end_inset
13407
13408  __at
13409 \begin_inset LatexCommand \index{at}
13410
13411 \end_inset
13412
13413  (0x02) bvar;
13414 \end_layout
13415
13416 \begin_layout Standard
13417 The above example will allocate the variable at offset 0x02 in the bit-addressab
13418 le space.
13419  There is no real advantage to assigning absolute addresses to variables
13420  in this manner, unless you want strict control over all the variables allocated.
13421  One possible use would be to write hardware portable code.
13422  For example, if you have a routine that uses one or more of the microcontroller
13423  I/O pins, and such pins are different for two different hardwares, you
13424  can declare the I/O pins in your routine using:
13425 \end_layout
13426
13427 \begin_layout Verse
13428
13429 \family typewriter
13430 extern volatile
13431 \begin_inset LatexCommand \index{volatile}
13432
13433 \end_inset
13434
13435  __bit MOSI;\InsetSpace ~
13436 \InsetSpace ~
13437 \InsetSpace ~
13438 \InsetSpace ~
13439 /* master out, slave in */
13440 \newline
13441 extern volatile __bit MISO;\InsetSpace ~
13442 \InsetSpace ~
13443 \InsetSpace ~
13444 \InsetSpace ~
13445 /* master
13446  in, slave out */
13447 \newline
13448 extern volatile __bit MCLK;\InsetSpace ~
13449 \InsetSpace ~
13450 \InsetSpace ~
13451 \InsetSpace ~
13452 /* master clock */
13453 \newline
13454
13455 \newline
13456 /* Input and
13457  Output of a byte on a 3-wire serial bus.
13458 \newline
13459 \InsetSpace ~
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 If needed adapt polarity of clock,
13463  polarity of data and bit order
13464 \newline
13465 \InsetSpace ~
13466 */
13467 \newline
13468 unsigned char spi_io(unsigned char out_byte)
13469  
13470 \newline
13471
13472 \newline
13473 \InsetSpace ~
13474 \InsetSpace ~
13475 \InsetSpace ~
13476 \InsetSpace ~
13477 unsigned char i=8;
13478 \newline
13479 \InsetSpace ~
13480 \InsetSpace ~
13481 \InsetSpace ~
13482 \InsetSpace ~
13483 do { 
13484 \newline
13485 \InsetSpace ~
13486 \InsetSpace ~
13487 \InsetSpace ~
13488 \InsetSpace ~
13489 \InsetSpace ~
13490 \InsetSpace ~
13491 \InsetSpace ~
13492 \InsetSpace ~
13493 MOSI = out_byte & 0x80; 
13494 \newline
13495 \InsetSpace ~
13496 \InsetSpace ~
13497 \InsetSpace ~
13498 \InsetSpace ~
13499 \InsetSpace ~
13500 \InsetSpace ~
13501 \InsetSpace ~
13502 \InsetSpace ~
13503 out_byte <<= 1;
13504 \newline
13505 \InsetSpace ~
13506 \InsetSpace ~
13507 \InsetSpace ~
13508 \InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 \InsetSpace ~
13512 \InsetSpace ~
13513 MCLK =
13514  1; 
13515 \newline
13516 \InsetSpace ~
13517 \InsetSpace ~
13518 \InsetSpace ~
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 \InsetSpace ~
13523 \InsetSpace ~
13524 /* _asm nop _endasm; */\InsetSpace ~
13525 \InsetSpace ~
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 \InsetSpace ~
13529 \InsetSpace ~
13530 \InsetSpace ~
13531 \InsetSpace ~
13532 /* for slow peripherals */
13533 \newline
13534 \InsetSpace ~
13535 \InsetSpace ~
13536 \InsetSpace ~
13537 \InsetSpace ~
13538 \InsetSpace ~
13539 \InsetSpace ~
13540 \InsetSpace ~
13541 \InsetSpace ~
13542 if(MISO) 
13543 \newline
13544 \InsetSpace ~
13545 \InsetSpace ~
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 \InsetSpace ~
13550 \InsetSpace ~
13551 \InsetSpace ~
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 out_byte +=
13557  1; 
13558 \newline
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 \InsetSpace ~
13564 \InsetSpace ~
13565 \InsetSpace ~
13566 \InsetSpace ~
13567 MCLK = 0; 
13568 \newline
13569 \InsetSpace ~
13570 \InsetSpace ~
13571 \InsetSpace ~
13572 \InsetSpace ~
13573 } while(--i);
13574 \newline
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 \InsetSpace ~
13578 \InsetSpace ~
13579 return out_byte; 
13580 \newline
13581 }
13582 \end_layout
13583
13584 \begin_layout Standard
13585 Then, someplace in the code for the first hardware you would use
13586 \end_layout
13587
13588 \begin_layout Verse
13589
13590 \family typewriter
13591 __bit __at
13592 \begin_inset LatexCommand \index{at}
13593
13594 \end_inset
13595
13596
13597 \begin_inset LatexCommand \index{\_\_at}
13598
13599 \end_inset
13600
13601  (0x80) MOSI;\InsetSpace ~
13602 \InsetSpace ~
13603 \InsetSpace ~
13604 \InsetSpace ~
13605 /* I/O port 0, bit 0 */
13606 \newline
13607 __bit __at (0x81) MISO;\InsetSpace ~
13608 \InsetSpace ~
13609 \InsetSpace ~
13610 \InsetSpace ~
13611 /* I/O port 0,
13612  bit 1 */
13613 \newline
13614 __bit __at (0x82) MCLK;\InsetSpace ~
13615 \InsetSpace ~
13616 \InsetSpace ~
13617 \InsetSpace ~
13618 /* I/O port 0, bit 2 */
13619 \end_layout
13620
13621 \begin_layout Standard
13622 Similarly, for the second hardware you would use
13623 \end_layout
13624
13625 \begin_layout Verse
13626
13627 \family typewriter
13628 __bit __at (0x83) MOSI;\InsetSpace ~
13629 \InsetSpace ~
13630 \InsetSpace ~
13631 \InsetSpace ~
13632 /* I/O port 0, bit 3 */
13633 \newline
13634 __bit __at (0x91) MISO;\InsetSpace ~
13635 \InsetSpace ~
13636 \InsetSpace ~
13637 \InsetSpace ~
13638 /*
13639  I/O port 1, bit 1 */
13640 \newline
13641 __bit
13642 \begin_inset LatexCommand \index{bit}
13643
13644 \end_inset
13645
13646  __at (0x92) MCLK;\InsetSpace ~
13647 \InsetSpace ~
13648 \InsetSpace ~
13649 \InsetSpace ~
13650 /* I/O port 1, bit 2 */
13651 \end_layout
13652
13653 \begin_layout Standard
13654 and you can use the same hardware dependent routine without changes, as
13655  for example in a library.
13656  This is somehow similar to sbit, but only one absolute address has to be
13657  specified in the whole project.
13658 \begin_inset VSpace bigskip
13659 \end_inset
13660
13661
13662 \end_layout
13663
13664 \begin_layout Section
13665 Parameters
13666 \begin_inset LatexCommand \index{Parameters}
13667
13668 \end_inset
13669
13670
13671 \begin_inset LatexCommand \index{function parameter}
13672
13673 \end_inset
13674
13675  & Local Variables
13676 \begin_inset LatexCommand \index{local variables}
13677
13678 \end_inset
13679
13680
13681 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13682
13683 \end_inset
13684
13685
13686 \end_layout
13687
13688 \begin_layout Standard
13689 Automatic (local) variables and parameters to functions can either be placed
13690  on the stack or in data-space.
13691  The default action of the compiler is to place these variables in the internal
13692  RAM (for small model) or external RAM (for medium or large model).
13693  This in fact makes them similar to 
13694 \emph on
13695 static
13696 \begin_inset LatexCommand \index{static}
13697
13698 \end_inset
13699
13700
13701 \emph default
13702  so by default functions are non-reentrant
13703 \begin_inset LatexCommand \index{reentrant}
13704
13705 \end_inset
13706
13707 .
13708  
13709 \newline
13710
13711 \newline
13712 They can be placed on the stack
13713 \begin_inset LatexCommand \index{stack}
13714
13715 \end_inset
13716
13717  by using the
13718 \emph on
13719  -
13720 \begin_inset ERT
13721 status collapsed
13722
13723 \begin_layout Standard
13724
13725
13726 \backslash
13727 /
13728 \end_layout
13729
13730 \end_inset
13731
13732 -stack-auto
13733 \begin_inset LatexCommand \index{-\/-stack-auto}
13734
13735 \end_inset
13736
13737
13738 \emph default
13739  option, by using 
13740 \emph on
13741 #pragma\InsetSpace ~
13742 stackauto
13743 \emph default
13744
13745 \begin_inset LatexCommand \index{\#pragma stackauto}
13746
13747 \end_inset
13748
13749  or by using the 
13750 \emph on
13751 reentrant
13752 \begin_inset LatexCommand \index{reentrant}
13753
13754 \end_inset
13755
13756
13757 \emph default
13758  keyword in the function declaration, e.g.:
13759 \end_layout
13760
13761 \begin_layout Verse
13762
13763 \family typewriter
13764 unsigned char foo(char i) __reentrant 
13765 \newline
13766
13767 \newline
13768 \InsetSpace ~
13769 \InsetSpace ~
13770 \InsetSpace ~
13771 \InsetSpace ~
13772 ...
13773  
13774 \newline
13775 }
13776 \end_layout
13777
13778 \begin_layout Standard
13779 Since stack space on 8051 is limited, the 
13780 \emph on
13781 reentrant 
13782 \emph default
13783 keyword or the
13784 \emph on
13785  -
13786 \begin_inset ERT
13787 status collapsed
13788
13789 \begin_layout Standard
13790
13791
13792 \backslash
13793 /
13794 \end_layout
13795
13796 \end_inset
13797
13798 -stack-auto
13799 \emph default
13800  option should be used sparingly.
13801  Note that the reentrant keyword just means that the parameters & local
13802  variables will be allocated to the stack, it 
13803 \emph on
13804 does not
13805 \emph default
13806  mean that the function is register bank
13807 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13808
13809 \end_inset
13810
13811  independent.
13812 \newline
13813
13814 \newline
13815 Local variables
13816 \begin_inset LatexCommand \index{local variables}
13817
13818 \end_inset
13819
13820  can be assigned storage classes and absolute
13821 \begin_inset LatexCommand \index{Absolute addressing}
13822
13823 \end_inset
13824
13825  addresses, e.g.: 
13826 \end_layout
13827
13828 \begin_layout Verse
13829
13830 \family typewriter
13831 unsigned char foo() 
13832 \newline
13833 {
13834 \newline
13835 \InsetSpace ~
13836 \InsetSpace ~
13837 \InsetSpace ~
13838 \InsetSpace ~
13839 __xdata unsigned char i;
13840 \newline
13841 \InsetSpace ~
13842 \InsetSpace ~
13843 \InsetSpace ~
13844 \InsetSpace ~
13845 __bit bvar;
13846 \newline
13847 \InsetSpace ~
13848 \InsetSpace ~
13849 \InsetSpace ~
13850 \InsetSpace ~
13851 __data __at
13852 \begin_inset LatexCommand \index{at}
13853
13854 \end_inset
13855
13856  (0x31) unsigned char j;
13857 \newline
13858 \InsetSpace ~
13859 \InsetSpace ~
13860 \InsetSpace ~
13861 \InsetSpace ~
13862 ...
13863  
13864 \newline
13865 }
13866 \end_layout
13867
13868 \begin_layout Standard
13869 In the above example the variable 
13870 \emph on
13871 i
13872 \emph default
13873  will be allocated in the external ram, 
13874 \emph on
13875 bvar
13876 \emph default
13877  in bit addressable space and
13878 \emph on
13879  j
13880 \emph default
13881  in internal ram.
13882  When compiled with 
13883 \emph on
13884 -
13885 \begin_inset ERT
13886 status collapsed
13887
13888 \begin_layout Standard
13889
13890
13891 \backslash
13892 /
13893 \end_layout
13894
13895 \end_inset
13896
13897 -stack-auto
13898 \emph default
13899  or when a function is declared as 
13900 \emph on
13901 reentrant
13902 \emph default
13903  this should only be done for static variables.
13904 \end_layout
13905
13906 \begin_layout Standard
13907 Parameters
13908 \begin_inset LatexCommand \index{function parameter}
13909
13910 \end_inset
13911
13912  however are not allowed any storage class
13913 \begin_inset LatexCommand \index{Storage class}
13914
13915 \end_inset
13916
13917 , (storage classes for parameters will be ignored), their allocation is
13918  governed by the memory model in use, and the reentrancy options.
13919 \end_layout
13920
13921 \begin_layout Standard
13922 It is however allowed to use bit parameters in reentrant functions and also
13923  non-static local bit variables are supported.
13924  Efficient use is limited to 8 semi-bitregisters in bit space.
13925  They are pushed and popped to stack
13926 \begin_inset LatexCommand \index{stack}
13927
13928 \end_inset
13929
13930  as a single byte just like the normal registers.
13931 \end_layout
13932
13933 \begin_layout Section
13934 Overlaying
13935 \begin_inset LatexCommand \label{sub:Overlaying}
13936
13937 \end_inset
13938
13939
13940 \begin_inset LatexCommand \index{Overlaying}
13941
13942 \end_inset
13943
13944
13945 \end_layout
13946
13947 \begin_layout Standard
13948 For non-reentrant
13949 \begin_inset LatexCommand \index{reentrant}
13950
13951 \end_inset
13952
13953  functions SDCC will try to reduce internal ram space usage by overlaying
13954  parameters and local variables of a function (if possible).
13955  Parameters and local variables
13956 \begin_inset LatexCommand \index{local variables}
13957
13958 \end_inset
13959
13960  of a function will be allocated to an overlayable segment if the function
13961  has 
13962 \emph on
13963 no other function calls and the function is non-reentrant and the memory
13964  model
13965 \begin_inset LatexCommand \index{Memory model}
13966
13967 \end_inset
13968
13969  is small.
13970
13971 \emph default
13972  If an explicit storage class
13973 \begin_inset LatexCommand \index{Storage class}
13974
13975 \end_inset
13976
13977  is specified for a local variable, it will NOT be overlayed.
13978 \end_layout
13979
13980 \begin_layout Standard
13981 Note that the compiler (not the linkage editor) makes the decision for overlayin
13982 g the data items.
13983  Functions that are called from an interrupt service routine
13984 \begin_inset Marginal
13985 status collapsed
13986
13987 \begin_layout Standard
13988
13989 \series bold
13990 !
13991 \end_layout
13992
13993 \end_inset
13994
13995  should be preceded by a #pragma\InsetSpace ~
13996 nooverlay
13997 \begin_inset LatexCommand \index{\#pragma nooverlay}
13998
13999 \end_inset
14000
14001  if they are not reentrant.
14002 \end_layout
14003
14004 \begin_layout Standard
14005 Also note that the compiler does not do any processing of inline assembler
14006  code, so the compiler might incorrectly assign local variables and parameters
14007  of a function into the overlay segment if the inline assembler code calls
14008  other c-functions that might use the overlay.
14009  In that case the #pragma\InsetSpace ~
14010 nooverlay should be used.
14011 \end_layout
14012
14013 \begin_layout Standard
14014 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14015 tion
14016 \begin_inset LatexCommand \index{Multiplication}
14017
14018 \end_inset
14019
14020  or division
14021 \begin_inset LatexCommand \index{Division}
14022
14023 \end_inset
14024
14025  will NOT be overlayed since these are implemented using external functions,
14026  e.g.:
14027 \end_layout
14028
14029 \begin_layout Verse
14030
14031 \family typewriter
14032 #pragma save 
14033 \newline
14034 #pragma nooverlay
14035 \begin_inset LatexCommand \index{\#pragma nooverlay}
14036
14037 \end_inset
14038
14039  
14040 \newline
14041 void set_error(unsigned char errcd) 
14042 \newline
14043 {
14044 \newline
14045 \InsetSpace ~
14046 \InsetSpace ~
14047 \InsetSpace ~
14048 \InsetSpace ~
14049 P3 = errcd;
14050 \newline
14051
14052 \newline
14053 #pragma restore 
14054 \newline
14055
14056 \newline
14057 void
14058  some_isr () __interrupt
14059 \begin_inset LatexCommand \index{interrupt}
14060
14061 \end_inset
14062
14063  (2)
14064 \newline
14065 {
14066 \newline
14067 \InsetSpace ~
14068 \InsetSpace ~
14069 \InsetSpace ~
14070 \InsetSpace ~
14071 ...
14072 \newline
14073 \InsetSpace ~
14074 \InsetSpace ~
14075 \InsetSpace ~
14076 \InsetSpace ~
14077 set_error(10);
14078 \newline
14079 \InsetSpace ~
14080 \InsetSpace ~
14081 \InsetSpace ~
14082 \InsetSpace ~
14083 ...
14084  
14085 \newline
14086 }
14087 \end_layout
14088
14089 \begin_layout Standard
14090 In the above example the parameter 
14091 \emph on
14092 errcd
14093 \emph default
14094  for the function 
14095 \emph on
14096 set_error
14097 \emph default
14098  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14099 nooverlay was
14100  not present, this could cause unpredictable runtime behavior when called
14101  from an interrupt service routine.
14102  The #pragma\InsetSpace ~
14103 nooverlay ensures that the parameters and local variables for
14104  the function are NOT overlayed.
14105 \begin_inset VSpace bigskip
14106 \end_inset
14107
14108
14109 \end_layout
14110
14111 \begin_layout Section
14112 Interrupt Service Routines
14113 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14114
14115 \end_inset
14116
14117
14118 \end_layout
14119
14120 \begin_layout Subsection
14121 General Information
14122 \end_layout
14123
14124 \begin_layout Standard
14125 SDCC allows 
14126 \emph on
14127 i
14128 \emph default
14129 nterrupt 
14130 \emph on
14131 s
14132 \emph default
14133 ervice 
14134 \emph on
14135 r
14136 \emph default
14137 outines to be coded in C, with some extended keywords.
14138 \end_layout
14139
14140 \begin_layout Verse
14141
14142 \family typewriter
14143 void timer_isr (void) __interrupt (1) __using (1) 
14144 \newline
14145
14146 \newline
14147 \InsetSpace ~
14148 \InsetSpace ~
14149 \InsetSpace ~
14150 \InsetSpace ~
14151 ...
14152  
14153 \newline
14154 }
14155 \end_layout
14156
14157 \begin_layout Standard
14158 The optional number following the 
14159 \emph on
14160 interrupt
14161 \begin_inset LatexCommand \index{interrupt}
14162
14163 \end_inset
14164
14165
14166 \begin_inset LatexCommand \index{\_\_interrupt}
14167
14168 \end_inset
14169
14170
14171 \emph default
14172  keyword is the interrupt number this routine will service.
14173  When present, the compiler will insert a call to this routine in the interrupt
14174  vector table
14175 \begin_inset LatexCommand \index{interrupt vector table}
14176
14177 \end_inset
14178
14179  for the interrupt number specified.
14180  If you have multiple source files in your project, interrupt service routines
14181  can be present in any of them, but a prototype of the isr MUST be present
14182  or included in the file that contains the function 
14183 \emph on
14184 main
14185 \emph default
14186 .
14187  The optional (8051 specific) keyword 
14188 \emph on
14189 using
14190 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14191
14192 \end_inset
14193
14194
14195 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14196
14197 \end_inset
14198
14199
14200 \emph default
14201  can be used to tell the compiler to use the specified register bank when
14202  generating code for this function.
14203  
14204 \newline
14205 Interrupt service routines open the door for some very interesting bugs:
14206 \end_layout
14207
14208 \begin_layout Subsubsection
14209 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14210
14211 \end_inset
14212
14213 Common interrupt pitfall: variable not declared 
14214 \emph on
14215 volatile
14216 \end_layout
14217
14218 \begin_layout Standard
14219 If an interrupt service routine changes variables which are accessed by
14220  other functions these variables have to be declared 
14221 \emph on
14222 volatile
14223 \emph default
14224
14225 \begin_inset LatexCommand \index{volatile}
14226
14227 \end_inset
14228
14229 .
14230  See 
14231 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14232
14233 \end_inset
14234
14235  .
14236 \end_layout
14237
14238 \begin_layout Subsubsection
14239 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14240
14241 \end_inset
14242
14243 Common interrupt pitfall: 
14244 \emph on
14245 non-atomic access
14246 \end_layout
14247
14248 \begin_layout Standard
14249 If the access to these variables is not 
14250 \emph on
14251 atomic
14252 \begin_inset LatexCommand \index{atomic}
14253
14254 \end_inset
14255
14256
14257 \emph default
14258  (i.e.
14259  the processor needs more than one instruction for the access and could
14260  be interrupted while accessing the variable) the interrupt must be disabled
14261  during the access to avoid inconsistent data.
14262  
14263 \newline
14264 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14265  and should be protected by disabling interrupts.
14266  You're not automatically on the safe side if you use 8 bit variables though.
14267  We need an example here: f.e.
14268  on the 8051 the harmless looking 
14269 \begin_inset Quotes srd
14270 \end_inset
14271
14272
14273 \family typewriter
14274 flags\InsetSpace ~
14275 |=\InsetSpace ~
14276 0x80;
14277 \family default
14278
14279 \begin_inset Quotes sld
14280 \end_inset
14281
14282  is not atomic if 
14283 \family typewriter
14284 flags
14285 \family default
14286  resides in xdata.
14287  Setting 
14288 \begin_inset Quotes srd
14289 \end_inset
14290
14291
14292 \family typewriter
14293 flags\InsetSpace ~
14294 |=\InsetSpace ~
14295 0x40;
14296 \family default
14297
14298 \begin_inset Quotes sld
14299 \end_inset
14300
14301  from within an interrupt routine might get lost if the interrupt occurs
14302  at the wrong time.
14303  
14304 \begin_inset Quotes sld
14305 \end_inset
14306
14307
14308 \family typewriter
14309 counter\InsetSpace ~
14310 +=\InsetSpace ~
14311 8;
14312 \family default
14313
14314 \begin_inset Quotes srd
14315 \end_inset
14316
14317  is not atomic on the 8051 even if 
14318 \family typewriter
14319 counter
14320 \family default
14321  is located in data memory.
14322 \newline
14323 Bugs like these are hard to reproduce and can
14324  cause a lot of trouble.
14325  
14326 \end_layout
14327
14328 \begin_layout Subsubsection
14329 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14330
14331 \end_inset
14332
14333 Common interrupt pitfall: 
14334 \emph on
14335 stack overflow
14336 \end_layout
14337
14338 \begin_layout Standard
14339 The return address and the registers used in the interrupt service routine
14340  are saved on the stack
14341 \begin_inset LatexCommand \index{stack}
14342
14343 \end_inset
14344
14345  so there must be sufficient stack space.
14346  If there isn't variables or registers (or even the return address itself)
14347  will be corrupted.
14348  This 
14349 \emph on
14350 stack overflow
14351 \emph default
14352
14353 \begin_inset LatexCommand \index{stack overflow}
14354
14355 \end_inset
14356
14357  is most likely to happen if the interrupt occurs during the 
14358 \begin_inset Quotes sld
14359 \end_inset
14360
14361 deepest
14362 \begin_inset Quotes srd
14363 \end_inset
14364
14365  subroutine when the stack is already in use for f.e.
14366  many return addresses.
14367 \end_layout
14368
14369 \begin_layout Subsubsection
14370 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14371
14372 \end_inset
14373
14374 Common interrupt pitfall: 
14375 \emph on
14376 use of non-reentrant functions
14377 \end_layout
14378
14379 \begin_layout Standard
14380 A special note here, int (16 bit) and long (32 bit) integer division
14381 \begin_inset LatexCommand \index{Division}
14382
14383 \end_inset
14384
14385 , multiplication
14386 \begin_inset LatexCommand \index{Multiplication}
14387
14388 \end_inset
14389
14390  & modulus
14391 \begin_inset LatexCommand \index{Modulus}
14392
14393 \end_inset
14394
14395  and floating-point
14396 \begin_inset LatexCommand \index{Floating point support}
14397
14398 \end_inset
14399
14400  operations are implemented using external support routines.
14401  If an interrupt service routine needs to do any of these operations then
14402  the support routines (as mentioned in a following section) will have to
14403  be recompiled using the
14404 \emph on
14405  -
14406 \begin_inset ERT
14407 status collapsed
14408
14409 \begin_layout Standard
14410
14411
14412 \backslash
14413 /
14414 \end_layout
14415
14416 \end_inset
14417
14418 -stack-auto
14419 \begin_inset LatexCommand \index{-\/-stack-auto}
14420
14421 \end_inset
14422
14423
14424 \emph default
14425  option and the source file will need to be compiled using the 
14426 \emph on
14427 -
14428 \begin_inset ERT
14429 status collapsed
14430
14431 \begin_layout Standard
14432
14433
14434 \backslash
14435 /
14436 \end_layout
14437
14438 \end_inset
14439
14440 -int-long-reent
14441 \emph default
14442
14443 \begin_inset LatexCommand \index{-\/-int-long-reent}
14444
14445 \end_inset
14446
14447  compiler option.
14448  
14449 \newline
14450 Note, the type promotion
14451 \begin_inset LatexCommand \index{type promotion}
14452
14453 \end_inset
14454
14455  required by ANSI C can cause 16 bit routines to be used
14456 \begin_inset Marginal
14457 status collapsed
14458
14459 \begin_layout Standard
14460
14461 \series bold
14462 \InsetSpace ~
14463 !
14464 \end_layout
14465
14466 \end_inset
14467
14468  without the programmer being aware of it.
14469  See f.e.
14470  the cast 
14471 \family typewriter
14472 (unsigned char)(tail-1)
14473 \family default
14474  within the if clause in section 
14475 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14476
14477 \end_inset
14478
14479 .
14480 \end_layout
14481
14482 \begin_layout Standard
14483 Calling other functions from an interrupt service routine is not recommended,
14484  avoid it if possible.
14485  Note that when some function is called from an interrupt service routine
14486  it should be preceded by a #pragma\InsetSpace ~
14487 nooverlay
14488 \begin_inset LatexCommand \index{\#pragma nooverlay}
14489
14490 \end_inset
14491
14492  if it is not reentrant.
14493  Furthermore nonreentrant functions should not be called from the main program
14494  while the interrupt service routine might be active.
14495  They also must not be called from low priority interrupt service routines
14496  while a high priority interrupt service routine might be active.
14497  You could use semaphores or make the function
14498 \emph on
14499  critical
14500 \emph default
14501  if all parameters are passed in registers.
14502 \newline
14503  Also see section 
14504 \begin_inset LatexCommand \ref{sub:Overlaying}
14505
14506 \end_inset
14507
14508 \InsetSpace ~
14509 about Overlaying and section 
14510 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14511
14512 \end_inset
14513
14514 \InsetSpace ~
14515 about Functions using private register banks.
14516 \begin_inset VSpace bigskip
14517 \end_inset
14518
14519
14520 \end_layout
14521
14522 \begin_layout Subsection
14523 MCS51/DS390 Interrupt Service Routines
14524 \end_layout
14525
14526 \begin_layout Standard
14527 Interrupt
14528 \begin_inset LatexCommand \index{interrupt}
14529
14530 \end_inset
14531
14532  numbers and the corresponding address & descriptions for the Standard 8051/8052
14533  are listed below.
14534  SDCC will automatically adjust the 
14535 \begin_inset LatexCommand \index{interrupt vector table}
14536
14537 \end_inset
14538
14539  to the maximum interrupt number specified.
14540 \newline
14541
14542 \end_layout
14543
14544 \begin_layout Standard
14545 \align center
14546 \begin_inset Tabular
14547 <lyxtabular version="3" rows="9" columns="3">
14548 <features>
14549 <column alignment="center" valignment="top" leftline="true" width="0in">
14550 <column alignment="left" valignment="top" leftline="true" width="0in">
14551 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14552 <row topline="true" bottomline="true">
14553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14554 \begin_inset Text
14555
14556 \begin_layout Standard
14557 Interrupt #
14558 \end_layout
14559
14560 \end_inset
14561 </cell>
14562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14563 \begin_inset Text
14564
14565 \begin_layout Standard
14566 Description
14567 \end_layout
14568
14569 \end_inset
14570 </cell>
14571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14572 \begin_inset Text
14573
14574 \begin_layout Standard
14575 Vector Address
14576 \end_layout
14577
14578 \end_inset
14579 </cell>
14580 </row>
14581 <row topline="true">
14582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14583 \begin_inset Text
14584
14585 \begin_layout Standard
14586 0
14587 \end_layout
14588
14589 \end_inset
14590 </cell>
14591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14592 \begin_inset Text
14593
14594 \begin_layout Standard
14595 External 0
14596 \end_layout
14597
14598 \end_inset
14599 </cell>
14600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14601 \begin_inset Text
14602
14603 \begin_layout Standard
14604 0x0003
14605 \end_layout
14606
14607 \end_inset
14608 </cell>
14609 </row>
14610 <row topline="true">
14611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14612 \begin_inset Text
14613
14614 \begin_layout Standard
14615 1
14616 \end_layout
14617
14618 \end_inset
14619 </cell>
14620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14621 \begin_inset Text
14622
14623 \begin_layout Standard
14624 Timer 0
14625 \end_layout
14626
14627 \end_inset
14628 </cell>
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14630 \begin_inset Text
14631
14632 \begin_layout Standard
14633 0x000b
14634 \end_layout
14635
14636 \end_inset
14637 </cell>
14638 </row>
14639 <row topline="true">
14640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14641 \begin_inset Text
14642
14643 \begin_layout Standard
14644 2
14645 \end_layout
14646
14647 \end_inset
14648 </cell>
14649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14650 \begin_inset Text
14651
14652 \begin_layout Standard
14653 External 1
14654 \end_layout
14655
14656 \end_inset
14657 </cell>
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14659 \begin_inset Text
14660
14661 \begin_layout Standard
14662 0x0013
14663 \end_layout
14664
14665 \end_inset
14666 </cell>
14667 </row>
14668 <row topline="true">
14669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14670 \begin_inset Text
14671
14672 \begin_layout Standard
14673 3
14674 \end_layout
14675
14676 \end_inset
14677 </cell>
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14679 \begin_inset Text
14680
14681 \begin_layout Standard
14682 Timer 1
14683 \end_layout
14684
14685 \end_inset
14686 </cell>
14687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14688 \begin_inset Text
14689
14690 \begin_layout Standard
14691 0x001b
14692 \end_layout
14693
14694 \end_inset
14695 </cell>
14696 </row>
14697 <row topline="true">
14698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14699 \begin_inset Text
14700
14701 \begin_layout Standard
14702 4
14703 \end_layout
14704
14705 \end_inset
14706 </cell>
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14708 \begin_inset Text
14709
14710 \begin_layout Standard
14711 Serial
14712 \end_layout
14713
14714 \end_inset
14715 </cell>
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14717 \begin_inset Text
14718
14719 \begin_layout Standard
14720 0x0023
14721 \end_layout
14722
14723 \end_inset
14724 </cell>
14725 </row>
14726 <row topline="true">
14727 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14728 \begin_inset Text
14729
14730 \begin_layout Standard
14731 5
14732 \end_layout
14733
14734 \end_inset
14735 </cell>
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14737 \begin_inset Text
14738
14739 \begin_layout Standard
14740 Timer 2 (8052)
14741 \end_layout
14742
14743 \end_inset
14744 </cell>
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14746 \begin_inset Text
14747
14748 \begin_layout Standard
14749 0x002b
14750 \end_layout
14751
14752 \end_inset
14753 </cell>
14754 </row>
14755 <row topline="true">
14756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14757 \begin_inset Text
14758
14759 \begin_layout Standard
14760 ...
14761 \end_layout
14762
14763 \end_inset
14764 </cell>
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14766 \begin_inset Text
14767
14768 \begin_layout Standard
14769
14770 \end_layout
14771
14772 \end_inset
14773 </cell>
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14775 \begin_inset Text
14776
14777 \begin_layout Standard
14778 ...
14779 \end_layout
14780
14781 \end_inset
14782 </cell>
14783 </row>
14784 <row topline="true" bottomline="true">
14785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14786 \begin_inset Text
14787
14788 \begin_layout Standard
14789 n
14790 \end_layout
14791
14792 \end_inset
14793 </cell>
14794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14795 \begin_inset Text
14796
14797 \begin_layout Standard
14798
14799 \end_layout
14800
14801 \end_inset
14802 </cell>
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14804 \begin_inset Text
14805
14806 \begin_layout Standard
14807 0x0003 + 8*n
14808 \end_layout
14809
14810 \end_inset
14811 </cell>
14812 </row>
14813 </lyxtabular>
14814
14815 \end_inset
14816
14817
14818 \newline
14819
14820 \end_layout
14821
14822 \begin_layout Standard
14823 If the interrupt service routine is defined without 
14824 \emph on
14825 using
14826 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14827
14828 \end_inset
14829
14830
14831 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14832
14833 \end_inset
14834
14835
14836 \emph default
14837  a register bank or with register bank 0 (
14838 \emph on
14839 using
14840 \emph default
14841  0), the compiler will save the registers used by itself on the stack upon
14842  entry and restore them at exit, however if such an interrupt service routine
14843  calls another function then the entire register bank will be saved on the
14844  stack.
14845  This scheme may be advantageous for small interrupt service routines which
14846  have low register usage.
14847 \end_layout
14848
14849 \begin_layout Standard
14850 If the interrupt service routine is defined to be using a specific register
14851  bank then only 
14852 \emph on
14853 a, b, dptr
14854 \emph default
14855  & psw are saved and restored, if such an interrupt service routine calls
14856  another function (using another register bank) then the entire register
14857  bank of the called function will be saved on the stack
14858 \begin_inset LatexCommand \index{stack}
14859
14860 \end_inset
14861
14862 .
14863  This scheme is recommended for larger interrupt service routines.
14864 \begin_inset VSpace bigskip
14865 \end_inset
14866
14867
14868 \end_layout
14869
14870 \begin_layout Subsection
14871 HC08
14872 \begin_inset LatexCommand \index{HC08}
14873
14874 \end_inset
14875
14876  Interrupt Service Routines
14877 \end_layout
14878
14879 \begin_layout Standard
14880 Since the number of interrupts
14881 \begin_inset LatexCommand \index{HC08!interrupt}
14882
14883 \end_inset
14884
14885  available is chip specific and the interrupt vector table always ends at
14886  the last byte of memory, the interrupt numbers corresponds to the interrupt
14887  vectors in reverse order of address.
14888  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14889  2 will use the interrupt vector at 0xfffa, and so on.
14890  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14891  this way; instead see section 
14892 \begin_inset LatexCommand \ref{sub:Startup-Code}
14893
14894 \end_inset
14895
14896  for details on customizing startup.
14897 \begin_inset VSpace bigskip
14898 \end_inset
14899
14900
14901 \end_layout
14902
14903 \begin_layout Subsection
14904 Z80 Interrupt Service Routines
14905 \end_layout
14906
14907 \begin_layout Standard
14908 The Z80
14909 \begin_inset LatexCommand \index{Z80}
14910
14911 \end_inset
14912
14913  uses several different methods for determining the correct interrupt
14914 \begin_inset LatexCommand \index{Z80!interrupt}
14915
14916 \end_inset
14917
14918  vector depending on the hardware implementation.
14919  Therefore, SDCC ignores the optional interrupt number and does not attempt
14920  to generate an interrupt vector table.
14921 \end_layout
14922
14923 \begin_layout Standard
14924 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14925  instruction to return from the interrupt.
14926  To write an interrupt handler for the non-maskable interrupt, which needs
14927  a RETN instruction instead, add the 
14928 \emph on
14929 critical
14930 \emph default
14931  keyword:
14932 \end_layout
14933
14934 \begin_layout Verse
14935
14936 \family typewriter
14937 void nmi_isr (void) critical interrupt
14938 \newline
14939
14940 \newline
14941 \InsetSpace ~
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 ...
14946  
14947 \newline
14948 }
14949 \end_layout
14950
14951 \begin_layout Standard
14952 However if you need to create a non-interruptable interrupt service routine
14953  you would also require the 
14954 \emph on
14955 critical
14956 \emph default
14957  keyword.
14958  To distinguish between this and an nmi_isr you must provide an interrupt
14959  number.
14960 \begin_inset VSpace bigskip
14961 \end_inset
14962
14963
14964 \end_layout
14965
14966 \begin_layout Section
14967 Enabling and Disabling Interrupts
14968 \end_layout
14969
14970 \begin_layout Subsection
14971 Critical Functions and Critical Statements
14972 \end_layout
14973
14974 \begin_layout Standard
14975 A special keyword may be associated with a block or a function declaring
14976  it as 
14977 \emph on
14978 critical
14979 \emph default
14980 .
14981  SDCC will generate code to disable all interrupts
14982 \begin_inset LatexCommand \index{interrupt}
14983
14984 \end_inset
14985
14986  upon entry to a critical function and restore the interrupt enable to the
14987  previous state before returning.
14988  Nesting critical functions will need one additional byte on the stack
14989 \begin_inset LatexCommand \index{stack}
14990
14991 \end_inset
14992
14993  for each call.
14994 \end_layout
14995
14996 \begin_layout Verse
14997
14998 \family typewriter
14999 int foo () __critical
15000 \begin_inset LatexCommand \index{critical}
15001
15002 \end_inset
15003
15004
15005 \begin_inset LatexCommand \index{\_\_critical}
15006
15007 \end_inset
15008
15009  
15010 \newline
15011
15012 \newline
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 ...
15018  
15019 \newline
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 ...
15025  
15026 \newline
15027 }
15028 \end_layout
15029
15030 \begin_layout Standard
15031 The critical attribute maybe used with other attributes like 
15032 \emph on
15033 reentrant.
15034 \emph default
15035
15036 \newline
15037 The keyword 
15038 \emph on
15039 critical
15040 \emph default
15041  may also be used to disable interrupts more locally:
15042 \end_layout
15043
15044 \begin_layout Verse
15045
15046 \family typewriter
15047 __critical{ i++; }
15048 \end_layout
15049
15050 \begin_layout Standard
15051 More than one statement could have been included in the block.
15052 \end_layout
15053
15054 \begin_layout Subsection
15055 Enabling and Disabling Interrupts directly
15056 \end_layout
15057
15058 \begin_layout Standard
15059 Interrupts
15060 \begin_inset LatexCommand \index{interrupt}
15061
15062 \end_inset
15063
15064  can also be disabled and enabled directly (8051):
15065 \end_layout
15066
15067 \begin_layout Verse
15068
15069 \family typewriter
15070 EA = 0;\InsetSpace ~
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 \InsetSpace ~
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 or:\InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 \InsetSpace ~
15093 EA_SAVE = EA;
15094 \end_layout
15095
15096 \begin_layout Verse
15097
15098 \family typewriter
15099 ...\InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 \InsetSpace ~
15104 \InsetSpace ~
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 \InsetSpace ~
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 \InsetSpace ~
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 EA = 0;
15130 \end_layout
15131
15132 \begin_layout Verse
15133
15134 \family typewriter
15135 EA = 1;\InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 \InsetSpace ~
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 ...
15162 \end_layout
15163
15164 \begin_layout Verse
15165
15166 \family typewriter
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 \InsetSpace ~
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 \InsetSpace ~
15188 \InsetSpace ~
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 \InsetSpace ~
15193 \InsetSpace ~
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 EA = EA_SAVE;
15201 \end_layout
15202
15203 \begin_layout Standard
15204 On other architectures which have seperate opcodes for enabling and disabling
15205  interrupts you might want to make use of defines with inline assembly
15206 \begin_inset LatexCommand \index{Assembler routines}
15207
15208 \end_inset
15209
15210  (HC08
15211 \begin_inset LatexCommand \index{HC08!interrupt}
15212
15213 \end_inset
15214
15215 ):
15216 \end_layout
15217
15218 \begin_layout Verse
15219
15220 \family typewriter
15221 #define CLI _asm
15222 \begin_inset LatexCommand \index{\_asm}
15223
15224 \end_inset
15225
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 cli\InsetSpace ~
15229 \InsetSpace ~
15230 _endasm
15231 \begin_inset LatexCommand \index{\_endasm}
15232
15233 \end_inset
15234
15235
15236 \end_layout
15237
15238 \begin_layout Verse
15239
15240 \family typewriter
15241 #define SEI _asm\InsetSpace ~
15242 \InsetSpace ~
15243 sei\InsetSpace ~
15244 \InsetSpace ~
15245 _endasm; 
15246 \end_layout
15247
15248 \begin_layout Verse
15249
15250 \family typewriter
15251 ...
15252 \end_layout
15253
15254 \begin_layout Standard
15255 Note: it is sometimes sufficient to disable only a specific interrupt source
15256  like f.e.
15257  a timer or serial interrupt by manipulating an 
15258 \emph on
15259 interrupt mask
15260 \begin_inset LatexCommand \index{interrupt mask}
15261
15262 \end_inset
15263
15264
15265 \emph default
15266  register.
15267  
15268 \end_layout
15269
15270 \begin_layout Standard
15271 Usually the time during which interrupts are disabled should be kept as
15272  short as possible.
15273  This minimizes both 
15274 \emph on
15275 interrupt latency
15276 \emph default
15277
15278 \begin_inset LatexCommand \index{interrupt latency}
15279
15280 \end_inset
15281
15282  (the time between the occurrence of the interrupt and the execution of
15283  the first code in the interrupt routine) and 
15284 \emph on
15285 interrupt jitter
15286 \emph default
15287
15288 \begin_inset LatexCommand \index{interrupt jitter}
15289
15290 \end_inset
15291
15292  (the difference between the shortest and the longest interrupt latency).
15293  These really are something different, f.e.
15294  a serial interrupt has to be served before its buffer overruns so it cares
15295  for the maximum interrupt latency, whereas it does not care about jitter.
15296  On a loudspeaker driven via a digital to analog converter which is fed
15297  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15298  a much smaller jitter will be very audible.
15299 \end_layout
15300
15301 \begin_layout Standard
15302 You can reenable interrupts within an interrupt routine and on some architecture
15303 s you can make use of two (or more) levels of 
15304 \emph on
15305 interrupt priorities
15306 \emph default
15307
15308 \begin_inset LatexCommand \index{interrupt priority}
15309
15310 \end_inset
15311
15312 .
15313  On some architectures which don't support interrupt priorities these can
15314  be implemented by manipulating the interrupt mask and reenabling interrupts
15315  within the interrupt routine.
15316  Check there is sufficient space on the stack
15317 \begin_inset LatexCommand \index{stack}
15318
15319 \end_inset
15320
15321  and don't add complexity unless you have to.
15322  
15323 \end_layout
15324
15325 \begin_layout Subsection
15326 Semaphore
15327 \begin_inset LatexCommand \index{semaphore}
15328
15329 \end_inset
15330
15331  locking (mcs51/ds390)
15332 \end_layout
15333
15334 \begin_layout Standard
15335 Some architectures (mcs51/ds390) have an atomic
15336 \begin_inset LatexCommand \index{atomic}
15337
15338 \end_inset
15339
15340  bit test and
15341 \emph on
15342  
15343 \emph default
15344 clear
15345 \emph on
15346  
15347 \emph default
15348 instruction.
15349  These type of instructions are typically used in preemptive multitasking
15350  systems, where a routine f.e.
15351  claims the use of a data structure ('acquires a lock
15352 \begin_inset LatexCommand \index{lock}
15353
15354 \end_inset
15355
15356  on it'), makes some modifications and then releases the lock when the data
15357  structure is consistent again.
15358  The instruction may also be used if interrupt and non-interrupt code have
15359  to compete for a resource.
15360  With the atomic bit test and clear instruction interrupts
15361 \begin_inset LatexCommand \index{interrupt}
15362
15363 \end_inset
15364
15365  don't have to be disabled for the locking operation.
15366  
15367 \end_layout
15368
15369 \begin_layout Standard
15370 SDCC generates this instruction if the source follows this pattern:
15371 \end_layout
15372
15373 \begin_layout Verse
15374
15375 \family typewriter
15376 volatile
15377 \begin_inset LatexCommand \index{volatile}
15378
15379 \end_inset
15380
15381  bit resource_is_free; 
15382 \newline
15383
15384 \newline
15385 if (resource_is_free) 
15386 \newline
15387 \InsetSpace ~
15388 \InsetSpace ~
15389
15390 \newline
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 \InsetSpace ~
15395 resource_is_free=0; 
15396 \newline
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 ...
15402  
15403 \newline
15404 \InsetSpace ~
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 resource_is_free=1;
15409 \newline
15410 \InsetSpace ~
15411 \InsetSpace ~
15412
15413 \end_layout
15414
15415 \begin_layout Standard
15416 Note, mcs51 and ds390 support only an atomic
15417 \begin_inset LatexCommand \index{atomic}
15418
15419 \end_inset
15420
15421  bit test and 
15422 \emph on
15423 clear
15424 \emph default
15425  instruction (as opposed to atomic bit test and 
15426 \emph on
15427 set).
15428 \end_layout
15429
15430 \begin_layout Section
15431 Functions using private register banks
15432 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15433
15434 \end_inset
15435
15436  (mcs51/ds390)
15437 \end_layout
15438
15439 \begin_layout Standard
15440 Some architectures have support for quickly changing register sets.
15441  SDCC supports this feature with the 
15442 \emph on
15443 using
15444 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15445
15446 \end_inset
15447
15448
15449 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15450
15451 \end_inset
15452
15453
15454 \emph default
15455  attribute (which tells the compiler to use a register bank
15456 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15457
15458 \end_inset
15459
15460  other than the default bank zero).
15461  It should only be applied to 
15462 \emph on
15463 interrupt
15464 \begin_inset LatexCommand \index{interrupt}
15465
15466 \end_inset
15467
15468
15469 \emph default
15470  functions (see footnote below).
15471  This will in most circumstances make the generated ISR code more efficient
15472  since it will not have to save registers on the stack.
15473 \end_layout
15474
15475 \begin_layout Standard
15476 The 
15477 \emph on
15478 using
15479 \emph default
15480  attribute will have no effect on the generated code for a 
15481 \emph on
15482 non-interrupt
15483 \emph default
15484  function (but may occasionally be useful anyway
15485 \begin_inset Foot
15486 status open
15487
15488 \begin_layout Standard
15489 possible exception: if a function is called ONLY from 'interrupt' functions
15490  using a particular bank, it can be declared with the same 'using' attribute
15491  as the calling 'interrupt' functions.
15492  For instance, if you have several ISRs using bank one, and all of them
15493  call memcpy(), it might make sense to create a specialized version of memcpy()
15494  'using 1', since this would prevent the ISR from having to save bank zero
15495  to the stack on entry and switch to bank zero before calling the function
15496 \end_layout
15497
15498 \end_inset
15499
15500 ).
15501 \newline
15502
15503 \emph on
15504 (pending: Note, nowadays the 
15505 \emph default
15506 using
15507 \emph on
15508  attribute has an effect on
15509 \emph default
15510  
15511 \emph on
15512 the generated code for a 
15513 \emph default
15514 non-interrupt
15515 \emph on
15516  function
15517 \emph default
15518 .
15519 \emph on
15520 )
15521 \end_layout
15522
15523 \begin_layout Standard
15524 An 
15525 \emph on
15526 interrupt
15527 \emph default
15528  function using a non-zero bank will assume that it can trash that register
15529  bank, and will not save it.
15530  Since high-priority interrupts
15531 \begin_inset LatexCommand \index{interrupts}
15532
15533 \end_inset
15534
15535
15536 \begin_inset LatexCommand \index{interrupt priority}
15537
15538 \end_inset
15539
15540  can interrupt low-priority ones on the 8051 and friends, this means that
15541  if a high-priority ISR 
15542 \emph on
15543 using
15544 \emph default
15545  a particular bank occurs while processing a low-priority ISR 
15546 \emph on
15547 using
15548 \emph default
15549  the same bank, terrible and bad things can happen.
15550  To prevent this, no single register bank should be 
15551 \emph on
15552 used
15553 \emph default
15554  by both a high priority and a low priority ISR.
15555  This is probably most easily done by having all high priority ISRs use
15556  one bank and all low priority ISRs use another.
15557  If you have an ISR which can change priority at runtime, you're on your
15558  own: I suggest using the default bank zero and taking the small performance
15559  hit.
15560 \end_layout
15561
15562 \begin_layout Standard
15563 It is most efficient if your ISR calls no other functions.
15564  If your ISR must call other functions, it is most efficient if those functions
15565  use the same bank as the ISR (see note 1 below); the next best is if the
15566  called functions use bank zero.
15567  It is very inefficient to call a function using a different, non-zero bank
15568  from an ISR.
15569  
15570 \begin_inset VSpace bigskip
15571 \end_inset
15572
15573
15574 \end_layout
15575
15576 \begin_layout Section
15577 Startup Code
15578 \begin_inset LatexCommand \label{sub:Startup-Code}
15579
15580 \end_inset
15581
15582
15583 \begin_inset LatexCommand \index{Startup code}
15584
15585 \end_inset
15586
15587
15588 \end_layout
15589
15590 \begin_layout Subsection
15591 MCS51/DS390 Startup Code
15592 \end_layout
15593
15594 \begin_layout Standard
15595 The compiler triggers the linker to link certain initialization modules
15596  from the runtime library
15597 \begin_inset LatexCommand \index{Runtime library}
15598
15599 \end_inset
15600
15601  called crt<something>.
15602  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15603  GSINIT5) is not linked unless the -
15604 \series bold
15605
15606 \begin_inset ERT
15607 status open
15608
15609 \begin_layout Standard
15610
15611
15612 \backslash
15613 /
15614 \end_layout
15615
15616 \end_inset
15617
15618
15619 \series default
15620 -xstack option is used.
15621  These modules are highly entangled by the use of special segments/areas,
15622  but a common layout is shown below:
15623 \end_layout
15624
15625 \begin_layout Verse
15626
15627 \family typewriter
15628 \series bold
15629 \size footnotesize
15630 (main.asm)
15631 \end_layout
15632
15633 \begin_layout Verse
15634
15635 \family typewriter
15636 \size footnotesize
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 \InsetSpace ~
15644 \InsetSpace ~
15645 .area HOME (CODE)
15646 \newline
15647 __interrupt_vect:
15648 \newline
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 \InsetSpace ~
15656 \InsetSpace ~
15657 ljmp __sdcc_gsinit_startup
15658 \end_layout
15659
15660 \begin_layout Verse
15661
15662 \family typewriter
15663 \series bold
15664 \size footnotesize
15665 (crtstart.asm)
15666 \end_layout
15667
15668 \begin_layout Verse
15669
15670 \family typewriter
15671 \size footnotesize
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 .area GSINIT0 (CODE)
15681 \newline
15682 __sdcc_gsinit_startup::
15683 \newline
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 mov sp,#__start__stack - 1
15693 \end_layout
15694
15695 \begin_layout Verse
15696
15697 \family typewriter
15698 \series bold
15699 \size footnotesize
15700 (crtxstack.asm)
15701 \end_layout
15702
15703 \begin_layout Verse
15704
15705 \family typewriter
15706 \size footnotesize
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 .area GSINIT1 (CODE)
15716 \newline
15717 __sdcc_init_xstack::
15718 \newline
15719 ; Need to initialize in GSINIT1 in
15720  case the user's __sdcc_external_startup uses the xstack.
15721 \newline
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 mov __XPAGE,#(__start__x
15731 stack >> 8)
15732 \newline
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 mov _spx,#__start__xstack
15742 \end_layout
15743
15744 \begin_layout Verse
15745
15746 \family typewriter
15747 \series bold
15748 \size footnotesize
15749 (crtstart.asm)
15750 \end_layout
15751
15752 \begin_layout Verse
15753
15754 \family typewriter
15755 \size footnotesize
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 .area GSINIT2 (CODE)
15765 \newline
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 lcall __sdcc_external_startup
15775 \newline
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 mov a,dpl
15785 \newline
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 jz __sdcc_init_data
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 ljmp
15805  __sdcc_program_startup
15806 \newline
15807 __sdcc_init_data:
15808 \end_layout
15809
15810 \begin_layout Verse
15811
15812 \family typewriter
15813 \series bold
15814 \size footnotesize
15815 (crtxinit.asm)
15816 \end_layout
15817
15818 \begin_layout Verse
15819
15820 \family typewriter
15821 \size footnotesize
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 .area GSINIT3 (CODE)
15831 \newline
15832 __mcs51_genXINIT::
15833 \newline
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 mov r1,#l_XINIT
15843 \newline
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 mov a,r1
15853 \newline
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 orl a,#(l_XINIT
15863  >> 8)
15864 \newline
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 jz 00003$
15874 \newline
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 mov r2,#((l_XINIT+255) >> 8)
15884 \newline
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 mov dptr,#s_XINIT
15894 \newline
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 mov r0,#s_XISEG
15904 \newline
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 mov
15914  __XPAGE,#(s_XISEG >> 8)
15915 \newline
15916 00001$:\InsetSpace ~
15917 clr a
15918 \newline
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 movc a,@a+dptr
15928 \newline
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 movx @r0,a
15938 \newline
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 inc dptr
15948 \newline
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 inc
15958  r0
15959 \newline
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 cjne r0,#0,00002$
15969 \newline
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 inc __XPAGE
15979 \newline
15980 00002$:\InsetSpace ~
15981 djnz r1,00001$
15982 \newline
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 djnz r2,00001$
15992 \newline
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 mov __XPAGE,#0
16002 xFF
16003 \newline
16004 00003$:
16005 \end_layout
16006
16007 \begin_layout Verse
16008
16009 \family typewriter
16010 \series bold
16011 \size footnotesize
16012 (crtclear.asm)
16013 \end_layout
16014
16015 \begin_layout Verse
16016
16017 \family typewriter
16018 \size footnotesize
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 .area GSINIT4 (CODE)
16028 \newline
16029 __mcs51_genRAMCLEAR::
16030 \newline
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 clr a
16040 \newline
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 mov r0,#(l_IRAM-1)
16050 \newline
16051 00004$:\InsetSpace ~
16052 mov
16053  @r0,a
16054 \newline
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 \InsetSpace ~
16063 djnz r0,00004$
16064 \newline
16065 ; _mcs51_genRAMCLEAR() end
16066 \end_layout
16067
16068 \begin_layout Verse
16069
16070 \family typewriter
16071 \series bold
16072 \size footnotesize
16073 (crtxclear.asm)
16074 \end_layout
16075
16076 \begin_layout Verse
16077
16078 \family typewriter
16079 \size footnotesize
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 .area GSINIT4 (CODE)
16089 \newline
16090 __mcs51_genXRAMCLEAR::
16091 \newline
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 mov r0,#l_PSEG
16101 \newline
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 mov a,r0
16111 \newline
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 orl a,#(l_PSEG
16121  >> 8)
16122 \newline
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 \InsetSpace ~
16131 jz 00006$
16132 \newline
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 mov r1,#s_PSEG
16142 \newline
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 mov __XPAGE,#(s_PSEG >> 8)
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 clr a
16162 \newline
16163 00005$:\InsetSpace ~
16164 movx
16165  @r1,a
16166 \newline
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 inc r1
16176 \newline
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 djnz r0,00005$
16186 \newline
16187 00006$:
16188 \newline
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 mov r0,#l_XSEG
16198 \newline
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 mov a,r0
16208 \newline
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 orl a,#(l_XSEG >>
16218  8)
16219 \newline
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 jz 00008$
16229 \newline
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 mov r1,#((l_XSEG + 255) >> 8)
16239 \newline
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 mov dptr,#s_XSEG
16249 \newline
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 clr a
16259 \newline
16260 00007$:\InsetSpace ~
16261 movx
16262  @dptr,a
16263 \newline
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 inc dptr
16273 \newline
16274 \InsetSpace ~
16275 \InsetSpace ~
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 djnz r0,00007$
16283 \newline
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 djnz r1,00007$
16293 \newline
16294 00008$:
16295 \end_layout
16296
16297 \begin_layout Verse
16298
16299 \family typewriter
16300 \series bold
16301 \size footnotesize
16302 (crtxstack.asm)
16303 \end_layout
16304
16305 \begin_layout Verse
16306
16307 \family typewriter
16308 \size footnotesize
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 \InsetSpace ~
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 \InsetSpace ~
16317 .area GSINIT5 (CODE)
16318 \newline
16319 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16320  modifies __XPAGE
16321 \newline
16322 ; and __mcs51_genRAMCLEAR modifies _spx.
16323 \newline
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 mov __XPAGE,#(__start__x
16333 stack >> 8)
16334 \newline
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 \InsetSpace ~
16343 mov _spx,#__start__xstack
16344 \end_layout
16345
16346 \begin_layout Verse
16347
16348 \family typewriter
16349 \series bold
16350 \size footnotesize
16351 (application modules)
16352 \end_layout
16353
16354 \begin_layout Verse
16355
16356 \family typewriter
16357 \size footnotesize
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 \InsetSpace ~
16363 \InsetSpace ~
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 .area GSINIT (CODE)
16367 \end_layout
16368
16369 \begin_layout Verse
16370
16371 \family typewriter
16372 \series bold
16373 \size footnotesize
16374 (main.asm)
16375 \end_layout
16376
16377 \begin_layout Verse
16378
16379 \family typewriter
16380 \size footnotesize
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 \InsetSpace ~
16389 .area GSFINAL (CODE)
16390 \newline
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 ljmp __sdcc_program_startup
16400 \newline
16401 ;---------------------------------
16402 -----------------------
16403 \newline
16404 ; Home
16405 \newline
16406 ;--------------------------------------------------
16407 ------
16408 \newline
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 .area HOME (CODE)
16418 \newline
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 .area CSEG (CODE)
16428 \newline
16429 __sdcc_program_startup:
16430 \newline
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 lcall _main
16440 \newline
16441 ;
16442  return from main will lock up
16443 \newline
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 sjmp .
16453 \end_layout
16454
16455 \begin_layout Standard
16456 One of these modules (crtstart.asm) contains a call to the C routine 
16457 \emph on
16458 _sdcc_external_startup()
16459 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16460
16461 \end_inset
16462
16463
16464 \series bold
16465 \emph default
16466  
16467 \series default
16468 at the start of the CODE area.
16469  This routine is also in the runtime library
16470 \begin_inset LatexCommand \index{Runtime library}
16471
16472 \end_inset
16473
16474  and returns 0 by default.
16475  If this routine returns a non-zero value, the static & global variable
16476  initialization will be skipped and the function main will be invoked.
16477  Otherwise static & global variables will be initialized before the function
16478  main is invoked.
16479  You could add an 
16480 \emph on
16481 _sdcc_external_startup()
16482 \emph default
16483  routine to your program to override the default if you need to setup hardware
16484  or perform some other critical operation prior to static & global variable
16485  initialization
16486 \begin_inset LatexCommand \index{Variable initialization}
16487
16488 \end_inset
16489
16490 .
16491  On some mcs51 variants xdata
16492 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16493
16494 \end_inset
16495
16496  memory has to be explicitly enabled before it can be accessed or if the
16497  watchdog
16498 \begin_inset LatexCommand \index{watchdog}
16499
16500 \end_inset
16501
16502  needs to be disabled, this is the place to do it.
16503  The startup code clears all internal data memory, 256 bytes by default,
16504  but from 0 to n-1 if 
16505 \emph on
16506 -
16507 \begin_inset ERT
16508 status collapsed
16509
16510 \begin_layout Standard
16511
16512
16513 \backslash
16514 /
16515 \end_layout
16516
16517 \end_inset
16518
16519 -iram-size
16520 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16521
16522 \end_inset
16523
16524 n
16525 \emph default
16526  is used.
16527  (recommended for Chipcon CC1010).
16528 \end_layout
16529
16530 \begin_layout Standard
16531 See also the compiler options 
16532 \emph on
16533 -
16534 \begin_inset ERT
16535 status collapsed
16536
16537 \begin_layout Standard
16538
16539
16540 \backslash
16541 /
16542 \end_layout
16543
16544 \end_inset
16545
16546 -no-xinit
16547 \emph default
16548 -
16549 \emph on
16550 opt
16551 \emph default
16552
16553 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16554
16555 \end_inset
16556
16557
16558 \emph on
16559 -
16560 \begin_inset ERT
16561 status collapsed
16562
16563 \begin_layout Standard
16564
16565
16566 \backslash
16567 /
16568 \end_layout
16569
16570 \end_inset
16571
16572 -main-return
16573 \emph default
16574
16575 \begin_inset LatexCommand \index{-\/-main-return}
16576
16577 \end_inset
16578
16579  and section 
16580 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16581
16582 \end_inset
16583
16584  about MCS51-variants.
16585 \newline
16586
16587 \end_layout
16588
16589 \begin_layout Standard
16590 While these initialization modules are meant as generic startup code there
16591  might be the need for customization.
16592  Let's assume the return value of 
16593 \emph on
16594 _sdcc_external_startup()
16595 \emph default
16596  in 
16597 \emph on
16598 crtstart.asm
16599 \emph default
16600  should not be checked (or 
16601 \emph on
16602 _sdcc_external_startup()
16603 \emph default
16604  should not be called at all).
16605  The recommended way would be to copy 
16606 \emph on
16607 crtstart.asm
16608 \emph default
16609  (f.e.
16610  from 
16611 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16612
16613 \end_inset
16614
16615 ) into the source directory, adapt it there, then assemble it with 
16616 \emph on
16617 asx8051 -plosgff
16618 \begin_inset Foot
16619 status open
16620
16621 \begin_layout Standard
16622 \begin_inset Quotes sld
16623 \end_inset
16624
16625 -plosgff
16626 \begin_inset Quotes srd
16627 \end_inset
16628
16629  are the assembler options used in 
16630 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16631
16632 \end_inset
16633
16634
16635 \end_layout
16636
16637 \end_inset
16638
16639  crtstart.asm
16640 \emph default
16641  and when linking your project explicitely specify 
16642 \emph on
16643 crtstart.rel
16644 \emph default
16645 .
16646  As a bonus a listing of the relocated object file 
16647 \emph on
16648 crtstart.rst
16649 \emph default
16650  is generated.
16651 \end_layout
16652
16653 \begin_layout Standard
16654 \begin_inset VSpace bigskip
16655 \end_inset
16656
16657
16658 \end_layout
16659
16660 \begin_layout Subsection
16661 HC08 Startup Code
16662 \end_layout
16663
16664 \begin_layout Standard
16665 The HC08
16666 \begin_inset LatexCommand \index{HC08}
16667
16668 \end_inset
16669
16670  startup code follows the same scheme as the MCS51 startup code.
16671 \begin_inset VSpace bigskip
16672 \end_inset
16673
16674
16675 \end_layout
16676
16677 \begin_layout Subsection
16678 Z80 Startup Code
16679 \end_layout
16680
16681 \begin_layout Standard
16682 On the Z80
16683 \begin_inset LatexCommand \index{Z80}
16684
16685 \end_inset
16686
16687  the startup code is inserted by linking with crt0.o which is generated from
16688  sdcc/device/lib/z80/crt0.s.
16689  If you need a different startup code you can use the compiler option 
16690 \emph on
16691 -
16692 \series bold
16693 \emph default
16694
16695 \begin_inset ERT
16696 status collapsed
16697
16698 \begin_layout Standard
16699
16700
16701 \backslash
16702 /
16703 \end_layout
16704
16705 \end_inset
16706
16707
16708 \series default
16709 \emph on
16710 -no-std-crt0
16711 \emph default
16712
16713 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16714
16715 \end_inset
16716
16717  and provide your own crt0.o.
16718  
16719 \begin_inset VSpace bigskip
16720 \end_inset
16721
16722
16723 \end_layout
16724
16725 \begin_layout Section
16726 Inline Assembler Code
16727 \begin_inset LatexCommand \index{Assembler routines}
16728
16729 \end_inset
16730
16731
16732 \end_layout
16733
16734 \begin_layout Subsection
16735 A Step by Step Introduction
16736 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16737
16738 \end_inset
16739
16740
16741 \end_layout
16742
16743 \begin_layout Standard
16744 Starting from a small snippet of c-code this example shows for the MCS51
16745  how to use inline assembly, access variables, a function parameter and
16746  an array in xdata memory.
16747  The example uses an MCS51 here but is easily adapted for other architectures.
16748  This is a buffer routine which should be optimized:
16749 \end_layout
16750
16751 \begin_layout Verse
16752
16753 \family typewriter
16754 \size footnotesize
16755 unsigned char __far
16756 \begin_inset LatexCommand \index{far (storage class)}
16757
16758 \end_inset
16759
16760
16761 \begin_inset LatexCommand \index{\_\_far (storage class)}
16762
16763 \end_inset
16764
16765  __at
16766 \begin_inset LatexCommand \index{at}
16767
16768 \end_inset
16769
16770
16771 \begin_inset LatexCommand \index{\_\_at}
16772
16773 \end_inset
16774
16775 (0x7f00) buf[0x100];
16776 \begin_inset LatexCommand \index{Aligned array}
16777
16778 \end_inset
16779
16780
16781 \newline
16782 unsigned char head, tail;\InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 /* if interrupts
16800 \begin_inset LatexCommand \index{interrupt}
16801
16802 \end_inset
16803
16804  are involved see
16805 \newline
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 section 
16852 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16853
16854 \end_inset
16855
16856  about
16857 \series bold
16858  volatile
16859 \series default
16860  */
16861 \newline
16862
16863 \newline
16864 void to_buffer( unsigned char c ) 
16865 \newline
16866 {
16867 \newline
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 \InsetSpace ~
16871 \InsetSpace ~
16872 if( head != (unsigned char)(tail-1)
16873  )\InsetSpace ~
16874 /* cast 
16875 \series bold
16876 needed
16877 \series default
16878  to avoid promotion
16879 \begin_inset LatexCommand \index{promotion to signed int}
16880
16881 \end_inset
16882
16883
16884 \begin_inset LatexCommand \index{type promotion}
16885
16886 \end_inset
16887
16888  to integer */
16889 \begin_inset Marginal
16890 status collapsed
16891
16892 \begin_layout Standard
16893
16894 \series bold
16895 \InsetSpace ~
16896 !
16897 \end_layout
16898
16899 \end_inset
16900
16901
16902 \newline
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 buf[ head++ ] = c;\InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 /* access to a 256 byte aligned array */
16928 \newline
16929
16930 \end_layout
16931
16932 \begin_layout Standard
16933 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16934  then a corresponding buffer.asm file is generated.
16935  We define a new function 
16936 \family typewriter
16937 to_buffer_asm()
16938 \family default
16939  in file buffer.c in which we cut and paste the generated code, removing
16940  unwanted comments and some ':'.
16941  Then add 
16942 \begin_inset Quotes sld
16943 \end_inset
16944
16945
16946 \series bold
16947 _asm
16948 \series default
16949
16950 \begin_inset Quotes srd
16951 \end_inset
16952
16953  and 
16954 \begin_inset Quotes sld
16955 \end_inset
16956
16957
16958 \series bold
16959 _endasm;
16960 \series default
16961
16962 \begin_inset Quotes srd
16963 \end_inset
16964
16965
16966 \begin_inset Foot
16967 status open
16968
16969 \begin_layout Standard
16970 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16971  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16972  has to be used.
16973  The latter is also used in the library functions.
16974 \end_layout
16975
16976 \end_inset
16977
16978  to the beginning and the end of the function body:
16979 \end_layout
16980
16981 \begin_layout Verse
16982
16983 \family typewriter
16984 \size footnotesize
16985 /* With a cut and paste from the .asm file, we have something to start with.
16986 \newline
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 The
16991  function is not yet OK! (registers aren't saved) */ 
16992 \newline
16993 void to_buffer_asm(
16994  unsigned char c ) 
16995 \newline
16996
16997 \newline
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 _asm
17003 \begin_inset LatexCommand \index{\_asm}
17004
17005 \end_inset
17006
17007
17008 \begin_inset LatexCommand \index{\_\_asm}
17009
17010 \end_inset
17011
17012
17013 \newline
17014 \InsetSpace ~
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 mov\InsetSpace ~
17019 \InsetSpace ~
17020 r2,dpl 
17021 \newline
17022 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17023 /* cast 
17024 \series bold
17025 needed
17026 \series default
17027  to avoid promotion
17028 \begin_inset LatexCommand \index{promotion to signed int}
17029
17030 \end_inset
17031
17032
17033 \begin_inset LatexCommand \index{type promotion}
17034
17035 \end_inset
17036
17037  to integer */
17038 \newline
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 \InsetSpace ~
17043 mov\InsetSpace ~
17044 \InsetSpace ~
17045 a,_tail 
17046 \newline
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 dec\InsetSpace ~
17052 \InsetSpace ~
17053
17054 \newline
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 \InsetSpace ~
17058 \InsetSpace ~
17059 mov\InsetSpace ~
17060 \InsetSpace ~
17061 r3,a 
17062 \newline
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 mov\InsetSpace ~
17068 \InsetSpace ~
17069 a,_head 
17070 \newline
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 cjne a,ar3,00106$ 
17076 \newline
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 ret
17082 \newline
17083 00106$:
17084  
17085 \newline
17086 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17087 \begin_inset LatexCommand \index{Aligned array}
17088
17089 \end_inset
17090
17091
17092 \newline
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 mov\InsetSpace ~
17098 \InsetSpace ~
17099 r3,_head 
17100 \newline
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 inc\InsetSpace ~
17106 \InsetSpace ~
17107 _head 
17108 \newline
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 mov\InsetSpace ~
17114 \InsetSpace ~
17115 dpl,r3 
17116 \newline
17117 \InsetSpace ~
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 mov\InsetSpace ~
17122 \InsetSpace ~
17123 dph,#(_buf >> 8) 
17124 \newline
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 mov\InsetSpace ~
17130 \InsetSpace ~
17131 a,r2 
17132 \newline
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 movx @dptr,a
17138  
17139 \newline
17140 00103$: 
17141 \newline
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 ret
17147 \newline
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 _endasm
17153 \begin_inset LatexCommand \index{\_endasm}
17154
17155 \end_inset
17156
17157
17158 \begin_inset LatexCommand \index{\_\_endasm}
17159
17160 \end_inset
17161
17162 ;
17163 \newline
17164
17165 \end_layout
17166
17167 \begin_layout Standard
17168 The new file buffer.c should compile with only one warning about the unreferenced
17169  function argument 'c'.
17170  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17171  (1) and finally have:
17172 \end_layout
17173
17174 \begin_layout Verse
17175
17176 \family typewriter
17177 \size footnotesize
17178 unsigned char __far __at(0x7f00) buf[0x100];
17179 \newline
17180 unsigned char head, tail;
17181 \newline
17182 #define
17183  USE_ASSEMBLY (1)
17184 \newline
17185
17186 \newline
17187 #if !USE_ASSEMBLY
17188 \newline
17189
17190 \newline
17191 void to_buffer( unsigned char c )
17192 \newline
17193 {
17194 \newline
17195 \InsetSpace ~
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 if(
17200  head != (unsigned char)(tail-1) )
17201 \newline
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 buf[ head++ ] = c;
17211 \newline
17212 }
17213 \newline
17214
17215 \newline
17216 #else
17217 \newline
17218
17219 \newline
17220 void to_buffer(
17221  unsigned char c )
17222 \newline
17223 {
17224 \newline
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 c; // to avoid warning: unreferenced function argument
17230 \newline
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 _asm
17236 \begin_inset LatexCommand \index{\_asm}
17237
17238 \end_inset
17239
17240
17241 \begin_inset LatexCommand \index{\_\_asm}
17242
17243 \end_inset
17244
17245
17246 \newline
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 \InsetSpace ~
17254 \InsetSpace ~
17255 ; save used registers here.
17256  
17257 \newline
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 \InsetSpace ~
17266 ; If we were still using r2,r3 we would have to push them here.
17267  
17268 \newline
17269 ; if( head != (unsigned char)(tail-1) )
17270 \newline
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 \InsetSpace ~
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 mov\InsetSpace ~
17280  a,_tail
17281 \newline
17282 \InsetSpace ~
17283 \InsetSpace ~
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 \InsetSpace ~
17290 dec\InsetSpace ~
17291  a
17292 \newline
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 xrl\InsetSpace ~
17302  a,_head
17303 \newline
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 \InsetSpace ~
17312 ; we
17313  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17314 \newline
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 \InsetSpace ~
17323 jz\InsetSpace ~
17324 \InsetSpace ~
17325  t_b_end$
17326 \newline
17327 \InsetSpace ~
17328 \InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 \InsetSpace ~
17334 \InsetSpace ~
17335 ;
17336 \newline
17337 ;
17338  buf[ head++ ] = c;
17339 \newline
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 \InsetSpace ~
17346 \InsetSpace ~
17347 \InsetSpace ~
17348 mov\InsetSpace ~
17349  a,dpl \InsetSpace ~
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 ; dpl holds lower byte of function argument
17357 \newline
17358 \InsetSpace ~
17359 \InsetSpace ~
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 mov\InsetSpace ~
17367
17368  dpl,_head \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 ; buf is 0x100 byte aligned so head can be used directly
17372 \newline
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 \InsetSpace ~
17377 \InsetSpace ~
17378 \InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 mov\InsetSpace ~
17382  dph,#(_bu
17383 f>>8)
17384 \newline
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 movx @dptr,a
17394 \newline
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 inc \InsetSpace ~
17404 _head
17405 \newline
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 \InsetSpace ~
17414 ; we could do an ANL _head,#0x0f here to use a
17415  smaller buffer (see above)
17416 \newline
17417 t_b_end$:
17418 \newline
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 \InsetSpace ~
17424 \InsetSpace ~
17425 \InsetSpace ~
17426 \InsetSpace ~
17427 ; restore used registers here 
17428 \newline
17429 \InsetSpace ~
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 _endasm
17434 \begin_inset LatexCommand \index{\_endasm}
17435
17436 \end_inset
17437
17438
17439 \begin_inset LatexCommand \index{\_\_endasm}
17440
17441 \end_inset
17442
17443 ;
17444 \newline
17445 }
17446 \newline
17447 #endif
17448 \end_layout
17449
17450 \begin_layout Standard
17451 The inline assembler code can contain any valid code understood by the assembler
17452 , this includes any assembler directives and comment lines.
17453  The assembler does not like some characters like ':' or ''' in comments.
17454  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17455 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17456
17457 \end_inset
17458
17459
17460 \begin_inset LatexCommand \index{Assembler documentation}
17461
17462 \end_inset
17463
17464  or online at 
17465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17466
17467 \end_inset
17468
17469 \InsetSpace ~
17470 .
17471 \end_layout
17472
17473 \begin_layout Standard
17474 The compiler does not do any validation of the code within the 
17475 \family typewriter
17476 _asm
17477 \begin_inset LatexCommand \index{\_asm}
17478
17479 \end_inset
17480
17481
17482 \begin_inset LatexCommand \index{\_\_asm}
17483
17484 \end_inset
17485
17486  ...
17487  _endasm
17488 \size footnotesize
17489
17490 \begin_inset LatexCommand \index{\_endasm}
17491
17492 \end_inset
17493
17494
17495 \begin_inset LatexCommand \index{\_\_endasm}
17496
17497 \end_inset
17498
17499
17500 \size default
17501 ;
17502 \family default
17503  keyword pair.
17504  Specifically it will not know which registers are used and thus register
17505  pushing/popping
17506 \begin_inset LatexCommand \index{push/pop}
17507
17508 \end_inset
17509
17510  has to be done manually.
17511  
17512 \end_layout
17513
17514 \begin_layout Standard
17515 It is recommended that each assembly instruction (including labels) be placed
17516  in a separate line (as the example shows).
17517  When the -
17518 \begin_inset ERT
17519 status collapsed
17520
17521 \begin_layout Standard
17522
17523
17524 \backslash
17525 /
17526 \end_layout
17527
17528 \end_inset
17529
17530 -
17531 \emph on
17532 peep-asm
17533 \begin_inset LatexCommand \index{-\/-peep-asm}
17534
17535 \end_inset
17536
17537
17538 \emph default
17539  command line option is used, the inline assembler code will be passed through
17540  the peephole optimizer
17541 \begin_inset LatexCommand \index{Peephole optimizer}
17542
17543 \end_inset
17544
17545 .
17546  There are only a few (if any) cases where this option makes sense, it might
17547  cause some unexpected changes in the inline assembler code.
17548  Please go through the peephole optimizer rules defined in file 
17549 \emph on
17550 SDCCpeeph.def
17551 \emph default
17552  before using this option.
17553 \end_layout
17554
17555 \begin_layout Subsection
17556 Naked Functions
17557 \begin_inset LatexCommand \label{sub:Naked-Functions}
17558
17559 \end_inset
17560
17561
17562 \begin_inset LatexCommand \index{Naked functions}
17563
17564 \end_inset
17565
17566
17567 \end_layout
17568
17569 \begin_layout Standard
17570 A special keyword may be associated with a function declaring it as 
17571 \emph on
17572 _naked
17573 \begin_inset LatexCommand \index{\_naked}
17574
17575 \end_inset
17576
17577
17578 \begin_inset LatexCommand \index{\_\_naked}
17579
17580 \end_inset
17581
17582 .
17583  
17584 \emph default
17585 The 
17586 \emph on
17587 _naked
17588 \emph default
17589  function modifier attribute prevents the compiler from generating prologue
17590 \begin_inset LatexCommand \index{function prologue}
17591
17592 \end_inset
17593
17594  and epilogue
17595 \begin_inset LatexCommand \index{function epilogue}
17596
17597 \end_inset
17598
17599  code for that function.
17600  This means that the user is entirely responsible for such things as saving
17601  any registers that may need to be preserved, selecting the proper register
17602  bank, generating the 
17603 \emph on
17604 return
17605 \emph default
17606  instruction at the end, etc.
17607  Practically, this means that the contents of the function must be written
17608  in inline assembler.
17609  This is particularly useful for interrupt functions, which can have a large
17610  (and often unnecessary) prologue/epilogue.
17611  For example, compare the code generated by these two functions:
17612 \end_layout
17613
17614 \begin_layout Verse
17615
17616 \family typewriter
17617 volatile
17618 \begin_inset LatexCommand \index{volatile}
17619
17620 \end_inset
17621
17622  data unsigned char counter;
17623 \newline
17624
17625 \newline
17626 void simpleInterrupt(void) __interrupt
17627 \begin_inset LatexCommand \index{interrupt}
17628
17629 \end_inset
17630
17631
17632 \begin_inset LatexCommand \index{\_\_interrupt}
17633
17634 \end_inset
17635
17636  (1)
17637 \newline
17638 {
17639 \newline
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 counter++;
17645 \newline
17646 }
17647 \newline
17648
17649 \newline
17650 void nakedInterrupt(void) __interrupt (2) __naked
17651 \newline
17652 {
17653 \newline
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 _asm
17659 \begin_inset LatexCommand \index{\_asm}
17660
17661 \end_inset
17662
17663
17664 \begin_inset LatexCommand \index{\_\_asm}
17665
17666 \end_inset
17667
17668
17669 \newline
17670 \InsetSpace ~
17671 \InsetSpace ~
17672 \InsetSpace ~
17673 \InsetSpace ~
17674 \InsetSpace ~
17675 \InsetSpace ~
17676 inc\InsetSpace ~
17677 \InsetSpace ~
17678 \InsetSpace ~
17679 \InsetSpace ~
17680 \InsetSpace ~
17681 _counter ; does not change flags, no need to save psw
17682 \newline
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 \InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 reti\InsetSpace ~
17690 \InsetSpace ~
17691 \InsetSpace ~
17692 \InsetSpace ~
17693 ; MUST explicitly
17694  include ret or reti in _naked function.
17695 \newline
17696 \InsetSpace ~
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 \InsetSpace ~
17700 _endasm
17701 \begin_inset LatexCommand \index{\_endasm}
17702
17703 \end_inset
17704
17705
17706 \begin_inset LatexCommand \index{\_\_endasm}
17707
17708 \end_inset
17709
17710 ;
17711 \newline
17712 }
17713 \end_layout
17714
17715 \begin_layout Standard
17716 For an 8051 target, the generated simpleInterrupt looks like:
17717 \end_layout
17718
17719 \begin_layout Verse
17720
17721 \family typewriter
17722 Note, this is an 
17723 \emph on
17724 outdated
17725 \emph default
17726  example, recent versions of SDCC generate
17727 \newline
17728 the 
17729 \emph on
17730 same
17731 \emph default
17732  code for simpleInterrupt() and nakedInterrupt()!
17733 \newline
17734
17735 \newline
17736 _simpleInterrupt:
17737 \newline
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 push\InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 acc
17747 \newline
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 push\InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 \InsetSpace ~
17756 b
17757 \newline
17758 \InsetSpace ~
17759 \InsetSpace ~
17760 \InsetSpace ~
17761 \InsetSpace ~
17762 pu
17763 sh\InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 \InsetSpace ~
17767 dpl
17768 \newline
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 push\InsetSpace ~
17774 \InsetSpace ~
17775 \InsetSpace ~
17776 \InsetSpace ~
17777 dph
17778 \newline
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 \InsetSpace ~
17783 push\InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 psw
17788 \newline
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 \InsetSpace ~
17793 mov\InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 \InsetSpace ~
17798 psw,#0x00
17799 \newline
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 \InsetSpace ~
17804 inc\InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 _counter
17810 \newline
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 \InsetSpace ~
17815 pop\InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 \InsetSpace ~
17820 psw
17821 \newline
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 pop\InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 dph
17832 \newline
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 \InsetSpace ~
17837 pop\InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 dpl
17843 \newline
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 pop\InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 \InsetSpace ~
17853 b
17854 \newline
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 pop\InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 acc
17865 \newline
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 reti
17871 \end_layout
17872
17873 \begin_layout Standard
17874 whereas nakedInterrupt looks like:
17875 \end_layout
17876
17877 \begin_layout Verse
17878
17879 \family typewriter
17880 _nakedInterrupt:
17881 \newline
17882 \InsetSpace ~
17883 \InsetSpace ~
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 inc\InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 \InsetSpace ~
17890 _counter ; does not change flags, no need to save psw
17891 \newline
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 reti\InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 \InsetSpace ~
17908 ;
17909  MUST explicitly include ret or reti in _naked function
17910 \end_layout
17911
17912 \begin_layout Standard
17913 The related directive #pragma exclude
17914 \begin_inset LatexCommand \index{\#pragma exclude}
17915
17916 \end_inset
17917
17918  allows a more fine grained control over pushing & popping
17919 \begin_inset LatexCommand \index{push/pop}
17920
17921 \end_inset
17922
17923  the registers.
17924 \end_layout
17925
17926 \begin_layout Standard
17927 While there is nothing preventing you from writing C code inside a 
17928 \family typewriter
17929 _naked
17930 \family default
17931  function, there are many ways to shoot yourself in the foot doing this,
17932  and it is recommended that you stick to inline assembler.
17933 \end_layout
17934
17935 \begin_layout Subsection
17936 Use of Labels within Inline Assembler
17937 \end_layout
17938
17939 \begin_layout Standard
17940 SDCC allows the use of in-line assembler with a few restrictions regarding
17941  labels.
17942  All labels defined within inline assembler code have to be of the form
17943  
17944 \emph on
17945 nnnnn$
17946 \emph default
17947  where nnnnn is a number less than 100 (which implies a limit of utmost
17948  100 inline assembler labels 
17949 \emph on
17950 per function
17951 \emph default
17952 \noun on
17953 )
17954 \noun default
17955 .
17956 \begin_inset Foot
17957 status open
17958
17959 \begin_layout Standard
17960 This is a slightly more stringent rule than absolutely necessary, but stays
17961  always on the safe side.
17962  Labels in the form of nnnnn$ are local labels in the assembler, locality
17963  of which is confined within two labels of the standard form.
17964  The compiler uses the same form for labels within a function (but starting
17965  from nnnnn=00100); and places always a standard label at the beginning
17966  of a function, thus limiting the locality of labels within the scope of
17967  the function.
17968  So, if the inline assembler part would be embedded into C-code, an improperly
17969  placed non-local label in the assembler would break up the reference space
17970  for labels created by the compiler for the C-code, leading to an assembling
17971  error.
17972 \end_layout
17973
17974 \begin_layout Standard
17975 The numeric part of local labels does not need to have 5 digits (although
17976  this is the form of labels output by the compiler), any valid integer will
17977  do.
17978  Please refer to the assemblers documentation for further details.
17979 \end_layout
17980
17981 \end_inset
17982
17983  
17984 \end_layout
17985
17986 \begin_layout Verse
17987
17988 \family typewriter
17989 _asm
17990 \begin_inset LatexCommand \index{\_asm}
17991
17992 \end_inset
17993
17994
17995 \begin_inset LatexCommand \index{\_\_asm}
17996
17997 \end_inset
17998
17999  
18000 \newline
18001 \InsetSpace ~
18002 \InsetSpace ~
18003 \InsetSpace ~
18004 \InsetSpace ~
18005 mov\InsetSpace ~
18006 \InsetSpace ~
18007 \InsetSpace ~
18008 \InsetSpace ~
18009 \InsetSpace ~
18010 b,#10 
18011 \newline
18012 00001$: 
18013 \newline
18014 \InsetSpace ~
18015 \InsetSpace ~
18016 \InsetSpace ~
18017 \InsetSpace ~
18018 djnz\InsetSpace ~
18019 \InsetSpace ~
18020 \InsetSpace ~
18021 \InsetSpace ~
18022 b,00001$ 
18023 \newline
18024 _endasm
18025 \begin_inset LatexCommand \index{\_endasm}
18026
18027 \end_inset
18028
18029
18030 \begin_inset LatexCommand \index{\_\_endasm}
18031
18032 \end_inset
18033
18034  ;
18035 \end_layout
18036
18037 \begin_layout Standard
18038 Inline assembler code cannot reference any C-labels, however it can reference
18039  labels
18040 \begin_inset LatexCommand \index{Labels}
18041
18042 \end_inset
18043
18044  defined by the inline assembler, e.g.:
18045 \end_layout
18046
18047 \begin_layout Verse
18048
18049 \family typewriter
18050 foo() { 
18051 \newline
18052 \InsetSpace ~
18053 \InsetSpace ~
18054 \InsetSpace ~
18055 \InsetSpace ~
18056 /* some c code */ 
18057 \newline
18058 \InsetSpace ~
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 \InsetSpace ~
18062 _asm 
18063 \newline
18064 \InsetSpace ~
18065 \InsetSpace ~
18066 \InsetSpace ~
18067 \InsetSpace ~
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 ; some assembler code 
18071 \newline
18072 \InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 \InsetSpace ~
18077 \InsetSpace ~
18078 ljmp 0003$ 
18079 \newline
18080 \InsetSpace ~
18081 \InsetSpace ~
18082 \InsetSpace ~
18083 \InsetSpace ~
18084 _endasm;
18085  
18086 \newline
18087 \InsetSpace ~
18088 \InsetSpace ~
18089 \InsetSpace ~
18090 \InsetSpace ~
18091 /* some more c code */ 
18092 \newline
18093 clabel:\InsetSpace ~
18094 \InsetSpace ~
18095 /* inline assembler cannot reference this
18096  label */ 
18097 \begin_inset Foot
18098 status open
18099
18100 \begin_layout Standard
18101 Here, the C-label 
18102 \family typewriter
18103 clabel
18104 \family default
18105  is translated by the compiler into a local label, so the locality of labels
18106  within the function is not broken.
18107 \end_layout
18108
18109 \end_inset
18110
18111
18112 \newline
18113 \InsetSpace ~
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 _asm
18118 \newline
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 0003$: ;label (can be referenced by inline assembler only) 
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 _endasm
18130 \begin_inset LatexCommand \index{\_endasm}
18131
18132 \end_inset
18133
18134
18135 \begin_inset LatexCommand \index{\_\_endasm}
18136
18137 \end_inset
18138
18139  ; 
18140 \newline
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 \InsetSpace ~
18144 \InsetSpace ~
18145 /* some more c code */
18146 \newline
18147 }
18148 \end_layout
18149
18150 \begin_layout Standard
18151 In other words inline assembly code can access labels defined in inline
18152  assembly within the scope of the function.
18153  The same goes the other way, i.e.
18154  labels defines in inline assembly can not be accessed by C statements.
18155 \end_layout
18156
18157 \begin_layout Section
18158 Interfacing with Assembler Code
18159 \begin_inset LatexCommand \index{Assembler routines}
18160
18161 \end_inset
18162
18163
18164 \end_layout
18165
18166 \begin_layout Subsection
18167 Global Registers used for Parameter Passing
18168 \begin_inset LatexCommand \index{Parameter passing}
18169
18170 \end_inset
18171
18172
18173 \end_layout
18174
18175 \begin_layout Standard
18176 The compiler always uses the global registers 
18177 \emph on
18178 DPL, DPH
18179 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18180
18181 \end_inset
18182
18183
18184 \begin_inset LatexCommand \index{DPTR}
18185
18186 \end_inset
18187
18188 , B
18189 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18190
18191 \end_inset
18192
18193  
18194 \emph default
18195 and
18196 \emph on
18197  ACC
18198 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18199
18200 \end_inset
18201
18202
18203 \emph default
18204  to pass the first (non-bit) parameter to a function, and also to pass the
18205  return value 
18206 \begin_inset LatexCommand \index{return value}
18207
18208 \end_inset
18209
18210 of function; according to the following scheme: one byte return value in
18211  
18212 \emph on
18213 DPL
18214 \emph default
18215 , two byte value in 
18216 \emph on
18217 DPL
18218 \emph default
18219  (LSB) and 
18220 \emph on
18221 DPH
18222 \emph default
18223  (MSB).
18224  three byte values (generic pointers) in 
18225 \emph on
18226 DPH
18227 \emph default
18228
18229 \emph on
18230 DPL
18231 \emph default
18232  and 
18233 \emph on
18234 B
18235 \emph default
18236 , and four byte values in 
18237 \emph on
18238 DPH
18239 \emph default
18240
18241 \emph on
18242 DPL
18243 \emph default
18244 ,
18245 \emph on
18246  B
18247 \emph default
18248  and 
18249 \emph on
18250 ACC
18251 \emph default
18252 .
18253  Generic pointers
18254 \begin_inset LatexCommand \index{generic pointer}
18255
18256 \end_inset
18257
18258  contain type of accessed memory in 
18259 \emph on
18260 B
18261 \emph default
18262
18263 \series bold
18264 0x00
18265 \series default
18266  -- xdata/far, 
18267 \series bold
18268 0x40
18269 \series default
18270  -- idata/near -- , 
18271 \series bold
18272 0x60
18273 \series default
18274  -- pdata, 
18275 \series bold
18276 0x80
18277 \series default
18278  -- code
18279 \begin_inset Note Note
18280 status collapsed
18281
18282 \begin_layout Standard
18283 This might not be the case of certain memory models (medium???)
18284 \end_layout
18285
18286 \end_inset
18287
18288 .
18289 \end_layout
18290
18291 \begin_layout Standard
18292 The second parameter onwards is either allocated on the stack (for reentrant
18293  routines or if -
18294 \begin_inset ERT
18295 status collapsed
18296
18297 \begin_layout Standard
18298
18299
18300 \backslash
18301 /
18302 \end_layout
18303
18304 \end_inset
18305
18306 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18307 \end_layout
18308
18309 \begin_layout Standard
18310 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18311  space for reentrant functions or allocated directly in bit memory otherwise.
18312 \end_layout
18313
18314 \begin_layout Standard
18315 Functions (with two or more parameters or bit parameters) that are called
18316  through function pointers
18317 \begin_inset LatexCommand \index{function pointers}
18318
18319 \end_inset
18320
18321  must therefor be reentrant so the compiler knows how to pass the parameters.
18322 \end_layout
18323
18324 \begin_layout Subsection
18325 Registers usage
18326 \end_layout
18327
18328 \begin_layout Standard
18329 Unless the called function is declared as 
18330 \family typewriter
18331 _naked
18332 \family default
18333
18334 \begin_inset LatexCommand \index{naked}
18335
18336 \end_inset
18337
18338 , or the -
18339 \begin_inset ERT
18340 status collapsed
18341
18342 \begin_layout Standard
18343
18344
18345 \backslash
18346 /
18347 \end_layout
18348
18349 \end_inset
18350
18351 -callee-saves
18352 \begin_inset LatexCommand \index{-\/-callee-saves}
18353
18354 \end_inset
18355
18356 /-
18357 \begin_inset ERT
18358 status collapsed
18359
18360 \begin_layout Standard
18361
18362
18363 \backslash
18364 /
18365 \end_layout
18366
18367 \end_inset
18368
18369 -all-callee-saves command line option or the corresponding callee_saves
18370  pragma are used, the caller will save the registers (
18371 \emph on
18372 R0-R7
18373 \emph default
18374 ) around the call, so the called function can destroy they content freely.
18375 \end_layout
18376
18377 \begin_layout Standard
18378 If the called function is not declared as 
18379 \family typewriter
18380 _naked
18381 \family default
18382 , the caller will swap register banks around the call, if caller and callee
18383  use different register banks (having them defined by the 
18384 \family typewriter
18385 _using
18386 \family default
18387  modifier).
18388  
18389 \end_layout
18390
18391 \begin_layout Standard
18392 The called function can also use 
18393 \emph on
18394 DPL
18395 \emph default
18396
18397 \emph on
18398 DPH
18399 \emph default
18400
18401 \emph on
18402 B
18403 \emph default
18404  and 
18405 \emph on
18406 ACC
18407 \emph default
18408  observing that they are used for parameter/return value passing.
18409 \end_layout
18410
18411 \begin_layout Subsection
18412 Assembler Routine (non-reentrant)
18413 \end_layout
18414
18415 \begin_layout Standard
18416 In the following example
18417 \begin_inset LatexCommand \index{reentrant}
18418
18419 \end_inset
18420
18421
18422 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18423
18424 \end_inset
18425
18426  the function c_func calls an assembler routine asm_func, which takes two
18427  parameters
18428 \begin_inset LatexCommand \index{function parameter}
18429
18430 \end_inset
18431
18432 .
18433 \end_layout
18434
18435 \begin_layout Verse
18436
18437 \family typewriter
18438 extern int asm_func(unsigned char, unsigned char);
18439 \newline
18440
18441 \newline
18442 int c_func (unsigned char
18443  i, unsigned char j)
18444 \newline
18445 {
18446 \newline
18447 \InsetSpace ~
18448 \InsetSpace ~
18449 \InsetSpace ~
18450 \InsetSpace ~
18451 return asm_func(i,j);
18452 \newline
18453 }
18454 \newline
18455
18456 \newline
18457 int main()
18458 \newline
18459 {
18460 \newline
18461 \InsetSpace ~
18462 \InsetSpace ~
18463 \InsetSpace ~
18464 \InsetSpace ~
18465 return c_func(10,9);
18466 \newline
18467 }
18468 \end_layout
18469
18470 \begin_layout Standard
18471 The corresponding assembler function is:
18472 \end_layout
18473
18474 \begin_layout Verse
18475
18476 \family typewriter
18477 .globl _asm_func_PARM_2 
18478 \newline
18479 \InsetSpace ~
18480 \InsetSpace ~
18481 \InsetSpace ~
18482 \InsetSpace ~
18483 \InsetSpace ~
18484 \InsetSpace ~
18485 \InsetSpace ~
18486 \InsetSpace ~
18487 .globl _asm_func 
18488 \newline
18489 \InsetSpace ~
18490 \InsetSpace ~
18491 \InsetSpace ~
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 \InsetSpace ~
18495 \InsetSpace ~
18496 \InsetSpace ~
18497 .area OSEG 
18498 \newline
18499 _asm_func_PARM_2:
18500 \newline
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 \InsetSpace ~
18509 .ds   
18510  1 
18511 \newline
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 \InsetSpace ~
18519 \InsetSpace ~
18520 .area CSEG 
18521 \newline
18522 _asm_func: 
18523 \newline
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 mov\InsetSpace ~
18533 \InsetSpace ~
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 a,dpl 
18537 \newline
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 \InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 add\InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 a,_asm_func_PARM_2 
18551 \newline
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 \InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 mov\InsetSpace ~
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 dpl,a 
18565 \newline
18566 \InsetSpace ~
18567 \InsetSpace ~
18568 \InsetSpace ~
18569 \InsetSpace ~
18570 \InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 mov\InsetSpace ~
18575 \InsetSpace ~
18576 \InsetSpace ~
18577 \InsetSpace ~
18578 dph
18579 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18580
18581 \end_inset
18582
18583 ,#0x00 
18584 \newline
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 \InsetSpace ~
18588 \InsetSpace ~
18589 \InsetSpace ~
18590 \InsetSpace ~
18591 \InsetSpace ~
18592 \InsetSpace ~
18593 ret
18594 \end_layout
18595
18596 \begin_layout Standard
18597 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18598  the parameter number starting from 1, and counting from the left.
18599  The first parameter is passed in 
18600 \emph on
18601 DPH
18602 \emph default
18603
18604 \emph on
18605 DPL
18606 \emph default
18607
18608 \emph on
18609 B
18610 \emph default
18611  and 
18612 \emph on
18613 ACC
18614 \emph default
18615  according to the description above.
18616  The variable name for the second parameter will be _<function_name>_PARM_2.
18617 \newline
18618
18619 \newline
18620 Assem
18621 ble the assembler routine with the following command:
18622 \newline
18623
18624 \newline
18625
18626 \family sans
18627 \series bold
18628 asx8051 -losg asmfunc.asm
18629 \newline
18630
18631 \newline
18632
18633 \family default
18634 \series default
18635 Then compile and link the assembler routine to the C source file with the
18636  following command:
18637 \newline
18638
18639 \newline
18640
18641 \family sans
18642 \series bold
18643 sdcc cfunc.c asmfunc.rel
18644 \end_layout
18645
18646 \begin_layout Subsection
18647 Assembler Routine (reentrant)
18648 \end_layout
18649
18650 \begin_layout Standard
18651 In this case
18652 \begin_inset LatexCommand \index{reentrant}
18653
18654 \end_inset
18655
18656
18657 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18658
18659 \end_inset
18660
18661  the second parameter
18662 \begin_inset LatexCommand \index{function parameter}
18663
18664 \end_inset
18665
18666  onwards will be passed on the stack, the parameters are pushed from right
18667  to left i.e.
18668  before the call the second leftmost parameter will be on the top of the
18669  stack (the leftmost parameter is passed in registers).
18670  Here is an example:
18671 \end_layout
18672
18673 \begin_layout Verse
18674
18675 \family typewriter
18676 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18677 \newline
18678
18679 \newline
18680 int
18681  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18682 \newline
18683 {
18684  
18685 \newline
18686 \InsetSpace ~
18687 \InsetSpace ~
18688 \InsetSpace ~
18689 \InsetSpace ~
18690 return asm_func(i,j,k); 
18691 \newline
18692
18693 \newline
18694
18695 \newline
18696 int main() 
18697 \newline
18698
18699 \newline
18700 \InsetSpace ~
18701 \InsetSpace ~
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 return c_func(10,9,8); 
18705 \newline
18706 }
18707 \end_layout
18708
18709 \begin_layout Standard
18710 The corresponding (unoptimized) assembler routine is:
18711 \end_layout
18712
18713 \begin_layout Verse
18714
18715 \family typewriter
18716 .globl _asm_func 
18717 \newline
18718 _asm_func: 
18719 \newline
18720 \InsetSpace ~
18721 \InsetSpace ~
18722 \InsetSpace ~
18723 \InsetSpace ~
18724 push\InsetSpace ~
18725 _bp 
18726 \newline
18727 \InsetSpace ~
18728 \InsetSpace ~
18729 \InsetSpace ~
18730 \InsetSpace ~
18731 mov\InsetSpace ~
18732 \InsetSpace ~
18733 _bp,sp\InsetSpace ~
18734 \InsetSpace ~
18735 \InsetSpace ~
18736 \InsetSpace ~
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 ;stack contains: _bp, return
18740  address, second parameter, third parameter
18741 \newline
18742 \InsetSpace ~
18743 \InsetSpace ~
18744 \InsetSpace ~
18745 \InsetSpace ~
18746 mov\InsetSpace ~
18747 \InsetSpace ~
18748 r2,dpl
18749 \newline
18750 \InsetSpace ~
18751 \InsetSpace ~
18752 \InsetSpace ~
18753 \InsetSpace ~
18754 mov\InsetSpace ~
18755 \InsetSpace ~
18756 a,_bp
18757 \newline
18758 \InsetSpace ~
18759 \InsetSpace ~
18760 \InsetSpace ~
18761 \InsetSpace ~
18762 add\InsetSpace ~
18763 \InsetSpace ~
18764 a,#0xfd\InsetSpace ~
18765 \InsetSpace ~
18766 \InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 ;calculate
18770  pointer to the second parameter
18771 \newline
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 mov\InsetSpace ~
18777 \InsetSpace ~
18778 r0,a 
18779 \newline
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 mov\InsetSpace ~
18785 \InsetSpace ~
18786 a,_bp 
18787 \newline
18788 \InsetSpace ~
18789 \InsetSpace ~
18790 \InsetSpace ~
18791 \InsetSpace ~
18792 add\InsetSpace ~
18793 \InsetSpace ~
18794 a,#0xfc\InsetSpace ~
18795 \InsetSpace ~
18796 \InsetSpace ~
18797 \InsetSpace ~
18798 \InsetSpace ~
18799 ;calculate pointer
18800  to the rightmost parameter
18801 \newline
18802 \InsetSpace ~
18803 \InsetSpace ~
18804 \InsetSpace ~
18805 \InsetSpace ~
18806 mov\InsetSpace ~
18807 \InsetSpace ~
18808 r1,a 
18809 \newline
18810 \InsetSpace ~
18811 \InsetSpace ~
18812 \InsetSpace ~
18813 \InsetSpace ~
18814 mov\InsetSpace ~
18815 \InsetSpace ~
18816 a,@r0
18817 \newline
18818 \InsetSpace ~
18819 \InsetSpace ~
18820 \InsetSpace ~
18821 \InsetSpace ~
18822 add\InsetSpace ~
18823 \InsetSpace ~
18824 a,@r1
18825 \newline
18826 \InsetSpace ~
18827 \InsetSpace ~
18828 \InsetSpace ~
18829 \InsetSpace ~
18830 add\InsetSpace ~
18831 \InsetSpace ~
18832 a,r2\InsetSpace ~
18833 \InsetSpace ~
18834 \InsetSpace ~
18835 \InsetSpace ~
18836 \InsetSpace ~
18837 \InsetSpace ~
18838 \InsetSpace ~
18839 \InsetSpace ~
18840 ;calculate the
18841  result (= sum of all three parameters)
18842 \newline
18843 \InsetSpace ~
18844 \InsetSpace ~
18845 \InsetSpace ~
18846 \InsetSpace ~
18847 mov\InsetSpace ~
18848 \InsetSpace ~
18849 dpl,a\InsetSpace ~
18850 \InsetSpace ~
18851 \InsetSpace ~
18852 \InsetSpace ~
18853 \InsetSpace ~
18854 \InsetSpace ~
18855 \InsetSpace ~
18856 ;return value goes into dptr
18857  (cast into int)
18858 \newline
18859 \InsetSpace ~
18860 \InsetSpace ~
18861 \InsetSpace ~
18862 \InsetSpace ~
18863 mov\InsetSpace ~
18864 \InsetSpace ~
18865 dph,#0x00 
18866 \newline
18867 \InsetSpace ~
18868 \InsetSpace ~
18869 \InsetSpace ~
18870 \InsetSpace ~
18871 mov\InsetSpace ~
18872 \InsetSpace ~
18873 sp,_bp 
18874 \newline
18875 \InsetSpace ~
18876 \InsetSpace ~
18877 \InsetSpace ~
18878 \InsetSpace ~
18879 pop\InsetSpace ~
18880 \InsetSpace ~
18881 _bp 
18882 \newline
18883 \InsetSpace ~
18884 \InsetSpace ~
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 ret
18888 \end_layout
18889
18890 \begin_layout Standard
18891 The compiling and linking procedure remains the same, however note the extra
18892  entry & exit linkage required for the assembler code, _bp is the stack
18893  frame pointer and is used to compute the offset into the stack for parameters
18894  and local variables.
18895 \begin_inset VSpace bigskip
18896 \end_inset
18897
18898
18899 \end_layout
18900
18901 \begin_layout Section
18902 int (16 bit)
18903 \begin_inset LatexCommand \index{int (16 bit)}
18904
18905 \end_inset
18906
18907  and long (32 bit)
18908 \begin_inset LatexCommand \index{long (32 bit)}
18909
18910 \end_inset
18911
18912  Support
18913 \end_layout
18914
18915 \begin_layout Standard
18916 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18917  multiplication and modulus operations are implemented by support routines.
18918  These support routines are all developed in ANSI-C to facilitate porting
18919  to other MCUs, although some model specific assembler optimizations are
18920  used.
18921  The following files contain the described routines, all of them can be
18922  found in <installdir>/share/sdcc/lib.
18923 \newline
18924
18925 \end_layout
18926
18927 \begin_layout Standard
18928 \align center
18929 \begin_inset Tabular
18930 <lyxtabular version="3" rows="11" columns="2">
18931 <features>
18932 <column alignment="left" valignment="top" leftline="true" width="0">
18933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18934 <row topline="true" bottomline="true">
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18936 \begin_inset Text
18937
18938 \begin_layout Standard
18939
18940 \series bold
18941 Function
18942 \end_layout
18943
18944 \end_inset
18945 </cell>
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18947 \begin_inset Text
18948
18949 \begin_layout Standard
18950
18951 \series bold
18952 Description
18953 \end_layout
18954
18955 \end_inset
18956 </cell>
18957 </row>
18958 <row topline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18960 \begin_inset Text
18961
18962 \begin_layout Standard
18963 _mulint.c 
18964 \end_layout
18965
18966 \end_inset
18967 </cell>
18968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18969 \begin_inset Text
18970
18971 \begin_layout Standard
18972 16 bit multiplication
18973 \end_layout
18974
18975 \end_inset
18976 </cell>
18977 </row>
18978 <row topline="true">
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18980 \begin_inset Text
18981
18982 \begin_layout Standard
18983 _divsint.c 
18984 \end_layout
18985
18986 \end_inset
18987 </cell>
18988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18989 \begin_inset Text
18990
18991 \begin_layout Standard
18992  signed 16 bit division (calls _divuint)
18993 \end_layout
18994
18995 \end_inset
18996 </cell>
18997 </row>
18998 <row topline="true">
18999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19000 \begin_inset Text
19001
19002 \begin_layout Standard
19003 _divuint.c 
19004 \end_layout
19005
19006 \end_inset
19007 </cell>
19008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19009 \begin_inset Text
19010
19011 \begin_layout Standard
19012  unsigned 16 bit division
19013 \end_layout
19014
19015 \end_inset
19016 </cell>
19017 </row>
19018 <row topline="true">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19020 \begin_inset Text
19021
19022 \begin_layout Standard
19023 _modsint.c
19024 \end_layout
19025
19026 \end_inset
19027 </cell>
19028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19029 \begin_inset Text
19030
19031 \begin_layout Standard
19032 signed 16 bit modulus (calls _moduint)
19033 \end_layout
19034
19035 \end_inset
19036 </cell>
19037 </row>
19038 <row topline="true">
19039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19040 \begin_inset Text
19041
19042 \begin_layout Standard
19043 _moduint.c
19044 \end_layout
19045
19046 \end_inset
19047 </cell>
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19049 \begin_inset Text
19050
19051 \begin_layout Standard
19052 unsigned 16 bit modulus
19053 \end_layout
19054
19055 \end_inset
19056 </cell>
19057 </row>
19058 <row topline="true">
19059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19060 \begin_inset Text
19061
19062 \begin_layout Standard
19063 _mullong.c
19064 \end_layout
19065
19066 \end_inset
19067 </cell>
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19069 \begin_inset Text
19070
19071 \begin_layout Standard
19072 32 bit multiplication
19073 \end_layout
19074
19075 \end_inset
19076 </cell>
19077 </row>
19078 <row topline="true">
19079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19080 \begin_inset Text
19081
19082 \begin_layout Standard
19083 _divslong.c 
19084 \end_layout
19085
19086 \end_inset
19087 </cell>
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19089 \begin_inset Text
19090
19091 \begin_layout Standard
19092  signed 32 division (calls _divulong)
19093 \end_layout
19094
19095 \end_inset
19096 </cell>
19097 </row>
19098 <row topline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19100 \begin_inset Text
19101
19102 \begin_layout Standard
19103 _divulong.c 
19104 \end_layout
19105
19106 \end_inset
19107 </cell>
19108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19109 \begin_inset Text
19110
19111 \begin_layout Standard
19112 unsigned 32 division
19113 \end_layout
19114
19115 \end_inset
19116 </cell>
19117 </row>
19118 <row topline="true">
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19120 \begin_inset Text
19121
19122 \begin_layout Standard
19123 _modslong.c
19124 \end_layout
19125
19126 \end_inset
19127 </cell>
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19129 \begin_inset Text
19130
19131 \begin_layout Standard
19132  signed 32 bit modulus (calls _modulong)
19133 \end_layout
19134
19135 \end_inset
19136 </cell>
19137 </row>
19138 <row topline="true" bottomline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19140 \begin_inset Text
19141
19142 \begin_layout Standard
19143 _modulong.c
19144 \end_layout
19145
19146 \end_inset
19147 </cell>
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19149 \begin_inset Text
19150
19151 \begin_layout Standard
19152 unsigned 32 bit modulus
19153 \end_layout
19154
19155 \end_inset
19156 </cell>
19157 </row>
19158 </lyxtabular>
19159
19160 \end_inset
19161
19162
19163 \newline
19164
19165 \end_layout
19166
19167 \begin_layout Standard
19168 Since they are compiled as 
19169 \emph on
19170 non-reentrant
19171 \emph default
19172
19173 \begin_inset LatexCommand \index{reentrant}
19174
19175 \end_inset
19176
19177 , interrupt
19178 \begin_inset LatexCommand \index{interrupt}
19179
19180 \end_inset
19181
19182  service routines should not do any of the above operations.
19183  If this is unavoidable then the above routines will need to be compiled
19184  with the 
19185 \emph on
19186 -
19187 \begin_inset ERT
19188 status collapsed
19189
19190 \begin_layout Standard
19191
19192
19193 \backslash
19194 /
19195 \end_layout
19196
19197 \end_inset
19198
19199 -stack-auto
19200 \begin_inset LatexCommand \index{-\/-stack-auto}
19201
19202 \end_inset
19203
19204
19205 \emph default
19206  option, after which the source program will have to be compiled with 
19207 \emph on
19208 -
19209 \begin_inset ERT
19210 status collapsed
19211
19212 \begin_layout Standard
19213
19214
19215 \backslash
19216 /
19217 \end_layout
19218
19219 \end_inset
19220
19221 -int-long-reent
19222 \begin_inset LatexCommand \index{-\/-int-long-reent}
19223
19224 \end_inset
19225
19226
19227 \emph default
19228  option.
19229  Notice that you don't have to call these routines directly.
19230  The compiler will use them automatically every time an integer operation
19231  is required.
19232 \end_layout
19233
19234 \begin_layout Section
19235 Floating Point Support
19236 \begin_inset LatexCommand \index{Floating point support}
19237
19238 \end_inset
19239
19240
19241 \end_layout
19242
19243 \begin_layout Standard
19244 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19245  The floating point support routines are derived from gcc's floatlib.c and
19246  consist of the following routines:
19247 \newline
19248
19249 \end_layout
19250
19251 \begin_layout Standard
19252 \align center
19253
19254 \size footnotesize
19255 \begin_inset Tabular
19256 <lyxtabular version="3" rows="17" columns="2">
19257 <features>
19258 <column alignment="left" valignment="top" leftline="true" width="0">
19259 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19260 <row topline="true" bottomline="true">
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19262 \begin_inset Text
19263
19264 \begin_layout Standard
19265
19266 \family roman
19267 \series medium
19268 \shape up
19269 \size normal
19270 \emph off
19271 \bar no
19272 \noun off
19273 \color none
19274 Function 
19275 \end_layout
19276
19277 \end_inset
19278 </cell>
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \begin_layout Standard
19283 Description
19284 \end_layout
19285
19286 \end_inset
19287 </cell>
19288 </row>
19289 <row topline="true">
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \begin_layout Standard
19294
19295 \family roman
19296 \series medium
19297 \shape up
19298 \size normal
19299 \emph off
19300 \bar no
19301 \noun off
19302 \color none
19303 _fsadd.c
19304 \end_layout
19305
19306 \end_inset
19307 </cell>
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19309 \begin_inset Text
19310
19311 \begin_layout Standard
19312
19313 \family roman
19314 \series medium
19315 \shape up
19316 \size normal
19317 \emph off
19318 \bar no
19319 \noun off
19320 \color none
19321 add floating point numbers
19322 \end_layout
19323
19324 \end_inset
19325 </cell>
19326 </row>
19327 <row topline="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \begin_layout Standard
19332
19333 \family roman
19334 \series medium
19335 \shape up
19336 \size normal
19337 \emph off
19338 \bar no
19339 \noun off
19340 \color none
19341 _fssub.c 
19342 \end_layout
19343
19344 \end_inset
19345 </cell>
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19347 \begin_inset Text
19348
19349 \begin_layout Standard
19350
19351 \family roman
19352 \series medium
19353 \shape up
19354 \size normal
19355 \emph off
19356 \bar no
19357 \noun off
19358 \color none
19359 subtract floating point numbers 
19360 \end_layout
19361
19362 \end_inset
19363 </cell>
19364 </row>
19365 <row topline="true">
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19367 \begin_inset Text
19368
19369 \begin_layout Standard
19370
19371 \family roman
19372 \series medium
19373 \shape up
19374 \size normal
19375 \emph off
19376 \bar no
19377 \noun off
19378 \color none
19379 _fsdiv.c 
19380 \end_layout
19381
19382 \end_inset
19383 </cell>
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19385 \begin_inset Text
19386
19387 \begin_layout Standard
19388
19389 \family roman
19390 \series medium
19391 \shape up
19392 \size normal
19393 \emph off
19394 \bar no
19395 \noun off
19396 \color none
19397 divide floating point numbers 
19398 \end_layout
19399
19400 \end_inset
19401 </cell>
19402 </row>
19403 <row topline="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19405 \begin_inset Text
19406
19407 \begin_layout Standard
19408
19409 \family roman
19410 \series medium
19411 \shape up
19412 \size normal
19413 \emph off
19414 \bar no
19415 \noun off
19416 \color none
19417 _fsmul.c 
19418 \end_layout
19419
19420 \end_inset
19421 </cell>
19422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19423 \begin_inset Text
19424
19425 \begin_layout Standard
19426
19427 \family roman
19428 \series medium
19429 \shape up
19430 \size normal
19431 \emph off
19432 \bar no
19433 \noun off
19434 \color none
19435 multiply floating point numbers 
19436 \end_layout
19437
19438 \end_inset
19439 </cell>
19440 </row>
19441 <row topline="true">
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19443 \begin_inset Text
19444
19445 \begin_layout Standard
19446
19447 \family roman
19448 \series medium
19449 \shape up
19450 \size normal
19451 \emph off
19452 \bar no
19453 \noun off
19454 \color none
19455 _fs2uchar.c
19456 \end_layout
19457
19458 \end_inset
19459 </cell>
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19461 \begin_inset Text
19462
19463 \begin_layout Standard
19464
19465 \family roman
19466 \series medium
19467 \shape up
19468 \size normal
19469 \emph off
19470 \bar no
19471 \noun off
19472 \color none
19473 convert floating point to unsigned char
19474 \end_layout
19475
19476 \end_inset
19477 </cell>
19478 </row>
19479 <row topline="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \begin_layout Standard
19484
19485 \family roman
19486 \series medium
19487 \shape up
19488 \size normal
19489 \emph off
19490 \bar no
19491 \noun off
19492 \color none
19493 _fs2char.c
19494 \end_layout
19495
19496 \end_inset
19497 </cell>
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19499 \begin_inset Text
19500
19501 \begin_layout Standard
19502
19503 \family roman
19504 \series medium
19505 \shape up
19506 \size normal
19507 \emph off
19508 \bar no
19509 \noun off
19510 \color none
19511 convert floating point to signed char
19512 \end_layout
19513
19514 \end_inset
19515 </cell>
19516 </row>
19517 <row topline="true">
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19519 \begin_inset Text
19520
19521 \begin_layout Standard
19522
19523 \family roman
19524 \series medium
19525 \shape up
19526 \size normal
19527 \emph off
19528 \bar no
19529 \noun off
19530 \color none
19531 _fs2uint.c
19532 \end_layout
19533
19534 \end_inset
19535 </cell>
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_inset Text
19538
19539 \begin_layout Standard
19540
19541 \family roman
19542 \series medium
19543 \shape up
19544 \size normal
19545 \emph off
19546 \bar no
19547 \noun off
19548 \color none
19549 convert floating point to unsigned int
19550 \end_layout
19551
19552 \end_inset
19553 </cell>
19554 </row>
19555 <row topline="true">
19556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19557 \begin_inset Text
19558
19559 \begin_layout Standard
19560
19561 \family roman
19562 \series medium
19563 \shape up
19564 \size normal
19565 \emph off
19566 \bar no
19567 \noun off
19568 \color none
19569 _fs2int.c
19570 \end_layout
19571
19572 \end_inset
19573 </cell>
19574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19575 \begin_inset Text
19576
19577 \begin_layout Standard
19578
19579 \family roman
19580 \series medium
19581 \shape up
19582 \size normal
19583 \emph off
19584 \bar no
19585 \noun off
19586 \color none
19587 convert floating point to signed int
19588 \end_layout
19589
19590 \end_inset
19591 </cell>
19592 </row>
19593 <row topline="true">
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19595 \begin_inset Text
19596
19597 \begin_layout Standard
19598
19599 \family roman
19600 \series medium
19601 \shape up
19602 \size normal
19603 \emph off
19604 \bar no
19605 \noun off
19606 \color none
19607 _fs2ulong.
19608 \family default
19609 \series default
19610 \shape default
19611 \size default
19612 \emph default
19613 \bar default
19614 \noun default
19615 c
19616 \end_layout
19617
19618 \end_inset
19619 </cell>
19620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19621 \begin_inset Text
19622
19623 \begin_layout Standard
19624
19625 \family roman
19626 \series medium
19627 \shape up
19628 \size normal
19629 \emph off
19630 \bar no
19631 \noun off
19632 \color none
19633 convert floating point to unsigned long
19634 \end_layout
19635
19636 \end_inset
19637 </cell>
19638 </row>
19639 <row topline="true">
19640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19641 \begin_inset Text
19642
19643 \begin_layout Standard
19644
19645 \family roman
19646 \series medium
19647 \shape up
19648 \size normal
19649 \emph off
19650 \bar no
19651 \noun off
19652 \color none
19653 _fs2long.c
19654 \end_layout
19655
19656 \end_inset
19657 </cell>
19658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19659 \begin_inset Text
19660
19661 \begin_layout Standard
19662
19663 \family roman
19664 \series medium
19665 \shape up
19666 \size normal
19667 \emph off
19668 \bar no
19669 \noun off
19670 \color none
19671 convert floating point to signed long
19672 \end_layout
19673
19674 \end_inset
19675 </cell>
19676 </row>
19677 <row topline="true">
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19679 \begin_inset Text
19680
19681 \begin_layout Standard
19682
19683 \family roman
19684 \series medium
19685 \shape up
19686 \size normal
19687 \emph off
19688 \bar no
19689 \noun off
19690 \color none
19691 _uchar2fs.c
19692 \end_layout
19693
19694 \end_inset
19695 </cell>
19696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19697 \begin_inset Text
19698
19699 \begin_layout Standard
19700
19701 \family roman
19702 \series medium
19703 \shape up
19704 \size normal
19705 \emph off
19706 \bar no
19707 \noun off
19708 \color none
19709 convert unsigned char to floating point
19710 \end_layout
19711
19712 \end_inset
19713 </cell>
19714 </row>
19715 <row topline="true">
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19717 \begin_inset Text
19718
19719 \begin_layout Standard
19720
19721 \family roman
19722 \series medium
19723 \shape up
19724 \size normal
19725 \emph off
19726 \bar no
19727 \noun off
19728 \color none
19729 _char2fs.c
19730 \end_layout
19731
19732 \end_inset
19733 </cell>
19734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19735 \begin_inset Text
19736
19737 \begin_layout Standard
19738
19739 \family roman
19740 \series medium
19741 \shape up
19742 \size normal
19743 \emph off
19744 \bar no
19745 \noun off
19746 \color none
19747 convert char to floating point number
19748 \end_layout
19749
19750 \end_inset
19751 </cell>
19752 </row>
19753 <row topline="true">
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19755 \begin_inset Text
19756
19757 \begin_layout Standard
19758
19759 \family roman
19760 \series medium
19761 \shape up
19762 \size normal
19763 \emph off
19764 \bar no
19765 \noun off
19766 \color none
19767 _uint2fs.c
19768 \end_layout
19769
19770 \end_inset
19771 </cell>
19772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19773 \begin_inset Text
19774
19775 \begin_layout Standard
19776
19777 \family roman
19778 \series medium
19779 \shape up
19780 \size normal
19781 \emph off
19782 \bar no
19783 \noun off
19784 \color none
19785 convert unsigned int to floating point
19786 \end_layout
19787
19788 \end_inset
19789 </cell>
19790 </row>
19791 <row topline="true">
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19793 \begin_inset Text
19794
19795 \begin_layout Standard
19796
19797 \family roman
19798 \series medium
19799 \shape up
19800 \size normal
19801 \emph off
19802 \bar no
19803 \noun off
19804 \color none
19805 _int2fs.c
19806 \end_layout
19807
19808 \end_inset
19809 </cell>
19810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19811 \begin_inset Text
19812
19813 \begin_layout Standard
19814
19815 \family roman
19816 \series medium
19817 \shape up
19818 \size normal
19819 \emph off
19820 \bar no
19821 \noun off
19822 \color none
19823 convert int to floating point numbers
19824 \end_layout
19825
19826 \end_inset
19827 </cell>
19828 </row>
19829 <row topline="true">
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19831 \begin_inset Text
19832
19833 \begin_layout Standard
19834
19835 \family roman
19836 \series medium
19837 \shape up
19838 \size normal
19839 \emph off
19840 \bar no
19841 \noun off
19842 \color none
19843 _ulong2fs.c
19844 \end_layout
19845
19846 \end_inset
19847 </cell>
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19849 \begin_inset Text
19850
19851 \begin_layout Standard
19852
19853 \family roman
19854 \series medium
19855 \shape up
19856 \size normal
19857 \emph off
19858 \bar no
19859 \noun off
19860 \color none
19861 convert unsigned long to floating point number
19862 \end_layout
19863
19864 \end_inset
19865 </cell>
19866 </row>
19867 <row topline="true" bottomline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19869 \begin_inset Text
19870
19871 \begin_layout Standard
19872
19873 \family roman
19874 \series medium
19875 \shape up
19876 \size normal
19877 \emph off
19878 \bar no
19879 \noun off
19880 \color none
19881 _long2fs.c
19882 \end_layout
19883
19884 \end_inset
19885 </cell>
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19887 \begin_inset Text
19888
19889 \begin_layout Standard
19890
19891 \family roman
19892 \series medium
19893 \shape up
19894 \size normal
19895 \emph off
19896 \bar no
19897 \noun off
19898 \color none
19899 convert long to floating point number
19900 \end_layout
19901
19902 \end_inset
19903 </cell>
19904 </row>
19905 </lyxtabular>
19906
19907 \end_inset
19908
19909
19910 \newline
19911
19912 \end_layout
19913
19914 \begin_layout Standard
19915 These support routines are developed in ANSI-C so there is room for space
19916  and speed improvement
19917 \begin_inset Foot
19918 status open
19919
19920 \begin_layout Standard
19921 These floating point routines (
19922 \emph on
19923 not
19924 \emph default
19925  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19926  
19927 \end_layout
19928
19929 \end_inset
19930
19931 .
19932  Note if all these routines are used simultaneously the data space might
19933  overflow.
19934  For serious floating point usage the large model might be needed.
19935  Also notice that you don't have to call this routines directly.
19936  The compiler will use them automatically every time a floating point operation
19937  is required.
19938 \begin_inset VSpace bigskip
19939 \end_inset
19940
19941
19942 \end_layout
19943
19944 \begin_layout Section
19945 Library Routines
19946 \begin_inset LatexCommand \index{Libraries}
19947
19948 \end_inset
19949
19950
19951 \end_layout
19952
19953 \begin_layout Standard
19954
19955 \emph on
19956 <pending: this is messy and incomplete - a little more information is in
19957  sdcc/doc/libdoc.txt
19958 \emph default
19959  >
19960 \end_layout
19961
19962 \begin_layout Subsection
19963 Compiler support routines (_gptrget, _mulint etc.)
19964 \end_layout
19965
19966 \begin_layout Subsection
19967 Stdclib functions (puts, printf, strcat etc.)
19968 \end_layout
19969
19970 \begin_layout Subsubsection
19971 <stdio.h>
19972 \end_layout
19973
19974 \begin_layout Paragraph
19975 getchar(), putchar()
19976 \end_layout
19977
19978 \begin_layout Standard
19979 \begin_inset LatexCommand \index{<stdio.h>}
19980
19981 \end_inset
19982
19983 As usual on embedded systems you have to provide your own 
19984 \family typewriter
19985 getchar()
19986 \begin_inset LatexCommand \index{getchar()}
19987
19988 \end_inset
19989
19990  
19991 \family default
19992 and 
19993 \family typewriter
19994 putchar()
19995 \begin_inset LatexCommand \index{putchar()}
19996
19997 \end_inset
19998
19999
20000 \family default
20001  routines.
20002  SDCC does not know whether the system connects to a serial line with or
20003  without handshake, LCD, keyboard or other device.
20004  And whether a 
20005 \family typewriter
20006 lf
20007 \family default
20008  to 
20009 \family typewriter
20010 crlf
20011 \family default
20012  conversion within 
20013 \family typewriter
20014 putchar()
20015 \family default
20016  is intended.
20017  You'll find examples for serial routines f.e.
20018  in sdcc/device/lib.
20019  For the mcs51 this minimalistic polling 
20020 \family typewriter
20021 putchar()
20022 \family default
20023  routine might be a start:
20024 \end_layout
20025
20026 \begin_layout Verse
20027
20028 \family typewriter
20029 void putchar (char c) { 
20030 \newline
20031 \InsetSpace ~
20032 \InsetSpace ~
20033 \InsetSpace ~
20034 \InsetSpace ~
20035 while (!TI)\InsetSpace ~
20036 \InsetSpace ~
20037 \InsetSpace ~
20038  /* assumes UART is initialized */
20039 \newline
20040 \InsetSpace ~
20041 \InsetSpace ~
20042 \InsetSpace ~
20043 \InsetSpace ~
20044 \InsetSpace ~
20045 \InsetSpace ~
20046 \InsetSpace ~
20047 \InsetSpace ~
20048 ;
20049 \newline
20050 \InsetSpace ~
20051 \InsetSpace ~
20052 \InsetSpace ~
20053 \InsetSpace ~
20054 TI
20055  = 0;
20056 \newline
20057 \InsetSpace ~
20058 \InsetSpace ~
20059 \InsetSpace ~
20060 \InsetSpace ~
20061 SBUF = c;
20062 \newline
20063 }
20064 \end_layout
20065
20066 \begin_layout Paragraph
20067 printf()
20068 \end_layout
20069
20070 \begin_layout Standard
20071 The default
20072 \family typewriter
20073  printf()
20074 \begin_inset LatexCommand \index{printf()}
20075
20076 \end_inset
20077
20078
20079 \family default
20080  implementation in
20081 \family typewriter
20082  printf_large.c
20083 \family default
20084  does not support float (except on ds390).
20085  To enable this recompile it with the option 
20086 \emph on
20087 -
20088 \begin_inset ERT
20089 status collapsed
20090
20091 \begin_layout Standard
20092
20093
20094 \backslash
20095 /
20096 \end_layout
20097
20098 \end_inset
20099
20100 DUSE_FLOATS=1
20101 \begin_inset LatexCommand \index{USE\_FLOATS}
20102
20103 \end_inset
20104
20105
20106 \emph default
20107  on the command line.
20108  Use
20109 \emph on
20110  -
20111 \begin_inset ERT
20112 status collapsed
20113
20114 \begin_layout Standard
20115
20116
20117 \backslash
20118 /
20119 \end_layout
20120
20121 \end_inset
20122
20123 -model-large
20124 \begin_inset LatexCommand \index{-\/-model-large}
20125
20126 \end_inset
20127
20128
20129 \emph default
20130  for the mcs51 port, since this uses a lot of memory.
20131 \end_layout
20132
20133 \begin_layout Standard
20134 If you're short on code memory you might want to use 
20135 \family typewriter
20136 printf_small()
20137 \begin_inset LatexCommand \index{printf\_small()}
20138
20139 \end_inset
20140
20141
20142 \family default
20143  
20144 \emph on
20145 instead
20146 \emph default
20147  of
20148 \family typewriter
20149  printf().
20150
20151 \family default
20152  For the mcs51 there additionally are assembly versions 
20153 \family typewriter
20154 printf_tiny()
20155 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20156
20157 \end_inset
20158
20159
20160 \family default
20161  (subset of printf using less than 270 bytes) and 
20162 \family typewriter
20163 printf_fast()
20164 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20165
20166 \end_inset
20167
20168  
20169 \family default
20170 and
20171 \family typewriter
20172  printf_fast_f()
20173 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20174
20175 \end_inset
20176
20177
20178 \family default
20179  (floating-point aware version of printf_fast) which should fit the requirements
20180  of many embedded systems (printf_fast() can be customized by unsetting
20181  #defines to 
20182 \emph on
20183 not
20184 \emph default
20185  support long variables and field widths).
20186  Be sure to use only one of these printf options within a project.
20187 \newline
20188
20189 \end_layout
20190
20191 \begin_layout Standard
20192 Feature matrix of different 
20193 \emph on
20194 printf
20195 \emph default
20196  options on mcs51.
20197 \end_layout
20198
20199 \begin_layout Standard
20200 \begin_inset Tabular
20201 <lyxtabular version="3" rows="14" columns="7">
20202 <features islongtable="true">
20203 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20204 <column alignment="center" valignment="top" leftline="true" width="0">
20205 <column alignment="center" valignment="top" leftline="true" width="12col%">
20206 <column alignment="center" valignment="top" leftline="true" width="10col%">
20207 <column alignment="center" valignment="top" leftline="true" width="0">
20208 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20209 <column alignment="center" valignment="top" rightline="true" width="0">
20210 <row topline="true" bottomline="true" endhead="true">
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20212 \begin_inset Text
20213
20214 \begin_layout Standard
20215
20216 \series bold
20217 \size large
20218 mcs51
20219 \end_layout
20220
20221 \end_inset
20222 </cell>
20223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 \begin_inset Text
20225
20226 \begin_layout Standard
20227 printf
20228 \begin_inset LatexCommand \index{printf}
20229
20230 \end_inset
20231
20232
20233 \end_layout
20234
20235 \end_inset
20236 </cell>
20237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20238 \begin_inset Text
20239
20240 \begin_layout Standard
20241 printf 
20242 \size scriptsize
20243 USE_FLOATS=1
20244 \end_layout
20245
20246 \end_inset
20247 </cell>
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20249 \begin_inset Text
20250
20251 \begin_layout Standard
20252 printf_small
20253 \end_layout
20254
20255 \end_inset
20256 </cell>
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20258 \begin_inset Text
20259
20260 \begin_layout Standard
20261 printf_fast
20262 \end_layout
20263
20264 \end_inset
20265 </cell>
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20267 \begin_inset Text
20268
20269 \begin_layout Standard
20270 printf_fast_f
20271 \end_layout
20272
20273 \end_inset
20274 </cell>
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20276 \begin_inset Text
20277
20278 \begin_layout Standard
20279 printf_tiny
20280 \end_layout
20281
20282 \end_inset
20283 </cell>
20284 </row>
20285 <row topline="true" endhead="true">
20286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20287 \begin_inset Text
20288
20289 \begin_layout Standard
20290 filename
20291 \end_layout
20292
20293 \end_inset
20294 </cell>
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20296 \begin_inset Text
20297
20298 \begin_layout Standard
20299
20300 \size scriptsize
20301 printf_large.c
20302 \end_layout
20303
20304 \end_inset
20305 </cell>
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_inset Text
20308
20309 \begin_layout Standard
20310
20311 \size scriptsize
20312 printf_large.c
20313 \end_layout
20314
20315 \end_inset
20316 </cell>
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20318 \begin_inset Text
20319
20320 \begin_layout Standard
20321
20322 \size scriptsize
20323 printfl.c
20324 \end_layout
20325
20326 \end_inset
20327 </cell>
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20329 \begin_inset Text
20330
20331 \begin_layout Standard
20332
20333 \size scriptsize
20334 printf_fast.c
20335 \end_layout
20336
20337 \end_inset
20338 </cell>
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20340 \begin_inset Text
20341
20342 \begin_layout Standard
20343
20344 \size scriptsize
20345 printf_fast_f.c
20346 \end_layout
20347
20348 \end_inset
20349 </cell>
20350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20351 \begin_inset Text
20352
20353 \begin_layout Standard
20354
20355 \size scriptsize
20356 printf_tiny.c
20357 \end_layout
20358
20359 \end_inset
20360 </cell>
20361 </row>
20362 <row topline="true" endhead="true">
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20364 \begin_inset Text
20365
20366 \begin_layout Standard
20367 \begin_inset Quotes sld
20368 \end_inset
20369
20370 Hello World
20371 \begin_inset Quotes srd
20372 \end_inset
20373
20374  size
20375 \end_layout
20376
20377 \begin_layout Standard
20378 small / large
20379 \end_layout
20380
20381 \end_inset
20382 </cell>
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \begin_layout Standard
20387 1.7k / 2.4k
20388 \end_layout
20389
20390 \end_inset
20391 </cell>
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20393 \begin_inset Text
20394
20395 \begin_layout Standard
20396 4.3k / 5.6k
20397 \end_layout
20398
20399 \end_inset
20400 </cell>
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20402 \begin_inset Text
20403
20404 \begin_layout Standard
20405 1.2k / 1.8k
20406 \end_layout
20407
20408 \end_inset
20409 </cell>
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20411 \begin_inset Text
20412
20413 \begin_layout Standard
20414 1.3k / 1.3k
20415 \end_layout
20416
20417 \end_inset
20418 </cell>
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20420 \begin_inset Text
20421
20422 \begin_layout Standard
20423 1.9k / 1.9k
20424 \end_layout
20425
20426 \end_inset
20427 </cell>
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20429 \begin_inset Text
20430
20431 \begin_layout Standard
20432 0.44k / 0.44k
20433 \end_layout
20434
20435 \end_inset
20436 </cell>
20437 </row>
20438 <row topline="true" endhead="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20440 \begin_inset Text
20441
20442 \begin_layout Standard
20443 code size
20444 \end_layout
20445
20446 \begin_layout Standard
20447 small / large
20448 \end_layout
20449
20450 \end_inset
20451 </cell>
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_inset Text
20454
20455 \begin_layout Standard
20456 1.4k / 2.0k
20457 \end_layout
20458
20459 \end_inset
20460 </cell>
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20462 \begin_inset Text
20463
20464 \begin_layout Standard
20465 2.8k / 3.7k
20466 \end_layout
20467
20468 \end_inset
20469 </cell>
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20471 \begin_inset Text
20472
20473 \begin_layout Standard
20474 0.45k / 0.47k (+ _ltoa)
20475 \end_layout
20476
20477 \end_inset
20478 </cell>
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20480 \begin_inset Text
20481
20482 \begin_layout Standard
20483 1.2k / 1.2k
20484 \end_layout
20485
20486 \end_inset
20487 </cell>
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20489 \begin_inset Text
20490
20491 \begin_layout Standard
20492 1.6k / 1.6k
20493 \end_layout
20494
20495 \end_inset
20496 </cell>
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20498 \begin_inset Text
20499
20500 \begin_layout Standard
20501 0.26k / 0.26k
20502 \end_layout
20503
20504 \end_inset
20505 </cell>
20506 </row>
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_inset Text
20510
20511 \begin_layout Standard
20512 formats
20513 \end_layout
20514
20515 \end_inset
20516 </cell>
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20518 \begin_inset Text
20519
20520 \begin_layout Standard
20521 cdi
20522 \emph on
20523 o
20524 \emph default
20525 psux
20526 \end_layout
20527
20528 \end_inset
20529 </cell>
20530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20531 \begin_inset Text
20532
20533 \begin_layout Standard
20534
20535 \family roman
20536 \series medium
20537 \shape up
20538 \size normal
20539 \emph off
20540 \bar no
20541 \noun off
20542 \color none
20543 cd
20544 \family default
20545 \series default
20546 \shape default
20547 \size default
20548 \emph default
20549 \bar default
20550 \noun default
20551 f
20552 \family roman
20553 \series medium
20554 \shape up
20555 \size normal
20556 \emph off
20557 \bar no
20558 \noun off
20559 i
20560 \family default
20561 \series default
20562 \shape default
20563 \size default
20564 \emph on
20565 \bar default
20566 \noun default
20567 o
20568 \family roman
20569 \series medium
20570 \shape up
20571 \size normal
20572 \emph off
20573 \bar no
20574 \noun off
20575 psux
20576 \end_layout
20577
20578 \end_inset
20579 </cell>
20580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20581 \begin_inset Text
20582
20583 \begin_layout Standard
20584 c
20585 \family roman
20586 \series medium
20587 \shape up
20588 \size normal
20589 \emph off
20590 \bar no
20591 \noun off
20592 \color none
20593 d
20594 \family default
20595 \series default
20596 \shape default
20597 \size default
20598 \emph on
20599 \bar default
20600 \noun default
20601 o
20602 \family roman
20603 \series medium
20604 \shape up
20605 \size normal
20606 \emph off
20607 \bar no
20608 \noun off
20609 s
20610 \family default
20611 \series default
20612 \shape default
20613 \size default
20614 \emph default
20615 \bar default
20616 \noun default
20617 x
20618 \end_layout
20619
20620 \end_inset
20621 </cell>
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20623 \begin_inset Text
20624
20625 \begin_layout Standard
20626 cdsux
20627 \end_layout
20628
20629 \end_inset
20630 </cell>
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20632 \begin_inset Text
20633
20634 \begin_layout Standard
20635 cdfsux
20636 \end_layout
20637
20638 \end_inset
20639 </cell>
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20641 \begin_inset Text
20642
20643 \begin_layout Standard
20644 cdsux
20645 \end_layout
20646
20647 \end_inset
20648 </cell>
20649 </row>
20650 <row topline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20652 \begin_inset Text
20653
20654 \begin_layout Standard
20655 long (32 bit) support
20656 \end_layout
20657
20658 \end_inset
20659 </cell>
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20661 \begin_inset Text
20662
20663 \begin_layout Standard
20664 x
20665 \end_layout
20666
20667 \end_inset
20668 </cell>
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20670 \begin_inset Text
20671
20672 \begin_layout Standard
20673 x
20674 \end_layout
20675
20676 \end_inset
20677 </cell>
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20679 \begin_inset Text
20680
20681 \begin_layout Standard
20682 x
20683 \end_layout
20684
20685 \end_inset
20686 </cell>
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20688 \begin_inset Text
20689
20690 \begin_layout Standard
20691 x
20692 \end_layout
20693
20694 \end_inset
20695 </cell>
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20697 \begin_inset Text
20698
20699 \begin_layout Standard
20700
20701 \family roman
20702 \series medium
20703 \shape up
20704 \size normal
20705 \emph off
20706 \bar no
20707 \noun off
20708 \color none
20709 x
20710 \end_layout
20711
20712 \end_inset
20713 </cell>
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20715 \begin_inset Text
20716
20717 \begin_layout Standard
20718 -
20719 \end_layout
20720
20721 \end_inset
20722 </cell>
20723 </row>
20724 <row topline="true">
20725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20726 \begin_inset Text
20727
20728 \begin_layout Standard
20729 byte arguments on stack
20730 \end_layout
20731
20732 \end_inset
20733 </cell>
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20735 \begin_inset Text
20736
20737 \begin_layout Standard
20738 b
20739 \end_layout
20740
20741 \end_inset
20742 </cell>
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20744 \begin_inset Text
20745
20746 \begin_layout Standard
20747 b
20748 \end_layout
20749
20750 \end_inset
20751 </cell>
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20753 \begin_inset Text
20754
20755 \begin_layout Standard
20756 -
20757 \end_layout
20758
20759 \end_inset
20760 </cell>
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20762 \begin_inset Text
20763
20764 \begin_layout Standard
20765 -
20766 \end_layout
20767
20768 \end_inset
20769 </cell>
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20771 \begin_inset Text
20772
20773 \begin_layout Standard
20774 -
20775 \end_layout
20776
20777 \end_inset
20778 </cell>
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20780 \begin_inset Text
20781
20782 \begin_layout Standard
20783 -
20784 \end_layout
20785
20786 \end_inset
20787 </cell>
20788 </row>
20789 <row topline="true">
20790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20791 \begin_inset Text
20792
20793 \begin_layout Standard
20794 float format
20795 \begin_inset LatexCommand \index{Floating point support}
20796
20797 \end_inset
20798
20799
20800 \end_layout
20801
20802 \end_inset
20803 </cell>
20804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20805 \begin_inset Text
20806
20807 \begin_layout Standard
20808 -
20809 \end_layout
20810
20811 \end_inset
20812 </cell>
20813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20814 \begin_inset Text
20815
20816 \begin_layout Standard
20817 %f
20818 \end_layout
20819
20820 \end_inset
20821 </cell>
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20823 \begin_inset Text
20824
20825 \begin_layout Standard
20826 -
20827 \end_layout
20828
20829 \end_inset
20830 </cell>
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20832 \begin_inset Text
20833
20834 \begin_layout Standard
20835 -
20836 \end_layout
20837
20838 \end_inset
20839 </cell>
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \begin_layout Standard
20844 %f
20845 \begin_inset Foot
20846 status collapsed
20847
20848 \begin_layout Standard
20849 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20850 \end_layout
20851
20852 \end_inset
20853
20854
20855 \end_layout
20856
20857 \end_inset
20858 </cell>
20859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20860 \begin_inset Text
20861
20862 \begin_layout Standard
20863 -
20864 \end_layout
20865
20866 \end_inset
20867 </cell>
20868 </row>
20869 <row topline="true">
20870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20871 \begin_inset Text
20872
20873 \begin_layout Standard
20874 float formats %e %g
20875 \end_layout
20876
20877 \end_inset
20878 </cell>
20879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20880 \begin_inset Text
20881
20882 \begin_layout Standard
20883 -
20884 \end_layout
20885
20886 \end_inset
20887 </cell>
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20889 \begin_inset Text
20890
20891 \begin_layout Standard
20892 -
20893 \end_layout
20894
20895 \end_inset
20896 </cell>
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20898 \begin_inset Text
20899
20900 \begin_layout Standard
20901 -
20902 \end_layout
20903
20904 \end_inset
20905 </cell>
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20907 \begin_inset Text
20908
20909 \begin_layout Standard
20910 -
20911 \end_layout
20912
20913 \end_inset
20914 </cell>
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20916 \begin_inset Text
20917
20918 \begin_layout Standard
20919 -
20920 \end_layout
20921
20922 \end_inset
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \begin_layout Standard
20928 -
20929 \end_layout
20930
20931 \end_inset
20932 </cell>
20933 </row>
20934 <row topline="true" bottomline="true">
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20936 \begin_inset Text
20937
20938 \begin_layout Standard
20939 field width
20940 \end_layout
20941
20942 \end_inset
20943 </cell>
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20945 \begin_inset Text
20946
20947 \begin_layout Standard
20948 x
20949 \end_layout
20950
20951 \end_inset
20952 </cell>
20953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20954 \begin_inset Text
20955
20956 \begin_layout Standard
20957 x
20958 \end_layout
20959
20960 \end_inset
20961 </cell>
20962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20963 \begin_inset Text
20964
20965 \begin_layout Standard
20966 -
20967 \end_layout
20968
20969 \end_inset
20970 </cell>
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20972 \begin_inset Text
20973
20974 \begin_layout Standard
20975 x
20976 \end_layout
20977
20978 \end_inset
20979 </cell>
20980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20981 \begin_inset Text
20982
20983 \begin_layout Standard
20984 x
20985 \end_layout
20986
20987 \end_inset
20988 </cell>
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20990 \begin_inset Text
20991
20992 \begin_layout Standard
20993 -
20994 \end_layout
20995
20996 \end_inset
20997 </cell>
20998 </row>
20999 <row bottomline="true">
21000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21001 \begin_inset Text
21002
21003 \begin_layout Standard
21004 string speed
21005 \begin_inset Foot
21006 status collapsed
21007
21008 \begin_layout Standard
21009 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21010 \backslash
21011 r', '
21012 \backslash
21013 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21014 \end_layout
21015
21016 \end_inset
21017
21018 ,
21019 \end_layout
21020
21021 \begin_layout Standard
21022 small / large
21023 \end_layout
21024
21025 \end_inset
21026 </cell>
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21028 \begin_inset Text
21029
21030 \begin_layout Standard
21031 1.52 / 2.59 ms
21032 \end_layout
21033
21034 \end_inset
21035 </cell>
21036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21037 \begin_inset Text
21038
21039 \begin_layout Standard
21040 1.53 / 2.62 ms
21041 \end_layout
21042
21043 \end_inset
21044 </cell>
21045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21046 \begin_inset Text
21047
21048 \begin_layout Standard
21049 0.92 / 0.93 ms
21050 \end_layout
21051
21052 \end_inset
21053 </cell>
21054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21055 \begin_inset Text
21056
21057 \begin_layout Standard
21058 0.45 / 0.45 ms
21059 \end_layout
21060
21061 \end_inset
21062 </cell>
21063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21064 \begin_inset Text
21065
21066 \begin_layout Standard
21067 0.46 / 0.46 ms
21068 \end_layout
21069
21070 \end_inset
21071 </cell>
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21073 \begin_inset Text
21074
21075 \begin_layout Standard
21076 0.45 / 0.45 ms
21077 \end_layout
21078
21079 \end_inset
21080 </cell>
21081 </row>
21082 <row bottomline="true">
21083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21084 \begin_inset Text
21085
21086 \begin_layout Standard
21087 int speed
21088 \begin_inset Foot
21089 status collapsed
21090
21091 \begin_layout Standard
21092 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21093  putchar()
21094 \end_layout
21095
21096 \end_inset
21097
21098 ,
21099 \end_layout
21100
21101 \begin_layout Standard
21102 small / large
21103 \end_layout
21104
21105 \end_inset
21106 </cell>
21107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21108 \begin_inset Text
21109
21110 \begin_layout Standard
21111 3.01 / 3.61 ms
21112 \end_layout
21113
21114 \end_inset
21115 </cell>
21116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21117 \begin_inset Text
21118
21119 \begin_layout Standard
21120 3.01 / 3.61 ms
21121 \end_layout
21122
21123 \end_inset
21124 </cell>
21125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21126 \begin_inset Text
21127
21128 \begin_layout Standard
21129 3.51 / 18.13 ms
21130 \end_layout
21131
21132 \end_inset
21133 </cell>
21134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21135 \begin_inset Text
21136
21137 \begin_layout Standard
21138 0.22 / 0.22 ms
21139 \end_layout
21140
21141 \end_inset
21142 </cell>
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21144 \begin_inset Text
21145
21146 \begin_layout Standard
21147 0.23 / 0.23 ms
21148 \end_layout
21149
21150 \end_inset
21151 </cell>
21152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21153 \begin_inset Text
21154
21155 \begin_layout Standard
21156 0.25 / 0.25 ms
21157 \begin_inset Foot
21158 status collapsed
21159
21160 \begin_layout Standard
21161 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21162 \end_layout
21163
21164 \end_inset
21165
21166
21167 \end_layout
21168
21169 \end_inset
21170 </cell>
21171 </row>
21172 <row bottomline="true">
21173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21174 \begin_inset Text
21175
21176 \begin_layout Standard
21177 long speed
21178 \begin_inset Foot
21179 status collapsed
21180
21181 \begin_layout Standard
21182 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21183  empty putchar()
21184 \end_layout
21185
21186 \end_inset
21187
21188 ,
21189 \end_layout
21190
21191 \begin_layout Standard
21192 small / large
21193 \end_layout
21194
21195 \end_inset
21196 </cell>
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21198 \begin_inset Text
21199
21200 \begin_layout Standard
21201 5.37 / 6.31 ms
21202 \end_layout
21203
21204 \end_inset
21205 </cell>
21206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21207 \begin_inset Text
21208
21209 \begin_layout Standard
21210 5.37 / 6.31 ms
21211 \end_layout
21212
21213 \end_inset
21214 </cell>
21215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21216 \begin_inset Text
21217
21218 \begin_layout Standard
21219 8.71 / 40.65 ms
21220 \end_layout
21221
21222 \end_inset
21223 </cell>
21224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21225 \begin_inset Text
21226
21227 \begin_layout Standard
21228 0.40 / 0.40 ms
21229 \end_layout
21230
21231 \end_inset
21232 </cell>
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21234 \begin_inset Text
21235
21236 \begin_layout Standard
21237 0.40 / 0.40 ms
21238 \end_layout
21239
21240 \end_inset
21241 </cell>
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21243 \begin_inset Text
21244
21245 \begin_layout Standard
21246 -
21247 \end_layout
21248
21249 \end_inset
21250 </cell>
21251 </row>
21252 <row bottomline="true">
21253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21254 \begin_inset Text
21255
21256 \begin_layout Standard
21257 float speed
21258 \begin_inset Foot
21259 status collapsed
21260
21261 \begin_layout Standard
21262 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21263  empty putchar()
21264 \end_layout
21265
21266 \end_inset
21267
21268 ,
21269 \end_layout
21270
21271 \begin_layout Standard
21272 small / large
21273 \end_layout
21274
21275 \end_inset
21276 </cell>
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21278 \begin_inset Text
21279
21280 \begin_layout Standard
21281 -
21282 \end_layout
21283
21284 \end_inset
21285 </cell>
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \begin_layout Standard
21290 7.49 / 22.47 ms
21291 \end_layout
21292
21293 \end_inset
21294 </cell>
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21296 \begin_inset Text
21297
21298 \begin_layout Standard
21299 -
21300 \end_layout
21301
21302 \end_inset
21303 </cell>
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21305 \begin_inset Text
21306
21307 \begin_layout Standard
21308 -
21309 \end_layout
21310
21311 \end_inset
21312 </cell>
21313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21314 \begin_inset Text
21315
21316 \begin_layout Standard
21317 1.04 / 1.04 ms
21318 \end_layout
21319
21320 \end_inset
21321 </cell>
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21323 \begin_inset Text
21324
21325 \begin_layout Standard
21326 -
21327 \end_layout
21328
21329 \end_inset
21330 </cell>
21331 </row>
21332 </lyxtabular>
21333
21334 \end_inset
21335
21336
21337 \end_layout
21338
21339 \begin_layout Subsubsection
21340 <malloc.h>
21341 \begin_inset LatexCommand \index{malloc.h}
21342
21343 \end_inset
21344
21345
21346 \end_layout
21347
21348 \begin_layout Standard
21349 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21350  using dynamic memory allocation
21351 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21352
21353 \end_inset
21354
21355  and a default heap
21356 \begin_inset LatexCommand \index{heap (malloc)}
21357
21358 \end_inset
21359
21360  space of 1024 bytes is provided for malloc to allocate memory from.
21361  If you need a different heap size you need to recompile _heap.c with the
21362  required size defined in HEAP_SIZE.
21363  It is recommended to make a copy of this file into your project directory
21364  and compile it there with:
21365 \end_layout
21366
21367 \begin_layout Verse
21368
21369 \family typewriter
21370 sdcc -c _heap.c -D HEAD_SIZE=2048
21371 \end_layout
21372
21373 \begin_layout Standard
21374 And then link it with:
21375 \end_layout
21376
21377 \begin_layout Verse
21378
21379 \family typewriter
21380 sdcc main.rel _heap.rel
21381 \end_layout
21382
21383 \begin_layout Subsection
21384 Math functions (sinf, powf, sqrtf etc.)
21385 \end_layout
21386
21387 \begin_layout Subsubsection
21388 <math.h>
21389 \end_layout
21390
21391 \begin_layout Standard
21392 See definitions in file <math.h>.
21393 \end_layout
21394
21395 \begin_layout Subsection
21396 Other libraries
21397 \end_layout
21398
21399 \begin_layout Standard
21400 Libraries
21401 \begin_inset LatexCommand \index{Libraries}
21402
21403 \end_inset
21404
21405  included in SDCC should have a license at least as liberal as the GNU Lesser
21406  General Public License
21407 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21408
21409 \end_inset
21410
21411  
21412 \emph on
21413 LGPL
21414 \emph default
21415 .
21416 \end_layout
21417
21418 \begin_layout Standard
21419 \begin_inset Note Note
21420 status collapsed
21421
21422 \begin_layout Standard
21423 license statements for the libraries are missing.
21424  sdcc/device/lib/ser_ir.c
21425 \end_layout
21426
21427 \begin_layout Standard
21428 or _decdptr f.e.
21429  come with a GPL (as opposed to LGPL) License - this will not be liberal
21430  enough for many embedded programmers.
21431 \end_layout
21432
21433 \end_inset
21434
21435
21436 \end_layout
21437
21438 \begin_layout Standard
21439 If you have ported some library or want to share experience about some code
21440  which f.e.
21441  falls into any of these categories Busses (I
21442 \begin_inset Formula $^{\textrm{2}}$
21443 \end_inset
21444
21445 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21446  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21447  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21448 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21449
21450 \end_inset
21451
21452 \InsetSpace ~
21453 would certainly like to hear about it.
21454 \end_layout
21455
21456 \begin_layout Standard
21457 Programmers coding for embedded systems are not especially famous for being
21458  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21459 e these references are very valuable.
21460  Let's help to create a climate where information is shared.
21461 \begin_inset VSpace bigskip
21462 \end_inset
21463
21464
21465 \end_layout
21466
21467 \begin_layout Section
21468 Memory Models
21469 \end_layout
21470
21471 \begin_layout Subsection
21472 MCS51 Memory Models
21473 \begin_inset LatexCommand \index{Memory model}
21474
21475 \end_inset
21476
21477
21478 \begin_inset LatexCommand \index{MCS51 memory model}
21479
21480 \end_inset
21481
21482
21483 \end_layout
21484
21485 \begin_layout Subsubsection
21486 Small, Medium and Large
21487 \end_layout
21488
21489 \begin_layout Standard
21490 SDCC allows three memory models for MCS51 code, 
21491 \shape slanted
21492 small, medium
21493 \shape default
21494  and 
21495 \shape slanted
21496 large
21497 \shape default
21498 .
21499  Modules compiled with different memory models should 
21500 \emph on
21501 never
21502 \emph default
21503  be combined together or the results would be unpredictable.
21504  The library routines supplied with the compiler are compiled as small,
21505  medium and large.
21506  The compiled library modules are contained in separate directories as small,
21507  medium and large so that you can link to the appropriate set.
21508 \end_layout
21509
21510 \begin_layout Standard
21511 When the medium or large model is used all variables declared without a
21512  storage class will be allocated into the external ram, this includes all
21513  parameters and local variables (for non-reentrant
21514 \begin_inset LatexCommand \index{reentrant}
21515
21516 \end_inset
21517
21518  functions).
21519  When the small model is used variables without storage class are allocated
21520  in the internal ram.
21521 \end_layout
21522
21523 \begin_layout Standard
21524 Judicious usage of the processor specific storage classes
21525 \begin_inset LatexCommand \index{Storage class}
21526
21527 \end_inset
21528
21529  and the 'reentrant' function type will yield much more efficient code,
21530  than using the large model.
21531  Several optimizations are disabled when the program is compiled using the
21532  large model, it is therefore recommended that the small model be used unless
21533  absolutely required.
21534 \end_layout
21535
21536 \begin_layout Subsubsection
21537 External Stack
21538 \begin_inset LatexCommand \label{sub:External-Stack}
21539
21540 \end_inset
21541
21542
21543 \begin_inset LatexCommand \index{stack}
21544
21545 \end_inset
21546
21547
21548 \begin_inset LatexCommand \index{External stack (mcs51)}
21549
21550 \end_inset
21551
21552
21553 \end_layout
21554
21555 \begin_layout Standard
21556 The external stack (-
21557 \begin_inset ERT
21558 status collapsed
21559
21560 \begin_layout Standard
21561
21562
21563 \backslash
21564 /
21565 \end_layout
21566
21567 \end_inset
21568
21569 -xstack option
21570 \begin_inset LatexCommand \index{-\/-xstack}
21571
21572 \end_inset
21573
21574 ) is located in pdata
21575 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21576
21577 \end_inset
21578
21579  memory (usually at the start of the external ram segment) and uses all
21580  unused space in pdata (max.
21581  256 bytes).
21582  When -
21583 \begin_inset ERT
21584 status collapsed
21585
21586 \begin_layout Standard
21587
21588
21589 \backslash
21590 /
21591 \end_layout
21592
21593 \end_inset
21594
21595 -xstack option is used to compile the program, the parameters and local
21596  variables
21597 \begin_inset LatexCommand \index{local variables}
21598
21599 \end_inset
21600
21601  of all reentrant functions are allocated in this area.
21602  This option is provided for programs with large stack space requirements.
21603  When used with the -
21604 \begin_inset ERT
21605 status collapsed
21606
21607 \begin_layout Standard
21608
21609
21610 \backslash
21611 /
21612 \end_layout
21613
21614 \end_inset
21615
21616 -stack-auto
21617 \begin_inset LatexCommand \index{-\/-stack-auto}
21618
21619 \end_inset
21620
21621  option, all parameters and local variables are allocated on the external
21622  stack (note: support libraries will need to be recompiled with the same
21623  options.
21624  There is a predefined target in the library makefile).
21625 \end_layout
21626
21627 \begin_layout Standard
21628 The compiler outputs the higher order address byte of the external ram segment
21629  into port P2
21630 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21631
21632 \end_inset
21633
21634  (see also section 
21635 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21636
21637 \end_inset
21638
21639 ), therefore when using the External Stack option, this port 
21640 \emph on
21641 may not
21642 \emph default
21643  be used by the application program.
21644 \end_layout
21645
21646 \begin_layout Subsection
21647 DS390 Memory Model
21648 \begin_inset LatexCommand \index{Memory model}
21649
21650 \end_inset
21651
21652
21653 \begin_inset LatexCommand \index{DS390 memory model}
21654
21655 \end_inset
21656
21657
21658 \end_layout
21659
21660 \begin_layout Standard
21661 The only model supported is Flat 24
21662 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21663
21664 \end_inset
21665
21666 .
21667  This generates code for the 24 bit contiguous addressing mode of the Dallas
21668  DS80C390 part.
21669  In this mode, up to four meg of external RAM or code space can be directly
21670  addressed.
21671  See the data sheets at www.dalsemi.com for further information on this part.
21672 \newline
21673
21674 \newline
21675 Note
21676  that the compiler does not generate any code to place the processor into
21677  24 bitmode (although 
21678 \emph on
21679 tinibios
21680 \emph default
21681  in the ds390 libraries will do that for you).
21682  If you don't use 
21683 \emph on
21684 tinibios
21685 \emph default
21686
21687 \begin_inset LatexCommand \index{Tinibios (DS390)}
21688
21689 \end_inset
21690
21691 , the boot loader or similar code must ensure that the processor is in 24
21692  bit contiguous addressing mode before calling the SDCC startup code.
21693 \newline
21694
21695 \newline
21696 Like
21697  the 
21698 \emph on
21699 -
21700 \begin_inset ERT
21701 status collapsed
21702
21703 \begin_layout Standard
21704
21705
21706 \backslash
21707 /
21708 \end_layout
21709
21710 \end_inset
21711
21712 -model-large
21713 \emph default
21714  option, variables will by default be placed into the XDATA segment.
21715  
21716 \newline
21717
21718 \newline
21719 Segments may be placed anywhere in the 4 meg address space using the usual
21720  -
21721 \begin_inset ERT
21722 status collapsed
21723
21724 \begin_layout Standard
21725
21726
21727 \backslash
21728 /
21729 \end_layout
21730
21731 \end_inset
21732
21733 -*-loc options.
21734  Note that if any segments are located above 64K, the -r flag must be passed
21735  to the linker to generate the proper segment relocations, and the Intel
21736  HEX output format must be used.
21737  The -r flag can be passed to the linker by using the option 
21738 \emph on
21739 -Wl-r
21740 \emph default
21741  on the SDCC command line.
21742  However, currently the linker can not handle code segments > 64k.
21743 \end_layout
21744
21745 \begin_layout Section
21746 Pragmas
21747 \begin_inset LatexCommand \label{sec:Pragmas}
21748
21749 \end_inset
21750
21751
21752 \begin_inset LatexCommand \index{Pragmas}
21753
21754 \end_inset
21755
21756
21757 \end_layout
21758
21759 \begin_layout Standard
21760 Pragmas are used to turn on and/or off certain compiler options.
21761  Some of them are closely related to corresponding command-line options
21762  (see section 
21763 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21764
21765 \end_inset
21766
21767 ).
21768 \newline
21769 Pragmas should be placed before and/or after a function, placing pragmas
21770  inside a function body could have unpredictable results.
21771 \newline
21772
21773 \newline
21774 SDCC supports the
21775  following #pragma directives:
21776 \end_layout
21777
21778 \begin_layout Itemize
21779
21780 \series bold
21781 save
21782 \series default
21783
21784 \begin_inset LatexCommand \index{\#pragma save}
21785
21786 \end_inset
21787
21788  - this will save most current options to the save/restore stack.
21789  See #pragma\InsetSpace ~
21790 restore.
21791 \end_layout
21792
21793 \begin_layout Itemize
21794
21795 \series bold
21796 restore
21797 \series default
21798
21799 \begin_inset LatexCommand \index{\#pragma restore}
21800
21801 \end_inset
21802
21803  - will restore saved options from the last save.
21804  saves & restores can be nested.
21805  SDCC uses a save/restore stack: save pushes current options to the stack,
21806  restore pulls current options from the stack.
21807  See #pragma\InsetSpace ~
21808 save.
21809 \newline
21810
21811 \end_layout
21812
21813 \begin_layout Itemize
21814
21815 \series bold
21816 callee_saves
21817 \series default
21818
21819 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21820
21821 \end_inset
21822
21823
21824 \begin_inset LatexCommand \index{function prologue}
21825
21826 \end_inset
21827
21828  function1[,function2[,function3...]] 
21829 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21830
21831 \end_inset
21832
21833 - The compiler by default uses a caller saves convention for register saving
21834  across function calls, however this can cause unnecessary register pushing
21835  and popping
21836 \begin_inset LatexCommand \index{push/pop}
21837
21838 \end_inset
21839
21840  when calling small functions from larger functions.
21841  This option can be used to switch off the register saving convention for
21842  the function names specified.
21843  The compiler will not save registers when calling these functions, extra
21844  code need to be manually inserted at the entry and exit for these functions
21845  to save and restore the registers used by these functions, this can SUBSTANTIAL
21846 LY reduce code and improve run time performance of the generated code.
21847  In the future the compiler (with inter procedural analysis) may be able
21848  to determine the appropriate scheme to use for each function call.
21849  If -
21850 \begin_inset ERT
21851 status collapsed
21852
21853 \begin_layout Standard
21854
21855
21856 \backslash
21857 /
21858 \end_layout
21859
21860 \end_inset
21861
21862 -callee-saves command line option is used (see page 
21863 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21864
21865 \end_inset
21866
21867 ), the function names specified in #pragma\InsetSpace ~
21868 callee_saves
21869 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21870
21871 \end_inset
21872
21873  is appended to the list of functions specified in the command line.
21874 \end_layout
21875
21876 \begin_layout Itemize
21877
21878 \series bold
21879 exclude
21880 \series default
21881
21882 \begin_inset LatexCommand \index{\#pragma exclude}
21883
21884 \end_inset
21885
21886  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21887  of pairs of push/pop
21888 \begin_inset LatexCommand \index{push/pop}
21889
21890 \end_inset
21891
21892  instructions in 
21893 \emph on
21894 I
21895 \emph default
21896 nterrupt
21897 \begin_inset LatexCommand \index{interrupt}
21898
21899 \end_inset
21900
21901  
21902 \emph on
21903 S
21904 \emph default
21905 ervice 
21906 \emph on
21907 R
21908 \emph default
21909 outines.
21910  The directive should be placed immediately before the ISR function definition
21911  and it affects ALL ISR functions following it.
21912  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21913 exclude\InsetSpace ~
21914 none
21915 \begin_inset LatexCommand \index{\#pragma exclude}
21916
21917 \end_inset
21918
21919 .
21920  See also the related keyword _naked
21921 \begin_inset LatexCommand \index{\_naked}
21922
21923 \end_inset
21924
21925
21926 \begin_inset LatexCommand \index{\_\_naked}
21927
21928 \end_inset
21929
21930 .
21931 \end_layout
21932
21933 \begin_layout Itemize
21934
21935 \series bold
21936 less_pedantic
21937 \series default
21938
21939 \begin_inset LatexCommand \index{pedantic}
21940
21941 \end_inset
21942
21943
21944 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21945
21946 \end_inset
21947
21948  
21949 \begin_inset LatexCommand \label{ite:less_pedantic}
21950
21951 \end_inset
21952
21953 - the compiler will not warn you anymore for obvious mistakes, you're on
21954  your own now ;-( .
21955  See also the command line option -
21956 \begin_inset ERT
21957 status collapsed
21958
21959 \begin_layout Standard
21960
21961
21962 \backslash
21963 /
21964 \end_layout
21965
21966 \end_inset
21967
21968 -less-pedantic 
21969 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21970
21971 \end_inset
21972
21973 .
21974  
21975 \newline
21976 More specifically, the following warnings will be disabled: 
21977 \shape italic
21978 comparison is always [true/false] due to limited range of data type
21979 \shape default
21980  (94); 
21981 \shape italic
21982 overflow in implicit constant conversion
21983 \shape default
21984  (158); [the (in)famous] 
21985 \shape italic
21986 conditional flow changed by optimizer: so said EVELYN the modified DOG
21987 \shape default
21988  (110); 
21989 \shape italic
21990 function '[function name]' must return value
21991 \shape default
21992  (59).
21993  
21994 \newline
21995 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21996  level) are disabled, too, namely: 
21997 \shape italic
21998 constant value '[
21999 \begin_inset Note Note
22000 status collapsed
22001
22002 \begin_layout Standard
22003 dunno what comes here - this warning appears to be unused altogether
22004 \end_layout
22005
22006 \end_inset
22007
22008 ]', out of range
22009 \shape default
22010  (81); 
22011 \shape italic
22012 [left/right] shifting more than size of object changed to zero
22013 \shape default
22014  (116); 
22015 \shape italic
22016 unreachable code
22017 \shape default
22018  (126); 
22019 \shape italic
22020 integer overflow in expression
22021 \shape default
22022  (165); 
22023 \shape italic
22024 unmatched #pragma save and #pragma restore
22025 \shape default
22026  (170); 
22027 \shape italic
22028 comparison of 'signed char' with 'unsigned char' requires promotion to int
22029 \shape default
22030  (185); 
22031 \shape italic
22032 ISO C90 does not support flexible array members
22033 \shape default
22034  (187); 
22035 \shape italic
22036 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22037 nam
22038 e]':\InsetSpace ~
22039 [
22040 \begin_inset Note Note
22041 status collapsed
22042
22043 \begin_layout Standard
22044 appears to be always blank - what was supposed to be here?
22045 \end_layout
22046
22047 \end_inset
22048
22049 ]
22050 \shape default
22051  (114); 
22052 \shape italic
22053 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22054  complexity [number]
22055 \shape default
22056  (121).
22057 \end_layout
22058
22059 \begin_layout Itemize
22060
22061 \series bold
22062 disable_warning
22063 \series default
22064  <nnnn>
22065 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22066
22067 \end_inset
22068
22069  - the compiler will not warn you anymore about warning number <nnnn>.
22070 \end_layout
22071
22072 \begin_layout Itemize
22073
22074 \series bold
22075 nogcse
22076 \series default
22077
22078 \begin_inset LatexCommand \index{\#pragma nogcse}
22079
22080 \end_inset
22081
22082  - will stop global common subexpression elimination.
22083 \end_layout
22084
22085 \begin_layout Itemize
22086
22087 \series bold
22088 noinduction
22089 \series default
22090
22091 \begin_inset LatexCommand \index{\#pragma noinduction}
22092
22093 \end_inset
22094
22095  - will stop loop induction optimizations.
22096 \end_layout
22097
22098 \begin_layout Itemize
22099
22100 \series bold
22101 noinvariant
22102 \series default
22103
22104 \begin_inset LatexCommand \index{\#pragma noinvariant}
22105
22106 \end_inset
22107
22108  - will not do loop invariant optimizations.
22109  For more details see Loop Invariants in section
22110 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22111
22112 \end_inset
22113
22114 .
22115 \end_layout
22116
22117 \begin_layout Itemize
22118
22119 \series bold
22120 noiv
22121 \series default
22122
22123 \begin_inset LatexCommand \index{\#pragma noiv}
22124
22125 \end_inset
22126
22127  - Do not generate interrupt
22128 \begin_inset LatexCommand \index{interrupt}
22129
22130 \end_inset
22131
22132  vector table
22133 \begin_inset LatexCommand \index{interrupt vector table}
22134
22135 \end_inset
22136
22137  entries for all ISR functions defined after the pragma.
22138  This is useful in cases where the interrupt vector table must be defined
22139  manually, or when there is a secondary, manually defined interrupt vector
22140  table (e.g.
22141  for the autovector feature of the Cypress EZ-USB FX2).
22142  More elegantly this can be achieved by obmitting the optional interrupt
22143  number after the interrupt keyword, see section 
22144 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22145
22146 \end_inset
22147
22148 \InsetSpace ~
22149 about interrupts.
22150 \end_layout
22151
22152 \begin_layout Itemize
22153
22154 \series bold
22155 nojtbound
22156 \series default
22157
22158 \begin_inset LatexCommand \index{\#pragma nojtbound}
22159
22160 \end_inset
22161
22162  - will not generate code for boundary value checking, when switch statements
22163  are turned into jump-tables (dangerous).
22164  For more details see section 
22165 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22166
22167 \end_inset
22168
22169 .
22170 \end_layout
22171
22172 \begin_layout Itemize
22173
22174 \series bold
22175 noloopreverse
22176 \series default
22177
22178 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22179
22180 \end_inset
22181
22182  - Will not do loop reversal optimization
22183 \end_layout
22184
22185 \begin_layout Itemize
22186
22187 \series bold
22188 nooverlay
22189 \series default
22190
22191 \begin_inset LatexCommand \index{\#pragma nooverlay}
22192
22193 \end_inset
22194
22195  - the compiler will not overlay the parameters and local variables of a
22196  function.
22197 \end_layout
22198
22199 \begin_layout Itemize
22200
22201 \series bold
22202 stackauto
22203 \series default
22204
22205 \begin_inset LatexCommand \index{\#pragma stackauto}
22206
22207 \end_inset
22208
22209 - See option -
22210 \begin_inset ERT
22211 status collapsed
22212
22213 \begin_layout Standard
22214
22215
22216 \backslash
22217 /
22218 \end_layout
22219
22220 \end_inset
22221
22222 -stack-auto
22223 \begin_inset LatexCommand \index{-\/-stack-auto}
22224
22225 \end_inset
22226
22227  and section 
22228 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22229
22230 \end_inset
22231
22232  Parameters and Local Variables.
22233 \end_layout
22234
22235 \begin_layout Itemize
22236
22237 \series bold
22238 opt_code_speed
22239 \series default
22240  
22241 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22242
22243 \end_inset
22244
22245 - The compiler will optimize code generation towards fast code, possibly
22246  at the expense of code size.
22247  Currently this has little effect.
22248 \end_layout
22249
22250 \begin_layout Itemize
22251
22252 \series bold
22253 opt_code_size
22254 \series default
22255  
22256 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22257
22258 \end_inset
22259
22260 - The compiler will optimize code generation towards compact code, possibly
22261  at the expense of code speed.
22262  Currently this has little effect.
22263 \end_layout
22264
22265 \begin_layout Itemize
22266
22267 \series bold
22268 opt_code_balanced
22269 \series default
22270  
22271 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22272
22273 \end_inset
22274
22275 - The compiler will attempt to generate code that is both compact and fast,
22276  as long as meeting one goal is not a detriment to the other (this is the
22277  default).
22278  
22279 \end_layout
22280
22281 \begin_layout Itemize
22282
22283 \series bold
22284 std_sdcc89
22285 \series default
22286  
22287 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22288
22289 \end_inset
22290
22291 - Generally follow the C89 standard, but allow SDCC features that conflict
22292  with the standard (default).
22293 \end_layout
22294
22295 \begin_layout Itemize
22296
22297 \series bold
22298 std_c89
22299 \series default
22300  
22301 \begin_inset LatexCommand \index{\#pragma std\_c89}
22302
22303 \end_inset
22304
22305 - Follow the C89 standard and disable SDCC features that conflict with the
22306  standard.
22307 \end_layout
22308
22309 \begin_layout Itemize
22310
22311 \series bold
22312 std_sdcc99
22313 \series default
22314  
22315 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22316
22317 \end_inset
22318
22319 - Generally follow the C99 standard, but allow SDCC features that conflict
22320  with the standard (incomplete support).
22321 \end_layout
22322
22323 \begin_layout Itemize
22324
22325 \series bold
22326 std_c99
22327 \series default
22328  
22329 \begin_inset LatexCommand \index{\#pragma std\_c99}
22330
22331 \end_inset
22332
22333 - Follow the C99 standard and disable SDCC features that conflict with the
22334  standard (incomplete support).
22335 \end_layout
22336
22337 \begin_layout Itemize
22338
22339 \series bold
22340 codeseg
22341 \series default
22342  <name>
22343 \begin_inset LatexCommand \index{\#pragma codeseg}
22344
22345 \end_inset
22346
22347 - Use this name (max.
22348  8 characters) for the code segment.
22349  See option -
22350 \begin_inset ERT
22351 status collapsed
22352
22353 \begin_layout Standard
22354
22355
22356 \backslash
22357 /
22358 \end_layout
22359
22360 \end_inset
22361
22362 -codeseg.
22363 \end_layout
22364
22365 \begin_layout Itemize
22366
22367 \series bold
22368 constseg
22369 \series default
22370  <name>
22371 \begin_inset LatexCommand \index{\#pragma constseg}
22372
22373 \end_inset
22374
22375 - Use this name (max.
22376  8 characters) for the const segment.
22377  See option -
22378 \begin_inset ERT
22379 status collapsed
22380
22381 \begin_layout Standard
22382
22383
22384 \backslash
22385 /
22386 \end_layout
22387
22388 \end_inset
22389
22390 -constseg.
22391 \end_layout
22392
22393 \begin_layout Standard
22394 The preprocessor SDCPP
22395 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22396
22397 \end_inset
22398
22399  supports the following #pragma directives:
22400 \end_layout
22401
22402 \begin_layout Itemize
22403
22404 \series bold
22405 pedantic_parse_number
22406 \series default
22407
22408 \begin_inset LatexCommand \index{pedantic}
22409
22410 \end_inset
22411
22412
22413 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22414
22415 \end_inset
22416
22417  (+ | -) 
22418 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22419
22420 \end_inset
22421
22422 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22423  properly and the macro LO_B(3) gets expanded.
22424  Default is off.
22425  See also the -
22426 \begin_inset ERT
22427 status collapsed
22428
22429 \begin_layout Standard
22430
22431
22432 \backslash
22433 /
22434 \end_layout
22435
22436 \end_inset
22437
22438 -pedantic-parse-number command line option 
22439 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22440
22441 \end_inset
22442
22443 .
22444  
22445 \newline
22446 Below is an example on how to use this pragma.
22447
22448 \emph on
22449  Note: this functionality is not in conformance with standard!
22450 \end_layout
22451
22452 \begin_layout Verse
22453
22454 \family typewriter
22455 #pragma pedantic_parse_number +
22456 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22457
22458 \end_inset
22459
22460
22461 \newline
22462
22463 \newline
22464 #define LO_B(x) ((x) & 0xff)
22465 \newline
22466
22467 \newline
22468 unsigned char foo(void)
22469 \newline
22470 {
22471 \newline
22472 \InsetSpace ~
22473 \InsetSpace ~
22474 \InsetSpace ~
22475 unsigned char c=0xfe-LO_B(3)
22476 ;
22477 \newline
22478
22479 \newline
22480 \InsetSpace ~
22481 \InsetSpace ~
22482 \InsetSpace ~
22483 return c;
22484 \newline
22485 }
22486 \newline
22487
22488 \end_layout
22489
22490 \begin_layout Itemize
22491
22492 \series bold
22493 preproc_asm
22494 \series default
22495
22496 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22497
22498 \end_inset
22499
22500  (+ | -) - switch _asm _endasm block preprocessing on / off.
22501  Default is on.
22502  You use this prama to define multilines of assembly code.
22503  This will prevent the preprocessor from changing the formating required
22504  by assembly code.
22505  Below is an example on how to use this pragma.
22506 \end_layout
22507
22508 \begin_layout Verse
22509
22510 \family typewriter
22511 #pragma preproc_asm -
22512 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22513
22514 \end_inset
22515
22516
22517 \newline
22518 #define MYDELAY _asm
22519 \newline
22520 \InsetSpace ~
22521 \InsetSpace ~
22522 \InsetSpace ~
22523 nop ;my assembly comment...
22524 \newline
22525 \InsetSpace ~
22526 \InsetSpace ~
22527 \InsetSpace ~
22528 nop
22529 \newline
22530 \InsetSpace ~
22531 \InsetSpace ~
22532 \InsetSpace ~
22533 nop
22534 \newline
22535 _endasm
22536 \newline
22537 #pragma preproc_asm
22538  +
22539 \newline
22540
22541 \newline
22542 void foo (void) 
22543 \newline
22544
22545 \newline
22546 \InsetSpace ~
22547 \InsetSpace ~
22548 \InsetSpace ~
22549  ...
22550  
22551 \newline
22552 \InsetSpace ~
22553 \InsetSpace ~
22554 \InsetSpace ~
22555  MYDELAY;
22556 \newline
22557 \InsetSpace ~
22558 \InsetSpace ~
22559 \InsetSpace ~
22560  ...
22561  
22562 \newline
22563
22564 \newline
22565
22566 \end_layout
22567
22568 \begin_layout Itemize
22569
22570 \series bold
22571 sdcc_hash
22572 \series default
22573
22574 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22575
22576 \end_inset
22577
22578  (+ | -) - Allow "naked" hash in macro definition, for example:
22579 \newline
22580
22581 \family typewriter
22582 #define DIR_LO(x) #(x & 0xff)
22583 \family default
22584
22585 \newline
22586 Default is off.
22587  Below is an example on how to use this pragma.
22588 \end_layout
22589
22590 \begin_layout Verse
22591
22592 \family typewriter
22593 #pragma preproc_asm +
22594 \newline
22595 #pragma sdcc_hash +
22596 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22597
22598 \end_inset
22599
22600
22601 \newline
22602
22603 \newline
22604 #define ROMCALL(x) 
22605 \backslash
22606
22607 \newline
22608 \InsetSpace ~
22609 \InsetSpace ~
22610 \InsetSpace ~
22611 mov R6_B3, #(x & 0xff) 
22612 \backslash
22613
22614 \newline
22615 \InsetSpace ~
22616 \InsetSpace ~
22617 \InsetSpace ~
22618 mov R7_B3, #((x >> 8) & 0xff) 
22619 \backslash
22620
22621 \newline
22622 \InsetSpace ~
22623 \InsetSpace ~
22624 \InsetSpace ~
22625 lcall __romcall
22626 \newline
22627
22628 \newline
22629 ...
22630 \newline
22631 _asm
22632 \newline
22633 ROMCALL(72)
22634 \newline
22635 _endasm;
22636 \newline
22637 ...
22638 \newline
22639
22640 \end_layout
22641
22642 \begin_layout Standard
22643 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22644 ons which might cause the compiler to generate extra stack and/or data space
22645  to store compiler generated temporary variables.
22646  This usually happens in large functions.
22647  Pragma directives should be used as shown in the following example, they
22648  are used to control options and optimizations for a given function.
22649  
22650 \end_layout
22651
22652 \begin_layout Verse
22653
22654 \family typewriter
22655 #pragma save
22656 \begin_inset LatexCommand \index{\#pragma save}
22657
22658 \end_inset
22659
22660  \InsetSpace ~
22661 \InsetSpace ~
22662 \InsetSpace ~
22663 \InsetSpace ~
22664 \InsetSpace ~
22665 \InsetSpace ~
22666 \InsetSpace ~
22667 /* save the current settings */ 
22668 \newline
22669 #pragma nogcse
22670 \begin_inset LatexCommand \index{\#pragma nogcse}
22671
22672 \end_inset
22673
22674  \InsetSpace ~
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 \InsetSpace ~
22678 \InsetSpace ~
22679 /* turnoff global subexpression elimination */ 
22680 \newline
22681 #pragma noinduction
22682 \begin_inset LatexCommand \index{\#pragma noinduction}
22683
22684 \end_inset
22685
22686  /* turn off induction optimizations */ 
22687 \newline
22688 int foo () 
22689 \newline
22690
22691 \newline
22692 \InsetSpace ~
22693  \InsetSpace ~
22694  ...
22695  
22696 \newline
22697 \InsetSpace ~
22698  \InsetSpace ~
22699  /* large code */ 
22700 \newline
22701 \InsetSpace ~
22702  \InsetSpace ~
22703  ...
22704  
22705 \newline
22706
22707 \newline
22708 #pragma restore
22709 \begin_inset LatexCommand \index{\#pragma restore}
22710
22711 \end_inset
22712
22713  /* turn the optimizations back on */
22714 \end_layout
22715
22716 \begin_layout Standard
22717 The compiler will generate a warning message when extra space is allocated.
22718  It is strongly recommended that the save and restore pragmas be used when
22719  changing options for a function.
22720 \newline
22721
22722 \newline
22723
22724 \newline
22725
22726 \end_layout
22727
22728 \begin_layout Section
22729 Defines Created by the Compiler
22730 \end_layout
22731
22732 \begin_layout Standard
22733 The compiler creates the following #defines
22734 \begin_inset LatexCommand \index{\#defines}
22735
22736 \end_inset
22737
22738
22739 \begin_inset LatexCommand \index{Defines created by the compiler}
22740
22741 \end_inset
22742
22743 :
22744 \newline
22745
22746 \end_layout
22747
22748 \begin_layout Standard
22749 \begin_inset Tabular
22750 <lyxtabular version="3" rows="15" columns="2">
22751 <features>
22752 <column alignment="left" valignment="top" leftline="true" width="3in">
22753 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22754 <row topline="true" bottomline="true">
22755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22756 \begin_inset Text
22757
22758 \begin_layout Standard
22759
22760 \series bold
22761 #define
22762 \end_layout
22763
22764 \end_inset
22765 </cell>
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22767 \begin_inset Text
22768
22769 \begin_layout Standard
22770
22771 \series bold
22772 Description
22773 \end_layout
22774
22775 \end_inset
22776 </cell>
22777 </row>
22778 <row topline="true">
22779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22780 \begin_inset Text
22781
22782 \begin_layout Standard
22783 SDCC
22784 \begin_inset LatexCommand \index{SDCC}
22785
22786 \end_inset
22787
22788  
22789 \end_layout
22790
22791 \end_inset
22792 </cell>
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22794 \begin_inset Text
22795
22796 \begin_layout Standard
22797 Always defined.
22798  Since version 2.5.6 the version number as an int (ex.
22799  256)
22800 \end_layout
22801
22802 \end_inset
22803 </cell>
22804 </row>
22805 <row topline="true">
22806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22807 \begin_inset Text
22808
22809 \begin_layout Standard
22810 SDCC_mcs51
22811 \begin_inset LatexCommand \index{SDCC\_mcs51}
22812
22813 \end_inset
22814
22815  or SDCC_ds390
22816 \begin_inset LatexCommand \index{SDCC\_ds390}
22817
22818 \end_inset
22819
22820  or SDCC_z80
22821 \begin_inset LatexCommand \index{SDCC\_z80}
22822
22823 \end_inset
22824
22825 , etc.
22826 \end_layout
22827
22828 \end_inset
22829 </cell>
22830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22831 \begin_inset Text
22832
22833 \begin_layout Standard
22834 depending on the model used (e.g.: -mds390)
22835 \end_layout
22836
22837 \end_inset
22838 </cell>
22839 </row>
22840 <row topline="true">
22841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22842 \begin_inset Text
22843
22844 \begin_layout Standard
22845 __mcs51
22846 \begin_inset LatexCommand \index{\_\_mcs51}
22847
22848 \end_inset
22849
22850 , __ds390
22851 \begin_inset LatexCommand \index{\_\_ds390}
22852
22853 \end_inset
22854
22855 , __hc08
22856 \begin_inset LatexCommand \index{\_\_hc08}
22857
22858 \end_inset
22859
22860 , __z80
22861 \begin_inset LatexCommand \index{\_\_z80}
22862
22863 \end_inset
22864
22865 , etc
22866 \end_layout
22867
22868 \end_inset
22869 </cell>
22870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22871 \begin_inset Text
22872
22873 \begin_layout Standard
22874 depending on the model used (e.g.
22875  -mz80)
22876 \end_layout
22877
22878 \end_inset
22879 </cell>
22880 </row>
22881 <row topline="true">
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22883 \begin_inset Text
22884
22885 \begin_layout Standard
22886 SDCC_STACK_AUTO
22887 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22888
22889 \end_inset
22890
22891
22892 \end_layout
22893
22894 \end_inset
22895 </cell>
22896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22897 \begin_inset Text
22898
22899 \begin_layout Standard
22900 when 
22901 \emph on
22902 -
22903 \begin_inset ERT
22904 status collapsed
22905
22906 \begin_layout Standard
22907
22908
22909 \backslash
22910 /
22911 \end_layout
22912
22913 \end_inset
22914
22915 -stack-auto
22916 \emph default
22917  option is used
22918 \end_layout
22919
22920 \end_inset
22921 </cell>
22922 </row>
22923 <row topline="true">
22924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22925 \begin_inset Text
22926
22927 \begin_layout Standard
22928 SDCC_MODEL_SMALL
22929 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22930
22931 \end_inset
22932
22933
22934 \end_layout
22935
22936 \end_inset
22937 </cell>
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22939 \begin_inset Text
22940
22941 \begin_layout Standard
22942 when 
22943 \emph on
22944 -
22945 \begin_inset ERT
22946 status collapsed
22947
22948 \begin_layout Standard
22949
22950
22951 \backslash
22952 /
22953 \end_layout
22954
22955 \end_inset
22956
22957 -model-small
22958 \emph default
22959  is used
22960 \end_layout
22961
22962 \end_inset
22963 </cell>
22964 </row>
22965 <row topline="true">
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22967 \begin_inset Text
22968
22969 \begin_layout Standard
22970 SDCC_MODEL_MEDIUM
22971 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22972
22973 \end_inset
22974
22975
22976 \end_layout
22977
22978 \end_inset
22979 </cell>
22980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22981 \begin_inset Text
22982
22983 \begin_layout Standard
22984 when 
22985 \emph on
22986 -
22987 \begin_inset ERT
22988 status collapsed
22989
22990 \begin_layout Standard
22991
22992
22993 \backslash
22994 /
22995 \end_layout
22996
22997 \end_inset
22998
22999 -model-medium
23000 \emph default
23001  is used
23002 \end_layout
23003
23004 \end_inset
23005 </cell>
23006 </row>
23007 <row topline="true">
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \begin_layout Standard
23012 SDCC_MODEL_LARGE
23013 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23014
23015 \end_inset
23016
23017
23018 \end_layout
23019
23020 \end_inset
23021 </cell>
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23023 \begin_inset Text
23024
23025 \begin_layout Standard
23026 when 
23027 \emph on
23028 -
23029 \begin_inset ERT
23030 status collapsed
23031
23032 \begin_layout Standard
23033
23034
23035 \backslash
23036 /
23037 \end_layout
23038
23039 \end_inset
23040
23041 -model-large
23042 \emph default
23043  is used
23044 \end_layout
23045
23046 \end_inset
23047 </cell>
23048 </row>
23049 <row topline="true">
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23051 \begin_inset Text
23052
23053 \begin_layout Standard
23054 SDCC_USE_XSTACK
23055 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23056
23057 \end_inset
23058
23059
23060 \end_layout
23061
23062 \end_inset
23063 </cell>
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \begin_layout Standard
23068 when 
23069 \emph on
23070 -
23071 \begin_inset ERT
23072 status collapsed
23073
23074 \begin_layout Standard
23075
23076
23077 \backslash
23078 /
23079 \end_layout
23080
23081 \end_inset
23082
23083 -xstack
23084 \emph default
23085  option is used
23086 \end_layout
23087
23088 \end_inset
23089 </cell>
23090 </row>
23091 <row topline="true">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23093 \begin_inset Text
23094
23095 \begin_layout Standard
23096 SDCC_STACK_TENBIT
23097 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23098
23099 \end_inset
23100
23101  
23102 \end_layout
23103
23104 \end_inset
23105 </cell>
23106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23107 \begin_inset Text
23108
23109 \begin_layout Standard
23110 when 
23111 \emph on
23112 -mds390
23113 \emph default
23114  is used
23115 \end_layout
23116
23117 \end_inset
23118 </cell>
23119 </row>
23120 <row topline="true">
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23122 \begin_inset Text
23123
23124 \begin_layout Standard
23125 SDCC_MODEL_FLAT24
23126 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23127
23128 \end_inset
23129
23130
23131 \end_layout
23132
23133 \end_inset
23134 </cell>
23135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23136 \begin_inset Text
23137
23138 \begin_layout Standard
23139 when 
23140 \emph on
23141 -mds390
23142 \emph default
23143  is used
23144 \end_layout
23145
23146 \end_inset
23147 </cell>
23148 </row>
23149 <row topline="true">
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23151 \begin_inset Text
23152
23153 \begin_layout Standard
23154 SDCC_REVISION
23155 \begin_inset LatexCommand \index{SDCC\_REVISION}
23156
23157 \end_inset
23158
23159
23160 \end_layout
23161
23162 \end_inset
23163 </cell>
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23165 \begin_inset Text
23166
23167 \begin_layout Standard
23168 Always defined.
23169  SDCC svn revision number
23170 \end_layout
23171
23172 \end_inset
23173 </cell>
23174 </row>
23175 <row topline="true">
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \begin_layout Standard
23180 SDCC_PARMS_IN_BANK1
23181 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23182
23183 \end_inset
23184
23185
23186 \end_layout
23187
23188 \end_inset
23189 </cell>
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23191 \begin_inset Text
23192
23193 \begin_layout Standard
23194 when 
23195 \emph on
23196 -
23197 \begin_inset ERT
23198 status collapsed
23199
23200 \begin_layout Standard
23201
23202
23203 \backslash
23204 /
23205 \end_layout
23206
23207 \end_inset
23208
23209 -parms-in-bank1
23210 \emph default
23211  is used
23212 \end_layout
23213
23214 \end_inset
23215 </cell>
23216 </row>
23217 <row topline="true">
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23219 \begin_inset Text
23220
23221 \begin_layout Standard
23222 SDCC_FLOAT_REENT
23223 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23224
23225 \end_inset
23226
23227
23228 \end_layout
23229
23230 \end_inset
23231 </cell>
23232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23233 \begin_inset Text
23234
23235 \begin_layout Standard
23236 when 
23237 \emph on
23238 -
23239 \begin_inset ERT
23240 status collapsed
23241
23242 \begin_layout Standard
23243
23244
23245 \backslash
23246 /
23247 \end_layout
23248
23249 \end_inset
23250
23251 -float-reent
23252 \emph default
23253  is used
23254 \end_layout
23255
23256 \end_inset
23257 </cell>
23258 </row>
23259 <row topline="true" bottomline="true">
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23261 \begin_inset Text
23262
23263 \begin_layout Standard
23264 SDCC_INT_LONG_REENT
23265 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23266
23267 \end_inset
23268
23269
23270 \end_layout
23271
23272 \end_inset
23273 </cell>
23274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23275 \begin_inset Text
23276
23277 \begin_layout Standard
23278 when 
23279 \emph on
23280 -
23281 \begin_inset ERT
23282 status collapsed
23283
23284 \begin_layout Standard
23285
23286
23287 \backslash
23288 /
23289 \end_layout
23290
23291 \end_inset
23292
23293 -int-long-reent
23294 \emph default
23295  is used
23296 \end_layout
23297
23298 \end_inset
23299 </cell>
23300 </row>
23301 </lyxtabular>
23302
23303 \end_inset
23304
23305
23306 \end_layout
23307
23308 \begin_layout Chapter
23309 Notes on supported Processors
23310 \end_layout
23311
23312 \begin_layout Section
23313 MCS51 variants
23314 \begin_inset LatexCommand \label{sub:MCS51-variants}
23315
23316 \end_inset
23317
23318
23319 \begin_inset LatexCommand \index{MCS51 variants}
23320
23321 \end_inset
23322
23323
23324 \end_layout
23325
23326 \begin_layout Standard
23327 MCS51 processors are available from many vendors and come in many different
23328  flavours.
23329  While they might differ considerably in respect to Special Function Registers
23330  the core MCS51 is usually not modified or is kept compatible.
23331  
23332 \end_layout
23333
23334 \begin_layout Subsection
23335 pdata access by SFR 
23336 \end_layout
23337
23338 \begin_layout Standard
23339 With the upcome of devices with internal xdata and flash memory devices
23340  using port P2
23341 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23342
23343 \end_inset
23344
23345  as dedicated I/O port is becoming more popular.
23346  Switching the high byte for pdata
23347 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23348
23349 \end_inset
23350
23351  access which was formerly done by port P2 is then achieved by a Special
23352  Function Register
23353 \begin_inset LatexCommand \index{sfr}
23354
23355 \end_inset
23356
23357 .
23358  In well-established MCS51 tradition the address of this 
23359 \emph on
23360 sfr
23361 \emph default
23362  is where the chip designers decided to put it.
23363  Needless to say that they didn't agree on a common name either.
23364  So that the startup code can correctly initialize xdata variables, you
23365  should define an sfr with the name _XPAGE
23366 \family typewriter
23367
23368 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23369
23370 \end_inset
23371
23372
23373 \family default
23374  at the appropriate location if the default, port P2, is not used for this.
23375  Some examples are:
23376 \end_layout
23377
23378 \begin_layout Verse
23379
23380 \family typewriter
23381 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23382  MPAGE */
23383 \end_layout
23384
23385 \begin_layout Verse
23386
23387 \family typewriter
23388 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23389  a.k.a.
23390  MPAGE */
23391 \end_layout
23392
23393 \begin_layout Verse
23394
23395 \family typewriter
23396 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23397  XPAGE */
23398 \end_layout
23399
23400 \begin_layout Verse
23401
23402 \family typewriter
23403 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23404  EMI0CN */
23405 \end_layout
23406
23407 \begin_layout Verse
23408
23409 \family typewriter
23410 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23411  EMI0CN */
23412 \end_layout
23413
23414 \begin_layout Standard
23415 For more exotic implementations further customizations may be needed.
23416  See section 
23417 \begin_inset LatexCommand \ref{sub:Startup-Code}
23418
23419 \end_inset
23420
23421  for other possibilities.
23422 \end_layout
23423
23424 \begin_layout Subsection
23425 Other Features available by SFR
23426 \end_layout
23427
23428 \begin_layout Standard
23429 Some MCS51 variants offer features like Double DPTR
23430 \begin_inset LatexCommand \index{DPTR}
23431
23432 \end_inset
23433
23434 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23435  These are currently not used for the MCS51 port.
23436  If you absolutely need them you can fall back to inline assembly or submit
23437  a patch to SDCC.
23438 \begin_inset VSpace bigskip
23439 \end_inset
23440
23441
23442 \end_layout
23443
23444 \begin_layout Section
23445 DS400 port
23446 \end_layout
23447
23448 \begin_layout Standard
23449 The DS80C400
23450 \begin_inset LatexCommand \index{DS80C400}
23451
23452 \end_inset
23453
23454
23455 \begin_inset LatexCommand \index{DS400}
23456
23457 \end_inset
23458
23459  microcontroller has a rich set of peripherals.
23460  In its built-in ROM library it includes functions to access some of the
23461  features, among them is a TCP stack with IP4 and IP6 support.
23462  Library headers (currently in beta status) and other files are provided
23463  at 
23464 \size footnotesize
23465
23466 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23467
23468 \end_inset
23469
23470 .
23471  
23472 \begin_inset VSpace bigskip
23473 \end_inset
23474
23475
23476 \end_layout
23477
23478 \begin_layout Section
23479 The Z80 and gbz80 port
23480 \end_layout
23481
23482 \begin_layout Standard
23483 SDCC can target both the Zilog Z80
23484 \begin_inset LatexCommand \index{Z80}
23485
23486 \end_inset
23487
23488  and the Nintendo Gameboy's Z80-like gbz80
23489 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23490
23491 \end_inset
23492
23493 .
23494  The Z80 port is passed through the same 
23495 \emph on
23496 regressions tests
23497 \begin_inset LatexCommand \index{Regression test}
23498
23499 \end_inset
23500
23501
23502 \emph default
23503  (see section 
23504 \begin_inset LatexCommand \ref{sec:Quality-control}
23505
23506 \end_inset
23507
23508 ) as the MCS51 and DS390 ports, so floating point support, support for long
23509  variables and bitfield support is fine.
23510  See mailing lists and forums about interrupt routines.
23511 \end_layout
23512
23513 \begin_layout Standard
23514 As always, the code is the authoritative reference - see z80/ralloc.c and
23515  z80/gen.c.
23516  The stack
23517 \begin_inset LatexCommand \index{Z80!stack}
23518
23519 \end_inset
23520
23521  frame is similar to that generated by the IAR Z80 compiler.
23522  IX is used as the base pointer, HL and IY are used as a temporary registers,
23523  and BC and DE are available for holding variables.
23524  Return values
23525 \begin_inset LatexCommand \index{Z80!return value}
23526
23527 \end_inset
23528
23529  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23530  bytes).
23531  The gbz80 port use the same set of registers for the return values, but
23532  in a different order of significance: E (one byte), DE (two bytes), or
23533  HLDE (four bytes).
23534 \begin_inset VSpace bigskip
23535 \end_inset
23536
23537
23538 \end_layout
23539
23540 \begin_layout Section
23541 The HC08 port
23542 \end_layout
23543
23544 \begin_layout Standard
23545 The port to the Freescale/Motorola HC08
23546 \begin_inset LatexCommand \index{HC08}
23547
23548 \end_inset
23549
23550  family has been added in October 2003, and is still undergoing some basic
23551  development.
23552  The code generator is complete, but the register allocation is still quite
23553  unoptimized.
23554  Some of the SDCC's standard C library functions have embedded non-HC08
23555  inline assembly and so are not yet usable.
23556 \end_layout
23557
23558 \begin_layout Standard
23559 The HC08 port passes the regression test suite (see section 
23560 \begin_inset LatexCommand \ref{sec:Quality-control}
23561
23562 \end_inset
23563
23564 ).
23565 \begin_inset VSpace bigskip
23566 \end_inset
23567
23568
23569 \newpage
23570
23571 \end_layout
23572
23573 \begin_layout Section
23574 The PIC14
23575 \begin_inset LatexCommand \index{PIC14}
23576
23577 \end_inset
23578
23579  port
23580 \end_layout
23581
23582 \begin_layout Standard
23583 The PIC14 port adds support for Microchip
23584 \begin_inset LatexCommand \index{Microchip}
23585
23586 \end_inset
23587
23588
23589 \begin_inset Formula $^{\text{TM}}$
23590 \end_inset
23591
23592  PIC
23593 \begin_inset LatexCommand \index{PIC14}
23594
23595 \end_inset
23596
23597
23598 \begin_inset Formula $^{\text{TM}}$
23599 \end_inset
23600
23601  MCUs with 14 bit wide instructions.
23602  This port is not yet mature and still lacks many features.
23603  However, it can work for simple code.
23604 \end_layout
23605
23606 \begin_layout Standard
23607 Currently supported devices include:
23608 \end_layout
23609
23610 \begin_layout Standard
23611 12F: 629, 635, 675, 683
23612 \end_layout
23613
23614 \begin_layout Standard
23615 16C: 432, 433
23616 \end_layout
23617
23618 \begin_layout Standard
23619 16C: 554, 557, 558
23620 \end_layout
23621
23622 \begin_layout Standard
23623 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23624 \end_layout
23625
23626 \begin_layout Standard
23627 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23628  781, 782
23629 \end_layout
23630
23631 \begin_layout Standard
23632 16C: 925, 926
23633 \end_layout
23634
23635 \begin_layout Standard
23636 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23637  689, 690
23638 \end_layout
23639
23640 \begin_layout Standard
23641 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23642 \end_layout
23643
23644 \begin_layout Standard
23645 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23646  877, 877a, 88
23647 \end_layout
23648
23649 \begin_layout Standard
23650 16F: 913, 914, 916, 917
23651 \end_layout
23652
23653 \begin_layout Standard
23654 An up-to-date list of currently supported devices can be obtained via 
23655 \family typewriter
23656 sdcc -mpic14 -phelp foo.c
23657 \family default
23658  (foo.c must exist...).
23659 \end_layout
23660
23661 \begin_layout Subsection
23662 PIC Code Pages
23663 \begin_inset LatexCommand \index{code page (pic14)}
23664
23665 \end_inset
23666
23667  and Memory Banks
23668 \begin_inset LatexCommand \index{Memory bank (pic14)}
23669
23670 \end_inset
23671
23672
23673 \end_layout
23674
23675 \begin_layout Standard
23676 The linker organizes allocation for the code page and RAM banks.
23677  It does not have intimate knowledge of the code flow.
23678  It will put all the code section of a single .asm file into a single code
23679  page.
23680  In order to make use of multiple code pages, separate asm files must be
23681  used.
23682  The compiler assigns all 
23683 \emph on
23684 static
23685 \emph default
23686  functions of a single .c file into the same code page.
23687 \newline
23688
23689 \newline
23690 To get the best results,
23691  follow these guidelines:
23692 \end_layout
23693
23694 \begin_layout Enumerate
23695 Make local functions static, as non static functions require code page selection
23696  overhead.
23697 \newline
23698 Due to the way sdcc handles functions, place called functions prior
23699  to calling functions in the file wherever possible: Otherwise sdcc will
23700  insert unneccessary pagesel directives around the call, believing that
23701  the called function is externally defined.
23702 \end_layout
23703
23704 \begin_layout Enumerate
23705 For devices that have multiple code pages it is more efficient to use the
23706  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23707  but only 2 files for the 16F874.
23708  This way the linker can put the code for each file into different code
23709  pages and there will be less page selection overhead.
23710 \end_layout
23711
23712 \begin_layout Enumerate
23713 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23714  instruction set), use `unsigned char' wherever possible instead of `int'.
23715 \end_layout
23716
23717 \begin_layout Subsection
23718 Adding New Devices to the Port 
23719 \end_layout
23720
23721 \begin_layout Standard
23722 Adding support for a new 14
23723 \begin_inset ERT
23724 status open
23725
23726 \begin_layout Standard
23727
23728
23729 \backslash
23730 ,
23731 \end_layout
23732
23733 \end_inset
23734
23735 bit PIC MCU requires the following steps:
23736 \end_layout
23737
23738 \begin_layout Enumerate
23739 Create a new device description.
23740 \newline
23741 Each device is described in two files: pic16f*.h
23742  and pic16f*.c.
23743  These files primarily define SFRs, structs to access their bits, and symbolic
23744  configuration options.
23745  Both files can be generated from gputils' .inc files using the perl script
23746  
23747 \family typewriter
23748 support/scripts/inc2h.pl
23749 \family default
23750 .
23751  This file also contains further instructions on how to proceed.
23752 \end_layout
23753
23754 \begin_layout Enumerate
23755 Copy the .h file into SDCC's include path and either add the .c file to your
23756  project or copy it to 
23757 \family typewriter
23758 device/lib/pic/libdev
23759 \family default
23760 .
23761  Afterwards, rebuild and install the libraries.
23762 \end_layout
23763
23764 \begin_layout Enumerate
23765 Edit pic14devices.txt in SDCC's include path (
23766 \family typewriter
23767 device/include/pic/
23768 \family default
23769  in the source tree or 
23770 \family typewriter
23771 /usr/local/share/sdcc/include/pic
23772 \family default
23773  after installation).
23774 \newline
23775 You need to add a device specification here to make
23776  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23777  the compiler.
23778  Probably you can copy and modify an existing entry.
23779  The file format is documented at the top of the file.
23780 \end_layout
23781
23782 \begin_layout Subsection
23783 Interrupt Code
23784 \end_layout
23785
23786 \begin_layout Standard
23787 For the interrupt function, use the keyword `__interrupt'
23788 \begin_inset LatexCommand \index{PIC14!interrupt}
23789
23790 \end_inset
23791
23792  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23793  there to avoid a syntax error - it ought to be fixed).
23794  E.g.:
23795 \end_layout
23796
23797 \begin_layout Verse
23798
23799 \family typewriter
23800 void Intr(void) __interrupt 0
23801 \newline
23802 {
23803 \newline
23804 \InsetSpace ~
23805 \InsetSpace ~
23806 T0IF = 0; /* Clear timer interrupt */
23807 \newline
23808 }
23809 \end_layout
23810
23811 \begin_layout Subsection
23812 Linking and Assembling
23813 \end_layout
23814
23815 \begin_layout Standard
23816 For assembling you can use either GPUTILS'
23817 \begin_inset LatexCommand \index{gputils (pic tools)}
23818
23819 \end_inset
23820
23821  gpasm.exe or MPLAB's mpasmwin.exe.
23822  GPUTILS are available from 
23823 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23824
23825 \end_inset
23826
23827 .
23828  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23829  If you use MPLAB and an interrupt function then the linker script file
23830  vectors section will need to be enlarged to link with mplink.
23831 \newline
23832
23833 \newline
23834 Here is a 
23835 \family typewriter
23836 Makefile
23837 \family default
23838  using GPUTILS:
23839 \end_layout
23840
23841 \begin_layout Verse
23842
23843 \family typewriter
23844 .c.o:
23845 \newline
23846 \InsetSpace ~
23847 \InsetSpace ~
23848 \InsetSpace ~
23849 \InsetSpace ~
23850 \InsetSpace ~
23851 \InsetSpace ~
23852 \InsetSpace ~
23853 \InsetSpace ~
23854 sdcc -V -mpic14 -p16f877 -c $< 
23855 \newline
23856
23857 \newline
23858 $(PRJ).hex: $(OBJS) 
23859 \newline
23860 \InsetSpace ~
23861 \InsetSpace ~
23862 \InsetSpace ~
23863 \InsetSpace ~
23864 \InsetSpace ~
23865 \InsetSpace ~
23866 \InsetSpace ~
23867 \InsetSpace ~
23868 gplink -m -s $(PRJ).lkr
23869  -o $(PRJ).hex $(OBJS) libsdcc.lib
23870 \end_layout
23871
23872 \begin_layout Standard
23873 Here is a 
23874 \family typewriter
23875 Makefile
23876 \family default
23877  using MPLAB:
23878 \end_layout
23879
23880 \begin_layout Verse
23881
23882 \family typewriter
23883 .c.o: 
23884 \newline
23885 \InsetSpace ~
23886 \InsetSpace ~
23887 \InsetSpace ~
23888 \InsetSpace ~
23889 \InsetSpace ~
23890 \InsetSpace ~
23891 \InsetSpace ~
23892 \InsetSpace ~
23893 sdcc -S -V -mpic14 -p16f877 $< 
23894 \newline
23895 \InsetSpace ~
23896 \InsetSpace ~
23897 \InsetSpace ~
23898 \InsetSpace ~
23899 \InsetSpace ~
23900 \InsetSpace ~
23901 \InsetSpace ~
23902 \InsetSpace ~
23903 mpasmwin /q /o $*.asm
23904 \newline
23905
23906 \newline
23907 $(PRJ).hex: $(OBJS)
23908  
23909 \newline
23910 \InsetSpace ~
23911 \InsetSpace ~
23912 \InsetSpace ~
23913 \InsetSpace ~
23914 \InsetSpace ~
23915 \InsetSpace ~
23916 \InsetSpace ~
23917 \InsetSpace ~
23918 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23919 \end_layout
23920
23921 \begin_layout Standard
23922 Please note that indentations within a
23923 \family typewriter
23924  Makefile
23925 \family default
23926  have to be done with a tabulator character.
23927 \end_layout
23928
23929 \begin_layout Subsection
23930 Command-Line Options
23931 \end_layout
23932
23933 \begin_layout Standard
23934 Besides the switches common to all SDCC backends, the PIC14 port accepts
23935  the following options (for an updated list see sdcc -
23936 \begin_inset ERT
23937 status collapsed
23938
23939 \begin_layout Standard
23940
23941
23942 \backslash
23943 /
23944 \end_layout
23945
23946 \end_inset
23947
23948 -help):
23949 \end_layout
23950
23951 \begin_layout Description
23952 -
23953 \begin_inset ERT
23954 status collapsed
23955
23956 \begin_layout Standard
23957
23958
23959 \backslash
23960 /
23961 \end_layout
23962
23963 \end_inset
23964
23965 -debug-xtra
23966 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23967
23968 \end_inset
23969
23970  emit debug info in assembly output
23971 \end_layout
23972
23973 \begin_layout Description
23974 -
23975 \begin_inset ERT
23976 status collapsed
23977
23978 \begin_layout Standard
23979
23980
23981 \backslash
23982 /
23983 \end_layout
23984
23985 \end_inset
23986
23987 -no-pcode-opt
23988 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23989
23990 \end_inset
23991
23992  disable (slightly faulty) optimization on pCode
23993 \end_layout
23994
23995 \begin_layout Description
23996 -
23997 \begin_inset ERT
23998 status collapsed
23999
24000 \begin_layout Standard
24001
24002
24003 \backslash
24004 /
24005 \end_layout
24006
24007 \end_inset
24008
24009 -stack-loc
24010 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24011
24012 \end_inset
24013
24014  sets the lowest address of the argument passing stack (defaults to a suitably
24015  large shared databank to reduce BANKSEL overhead)
24016 \end_layout
24017
24018 \begin_layout Description
24019 -
24020 \begin_inset ERT
24021 status collapsed
24022
24023 \begin_layout Standard
24024
24025
24026 \backslash
24027 /
24028 \end_layout
24029
24030 \end_inset
24031
24032 -stack-size
24033 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24034
24035 \end_inset
24036
24037  sets the size if the argument passing stack (default: 16, minimum: 4)
24038 \end_layout
24039
24040 \begin_layout Subsection
24041 Environment Variables
24042 \end_layout
24043
24044 \begin_layout Standard
24045 The PIC14 port recognizes the following environment variables:
24046 \end_layout
24047
24048 \begin_layout Description
24049 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24050  register (the ones called r0xNNNN) in a section of its own.
24051  By default (if this variable is unset), sdcc tries to cluster registers
24052  in sections in order to reduce the BANKSEL overhead when accessing them.
24053 \end_layout
24054
24055 \begin_layout Subsection
24056 The Library
24057 \end_layout
24058
24059 \begin_layout Standard
24060 The PIC14 library currently only contains support routines required by the
24061  compiler to implement multiplication, division, and floating point support.
24062  No libc-like replacement is available at the moment, though many of the
24063  common sdcc library sources (in 
24064 \family typewriter
24065 device/lib
24066 \family default
24067 ) should also compile with the PIC14 port.
24068 \end_layout
24069
24070 \begin_layout Subsubsection
24071 error: missing definition for symbol ``__gptrget1''
24072 \end_layout
24073
24074 \begin_layout Standard
24075 The PIC14 port uses library routines to provide more complex operations
24076  like multiplication, division/modulus and (generic) pointer dereferencing.
24077  In order to add these routines to your project, you must link with PIC14's
24078  
24079 \family typewriter
24080 libsdcc.lib
24081 \family default
24082 .
24083  For single source file projects this is done automatically, more complex
24084  projects must add 
24085 \family typewriter
24086 libsdcc.lib
24087 \family default
24088  to the linker's arguments.
24089  Make sure you also add an include path for the library (using the -I switch
24090  to the linker)!
24091 \end_layout
24092
24093 \begin_layout Subsubsection
24094 Processor mismatch in file ``XXX''.
24095 \end_layout
24096
24097 \begin_layout Standard
24098 This warning can usually be ignored due to the very good compatibility amongst
24099  14
24100 \begin_inset ERT
24101 status open
24102
24103 \begin_layout Standard
24104
24105
24106 \backslash
24107 ,
24108 \end_layout
24109
24110 \end_inset
24111
24112 bit PIC
24113 \begin_inset LatexCommand \index{PIC14}
24114
24115 \end_inset
24116
24117  devices.
24118 \end_layout
24119
24120 \begin_layout Standard
24121 You might also consider recompiling the library for your specific device
24122  by changing the ARCH=p16f877 (default target) entry in 
24123 \family typewriter
24124 device/lib/pic/Makefile.in
24125 \family default
24126  and 
24127 \family typewriter
24128 device/lib/pic/Makefile
24129 \family default
24130  to reflect your device.
24131  This might even improve performance for smaller devices as unneccesary
24132  BANKSELs might be removed.
24133 \end_layout
24134
24135 \begin_layout Subsection
24136 Known Bugs
24137 \end_layout
24138
24139 \begin_layout Subsubsection
24140 Function arguments
24141 \end_layout
24142
24143 \begin_layout Standard
24144 Functions with variable argument lists (like printf) are not yet supported.
24145  Similarly, taking the argument of the first argument passed into a function
24146  does not work: It is currently passed in WREG and has no address...
24147 \end_layout
24148
24149 \begin_layout Subsubsection
24150 Regression tests fail
24151 \end_layout
24152
24153 \begin_layout Standard
24154 Though the small subset of regression tests in src/regression passes, SDCC
24155  regression test suite does not, indicating that there are still major bugs
24156  in the port.
24157  However, many smaller projects have successfully used SDCC in the past...
24158 \end_layout
24159
24160 \begin_layout Standard
24161
24162 \size footnotesize
24163
24164 \newpage
24165
24166 \end_layout
24167
24168 \begin_layout Section
24169 The PIC16
24170 \begin_inset LatexCommand \index{PIC16}
24171
24172 \end_inset
24173
24174  port
24175 \end_layout
24176
24177 \begin_layout Standard
24178 The PIC16 port adds support for Microchip
24179 \begin_inset LatexCommand \index{Microchip}
24180
24181 \end_inset
24182
24183
24184 \begin_inset Formula $^{\text{TM}}$
24185 \end_inset
24186
24187  PIC
24188 \begin_inset LatexCommand \index{PIC}
24189
24190 \end_inset
24191
24192
24193 \begin_inset Formula $^{\text{TM}}$
24194 \end_inset
24195
24196  MCUs with 16 bit wide instructions.
24197  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24198 ; devices supported by the port include:
24199 \end_layout
24200
24201 \begin_layout Standard
24202 18F: 242, 248, 252, 258, 442, 448, 452, 458
24203 \end_layout
24204
24205 \begin_layout Standard
24206 18F: 1220, 1320
24207 \end_layout
24208
24209 \begin_layout Standard
24210 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24211  2620
24212 \end_layout
24213
24214 \begin_layout Standard
24215 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24216  45j10, 4620
24217 \end_layout
24218
24219 \begin_layout Standard
24220 18F: 6520, 6620, 6680, 6720
24221 \end_layout
24222
24223 \begin_layout Standard
24224 18F: 8520, 8620, 8680, 8720
24225 \end_layout
24226
24227 \begin_layout Subsection
24228 Global Options
24229 \end_layout
24230
24231 \begin_layout Standard
24232 PIC16 port supports the standard command line arguments as supposed, with
24233  the exception of certain cases that will be mentioned in the following
24234  list:
24235 \end_layout
24236
24237 \begin_layout Description
24238 -
24239 \begin_inset ERT
24240 status collapsed
24241
24242 \begin_layout Standard
24243
24244
24245 \backslash
24246 /
24247 \end_layout
24248
24249 \end_inset
24250
24251 -callee-saves
24252 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24253
24254 \end_inset
24255
24256  See -
24257 \begin_inset ERT
24258 status collapsed
24259
24260 \begin_layout Standard
24261
24262
24263 \backslash
24264 /
24265 \end_layout
24266
24267 \end_inset
24268
24269 -all-callee-saves
24270 \end_layout
24271
24272 \begin_layout Description
24273 -
24274 \begin_inset ERT
24275 status collapsed
24276
24277 \begin_layout Standard
24278
24279
24280 \backslash
24281 /
24282 \end_layout
24283
24284 \end_inset
24285
24286 -fommit-frame-pointer
24287 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24288
24289 \end_inset
24290
24291  Frame pointer will be omitted when the function uses no local variables.
24292 \end_layout
24293
24294 \begin_layout Subsection
24295 Port Specific Options
24296 \begin_inset LatexCommand \index{Options PIC16}
24297
24298 \end_inset
24299
24300
24301 \end_layout
24302
24303 \begin_layout Standard
24304 The port specific options appear after the global options in the sdcc -
24305 \begin_inset ERT
24306 status collapsed
24307
24308 \begin_layout Standard
24309
24310
24311 \backslash
24312 /
24313 \end_layout
24314
24315 \end_inset
24316
24317 -help output.
24318 \end_layout
24319
24320 \begin_layout Subsubsection
24321 Code Generation Options
24322 \end_layout
24323
24324 \begin_layout Standard
24325 These options influence the generated assembler code.
24326 \end_layout
24327
24328 \begin_layout Description
24329 -
24330 \begin_inset ERT
24331 status collapsed
24332
24333 \begin_layout Standard
24334
24335
24336 \backslash
24337 /
24338 \end_layout
24339
24340 \end_inset
24341
24342 -pstack-model=[model] Used in conjuction with the command above.
24343  Defines the stack model to be used, valid stack models are:
24344 \end_layout
24345
24346 \begin_deeper
24347 \begin_layout List
24348 \labelwidthstring 00.00.0000
24349
24350 \emph on
24351 small
24352 \emph default
24353  Selects small stack model.
24354  8 bit stack and frame pointers.
24355  Supports 256 bytes stack size.
24356 \end_layout
24357
24358 \begin_layout List
24359 \labelwidthstring 00.00.0000
24360
24361 \emph on
24362 large
24363 \emph default
24364  Selects large stack model.
24365  16 bit stack and frame pointers.
24366  Supports 65536 bytes stack size.
24367 \end_layout
24368
24369 \end_deeper
24370 \begin_layout Description
24371 -
24372 \begin_inset ERT
24373 status collapsed
24374
24375 \begin_layout Standard
24376
24377
24378 \backslash
24379 /
24380 \end_layout
24381
24382 \end_inset
24383
24384 -pno-banksel Do not generate BANKSEL assembler directives.
24385 \end_layout
24386
24387 \begin_layout Description
24388 -
24389 \begin_inset ERT
24390 status collapsed
24391
24392 \begin_layout Standard
24393
24394
24395 \backslash
24396 /
24397 \end_layout
24398
24399 \end_inset
24400
24401 -extended Enable extended instruction set/literal offset addressing mode.
24402  Use with care!
24403 \end_layout
24404
24405 \begin_layout Subsubsection
24406 Optimization Options
24407 \end_layout
24408
24409 \begin_layout Description
24410 -
24411 \begin_inset ERT
24412 status collapsed
24413
24414 \begin_layout Standard
24415
24416
24417 \backslash
24418 /
24419 \end_layout
24420
24421 \end_inset
24422
24423 -obanksel=n Set optimization level for inserting BANKSELs.
24424 \newline
24425
24426 \end_layout
24427
24428 \begin_deeper
24429 \begin_layout List
24430 \labelwidthstring 00.00.0000
24431 0 no optimization
24432 \end_layout
24433
24434 \begin_layout List
24435 \labelwidthstring 00.00.0000
24436 1 checks previous used register and if it is the same then does not emit
24437  BANKSEL, accounts only for labels.
24438 \end_layout
24439
24440 \begin_layout List
24441 \labelwidthstring 00.00.0000
24442 2 tries to check the location of (even different) symbols and removes BANKSELs
24443  if they are in the same bank.
24444  
24445 \newline
24446
24447 \emph on
24448 Important: There might be problems if the linker script has data sections
24449  across bank borders!
24450 \end_layout
24451
24452 \end_deeper
24453 \begin_layout Description
24454 -
24455 \begin_inset ERT
24456 status collapsed
24457
24458 \begin_layout Standard
24459
24460
24461 \backslash
24462 /
24463 \end_layout
24464
24465 \end_inset
24466
24467 -denable-peeps Force the usage of peepholes.
24468  Use with care.
24469 \end_layout
24470
24471 \begin_layout Description
24472 -
24473 \begin_inset ERT
24474 status collapsed
24475
24476 \begin_layout Standard
24477
24478
24479 \backslash
24480 /
24481 \end_layout
24482
24483 \end_inset
24484
24485 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24486 \end_layout
24487
24488 \begin_layout Description
24489 -
24490 \begin_inset ERT
24491 status collapsed
24492
24493 \begin_layout Standard
24494
24495
24496 \backslash
24497 /
24498 \end_layout
24499
24500 \end_inset
24501
24502 -optimize-cmp Try to optimize some compares.
24503 \end_layout
24504
24505 \begin_layout Description
24506 -
24507 \begin_inset ERT
24508 status collapsed
24509
24510 \begin_layout Standard
24511
24512
24513 \backslash
24514 /
24515 \end_layout
24516
24517 \end_inset
24518
24519 -optimize-df Analyze the dataflow of the generated code and improve it.
24520 \end_layout
24521
24522 \begin_layout Subsubsection
24523 Assembling Options
24524 \end_layout
24525
24526 \begin_layout Description
24527 -
24528 \begin_inset ERT
24529 status collapsed
24530
24531 \begin_layout Standard
24532
24533
24534 \backslash
24535 /
24536 \end_layout
24537
24538 \end_inset
24539
24540 -asm= Sets the full path and name of an external assembler to call.
24541 \end_layout
24542
24543 \begin_layout Description
24544 -
24545 \begin_inset ERT
24546 status collapsed
24547
24548 \begin_layout Standard
24549
24550
24551 \backslash
24552 /
24553 \end_layout
24554
24555 \end_inset
24556
24557 -mplab-comp MPLAB
24558 \begin_inset LatexCommand \index{PIC16!MPLAB}
24559
24560 \end_inset
24561
24562  compatibility option.
24563  Currently only suppresses special gpasm directives.
24564 \end_layout
24565
24566 \begin_layout Subsubsection
24567 Linking Options
24568 \end_layout
24569
24570 \begin_layout Description
24571 -
24572 \begin_inset ERT
24573 status collapsed
24574
24575 \begin_layout Standard
24576
24577
24578 \backslash
24579 /
24580 \end_layout
24581
24582 \end_inset
24583
24584 -link= Sets the full path and name of an external linker to call.
24585 \end_layout
24586
24587 \begin_layout Description
24588 -
24589 \begin_inset ERT
24590 status collapsed
24591
24592 \begin_layout Standard
24593
24594
24595 \backslash
24596 /
24597 \end_layout
24598
24599 \end_inset
24600
24601 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24602  unitialized data variables with [kword].
24603  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24604 \end_layout
24605
24606 \begin_layout Description
24607 -
24608 \begin_inset ERT
24609 status collapsed
24610
24611 \begin_layout Standard
24612
24613
24614 \backslash
24615 /
24616 \end_layout
24617
24618 \end_inset
24619
24620 -ivt-loc=n Place the interrupt vector table at address 
24621 \emph on
24622 n
24623 \emph default
24624 .
24625  Useful for bootloaders.
24626 \end_layout
24627
24628 \begin_layout Description
24629 -
24630 \begin_inset ERT
24631 status collapsed
24632
24633 \begin_layout Standard
24634
24635
24636 \backslash
24637 /
24638 \end_layout
24639
24640 \end_inset
24641
24642 -nodefaultlibs Do not link default libraries when linking.
24643 \end_layout
24644
24645 \begin_layout Description
24646 -
24647 \begin_inset ERT
24648 status collapsed
24649
24650 \begin_layout Standard
24651
24652
24653 \backslash
24654 /
24655 \end_layout
24656
24657 \end_inset
24658
24659 -use-crt= Use a custom run-time module instead of the defaults.
24660 \end_layout
24661
24662 \begin_layout Description
24663 -
24664 \begin_inset ERT
24665 status collapsed
24666
24667 \begin_layout Standard
24668
24669
24670 \backslash
24671 /
24672 \end_layout
24673
24674 \end_inset
24675
24676 -no-crt Don't link the default run-time modules
24677 \end_layout
24678
24679 \begin_layout Subsubsection
24680 Debugging Options
24681 \end_layout
24682
24683 \begin_layout Standard
24684 Debugging options enable extra debugging information in the output files.
24685 \end_layout
24686
24687 \begin_layout Description
24688 -
24689 \begin_inset ERT
24690 status collapsed
24691
24692 \begin_layout Standard
24693
24694
24695 \backslash
24696 /
24697 \end_layout
24698
24699 \end_inset
24700
24701 -debug-xtra Similar to -
24702 \begin_inset ERT
24703 status collapsed
24704
24705 \begin_layout Standard
24706
24707
24708 \backslash
24709 /
24710 \end_layout
24711
24712 \end_inset
24713
24714 -debug
24715 \begin_inset LatexCommand \index{-\/-debug}
24716
24717 \end_inset
24718
24719 , but dumps more information.
24720 \end_layout
24721
24722 \begin_layout Description
24723 -
24724 \begin_inset ERT
24725 status collapsed
24726
24727 \begin_layout Standard
24728
24729
24730 \backslash
24731 /
24732 \end_layout
24733
24734 \end_inset
24735
24736 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24737  information.
24738  <source> is the name of the file being compiled.
24739 \end_layout
24740
24741 \begin_layout Description
24742 -
24743 \begin_inset ERT
24744 status collapsed
24745
24746 \begin_layout Standard
24747
24748
24749 \backslash
24750 /
24751 \end_layout
24752
24753 \end_inset
24754
24755 -pcode-verbose Enable pcode debugging information in translation.
24756 \end_layout
24757
24758 \begin_layout Description
24759 -
24760 \begin_inset ERT
24761 status collapsed
24762
24763 \begin_layout Standard
24764
24765
24766 \backslash
24767 /
24768 \end_layout
24769
24770 \end_inset
24771
24772 -calltree Dump call tree in .calltree file.
24773 \end_layout
24774
24775 \begin_layout Description
24776 -
24777 \begin_inset ERT
24778 status collapsed
24779
24780 \begin_layout Standard
24781
24782
24783 \backslash
24784 /
24785 \end_layout
24786
24787 \end_inset
24788
24789 -gstack Trace push/pops for stack pointer overflow.
24790 \end_layout
24791
24792 \begin_layout Subsection
24793 Enviroment Variables
24794 \end_layout
24795
24796 \begin_layout Standard
24797 There is a number of enviromental variables that can be used when running
24798  SDCC to enable certain optimizations or force a specific program behaviour.
24799  these variables are primarily for debugging purposes so they can be enabled/dis
24800 abled at will.
24801 \end_layout
24802
24803 \begin_layout Standard
24804 Currently there is only two such variables available:
24805 \end_layout
24806
24807 \begin_layout Description
24808 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24809  bitfields is optimized by directly loading FSR0 with the address of the
24810  bitfield structure.
24811  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24812  then load FSR0.
24813  This step saves data ram and code space for functions that make heavy use
24814  of bitfields.
24815  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24816  option).
24817  
24818 \end_layout
24819
24820 \begin_layout Description
24821 NO_REG_OPT Do not perform pCode registers optimization.
24822  This should be used for debugging purposes.
24823  If bugs in the pcode optimizer are found, users can benefit from temporarily
24824  disabling the optimizer until the bug is fixed.
24825 \end_layout
24826
24827 \begin_layout Subsection
24828 Preprocessor Macros
24829 \end_layout
24830
24831 \begin_layout Standard
24832 PIC16
24833 \begin_inset LatexCommand \index{PIC16}
24834
24835 \end_inset
24836
24837  port defines the following preprocessor macros while translating a source.
24838 \end_layout
24839
24840 \begin_layout Standard
24841 \align center
24842 \begin_inset Tabular
24843 <lyxtabular version="3" rows="6" columns="2">
24844 <features>
24845 <column alignment="center" valignment="top" leftline="true" width="0">
24846 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24847 <row topline="true" bottomline="true">
24848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24849 \begin_inset Text
24850
24851 \begin_layout Standard
24852 Macro
24853 \end_layout
24854
24855 \end_inset
24856 </cell>
24857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24858 \begin_inset Text
24859
24860 \begin_layout Standard
24861 Description
24862 \end_layout
24863
24864 \end_inset
24865 </cell>
24866 </row>
24867 <row topline="true">
24868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24869 \begin_inset Text
24870
24871 \begin_layout Standard
24872 SDCC_pic16
24873 \end_layout
24874
24875 \end_inset
24876 </cell>
24877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24878 \begin_inset Text
24879
24880 \begin_layout Standard
24881 Port identification
24882 \end_layout
24883
24884 \end_inset
24885 </cell>
24886 </row>
24887 <row topline="true">
24888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24889 \begin_inset Text
24890
24891 \begin_layout Standard
24892 _
24893 \begin_inset ERT
24894 status collapsed
24895
24896 \begin_layout Standard
24897
24898
24899 \backslash
24900 /
24901 \end_layout
24902
24903 \end_inset
24904
24905 _pic16
24906 \end_layout
24907
24908 \end_inset
24909 </cell>
24910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24911 \begin_inset Text
24912
24913 \begin_layout Standard
24914 Port identification (same as above)
24915 \end_layout
24916
24917 \end_inset
24918 </cell>
24919 </row>
24920 <row topline="true">
24921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24922 \begin_inset Text
24923
24924 \begin_layout Standard
24925 pic18fxxxx
24926 \end_layout
24927
24928 \end_inset
24929 </cell>
24930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24931 \begin_inset Text
24932
24933 \begin_layout Standard
24934 MCU Identification.
24935  
24936 \emph on
24937 xxxx
24938 \emph default
24939  is the microcontrol identification number, i.e.
24940  452, 6620, etc
24941 \end_layout
24942
24943 \end_inset
24944 </cell>
24945 </row>
24946 <row topline="true">
24947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24948 \begin_inset Text
24949
24950 \begin_layout Standard
24951 _
24952 \begin_inset ERT
24953 status collapsed
24954
24955 \begin_layout Standard
24956
24957
24958 \backslash
24959 /
24960 \end_layout
24961
24962 \end_inset
24963
24964 _18Fxxxx
24965 \end_layout
24966
24967 \end_inset
24968 </cell>
24969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24970 \begin_inset Text
24971
24972 \begin_layout Standard
24973 MCU Identification (same as above)
24974 \end_layout
24975
24976 \end_inset
24977 </cell>
24978 </row>
24979 <row topline="true" bottomline="true">
24980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24981 \begin_inset Text
24982
24983 \begin_layout Standard
24984 STACK_MODEL_nnn
24985 \end_layout
24986
24987 \end_inset
24988 </cell>
24989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24990 \begin_inset Text
24991
24992 \begin_layout Standard
24993 nnn = SMALL or LARGE respectively according to the stack model used
24994 \end_layout
24995
24996 \end_inset
24997 </cell>
24998 </row>
24999 </lyxtabular>
25000
25001 \end_inset
25002
25003
25004 \end_layout
25005
25006 \begin_layout Standard
25007 In addition the following macros are defined when calling assembler:
25008 \end_layout
25009
25010 \begin_layout Standard
25011 \align center
25012 \begin_inset Tabular
25013 <lyxtabular version="3" rows="4" columns="2">
25014 <features>
25015 <column alignment="center" valignment="top" leftline="true" width="0">
25016 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25017 <row topline="true" bottomline="true">
25018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25019 \begin_inset Text
25020
25021 \begin_layout Standard
25022 Macro
25023 \end_layout
25024
25025 \end_inset
25026 </cell>
25027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25028 \begin_inset Text
25029
25030 \begin_layout Standard
25031 Description
25032 \end_layout
25033
25034 \end_inset
25035 </cell>
25036 </row>
25037 <row topline="true">
25038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25039 \begin_inset Text
25040
25041 \begin_layout Standard
25042 __18Fxxxx
25043 \end_layout
25044
25045 \end_inset
25046 </cell>
25047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25048 \begin_inset Text
25049
25050 \begin_layout Standard
25051 MCU Identification.
25052  
25053 \emph on
25054 xxxx
25055 \emph default
25056  is the microcontrol identification number, i.e.
25057  452, 6620, etc
25058 \end_layout
25059
25060 \end_inset
25061 </cell>
25062 </row>
25063 <row topline="true">
25064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25065 \begin_inset Text
25066
25067 \begin_layout Standard
25068 SDCC_MODEL_nnn
25069 \end_layout
25070
25071 \end_inset
25072 </cell>
25073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25074 \begin_inset Text
25075
25076 \begin_layout Standard
25077 nnn = SMALL or LARGE respectively according to the memory model used for
25078  SDCC
25079 \end_layout
25080
25081 \end_inset
25082 </cell>
25083 </row>
25084 <row topline="true" bottomline="true">
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25086 \begin_inset Text
25087
25088 \begin_layout Standard
25089 STACK_MODEL_nnn
25090 \end_layout
25091
25092 \end_inset
25093 </cell>
25094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25095 \begin_inset Text
25096
25097 \begin_layout Standard
25098 nnn = SMALL or LARGE respectively according to the stack model used
25099 \end_layout
25100
25101 \end_inset
25102 </cell>
25103 </row>
25104 </lyxtabular>
25105
25106 \end_inset
25107
25108
25109 \end_layout
25110
25111 \begin_layout Subsection
25112 Directories
25113 \end_layout
25114
25115 \begin_layout Standard
25116 PIC16
25117 \begin_inset LatexCommand \index{PIC16}
25118
25119 \end_inset
25120
25121  port uses the following directories for searching header files and libraries.
25122 \end_layout
25123
25124 \begin_layout Standard
25125 \align center
25126 \begin_inset Tabular
25127 <lyxtabular version="3" rows="3" columns="4">
25128 <features>
25129 <column alignment="center" valignment="top" leftline="true" width="0">
25130 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25131 <column alignment="center" valignment="top" width="0">
25132 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25133 <row topline="true" bottomline="true">
25134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25135 \begin_inset Text
25136
25137 \begin_layout Standard
25138 Directory
25139 \end_layout
25140
25141 \end_inset
25142 </cell>
25143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25144 \begin_inset Text
25145
25146 \begin_layout Standard
25147 Description
25148 \end_layout
25149
25150 \end_inset
25151 </cell>
25152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25153 \begin_inset Text
25154
25155 \begin_layout Standard
25156 Target
25157 \end_layout
25158
25159 \end_inset
25160 </cell>
25161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25162 \begin_inset Text
25163
25164 \begin_layout Standard
25165 Command prefix
25166 \end_layout
25167
25168 \end_inset
25169 </cell>
25170 </row>
25171 <row topline="true">
25172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25173 \begin_inset Text
25174
25175 \begin_layout Standard
25176 PREFIX/sdcc/include/pic16
25177 \end_layout
25178
25179 \end_inset
25180 </cell>
25181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25182 \begin_inset Text
25183
25184 \begin_layout Standard
25185 PIC16 specific headers
25186 \end_layout
25187
25188 \end_inset
25189 </cell>
25190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25191 \begin_inset Text
25192
25193 \begin_layout Standard
25194 Compiler
25195 \end_layout
25196
25197 \end_inset
25198 </cell>
25199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25200 \begin_inset Text
25201
25202 \begin_layout Standard
25203 -I
25204 \end_layout
25205
25206 \end_inset
25207 </cell>
25208 </row>
25209 <row topline="true" bottomline="true">
25210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25211 \begin_inset Text
25212
25213 \begin_layout Standard
25214 PREFIX/sdcc/lib/pic16
25215 \end_layout
25216
25217 \end_inset
25218 </cell>
25219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25220 \begin_inset Text
25221
25222 \begin_layout Standard
25223 PIC16 specific libraries
25224 \end_layout
25225
25226 \end_inset
25227 </cell>
25228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25229 \begin_inset Text
25230
25231 \begin_layout Standard
25232 Linker
25233 \end_layout
25234
25235 \end_inset
25236 </cell>
25237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25238 \begin_inset Text
25239
25240 \begin_layout Standard
25241 -L
25242 \end_layout
25243
25244 \end_inset
25245 </cell>
25246 </row>
25247 </lyxtabular>
25248
25249 \end_inset
25250
25251
25252 \end_layout
25253
25254 \begin_layout Subsection
25255 Pragmas
25256 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25257
25258 \end_inset
25259
25260
25261 \end_layout
25262
25263 \begin_layout Standard
25264 The PIC16
25265 \begin_inset LatexCommand \index{PIC16}
25266
25267 \end_inset
25268
25269  port currently supports the following pragmas:
25270 \end_layout
25271
25272 \begin_layout Description
25273 stack
25274 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25275
25276 \end_inset
25277
25278  This forces the code generator to initialize the stack & frame pointers
25279  at a specific address.
25280  This is an ad hoc solution for cases where no STACK directive is available
25281  in the linker script or gplink is not instructed to create a stack section.
25282 \newline
25283 The
25284  stack pragma should be used only once in a project.
25285  Multiple pragmas may result in indeterminate behaviour of the program.
25286 \begin_inset Foot
25287 status open
25288
25289 \begin_layout Standard
25290 The old format (ie.
25291  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25292  cross page boundaries (or even exceed the available data RAM) and crash
25293  the program.
25294  Make sure that stack does not cross page boundaries when using the SMALL
25295  stack model.
25296 \end_layout
25297
25298 \end_inset
25299
25300
25301 \newline
25302 The format is as follows:
25303 \newline
25304
25305 \end_layout
25306
25307 \begin_layout LyX-Code
25308 #pragma stack bottom_address [stack_size]
25309 \newline
25310
25311 \end_layout
25312
25313 \begin_layout Standard
25314
25315 \emph on
25316 bottom_address
25317 \emph default
25318  is the lower bound of the stack section.
25319  The stack pointer initially will point at address (bottom_address+stack_size-1).
25320 \end_layout
25321
25322 \begin_layout LyX-Code
25323 Example:
25324 \end_layout
25325
25326 \begin_layout LyX-Code
25327
25328 \end_layout
25329
25330 \begin_layout LyX-Code
25331 /* initializes stack of 100 bytes at RAM address 0x200 */
25332 \end_layout
25333
25334 \begin_layout LyX-Code
25335 #pragma stack 0x200 100
25336 \end_layout
25337
25338 \begin_layout Standard
25339 If the stack_size field is omitted then a stack is created with the default
25340  size of 64.
25341  This size might be enough for most programs, but its not enough for operations
25342  with deep function nesting or excessive stack usage.
25343 \end_layout
25344
25345 \begin_layout Description
25346 code
25347 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25348
25349 \end_inset
25350
25351  Force a function to a static FLASH address.
25352 \end_layout
25353
25354 \begin_layout LyX-Code
25355 Example:
25356 \end_layout
25357
25358 \begin_layout LyX-Code
25359
25360 \end_layout
25361
25362 \begin_layout LyX-Code
25363 /* place function test_func at 0x4000 */
25364 \end_layout
25365
25366 \begin_layout LyX-Code
25367 #pragma code test_func 0x4000
25368 \end_layout
25369
25370 \begin_layout LyX-Code
25371
25372 \end_layout
25373
25374 \begin_layout Description
25375 library instructs the linker to use a library module.
25376 \newline
25377 Usage:
25378 \end_layout
25379
25380 \begin_layout LyX-Code
25381 #pragma library module_name
25382 \end_layout
25383
25384 \begin_layout Standard
25385
25386 \emph on
25387 module_name
25388 \emph default
25389  can be any library or object file (including its path).
25390  Note that there are four reserved keywords which have special meaning.
25391  These are:
25392 \end_layout
25393
25394 \begin_layout Standard
25395 \align center
25396 \begin_inset Tabular
25397 <lyxtabular version="3" rows="6" columns="3">
25398 <features>
25399 <column alignment="center" valignment="top" leftline="true" width="0">
25400 <column alignment="block" valignment="top" leftline="true" width="20page%">
25401 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25402 <row topline="true" bottomline="true">
25403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25404 \begin_inset Text
25405
25406 \begin_layout Standard
25407 Keyword
25408 \end_layout
25409
25410 \end_inset
25411 </cell>
25412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25413 \begin_inset Text
25414
25415 \begin_layout Standard
25416 Description
25417 \end_layout
25418
25419 \end_inset
25420 </cell>
25421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25422 \begin_inset Text
25423
25424 \begin_layout Standard
25425 Module to link
25426 \end_layout
25427
25428 \end_inset
25429 </cell>
25430 </row>
25431 <row topline="true">
25432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25433 \begin_inset Text
25434
25435 \begin_layout Standard
25436
25437 \series bold
25438 ignore
25439 \end_layout
25440
25441 \end_inset
25442 </cell>
25443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25444 \begin_inset Text
25445
25446 \begin_layout Standard
25447 ignore all library pragmas
25448 \end_layout
25449
25450 \end_inset
25451 </cell>
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25453 \begin_inset Text
25454
25455 \begin_layout Standard
25456
25457 \emph on
25458 (none)
25459 \end_layout
25460
25461 \end_inset
25462 </cell>
25463 </row>
25464 <row topline="true">
25465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25466 \begin_inset Text
25467
25468 \begin_layout Standard
25469
25470 \series bold
25471 c
25472 \end_layout
25473
25474 \end_inset
25475 </cell>
25476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25477 \begin_inset Text
25478
25479 \begin_layout Standard
25480 link the C library
25481 \end_layout
25482
25483 \end_inset
25484 </cell>
25485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25486 \begin_inset Text
25487
25488 \begin_layout Standard
25489
25490 \emph on
25491 libc18f
25492 \emph default
25493 .lib
25494 \end_layout
25495
25496 \end_inset
25497 </cell>
25498 </row>
25499 <row topline="true">
25500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25501 \begin_inset Text
25502
25503 \begin_layout Standard
25504
25505 \series bold
25506 math
25507 \end_layout
25508
25509 \end_inset
25510 </cell>
25511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25512 \begin_inset Text
25513
25514 \begin_layout Standard
25515 link the Math libarary
25516 \end_layout
25517
25518 \end_inset
25519 </cell>
25520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25521 \begin_inset Text
25522
25523 \begin_layout Standard
25524
25525 \emph on
25526 libm18f
25527 \emph default
25528 .lib
25529 \end_layout
25530
25531 \end_inset
25532 </cell>
25533 </row>
25534 <row topline="true">
25535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25536 \begin_inset Text
25537
25538 \begin_layout Standard
25539
25540 \series bold
25541 io
25542 \end_layout
25543
25544 \end_inset
25545 </cell>
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25547 \begin_inset Text
25548
25549 \begin_layout Standard
25550 link the I/O library
25551 \end_layout
25552
25553 \end_inset
25554 </cell>
25555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25556 \begin_inset Text
25557
25558 \begin_layout Standard
25559
25560 \emph on
25561 libio18f*
25562 \emph default
25563 .lib
25564 \end_layout
25565
25566 \end_inset
25567 </cell>
25568 </row>
25569 <row topline="true" bottomline="true">
25570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25571 \begin_inset Text
25572
25573 \begin_layout Standard
25574
25575 \series bold
25576 debug
25577 \end_layout
25578
25579 \end_inset
25580 </cell>
25581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25582 \begin_inset Text
25583
25584 \begin_layout Standard
25585 link the debug library
25586 \end_layout
25587
25588 \end_inset
25589 </cell>
25590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25591 \begin_inset Text
25592
25593 \begin_layout Standard
25594
25595 \emph on
25596 libdebug
25597 \emph default
25598 .lib
25599 \end_layout
25600
25601 \end_inset
25602 </cell>
25603 </row>
25604 </lyxtabular>
25605
25606 \end_inset
25607
25608
25609 \newline
25610 * is the device number, i.e.
25611  452 for PIC18F452 MCU.
25612 \end_layout
25613
25614 \begin_layout Standard
25615 This feature allows for linking with specific libraries withoug having to
25616  explicit name them in the command line.
25617  Note that the 
25618 \noun on
25619 ignore
25620 \noun default
25621  keyword will reject all modules specified by the library pragma.
25622 \end_layout
25623
25624 \begin_layout Description
25625 udata The pragma udata instructs the compiler to emit code so that linker
25626  will place a variable at a specific memory bank.
25627 \end_layout
25628
25629 \begin_layout LyX-Code
25630 Example:
25631 \end_layout
25632
25633 \begin_layout LyX-Code
25634
25635 \end_layout
25636
25637 \begin_layout LyX-Code
25638 /* places variable foo at bank2 */
25639 \end_layout
25640
25641 \begin_layout LyX-Code
25642 #pragma udata bank2 foo
25643 \end_layout
25644
25645 \begin_layout LyX-Code
25646 char foo;
25647 \end_layout
25648
25649 \begin_layout Standard
25650 In order for this pragma to work extra SECTION directives should be added
25651  in the .lkr script.
25652  In the following example a sample .lkr file is shown:
25653 \end_layout
25654
25655 \begin_layout LyX-Code
25656
25657 \end_layout
25658
25659 \begin_layout LyX-Code
25660 // Sample linker script for the PIC18F452 processor
25661 \end_layout
25662
25663 \begin_layout LyX-Code
25664 LIBPATH .
25665 \end_layout
25666
25667 \begin_layout LyX-Code
25668 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25669 \end_layout
25670
25671 \begin_layout LyX-Code
25672 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25673 \end_layout
25674
25675 \begin_layout LyX-Code
25676 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25677 \end_layout
25678
25679 \begin_layout LyX-Code
25680 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25681 \end_layout
25682
25683 \begin_layout LyX-Code
25684 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25685 \end_layout
25686
25687 \begin_layout LyX-Code
25688 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25689 \end_layout
25690
25691 \begin_layout LyX-Code
25692 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25693 \end_layout
25694
25695 \begin_layout LyX-Code
25696
25697 \end_layout
25698
25699 \begin_layout LyX-Code
25700 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25701 \end_layout
25702
25703 \begin_layout LyX-Code
25704 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25705 \end_layout
25706
25707 \begin_layout LyX-Code
25708 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25709 \end_layout
25710
25711 \begin_layout LyX-Code
25712 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25713 \end_layout
25714
25715 \begin_layout LyX-Code
25716 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25717 \end_layout
25718
25719 \begin_layout LyX-Code
25720 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25721 \end_layout
25722
25723 \begin_layout LyX-Code
25724 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25725 \end_layout
25726
25727 \begin_layout LyX-Code
25728
25729 \end_layout
25730
25731 \begin_layout LyX-Code
25732 SECTION    NAME=CONFIG     ROM=config
25733 \end_layout
25734
25735 \begin_layout LyX-Code
25736
25737 \end_layout
25738
25739 \begin_layout LyX-Code
25740 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25741 \end_layout
25742
25743 \begin_layout LyX-Code
25744 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25745 \end_layout
25746
25747 \begin_layout LyX-Code
25748 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25749 \end_layout
25750
25751 \begin_layout LyX-Code
25752 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25753 \end_layout
25754
25755 \begin_layout LyX-Code
25756 SECTION    NAME=bank4      RAM=gpr4
25757 \end_layout
25758
25759 \begin_layout LyX-Code
25760 SECTION    NAME=bank5      RAM=gpr5
25761 \end_layout
25762
25763 \begin_layout Standard
25764 The linker will recognise the section name set in the pragma statement and
25765  will position the variable at the memory bank set with the RAM field at
25766  the SECTION line in the linker script file.
25767 \end_layout
25768
25769 \begin_layout Subsection
25770 Header Files
25771 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25772
25773 \end_inset
25774
25775
25776 \end_layout
25777
25778 \begin_layout Standard
25779 There is one main header file
25780 \begin_inset LatexCommand \index{PIC16!Header files}
25781
25782 \end_inset
25783
25784  that can be included to the source files using the pic16
25785 \begin_inset LatexCommand \index{PIC16}
25786
25787 \end_inset
25788
25789  port.
25790  That file is the 
25791 \series bold
25792 pic18fregs.h
25793 \series default
25794 .
25795  This header file contains the definitions for the processor special registers,
25796  so it is necessary if the source accesses them.
25797  It can be included by adding the following line in the beginning of the
25798  file:
25799 \end_layout
25800
25801 \begin_layout LyX-Code
25802 #include <pic18fregs.h>
25803 \end_layout
25804
25805 \begin_layout Standard
25806 The specific microcontroller is selected within the pic18fregs.h automatically,
25807  so the same source can be used with a variety of devices.
25808 \end_layout
25809
25810 \begin_layout Subsection
25811 Libraries
25812 \end_layout
25813
25814 \begin_layout Standard
25815 The libraries
25816 \begin_inset LatexCommand \index{PIC16!Libraries}
25817
25818 \end_inset
25819
25820  that PIC16
25821 \begin_inset LatexCommand \index{PIC16}
25822
25823 \end_inset
25824
25825  port depends on are the microcontroller device libraries which contain
25826  the symbol definitions for the microcontroller special function registers.
25827  These libraries have the format pic18fxxxx.lib, where 
25828 \emph on
25829 xxxx
25830 \emph default
25831  is the microcontroller identification number.
25832  The specific library is selected automatically by the compiler at link
25833  stage according to the selected device.
25834 \end_layout
25835
25836 \begin_layout Standard
25837 Libraries are created with gplib which is part of the gputils package 
25838 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25839
25840 \end_inset
25841
25842 .
25843 \end_layout
25844
25845 \begin_layout Subsubsection*
25846 Building the libraries
25847 \end_layout
25848
25849 \begin_layout Standard
25850 Before using SDCC/pic16 there are some libraries that need to be compiled.
25851  This process is not done automatically by SDCC since not all users use
25852  SDCC for pic16 projects.
25853  So each user should compile the libraries separately.
25854 \end_layout
25855
25856 \begin_layout Standard
25857 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25858 \end_layout
25859
25860 \begin_layout LyX-Code
25861 cd device/lib/pic16
25862 \end_layout
25863
25864 \begin_layout LyX-Code
25865 ./configure
25866 \end_layout
25867
25868 \begin_layout LyX-Code
25869 make
25870 \end_layout
25871
25872 \begin_layout LyX-Code
25873 cd ..
25874 \end_layout
25875
25876 \begin_layout LyX-Code
25877 make model-pic16
25878 \end_layout
25879
25880 \begin_layout LyX-Code
25881 su -c 'make install'     # install the libraries, you need the root password
25882 \end_layout
25883
25884 \begin_layout Standard
25885 If you need to install the headers too, do:
25886 \end_layout
25887
25888 \begin_layout LyX-Code
25889 cd device/include
25890 \end_layout
25891
25892 \begin_layout LyX-Code
25893 su -c 'make install'     # install the headers, you need the root password
25894 \end_layout
25895
25896 \begin_layout Standard
25897 There exist a special target to build the I/O libraries.
25898  This target is not automatically build because it will build the I/O library
25899  for 
25900 \emph on
25901 every
25902 \emph default
25903  supported device.
25904  This way building will take quite a lot of time.
25905  Users are advised to edit the 
25906 \series bold
25907 device/lib/pic16/pics.build
25908 \series default
25909  file and then execute:
25910 \end_layout
25911
25912 \begin_layout LyX-Code
25913 make lib-io
25914 \end_layout
25915
25916 \begin_layout Subsection
25917 Adding New Devices to the Port
25918 \end_layout
25919
25920 \begin_layout Standard
25921 Adding support for a new 16
25922 \begin_inset ERT
25923 status open
25924
25925 \begin_layout Standard
25926
25927
25928 \backslash
25929 ,
25930 \end_layout
25931
25932 \end_inset
25933
25934 bit PIC MCU requires the following steps:
25935 \end_layout
25936
25937 \begin_layout Enumerate
25938 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25939 \newline
25940
25941 \family typewriter
25942 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25943 inc
25944 \end_layout
25945
25946 \begin_layout Enumerate
25947
25948 \family typewriter
25949 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25950 \end_layout
25951
25952 \begin_layout Enumerate
25953
25954 \family typewriter
25955 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25956 \end_layout
25957
25958 \begin_layout Enumerate
25959 Add DEVICE to 
25960 \family typewriter
25961 /path/to/sdcc/device/lib/pic16/pics.all
25962 \family default
25963  (and 
25964 \family typewriter
25965 .build
25966 \family default
25967 ).
25968 \newline
25969 Note: No 18f prefix here!
25970 \end_layout
25971
25972 \begin_layout Enumerate
25973 Adjust 
25974 \family typewriter
25975 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25976 \family default
25977
25978 \newline
25979 Add your DEVICE if it does not compile in 
25980 \family typewriter
25981 adc
25982 \family default
25983
25984 \family typewriter
25985 i2c
25986 \family default
25987 , or 
25988 \family typewriter
25989 usart
25990 \family default
25991 .
25992 \end_layout
25993
25994 \begin_layout Enumerate
25995 Edit 
25996 \family typewriter
25997 /path/to/sdcc/device/include/pic16/pic18fregs.h
25998 \family default
25999 .
26000  The file format is self-explanatory, just add
26001 \newline
26002
26003 \family typewriter
26004 #elif defined(picDEVICE)
26005 \newline
26006 # include <picDEVICE.h>
26007 \family default
26008
26009 \newline
26010 at the right place (keep it sorted).
26011 \end_layout
26012
26013 \begin_layout Enumerate
26014 Edit 
26015 \family typewriter
26016 /path/to/sdcc/src/pic16/devices.inc
26017 \family default
26018 .
26019  Copy and modify an existing entry and insert it at the correct place (keep
26020  the file sorted).
26021  The file is hardly documented, look at the entries for the 18f2221...
26022 \end_layout
26023
26024 \begin_layout Enumerate
26025 Recompile SDCC, including the pic16 libraries.
26026 \end_layout
26027
26028 \begin_layout Subsection
26029 Memory Models
26030 \end_layout
26031
26032 \begin_layout Standard
26033 The following memory models are supported by the PIC16 port:
26034 \end_layout
26035
26036 \begin_layout Itemize
26037 small model
26038 \end_layout
26039
26040 \begin_layout Itemize
26041 large model
26042 \end_layout
26043
26044 \begin_layout Standard
26045 Memory model affects the default size of pointers within the source.
26046  The sizes are shown in the next table:
26047 \end_layout
26048
26049 \begin_layout Standard
26050 \align center
26051 \begin_inset Tabular
26052 <lyxtabular version="3" rows="3" columns="3">
26053 <features>
26054 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26055 <column alignment="center" valignment="top" leftline="true" width="0">
26056 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26057 <row topline="true" bottomline="true">
26058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26059 \begin_inset Text
26060
26061 \begin_layout Standard
26062 Pointer sizes according to memory model
26063 \end_layout
26064
26065 \end_inset
26066 </cell>
26067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26068 \begin_inset Text
26069
26070 \begin_layout Standard
26071 small model
26072 \end_layout
26073
26074 \end_inset
26075 </cell>
26076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26077 \begin_inset Text
26078
26079 \begin_layout Standard
26080 large model
26081 \end_layout
26082
26083 \end_inset
26084 </cell>
26085 </row>
26086 <row topline="true" bottomline="true">
26087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26088 \begin_inset Text
26089
26090 \begin_layout Standard
26091 code pointers
26092 \end_layout
26093
26094 \end_inset
26095 </cell>
26096 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26097 \begin_inset Text
26098
26099 \begin_layout Standard
26100 16-bits
26101 \end_layout
26102
26103 \end_inset
26104 </cell>
26105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26106 \begin_inset Text
26107
26108 \begin_layout Standard
26109 24-bits
26110 \end_layout
26111
26112 \end_inset
26113 </cell>
26114 </row>
26115 <row topline="true" bottomline="true">
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26117 \begin_inset Text
26118
26119 \begin_layout Standard
26120 data pointers
26121 \end_layout
26122
26123 \end_inset
26124 </cell>
26125 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26126 \begin_inset Text
26127
26128 \begin_layout Standard
26129 16-bits
26130 \end_layout
26131
26132 \end_inset
26133 </cell>
26134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26135 \begin_inset Text
26136
26137 \begin_layout Standard
26138 16-bits
26139 \end_layout
26140
26141 \end_inset
26142 </cell>
26143 </row>
26144 </lyxtabular>
26145
26146 \end_inset
26147
26148
26149 \end_layout
26150
26151 \begin_layout Standard
26152 It is advisable that all sources within a project are compiled with the
26153  same memory model.
26154  If one wants to override the default memory model, this can be done by
26155  declaring a pointer as 
26156 \series bold
26157 far
26158 \series default
26159  or 
26160 \series bold
26161 near
26162 \series default
26163 .
26164  Far selects large memory model's pointers, while near selects small memory
26165  model's pointers.
26166 \end_layout
26167
26168 \begin_layout Standard
26169 The standard device libraries (see 
26170 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26171
26172 \end_inset
26173
26174 ) contain no reference to pointers, so they can be used with both memory
26175  models.
26176 \end_layout
26177
26178 \begin_layout Subsection
26179 Stack
26180 \end_layout
26181
26182 \begin_layout Standard
26183 The stack
26184 \begin_inset LatexCommand \index{PIC16!stack}
26185
26186 \end_inset
26187
26188  implementation for the PIC16 port uses two indirect registers, FSR1 and
26189  FSR2.
26190 \end_layout
26191
26192 \begin_layout Description
26193 FSR1 is assigned as stack pointer
26194 \end_layout
26195
26196 \begin_layout Description
26197 FSR2 is assigned as frame pointer
26198 \end_layout
26199
26200 \begin_layout Standard
26201 The following stack models are supported by the PIC16 port
26202 \end_layout
26203
26204 \begin_layout Itemize
26205
26206 \noun on
26207 small
26208 \noun default
26209  model
26210 \end_layout
26211
26212 \begin_layout Itemize
26213
26214 \noun on
26215 large
26216 \noun default
26217  model
26218 \end_layout
26219
26220 \begin_layout Standard
26221
26222 \noun on
26223 Small
26224 \noun default
26225  model means that only the FSRxL byte is used to access stack and frame,
26226  while 
26227 \emph on
26228 \noun on
26229 large
26230 \emph default
26231 \noun default
26232  uses both FSRxL and FSRxH registers.
26233  The following table shows the stack/frame pointers sizes according to stack
26234  model and the maximum space they can address:
26235 \end_layout
26236
26237 \begin_layout Standard
26238 \align center
26239 \begin_inset Tabular
26240 <lyxtabular version="3" rows="3" columns="3">
26241 <features>
26242 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26243 <column alignment="center" valignment="top" leftline="true" width="0">
26244 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26245 <row topline="true" bottomline="true">
26246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26247 \begin_inset Text
26248
26249 \begin_layout Standard
26250 Stack & Frame pointer sizes according to stack model
26251 \end_layout
26252
26253 \end_inset
26254 </cell>
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26256 \begin_inset Text
26257
26258 \begin_layout Standard
26259 small
26260 \end_layout
26261
26262 \end_inset
26263 </cell>
26264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26265 \begin_inset Text
26266
26267 \begin_layout Standard
26268 large
26269 \end_layout
26270
26271 \end_inset
26272 </cell>
26273 </row>
26274 <row topline="true">
26275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26276 \begin_inset Text
26277
26278 \begin_layout Standard
26279 Stack pointer FSR1
26280 \end_layout
26281
26282 \end_inset
26283 </cell>
26284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26285 \begin_inset Text
26286
26287 \begin_layout Standard
26288 8-bits
26289 \end_layout
26290
26291 \end_inset
26292 </cell>
26293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26294 \begin_inset Text
26295
26296 \begin_layout Standard
26297 16-bits
26298 \end_layout
26299
26300 \end_inset
26301 </cell>
26302 </row>
26303 <row topline="true" bottomline="true">
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26305 \begin_inset Text
26306
26307 \begin_layout Standard
26308 Frame pointer FSR2
26309 \end_layout
26310
26311 \end_inset
26312 </cell>
26313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26314 \begin_inset Text
26315
26316 \begin_layout Standard
26317 8-bits
26318 \end_layout
26319
26320 \end_inset
26321 </cell>
26322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26323 \begin_inset Text
26324
26325 \begin_layout Standard
26326 16-bits
26327 \end_layout
26328
26329 \end_inset
26330 </cell>
26331 </row>
26332 </lyxtabular>
26333
26334 \end_inset
26335
26336
26337 \end_layout
26338
26339 \begin_layout Standard
26340
26341 \noun on
26342 Large 
26343 \noun default
26344 stack model is currently not working properly throughout the code generator.
26345  So its use is not advised.
26346  Also there are some other points that need special care:
26347 \newline
26348
26349 \end_layout
26350
26351 \begin_layout Enumerate
26352 Do not create stack sections with size more than one physical bank (that
26353  is 256 bytes)
26354 \end_layout
26355
26356 \begin_layout Enumerate
26357 Stack sections should no cross physical bank limits (i.e.
26358  #pragma stack 0x50 0x100)
26359 \end_layout
26360
26361 \begin_layout Standard
26362 These limitations are caused by the fact that only FSRxL is modified when
26363  using SMALL stack model, so no more than 256 bytes of stack can be used.
26364  This problem will disappear after LARGE model is fully implemented.
26365 \end_layout
26366
26367 \begin_layout Subsection
26368 Functions
26369 \end_layout
26370
26371 \begin_layout Standard
26372 In addition to the standard SDCC function keywords, PIC16
26373 \begin_inset LatexCommand \index{PIC16}
26374
26375 \end_inset
26376
26377  port makes available two more:
26378 \end_layout
26379
26380 \begin_layout Description
26381 wparam
26382 \begin_inset LatexCommand \index{PIC16!wparam}
26383
26384 \end_inset
26385
26386  Use the WREG to pass one byte of the first function argument.
26387  This improves speed but you may not use this for functions with arguments
26388  that are called via function pointers, otherwise the first byte of the
26389  first parameter will get lost.
26390  Usage:
26391 \end_layout
26392
26393 \begin_layout LyX-Code
26394 void func_wparam(int a) wparam
26395 \end_layout
26396
26397 \begin_layout LyX-Code
26398 {
26399 \end_layout
26400
26401 \begin_layout LyX-Code
26402     /* WREG hold the lower part of a */
26403 \end_layout
26404
26405 \begin_layout LyX-Code
26406     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26407  */
26408 \end_layout
26409
26410 \begin_layout LyX-Code
26411 ...
26412 \end_layout
26413
26414 \begin_layout LyX-Code
26415 }
26416 \end_layout
26417
26418 \begin_layout Description
26419 shadowregs
26420 \begin_inset LatexCommand \index{PIC16!shadowregs}
26421
26422 \end_inset
26423
26424  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26425  hardware shadow registers which hold the values of WREG, STATUS and BSR
26426  registers.
26427  This can be done by adding the keyword 
26428 \emph on
26429 shadowregs
26430 \emph default
26431  before the 
26432 \emph on
26433 interrupt
26434 \emph default
26435  keyword in the function's header.
26436 \end_layout
26437
26438 \begin_layout LyX-Code
26439 void isr_shadow(void) shadowregs interrupt 1
26440 \end_layout
26441
26442 \begin_layout LyX-Code
26443 {
26444 \end_layout
26445
26446 \begin_layout LyX-Code
26447 ...
26448 \end_layout
26449
26450 \begin_layout LyX-Code
26451 }
26452 \end_layout
26453
26454 \begin_layout Standard
26455
26456 \emph on
26457 shadowregs
26458 \emph default
26459  instructs the code generator not to store/restore WREG, STATUS, BSR when
26460  entering/exiting the ISR.
26461 \end_layout
26462
26463 \begin_layout Subsection
26464 Function return values
26465 \end_layout
26466
26467 \begin_layout Standard
26468 Return values from functions are placed to the appropriate registers following
26469  a modified Microchip policy optimized for SDCC.
26470  The following table shows these registers:
26471 \end_layout
26472
26473 \begin_layout Standard
26474 \align center
26475 \begin_inset Tabular
26476 <lyxtabular version="3" rows="6" columns="2">
26477 <features>
26478 <column alignment="center" valignment="top" leftline="true" width="0">
26479 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26480 <row topline="true" bottomline="true">
26481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26482 \begin_inset Text
26483
26484 \begin_layout Standard
26485 size
26486 \end_layout
26487
26488 \end_inset
26489 </cell>
26490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26491 \begin_inset Text
26492
26493 \begin_layout Standard
26494 destination register
26495 \end_layout
26496
26497 \end_inset
26498 </cell>
26499 </row>
26500 <row topline="true">
26501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26502 \begin_inset Text
26503
26504 \begin_layout Standard
26505 8 bits
26506 \end_layout
26507
26508 \end_inset
26509 </cell>
26510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26511 \begin_inset Text
26512
26513 \begin_layout Standard
26514 WREG
26515 \end_layout
26516
26517 \end_inset
26518 </cell>
26519 </row>
26520 <row topline="true">
26521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26522 \begin_inset Text
26523
26524 \begin_layout Standard
26525 16 bits
26526 \end_layout
26527
26528 \end_inset
26529 </cell>
26530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26531 \begin_inset Text
26532
26533 \begin_layout Standard
26534 PRODL:WREG
26535 \end_layout
26536
26537 \end_inset
26538 </cell>
26539 </row>
26540 <row topline="true">
26541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26542 \begin_inset Text
26543
26544 \begin_layout Standard
26545 24 bits
26546 \end_layout
26547
26548 \end_inset
26549 </cell>
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26551 \begin_inset Text
26552
26553 \begin_layout Standard
26554 PRODH:PRODL:WREG
26555 \end_layout
26556
26557 \end_inset
26558 </cell>
26559 </row>
26560 <row topline="true">
26561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26562 \begin_inset Text
26563
26564 \begin_layout Standard
26565 32 bits
26566 \end_layout
26567
26568 \end_inset
26569 </cell>
26570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26571 \begin_inset Text
26572
26573 \begin_layout Standard
26574 FSR0L:PRODH:PRODL:WREG
26575 \end_layout
26576
26577 \end_inset
26578 </cell>
26579 </row>
26580 <row topline="true" bottomline="true">
26581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26582 \begin_inset Text
26583
26584 \begin_layout Standard
26585 >32 bits
26586 \end_layout
26587
26588 \end_inset
26589 </cell>
26590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26591 \begin_inset Text
26592
26593 \begin_layout Standard
26594 on stack, FSR0 points to the beginning
26595 \end_layout
26596
26597 \end_inset
26598 </cell>
26599 </row>
26600 </lyxtabular>
26601
26602 \end_inset
26603
26604
26605 \end_layout
26606
26607 \begin_layout Subsection
26608 Interrupts
26609 \end_layout
26610
26611 \begin_layout Standard
26612 An interrupt
26613 \begin_inset LatexCommand \index{PIC16!interrupt}
26614
26615 \end_inset
26616
26617  service routine (ISR) is declared using the 
26618 \emph on
26619 interrupt
26620 \emph default
26621  keyword.
26622 \end_layout
26623
26624 \begin_layout LyX-Code
26625 void isr(void) interrupt 
26626 \emph on
26627 n
26628 \end_layout
26629
26630 \begin_layout LyX-Code
26631 {
26632 \end_layout
26633
26634 \begin_layout LyX-Code
26635 ...
26636 \end_layout
26637
26638 \begin_layout LyX-Code
26639 }
26640 \end_layout
26641
26642 \begin_layout Standard
26643
26644 \emph on
26645 n
26646 \emph default
26647  is the interrupt number, which for PIC18F devices can be:
26648 \end_layout
26649
26650 \begin_layout Standard
26651 \align center
26652 \begin_inset Tabular
26653 <lyxtabular version="3" rows="4" columns="3">
26654 <features>
26655 <column alignment="center" valignment="top" leftline="true" width="0">
26656 <column alignment="center" valignment="top" leftline="true" width="0">
26657 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26658 <row topline="true" bottomline="true">
26659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26660 \begin_inset Text
26661
26662 \begin_layout Standard
26663
26664 \emph on
26665 n
26666 \end_layout
26667
26668 \end_inset
26669 </cell>
26670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26671 \begin_inset Text
26672
26673 \begin_layout Standard
26674 Interrupt Vector
26675 \end_layout
26676
26677 \end_inset
26678 </cell>
26679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26680 \begin_inset Text
26681
26682 \begin_layout Standard
26683 Interrupt Vector Address
26684 \end_layout
26685
26686 \end_inset
26687 </cell>
26688 </row>
26689 <row topline="true">
26690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26691 \begin_inset Text
26692
26693 \begin_layout Standard
26694 0
26695 \end_layout
26696
26697 \end_inset
26698 </cell>
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26700 \begin_inset Text
26701
26702 \begin_layout Standard
26703 RESET vector
26704 \end_layout
26705
26706 \end_inset
26707 </cell>
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26709 \begin_inset Text
26710
26711 \begin_layout Standard
26712 0x000000
26713 \end_layout
26714
26715 \end_inset
26716 </cell>
26717 </row>
26718 <row topline="true">
26719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26720 \begin_inset Text
26721
26722 \begin_layout Standard
26723
26724 \family roman
26725 \series medium
26726 \shape up
26727 \size normal
26728 \emph off
26729 \bar no
26730 \noun off
26731 \color none
26732 1
26733 \end_layout
26734
26735 \end_inset
26736 </cell>
26737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26738 \begin_inset Text
26739
26740 \begin_layout Standard
26741
26742 \family roman
26743 \series medium
26744 \shape up
26745 \size normal
26746 \emph off
26747 \bar no
26748 \noun off
26749 \color none
26750 HIGH priority interrupts
26751 \end_layout
26752
26753 \end_inset
26754 </cell>
26755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26756 \begin_inset Text
26757
26758 \begin_layout Standard
26759 0x000008
26760 \end_layout
26761
26762 \end_inset
26763 </cell>
26764 </row>
26765 <row topline="true" bottomline="true">
26766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26767 \begin_inset Text
26768
26769 \begin_layout Standard
26770 2
26771 \end_layout
26772
26773 \end_inset
26774 </cell>
26775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26776 \begin_inset Text
26777
26778 \begin_layout Standard
26779 LOW priority interrupts
26780 \end_layout
26781
26782 \end_inset
26783 </cell>
26784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26785 \begin_inset Text
26786
26787 \begin_layout Standard
26788 0x000018
26789 \end_layout
26790
26791 \end_inset
26792 </cell>
26793 </row>
26794 </lyxtabular>
26795
26796 \end_inset
26797
26798
26799 \end_layout
26800
26801 \begin_layout Standard
26802 When generating assembly code for ISR the code generator places a 
26803 \noun on
26804 goto 
26805 \noun default
26806 instruction at the 
26807 \emph on
26808 Interrupt Vector Address
26809 \emph default
26810  which points at the genetated ISR.
26811  This single GOTO instruction is part of an automatically generated 
26812 \emph on
26813 interrupt entry point
26814 \emph default
26815  function.
26816  The actuall ISR code is placed as normally would in the code space.
26817  Upon interrupt request, the GOTO instruction is executed which jumps to
26818  the ISR code.
26819  When declaring interrupt functions as _naked this GOTO instruction is 
26820 \series bold
26821 not
26822 \series default
26823  generated.
26824  The whole interrupt functions is therefore placed at the Interrupt Vector
26825  Address of the specific interrupt.
26826  This is not a problem for the LOW priority interrupts, but it is a problem
26827  for the RESET and the HIGH priority interrupts because code may be written
26828  at the next interrupt's vector address and cause undeterminate program
26829  behaviour if that interrupt is raised.
26830 \begin_inset Foot
26831 status open
26832
26833 \begin_layout Standard
26834 This is not a problem when
26835 \end_layout
26836
26837 \begin_layout Enumerate
26838 this is a HIGH interrupt ISR and LOW interrupts are 
26839 \emph on
26840 disabled
26841 \emph default
26842  or not used.
26843 \end_layout
26844
26845 \begin_layout Enumerate
26846 when the ISR is small enough not to reach the next interrupt's vector address.
26847 \end_layout
26848
26849 \end_inset
26850
26851
26852 \end_layout
26853
26854 \begin_layout Standard
26855
26856 \emph on
26857 n
26858 \emph default
26859  may be omitted.
26860  This way a function is generated similar to an ISR, but it is not assigned
26861  to any interrupt.
26862 \end_layout
26863
26864 \begin_layout Standard
26865 When entering an interrupt, currently the PIC16
26866 \begin_inset LatexCommand \index{PIC16}
26867
26868 \end_inset
26869
26870  port automatically saves the following registers:
26871 \end_layout
26872
26873 \begin_layout Itemize
26874 WREG
26875 \end_layout
26876
26877 \begin_layout Itemize
26878 STATUS
26879 \end_layout
26880
26881 \begin_layout Itemize
26882 BSR
26883 \end_layout
26884
26885 \begin_layout Itemize
26886 PROD (PRODL and PRODH)
26887 \end_layout
26888
26889 \begin_layout Itemize
26890 FSR0 (FSR0L and FSR0H)
26891 \end_layout
26892
26893 \begin_layout Standard
26894 These registers are restored upon return from the interrupt routine.
26895 \begin_inset Foot
26896 status open
26897
26898 \begin_layout Standard
26899 NOTE that when the _naked attribute is specified for an interrupt routine,
26900  then NO registers are stored or restored.
26901 \end_layout
26902
26903 \end_inset
26904
26905
26906 \end_layout
26907
26908 \begin_layout Subsection
26909 Generic Pointers
26910 \end_layout
26911
26912 \begin_layout Standard
26913 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26914  There are 3 types of generic pointers currently implemented data, code
26915  and eeprom pointers.
26916  They are differentiated by the value of the 7th and 6th bits of the upper
26917  byte:
26918 \end_layout
26919
26920 \begin_layout Standard
26921 \align center
26922 \begin_inset Tabular
26923 <lyxtabular version="3" rows="5" columns="5">
26924 <features>
26925 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26926 <column alignment="center" valignment="top" width="0">
26927 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26928 <column alignment="center" valignment="top" width="0">
26929 <column alignment="left" valignment="top" rightline="true" width="0">
26930 <row topline="true" bottomline="true">
26931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26932 \begin_inset Text
26933
26934 \begin_layout Standard
26935 pointer type
26936 \end_layout
26937
26938 \end_inset
26939 </cell>
26940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26941 \begin_inset Text
26942
26943 \begin_layout Standard
26944 7th bit
26945 \end_layout
26946
26947 \end_inset
26948 </cell>
26949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26950 \begin_inset Text
26951
26952 \begin_layout Standard
26953 6th bit
26954 \end_layout
26955
26956 \end_inset
26957 </cell>
26958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26959 \begin_inset Text
26960
26961 \begin_layout Standard
26962 rest of the pointer
26963 \end_layout
26964
26965 \end_inset
26966 </cell>
26967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26968 \begin_inset Text
26969
26970 \begin_layout Standard
26971 description
26972 \end_layout
26973
26974 \end_inset
26975 </cell>
26976 </row>
26977 <row topline="true" bottomline="true">
26978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26979 \begin_inset Text
26980
26981 \begin_layout Standard
26982 data 
26983 \end_layout
26984
26985 \end_inset
26986 </cell>
26987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26988 \begin_inset Text
26989
26990 \begin_layout Standard
26991 1
26992 \end_layout
26993
26994 \end_inset
26995 </cell>
26996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26997 \begin_inset Text
26998
26999 \begin_layout Standard
27000 0
27001 \end_layout
27002
27003 \end_inset
27004 </cell>
27005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27006 \begin_inset Text
27007
27008 \begin_layout Standard
27009
27010 \family typewriter
27011 \shape slanted
27012 \emph on
27013 uuuuuu uuuuxxxx xxxxxxxx
27014 \end_layout
27015
27016 \end_inset
27017 </cell>
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27019 \begin_inset Text
27020
27021 \begin_layout Standard
27022 a 12-bit data pointer in data RAM memory
27023 \end_layout
27024
27025 \end_inset
27026 </cell>
27027 </row>
27028 <row bottomline="true">
27029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27030 \begin_inset Text
27031
27032 \begin_layout Standard
27033 code
27034 \end_layout
27035
27036 \end_inset
27037 </cell>
27038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27039 \begin_inset Text
27040
27041 \begin_layout Standard
27042 0
27043 \end_layout
27044
27045 \end_inset
27046 </cell>
27047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27048 \begin_inset Text
27049
27050 \begin_layout Standard
27051 0
27052 \end_layout
27053
27054 \end_inset
27055 </cell>
27056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27057 \begin_inset Text
27058
27059 \begin_layout Standard
27060
27061 \family typewriter
27062 \shape slanted
27063 \emph on
27064 uxxxxx xxxxxxxx xxxxxxxx
27065 \end_layout
27066
27067 \end_inset
27068 </cell>
27069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27070 \begin_inset Text
27071
27072 \begin_layout Standard
27073 a 21-bit code pointer in FLASH memory
27074 \end_layout
27075
27076 \end_inset
27077 </cell>
27078 </row>
27079 <row bottomline="true">
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27081 \begin_inset Text
27082
27083 \begin_layout Standard
27084 eeprom
27085 \end_layout
27086
27087 \end_inset
27088 </cell>
27089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27090 \begin_inset Text
27091
27092 \begin_layout Standard
27093 0
27094 \end_layout
27095
27096 \end_inset
27097 </cell>
27098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27099 \begin_inset Text
27100
27101 \begin_layout Standard
27102 1
27103 \end_layout
27104
27105 \end_inset
27106 </cell>
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27108 \begin_inset Text
27109
27110 \begin_layout Standard
27111
27112 \family typewriter
27113 \shape slanted
27114 \emph on
27115 uuuuuu uuuuuuxx xxxxxxxx
27116 \end_layout
27117
27118 \end_inset
27119 </cell>
27120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27121 \begin_inset Text
27122
27123 \begin_layout Standard
27124 a 10-bit eeprom pointer in EEPROM memory
27125 \end_layout
27126
27127 \end_inset
27128 </cell>
27129 </row>
27130 <row bottomline="true">
27131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27132 \begin_inset Text
27133
27134 \begin_layout Standard
27135 (unimplemented)
27136 \end_layout
27137
27138 \end_inset
27139 </cell>
27140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27141 \begin_inset Text
27142
27143 \begin_layout Standard
27144 1
27145 \end_layout
27146
27147 \end_inset
27148 </cell>
27149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27150 \begin_inset Text
27151
27152 \begin_layout Standard
27153 1
27154 \end_layout
27155
27156 \end_inset
27157 </cell>
27158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27159 \begin_inset Text
27160
27161 \begin_layout Standard
27162
27163 \family typewriter
27164 \shape slanted
27165 \emph on
27166 xxxxxx xxxxxxxx xxxxxxxx
27167 \end_layout
27168
27169 \end_inset
27170 </cell>
27171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27172 \begin_inset Text
27173
27174 \begin_layout Standard
27175 unimplemented pointer type
27176 \end_layout
27177
27178 \end_inset
27179 </cell>
27180 </row>
27181 </lyxtabular>
27182
27183 \end_inset
27184
27185
27186 \end_layout
27187
27188 \begin_layout Standard
27189 Generic pointer are read and written with a set of library functions which
27190  read/write 1, 2, 3, 4 bytes.
27191 \end_layout
27192
27193 \begin_layout Subsection
27194 PIC16 C Libraries
27195 \end_layout
27196
27197 \begin_layout Subsubsection
27198 Standard I/O Streams
27199 \end_layout
27200
27201 \begin_layout Standard
27202 In the 
27203 \emph on
27204 stdio.h
27205 \emph default
27206  the type FILE is defined as:
27207 \end_layout
27208
27209 \begin_layout LyX-Code
27210 typedef char * FILE;
27211 \end_layout
27212
27213 \begin_layout Standard
27214 This type is the stream type implemented I/O in the PIC18F devices.
27215  Also the standard input and output streams are declared in stdio.h:
27216 \end_layout
27217
27218 \begin_layout LyX-Code
27219 extern FILE * stdin;
27220 \end_layout
27221
27222 \begin_layout LyX-Code
27223 extern FILE * stdout;
27224 \end_layout
27225
27226 \begin_layout Standard
27227 The FILE type is actually a generic pointer which defines one more type
27228  of generic pointers, the 
27229 \emph on
27230 stream 
27231 \emph default
27232 pointer.
27233  This new type has the format:
27234 \end_layout
27235
27236 \begin_layout Standard
27237 \align center
27238 \begin_inset Tabular
27239 <lyxtabular version="3" rows="2" columns="7">
27240 <features>
27241 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27242 <column alignment="center" valignment="top" width="0">
27243 <column alignment="center" valignment="top" leftline="true" width="0">
27244 <column alignment="center" valignment="top" leftline="true" width="0">
27245 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27246 <column alignment="center" valignment="top" width="0">
27247 <column alignment="left" valignment="top" rightline="true" width="0">
27248 <row topline="true" bottomline="true">
27249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27250 \begin_inset Text
27251
27252 \begin_layout Standard
27253 pointer type
27254 \end_layout
27255
27256 \end_inset
27257 </cell>
27258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27259 \begin_inset Text
27260
27261 \begin_layout Standard
27262 <7:6>
27263 \end_layout
27264
27265 \end_inset
27266 </cell>
27267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27268 \begin_inset Text
27269
27270 \begin_layout Standard
27271 <5>
27272 \end_layout
27273
27274 \end_inset
27275 </cell>
27276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27277 \begin_inset Text
27278
27279 \begin_layout Standard
27280 <4>
27281 \end_layout
27282
27283 \end_inset
27284 </cell>
27285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27286 \begin_inset Text
27287
27288 \begin_layout Standard
27289 <3:0>
27290 \end_layout
27291
27292 \end_inset
27293 </cell>
27294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27295 \begin_inset Text
27296
27297 \begin_layout Standard
27298 rest of the pointer
27299 \end_layout
27300
27301 \end_inset
27302 </cell>
27303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27304 \begin_inset Text
27305
27306 \begin_layout Standard
27307 descrption
27308 \end_layout
27309
27310 \end_inset
27311 </cell>
27312 </row>
27313 <row topline="true" bottomline="true">
27314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27315 \begin_inset Text
27316
27317 \begin_layout Standard
27318 stream
27319 \end_layout
27320
27321 \end_inset
27322 </cell>
27323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27324 \begin_inset Text
27325
27326 \begin_layout Standard
27327 00
27328 \end_layout
27329
27330 \end_inset
27331 </cell>
27332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27333 \begin_inset Text
27334
27335 \begin_layout Standard
27336 1
27337 \end_layout
27338
27339 \end_inset
27340 </cell>
27341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27342 \begin_inset Text
27343
27344 \begin_layout Standard
27345 0
27346 \end_layout
27347
27348 \end_inset
27349 </cell>
27350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27351 \begin_inset Text
27352
27353 \begin_layout Standard
27354 nnnn
27355 \end_layout
27356
27357 \end_inset
27358 </cell>
27359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27360 \begin_inset Text
27361
27362 \begin_layout Standard
27363
27364 \family typewriter
27365 \shape slanted
27366 \emph on
27367 uuuuuuuu uuuuuuuu
27368 \end_layout
27369
27370 \end_inset
27371 </cell>
27372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27373 \begin_inset Text
27374
27375 \begin_layout Standard
27376 upper byte high nubble is 0x2n, the rest are zeroes
27377 \end_layout
27378
27379 \end_inset
27380 </cell>
27381 </row>
27382 </lyxtabular>
27383
27384 \end_inset
27385
27386
27387 \end_layout
27388
27389 \begin_layout Standard
27390 Currently implemented there are 3 types of streams defined:
27391 \end_layout
27392
27393 \begin_layout Standard
27394 \align center
27395 \begin_inset Tabular
27396 <lyxtabular version="3" rows="4" columns="4">
27397 <features>
27398 <column alignment="center" valignment="top" leftline="true" width="0">
27399 <column alignment="center" valignment="top" leftline="true" width="0">
27400 <column alignment="center" valignment="top" leftline="true" width="0">
27401 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27402 <row topline="true" bottomline="true">
27403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27404 \begin_inset Text
27405
27406 \begin_layout Standard
27407 stream type
27408 \end_layout
27409
27410 \end_inset
27411 </cell>
27412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27413 \begin_inset Text
27414
27415 \begin_layout Standard
27416 value
27417 \end_layout
27418
27419 \end_inset
27420 </cell>
27421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27422 \begin_inset Text
27423
27424 \begin_layout Standard
27425 module
27426 \end_layout
27427
27428 \end_inset
27429 </cell>
27430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27431 \begin_inset Text
27432
27433 \begin_layout Standard
27434 description
27435 \end_layout
27436
27437 \end_inset
27438 </cell>
27439 </row>
27440 <row topline="true">
27441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27442 \begin_inset Text
27443
27444 \begin_layout Standard
27445 STREAM_USART
27446 \end_layout
27447
27448 \end_inset
27449 </cell>
27450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27451 \begin_inset Text
27452
27453 \begin_layout Standard
27454
27455 \family typewriter
27456 0x200000UL
27457 \end_layout
27458
27459 \end_inset
27460 </cell>
27461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27462 \begin_inset Text
27463
27464 \begin_layout Standard
27465 USART
27466 \end_layout
27467
27468 \end_inset
27469 </cell>
27470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27471 \begin_inset Text
27472
27473 \begin_layout Standard
27474 Writes/Reads characters via the USART peripheral
27475 \end_layout
27476
27477 \end_inset
27478 </cell>
27479 </row>
27480 <row topline="true">
27481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27482 \begin_inset Text
27483
27484 \begin_layout Standard
27485 STREAM_MSSP
27486 \end_layout
27487
27488 \end_inset
27489 </cell>
27490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27491 \begin_inset Text
27492
27493 \begin_layout Standard
27494
27495 \family typewriter
27496 0x210000UL
27497 \end_layout
27498
27499 \end_inset
27500 </cell>
27501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27502 \begin_inset Text
27503
27504 \begin_layout Standard
27505 MSSP
27506 \end_layout
27507
27508 \end_inset
27509 </cell>
27510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27511 \begin_inset Text
27512
27513 \begin_layout Standard
27514 Writes/Reads characters via the MSSP peripheral
27515 \end_layout
27516
27517 \end_inset
27518 </cell>
27519 </row>
27520 <row topline="true" bottomline="true">
27521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27522 \begin_inset Text
27523
27524 \begin_layout Standard
27525 STREAM_USER
27526 \end_layout
27527
27528 \end_inset
27529 </cell>
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27531 \begin_inset Text
27532
27533 \begin_layout Standard
27534
27535 \family typewriter
27536 0x2f0000UL
27537 \end_layout
27538
27539 \end_inset
27540 </cell>
27541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27542 \begin_inset Text
27543
27544 \begin_layout Standard
27545 (none)
27546 \end_layout
27547
27548 \end_inset
27549 </cell>
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27551 \begin_inset Text
27552
27553 \begin_layout Standard
27554 Writes/Reads characters via used defined functions
27555 \end_layout
27556
27557 \end_inset
27558 </cell>
27559 </row>
27560 </lyxtabular>
27561
27562 \end_inset
27563
27564
27565 \end_layout
27566
27567 \begin_layout Standard
27568 The stream identifiers are declared as macros in the stdio.h header.
27569 \end_layout
27570
27571 \begin_layout Standard
27572 In the libc library there exist the functions that are used to write to
27573  each of the above streams.
27574  These are
27575 \end_layout
27576
27577 \begin_layout Description
27578 _
27579 \begin_inset ERT
27580 status collapsed
27581
27582 \begin_layout Standard
27583
27584
27585 \backslash
27586 /
27587 \end_layout
27588
27589 \end_inset
27590
27591 _stream_usart_putchar writes a character at the USART stream
27592 \end_layout
27593
27594 \begin_layout Description
27595 _
27596 \begin_inset ERT
27597 status collapsed
27598
27599 \begin_layout Standard
27600
27601
27602 \backslash
27603 /
27604 \end_layout
27605
27606 \end_inset
27607
27608 _stream_mssp_putchar writes a character at the MSSP stream
27609 \end_layout
27610
27611 \begin_layout Description
27612 putchar dummy function.
27613  This writes a character to a user specified manner.
27614 \end_layout
27615
27616 \begin_layout Standard
27617 In order to increase performance 
27618 \emph on
27619 putchar 
27620 \emph default
27621 is declared in stdio.h as having its parameter in WREG (it has the wparam
27622  keyword).
27623  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27624  in a user-friendly way.
27625  
27626 \emph on
27627 arg
27628 \emph default
27629  is the name of the variable that holds the character to print.
27630  An example follows:
27631 \end_layout
27632
27633 \begin_layout LyX-Code
27634 #include <pic18fregs.h>
27635 \newline
27636 #include <stdio.h>
27637 \newline
27638
27639 \newline
27640 PUTCHAR( c )
27641 \end_layout
27642
27643 \begin_layout LyX-Code
27644 {
27645 \end_layout
27646
27647 \begin_layout LyX-Code
27648     PORTA = c;    /* dump character c to PORTA */
27649 \end_layout
27650
27651 \begin_layout LyX-Code
27652
27653 \newline
27654
27655 \newline
27656 void main(void)
27657 \end_layout
27658
27659 \begin_layout LyX-Code
27660 {
27661 \end_layout
27662
27663 \begin_layout LyX-Code
27664     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27665 \end_layout
27666
27667 \begin_layout LyX-Code
27668                               * by default to STREAM_USER */
27669 \end_layout
27670
27671 \begin_layout LyX-Code
27672     printf (
27673 \begin_inset Quotes sld
27674 \end_inset
27675
27676 This is a printf test
27677 \backslash
27678 n
27679 \begin_inset Quotes srd
27680 \end_inset
27681
27682 );
27683 \end_layout
27684
27685 \begin_layout LyX-Code
27686 }
27687 \end_layout
27688
27689 \begin_layout LyX-Code
27690
27691 \end_layout
27692
27693 \begin_layout Subsubsection
27694 Printing functions
27695 \end_layout
27696
27697 \begin_layout Standard
27698 PIC16 contains an implementation of the printf-family of functions.
27699  There exist the following functions:
27700 \end_layout
27701
27702 \begin_layout LyX-Code
27703 extern unsigned int sprintf(char *buf, char *fmt, ...);
27704 \end_layout
27705
27706 \begin_layout LyX-Code
27707 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27708 \end_layout
27709
27710 \begin_layout LyX-Code
27711
27712 \end_layout
27713
27714 \begin_layout LyX-Code
27715 extern unsigned int printf(char *fmt, ...);
27716 \end_layout
27717
27718 \begin_layout LyX-Code
27719 extern unsigned int vprintf(char *fmt, va_lista ap);
27720 \end_layout
27721
27722 \begin_layout LyX-Code
27723
27724 \end_layout
27725
27726 \begin_layout LyX-Code
27727 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27728 \end_layout
27729
27730 \begin_layout LyX-Code
27731 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27732 \end_layout
27733
27734 \begin_layout Standard
27735 For sprintf and vsprintf 
27736 \emph on
27737 buf 
27738 \emph default
27739 should normally be a data pointer where the resulting string will be placed.
27740  No range checking is done so the user should allocate the necessery buffer.
27741  For fprintf and vfprintf 
27742 \emph on
27743 fp
27744 \emph default
27745  should be a stream pointer (i.e.
27746  stdout, STREAM_MSSP, etc...).
27747 \end_layout
27748
27749 \begin_layout Subsubsection
27750 Signals
27751 \end_layout
27752
27753 \begin_layout Standard
27754 The PIC18F family of microcontrollers supports a number of interrupt sources.
27755  A list of these interrupts is shown in the following table:
27756 \end_layout
27757
27758 \begin_layout Standard
27759 \align center
27760 \begin_inset Tabular
27761 <lyxtabular version="3" rows="11" columns="4">
27762 <features>
27763 <column alignment="left" valignment="top" leftline="true" width="0">
27764 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27765 <column alignment="left" valignment="top" leftline="true" width="0">
27766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27767 <row topline="true" bottomline="true">
27768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27769 \begin_inset Text
27770
27771 \begin_layout Standard
27772 signal name
27773 \end_layout
27774
27775 \end_inset
27776 </cell>
27777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27778 \begin_inset Text
27779
27780 \begin_layout Standard
27781 description
27782 \end_layout
27783
27784 \end_inset
27785 </cell>
27786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27787 \begin_inset Text
27788
27789 \begin_layout Standard
27790 signal name
27791 \end_layout
27792
27793 \end_inset
27794 </cell>
27795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27796 \begin_inset Text
27797
27798 \begin_layout Standard
27799 descritpion
27800 \end_layout
27801
27802 \end_inset
27803 </cell>
27804 </row>
27805 <row topline="true">
27806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27807 \begin_inset Text
27808
27809 \begin_layout Standard
27810 SIG_RB
27811 \end_layout
27812
27813 \end_inset
27814 </cell>
27815 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27816 \begin_inset Text
27817
27818 \begin_layout Standard
27819 PORTB change interrupt
27820 \end_layout
27821
27822 \end_inset
27823 </cell>
27824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27825 \begin_inset Text
27826
27827 \begin_layout Standard
27828 SIG_EE
27829 \end_layout
27830
27831 \end_inset
27832 </cell>
27833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27834 \begin_inset Text
27835
27836 \begin_layout Standard
27837 EEPROM/FLASH write complete interrupt
27838 \end_layout
27839
27840 \end_inset
27841 </cell>
27842 </row>
27843 <row topline="true">
27844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27845 \begin_inset Text
27846
27847 \begin_layout Standard
27848 SIG_INT0
27849 \end_layout
27850
27851 \end_inset
27852 </cell>
27853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27854 \begin_inset Text
27855
27856 \begin_layout Standard
27857 INT0 external interrupt
27858 \end_layout
27859
27860 \end_inset
27861 </cell>
27862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27863 \begin_inset Text
27864
27865 \begin_layout Standard
27866 SIG_BCOL
27867 \end_layout
27868
27869 \end_inset
27870 </cell>
27871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27872 \begin_inset Text
27873
27874 \begin_layout Standard
27875 Bus collision interrupt
27876 \end_layout
27877
27878 \end_inset
27879 </cell>
27880 </row>
27881 <row topline="true">
27882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27883 \begin_inset Text
27884
27885 \begin_layout Standard
27886 SIG_INT1
27887 \end_layout
27888
27889 \end_inset
27890 </cell>
27891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27892 \begin_inset Text
27893
27894 \begin_layout Standard
27895 INT1 external interrupt
27896 \end_layout
27897
27898 \end_inset
27899 </cell>
27900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27901 \begin_inset Text
27902
27903 \begin_layout Standard
27904 SIG_LVD
27905 \end_layout
27906
27907 \end_inset
27908 </cell>
27909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27910 \begin_inset Text
27911
27912 \begin_layout Standard
27913 Low voltage detect interrupt
27914 \end_layout
27915
27916 \end_inset
27917 </cell>
27918 </row>
27919 <row topline="true">
27920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27921 \begin_inset Text
27922
27923 \begin_layout Standard
27924 SIG_INT2
27925 \end_layout
27926
27927 \end_inset
27928 </cell>
27929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27930 \begin_inset Text
27931
27932 \begin_layout Standard
27933 INT2 external interrupt
27934 \end_layout
27935
27936 \end_inset
27937 </cell>
27938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27939 \begin_inset Text
27940
27941 \begin_layout Standard
27942 SIG_PSP
27943 \end_layout
27944
27945 \end_inset
27946 </cell>
27947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27948 \begin_inset Text
27949
27950 \begin_layout Standard
27951 Parallel slave port interrupt
27952 \end_layout
27953
27954 \end_inset
27955 </cell>
27956 </row>
27957 <row topline="true">
27958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27959 \begin_inset Text
27960
27961 \begin_layout Standard
27962 SIG_CCP1
27963 \end_layout
27964
27965 \end_inset
27966 </cell>
27967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27968 \begin_inset Text
27969
27970 \begin_layout Standard
27971 CCP1 module interrupt
27972 \end_layout
27973
27974 \end_inset
27975 </cell>
27976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27977 \begin_inset Text
27978
27979 \begin_layout Standard
27980 SIG_AD
27981 \end_layout
27982
27983 \end_inset
27984 </cell>
27985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27986 \begin_inset Text
27987
27988 \begin_layout Standard
27989 AD convertion complete interrupt
27990 \end_layout
27991
27992 \end_inset
27993 </cell>
27994 </row>
27995 <row topline="true">
27996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27997 \begin_inset Text
27998
27999 \begin_layout Standard
28000 SIG_CCP2
28001 \end_layout
28002
28003 \end_inset
28004 </cell>
28005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28006 \begin_inset Text
28007
28008 \begin_layout Standard
28009 CCP2 module interrupt
28010 \end_layout
28011
28012 \end_inset
28013 </cell>
28014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28015 \begin_inset Text
28016
28017 \begin_layout Standard
28018 SIG_RC
28019 \end_layout
28020
28021 \end_inset
28022 </cell>
28023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28024 \begin_inset Text
28025
28026 \begin_layout Standard
28027 USART receive interrupt
28028 \end_layout
28029
28030 \end_inset
28031 </cell>
28032 </row>
28033 <row topline="true">
28034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28035 \begin_inset Text
28036
28037 \begin_layout Standard
28038 SIG_TMR0
28039 \end_layout
28040
28041 \end_inset
28042 </cell>
28043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28044 \begin_inset Text
28045
28046 \begin_layout Standard
28047 TMR0 overflow interrupt
28048 \end_layout
28049
28050 \end_inset
28051 </cell>
28052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28053 \begin_inset Text
28054
28055 \begin_layout Standard
28056 SIG_TX
28057 \end_layout
28058
28059 \end_inset
28060 </cell>
28061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28062 \begin_inset Text
28063
28064 \begin_layout Standard
28065 USART transmit interrupt
28066 \end_layout
28067
28068 \end_inset
28069 </cell>
28070 </row>
28071 <row topline="true">
28072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28073 \begin_inset Text
28074
28075 \begin_layout Standard
28076 SIG_TMR1
28077 \end_layout
28078
28079 \end_inset
28080 </cell>
28081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28082 \begin_inset Text
28083
28084 \begin_layout Standard
28085 TMR1 overflow interrupt
28086 \end_layout
28087
28088 \end_inset
28089 </cell>
28090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28091 \begin_inset Text
28092
28093 \begin_layout Standard
28094 SIG_MSSP
28095 \end_layout
28096
28097 \end_inset
28098 </cell>
28099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28100 \begin_inset Text
28101
28102 \begin_layout Standard
28103 SSP receive/transmit interrupt
28104 \end_layout
28105
28106 \end_inset
28107 </cell>
28108 </row>
28109 <row topline="true">
28110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28111 \begin_inset Text
28112
28113 \begin_layout Standard
28114 SIG_TMR2
28115 \end_layout
28116
28117 \end_inset
28118 </cell>
28119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28120 \begin_inset Text
28121
28122 \begin_layout Standard
28123 TMR2 matches PR2 interrupt
28124 \end_layout
28125
28126 \end_inset
28127 </cell>
28128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28129 \begin_inset Text
28130
28131 \begin_layout Standard
28132
28133 \end_layout
28134
28135 \end_inset
28136 </cell>
28137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28138 \begin_inset Text
28139
28140 \begin_layout Standard
28141
28142 \end_layout
28143
28144 \end_inset
28145 </cell>
28146 </row>
28147 <row topline="true" bottomline="true">
28148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28149 \begin_inset Text
28150
28151 \begin_layout Standard
28152 SIG_TMR3
28153 \end_layout
28154
28155 \end_inset
28156 </cell>
28157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28158 \begin_inset Text
28159
28160 \begin_layout Standard
28161 TMR3 overflow interrupt
28162 \end_layout
28163
28164 \end_inset
28165 </cell>
28166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28167 \begin_inset Text
28168
28169 \begin_layout Standard
28170
28171 \end_layout
28172
28173 \end_inset
28174 </cell>
28175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28176 \begin_inset Text
28177
28178 \begin_layout Standard
28179
28180 \end_layout
28181
28182 \end_inset
28183 </cell>
28184 </row>
28185 </lyxtabular>
28186
28187 \end_inset
28188
28189
28190 \end_layout
28191
28192 \begin_layout Standard
28193 The prototypes for these names are defined in the header file 
28194 \emph on
28195 signal.h
28196 \emph default
28197  .
28198 \end_layout
28199
28200 \begin_layout Standard
28201 In order to simplify signal handling, a number of macros is provided:
28202 \end_layout
28203
28204 \begin_layout List
28205 \labelwidthstring 00.00.0000
28206 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28207  high priority interrupts.
28208  
28209 \emph on
28210 name
28211 \emph default
28212  is the function name to use.
28213 \end_layout
28214
28215 \begin_layout List
28216 \labelwidthstring 00.00.0000
28217 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28218  low priority interrupt.
28219  
28220 \emph on
28221 name
28222 \emph default
28223  is the function name to use.
28224 \end_layout
28225
28226 \begin_layout List
28227 \labelwidthstring 00.00.0000
28228 DEF_HANDLER(sig,handler) define a handler for signal 
28229 \emph on
28230 sig.
28231 \end_layout
28232
28233 \begin_layout List
28234 \labelwidthstring 00.00.0000
28235 END_DEF end the declaration of the dispatch table.
28236 \end_layout
28237
28238 \begin_layout Standard
28239 Additionally there are two more macros to simplify the declaration of the
28240  signal handler:
28241 \end_layout
28242
28243 \begin_layout List
28244 \labelwidthstring 00.00.0000
28245
28246 \series medium
28247 SIGHANDLER(handler) 
28248 \series default
28249 this declares the function prototype for the 
28250 \emph on
28251 handler
28252 \emph default
28253  function.
28254 \end_layout
28255
28256 \begin_layout List
28257 \labelwidthstring 00.00.0000
28258 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28259 \end_layout
28260
28261 \begin_layout Standard
28262 An example of using the macros above is shown below:
28263 \end_layout
28264
28265 \begin_layout LyX-Code
28266 #include <pic18fregs.h>
28267 \end_layout
28268
28269 \begin_layout LyX-Code
28270 #include <signal.h>
28271 \newline
28272
28273 \newline
28274 DEF_INTHIGH(high_int)
28275 \end_layout
28276
28277 \begin_layout LyX-Code
28278 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28279 \end_layout
28280
28281 \begin_layout LyX-Code
28282 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28283 \end_layout
28284
28285 \begin_layout LyX-Code
28286 END_DEF
28287 \newline
28288
28289 \newline
28290 SIGHANDLER(_tmr0_handler)
28291 \end_layout
28292
28293 \begin_layout LyX-Code
28294 {
28295 \end_layout
28296
28297 \begin_layout LyX-Code
28298   /* action to be taken when timer 0 overflows */
28299 \end_layout
28300
28301 \begin_layout LyX-Code
28302 }
28303 \newline
28304
28305 \newline
28306 SIGHANDLERNAKED(_bcol_handler)
28307 \end_layout
28308
28309 \begin_layout LyX-Code
28310 {
28311 \end_layout
28312
28313 \begin_layout LyX-Code
28314   _asm
28315 \end_layout
28316
28317 \begin_layout LyX-Code
28318     /* action to be taken when bus collision occurs */
28319 \end_layout
28320
28321 \begin_layout LyX-Code
28322     retfie
28323 \end_layout
28324
28325 \begin_layout LyX-Code
28326  _endasm;
28327 \end_layout
28328
28329 \begin_layout LyX-Code
28330 }
28331 \end_layout
28332
28333 \begin_layout Standard
28334
28335 \series bold
28336 NOTES:
28337 \series default
28338  Special care should be taken when using the above scheme:
28339 \end_layout
28340
28341 \begin_layout Itemize
28342 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28343 \end_layout
28344
28345 \begin_layout Itemize
28346 when declaring SIGHANDLERNAKED handler never forget to use 
28347 \emph on
28348 retfie
28349 \emph default
28350  for proper returning.
28351 \end_layout
28352
28353 \begin_layout Subsection
28354 PIC16 Port -- Tips
28355 \end_layout
28356
28357 \begin_layout Standard
28358 Here you can find some general tips for compiling programs with SDCC/pic16.
28359 \end_layout
28360
28361 \begin_layout Subsubsection
28362 Stack size
28363 \end_layout
28364
28365 \begin_layout Standard
28366 The default stack
28367 \begin_inset LatexCommand \index{PIC16!stack}
28368
28369 \end_inset
28370
28371  size (that is 64 bytes) probably is enough for many programs.
28372  One must take care that when there are many levels of function nesting,
28373  or there is excessive usage of stack, its size should be extended.
28374  An example of such a case is the printf/sprintf family of functions.
28375  If you encounter problems like not being able to print integers, then you
28376  need to set the stack size around the maximum (256 for small stack model).
28377  The following diagram shows what happens when calling printf to print an
28378  integer:
28379 \end_layout
28380
28381 \begin_layout LyX-Code
28382 printf () --> ltoa () --> ultoa () --> divschar ()
28383 \end_layout
28384
28385 \begin_layout Standard
28386 It is should be understood that stack is easily consumed when calling complicate
28387 d functions.
28388  Using command line arguments like -
28389 \begin_inset ERT
28390 status collapsed
28391
28392 \begin_layout Standard
28393
28394
28395 \backslash
28396 /
28397 \end_layout
28398
28399 \end_inset
28400
28401 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28402  stack frames.
28403  Other ways to reduce stack usage may exist.
28404 \end_layout
28405
28406 \begin_layout Subsection
28407 Known Bugs
28408 \end_layout
28409
28410 \begin_layout Standard
28411 The PIC16 Port currently does not pass SDCC's regression test
28412 \begin_inset LatexCommand \index{Regression test (PIC16)}
28413
28414 \end_inset
28415
28416  suite (see section 
28417 \begin_inset LatexCommand \ref{sec:Quality-control}
28418
28419 \end_inset
28420
28421 ) and thus the snapshot build regression tests for the PIC16 target are
28422  currently disabled for all hosts
28423 \emph on
28424 .
28425 \end_layout
28426
28427 \begin_layout Chapter
28428 Debugging
28429 \end_layout
28430
28431 \begin_layout Standard
28432 There are several approaches to debugging your code.
28433  This chapter is meant to show your options and to give detail on some of
28434  them:
28435 \newline
28436
28437 \newline
28438 When writing your code:
28439 \end_layout
28440
28441 \begin_layout Itemize
28442 write your code with debugging in mind (avoid duplicating code, put conceptually
28443  similar variables into structs, use structured code, have strategic points
28444  within your code where all variables are consistent, ...)
28445 \end_layout
28446
28447 \begin_layout Itemize
28448 run a syntax-checking tool like splint
28449 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28450
28451 \end_inset
28452
28453
28454 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28455
28456 \end_inset
28457
28458  (see -
28459 \begin_inset ERT
28460 status collapsed
28461
28462 \begin_layout Standard
28463
28464
28465 \backslash
28466 /
28467 \end_layout
28468
28469 \end_inset
28470
28471 -more-pedantic 
28472 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28473
28474 \end_inset
28475
28476 ) over the code.
28477 \end_layout
28478
28479 \begin_layout Itemize
28480 for the high level code use a C-compiler (like f.e.
28481  GCC) to compile run and debug the code on your host.
28482  See (see -
28483 \begin_inset ERT
28484 status collapsed
28485
28486 \begin_layout Standard
28487
28488
28489 \backslash
28490 /
28491 \end_layout
28492
28493 \end_inset
28494
28495 -more-pedantic 
28496 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28497
28498 \end_inset
28499
28500 ) on how to handle syntax extensions like __xdata, __at(), ...
28501  
28502 \end_layout
28503
28504 \begin_layout Itemize
28505 use another C-compiler to compile code for your target.
28506  Always an option but not recommended:) And not very likely to help you.
28507  If you seriously consider walking this path you should at least occasionally
28508  check portability of your code.
28509  Most commercial compiler vendors will offer an evaluation version so you
28510  can test compile your code or snippets of your code.
28511 \end_layout
28512
28513 \begin_layout Standard
28514 Debugging on a simulator:
28515 \end_layout
28516
28517 \begin_layout Itemize
28518 there is a separate section about SDCDB (section 
28519 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28520
28521 \end_inset
28522
28523 ) below.
28524 \end_layout
28525
28526 \begin_layout Itemize
28527 or (8051 specific) use a freeware/commercial simulator which interfaces
28528  to the AOMF
28529 \begin_inset LatexCommand \index{AOMF, AOMF51}
28530
28531 \end_inset
28532
28533  file (see 
28534 \begin_inset LatexCommand \ref{OMF file}
28535
28536 \end_inset
28537
28538 ) optionally generated by SDCC.
28539 \end_layout
28540
28541 \begin_layout Standard
28542 Debugging On-target: 
28543 \end_layout
28544
28545 \begin_layout Itemize
28546 use a MCU port pin to serially output debug data to the RS232 port of your
28547  host.
28548  You'll probably want some level shifting device typically involving a MAX232
28549  or similar IC.
28550  If the hardware serial port of the MCU is not available search for 'Software
28551  UART' in your favourite search machine.
28552 \end_layout
28553
28554 \begin_layout Itemize
28555 use an on-target monitor.
28556  In this context a monitor is a small program which usually accepts commands
28557  via a serial line and allows to set program counter, to single step through
28558  a program and read/write memory locations.
28559  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28560  
28561 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28562
28563 \end_inset
28564
28565 ).
28566 \end_layout
28567
28568 \begin_layout Itemize
28569 toggle MCU port pins at strategic points within your code and use an oscilloscop
28570 e.
28571  A 
28572 \emph on
28573 digital oscilloscope
28574 \emph default
28575
28576 \begin_inset LatexCommand \index{Oscilloscope}
28577
28578 \end_inset
28579
28580  with deep trace memory is really helpful especially if you have to debug
28581  a realtime application.
28582  If you need to monitor more pins than your oscilloscope provides you can
28583  sometimes get away with a small R-2R network.
28584  On a single channel oscilloscope you could f.e.
28585  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28586 k
28587 \begin_inset Formula $\Omega$
28588 \end_inset
28589
28590  resistor and the other one by a 5\InsetSpace ~
28591 k
28592 \begin_inset Formula $\Omega$
28593 \end_inset
28594
28595  resistor to the oscilloscope probe (check output drive capability of the
28596  pins you want to monitor).
28597  If you need to monitor many more pins a 
28598 \emph on
28599 logic analyzer
28600 \emph default
28601  will be handy.
28602 \end_layout
28603
28604 \begin_layout Itemize
28605 use an ICE (
28606 \emph on
28607 i
28608 \emph default
28609
28610 \emph on
28611 c
28612 \emph default
28613 ircuit 
28614 \emph on
28615 e
28616 \emph default
28617 mulator
28618 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28619
28620 \end_inset
28621
28622 ).
28623  Usually very expensive.
28624  And very nice to have too.
28625  And usually locks you (for years...) to the devices the ICE can emulate.
28626  
28627 \end_layout
28628
28629 \begin_layout Itemize
28630 use a remote debugger.
28631  In most 8-bit systems the symbol information is not available on the target,
28632  and a complete debugger is too bulky for the target system.
28633  Therefore usually a debugger on the host system connects to an on-target
28634  debugging stub which accepts only primitive commands.
28635  
28636 \newline
28637 Terms to enter into your favourite search engine could be 'remote debugging',
28638  'gdb stub' or 'inferior debugger'.
28639  (is there one?)
28640 \end_layout
28641
28642 \begin_layout Itemize
28643 use an on target hardware debugger.
28644  Some of the more modern MCUs include hardware support for setting break
28645  points and monitoring/changing variables by using dedicated hardware pins.
28646  This facility doesn't require additional code to run on the target and
28647  
28648 \emph on
28649 usually
28650 \emph default
28651  doesn't affect runtime behaviour until a breakpoint is hit.
28652  For the mcs51 most hardware debuggers use the AOMF
28653 \begin_inset LatexCommand \index{AOMF, AOMF51}
28654
28655 \end_inset
28656
28657  file (see 
28658 \begin_inset LatexCommand \ref{OMF file}
28659
28660 \end_inset
28661
28662 ) as input file.
28663  
28664 \end_layout
28665
28666 \begin_layout Standard
28667 Last not least:
28668 \end_layout
28669
28670 \begin_layout Itemize
28671 if you are not familiar with any of the following terms you're likely to
28672  run into problems rather sooner than later: 
28673 \emph on
28674 volatile
28675 \emph default
28676
28677 \emph on
28678 atomic
28679 \emph default
28680
28681 \emph on
28682 memory map
28683 \emph default
28684
28685 \emph on
28686 overlay
28687 \emph default
28688 .
28689  As an embedded programmer you 
28690 \emph on
28691 have
28692 \emph default
28693  to know them so why not look them up 
28694 \emph on
28695 before
28696 \emph default
28697  you have problems?)
28698 \end_layout
28699
28700 \begin_layout Itemize
28701 tell someone else about your problem (actually this is a surprisingly effective
28702  means to hunt down the bug even if the listener is not familiar with your
28703  environment).
28704  As 'failure to communicate' is probably one of the job-induced deformations
28705  of an embedded programmer this is highly encouraged.
28706 \end_layout
28707
28708 \begin_layout Section
28709 Debugging with SDCDB
28710 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28711
28712 \end_inset
28713
28714
28715 \begin_inset LatexCommand \index{SDCDB (debugger)}
28716
28717 \end_inset
28718
28719  
28720 \end_layout
28721
28722 \begin_layout Standard
28723 SDCC is distributed with a source level debugger
28724 \begin_inset LatexCommand \index{Debugger}
28725
28726 \end_inset
28727
28728 .
28729  The debugger uses a command line interface, the command repertoire of the
28730  debugger has been kept as close to gdb
28731 \begin_inset LatexCommand \index{gdb}
28732
28733 \end_inset
28734
28735  (the GNU debugger) as possible.
28736  The configuration and build process is part of the standard compiler installati
28737 on, which also builds and installs the debugger in the target directory
28738  specified during configuration.
28739  The debugger allows you debug BOTH at the C source and at the ASM source
28740  level.
28741 \end_layout
28742
28743 \begin_layout Subsection
28744 Compiling for Debugging
28745 \end_layout
28746
28747 \begin_layout Standard
28748 The -
28749 \begin_inset ERT
28750 status collapsed
28751
28752 \begin_layout Standard
28753
28754
28755 \backslash
28756 /
28757 \end_layout
28758
28759 \end_inset
28760
28761 -debug
28762 \begin_inset LatexCommand \index{-\/-debug}
28763
28764 \end_inset
28765
28766  option must be specified for all files for which debug information is to
28767  be generated.
28768  The compiler generates a .adb file for each of these files.
28769  The linker creates the .cdb
28770 \begin_inset LatexCommand \index{<file>.cdb}
28771
28772 \end_inset
28773
28774  file from the .adb
28775 \begin_inset LatexCommand \index{<file>.adb}
28776
28777 \end_inset
28778
28779  files and the address information.
28780  This .cdb is used by the debugger.
28781 \end_layout
28782
28783 \begin_layout Subsection
28784 How the Debugger Works
28785 \end_layout
28786
28787 \begin_layout Standard
28788 When the -
28789 \begin_inset ERT
28790 status collapsed
28791
28792 \begin_layout Standard
28793
28794
28795 \backslash
28796 /
28797 \end_layout
28798
28799 \end_inset
28800
28801 -debug option is specified the compiler generates extra symbol information
28802  some of which are put into the assembler source and some are put into the
28803  .adb file.
28804  Then the linker creates the .cdb file from the individual .adb files with
28805  the address information for the symbols.
28806  The debugger reads the symbolic information generated by the compiler &
28807  the address information generated by the linker.
28808  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28809  execution is controlled by the debugger.
28810  When a command is issued for the debugger, it translates it into appropriate
28811  commands for the simulator.
28812  (Currently SDCDM only connects to the simulator but 
28813 \emph on
28814 newcdb
28815 \emph default
28816  at 
28817 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28818
28819 \end_inset
28820
28821  is an effort to connect directly to the hardware.) 
28822 \end_layout
28823
28824 \begin_layout Subsection
28825 Starting the Debugger SDCDB
28826 \end_layout
28827
28828 \begin_layout Standard
28829 The debugger can be started using the following command line.
28830  (Assume the file you are debugging has the file name foo).
28831 \newline
28832
28833 \newline
28834
28835 \family sans
28836 \series bold
28837 sdcdb foo
28838 \newline
28839
28840 \family default
28841 \series default
28842
28843 \newline
28844 The debugger will look for the following files.
28845 \end_layout
28846
28847 \begin_layout Itemize
28848 foo.c - the source file.
28849 \end_layout
28850
28851 \begin_layout Itemize
28852 foo.cdb - the debugger symbol information file.
28853 \end_layout
28854
28855 \begin_layout Itemize
28856 foo.ihx - the Intel hex format
28857 \begin_inset LatexCommand \index{Intel hex format}
28858
28859 \end_inset
28860
28861  object file.
28862 \end_layout
28863
28864 \begin_layout Subsection
28865 SDCDB Command Line Options
28866 \end_layout
28867
28868 \begin_layout Itemize
28869 -
28870 \begin_inset ERT
28871 status collapsed
28872
28873 \begin_layout Standard
28874
28875
28876 \backslash
28877 /
28878 \end_layout
28879
28880 \end_inset
28881
28882 -directory=<source file directory> this option can used to specify the directory
28883  search list.
28884  The debugger will look into the directory list specified for source, cdb
28885  & ihx files.
28886  The items in the directory list must be separated by ':', e.g.
28887  if the source files can be in the directories /home/src1 and /home/src2,
28888  the -
28889 \begin_inset ERT
28890 status collapsed
28891
28892 \begin_layout Standard
28893
28894
28895 \backslash
28896 /
28897 \end_layout
28898
28899 \end_inset
28900
28901 -directory option should be -
28902 \begin_inset ERT
28903 status collapsed
28904
28905 \begin_layout Standard
28906
28907
28908 \backslash
28909 /
28910 \end_layout
28911
28912 \end_inset
28913
28914 -directory=/home/src1:/home/src2.
28915  Note there can be no spaces in the option.
28916  
28917 \end_layout
28918
28919 \begin_layout Itemize
28920 -cd <directory> - change to the <directory>.
28921 \end_layout
28922
28923 \begin_layout Itemize
28924 -fullname - used by GUI front ends.
28925 \end_layout
28926
28927 \begin_layout Itemize
28928 -cpu <cpu-type> - this argument is passed to the simulator please see the
28929  simulator docs for details.
28930 \end_layout
28931
28932 \begin_layout Itemize
28933 -X <Clock frequency > this options is passed to the simulator please see
28934  the simulator docs for details.
28935 \end_layout
28936
28937 \begin_layout Itemize
28938 -s <serial port file> passed to simulator see the simulator docs for details.
28939 \end_layout
28940
28941 \begin_layout Itemize
28942 -S <serial in,out> passed to simulator see the simulator docs for details.
28943 \end_layout
28944
28945 \begin_layout Itemize
28946 -k <port number> passed to simulator see the simulator docs for details.
28947 \end_layout
28948
28949 \begin_layout Subsection
28950 SDCDB Debugger Commands
28951 \end_layout
28952
28953 \begin_layout Standard
28954 As mentioned earlier the command interface for the debugger has been deliberatel
28955 y kept as close the GNU debugger gdb, as possible.
28956  This will help the integration with existing graphical user interfaces
28957  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28958  If you use a graphical user interface for the debugger you can skip this
28959  section.
28960 \end_layout
28961
28962 \begin_layout Subsubsection*
28963 break [line | file:line | function | file:function]
28964 \end_layout
28965
28966 \begin_layout Standard
28967 Set breakpoint at specified line or function:
28968 \newline
28969
28970 \newline
28971
28972 \family sans
28973 \series bold
28974 sdcdb>break 100 
28975 \newline
28976 sdcdb>break foo.c:100
28977 \newline
28978 sdcdb>break funcfoo
28979 \newline
28980 sdcdb>break foo.c:funcfoo
28981 \end_layout
28982
28983 \begin_layout Subsubsection*
28984 clear [line | file:line | function | file:function ]
28985 \end_layout
28986
28987 \begin_layout Standard
28988 Clear breakpoint at specified line or function:
28989 \newline
28990
28991 \newline
28992
28993 \family sans
28994 \series bold
28995 sdcdb>clear 100
28996 \newline
28997 sdcdb>clear foo.c:100
28998 \newline
28999 sdcdb>clear funcfoo
29000 \newline
29001 sdcdb>clear foo.c:funcfoo
29002 \end_layout
29003
29004 \begin_layout Subsubsection*
29005 continue
29006 \end_layout
29007
29008 \begin_layout Standard
29009 Continue program being debugged, after breakpoint.
29010 \end_layout
29011
29012 \begin_layout Subsubsection*
29013 finish
29014 \end_layout
29015
29016 \begin_layout Standard
29017 Execute till the end of the current function.
29018 \end_layout
29019
29020 \begin_layout Subsubsection*
29021 delete [n]
29022 \end_layout
29023
29024 \begin_layout Standard
29025 Delete breakpoint number 'n'.
29026  If used without any option clear ALL user defined break points.
29027 \end_layout
29028
29029 \begin_layout Subsubsection*
29030 info [break | stack | frame | registers ]
29031 \end_layout
29032
29033 \begin_layout Itemize
29034 info break - list all breakpoints
29035 \end_layout
29036
29037 \begin_layout Itemize
29038 info stack - show the function call stack.
29039 \end_layout
29040
29041 \begin_layout Itemize
29042 info frame - show information about the current execution frame.
29043 \end_layout
29044
29045 \begin_layout Itemize
29046 info registers - show content of all registers.
29047 \end_layout
29048
29049 \begin_layout Subsubsection*
29050 step
29051 \end_layout
29052
29053 \begin_layout Standard
29054 Step program until it reaches a different source line.
29055  Note: pressing <return> repeats the last command.
29056 \end_layout
29057
29058 \begin_layout Subsubsection*
29059 next
29060 \end_layout
29061
29062 \begin_layout Standard
29063 Step program, proceeding through subroutine calls.
29064 \end_layout
29065
29066 \begin_layout Subsubsection*
29067 run
29068 \end_layout
29069
29070 \begin_layout Standard
29071 Start debugged program.
29072 \end_layout
29073
29074 \begin_layout Subsubsection*
29075 ptype variable 
29076 \end_layout
29077
29078 \begin_layout Standard
29079 Print type information of the variable.
29080 \end_layout
29081
29082 \begin_layout Subsubsection*
29083 print variable
29084 \end_layout
29085
29086 \begin_layout Standard
29087 print value of variable.
29088 \end_layout
29089
29090 \begin_layout Subsubsection*
29091 file filename
29092 \end_layout
29093
29094 \begin_layout Standard
29095 load the given file name.
29096  Note this is an alternate method of loading file for debugging.
29097 \end_layout
29098
29099 \begin_layout Subsubsection*
29100 frame
29101 \end_layout
29102
29103 \begin_layout Standard
29104 print information about current frame.
29105 \end_layout
29106
29107 \begin_layout Subsubsection*
29108 set srcmode
29109 \end_layout
29110
29111 \begin_layout Standard
29112 Toggle between C source & assembly source.
29113 \end_layout
29114
29115 \begin_layout Subsubsection*
29116 ! simulator command
29117 \end_layout
29118
29119 \begin_layout Standard
29120 Send the string following '!' to the simulator, the simulator response is
29121  displayed.
29122  Note the debugger does not interpret the command being sent to the simulator,
29123  so if a command like 'go' is sent the debugger can loose its execution
29124  context and may display incorrect values.
29125 \end_layout
29126
29127 \begin_layout Subsubsection*
29128 quit
29129 \end_layout
29130
29131 \begin_layout Standard
29132 "Watch me now.
29133  Iam going Down.
29134  My name is Bobby Brown"
29135 \end_layout
29136
29137 \begin_layout Subsection
29138 Interfacing SDCDB with DDD
29139 \end_layout
29140
29141 \begin_layout Standard
29142 \begin_inset Note Note
29143 status collapsed
29144
29145 \begin_layout Standard
29146 The screenshot was converted from png to eps with: 
29147 \begin_inset Quotes sld
29148 \end_inset
29149
29150 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29151 \begin_inset Quotes srd
29152 \end_inset
29153
29154  which produces a pretty compact eps file which is free from compression
29155  artifacts.
29156 \end_layout
29157
29158 \begin_layout Standard
29159 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29160  as this broke the build system on Sourceforge (pdf-file was broken.
29161  pdflatex does not accept eps files).
29162 \end_layout
29163
29164 \end_inset
29165
29166
29167 \end_layout
29168
29169 \begin_layout Standard
29170 The 
29171 \emph on
29172 p
29173 \emph default
29174 ortable 
29175 \emph on
29176 n
29177 \emph default
29178 etwork 
29179 \emph on
29180 g
29181 \emph default
29182 raphics File 
29183 \size footnotesize
29184
29185 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29186
29187 \end_inset
29188
29189
29190 \size default
29191  shows a screenshot of a debugging session with DDD
29192 \begin_inset LatexCommand \index{DDD (debugger)}
29193
29194 \end_inset
29195
29196  (Unix only) on a simulated 8032.
29197  The debugging session might not run as smoothly as the screenshot suggests.
29198  The debugger allows setting of breakpoints, displaying and changing variables,
29199  single stepping through C and assembler code.
29200  
29201 \newline
29202 The source was compiled with 
29203 \family sans
29204 \series bold
29205
29206 \newline
29207
29208 \newline
29209 sdcc -
29210 \family default
29211 \series default
29212
29213 \begin_inset ERT
29214 status collapsed
29215
29216 \begin_layout Standard
29217
29218
29219 \backslash
29220 /
29221 \end_layout
29222
29223 \end_inset
29224
29225
29226 \family sans
29227 \series bold
29228 -debug ddd_example.c
29229 \family default
29230 \series default
29231  
29232 \family sans
29233 \series bold
29234
29235 \newline
29236
29237 \family default
29238 \series default
29239
29240 \newline
29241 and DDD was invoked with 
29242 \family sans
29243 \series bold
29244
29245 \newline
29246
29247 \newline
29248 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29249 \end_layout
29250
29251 \begin_layout Standard
29252 \begin_inset Note Note
29253 status open
29254
29255 \begin_layout Standard
29256 Check that the double quotes or an apostroph within the command line survive
29257  the LyX tool chain.
29258  Previously the apostrophs got slanted in the PDF output so a cut and paste
29259  did not work.
29260 \end_layout
29261
29262 \end_inset
29263
29264
29265 \end_layout
29266
29267 \begin_layout Subsection
29268 Interfacing SDCDB with XEmacs
29269 \begin_inset LatexCommand \index{XEmacs}
29270
29271 \end_inset
29272
29273
29274 \begin_inset LatexCommand \index{Emacs}
29275
29276 \end_inset
29277
29278
29279 \end_layout
29280
29281 \begin_layout Standard
29282 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29283  sdcdb.el and sdcdbsrc.el.
29284  These two files can be found in the $(prefix)/bin directory after the installat
29285 ion is complete.
29286  These files need to be loaded into XEmacs for the interface to work.
29287  This can be done at XEmacs startup time by inserting the following into
29288  your '.xemacs' file (which can be found in your HOME directory): 
29289 \newline
29290
29291 \newline
29292
29293 \family typewriter
29294 (load-file sdcdbsrc.el) 
29295 \family default
29296
29297 \newline
29298
29299 \newline
29300 .xemacs is a lisp file so the () around the command is REQUIRED.
29301  The files can also be loaded dynamically while XEmacs is running, set the
29302  environment variable 'EMACSLOADPATH' to the installation bin directory
29303  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29304  To start the interface enter the following command: 
29305 \newline
29306
29307 \newline
29308
29309 \family sans
29310 \series bold
29311 ESC-x sdcdbsrc
29312 \family default
29313 \series default
29314
29315 \newline
29316
29317 \newline
29318 You will prompted to enter the file name to be debugged.
29319  
29320 \newline
29321
29322 \newline
29323 The command line options that are passed to the simulator directly are
29324  bound to default values in the file sdcdbsrc.el.
29325  The variables are listed below, these values maybe changed as required.
29326 \end_layout
29327
29328 \begin_layout Itemize
29329 sdcdbsrc-cpu-type '51
29330 \end_layout
29331
29332 \begin_layout Itemize
29333 sdcdbsrc-frequency '11059200
29334 \end_layout
29335
29336 \begin_layout Itemize
29337 sdcdbsrc-serial nil
29338 \end_layout
29339
29340 \begin_layout Standard
29341 The following is a list of key mapping for the debugger interface.
29342 \end_layout
29343
29344 \begin_layout Standard
29345 \InsetSpace ~
29346
29347 \family typewriter
29348
29349 \newline
29350 ;;\InsetSpace ~
29351 Current Listing :: 
29352 \newline
29353 ;;key\InsetSpace ~
29354 \InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 \InsetSpace ~
29359 \InsetSpace ~
29360 \InsetSpace ~
29361 \InsetSpace ~
29362 \InsetSpace ~
29363 \InsetSpace ~
29364 \InsetSpace ~
29365 \InsetSpace ~
29366 \InsetSpace ~
29367 binding\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 Comment 
29390 \newline
29391 ;;---\InsetSpace ~
29392 \InsetSpace ~
29393 \InsetSpace ~
29394 \InsetSpace ~
29395 \InsetSpace ~
29396 \InsetSpace ~
29397 \InsetSpace ~
29398 \InsetSpace ~
29399 \InsetSpace ~
29400 \InsetSpace ~
29401 \InsetSpace ~
29402 \InsetSpace ~
29403 \InsetSpace ~
29404 \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 \InsetSpace ~
29420 \InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423 \InsetSpace ~
29424 \InsetSpace ~
29425 \InsetSpace ~
29426 \InsetSpace ~
29427 -------
29428 \newline
29429 ;; 
29430 \newline
29431 ;;\InsetSpace ~
29432 n\InsetSpace ~
29433 \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 sdcdb-next-fro
29448 m-src\InsetSpace ~
29449 \InsetSpace ~
29450 \InsetSpace ~
29451 \InsetSpace ~
29452 \InsetSpace ~
29453 \InsetSpace ~
29454 \InsetSpace ~
29455 \InsetSpace ~
29456 \InsetSpace ~
29457 \InsetSpace ~
29458 SDCDB next command 
29459 \newline
29460 ;;\InsetSpace ~
29461 b\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-back-from-src\InsetSpace ~
29477 \InsetSpace ~
29478 \InsetSpace ~
29479 \InsetSpace ~
29480 \InsetSpace ~
29481 \InsetSpace ~
29482 \InsetSpace ~
29483 \InsetSpace ~
29484 \InsetSpace ~
29485 \InsetSpace ~
29486 SDCDB back command 
29487 \newline
29488 ;;\InsetSpace ~
29489 c\InsetSpace ~
29490 \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 sdcdb-cont-f
29505 rom-src\InsetSpace ~
29506 \InsetSpace ~
29507 \InsetSpace ~
29508 \InsetSpace ~
29509 \InsetSpace ~
29510 \InsetSpace ~
29511 \InsetSpace ~
29512 \InsetSpace ~
29513 \InsetSpace ~
29514 \InsetSpace ~
29515 SDCDB continue command
29516 \newline
29517 ;;\InsetSpace ~
29518 s\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-step-from-src\InsetSpace ~
29534 \InsetSpace ~
29535 \InsetSpace ~
29536 \InsetSpace ~
29537 \InsetSpace ~
29538 \InsetSpace ~
29539 \InsetSpace ~
29540 \InsetSpace ~
29541 \InsetSpace ~
29542 \InsetSpace ~
29543 SDCDB step command 
29544 \newline
29545 ;;\InsetSpace ~
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 sdcdb-w
29562 hatis-c-sexp\InsetSpace ~
29563 \InsetSpace ~
29564 \InsetSpace ~
29565 \InsetSpace ~
29566 \InsetSpace ~
29567 \InsetSpace ~
29568 \InsetSpace ~
29569 \InsetSpace ~
29570 \InsetSpace ~
29571 \InsetSpace ~
29572 SDCDB ptypecommand for data at 
29573 \newline
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 \InsetSpace ~
29594 \InsetSpace ~
29595 \InsetSpace ~
29596 \InsetSpace ~
29597 \InsetSpace ~
29598 \InsetSpace ~
29599 \InsetSpace ~
29600 \InsetSpace ~
29601 \InsetSpace ~
29602 \InsetSpace ~
29603 \InsetSpace ~
29604 \InsetSpace ~
29605 \InsetSpace ~
29606 \InsetSpace ~
29607 \InsetSpace ~
29608 \InsetSpace ~
29609 \InsetSpace ~
29610 \InsetSpace ~
29611 \InsetSpace ~
29612 \InsetSpace ~
29613 \InsetSpace ~
29614 \InsetSpace ~
29615 \InsetSpace ~
29616 \InsetSpace ~
29617 \InsetSpace ~
29618 \InsetSpace ~
29619 \InsetSpace ~
29620 \InsetSpace ~
29621 buffer point 
29622 \newline
29623 ;;\InsetSpace ~
29624 x\InsetSpace ~
29625 \InsetSpace ~
29626 \InsetSpace ~
29627 \InsetSpace ~
29628 \InsetSpace ~
29629 \InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 \InsetSpace ~
29633 \InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 sdcdbsrc-delete\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 SDCD
29654 B Delete all breakpoints if no arg 
29655 \newline
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 \InsetSpace ~
29676 \InsetSpace ~
29677 \InsetSpace ~
29678 \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 \InsetSpace ~
29694 \InsetSpace ~
29695 \InsetSpace ~
29696 \InsetSpace ~
29697 \InsetSpace ~
29698 \InsetSpace ~
29699 \InsetSpace ~
29700 \InsetSpace ~
29701 \InsetSpace ~
29702 \InsetSpace ~
29703 given or delete arg (C-u arg x) 
29704 \newline
29705 ;;\InsetSpace ~
29706 m\InsetSpace ~
29707 \InsetSpace ~
29708 \InsetSpace ~
29709 \InsetSpace ~
29710 \InsetSpace ~
29711 \InsetSpace ~
29712 \InsetSpace ~
29713 \InsetSpace ~
29714 \InsetSpace ~
29715 \InsetSpace ~
29716 \InsetSpace ~
29717 \InsetSpace ~
29718 \InsetSpace ~
29719 \InsetSpace ~
29720 \InsetSpace ~
29721 sdcdbsrc
29722 -frame\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 SDCDB Display current frame if no arg, 
29738 \newline
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 \InsetSpace ~
29759 \InsetSpace ~
29760 \InsetSpace ~
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 given or display frame arg
29787  
29788 \newline
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 \InsetSpace ~
29809 \InsetSpace ~
29810 \InsetSpace ~
29811 \InsetSpace ~
29812 \InsetSpace ~
29813 \InsetSpace ~
29814 \InsetSpace ~
29815 \InsetSpace ~
29816 \InsetSpace ~
29817 \InsetSpace ~
29818 \InsetSpace ~
29819 \InsetSpace ~
29820 \InsetSpace ~
29821 \InsetSpace ~
29822 \InsetSpace ~
29823 \InsetSpace ~
29824 \InsetSpace ~
29825 \InsetSpace ~
29826 \InsetSpace ~
29827 \InsetSpace ~
29828 \InsetSpace ~
29829 \InsetSpace ~
29830 \InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 \InsetSpace ~
29835 \InsetSpace ~
29836 buffer point 
29837 \newline
29838 ;;\InsetSpace ~
29839 !\InsetSpace ~
29840 \InsetSpace ~
29841 \InsetSpace ~
29842 \InsetSpace ~
29843 \InsetSpace ~
29844 \InsetSpace ~
29845 \InsetSpace ~
29846 \InsetSpace ~
29847 \InsetSpace ~
29848 \InsetSpace ~
29849 \InsetSpace ~
29850 \InsetSpace ~
29851 \InsetSpace ~
29852 \InsetSpace ~
29853 \InsetSpace ~
29854 sdcdbsrc-goto-sdcdb\InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 Goto the SDCDB output buffer 
29865 \newline
29866 ;;\InsetSpace ~
29867 p\InsetSpace ~
29868 \InsetSpace ~
29869 \InsetSpace ~
29870 \InsetSpace ~
29871 \InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 \InsetSpace ~
29876 \InsetSpace ~
29877 \InsetSpace ~
29878 \InsetSpace ~
29879 \InsetSpace ~
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 sdcdb-prin
29883 t-c-sexp\InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 \InsetSpace ~
29887 \InsetSpace ~
29888 \InsetSpace ~
29889 \InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 \InsetSpace ~
29894 SDCDB print command for data at 
29895 \newline
29896 ;;\InsetSpace ~
29897 \InsetSpace ~
29898 \InsetSpace ~
29899 \InsetSpace ~
29900 \InsetSpace ~
29901 \InsetSpace ~
29902 \InsetSpace ~
29903 \InsetSpace ~
29904 \InsetSpace ~
29905 \InsetSpace ~
29906 \InsetSpace ~
29907 \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911 \InsetSpace ~
29912 \InsetSpace ~
29913 \InsetSpace ~
29914 \InsetSpace ~
29915 \InsetSpace ~
29916 \InsetSpace ~
29917 \InsetSpace ~
29918 \InsetSpace ~
29919 \InsetSpace ~
29920 \InsetSpace ~
29921 \InsetSpace ~
29922 \InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 \InsetSpace ~
29929 \InsetSpace ~
29930 \InsetSpace ~
29931 \InsetSpace ~
29932 \InsetSpace ~
29933 \InsetSpace ~
29934 \InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938 \InsetSpace ~
29939 \InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 buffer point 
29944 \newline
29945 ;;\InsetSpace ~
29946 g\InsetSpace ~
29947 \InsetSpace ~
29948 \InsetSpace ~
29949 \InsetSpace ~
29950 \InsetSpace ~
29951 \InsetSpace ~
29952 \InsetSpace ~
29953 \InsetSpace ~
29954 \InsetSpace ~
29955 \InsetSpace ~
29956 \InsetSpace ~
29957 \InsetSpace ~
29958 \InsetSpace ~
29959 \InsetSpace ~
29960 \InsetSpace ~
29961 sdcdbsrc-goto-sdcdb\InsetSpace ~
29962 \InsetSpace ~
29963 \InsetSpace ~
29964 \InsetSpace ~
29965 \InsetSpace ~
29966 \InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 \InsetSpace ~
29971 Got
29972 o the SDCDB output buffer 
29973 \newline
29974 ;;\InsetSpace ~
29975 t\InsetSpace ~
29976 \InsetSpace ~
29977 \InsetSpace ~
29978 \InsetSpace ~
29979 \InsetSpace ~
29980 \InsetSpace ~
29981 \InsetSpace ~
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 \InsetSpace ~
29986 \InsetSpace ~
29987 \InsetSpace ~
29988 \InsetSpace ~
29989 \InsetSpace ~
29990 sdcdbsrc-mode\InsetSpace ~
29991 \InsetSpace ~
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 \InsetSpace ~
29995 \InsetSpace ~
29996 \InsetSpace ~
29997 \InsetSpace ~
29998 \InsetSpace ~
29999 \InsetSpace ~
30000 \InsetSpace ~
30001 \InsetSpace ~
30002 \InsetSpace ~
30003 \InsetSpace ~
30004 \InsetSpace ~
30005 \InsetSpace ~
30006 Toggles Sdcdbsrc mode (turns it
30007  off) 
30008 \newline
30009 ;; 
30010 \newline
30011 ;;\InsetSpace ~
30012 C-c\InsetSpace ~
30013 C-f\InsetSpace ~
30014 \InsetSpace ~
30015 \InsetSpace ~
30016 \InsetSpace ~
30017 \InsetSpace ~
30018 \InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 sdcdb-finish-from-src\InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 \InsetSpace ~
30029 \InsetSpace ~
30030 SDCDB finish command 
30031 \newline
30032 ;; 
30033 \newline
30034 ;;\InsetSpace ~
30035 C-x\InsetSpace ~
30036 SPC\InsetSpace ~
30037 \InsetSpace ~
30038 \InsetSpace ~
30039 \InsetSpace ~
30040 \InsetSpace ~
30041 \InsetSpace ~
30042 \InsetSpace ~
30043 \InsetSpace ~
30044 \InsetSpace ~
30045 sdcdb-brea
30046 k\InsetSpace ~
30047 \InsetSpace ~
30048 \InsetSpace ~
30049 \InsetSpace ~
30050 \InsetSpace ~
30051 \InsetSpace ~
30052 \InsetSpace ~
30053 \InsetSpace ~
30054 \InsetSpace ~
30055 \InsetSpace ~
30056 \InsetSpace ~
30057 \InsetSpace ~
30058 \InsetSpace ~
30059 \InsetSpace ~
30060 \InsetSpace ~
30061 \InsetSpace ~
30062 \InsetSpace ~
30063 \InsetSpace ~
30064 Set break for line with point 
30065 \newline
30066 ;;\InsetSpace ~
30067 ESC\InsetSpace ~
30068 t\InsetSpace ~
30069 \InsetSpace ~
30070 \InsetSpace ~
30071 \InsetSpace ~
30072 \InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 \InsetSpace ~
30078 \InsetSpace ~
30079 sdcdbsrc-mode\InsetSpace ~
30080 \InsetSpace ~
30081 \InsetSpace ~
30082 \InsetSpace ~
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 \InsetSpace ~
30092 \InsetSpace ~
30093 \InsetSpace ~
30094 \InsetSpace ~
30095 Toggle Sdcdbsrc mode 
30096 \newline
30097 ;;\InsetSpace ~
30098 ESC\InsetSpace ~
30099 m\InsetSpace ~
30100 \InsetSpace ~
30101 \InsetSpace ~
30102 \InsetSpace ~
30103 \InsetSpace ~
30104 \InsetSpace ~
30105 \InsetSpace ~
30106 \InsetSpace ~
30107 \InsetSpace ~
30108 \InsetSpace ~
30109 \InsetSpace ~
30110 sdc
30111 dbsrc-srcmode\InsetSpace ~
30112 \InsetSpace ~
30113 \InsetSpace ~
30114 \InsetSpace ~
30115 \InsetSpace ~
30116 \InsetSpace ~
30117 \InsetSpace ~
30118 \InsetSpace ~
30119 \InsetSpace ~
30120 \InsetSpace ~
30121 \InsetSpace ~
30122 \InsetSpace ~
30123 \InsetSpace ~
30124 Toggle list mode 
30125 \newline
30126 ;; 
30127 \newline
30128
30129 \family default
30130
30131 \newpage
30132
30133 \end_layout
30134
30135 \begin_layout Chapter
30136 TIPS
30137 \end_layout
30138
30139 \begin_layout Standard
30140 Here are a few guidelines that will help the compiler generate more efficient
30141  code, some of the tips are specific to this compiler others are generally
30142  good programming practice.
30143 \end_layout
30144
30145 \begin_layout Itemize
30146 Use the smallest data type to represent your data-value.
30147  If it is known in advance that the value is going to be less than 256 then
30148  use an 'unsigned char' instead of a 'short' or 'int'.
30149  Please note, that ANSI C requires both signed and unsigned chars to be
30150  promoted to 'signed int'
30151 \begin_inset LatexCommand \index{promotion to signed int}
30152
30153 \end_inset
30154
30155
30156 \begin_inset Marginal
30157 status collapsed
30158
30159 \begin_layout Standard
30160
30161 \series bold
30162 \InsetSpace ~
30163 !
30164 \end_layout
30165
30166 \end_inset
30167
30168  before doing any operation.
30169  This promotion
30170 \begin_inset LatexCommand \index{type promotion}
30171
30172 \end_inset
30173
30174
30175 \begin_inset LatexCommand \label{type promotion}
30176
30177 \end_inset
30178
30179  can be omitted, if the result is the same.
30180  The effect of the promotion rules together with the sign-extension is often
30181  surprising:
30182 \end_layout
30183
30184 \begin_deeper
30185 \begin_layout Verse
30186
30187 \family typewriter
30188 unsigned char uc = 0xfe;
30189 \newline
30190 if (uc * uc < 0) /* this is true! */
30191 \newline
30192 {
30193 \newline
30194 \InsetSpace ~
30195 \InsetSpace ~
30196 \InsetSpace ~
30197 \InsetSpace ~
30198 ....
30199 \newline
30200 }
30201 \end_layout
30202
30203 \begin_layout Standard
30204
30205 \family typewriter
30206 uc * uc
30207 \family default
30208  is evaluated as 
30209 \family typewriter
30210 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30211 \family default
30212 .
30213  
30214 \newline
30215 Another one:
30216 \end_layout
30217
30218 \begin_layout Verse
30219
30220 \family typewriter
30221 (unsigned char) -12 / (signed char) -3 = ...
30222 \end_layout
30223
30224 \begin_layout Standard
30225 No, the result is not 4:
30226 \end_layout
30227
30228 \begin_layout Verse
30229
30230 \family typewriter
30231 (int) (unsigned char) -12 / (int) (signed char) -3 =
30232 \newline
30233 (int) (unsigned char)
30234  0xf4 / (int) (signed char) 0xfd =
30235 \newline
30236 (int) 0x00f4 / (int) 0xfffd =
30237 \newline
30238 (int) 0x00f4
30239  / (int) 0xfffd =
30240 \newline
30241 (int) 244 / (int) -3 =
30242 \newline
30243 (int) -81 = (int) 0xffaf;
30244 \end_layout
30245
30246 \begin_layout Standard
30247 Don't complain, that gcc gives you a different result.
30248  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30249  Therefore the results are different.
30250 \newline
30251 From 
30252 \begin_inset Quotes sld
30253 \end_inset
30254
30255 comp.lang.c FAQ
30256 \begin_inset Quotes srd
30257 \end_inset
30258
30259 :
30260 \end_layout
30261
30262 \begin_layout Quote
30263
30264 \emph on
30265 If well-defined overflow characteristics are important and negative values
30266  are not, or if you want to steer clear of sign-extension problems when
30267  manipulating bits or bytes, use one of the corresponding unsigned types.
30268  (Beware when mixing signed and unsigned values in expressions, though.)
30269 \newline
30270 Although
30271  character types (especially unsigned char) can be used as "tiny" integers,
30272  doing so is sometimes more trouble than it's worth, due to unpredictable
30273  sign extension and increased code size.
30274 \end_layout
30275
30276 \end_deeper
30277 \begin_layout Itemize
30278 Use unsigned when it is known in advance that the value is not going to
30279  be negative.
30280  This helps especially if you are doing division or multiplication, bit-shifting
30281  or are using an array index.
30282 \end_layout
30283
30284 \begin_layout Itemize
30285 NEVER jump into a LOOP.
30286 \end_layout
30287
30288 \begin_layout Itemize
30289 Declare the variables to be local
30290 \begin_inset LatexCommand \index{local variables}
30291
30292 \end_inset
30293
30294  whenever possible, especially loop control variables (induction).
30295 \end_layout
30296
30297 \begin_layout Itemize
30298 Have a look at the assembly listing to get a 
30299 \begin_inset Quotes sld
30300 \end_inset
30301
30302 feeling
30303 \begin_inset Quotes srd
30304 \end_inset
30305
30306  for the code generation.
30307 \end_layout
30308
30309 \begin_layout Section
30310 Porting code from or to other compilers
30311 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30312
30313 \end_inset
30314
30315
30316 \end_layout
30317
30318 \begin_layout Itemize
30319 check whether endianness of the compilers differs and adapt where needed.
30320 \end_layout
30321
30322 \begin_layout Itemize
30323 check the device specific header files
30324 \begin_inset LatexCommand \index{Header files}
30325
30326 \end_inset
30327
30328
30329 \begin_inset LatexCommand \index{Include files}
30330
30331 \end_inset
30332
30333  for compiler specific syntax.
30334  Eventually include the file <compiler.h
30335 \begin_inset LatexCommand \index{compiler.h (include file)}
30336
30337 \end_inset
30338
30339
30340 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30341
30342 \end_inset
30343
30344  to allow using common header files.
30345  (see f.e.
30346  cc2510fx.h 
30347 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30348
30349 \end_inset
30350
30351 ).
30352 \end_layout
30353
30354 \begin_layout Itemize
30355 check whether the startup code contains the correct initialization (watchdog,
30356  peripherals).
30357 \end_layout
30358
30359 \begin_layout Itemize
30360 check whether the sizes of short, int, long match.
30361 \end_layout
30362
30363 \begin_layout Itemize
30364 check if some 16 or 32 bit hardware registers require a specific addressing
30365  order (least significant or most significant byte first) and adapt if needed
30366  (
30367 \emph on
30368 first
30369 \emph default
30370  and 
30371 \emph on
30372 last
30373 \emph default
30374  relate to time and not to lower/upper memory location here, so this is
30375  
30376 \emph on
30377 not
30378 \emph default
30379  the same as endianness).
30380 \end_layout
30381
30382 \begin_layout Itemize
30383 check whether the keyword 
30384 \emph on
30385 volatile
30386 \emph default
30387  is used where needed.
30388  The compilers might differ in their optimization characteristics (as different
30389  versions of the same compiler might also use more clever optimizations
30390  this is good idea anyway).
30391  See section 
30392 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30393
30394 \end_inset
30395
30396 .
30397 \end_layout
30398
30399 \begin_layout Itemize
30400 check that the compilers are not told to supress warnings.
30401 \end_layout
30402
30403 \begin_layout Itemize
30404 check and convert compiler specific extensions (interrupts, memory areas,
30405  pragmas etc.).
30406 \end_layout
30407
30408 \begin_layout Itemize
30409 check for differences in type promotion.
30410  Especially check for math operations on 
30411 \family typewriter
30412 char
30413 \family default
30414  or 
30415 \family typewriter
30416 unsigned char
30417 \family default
30418  variables.
30419  For the sake of C99 compatibility SDCC will probably promote these to 
30420 \family typewriter
30421 int
30422 \family default
30423  more often than other compilers.
30424  Eventually insert explicit casts to 
30425 \family typewriter
30426 (char) 
30427 \family default
30428 or
30429 \family typewriter
30430  (unsigned char)
30431 \family default
30432 .
30433  Also check that the ~\InsetSpace ~
30434 operator
30435 \begin_inset LatexCommand \index{\~\/ Operator}
30436
30437 \end_inset
30438
30439  is not used on 
30440 \family typewriter
30441 bit
30442 \begin_inset LatexCommand \index{bit}
30443
30444 \end_inset
30445
30446
30447 \family default
30448  variables, use the !\InsetSpace ~
30449 operator instead.
30450  See sections 
30451 \begin_inset LatexCommand \ref{type promotion}
30452
30453 \end_inset
30454
30455  and 
30456 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30457
30458 \end_inset
30459
30460 .
30461 \end_layout
30462
30463 \begin_layout Itemize
30464 check the assembly code generated for interrupt routines (f.e.
30465  for calls to possibly non-reentrant library functions).
30466 \end_layout
30467
30468 \begin_layout Itemize
30469 check whether timing loops result in proper timing (or preferably consider
30470  a rewrite of the code with timer based delays instead).
30471 \end_layout
30472
30473 \begin_layout Itemize
30474 check for differences in printf parameters (some compilers push (va_arg
30475 \begin_inset LatexCommand \index{vararg, va\_arg}
30476
30477 \end_inset
30478
30479 ) char variables as 
30480 \family typewriter
30481 int
30482 \family default
30483  others push them as 
30484 \family typewriter
30485 char
30486 \family default
30487 .
30488  See section 
30489 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30490
30491 \end_inset
30492
30493 ).
30494 \end_layout
30495
30496 \begin_layout Itemize
30497 check the resulting memory map
30498 \begin_inset LatexCommand \index{Memory map}
30499
30500 \end_inset
30501
30502 .
30503  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30504 ly idata, pdata, xdata).
30505  Eventually check if unexpected library functions are included.
30506 \end_layout
30507
30508 \begin_layout Section
30509 Tools
30510 \begin_inset LatexCommand \index{Tools}
30511
30512 \end_inset
30513
30514  included in the distribution
30515 \end_layout
30516
30517 \begin_layout Standard
30518 \align left
30519 \begin_inset Tabular
30520 <lyxtabular version="3" rows="12" columns="3">
30521 <features>
30522 <column alignment="left" valignment="top" leftline="true" width="0pt">
30523 <column alignment="left" valignment="top" leftline="true" width="0pt">
30524 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30525 <row topline="true" bottomline="true">
30526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30527 \begin_inset Text
30528
30529 \begin_layout Standard
30530
30531 \series bold
30532 Name
30533 \end_layout
30534
30535 \end_inset
30536 </cell>
30537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30538 \begin_inset Text
30539
30540 \begin_layout Standard
30541
30542 \series bold
30543 Purpose
30544 \end_layout
30545
30546 \end_inset
30547 </cell>
30548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30549 \begin_inset Text
30550
30551 \begin_layout Standard
30552
30553 \series bold
30554 Directory
30555 \end_layout
30556
30557 \end_inset
30558 </cell>
30559 </row>
30560 <row topline="true">
30561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30562 \begin_inset Text
30563
30564 \begin_layout Standard
30565 uCsim
30566 \begin_inset LatexCommand \index{uCsim}
30567
30568 \end_inset
30569
30570
30571 \end_layout
30572
30573 \end_inset
30574 </cell>
30575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30576 \begin_inset Text
30577
30578 \begin_layout Standard
30579 Simulator for various architectures
30580 \end_layout
30581
30582 \end_inset
30583 </cell>
30584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30585 \begin_inset Text
30586
30587 \begin_layout Standard
30588 sdcc/sim/ucsim
30589 \end_layout
30590
30591 \end_inset
30592 </cell>
30593 </row>
30594 <row topline="true">
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30596 \begin_inset Text
30597
30598 \begin_layout Standard
30599 keil2sdcc.pl
30600 \end_layout
30601
30602 \end_inset
30603 </cell>
30604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30605 \begin_inset Text
30606
30607 \begin_layout Standard
30608 header file
30609 \begin_inset LatexCommand \index{Header files}
30610
30611 \end_inset
30612
30613
30614 \begin_inset LatexCommand \index{Include files}
30615
30616 \end_inset
30617
30618  conversion
30619 \end_layout
30620
30621 \end_inset
30622 </cell>
30623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30624 \begin_inset Text
30625
30626 \begin_layout Standard
30627 sdcc/support/scripts
30628 \end_layout
30629
30630 \end_inset
30631 </cell>
30632 </row>
30633 <row topline="true">
30634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30635 \begin_inset Text
30636
30637 \begin_layout Standard
30638 mh2h.c
30639 \end_layout
30640
30641 \end_inset
30642 </cell>
30643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30644 \begin_inset Text
30645
30646 \begin_layout Standard
30647 header file conversion
30648 \end_layout
30649
30650 \end_inset
30651 </cell>
30652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30653 \begin_inset Text
30654
30655 \begin_layout Standard
30656 sdcc/support/scripts
30657 \end_layout
30658
30659 \end_inset
30660 </cell>
30661 </row>
30662 <row topline="true">
30663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30664 \begin_inset Text
30665
30666 \begin_layout Standard
30667 as-gbz80
30668 \end_layout
30669
30670 \end_inset
30671 </cell>
30672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30673 \begin_inset Text
30674
30675 \begin_layout Standard
30676 Assembler
30677 \end_layout
30678
30679 \end_inset
30680 </cell>
30681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30682 \begin_inset Text
30683
30684 \begin_layout Standard
30685
30686 \family roman
30687 \series medium
30688 \shape up
30689 \size normal
30690 \emph off
30691 \bar no
30692 \noun off
30693 \color none
30694 sdcc/bin
30695 \end_layout
30696
30697 \end_inset
30698 </cell>
30699 </row>
30700 <row topline="true">
30701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30702 \begin_inset Text
30703
30704 \begin_layout Standard
30705 as-z80
30706 \end_layout
30707
30708 \end_inset
30709 </cell>
30710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30711 \begin_inset Text
30712
30713 \begin_layout Standard
30714 Assembler
30715 \end_layout
30716
30717 \end_inset
30718 </cell>
30719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30720 \begin_inset Text
30721
30722 \begin_layout Standard
30723
30724 \family roman
30725 \series medium
30726 \shape up
30727 \size normal
30728 \emph off
30729 \bar no
30730 \noun off
30731 \color none
30732 sdcc/bin
30733 \end_layout
30734
30735 \end_inset
30736 </cell>
30737 </row>
30738 <row topline="true">
30739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30740 \begin_inset Text
30741
30742 \begin_layout Standard
30743 asx8051
30744 \end_layout
30745
30746 \end_inset
30747 </cell>
30748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30749 \begin_inset Text
30750
30751 \begin_layout Standard
30752 Assembler
30753 \end_layout
30754
30755 \end_inset
30756 </cell>
30757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30758 \begin_inset Text
30759
30760 \begin_layout Standard
30761
30762 \family roman
30763 \series medium
30764 \shape up
30765 \size normal
30766 \emph off
30767 \bar no
30768 \noun off
30769 \color none
30770 sdcc/bin
30771 \end_layout
30772
30773 \end_inset
30774 </cell>
30775 </row>
30776 <row topline="true">
30777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30778 \begin_inset Text
30779
30780 \begin_layout Standard
30781 SDCDB
30782 \end_layout
30783
30784 \end_inset
30785 </cell>
30786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30787 \begin_inset Text
30788
30789 \begin_layout Standard
30790 Simulator
30791 \end_layout
30792
30793 \end_inset
30794 </cell>
30795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30796 \begin_inset Text
30797
30798 \begin_layout Standard
30799
30800 \family roman
30801 \series medium
30802 \shape up
30803 \size normal
30804 \emph off
30805 \bar no
30806 \noun off
30807 \color none
30808 sdcc/bin
30809 \end_layout
30810
30811 \end_inset
30812 </cell>
30813 </row>
30814 <row topline="true">
30815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30816 \begin_inset Text
30817
30818 \begin_layout Standard
30819 aslink
30820 \end_layout
30821
30822 \end_inset
30823 </cell>
30824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30825 \begin_inset Text
30826
30827 \begin_layout Standard
30828 Linker
30829 \end_layout
30830
30831 \end_inset
30832 </cell>
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30834 \begin_inset Text
30835
30836 \begin_layout Standard
30837
30838 \family roman
30839 \series medium
30840 \shape up
30841 \size normal
30842 \emph off
30843 \bar no
30844 \noun off
30845 \color none
30846 sdcc/bin
30847 \end_layout
30848
30849 \end_inset
30850 </cell>
30851 </row>
30852 <row topline="true">
30853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30854 \begin_inset Text
30855
30856 \begin_layout Standard
30857 link-z80
30858 \end_layout
30859
30860 \end_inset
30861 </cell>
30862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30863 \begin_inset Text
30864
30865 \begin_layout Standard
30866 Linker
30867 \end_layout
30868
30869 \end_inset
30870 </cell>
30871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30872 \begin_inset Text
30873
30874 \begin_layout Standard
30875
30876 \family roman
30877 \series medium
30878 \shape up
30879 \size normal
30880 \emph off
30881 \bar no
30882 \noun off
30883 \color none
30884 sdcc/bin
30885 \end_layout
30886
30887 \end_inset
30888 </cell>
30889 </row>
30890 <row topline="true">
30891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30892 \begin_inset Text
30893
30894 \begin_layout Standard
30895 link-gbz80
30896 \end_layout
30897
30898 \end_inset
30899 </cell>
30900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30901 \begin_inset Text
30902
30903 \begin_layout Standard
30904 Linker
30905 \end_layout
30906
30907 \end_inset
30908 </cell>
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30910 \begin_inset Text
30911
30912 \begin_layout Standard
30913
30914 \family roman
30915 \series medium
30916 \shape up
30917 \size normal
30918 \emph off
30919 \bar no
30920 \noun off
30921 \color none
30922 sdcc/bin
30923 \end_layout
30924
30925 \end_inset
30926 </cell>
30927 </row>
30928 <row topline="true" bottomline="true">
30929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30930 \begin_inset Text
30931
30932 \begin_layout Standard
30933 packihx
30934 \end_layout
30935
30936 \end_inset
30937 </cell>
30938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30939 \begin_inset Text
30940
30941 \begin_layout Standard
30942 Intel Hex packer 
30943 \begin_inset LatexCommand \index{packihx (tool)}
30944
30945 \end_inset
30946
30947
30948 \end_layout
30949
30950 \end_inset
30951 </cell>
30952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30953 \begin_inset Text
30954
30955 \begin_layout Standard
30956
30957 \family roman
30958 \series medium
30959 \shape up
30960 \size normal
30961 \emph off
30962 \bar no
30963 \noun off
30964 \color none
30965 sdcc/bin
30966 \end_layout
30967
30968 \end_inset
30969 </cell>
30970 </row>
30971 </lyxtabular>
30972
30973 \end_inset
30974
30975
30976 \newline
30977
30978 \end_layout
30979
30980 \begin_layout Section
30981 Documentation
30982 \begin_inset LatexCommand \index{Documentation}
30983
30984 \end_inset
30985
30986  included in the distribution
30987 \end_layout
30988
30989 \begin_layout Standard
30990 \align left
30991 \begin_inset Tabular
30992 <lyxtabular version="3" rows="10" columns="2">
30993 <features>
30994 <column alignment="block" valignment="top" leftline="true" width="40col%">
30995 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30996 <row topline="true" bottomline="true" endhead="true">
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30998 \begin_inset Text
30999
31000 \begin_layout Standard
31001
31002 \series bold
31003 Subject / Title
31004 \end_layout
31005
31006 \end_inset
31007 </cell>
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31009 \begin_inset Text
31010
31011 \begin_layout Standard
31012
31013 \series bold
31014 Filename / Where to get
31015 \end_layout
31016
31017 \end_inset
31018 </cell>
31019 </row>
31020 <row topline="true">
31021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31022 \begin_inset Text
31023
31024 \begin_layout Standard
31025 SDCC Compiler User Guide
31026 \end_layout
31027
31028 \end_inset
31029 </cell>
31030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31031 \begin_inset Text
31032
31033 \begin_layout Standard
31034 You're reading it right now
31035 \emph on
31036  \InsetSpace ~
31037 \InsetSpace ~
31038 \InsetSpace ~
31039
31040 \hfill
31041 online at:
31042 \emph default
31043
31044 \newline
31045
31046 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31047
31048 \end_inset
31049
31050
31051 \end_layout
31052
31053 \end_inset
31054 </cell>
31055 </row>
31056 <row topline="true">
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31058 \begin_inset Text
31059
31060 \begin_layout Standard
31061 Changelog of SDCC
31062 \end_layout
31063
31064 \end_inset
31065 </cell>
31066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31067 \begin_inset Text
31068
31069 \begin_layout Standard
31070 sdcc/Changelog
31071 \emph on
31072  \InsetSpace ~
31073 \InsetSpace ~
31074 \InsetSpace ~
31075
31076 \hfill
31077 online at:
31078 \emph default
31079
31080 \newline
31081
31082 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31083
31084 \end_inset
31085
31086
31087 \end_layout
31088
31089 \end_inset
31090 </cell>
31091 </row>
31092 <row topline="true">
31093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31094 \begin_inset Text
31095
31096 \begin_layout Standard
31097 ASXXXX
31098 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31099
31100 \end_inset
31101
31102
31103 \begin_inset LatexCommand \index{Assembler documentation}
31104
31105 \end_inset
31106
31107  Assemblers and
31108 \newline
31109 ASLINK
31110 \begin_inset LatexCommand \index{aslink}
31111
31112 \end_inset
31113
31114
31115 \begin_inset LatexCommand \index{Linker documentation}
31116
31117 \end_inset
31118
31119  Relocating Linker
31120 \end_layout
31121
31122 \end_inset
31123 </cell>
31124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31125 \begin_inset Text
31126
31127 \begin_layout Standard
31128 sdcc/as/doc/asxhtm.html 
31129 \emph on
31130 \InsetSpace ~
31131 \InsetSpace ~
31132 \InsetSpace ~
31133
31134 \hfill
31135 online at:
31136 \emph default
31137
31138 \newline
31139
31140 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31141
31142 \end_inset
31143
31144
31145 \end_layout
31146
31147 \end_inset
31148 </cell>
31149 </row>
31150 <row topline="true">
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31152 \begin_inset Text
31153
31154 \begin_layout Standard
31155 SDCC regression test
31156 \begin_inset LatexCommand \index{Regression test}
31157
31158 \end_inset
31159
31160
31161 \end_layout
31162
31163 \end_inset
31164 </cell>
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31166 \begin_inset Text
31167
31168 \begin_layout Standard
31169 sdcc/doc/test_suite_spec.pdf 
31170 \emph on
31171 \InsetSpace ~
31172 \InsetSpace ~
31173 \InsetSpace ~
31174
31175 \hfill
31176 online at:
31177 \emph default
31178
31179 \newline
31180
31181 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31182
31183 \end_inset
31184
31185
31186 \end_layout
31187
31188 \end_inset
31189 </cell>
31190 </row>
31191 <row topline="true">
31192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31193 \begin_inset Text
31194
31195 \begin_layout Standard
31196 Various notes
31197 \end_layout
31198
31199 \end_inset
31200 </cell>
31201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31202 \begin_inset Text
31203
31204 \begin_layout Standard
31205 sdcc/doc/* 
31206 \emph on
31207 \InsetSpace ~
31208 \InsetSpace ~
31209 \InsetSpace ~
31210
31211 \hfill
31212 online at:
31213 \emph default
31214
31215 \newline
31216
31217 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31218
31219 \end_inset
31220
31221
31222 \end_layout
31223
31224 \end_inset
31225 </cell>
31226 </row>
31227 <row topline="true">
31228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31229 \begin_inset Text
31230
31231 \begin_layout Standard
31232 Notes on debugging with SDCDB
31233 \begin_inset LatexCommand \index{SDCDB (debugger)}
31234
31235 \end_inset
31236
31237
31238 \end_layout
31239
31240 \end_inset
31241 </cell>
31242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31243 \begin_inset Text
31244
31245 \begin_layout Standard
31246 sdcc/debugger/README 
31247 \emph on
31248 \InsetSpace ~
31249 \InsetSpace ~
31250 \InsetSpace ~
31251
31252 \hfill
31253 online at
31254 \emph default
31255 :
31256 \newline
31257
31258 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31259
31260 \end_inset
31261
31262
31263 \end_layout
31264
31265 \end_inset
31266 </cell>
31267 </row>
31268 <row topline="true">
31269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31270 \begin_inset Text
31271
31272 \begin_layout Standard
31273 uCsim
31274 \begin_inset LatexCommand \index{uCsim}
31275
31276 \end_inset
31277
31278  Software simulator for microcontrollers
31279 \end_layout
31280
31281 \end_inset
31282 </cell>
31283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31284 \begin_inset Text
31285
31286 \begin_layout Standard
31287
31288 \family roman
31289 \series medium
31290 \shape up
31291 \size normal
31292 \emph off
31293 \bar no
31294 \noun off
31295 \color none
31296 sdcc/sim/ucsim/doc
31297 \family default
31298 \series default
31299 \shape default
31300 \size default
31301 \emph default
31302 \bar default
31303 \noun default
31304 /index.html 
31305 \emph on
31306 \InsetSpace ~
31307 \InsetSpace ~
31308 \InsetSpace ~
31309
31310 \hfill
31311 online at:
31312 \emph default
31313
31314 \newline
31315
31316 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31317
31318 \end_inset
31319
31320
31321 \end_layout
31322
31323 \end_inset
31324 </cell>
31325 </row>
31326 <row topline="true">
31327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31328 \begin_inset Text
31329
31330 \begin_layout Standard
31331 Temporary notes on the pic16
31332 \begin_inset LatexCommand \index{PIC16}
31333
31334 \end_inset
31335
31336  port
31337 \end_layout
31338
31339 \end_inset
31340 </cell>
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31342 \begin_inset Text
31343
31344 \begin_layout Standard
31345 sdcc/src/pic16/NOTES 
31346 \emph on
31347 \InsetSpace ~
31348 \InsetSpace ~
31349 \InsetSpace ~
31350
31351 \hfill
31352 online at:
31353 \newline
31354
31355 \emph default
31356
31357 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31358
31359 \end_inset
31360
31361
31362 \end_layout
31363
31364 \end_inset
31365 </cell>
31366 </row>
31367 <row topline="true" bottomline="true">
31368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31369 \begin_inset Text
31370
31371 \begin_layout Standard
31372 SDCC internal documentation (debugging file format)
31373 \end_layout
31374
31375 \end_inset
31376 </cell>
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31378 \begin_inset Text
31379
31380 \begin_layout Standard
31381 sdcc/doc/
31382 \family roman
31383 \series medium
31384 \shape up
31385 \size normal
31386 \emph off
31387 \bar no
31388 \noun off
31389 \color none
31390 cdbfileformat.pd
31391 \family default
31392 \series default
31393 \shape default
31394 \size default
31395 \emph default
31396 \bar default
31397 \noun default
31398 f
31399 \emph on
31400  \InsetSpace ~
31401 \InsetSpace ~
31402 \InsetSpace ~
31403
31404 \hfill
31405 online at:
31406 \emph default
31407
31408 \newline
31409
31410 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31411
31412 \end_inset
31413
31414
31415 \end_layout
31416
31417 \end_inset
31418 </cell>
31419 </row>
31420 </lyxtabular>
31421
31422 \end_inset
31423
31424
31425 \newline
31426
31427 \end_layout
31428
31429 \begin_layout Section
31430 Related open source tools
31431 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31432
31433 \end_inset
31434
31435
31436 \begin_inset LatexCommand \index{Related tools}
31437
31438 \end_inset
31439
31440
31441 \end_layout
31442
31443 \begin_layout Standard
31444 \align left
31445 \begin_inset Tabular
31446 <lyxtabular version="3" rows="16" columns="3">
31447 <features>
31448 <column alignment="left" valignment="top" leftline="true" width="0pt">
31449 <column alignment="block" valignment="top" leftline="true" width="30line%">
31450 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31451 <row topline="true" bottomline="true">
31452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31453 \begin_inset Text
31454
31455 \begin_layout Standard
31456
31457 \series bold
31458 Name
31459 \end_layout
31460
31461 \end_inset
31462 </cell>
31463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31464 \begin_inset Text
31465
31466 \begin_layout Standard
31467
31468 \series bold
31469 Purpose
31470 \end_layout
31471
31472 \end_inset
31473 </cell>
31474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31475 \begin_inset Text
31476
31477 \begin_layout Standard
31478
31479 \series bold
31480 Where to get
31481 \end_layout
31482
31483 \end_inset
31484 </cell>
31485 </row>
31486 <row topline="true">
31487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31488 \begin_inset Text
31489
31490 \begin_layout Standard
31491 gpsim
31492 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31493
31494 \end_inset
31495
31496
31497 \end_layout
31498
31499 \end_inset
31500 </cell>
31501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31502 \begin_inset Text
31503
31504 \begin_layout Standard
31505 PIC simulator
31506 \end_layout
31507
31508 \end_inset
31509 </cell>
31510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31511 \begin_inset Text
31512
31513 \begin_layout Standard
31514 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31515
31516 \end_inset
31517
31518
31519 \end_layout
31520
31521 \end_inset
31522 </cell>
31523 </row>
31524 <row topline="true">
31525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31526 \begin_inset Text
31527
31528 \begin_layout Standard
31529 gputils
31530 \begin_inset LatexCommand \index{gputils (pic tools)}
31531
31532 \end_inset
31533
31534
31535 \end_layout
31536
31537 \end_inset
31538 </cell>
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31540 \begin_inset Text
31541
31542 \begin_layout Standard
31543 GNU PIC utilities
31544 \end_layout
31545
31546 \end_inset
31547 </cell>
31548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31549 \begin_inset Text
31550
31551 \begin_layout Standard
31552 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31553
31554 \end_inset
31555
31556
31557 \end_layout
31558
31559 \end_inset
31560 </cell>
31561 </row>
31562 <row topline="true">
31563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31564 \begin_inset Text
31565
31566 \begin_layout Standard
31567 flP5
31568 \end_layout
31569
31570 \end_inset
31571 </cell>
31572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31573 \begin_inset Text
31574
31575 \begin_layout Standard
31576 PIC programmer
31577 \end_layout
31578
31579 \end_inset
31580 </cell>
31581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31582 \begin_inset Text
31583
31584 \begin_layout Standard
31585 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31586
31587 \end_inset
31588
31589
31590 \end_layout
31591
31592 \end_inset
31593 </cell>
31594 </row>
31595 <row topline="true">
31596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31597 \begin_inset Text
31598
31599 \begin_layout Standard
31600 ec2drv/newcdb
31601 \end_layout
31602
31603 \end_inset
31604 </cell>
31605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31606 \begin_inset Text
31607
31608 \begin_layout Standard
31609 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31610  (Unix only)
31611 \end_layout
31612
31613 \end_inset
31614 </cell>
31615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31616 \begin_inset Text
31617
31618 \begin_layout Standard
31619 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31620
31621 \end_inset
31622
31623
31624 \end_layout
31625
31626 \end_inset
31627 </cell>
31628 </row>
31629 <row topline="true">
31630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31631 \begin_inset Text
31632
31633 \begin_layout Standard
31634 indent
31635 \begin_inset LatexCommand \index{indent (source formatting tool)}
31636
31637 \end_inset
31638
31639
31640 \end_layout
31641
31642 \end_inset
31643 </cell>
31644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31645 \begin_inset Text
31646
31647 \begin_layout Standard
31648 Formats C source - Master of the white spaces
31649 \end_layout
31650
31651 \end_inset
31652 </cell>
31653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31654 \begin_inset Text
31655
31656 \begin_layout Standard
31657 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31658
31659 \end_inset
31660
31661
31662 \end_layout
31663
31664 \end_inset
31665 </cell>
31666 </row>
31667 <row topline="true">
31668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31669 \begin_inset Text
31670
31671 \begin_layout Standard
31672 srecord
31673 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31674
31675 \end_inset
31676
31677
31678 \end_layout
31679
31680 \end_inset
31681 </cell>
31682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31683 \begin_inset Text
31684
31685 \begin_layout Standard
31686 Object file conversion, checksumming, ...
31687 \end_layout
31688
31689 \end_inset
31690 </cell>
31691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31692 \begin_inset Text
31693
31694 \begin_layout Standard
31695 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31696
31697 \end_inset
31698
31699
31700 \end_layout
31701
31702 \end_inset
31703 </cell>
31704 </row>
31705 <row topline="true">
31706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31707 \begin_inset Text
31708
31709 \begin_layout Standard
31710 objdump
31711 \begin_inset LatexCommand \index{objdump (tool)}
31712
31713 \end_inset
31714
31715
31716 \end_layout
31717
31718 \end_inset
31719 </cell>
31720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31721 \begin_inset Text
31722
31723 \begin_layout Standard
31724 Object file conversion, ...
31725 \end_layout
31726
31727 \end_inset
31728 </cell>
31729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31730 \begin_inset Text
31731
31732 \begin_layout Standard
31733 Part of binutils (should be there anyway)
31734 \end_layout
31735
31736 \end_inset
31737 </cell>
31738 </row>
31739 <row topline="true">
31740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31741 \begin_inset Text
31742
31743 \begin_layout Standard
31744 cmon51
31745 \end_layout
31746
31747 \end_inset
31748 </cell>
31749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31750 \begin_inset Text
31751
31752 \begin_layout Standard
31753 8051 monitor (hex up-/download, single step, disassemble)
31754 \end_layout
31755
31756 \end_inset
31757 </cell>
31758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31759 \begin_inset Text
31760
31761 \begin_layout Standard
31762 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31763
31764 \end_inset
31765
31766
31767 \end_layout
31768
31769 \end_inset
31770 </cell>
31771 </row>
31772 <row topline="true">
31773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31774 \begin_inset Text
31775
31776 \begin_layout Standard
31777 doxygen
31778 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31779
31780 \end_inset
31781
31782
31783 \end_layout
31784
31785 \end_inset
31786 </cell>
31787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31788 \begin_inset Text
31789
31790 \begin_layout Standard
31791 Source code documentation system
31792 \end_layout
31793
31794 \end_inset
31795 </cell>
31796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31797 \begin_inset Text
31798
31799 \begin_layout Standard
31800 \begin_inset LatexCommand \url{http://www.doxygen.org}
31801
31802 \end_inset
31803
31804
31805 \end_layout
31806
31807 \end_inset
31808 </cell>
31809 </row>
31810 <row topline="true">
31811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31812 \begin_inset Text
31813
31814 \begin_layout Standard
31815 kdevelop
31816 \end_layout
31817
31818 \end_inset
31819 </cell>
31820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31821 \begin_inset Text
31822
31823 \begin_layout Standard
31824 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31825 \end_layout
31826
31827 \end_inset
31828 </cell>
31829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31830 \begin_inset Text
31831
31832 \begin_layout Standard
31833 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31834
31835 \end_inset
31836
31837
31838 \end_layout
31839
31840 \end_inset
31841 </cell>
31842 </row>
31843 <row topline="true">
31844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31845 \begin_inset Text
31846
31847 \begin_layout Standard
31848 paulmon
31849 \end_layout
31850
31851 \end_inset
31852 </cell>
31853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31854 \begin_inset Text
31855
31856 \begin_layout Standard
31857 8051 monitor (hex up-/download, single step, disassemble)
31858 \end_layout
31859
31860 \end_inset
31861 </cell>
31862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31863 \begin_inset Text
31864
31865 \begin_layout Standard
31866 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31867
31868 \end_inset
31869
31870
31871 \end_layout
31872
31873 \end_inset
31874 </cell>
31875 </row>
31876 <row topline="true">
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31878 \begin_inset Text
31879
31880 \begin_layout Standard
31881 splint
31882 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31883
31884 \end_inset
31885
31886
31887 \end_layout
31888
31889 \end_inset
31890 </cell>
31891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31892 \begin_inset Text
31893
31894 \begin_layout Standard
31895 Statically checks c sources (see 
31896 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31897
31898 \end_inset
31899
31900 )
31901 \end_layout
31902
31903 \end_inset
31904 </cell>
31905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31906 \begin_inset Text
31907
31908 \begin_layout Standard
31909 \begin_inset LatexCommand \url{http://www.splint.org}
31910
31911 \end_inset
31912
31913
31914 \end_layout
31915
31916 \end_inset
31917 </cell>
31918 </row>
31919 <row topline="true" bottomline="true">
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31921 \begin_inset Text
31922
31923 \begin_layout Standard
31924 ddd
31925 \begin_inset LatexCommand \index{DDD (debugger)}
31926
31927 \end_inset
31928
31929
31930 \end_layout
31931
31932 \end_inset
31933 </cell>
31934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31935 \begin_inset Text
31936
31937 \begin_layout Standard
31938 Debugger, serves nicely as GUI to SDCDB
31939 \begin_inset LatexCommand \index{SDCDB (debugger)}
31940
31941 \end_inset
31942
31943  (Unix only)
31944 \end_layout
31945
31946 \end_inset
31947 </cell>
31948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31949 \begin_inset Text
31950
31951 \begin_layout Standard
31952 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31953
31954 \end_inset
31955
31956
31957 \end_layout
31958
31959 \end_inset
31960 </cell>
31961 </row>
31962 <row bottomline="true">
31963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31964 \begin_inset Text
31965
31966 \begin_layout Standard
31967 d52
31968 \begin_inset LatexCommand \index{d52}
31969
31970 \end_inset
31971
31972
31973 \begin_inset LatexCommand \index{d52 (disassembler)}
31974
31975 \end_inset
31976
31977
31978 \end_layout
31979
31980 \end_inset
31981 </cell>
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31983 \begin_inset Text
31984
31985 \begin_layout Standard
31986 Disassembler, can count instruction cycles
31987 \begin_inset LatexCommand \index{instruction cycles (count)}
31988
31989 \end_inset
31990
31991 , use with options -pnd
31992 \end_layout
31993
31994 \end_inset
31995 </cell>
31996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31997 \begin_inset Text
31998
31999 \begin_layout Standard
32000 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32001
32002 \end_inset
32003
32004
32005 \end_layout
32006
32007 \end_inset
32008 </cell>
32009 </row>
32010 <row bottomline="true">
32011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32012 \begin_inset Text
32013
32014 \begin_layout Standard
32015 cmake
32016 \begin_inset LatexCommand \index{cmake}
32017
32018 \end_inset
32019
32020
32021 \end_layout
32022
32023 \end_inset
32024 </cell>
32025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32026 \begin_inset Text
32027
32028 \begin_layout Standard
32029 Cross platform build system, generates Makefiles
32030 \begin_inset LatexCommand \index{Makefile}
32031
32032 \end_inset
32033
32034  and project workspaces
32035 \begin_inset LatexCommand \index{project workspace}
32036
32037 \end_inset
32038
32039
32040 \end_layout
32041
32042 \end_inset
32043 </cell>
32044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32045 \begin_inset Text
32046
32047 \begin_layout Standard
32048 \begin_inset LatexCommand \url{http://www.cmake.org}
32049
32050 \end_inset
32051
32052  \InsetSpace ~
32053 \InsetSpace ~
32054 \InsetSpace ~
32055 \InsetSpace ~
32056 and a dedicated wiki entry: 
32057 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32058
32059 \end_inset
32060
32061
32062 \end_layout
32063
32064 \end_inset
32065 </cell>
32066 </row>
32067 </lyxtabular>
32068
32069 \end_inset
32070
32071
32072 \newline
32073
32074 \end_layout
32075
32076 \begin_layout Section
32077 Related documentation / recommended reading
32078 \end_layout
32079
32080 \begin_layout Standard
32081 \align left
32082 \begin_inset Tabular
32083 <lyxtabular version="3" rows="7" columns="3">
32084 <features>
32085 <column alignment="left" valignment="top" leftline="true" width="0pt">
32086 <column alignment="left" valignment="top" leftline="true" width="0">
32087 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32088 <row topline="true" bottomline="true">
32089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32090 \begin_inset Text
32091
32092 \begin_layout Standard
32093
32094 \series bold
32095 Name
32096 \end_layout
32097
32098 \end_inset
32099 </cell>
32100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32101 \begin_inset Text
32102
32103 \begin_layout Standard
32104
32105 \series bold
32106 Subject / Title
32107 \end_layout
32108
32109 \end_inset
32110 </cell>
32111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32112 \begin_inset Text
32113
32114 \begin_layout Standard
32115
32116 \series bold
32117 Where to get
32118 \end_layout
32119
32120 \end_inset
32121 </cell>
32122 </row>
32123 <row topline="true">
32124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32125 \begin_inset Text
32126
32127 \begin_layout Standard
32128
32129 \family roman
32130 \series medium
32131 \shape up
32132 \size normal
32133 \emph off
32134 \bar no
32135 \noun off
32136 \color none
32137 c-refcard.pdf
32138 \end_layout
32139
32140 \end_inset
32141 </cell>
32142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32143 \begin_inset Text
32144
32145 \begin_layout Standard
32146 C Reference Card
32147 \begin_inset LatexCommand \index{C Reference card}
32148
32149 \end_inset
32150
32151 , 2 pages
32152 \end_layout
32153
32154 \end_inset
32155 </cell>
32156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32157 \begin_inset Text
32158
32159 \begin_layout Standard
32160 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32161
32162 \end_inset
32163
32164
32165 \end_layout
32166
32167 \end_inset
32168 </cell>
32169 </row>
32170 <row topline="true">
32171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32172 \begin_inset Text
32173
32174 \begin_layout Standard
32175 c-faq
32176 \end_layout
32177
32178 \end_inset
32179 </cell>
32180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32181 \begin_inset Text
32182
32183 \begin_layout Standard
32184 C-FAQ
32185 \begin_inset LatexCommand \index{C FAQ}
32186
32187 \end_inset
32188
32189
32190 \end_layout
32191
32192 \end_inset
32193 </cell>
32194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32195 \begin_inset Text
32196
32197 \begin_layout Standard
32198 \begin_inset LatexCommand \url{http://www.c-faq.com}
32199
32200 \end_inset
32201
32202
32203 \end_layout
32204
32205 \end_inset
32206 </cell>
32207 </row>
32208 <row topline="true">
32209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32210 \begin_inset Text
32211
32212 \begin_layout Standard
32213 ISO/IEC 9899:TC2
32214 \end_layout
32215
32216 \end_inset
32217 </cell>
32218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32219 \begin_inset Text
32220
32221 \begin_layout Standard
32222 \begin_inset Quotes sld
32223 \end_inset
32224
32225 C-Standard
32226 \begin_inset Quotes srd
32227 \end_inset
32228
32229
32230 \end_layout
32231
32232 \end_inset
32233 </cell>
32234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32235 \begin_inset Text
32236
32237 \begin_layout Standard
32238
32239 \size footnotesize
32240 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32241
32242 \end_inset
32243
32244
32245 \end_layout
32246
32247 \end_inset
32248 </cell>
32249 </row>
32250 <row topline="true">
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32252 \begin_inset Text
32253
32254 \begin_layout Standard
32255 ISO/IEC DTR 18037
32256 \end_layout
32257
32258 \end_inset
32259 </cell>
32260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32261 \begin_inset Text
32262
32263 \begin_layout Standard
32264 \begin_inset Quotes sld
32265 \end_inset
32266
32267 Extensions for Embedded C
32268 \begin_inset Quotes srd
32269 \end_inset
32270
32271
32272 \end_layout
32273
32274 \end_inset
32275 </cell>
32276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32277 \begin_inset Text
32278
32279 \begin_layout Standard
32280
32281 \size footnotesize
32282 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32283
32284 \end_inset
32285
32286
32287 \end_layout
32288
32289 \end_inset
32290 </cell>
32291 </row>
32292 <row topline="true">
32293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32294 \begin_inset Text
32295
32296 \begin_layout Standard
32297
32298 \end_layout
32299
32300 \end_inset
32301 </cell>
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32303 \begin_inset Text
32304
32305 \begin_layout Standard
32306 Latest datasheet of target CPU
32307 \end_layout
32308
32309 \end_inset
32310 </cell>
32311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32312 \begin_inset Text
32313
32314 \begin_layout Standard
32315 vendor
32316 \end_layout
32317
32318 \end_inset
32319 </cell>
32320 </row>
32321 <row topline="true" bottomline="true">
32322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32323 \begin_inset Text
32324
32325 \begin_layout Standard
32326
32327 \end_layout
32328
32329 \end_inset
32330 </cell>
32331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32332 \begin_inset Text
32333
32334 \begin_layout Standard
32335 Revision history of datasheet
32336 \end_layout
32337
32338 \end_inset
32339 </cell>
32340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32341 \begin_inset Text
32342
32343 \begin_layout Standard
32344 vendor
32345 \end_layout
32346
32347 \end_inset
32348 </cell>
32349 </row>
32350 </lyxtabular>
32351
32352 \end_inset
32353
32354
32355 \newline
32356
32357 \end_layout
32358
32359 \begin_layout Section
32360 Application notes specifically for SDCC
32361 \end_layout
32362
32363 \begin_layout Standard
32364 SDCC makes no claims about the completeness of this list and about up-to-datenes
32365 s or correctness of the application notes
32366 \begin_inset LatexCommand \index{Application notes}
32367
32368 \end_inset
32369
32370 .
32371 \end_layout
32372
32373 \begin_layout Standard
32374 \align left
32375
32376 \size footnotesize
32377 \begin_inset Tabular
32378 <lyxtabular version="3" rows="7" columns="3">
32379 <features>
32380 <column alignment="block" valignment="top" leftline="true" width="17col%">
32381 <column alignment="block" valignment="top" leftline="true" width="27col%">
32382 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32383 <row topline="true" bottomline="true">
32384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32385 \begin_inset Text
32386
32387 \begin_layout Standard
32388
32389 \series bold
32390 \size footnotesize
32391 Vendor
32392 \end_layout
32393
32394 \end_inset
32395 </cell>
32396 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32397 \begin_inset Text
32398
32399 \begin_layout Standard
32400
32401 \series bold
32402 \size footnotesize
32403 Subject / Title
32404 \end_layout
32405
32406 \end_inset
32407 </cell>
32408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32409 \begin_inset Text
32410
32411 \begin_layout Standard
32412
32413 \series bold
32414 \size footnotesize
32415 Where to get
32416 \end_layout
32417
32418 \end_inset
32419 </cell>
32420 </row>
32421 <row topline="true">
32422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32423 \begin_inset Text
32424
32425 \begin_layout Standard
32426
32427 \size footnotesize
32428 Maxim / Dallas
32429 \end_layout
32430
32431 \end_inset
32432 </cell>
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32434 \begin_inset Text
32435
32436 \begin_layout Standard
32437
32438 \size footnotesize
32439 Using the SDCC Compiler for the DS80C400
32440 \begin_inset LatexCommand \index{DS80C400}
32441
32442 \end_inset
32443
32444
32445 \end_layout
32446
32447 \end_inset
32448 </cell>
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32450 \begin_inset Text
32451
32452 \begin_layout Standard
32453
32454 \size footnotesize
32455 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32456
32457 \end_inset
32458
32459
32460 \end_layout
32461
32462 \end_inset
32463 </cell>
32464 </row>
32465 <row topline="true">
32466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32467 \begin_inset Text
32468
32469 \begin_layout Standard
32470
32471 \size footnotesize
32472 Maxim / Dallas
32473 \end_layout
32474
32475 \end_inset
32476 </cell>
32477 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32478 \begin_inset Text
32479
32480 \begin_layout Standard
32481
32482 \size footnotesize
32483 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32484 \begin_inset LatexCommand \index{DS89C4x0}
32485
32486 \end_inset
32487
32488  Family of Microcontrollers
32489 \end_layout
32490
32491 \end_inset
32492 </cell>
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32494 \begin_inset Text
32495
32496 \begin_layout Standard
32497
32498 \size footnotesize
32499 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32500
32501 \end_inset
32502
32503
32504 \end_layout
32505
32506 \end_inset
32507 </cell>
32508 </row>
32509 <row topline="true">
32510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32511 \begin_inset Text
32512
32513 \begin_layout Standard
32514
32515 \size footnotesize
32516 Silicon Laboratories / Cygnal
32517 \end_layout
32518
32519 \end_inset
32520 </cell>
32521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32522 \begin_inset Text
32523
32524 \begin_layout Standard
32525
32526 \size footnotesize
32527 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32528 \begin_inset LatexCommand \index{IDE}
32529
32530 \end_inset
32531
32532
32533 \end_layout
32534
32535 \end_inset
32536 </cell>
32537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32538 \begin_inset Text
32539
32540 \begin_layout Standard
32541
32542 \size footnotesize
32543 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32544
32545 \end_inset
32546
32547
32548 \end_layout
32549
32550 \end_inset
32551 </cell>
32552 </row>
32553 <row topline="true">
32554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32555 \begin_inset Text
32556
32557 \begin_layout Standard
32558
32559 \size footnotesize
32560 Ramtron / Goal Semiconductor
32561 \end_layout
32562
32563 \end_inset
32564 </cell>
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 Interfacing SDCC to Syn and Textpad
32572 \end_layout
32573
32574 \end_inset
32575 </cell>
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32577 \begin_inset Text
32578
32579 \begin_layout Standard
32580
32581 \size footnotesize
32582 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32583
32584 \end_inset
32585
32586
32587 \end_layout
32588
32589 \end_inset
32590 </cell>
32591 </row>
32592 <row topline="true">
32593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32594 \begin_inset Text
32595
32596 \begin_layout Standard
32597
32598 \size footnotesize
32599 Ramtron / Goal Semiconductor
32600 \end_layout
32601
32602 \end_inset
32603 </cell>
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 Installing and Configuring SDCC and Crimson Editor 
32611 \end_layout
32612
32613 \end_inset
32614 </cell>
32615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32616 \begin_inset Text
32617
32618 \begin_layout Standard
32619
32620 \size footnotesize
32621 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32622
32623 \end_inset
32624
32625
32626 \end_layout
32627
32628 \end_inset
32629 </cell>
32630 </row>
32631 <row topline="true" bottomline="true">
32632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32633 \begin_inset Text
32634
32635 \begin_layout Standard
32636
32637 \size footnotesize
32638 Texas Instruments
32639 \end_layout
32640
32641 \end_inset
32642 </cell>
32643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32644 \begin_inset Text
32645
32646 \begin_layout Standard
32647
32648 \size footnotesize
32649 MSC12xx Programming with SDCC
32650 \end_layout
32651
32652 \end_inset
32653 </cell>
32654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32655 \begin_inset Text
32656
32657 \begin_layout Standard
32658
32659 \size footnotesize
32660 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32661
32662 \end_inset
32663
32664
32665 \end_layout
32666
32667 \end_inset
32668 </cell>
32669 </row>
32670 </lyxtabular>
32671
32672 \end_inset
32673
32674
32675 \end_layout
32676
32677 \begin_layout Section
32678 Some Questions
32679 \end_layout
32680
32681 \begin_layout Standard
32682 Some questions answered, some pointers given - it might be time to in turn
32683  ask 
32684 \emph on
32685 you
32686 \emph default
32687  some questions: 
32688 \end_layout
32689
32690 \begin_layout Itemize
32691 can you solve your project with the selected microcontroller? Would you
32692  find out early or rather late that your target is too small/slow/whatever?
32693  Can you switch to a slightly better device if it doesn't fit?
32694 \end_layout
32695
32696 \begin_layout Itemize
32697 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32698  and/or another programming language be more adequate? Would an operating
32699  system on the target device help?
32700 \end_layout
32701
32702 \begin_layout Itemize
32703 if you solved the problem, will the marketing department be happy?
32704 \end_layout
32705
32706 \begin_layout Itemize
32707 if the marketing department is happy, will customers be happy?
32708 \end_layout
32709
32710 \begin_layout Itemize
32711 if you're the project manager, marketing department and maybe even the customer
32712  in one person, have you tried to see the project from the outside?
32713 \end_layout
32714
32715 \begin_layout Itemize
32716 is the project done if you think it is done? Or is just that other interface/pro
32717 tocol/feature/configuration/option missing? How about website, manual(s),
32718  internationali(z|s)ation, packaging, labels, 2nd source for components,
32719  electromagnetic compatability/interference, documentation for production,
32720  production test software, update mechanism, patent issues?
32721 \end_layout
32722
32723 \begin_layout Itemize
32724 is your project adequately positioned in that magic triangle: fame, fortune,
32725  fun?
32726 \end_layout
32727
32728 \begin_layout Standard
32729 Maybe not all answers to these questions are known and some answers may
32730  even be 
32731 \emph on
32732 no
32733 \emph default
32734 , nevertheless knowing these questions may help you to avoid burnout
32735 \begin_inset Foot
32736 status open
32737
32738 \begin_layout Standard
32739 burnout is bad for electronic devices, programmers and motorcycle tyres
32740 \end_layout
32741
32742 \end_inset
32743
32744 .
32745  Chances are you didn't want to hear some of them...
32746 \end_layout
32747
32748 \begin_layout Chapter
32749 Support
32750 \begin_inset LatexCommand \index{Support}
32751
32752 \end_inset
32753
32754
32755 \end_layout
32756
32757 \begin_layout Standard
32758 SDCC has grown to be a large project.
32759  The compiler alone (without the preprocessor, assembler and linker) is
32760  well over 150,000 lines of code (blank stripped).
32761  The open source nature of this project is a key to its continued growth
32762  and support.
32763  You gain the benefit and support of many active software developers and
32764  end users.
32765  Is SDCC perfect? No, that's why we need your help.
32766  The developers take pride in fixing reported bugs.
32767  You can help by reporting the bugs and helping other SDCC users.
32768  There are lots of ways to contribute, and we encourage you to take part
32769  in making SDCC a great software package.
32770  
32771 \end_layout
32772
32773 \begin_layout Standard
32774 The SDCC project is hosted on the SDCC sourceforge site at 
32775 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32776
32777 \end_inset
32778
32779 .
32780  You'll find the complete set of mailing lists
32781 \begin_inset LatexCommand \index{Mailing list(s)}
32782
32783 \end_inset
32784
32785 , forums, bug reporting system, patch submission
32786 \begin_inset LatexCommand \index{Patch submission}
32787
32788 \end_inset
32789
32790  system, download
32791 \begin_inset LatexCommand \index{download}
32792
32793 \end_inset
32794
32795  area and Subversion code repository
32796 \begin_inset LatexCommand \index{Subversion code repository}
32797
32798 \end_inset
32799
32800  there.
32801 \end_layout
32802
32803 \begin_layout Section
32804 Reporting Bugs
32805 \begin_inset LatexCommand \index{Bug reporting}
32806
32807 \end_inset
32808
32809
32810 \begin_inset LatexCommand \index{Reporting bugs}
32811
32812 \end_inset
32813
32814
32815 \end_layout
32816
32817 \begin_layout Standard
32818 The recommended way of reporting bugs is using the infrastructure of the
32819  sourceforge site.
32820  You can follow the status of bug reports there and have an overview about
32821  the known bugs.
32822 \end_layout
32823
32824 \begin_layout Standard
32825 Bug reports are automatically forwarded to the developer mailing list and
32826  will be fixed ASAP.
32827  When reporting a bug, it is very useful to include a small test program
32828  (the smaller the better) which reproduces the problem.
32829  If you can isolate the problem by looking at the generated assembly code,
32830  this can be very helpful.
32831  Compiling your program with the -
32832 \begin_inset ERT
32833 status collapsed
32834
32835 \begin_layout Standard
32836
32837
32838 \backslash
32839 /
32840 \end_layout
32841
32842 \end_inset
32843
32844 -dumpall
32845 \begin_inset LatexCommand \index{-\/-dumpall}
32846
32847 \end_inset
32848
32849  option can sometimes be useful in locating optimization problems.
32850  When reporting a bug please make sure you:
32851 \end_layout
32852
32853 \begin_layout Enumerate
32854 Attach the code you are compiling with SDCC.
32855  
32856 \end_layout
32857
32858 \begin_layout Enumerate
32859 Specify the exact command you use to run SDCC, or attach your Makefile.
32860  
32861 \end_layout
32862
32863 \begin_layout Enumerate
32864 Specify the SDCC version (type "
32865 \family sans
32866 \series bold
32867 sdcc -v
32868 \family default
32869 \series default
32870 "), your platform, and operating system.
32871  
32872 \end_layout
32873
32874 \begin_layout Enumerate
32875 Provide an exact copy of any error message or incorrect output.
32876  
32877 \end_layout
32878
32879 \begin_layout Enumerate
32880 Put something meaningful in the subject of your message.
32881 \end_layout
32882
32883 \begin_layout Standard
32884 Please attempt to include these 5 important parts, as applicable, in all
32885  requests for support or when reporting any problems or bugs with SDCC.
32886  Though this will make your message lengthy, it will greatly improve your
32887  chance that SDCC users and developers will be able to help you.
32888  Some SDCC developers are frustrated by bug reports without code provided
32889  that they can use to reproduce and ultimately fix the problem, so please
32890  be sure to provide sample code if you are reporting a bug! 
32891 \end_layout
32892
32893 \begin_layout Standard
32894 Please have a short check that you are using a recent version of SDCC and
32895  the bug is not yet known.
32896  This is the link for reporting bugs: 
32897 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32898
32899 \end_inset
32900
32901 .
32902  With SDCC on average having more than 200 downloads
32903 \begin_inset LatexCommand \index{download}
32904
32905 \end_inset
32906
32907  on sourceforge per day
32908 \begin_inset Foot
32909 status open
32910
32911 \begin_layout Standard
32912 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32913  between 2002 and 2005.
32914  This does not include other methods of distribution.
32915 \end_layout
32916
32917 \end_inset
32918
32919  there must be some users.
32920  So it's not exactly easy to find a new bug.
32921  If you find one we need it: 
32922 \emph on
32923 reporting bugs is good
32924 \emph default
32925 .
32926 \end_layout
32927
32928 \begin_layout Section
32929 Requesting Features
32930 \begin_inset LatexCommand \label{sub:Requesting-Features}
32931
32932 \end_inset
32933
32934
32935 \begin_inset LatexCommand \index{Feature request}
32936
32937 \end_inset
32938
32939
32940 \begin_inset LatexCommand \index{Requesting features}
32941
32942 \end_inset
32943
32944
32945 \end_layout
32946
32947 \begin_layout Standard
32948 Like bug reports feature requests are forwarded to the developer mailing
32949  list.
32950  This is the link for requesting features: 
32951 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32952
32953 \end_inset
32954
32955 .
32956 \end_layout
32957
32958 \begin_layout Section
32959 Submitting patches
32960 \end_layout
32961
32962 \begin_layout Standard
32963 Like bug reports contributed patches are forwarded to the developer mailing
32964  list.
32965  This is the link for submitting patches
32966 \begin_inset LatexCommand \index{Patch submission}
32967
32968 \end_inset
32969
32970
32971 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32972
32973 \end_inset
32974
32975 .
32976 \end_layout
32977
32978 \begin_layout Standard
32979 You need to specify some parameters to the 
32980 \family typewriter
32981 diff
32982 \family default
32983  command for the patches to be useful.
32984  If you modified more than one file a patch created f.e.
32985  with 
32986 \family sans
32987 \series bold
32988
32989 \begin_inset Quotes sld
32990 \end_inset
32991
32992 diff -Naur unmodified_directory modified_directory >my_changes.patch
32993 \begin_inset Quotes srd
32994 \end_inset
32995
32996
32997 \family default
32998 \series default
32999  will be fine, otherwise 
33000 \family sans
33001 \series bold
33002
33003 \begin_inset Quotes sld
33004 \end_inset
33005
33006 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33007 \begin_inset Quotes srd
33008 \end_inset
33009
33010
33011 \series default
33012  
33013 \family default
33014 will do.
33015 \end_layout
33016
33017 \begin_layout Section
33018 Getting Help
33019 \end_layout
33020
33021 \begin_layout Standard
33022 These links should take you directly to the 
33023 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33024
33025 \end_inset
33026
33027
33028 \begin_inset Foot
33029 status open
33030
33031 \begin_layout Standard
33032 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33033  automated messages (mid 2003)
33034 \end_layout
33035
33036 \end_inset
33037
33038  and the 
33039 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33040
33041 \end_inset
33042
33043 , lists
33044 \begin_inset LatexCommand \index{Mailing list(s)}
33045
33046 \end_inset
33047
33048  and forums are archived and searchable so if you are lucky someone already
33049  had a similar problem.
33050  While mails to the lists themselves are delivered promptly their web front
33051  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33052  if you're seriously using SDCC please consider subscribing to the lists.
33053 \end_layout
33054
33055 \begin_layout Section
33056 ChangeLog
33057 \end_layout
33058
33059 \begin_layout Standard
33060 You can follow the status of the Subversion version
33061 \begin_inset LatexCommand \index{version}
33062
33063 \end_inset
33064
33065  of SDCC by watching the Changelog
33066 \begin_inset LatexCommand \index{Changelog}
33067
33068 \end_inset
33069
33070  in the Subversion repository
33071 \size footnotesize
33072  
33073 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33074
33075 \end_inset
33076
33077 .
33078 \end_layout
33079
33080 \begin_layout Section
33081 Subversion Source Code Repository
33082 \end_layout
33083
33084 \begin_layout Standard
33085 The output of 
33086 \family sans
33087 \series bold
33088 sdcc -
33089 \family default
33090
33091 \begin_inset ERT
33092 status open
33093
33094 \begin_layout Standard
33095
33096
33097 \backslash
33098 /
33099 \end_layout
33100
33101 \end_inset
33102
33103
33104 \family sans
33105 -version
33106 \family default
33107 \series default
33108  or the filenames of the snapshot versions of SDCC include date and its
33109  Subversion
33110 \begin_inset LatexCommand \index{Subversion code repository}
33111
33112 \end_inset
33113
33114  number.
33115  Subversion allows to download the source of recent or previous versions
33116  
33117 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33118
33119 \end_inset
33120
33121  (by number or by date).
33122  An on-line source code browser and detailled instructions are also available
33123  there.
33124  SDCC versions starting from 1999 up to now are available (currently the
33125  versions prior to the conversion from cvs
33126 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33127
33128 \end_inset
33129
33130  to Subversion (April 2006) are either by accessible by Subversion or by
33131  cvs).
33132 \end_layout
33133
33134 \begin_layout Section
33135 Release policy
33136 \begin_inset LatexCommand \index{Release policy}
33137
33138 \end_inset
33139
33140
33141 \end_layout
33142
33143 \begin_layout Standard
33144 Historically there often were long delays between official releases and
33145  the sourceforge download area tends to get not updated at all.
33146  Excuses in the past might have referred to problems with live range analysis,
33147  but as this was fixed a while ago, the current problem is that another
33148  excuse has to be found.
33149  Kidding aside, we have to get better there! On the other hand there are
33150  daily snapshots available at 
33151 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33152
33153 \end_inset
33154
33155 , and you can always build the very last version (hopefully with many bugs
33156  fixed, and features added) from the source code available at 
33157 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33158
33159 \end_inset
33160
33161 .
33162  The SDCC Wiki
33163 \begin_inset LatexCommand \index{wiki}
33164
33165 \end_inset
33166
33167
33168 \begin_inset LatexCommand \index{SDCC Wiki}
33169
33170 \end_inset
33171
33172  at 
33173 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33174
33175 \end_inset
33176
33177  also holds some information about past and future releases.
33178 \end_layout
33179
33180 \begin_layout Section
33181 Examples
33182 \begin_inset LatexCommand \index{Examples}
33183
33184 \end_inset
33185
33186
33187 \end_layout
33188
33189 \begin_layout Standard
33190 You'll find some small examples in the directory 
33191 \emph on
33192 sdcc/device/examples/.
33193  
33194 \emph default
33195 More examples and libraries are available at
33196 \emph on
33197  The SDCC Open Knowledge Resource 
33198 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33199
33200 \end_inset
33201
33202  
33203 \emph default
33204 web site or at 
33205 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33206
33207 \end_inset
33208
33209 .
33210 \end_layout
33211
33212 \begin_layout Standard
33213 \begin_inset Note Note
33214 status collapsed
33215
33216 \begin_layout Standard
33217 I did insert a reference to Paul's web site here although it seems rather
33218  dedicated to a specific 8032 board (I think it's okay because it f.e.
33219  shows LCD/Harddisc interface and has a free 8051 monitor.
33220  Independent 8032 board vendors face hard competition of heavily subsidized
33221  development boards anyway).
33222 \end_layout
33223
33224 \begin_layout Standard
33225 Maybe we should include some links to real world applications.
33226  Preferably pointer to pointers (one for each architecture) so this stays
33227  manageable here?
33228 \end_layout
33229
33230 \end_inset
33231
33232
33233 \end_layout
33234
33235 \begin_layout Section
33236 Quality control
33237 \begin_inset LatexCommand \label{sec:Quality-control}
33238
33239 \end_inset
33240
33241
33242 \begin_inset LatexCommand \index{Quality control}
33243
33244 \end_inset
33245
33246
33247 \end_layout
33248
33249 \begin_layout Standard
33250 The compiler is passed through snaphot build compile and build checks.
33251  The so called 
33252 \shape italic
33253 regression tests
33254 \shape default
33255
33256 \begin_inset LatexCommand \index{Regression test}
33257
33258 \end_inset
33259
33260  check that SDCC itself compiles flawlessly on several host platforms (i386,
33261  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33262  and checks the quality of the code generated by SDCC by running the code
33263  for several target platforms through simulators.
33264  The regression test suite comprises more than 100 files which expand to
33265  more than 500 test cases which include more than 4500 tests.
33266  The results of these tests are published daily on SDCC's snapshot page
33267  (click on the red or green symbols on the right side of 
33268 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33269
33270 \end_inset
33271
33272 ).
33273 \end_layout
33274
33275 \begin_layout Standard
33276 There is a separate document 
33277 \shape italic
33278 test_suite.pdf 
33279 \begin_inset LatexCommand \index{Test suite}
33280
33281 \end_inset
33282
33283
33284 \shape default
33285  
33286 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33287
33288 \end_inset
33289
33290  about the regression test suite.
33291 \end_layout
33292
33293 \begin_layout Standard
33294 You'll find the test code in the directory 
33295 \shape italic
33296 sdcc/support/regression
33297 \shape default
33298 .
33299  You can run these tests manually by running 
33300 \family sans
33301 make
33302 \family default
33303  in this directory (or f.e.
33304  
33305 \family sans
33306 \series bold
33307
33308 \begin_inset Quotes sld
33309 \end_inset
33310
33311 make test-mcs51
33312 \begin_inset Quotes srd
33313 \end_inset
33314
33315
33316 \family default
33317 \series default
33318  if you don't want to run the complete tests).
33319  The test code might also be interesting if you want to look for examples
33320 \begin_inset LatexCommand \index{Examples}
33321
33322 \end_inset
33323
33324  checking corner cases of SDCC or if you plan to submit patches
33325 \begin_inset LatexCommand \index{Patch submission}
33326
33327 \end_inset
33328
33329 .
33330 \end_layout
33331
33332 \begin_layout Standard
33333 The PIC14 port uses a different set of regression tests 
33334 \begin_inset LatexCommand \index{Regression test (PIC14)}
33335
33336 \end_inset
33337
33338 , you'll find them in the directory 
33339 \shape italic
33340 sdcc/src/regression
33341 \shape default
33342 .
33343 \end_layout
33344
33345 \begin_layout Section
33346 Use of SDCC in Education
33347 \end_layout
33348
33349 \begin_layout Standard
33350 In short: 
33351 \emph on
33352 highly
33353 \emph default
33354  encouraged
33355 \begin_inset Foot
33356 status open
33357
33358 \begin_layout Standard
33359 the phrase "use in education" might evoke the association "
33360 \emph on
33361 only
33362 \emph default
33363  fit for use in education".
33364  This connotation is not intended but nevertheless risked as the licensing
33365  of SDCC makes it difficult to offer educational discounts
33366 \end_layout
33367
33368 \end_inset
33369
33370 .
33371  If your rationales are to:
33372 \end_layout
33373
33374 \begin_layout Enumerate
33375 give students a chance to understand the 
33376 \emph on
33377 complete
33378 \emph default
33379  steps of code generation
33380 \end_layout
33381
33382 \begin_layout Enumerate
33383 have a curriculum that can be extended for years.
33384  Then you could use an fpga board as target and your curriculum will seamlessly
33385  extend from logic synthesis (
33386 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33387
33388 \end_inset
33389
33390
33391 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33392
33393 \end_inset
33394
33395 ), over assembly programming, to C to FPGA compilers (
33396 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33397
33398 \end_inset
33399
33400 ) and to C.
33401 \end_layout
33402
33403 \begin_layout Enumerate
33404 be able to insert excursions about skills like using a revision control
33405  system, submitting/applying patches, using a type-setting (as opposed to
33406  word-processing) engine LyX/LaTeX, using 
33407 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33408
33409 \end_inset
33410
33411 , following some 
33412 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33413
33414 \end_inset
33415
33416 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33417  Source Software, CPU simulation, compiler regression tests
33418 \begin_inset LatexCommand \index{Regression test}
33419
33420 \end_inset
33421
33422 .
33423  
33424 \newline
33425 And if there should be a shortage of ideas then you can always point students
33426  to the ever-growing feature request list 
33427 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33428
33429 \end_inset
33430
33431 .
33432 \end_layout
33433
33434 \begin_layout Enumerate
33435 not tie students to a specific host platform and instead allow them to use
33436  a host platform of 
33437 \emph on
33438 their
33439 \emph default
33440  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33441  and eventually 
33442 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33443
33444 \end_inset
33445
33446 )
33447 \end_layout
33448
33449 \begin_layout Enumerate
33450 not encourage students to use illegal copies of educational software
33451 \end_layout
33452
33453 \begin_layout Enumerate
33454 be immune to licensing/availability/price changes of the chosen tool chain
33455 \end_layout
33456
33457 \begin_layout Enumerate
33458 be able to change to a new target platform without having to adopt a new
33459  tool chain
33460 \end_layout
33461
33462 \begin_layout Enumerate
33463 have complete control over and insight into the tool chain
33464 \end_layout
33465
33466 \begin_layout Enumerate
33467 make your students aware about the pros and cons of open source software
33468  development
33469 \end_layout
33470
33471 \begin_layout Enumerate
33472 give back to the public as you are probably at least partially publically
33473  funded
33474 \end_layout
33475
33476 \begin_layout Enumerate
33477 give students a chance to publically prove their skills and to possibly
33478  see a world wide impact
33479 \end_layout
33480
33481 \begin_layout Standard
33482 then SDCC is probably among the first choices.
33483  Well, probably SDCC might be the only choice.
33484 \newpage
33485
33486 \end_layout
33487
33488 \begin_layout Chapter
33489 SDCC Technical Data
33490 \end_layout
33491
33492 \begin_layout Section
33493 Optimizations
33494 \begin_inset LatexCommand \index{Optimizations}
33495
33496 \end_inset
33497
33498
33499 \end_layout
33500
33501 \begin_layout Standard
33502 SDCC performs a host of standard optimizations in addition to some MCU specific
33503  optimizations.
33504  
33505 \end_layout
33506
33507 \begin_layout Subsection
33508 Sub-expression Elimination
33509 \begin_inset LatexCommand \index{Subexpression elimination}
33510
33511 \end_inset
33512
33513
33514 \end_layout
33515
33516 \begin_layout Standard
33517 The compiler does local and 
33518 \emph on
33519 g
33520 \emph default
33521 lobal 
33522 \emph on
33523 c
33524 \emph default
33525 ommon 
33526 \emph on
33527 s
33528 \emph default
33529 ubexpression 
33530 \emph on
33531 e
33532 \emph default
33533 limination, e.g.: 
33534 \end_layout
33535
33536 \begin_layout Verse
33537
33538 \family typewriter
33539 i = x + y + 1; 
33540 \newline
33541 j = x + y;
33542 \end_layout
33543
33544 \begin_layout Standard
33545 will be translated to
33546 \end_layout
33547
33548 \begin_layout Verse
33549
33550 \family typewriter
33551 iTemp = x + y; 
33552 \newline
33553 i = iTemp + 1; 
33554 \newline
33555 j = iTemp;
33556 \end_layout
33557
33558 \begin_layout Standard
33559 Some subexpressions are not as obvious as the above example, e.g.:
33560 \end_layout
33561
33562 \begin_layout Verse
33563
33564 \family typewriter
33565 a->b[i].c = 10; 
33566 \newline
33567 a->b[i].d = 11;
33568 \end_layout
33569
33570 \begin_layout Standard
33571 In this case the address arithmetic a->b[i] will be computed only once;
33572  the equivalent code in C would be.
33573 \end_layout
33574
33575 \begin_layout Verse
33576
33577 \family typewriter
33578 iTemp = a->b[i]; 
33579 \newline
33580 iTemp.c = 10; 
33581 \newline
33582 iTemp.d = 11;
33583 \end_layout
33584
33585 \begin_layout Standard
33586 The compiler will try to keep these temporary variables in registers.
33587 \end_layout
33588
33589 \begin_layout Subsection
33590 Dead-Code Elimination
33591 \begin_inset LatexCommand \index{Dead-code elimination}
33592
33593 \end_inset
33594
33595
33596 \end_layout
33597
33598 \begin_layout Verse
33599
33600 \family typewriter
33601 int global;
33602 \newline
33603
33604 \newline
33605 void f () { 
33606 \newline
33607 \InsetSpace ~
33608 \InsetSpace ~
33609 int i; 
33610 \newline
33611 \InsetSpace ~
33612 \InsetSpace ~
33613 i = 1; \InsetSpace ~
33614 \InsetSpace ~
33615 \InsetSpace ~
33616 \InsetSpace ~
33617 \InsetSpace ~
33618 /* dead store */ 
33619 \newline
33620 \InsetSpace ~
33621 \InsetSpace ~
33622 global = 1;\InsetSpace ~
33623 /* dead
33624  store */ 
33625 \newline
33626 \InsetSpace ~
33627 \InsetSpace ~
33628 global = 2; 
33629 \newline
33630 \InsetSpace ~
33631 \InsetSpace ~
33632 return; 
33633 \newline
33634 \InsetSpace ~
33635 \InsetSpace ~
33636 global = 3;\InsetSpace ~
33637 /* unreachable */ 
33638 \newline
33639 }
33640 \end_layout
33641
33642 \begin_layout Standard
33643 will be changed to
33644 \end_layout
33645
33646 \begin_layout Verse
33647
33648 \family typewriter
33649 int global;
33650 \newline
33651
33652 \newline
33653 void f () {
33654 \newline
33655 \InsetSpace ~
33656 \InsetSpace ~
33657 global = 2; 
33658 \newline
33659 }
33660 \end_layout
33661
33662 \begin_layout Subsection
33663 Copy-Propagation
33664 \begin_inset LatexCommand \index{Copy propagation}
33665
33666 \end_inset
33667
33668
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 = i; 
33687 \newline
33688 \InsetSpace ~
33689 \InsetSpace ~
33690 return j; 
33691 \newline
33692 }
33693 \end_layout
33694
33695 \begin_layout Standard
33696 will be changed to 
33697 \end_layout
33698
33699 \begin_layout Verse
33700
33701 \family typewriter
33702 int f() { 
33703 \newline
33704 \InsetSpace ~
33705 \InsetSpace ~
33706 int i, j; 
33707 \newline
33708 \InsetSpace ~
33709 \InsetSpace ~
33710 i = 10; 
33711 \newline
33712 \InsetSpace ~
33713 \InsetSpace ~
33714 j = 10; 
33715 \newline
33716 \InsetSpace ~
33717 \InsetSpace ~
33718 return 10; 
33719 \newline
33720 }
33721 \end_layout
33722
33723 \begin_layout Standard
33724 Note: the dead stores created by this copy propagation will be eliminated
33725  by dead-code elimination.
33726 \end_layout
33727
33728 \begin_layout Subsection
33729 Loop Optimizations
33730 \begin_inset LatexCommand \index{Loop optimization}
33731
33732 \end_inset
33733
33734
33735 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33736
33737 \end_inset
33738
33739
33740 \end_layout
33741
33742 \begin_layout Standard
33743 Two types of loop optimizations are done by SDCC 
33744 \emph on
33745 loop invariant
33746 \emph default
33747  lifting and
33748 \emph on
33749  strength reduction
33750 \emph default
33751  of loop induction variables.
33752  In addition to the strength reduction the optimizer marks the induction
33753  variables and the register allocator tries to keep the induction variables
33754  in registers for the duration of the loop.
33755  Because of this preference of the register allocator
33756 \begin_inset LatexCommand \index{Register allocation}
33757
33758 \end_inset
33759
33760 , loop induction optimization causes an increase in register pressure, which
33761  may cause unwanted spilling of other temporary variables into the stack
33762 \begin_inset LatexCommand \index{stack}
33763
33764 \end_inset
33765
33766  / data space.
33767  The compiler will generate a warning message when it is forced to allocate
33768  extra space either on the stack or data space.
33769  If this extra space allocation is undesirable then induction optimization
33770  can be eliminated either for the entire source file (with -
33771 \begin_inset ERT
33772 status collapsed
33773
33774 \begin_layout Standard
33775
33776
33777 \backslash
33778 /
33779 \end_layout
33780
33781 \end_inset
33782
33783 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33784 noinduction
33785 \begin_inset LatexCommand \index{\#pragma noinduction}
33786
33787 \end_inset
33788
33789 .
33790 \newline
33791
33792 \newline
33793 Loop Invariant:
33794 \end_layout
33795
33796 \begin_layout Verse
33797
33798 \family typewriter
33799 for (i = 0 ; i < 100 ; i ++) 
33800 \newline
33801 \InsetSpace ~
33802 \InsetSpace ~
33803 \InsetSpace ~
33804 \InsetSpace ~
33805 f += k + l;
33806 \end_layout
33807
33808 \begin_layout Standard
33809 changed to
33810 \end_layout
33811
33812 \begin_layout Verse
33813
33814 \family typewriter
33815 itemp = k + l; 
33816 \newline
33817 for (i = 0; i < 100; i++) 
33818 \newline
33819 \InsetSpace ~
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 \InsetSpace ~
33823 f += itemp;
33824 \end_layout
33825
33826 \begin_layout Standard
33827 As mentioned previously some loop invariants are not as apparent, all static
33828  address computations are also moved out of the loop.
33829 \newline
33830
33831 \newline
33832 Strength Reduction
33833 \begin_inset LatexCommand \index{Strength reduction}
33834
33835 \end_inset
33836
33837 , this optimization substitutes an expression by a cheaper expression:
33838 \end_layout
33839
33840 \begin_layout Verse
33841
33842 \family typewriter
33843 for (i=0;i < 100; i++)
33844 \newline
33845 \InsetSpace ~
33846 \InsetSpace ~
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 ar[i*5] = i*3;
33850 \end_layout
33851
33852 \begin_layout Standard
33853 changed to
33854 \end_layout
33855
33856 \begin_layout Verse
33857
33858 \family typewriter
33859 itemp1 = 0; 
33860 \newline
33861 itemp2 = 0; 
33862 \newline
33863 for (i=0;i< 100;i++) { 
33864 \newline
33865 \InsetSpace ~
33866 \InsetSpace ~
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 ar[itemp1] = itemp2; 
33870 \newline
33871 \InsetSpace ~
33872 \InsetSpace ~
33873 \InsetSpace ~
33874 \InsetSpace ~
33875 itemp1
33876  += 5; 
33877 \newline
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 itemp2 += 3; 
33883 \newline
33884 }
33885 \end_layout
33886
33887 \begin_layout Standard
33888 The more expensive multiplication
33889 \begin_inset LatexCommand \index{Multiplication}
33890
33891 \end_inset
33892
33893  is changed to a less expensive addition.
33894 \end_layout
33895
33896 \begin_layout Subsection
33897 Loop Reversing
33898 \begin_inset LatexCommand \index{Loop reversing}
33899
33900 \end_inset
33901
33902
33903 \end_layout
33904
33905 \begin_layout Standard
33906 This optimization is done to reduce the overhead of checking loop boundaries
33907  for every iteration.
33908  Some simple loops can be reversed and implemented using a 
33909 \begin_inset Quotes eld
33910 \end_inset
33911
33912 decrement and jump if not zero
33913 \begin_inset Quotes erd
33914 \end_inset
33915
33916  instruction.
33917  SDCC checks for the following criterion to determine if a loop is reversible
33918  (note: more sophisticated compilers use data-dependency analysis to make
33919  this determination, SDCC uses a more simple minded analysis).
33920 \end_layout
33921
33922 \begin_layout Itemize
33923 The 'for' loop is of the form 
33924 \newline
33925
33926 \newline
33927
33928 \family typewriter
33929 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33930  += 1])
33931 \newline
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 <for body>
33937 \end_layout
33938
33939 \begin_layout Itemize
33940 The <for body> does not contain 
33941 \begin_inset Quotes eld
33942 \end_inset
33943
33944 continue
33945 \begin_inset Quotes erd
33946 \end_inset
33947
33948  or 'break
33949 \begin_inset Quotes erd
33950 \end_inset
33951
33952 .
33953 \end_layout
33954
33955 \begin_layout Itemize
33956 All goto's are contained within the loop.
33957 \end_layout
33958
33959 \begin_layout Itemize
33960 No function calls within the loop.
33961 \end_layout
33962
33963 \begin_layout Itemize
33964 The loop control variable <sym> is not assigned any value within the loop
33965 \end_layout
33966
33967 \begin_layout Itemize
33968 The loop control variable does NOT participate in any arithmetic operation
33969  within the loop.
33970 \end_layout
33971
33972 \begin_layout Itemize
33973 There are NO switch statements in the loop.
33974 \end_layout
33975
33976 \begin_layout Subsection
33977 Algebraic Simplifications
33978 \end_layout
33979
33980 \begin_layout Standard
33981 SDCC does numerous algebraic simplifications, the following is a small sub-set
33982  of these optimizations.
33983 \end_layout
33984
33985 \begin_layout Verse
33986
33987 \family typewriter
33988 i = j + 0;\InsetSpace ~
33989 \InsetSpace ~
33990 \InsetSpace ~
33991 \InsetSpace ~
33992  /* changed to: */\InsetSpace ~
33993 \InsetSpace ~
33994 \InsetSpace ~
33995 \InsetSpace ~
33996  i = j; 
33997 \newline
33998 i /= 2;\InsetSpace ~
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 \InsetSpace ~
34002 \InsetSpace ~
34003 \InsetSpace ~
34004 \InsetSpace ~
34005  /* changed to: */\InsetSpace ~
34006 \InsetSpace ~
34007 \InsetSpace ~
34008 \InsetSpace ~
34009  i >>= 1; 
34010 \newline
34011 i
34012  = j - j;\InsetSpace ~
34013 \InsetSpace ~
34014 \InsetSpace ~
34015 \InsetSpace ~
34016  /* changed to: */\InsetSpace ~
34017 \InsetSpace ~
34018 \InsetSpace ~
34019 \InsetSpace ~
34020  i = 0; 
34021 \newline
34022 i = j / 1;\InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025 \InsetSpace ~
34026  /* changed to: */\InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030  i = j;
34031 \end_layout
34032
34033 \begin_layout Standard
34034 Note the subexpressions
34035 \begin_inset LatexCommand \index{Subexpression}
34036
34037 \end_inset
34038
34039  given above are generally introduced by macro expansions or as a result
34040  of copy/constant propagation.
34041 \end_layout
34042
34043 \begin_layout Subsection
34044 'switch' Statements
34045 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34046
34047 \end_inset
34048
34049
34050 \begin_inset LatexCommand \index{switch statement}
34051
34052 \end_inset
34053
34054
34055 \end_layout
34056
34057 \begin_layout Standard
34058 SDCC can optimize switch statements to jump tables
34059 \begin_inset LatexCommand \index{jump tables}
34060
34061 \end_inset
34062
34063 .
34064  It makes the decision based on an estimate of the generated code size.
34065  SDCC is quite liberal in the requirements for jump table generation: 
34066 \end_layout
34067
34068 \begin_layout Itemize
34069 The labels need not be in order, and the starting number need not be one
34070  or zero, the case labels are in numerical sequence or not too many case
34071  labels are missing.
34072 \end_layout
34073
34074 \begin_deeper
34075 \begin_layout Verse
34076
34077 \family typewriter
34078 switch(i) {\InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 \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 switch (i) { 
34105 \newline
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 case 4: ...\InsetSpace ~
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 \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 case 0: ...
34136  
34137 \newline
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 \InsetSpace ~
34141 case 5: ...\InsetSpace ~
34142 \InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 \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 case 1: ...
34168  
34169 \newline
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 case 3: ...\InsetSpace ~
34174 \InsetSpace ~
34175 \InsetSpace ~
34176 \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
34200 \newline
34201 \InsetSpace ~
34202 \InsetSpace ~
34203 \InsetSpace ~
34204 case 6: ...\InsetSpace ~
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 \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 case 3: ...
34231  
34232 \newline
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 case 7: ...\InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \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 case 4: ...
34263  
34264 \newline
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 case 8: ...\InsetSpace ~
34269 \InsetSpace ~
34270 \InsetSpace ~
34271 \InsetSpace ~
34272 \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 case 5: ...
34295  
34296 \newline
34297 \InsetSpace ~
34298 \InsetSpace ~
34299 \InsetSpace ~
34300 case 9: ...\InsetSpace ~
34301 \InsetSpace ~
34302 \InsetSpace ~
34303 \InsetSpace ~
34304 \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 case 6: ...
34327  
34328 \newline
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 case 10: ...\InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \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 case 7: ...
34358  
34359 \newline
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 case 11: ...\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 case 8: ...
34389  
34390 \newline
34391 }\InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401 \InsetSpace ~
34402 \InsetSpace ~
34403 \InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 }
34428 \end_layout
34429
34430 \begin_layout Standard
34431 Both the above switch statements will be implemented using a jump-table.
34432  The example to the right side is slightly more efficient as the check for
34433  the lower boundary of the jump-table is not needed.
34434 \end_layout
34435
34436 \end_deeper
34437 \begin_layout Itemize
34438 The number of case labels is not larger than supported by the target architectur
34439 e.
34440 \end_layout
34441
34442 \begin_layout Itemize
34443 If the case labels are not in numerical sequence ('gaps' between cases)
34444  SDCC checks whether a jump table with additionally inserted dummy cases
34445  is still attractive.
34446  
34447 \end_layout
34448
34449 \begin_layout Itemize
34450 If the starting number is not zero and a check for the lower boundary of
34451  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34452  ...
34453  .
34454 \end_layout
34455
34456 \begin_layout Standard
34457 Switch statements which have large gaps in the numeric sequence or those
34458  that have too many case labels can be split into more than one switch statement
34459  for efficient code generation, e.g.:
34460 \end_layout
34461
34462 \begin_layout Verse
34463
34464 \family typewriter
34465 switch (i) { 
34466 \newline
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 case 1: ...
34470  
34471 \newline
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 case 2: ...
34475  
34476 \newline
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 case 3: ...
34480  
34481 \newline
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 case 4: ...
34485  
34486 \newline
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 case 5: ...
34490  
34491 \newline
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 case 6: ...
34495  
34496 \newline
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 case 7: ...
34500  
34501 \newline
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 case 101: ...
34505  
34506 \newline
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 case 102: ...
34510  
34511 \newline
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 case 103: ...
34515  
34516 \newline
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 case 104: ...
34520  
34521 \newline
34522 \InsetSpace ~
34523 \InsetSpace ~
34524 case 105: ...
34525  
34526 \newline
34527 \InsetSpace ~
34528 \InsetSpace ~
34529 case 106: ...
34530  
34531 \newline
34532 \InsetSpace ~
34533 \InsetSpace ~
34534 case 107: ...
34535  
34536 \newline
34537 }
34538 \end_layout
34539
34540 \begin_layout Standard
34541 If the above switch statement is broken down into two switch statements
34542 \end_layout
34543
34544 \begin_layout Verse
34545
34546 \family typewriter
34547 switch (i) { 
34548 \newline
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 case 1: ...
34552  
34553 \newline
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 case 2: ...
34557  
34558 \newline
34559 \InsetSpace ~
34560 \InsetSpace ~
34561 case 3: ...
34562  
34563 \newline
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 case 4: ...
34567  
34568 \newline
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 case 5: ...
34572  
34573 \newline
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 case 6: ...
34577  
34578 \newline
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 case 7: ...
34582  
34583 \newline
34584 }
34585 \end_layout
34586
34587 \begin_layout Standard
34588 and
34589 \end_layout
34590
34591 \begin_layout Verse
34592
34593 \family typewriter
34594 switch (i) { 
34595 \newline
34596 \InsetSpace ~
34597 \InsetSpace ~
34598 case 101: ...
34599  
34600 \newline
34601 \InsetSpace ~
34602 \InsetSpace ~
34603 case 102: ...
34604  
34605 \newline
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 case 103: ...
34609  
34610 \newline
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 case 104: ...
34614  
34615 \newline
34616 \InsetSpace ~
34617 \InsetSpace ~
34618 case 105: ...
34619  
34620 \newline
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 case 106: ...
34624  
34625 \newline
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 case 107: ...
34629  
34630 \newline
34631 }
34632 \end_layout
34633
34634 \begin_layout Standard
34635 then both the switch statements will be implemented using jump-tables whereas
34636  the unmodified switch statement will not be.
34637 \end_layout
34638
34639 \begin_layout Standard
34640 \begin_inset Note Note
34641 status collapsed
34642
34643 \begin_layout Standard
34644 There might be reasons which SDCC cannot know about to either favour or
34645  not favour jump tables.
34646  If the target system has to be as quick for the last switch case as for
34647  the first (pro jump table), or if the switch argument is known to be zero
34648  in the majority of the cases (contra jump table).
34649 \end_layout
34650
34651 \end_inset
34652
34653
34654 \end_layout
34655
34656 \begin_layout Standard
34657 The pragma nojtbound
34658 \begin_inset LatexCommand \index{\#pragma nojtbound}
34659
34660 \end_inset
34661
34662  can be used to turn off checking the 
34663 \emph on
34664 j
34665 \emph default
34666 ump 
34667 \emph on
34668 t
34669 \emph default
34670 able 
34671 \emph on
34672 bound
34673 \emph default
34674 aries.
34675  It has no effect if a default label is supplied.
34676  Use of this pragma is dangerous: if the switch
34677 \begin_inset LatexCommand \index{switch statement}
34678
34679 \end_inset
34680
34681  argument is not matched by a case statement the processor will happily
34682  jump into Nirvana.
34683 \end_layout
34684
34685 \begin_layout Subsection
34686 Bit-shifting Operations
34687 \begin_inset LatexCommand \index{Bit shifting}
34688
34689 \end_inset
34690
34691 .
34692 \end_layout
34693
34694 \begin_layout Standard
34695 Bit shifting is one of the most frequently used operation in embedded programmin
34696 g.
34697  SDCC tries to implement bit-shift operations in the most efficient way
34698  possible, e.g.:
34699 \end_layout
34700
34701 \begin_layout Verse
34702
34703 \family typewriter
34704 unsigned char i;
34705 \newline
34706 ...
34707  
34708 \newline
34709 i >>= 4; 
34710 \newline
34711 ...
34712 \end_layout
34713
34714 \begin_layout Standard
34715 generates the following code:
34716 \end_layout
34717
34718 \begin_layout Verse
34719
34720 \family typewriter
34721 mov\InsetSpace ~
34722  a,_i 
34723 \newline
34724 swap a 
34725 \newline
34726 anl\InsetSpace ~
34727  a,#0x0f 
34728 \newline
34729 mov\InsetSpace ~
34730  _i,a
34731 \end_layout
34732
34733 \begin_layout Standard
34734 In general SDCC will never setup a loop if the shift count is known.
34735  Another example:
34736 \end_layout
34737
34738 \begin_layout Verse
34739
34740 \family typewriter
34741 unsigned int i; 
34742 \newline
34743 ...
34744  
34745 \newline
34746 i >>= 9; 
34747 \newline
34748 ...
34749 \end_layout
34750
34751 \begin_layout Standard
34752 will generate:
34753 \end_layout
34754
34755 \begin_layout Verse
34756
34757 \family typewriter
34758 mov\InsetSpace ~
34759 \InsetSpace ~
34760 a,(_i + 1) 
34761 \newline
34762 mov\InsetSpace ~
34763 \InsetSpace ~
34764 (_i + 1),#0x00 
34765 \newline
34766 clr\InsetSpace ~
34767 \InsetSpace ~
34768
34769 \newline
34770 rrc\InsetSpace ~
34771 \InsetSpace ~
34772
34773 \newline
34774 mov\InsetSpace ~
34775 \InsetSpace ~
34776 _i,a
34777 \end_layout
34778
34779 \begin_layout Subsection
34780 Bit-rotation
34781 \begin_inset LatexCommand \index{Bit rotation}
34782
34783 \end_inset
34784
34785
34786 \end_layout
34787
34788 \begin_layout Standard
34789 A special case of the bit-shift operation is bit rotation
34790 \begin_inset LatexCommand \index{rotating bits}
34791
34792 \end_inset
34793
34794 , SDCC recognizes the following expression to be a left bit-rotation:
34795 \end_layout
34796
34797 \begin_layout Verse
34798
34799 \family typewriter
34800 \series bold
34801 unsigned
34802 \series default
34803 \InsetSpace ~
34804 \InsetSpace ~
34805 char i;\InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 /* unsigned is needed for rotation */ 
34817 \newline
34818 ...
34819  
34820 \newline
34821 i = ((i << 1) | (i >> 7)); 
34822 \family default
34823
34824 \newline
34825
34826 \family typewriter
34827 ...
34828 \end_layout
34829
34830 \begin_layout Standard
34831 will generate the following code:
34832 \end_layout
34833
34834 \begin_layout Verse
34835
34836 \family typewriter
34837 mov\InsetSpace ~
34838 \InsetSpace ~
34839 a,_i 
34840 \newline
34841 rl\InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844
34845 \newline
34846 mov\InsetSpace ~
34847 \InsetSpace ~
34848 _i,a
34849 \end_layout
34850
34851 \begin_layout Standard
34852 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34853 ns of this case will also be recognized as bit-rotation, i.e.: 
34854 \end_layout
34855
34856 \begin_layout Verse
34857
34858 \family typewriter
34859 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34860 \end_layout
34861
34862 \begin_layout Subsection
34863 Nibble and Byte Swapping
34864 \end_layout
34865
34866 \begin_layout Standard
34867 Other special cases of the bit-shift operations are nibble or byte swapping
34868 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34869
34870 \end_inset
34871
34872 , SDCC recognizes the following expressions:
34873 \end_layout
34874
34875 \begin_layout Verse
34876
34877 \family typewriter
34878 \series bold
34879 unsigned
34880 \series default
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 char i; 
34884 \newline
34885
34886 \series bold
34887 unsigned
34888 \series default
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 int j; 
34892 \newline
34893 ...
34894  
34895 \newline
34896 i = ((i << 4) | (i >> 4)); 
34897 \family default
34898
34899 \newline
34900
34901 \family typewriter
34902 j = ((j << 8) | (j >> 8)); 
34903 \end_layout
34904
34905 \begin_layout Standard
34906 and generates a swap instruction for the nibble swapping
34907 \begin_inset LatexCommand \index{Nibble swapping}
34908
34909 \end_inset
34910
34911  or move instructions for the byte swapping
34912 \begin_inset LatexCommand \index{Byte swapping}
34913
34914 \end_inset
34915
34916 .
34917  The 
34918 \begin_inset Quotes sld
34919 \end_inset
34920
34921 j
34922 \begin_inset Quotes srd
34923 \end_inset
34924
34925  example can be used to convert from little to big-endian or vice versa.
34926  If you want to change the endianness of a 
34927 \emph on
34928 signed
34929 \emph default
34930  integer you have to cast to 
34931 \family typewriter
34932 (unsigned int)
34933 \family default
34934  first.
34935 \end_layout
34936
34937 \begin_layout Standard
34938 Note that SDCC stores numbers in little-endian
34939 \begin_inset Foot
34940 status open
34941
34942 \begin_layout Standard
34943 Usually 8-bit processors don't care much about endianness.
34944  This is not the case for the standard 8051 which only has an instruction
34945  to increment its 
34946 \emph on
34947 dptr
34948 \emph default
34949
34950 \begin_inset LatexCommand \index{DPTR}
34951
34952 \end_inset
34953
34954 -datapointer
34955 \emph on
34956  
34957 \emph default
34958 so little-endian is the more efficient byte order.
34959 \end_layout
34960
34961 \end_inset
34962
34963
34964 \begin_inset LatexCommand \index{little-endian}
34965
34966 \end_inset
34967
34968
34969 \begin_inset LatexCommand \index{Endianness}
34970
34971 \end_inset
34972
34973  format (i.e.
34974  lowest order first).
34975 \end_layout
34976
34977 \begin_layout Subsection
34978 Highest Order Bit
34979 \begin_inset LatexCommand \index{Highest Order Bit}
34980
34981 \end_inset
34982
34983  / Any Order Bit
34984 \begin_inset LatexCommand \index{Any Order Bit}
34985
34986 \end_inset
34987
34988
34989 \end_layout
34990
34991 \begin_layout Standard
34992 It is frequently required to obtain the highest order bit of an integral
34993  type (long, int, short or char types).
34994  Also obtaining any other order bit is not uncommon.
34995  SDCC recognizes the following expressions to yield the highest order bit
34996  and generates optimized code for it, e.g.:
34997 \end_layout
34998
34999 \begin_layout Verse
35000
35001 \family typewriter
35002 unsigned int gint; 
35003 \newline
35004
35005 \newline
35006 foo () { 
35007 \newline
35008 \InsetSpace ~
35009 \InsetSpace ~
35010 unsigned char hob1, aob1; 
35011 \newline
35012 \InsetSpace ~
35013 \InsetSpace ~
35014 bit hob2, hob3, aob2,
35015  aob3; 
35016 \newline
35017 \InsetSpace ~
35018 \InsetSpace ~
35019 ...
35020  
35021 \newline
35022 \InsetSpace ~
35023 \InsetSpace ~
35024 hob1 = (gint >> 15) & 1; 
35025 \newline
35026 \InsetSpace ~
35027 \InsetSpace ~
35028 hob2 = (gint >> 15) & 1; 
35029 \newline
35030 \InsetSpace ~
35031 \InsetSpace ~
35032 hob3 = gint & 0x8000;
35033  
35034 \newline
35035 \InsetSpace ~
35036 \InsetSpace ~
35037 aob1 = (gint >> 9) & 1; 
35038 \newline
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 aob2 = (gint >> 8) & 1; 
35042 \newline
35043 \InsetSpace ~
35044 \InsetSpace ~
35045 aob3 = gint & 0x0800; 
35046 \newline
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 ..
35050  
35051 \newline
35052 }
35053 \end_layout
35054
35055 \begin_layout Standard
35056 will generate the following code:
35057 \end_layout
35058
35059 \begin_layout Verse
35060
35061 \family typewriter
35062 \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 \InsetSpace ~
35078 \InsetSpace ~
35079 \InsetSpace ~
35080 \InsetSpace ~
35081 \InsetSpace ~
35082 \InsetSpace ~
35083 \InsetSpace ~
35084 \InsetSpace ~
35085 \InsetSpace ~
35086 \InsetSpace ~
35087  61 ;\InsetSpace ~
35088  hob.c 7 
35089 \newline
35090 000A E5*01\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  62\InsetSpace ~
35106 \InsetSpace ~
35107 \InsetSpace ~
35108 \InsetSpace ~
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 \InsetSpace ~
35112 \InsetSpace ~
35113  mov\InsetSpace ~
35114 \InsetSpace ~
35115  a,(_gint + 1) 
35116 \newline
35117 000C 23\InsetSpace ~
35118 \InsetSpace ~
35119 \InsetSpace ~
35120 \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  63\InsetSpace ~
35136 \InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 \InsetSpace ~
35142 \InsetSpace ~
35143  rl\InsetSpace ~
35144 \InsetSpace ~
35145 \InsetSpace ~
35146  a 
35147 \newline
35148 000D 54 01\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
35164  64\InsetSpace ~
35165 \InsetSpace ~
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172  anl\InsetSpace ~
35173 \InsetSpace ~
35174  a,#0x01 
35175 \newline
35176 000F F5*02\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  65\InsetSpace ~
35192 \InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196 \InsetSpace ~
35197 \InsetSpace ~
35198 \InsetSpace ~
35199  mov\InsetSpace ~
35200 \InsetSpace ~
35201  _foo_hob1_1_1,a 
35202 \newline
35203 \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 \InsetSpace ~
35219 \InsetSpace ~
35220 \InsetSpace ~
35221 \InsetSpace ~
35222 \InsetSpace ~
35223 \InsetSpace ~
35224 \InsetSpace ~
35225 \InsetSpace ~
35226 \InsetSpace ~
35227 \InsetSpace ~
35228  66 ;\InsetSpace ~
35229  hob.c 8 
35230 \newline
35231 0011 E5*01\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
35247  67\InsetSpace ~
35248 \InsetSpace ~
35249 \InsetSpace ~
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 \InsetSpace ~
35253 \InsetSpace ~
35254 \InsetSpace ~
35255  mov\InsetSpace ~
35256 \InsetSpace ~
35257  a,(_gint + 1) 
35258 \newline
35259 0013 33\InsetSpace ~
35260 \InsetSpace ~
35261 \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 \InsetSpace ~
35277  68\InsetSpace ~
35278 \InsetSpace ~
35279 \InsetSpace ~
35280 \InsetSpace ~
35281 \InsetSpace ~
35282 \InsetSpace ~
35283 \InsetSpace ~
35284 \InsetSpace ~
35285  rlc\InsetSpace ~
35286 \InsetSpace ~
35287  a 
35288 \newline
35289 0014 92*00\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  69\InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 \InsetSpace ~
35312  mov\InsetSpace ~
35313 \InsetSpace ~
35314  _foo_hob2_1_1,c
35315  
35316 \newline
35317 \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 \InsetSpace ~
35333 \InsetSpace ~
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 \InsetSpace ~
35339 \InsetSpace ~
35340 \InsetSpace ~
35341 \InsetSpace ~
35342  66 ;\InsetSpace ~
35343  hob.c 9 
35344 \newline
35345 0016 E5*01\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  67\InsetSpace ~
35361 \InsetSpace ~
35362 \InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367 \InsetSpace ~
35368  mov\InsetSpace ~
35369 \InsetSpace ~
35370  a,(_gint + 1) 
35371 \newline
35372 0018 33\InsetSpace ~
35373 \InsetSpace ~
35374 \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 \InsetSpace ~
35390  68\InsetSpace ~
35391 \InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398  rlc\InsetSpace ~
35399 \InsetSpace ~
35400  a 
35401 \newline
35402 0019 92*01\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
35418  69\InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426  mov\InsetSpace ~
35427 \InsetSpace ~
35428  _foo_hob3_1_1,c 
35429 \newline
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455  70 ;\InsetSpace ~
35456  hob.c 10 
35457 \newline
35458 001B E5*01\InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473  71\InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481  mov\InsetSpace ~
35482 \InsetSpace ~
35483  a,(_gint + 1) 
35484 \newline
35485 001D
35486  03\InsetSpace ~
35487 \InsetSpace ~
35488 \InsetSpace ~
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504  72\InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512  rr\InsetSpace ~
35513 \InsetSpace ~
35514 \InsetSpace ~
35515  a 
35516 \newline
35517 001E 54 01\InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523 \InsetSpace ~
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532  73\InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540  anl\InsetSpace ~
35541 \InsetSpace ~
35542  a,#0x01 
35543 \newline
35544 0020 F5*03\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  74\InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567  mov\InsetSpace ~
35568 \InsetSpace ~
35569  _foo_aob1_1_1,a
35570  
35571 \newline
35572 \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 \InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596 \InsetSpace ~
35597  75 ;\InsetSpace ~
35598  hob.c 11 
35599 \newline
35600 0022 E5*01\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  76\InsetSpace ~
35616 \InsetSpace ~
35617 \InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623  mov\InsetSpace ~
35624 \InsetSpace ~
35625  a,(_gint + 1) 
35626 \newline
35627 0024 13\InsetSpace ~
35628 \InsetSpace ~
35629 \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 \InsetSpace ~
35645  77\InsetSpace ~
35646 \InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653  rrc\InsetSpace ~
35654 \InsetSpace ~
35655  a 
35656 \newline
35657 0025 92*02\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
35673  78\InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681  mov\InsetSpace ~
35682 \InsetSpace ~
35683  _foo_aob2_1_1,c 
35684 \newline
35685 \InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700 \InsetSpace ~
35701 \InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710  79 ;\InsetSpace ~
35711  hob.c 12 
35712 \newline
35713 0027 E5*01\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  80\InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736  mov\InsetSpace ~
35737 \InsetSpace ~
35738  a,(_gint + 1) 
35739 \newline
35740 0029
35741  A2 E3\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 \InsetSpace ~
35756  81\InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760 \InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764  mov\InsetSpace ~
35765 \InsetSpace ~
35766  c,acc[3] 
35767 \newline
35768 002B 92*03\InsetSpace ~
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772 \InsetSpace ~
35773 \InsetSpace ~
35774 \InsetSpace ~
35775 \InsetSpace ~
35776 \InsetSpace ~
35777 \InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783  82\InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 \InsetSpace ~
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791  mov\InsetSpace ~
35792 \InsetSpace ~
35793  _foo_aob3_1_1,c 
35794 \end_layout
35795
35796 \begin_layout Standard
35797 Other variations of these cases however will 
35798 \emph on
35799 not
35800 \emph default
35801  be recognized.
35802  They are standard C expressions, so I heartily recommend these be the only
35803  way to get the highest order bit, (it is portable).
35804  Of course it will be recognized even if it is embedded in other expressions,
35805  e.g.:
35806 \end_layout
35807
35808 \begin_layout Verse
35809
35810 \family typewriter
35811 xyz = gint + ((gint >> 15) & 1);
35812 \end_layout
35813
35814 \begin_layout Standard
35815 will still be recognized.
35816 \end_layout
35817
35818 \begin_layout Subsection
35819 Higher Order Byte
35820 \begin_inset LatexCommand \index{Higher Order Byte}
35821
35822 \end_inset
35823
35824  / Higher Order Word
35825 \begin_inset LatexCommand \index{Higher Order Word}
35826
35827 \end_inset
35828
35829
35830 \end_layout
35831
35832 \begin_layout Standard
35833 It is also frequently required to obtain a higher order byte or word of
35834  a larger integral type (long, int or short types).
35835  SDCC recognizes the following expressions to yield the higher order byte
35836  or word and generates optimized code for it, e.g.:
35837 \end_layout
35838
35839 \begin_layout Verse
35840
35841 \family typewriter
35842 unsigned int gint; 
35843 \newline
35844 unsigned long int glong; 
35845 \newline
35846
35847 \newline
35848 foo () { 
35849 \newline
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 unsigned char hob1,
35853  hob2; 
35854 \newline
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 unsigned int how1, how2; 
35858 \newline
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 ...
35862  
35863 \newline
35864 \InsetSpace ~
35865 \InsetSpace ~
35866 hob1 = (gint >> 8) & 0xFF; 
35867 \newline
35868 \InsetSpace ~
35869 \InsetSpace ~
35870 hob2 = glong >> 24; 
35871 \newline
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 how1 = (glong >> 16) & 0xFFFF;
35875  
35876 \newline
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 how2 = glong >> 8; 
35880 \newline
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 ..
35884  
35885 \newline
35886 }
35887 \end_layout
35888
35889 \begin_layout Standard
35890 will generate the following code:
35891 \end_layout
35892
35893 \begin_layout Verse
35894
35895 \family typewriter
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921  91 ;\InsetSpace ~
35922  hob.c 15 
35923 \newline
35924 0037 85*01*06\InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936  92\InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944  mov\InsetSpace ~
35945 \InsetSpace ~
35946  _foo_hob1_1_1,(_gint + 1) 
35947 \newline
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973  93 ;\InsetSpace ~
35974  hob.c
35975  16 
35976 \newline
35977 003A 85*05*07\InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989  94\InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997  mov\InsetSpace ~
35998 \InsetSpace ~
35999  _foo_hob2_1_1,(_glong + 3) 
36000 \newline
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 \InsetSpace ~
36023 \InsetSpace ~
36024 \InsetSpace ~
36025 \InsetSpace ~
36026  95 ;\InsetSpace ~
36027  hob.c 17 
36028 \newline
36029 003D 85*04*08\InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041
36042  96\InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050  mov\InsetSpace ~
36051 \InsetSpace ~
36052  _foo_how1_1_1,(_glong + 2) 
36053 \newline
36054 0040 85*05*09\InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066  97\InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070 \InsetSpace ~
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074  mov\InsetSpace ~
36075 \InsetSpace ~
36076  (_foo_how1_1_1 +
36077  1),(_glong + 3) 
36078 \newline
36079 0043 85*03*0A\InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 \InsetSpace ~
36086 \InsetSpace ~
36087 \InsetSpace ~
36088 \InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091  98\InsetSpace ~
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 \InsetSpace ~
36099  mov\InsetSpace ~
36100 \InsetSpace ~
36101  _foo_how2_1_1,(_glong + 1) 
36102 \newline
36103 0046 85*04*0B\InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115
36116  99\InsetSpace ~
36117 \InsetSpace ~
36118 \InsetSpace ~
36119 \InsetSpace ~
36120 \InsetSpace ~
36121 \InsetSpace ~
36122 \InsetSpace ~
36123 \InsetSpace ~
36124  mov\InsetSpace ~
36125 \InsetSpace ~
36126  (_foo_how2_1_1 + 1),(_glong + 2) 
36127 \end_layout
36128
36129 \begin_layout Standard
36130 Again, variations of these cases may 
36131 \emph on
36132 not
36133 \emph default
36134  be recognized.
36135  They are standard C expressions, so I heartily recommend these be the only
36136  way to get the higher order byte/word, (it is portable).
36137  Of course it will be recognized even if it is embedded in other expressions,
36138  e.g.:
36139 \end_layout
36140
36141 \begin_layout Verse
36142
36143 \family typewriter
36144 xyz = gint + ((gint >> 8) & 0xFF);
36145 \end_layout
36146
36147 \begin_layout Standard
36148 will still be recognized.
36149 \end_layout
36150
36151 \begin_layout Subsection
36152 Peephole Optimizer
36153 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36154
36155 \end_inset
36156
36157
36158 \begin_inset LatexCommand \index{Peephole optimizer}
36159
36160 \end_inset
36161
36162
36163 \end_layout
36164
36165 \begin_layout Standard
36166 The compiler uses a rule based, pattern matching and re-writing mechanism
36167  for peep-hole optimization.
36168  It is inspired by 
36169 \emph on
36170 copt
36171 \emph default
36172  a peep-hole optimizer by Christopher W.
36173  Fraser (cwfraser\InsetSpace ~
36174 @\InsetSpace ~
36175 microsoft.com).
36176  A default set of rules are compiled into the compiler, additional rules
36177  may be added with the 
36178 \emph on
36179 -
36180 \begin_inset ERT
36181 status collapsed
36182
36183 \begin_layout Standard
36184
36185
36186 \backslash
36187 /
36188 \end_layout
36189
36190 \end_inset
36191
36192 -peep-file
36193 \begin_inset LatexCommand \index{-\/-peep-file}
36194
36195 \end_inset
36196
36197  <filename>
36198 \emph default
36199  option.
36200  The rule language is best illustrated with examples.
36201 \end_layout
36202
36203 \begin_layout Verse
36204
36205 \family typewriter
36206 replace { 
36207 \newline
36208 \InsetSpace ~
36209 \InsetSpace ~
36210 mov %1,a 
36211 \newline
36212 \InsetSpace ~
36213 \InsetSpace ~
36214 mov a,%1
36215 \newline
36216 } by {
36217 \newline
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 mov %1,a
36221 \newline
36222 }
36223 \end_layout
36224
36225 \begin_layout Standard
36226 The above rule will change the following assembly
36227 \begin_inset LatexCommand \index{Assembler routines}
36228
36229 \end_inset
36230
36231  sequence:
36232 \end_layout
36233
36234 \begin_layout Verse
36235
36236 \family typewriter
36237 mov r1,a 
36238 \newline
36239 mov a,r1
36240 \end_layout
36241
36242 \begin_layout Standard
36243 to
36244 \end_layout
36245
36246 \begin_layout Verse
36247
36248 \family typewriter
36249 mov r1,a
36250 \end_layout
36251
36252 \begin_layout Standard
36253 Note: All occurrences of a 
36254 \emph on
36255 %n
36256 \emph default
36257  (pattern variable) must denote the same string.
36258  With the above rule, the assembly sequence:
36259 \end_layout
36260
36261 \begin_layout Verse
36262
36263 \family typewriter
36264 mov r1,a 
36265 \newline
36266 mov a,r2
36267 \end_layout
36268
36269 \begin_layout Standard
36270 will remain unmodified.
36271 \newline
36272
36273 \newline
36274 Other special case optimizations may be added by the
36275  user (via 
36276 \emph on
36277 -
36278 \begin_inset ERT
36279 status collapsed
36280
36281 \begin_layout Standard
36282
36283
36284 \backslash
36285 /
36286 \end_layout
36287
36288 \end_inset
36289
36290 -peep-file option
36291 \emph default
36292 ).
36293  E.g.
36294  some variants of the 8051 MCU
36295 \begin_inset LatexCommand \index{MCS51 variants}
36296
36297 \end_inset
36298
36299  allow only 
36300 \family typewriter
36301 ajmp
36302 \family default
36303  and 
36304 \family typewriter
36305 acall
36306 \family default
36307 .
36308  The following two rules will change all 
36309 \family typewriter
36310 ljmp
36311 \family default
36312  and 
36313 \family typewriter
36314 lcall
36315 \family default
36316  to 
36317 \family typewriter
36318 ajmp
36319 \family default
36320  and 
36321 \family typewriter
36322 acall
36323 \end_layout
36324
36325 \begin_layout Verse
36326
36327 \family typewriter
36328 replace { lcall %1 } by { acall %1 } 
36329 \newline
36330 replace { ljmp %1 } by { ajmp %1 }
36331 \end_layout
36332
36333 \begin_layout Standard
36334 (NOTE: from version 2.7.3 on, you can use option -
36335 \emph on
36336
36337 \begin_inset ERT
36338 status collapsed
36339
36340 \begin_layout Standard
36341
36342
36343 \backslash
36344 /
36345 \end_layout
36346
36347 \end_inset
36348
36349
36350 \emph default
36351 -acall-ajmp
36352 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36353
36354 \end_inset
36355
36356 , which also takes care of aligning the interrupt vectors properly.)
36357 \newline
36358
36359 \end_layout
36360
36361 \begin_layout Standard
36362 The 
36363 \emph on
36364 inline-assembler code
36365 \emph default
36366  is also passed through the peep hole optimizer, thus the peephole optimizer
36367  can also be used as an assembly level macro expander.
36368  The rules themselves are MCU dependent whereas the rule language infra-structur
36369 e is MCU independent.
36370  Peephole optimization rules for other MCU can be easily programmed using
36371  the rule language.
36372 \newline
36373
36374 \newline
36375 The syntax for a rule is as follows:
36376 \end_layout
36377
36378 \begin_layout Verse
36379
36380 \family typewriter
36381 rule := replace [ restart ] '{' <assembly sequence> '
36382 \backslash
36383 n' 
36384 \newline
36385 \InsetSpace ~
36386  \InsetSpace ~
36387  \InsetSpace ~
36388  \InsetSpace ~
36389  \InsetSpace ~
36390  \InsetSpace ~
36391  \InsetSpace ~
36392  \InsetSpace ~
36393  \InsetSpace ~
36394  \InsetSpace ~
36395  \InsetSpace ~
36396  \InsetSpace ~
36397  \InsetSpace ~
36398  \InsetSpace ~
36399  '}' by '{' '
36400 \backslash
36401 n' 
36402 \newline
36403 \InsetSpace ~
36404  \InsetSpace ~
36405  \InsetSpace ~
36406  \InsetSpace ~
36407  \InsetSpace ~
36408  \InsetSpace ~
36409  \InsetSpace ~
36410  \InsetSpace ~
36411  \InsetSpace ~
36412  \InsetSpace ~
36413  \InsetSpace ~
36414  \InsetSpace ~
36415  \InsetSpace ~
36416  \InsetSpace ~
36417  \InsetSpace ~
36418  \InsetSpace ~
36419  <assembly sequence> '
36420 \backslash
36421 n' 
36422 \newline
36423 \InsetSpace ~
36424  \InsetSpace ~
36425  \InsetSpace ~
36426  \InsetSpace ~
36427  \InsetSpace ~
36428  \InsetSpace ~
36429  \InsetSpace ~
36430  \InsetSpace ~
36431  \InsetSpace ~
36432  \InsetSpace ~
36433  \InsetSpace ~
36434  \InsetSpace ~
36435  \InsetSpace ~
36436  \InsetSpace ~
36437  '}' [if <functionName> ] '
36438 \backslash
36439 n' 
36440 \end_layout
36441
36442 \begin_layout Standard
36443 <assembly sequence> := assembly instruction (each instruction including
36444  labels must be on a separate line).
36445 \newline
36446
36447 \newline
36448 The optimizer will apply to the rules
36449  one by one from the top in the sequence of their appearance, it will terminate
36450  when all rules are exhausted.
36451  If the 'restart' option is specified, then the optimizer will start matching
36452  the rules again from the top, this option for a rule is expensive (performance)
36453 , it is intended to be used in situations where a transformation will trigger
36454  the same rule again.
36455  An example of this (not a good one, it has side effects) is the following
36456  rule:
36457 \end_layout
36458
36459 \begin_layout Verse
36460
36461 \family typewriter
36462 replace restart { 
36463 \newline
36464 \InsetSpace ~
36465 \InsetSpace ~
36466 pop %1 
36467 \newline
36468 \InsetSpace ~
36469 \InsetSpace ~
36470 push %1 } by { 
36471 \newline
36472 \InsetSpace ~
36473 \InsetSpace ~
36474 ; nop 
36475 \newline
36476 }
36477 \end_layout
36478
36479 \begin_layout Standard
36480 Note that the replace pattern cannot be a blank, but can be a comment line.
36481  Without the 'restart' option only the innermost 'pop' 'push' pair would
36482  be eliminated, i.e.:
36483 \end_layout
36484
36485 \begin_layout Verse
36486
36487 \family typewriter
36488 pop ar1 
36489 \newline
36490 pop ar2 
36491 \newline
36492 push ar2 
36493 \newline
36494 push ar1
36495 \end_layout
36496
36497 \begin_layout Standard
36498 would result in:
36499 \end_layout
36500
36501 \begin_layout Verse
36502
36503 \family typewriter
36504 pop ar1 
36505 \newline
36506 ; nop 
36507 \newline
36508 push ar1
36509 \end_layout
36510
36511 \begin_layout Standard
36512
36513 \emph on
36514 with
36515 \emph default
36516  the restart option the rule will be applied again to the resulting code
36517  and then all the pop-push pairs will be eliminated to yield:
36518 \end_layout
36519
36520 \begin_layout Verse
36521
36522 \family typewriter
36523 ; nop 
36524 \newline
36525 ; nop
36526 \end_layout
36527
36528 \begin_layout Standard
36529 A conditional function can be attached to a rule.
36530  Attaching rules are somewhat more involved, let me illustrate this with
36531  an example.
36532 \end_layout
36533
36534 \begin_layout Verse
36535
36536 \family typewriter
36537 replace { 
36538 \newline
36539 \InsetSpace ~
36540  \InsetSpace ~
36541  \InsetSpace ~
36542 ljmp %5 
36543 \newline
36544 %2:
36545 \newline
36546 } by { 
36547 \newline
36548 \InsetSpace ~
36549  \InsetSpace ~
36550  \InsetSpace ~
36551 sjmp %5 
36552 \newline
36553 %2:
36554 \newline
36555 } if labelInRange
36556 \end_layout
36557
36558 \begin_layout Standard
36559 The optimizer does a look-up of a function name table defined in function
36560  
36561 \emph on
36562 callFuncByName
36563 \emph default
36564  in the source file SDCCpeeph.c, with the name 
36565 \emph on
36566 labelInRange
36567 \emph default
36568 .
36569  If it finds a corresponding entry the function is called.
36570  Note there can be no parameters specified for these functions, in this
36571  case the use of 
36572 \emph on
36573 %5
36574 \emph default
36575  is crucial, since the function 
36576 \emph on
36577 labelInRange
36578 \emph default
36579  expects to find the label in that particular variable (the hash table containin
36580 g the variable bindings is passed as a parameter).
36581  If you want to code more such functions, take a close look at the function
36582  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36583  Currently implemented are 
36584 \emph on
36585 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36586  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36587 \emph default
36588 and
36589 \emph on
36590  notVolatile
36591 \emph default
36592 .
36593 \end_layout
36594
36595 \begin_layout Standard
36596 I know this whole thing is a little kludgey, but maybe some day we will
36597  have some better means.
36598  If you are looking at this file, you will see the default rules that are
36599  compiled into the compiler, you can add your own rules in the default set
36600  there if you get tired of specifying the -
36601 \begin_inset ERT
36602 status collapsed
36603
36604 \begin_layout Standard
36605
36606
36607 \backslash
36608 /
36609 \end_layout
36610
36611 \end_inset
36612
36613 -peep-file option.
36614 \end_layout
36615
36616 \begin_layout Section
36617 ANSI-Compliance
36618 \begin_inset LatexCommand \index{ANSI-compliance}
36619
36620 \end_inset
36621
36622
36623 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36624
36625 \end_inset
36626
36627
36628 \end_layout
36629
36630 \begin_layout Standard
36631 The latest publically available version of the standard 
36632 \emph on
36633 ISO/IEC 9899 - Programming languages - C
36634 \emph default
36635  should be available at: 
36636 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36637
36638 \end_inset
36639
36640 .
36641 \newline
36642
36643 \end_layout
36644
36645 \begin_layout Standard
36646 Deviations from the compliance:
36647 \end_layout
36648
36649 \begin_layout Itemize
36650 functions are not reentrant
36651 \begin_inset LatexCommand \index{reentrant}
36652
36653 \end_inset
36654
36655  unless explicitly declared as such or the 
36656 \series bold
36657 -
36658 \begin_inset ERT
36659 status collapsed
36660
36661 \begin_layout Standard
36662
36663
36664 \backslash
36665 /
36666 \end_layout
36667
36668 \end_inset
36669
36670 -stack-auto
36671 \begin_inset LatexCommand \index{-\/-stack-auto}
36672
36673 \end_inset
36674
36675
36676 \series default
36677  command line option is specified.
36678 \end_layout
36679
36680 \begin_layout Itemize
36681 structures
36682 \begin_inset LatexCommand \index{struct}
36683
36684 \end_inset
36685
36686  and unions
36687 \begin_inset LatexCommand \index{union}
36688
36689 \end_inset
36690
36691  cannot be assigned values directly, cannot be passed as function parameters
36692  or assigned to each other and cannot be a return value
36693 \begin_inset LatexCommand \index{return value}
36694
36695 \end_inset
36696
36697  from a function, e.g.:
36698 \end_layout
36699
36700 \begin_deeper
36701 \begin_layout Verse
36702
36703 \family typewriter
36704 struct s { ...
36705  }; 
36706 \newline
36707 struct s s1, s2; 
36708 \newline
36709 foo() 
36710 \newline
36711
36712 \newline
36713 \InsetSpace ~
36714 \InsetSpace ~
36715 \InsetSpace ~
36716 \InsetSpace ~
36717 ...
36718  
36719 \newline
36720 \InsetSpace ~
36721 \InsetSpace ~
36722 \InsetSpace ~
36723 \InsetSpace ~
36724 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36725 \newline
36726 \InsetSpace ~
36727 \InsetSpace ~
36728 \InsetSpace ~
36729 \InsetSpace ~
36730 ...
36731  
36732 \newline
36733 }
36734 \newline
36735
36736 \series bold
36737 struct
36738 \series default
36739  s foo1 (
36740 \series bold
36741 struct
36742 \series default
36743  s parms) /* invalid in SDCC although allowed in ANSI */
36744 \newline
36745
36746 \newline
36747 \InsetSpace ~
36748 \InsetSpace ~
36749 \InsetSpace ~
36750 \InsetSpace ~
36751 struct s rets;
36752  
36753 \newline
36754 \InsetSpace ~
36755 \InsetSpace ~
36756 \InsetSpace ~
36757 \InsetSpace ~
36758 ...
36759  
36760 \newline
36761 \InsetSpace ~
36762 \InsetSpace ~
36763 \InsetSpace ~
36764 \InsetSpace ~
36765 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36766 \newline
36767 }
36768 \end_layout
36769
36770 \end_deeper
36771 \begin_layout Itemize
36772 initialization of structure arrays must be fully braced.
36773 \end_layout
36774
36775 \begin_deeper
36776 \begin_layout Verse
36777
36778 \family typewriter
36779 struct s { char x } a[] = {1, 2};\InsetSpace ~
36780 \InsetSpace ~
36781 \InsetSpace ~
36782 \InsetSpace ~
36783 \InsetSpace ~
36784 /* invalid in SDCC */
36785 \newline
36786 struct s { char x
36787  } a[] = {{1}, {2}}; /* OK */
36788 \end_layout
36789
36790 \end_deeper
36791 \begin_layout Itemize
36792 'long long
36793 \begin_inset LatexCommand \index{long long (not supported)}
36794
36795 \end_inset
36796
36797 ' (64 bit integers
36798 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36799
36800 \end_inset
36801
36802 ) not supported.
36803 \end_layout
36804
36805 \begin_layout Itemize
36806 'double
36807 \begin_inset LatexCommand \index{double (not supported)}
36808
36809 \end_inset
36810
36811 ' precision floating point 
36812 \begin_inset LatexCommand \index{Floating point support}
36813
36814 \end_inset
36815
36816 not supported.
36817 \end_layout
36818
36819 \begin_layout Itemize
36820 Old K&R style
36821 \begin_inset LatexCommand \index{K\&R style}
36822
36823 \end_inset
36824
36825  function declarations are NOT allowed.
36826 \end_layout
36827
36828 \begin_deeper
36829 \begin_layout Verse
36830
36831 \family typewriter
36832 foo(i,j) /* this old style of function declarations */ 
36833 \newline
36834 int i,j; /* is valid
36835  in ANSI but not valid in SDCC */ 
36836 \newline
36837
36838 \newline
36839 \InsetSpace ~
36840 \InsetSpace ~
36841 \InsetSpace ~
36842 \InsetSpace ~
36843 ...
36844  
36845 \newline
36846 }
36847 \end_layout
36848
36849 \end_deeper
36850 \begin_layout Itemize
36851 Most enhancements in C99 are not supported, e.g.:
36852 \end_layout
36853
36854 \begin_deeper
36855 \begin_layout Verse
36856
36857 \family typewriter
36858 for (
36859 \series bold
36860 int
36861 \series default
36862  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36863 \end_layout
36864
36865 \end_deeper
36866 \begin_layout Itemize
36867 But some have been added recently in SDCC 2.7.0.
36868  They must be considered alpha quality however.
36869 \end_layout
36870
36871 \begin_deeper
36872 \begin_layout Verse
36873
36874 \family typewriter
36875 \series bold
36876 inline
36877 \begin_inset LatexCommand \index{inline (not supported)}
36878
36879 \end_inset
36880
36881
36882 \series default
36883  int increment (int a) { return a+1; } /* inlines the increment without
36884  function call overhead */
36885 \newline
36886 int * 
36887 \series bold
36888 restrict
36889 \begin_inset LatexCommand \index{inline (not supported)}
36890
36891 \end_inset
36892
36893
36894 \series default
36895  p; /* accepted but ignored */
36896 \end_layout
36897
36898 \end_deeper
36899 \begin_layout Itemize
36900 Certain words that are valid identifiers in the standard may be reserved
36901  words in SDCC unless the 
36902 \series bold
36903 -
36904 \begin_inset ERT
36905 status collapsed
36906
36907 \begin_layout Standard
36908
36909
36910 \backslash
36911 /
36912 \end_layout
36913
36914 \end_inset
36915
36916 -std-c89
36917 \begin_inset LatexCommand \index{-\/-std-c89}
36918
36919 \end_inset
36920
36921  
36922 \series default
36923 or
36924 \series bold
36925  -
36926 \begin_inset ERT
36927 status collapsed
36928
36929 \begin_layout Standard
36930
36931
36932 \backslash
36933 /
36934 \end_layout
36935
36936 \end_inset
36937
36938 -std-c99
36939 \begin_inset LatexCommand \index{-\/-std-c99}
36940
36941 \end_inset
36942
36943
36944 \series default
36945  command line options are used.
36946  These may include (depending on the selected processor): 'at', 'banked',
36947  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36948 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36949  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36950  '_naked'.
36951  Compliant equivalents of these keywords are always available in a form
36952  that begin with two underscores
36953 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36954
36955 \end_inset
36956
36957 , f.e.
36958  '__data' instead of 'data'.
36959 \end_layout
36960
36961 \begin_layout Itemize
36962 Integer promotion of variable arguments is not performed if the argument
36963  is explicitly taypecasted unless the
36964 \series bold
36965  -
36966 \begin_inset ERT
36967 status collapsed
36968
36969 \begin_layout Standard
36970
36971
36972 \backslash
36973 /
36974 \end_layout
36975
36976 \end_inset
36977
36978 -std-c89
36979 \begin_inset LatexCommand \index{-\/-std-c89}
36980
36981 \end_inset
36982
36983  
36984 \series default
36985 or
36986 \series bold
36987  -
36988 \begin_inset ERT
36989 status collapsed
36990
36991 \begin_layout Standard
36992
36993
36994 \backslash
36995 /
36996 \end_layout
36997
36998 \end_inset
36999
37000 -std-c99
37001 \begin_inset LatexCommand \index{-\/-std-c99}
37002
37003 \end_inset
37004
37005
37006 \series default
37007  command line options are used.
37008 \end_layout
37009
37010 \begin_deeper
37011 \begin_layout Verse
37012
37013 \family typewriter
37014 void vararg_func (char *str, ...) { str; }
37015 \newline
37016
37017 \newline
37018 void main (void)
37019 \newline
37020 {
37021 \newline
37022 \InsetSpace ~
37023 \InsetSpace ~
37024 char c = 10;
37025 \newline
37026
37027 \newline
37028 \InsetSpace ~
37029 \InsetSpace ~
37030 /* argument
37031  u is promoted to int before
37032 \newline
37033 \InsetSpace ~
37034 \InsetSpace ~
37035 \InsetSpace ~
37036 * passing to function */
37037 \newline
37038 \InsetSpace ~
37039 \InsetSpace ~
37040 vararg_func ("%c", c);
37041 \newline
37042
37043 \newline
37044 \InsetSpace ~
37045 \InsetSpace ~
37046 /*
37047  argument u is not promoted to int,
37048 \newline
37049 \InsetSpace ~
37050 \InsetSpace ~
37051 \InsetSpace ~
37052 * it is passed as char to function
37053 \newline
37054 \InsetSpace ~
37055 \InsetSpace ~
37056 \InsetSpace ~
37057 * if
37058  --std-cXX is not defined;
37059 \newline
37060 \InsetSpace ~
37061 \InsetSpace ~
37062 \InsetSpace ~
37063 * is promoted to int before passing
37064 \newline
37065 \InsetSpace ~
37066 \InsetSpace ~
37067 \InsetSpace ~
37068 * to function
37069  if --std-cXX is defined */
37070 \newline
37071 \InsetSpace ~
37072 \InsetSpace ~
37073 vararg_func ("%bc", (char)u);
37074 \newline
37075 }
37076 \end_layout
37077
37078 \end_deeper
37079 \begin_layout Section
37080 Cyclomatic Complexity
37081 \begin_inset LatexCommand \index{Cyclomatic complexity}
37082
37083 \end_inset
37084
37085
37086 \end_layout
37087
37088 \begin_layout Standard
37089 Cyclomatic complexity of a function is defined as the number of independent
37090  paths the program can take during execution of the function.
37091  This is an important number since it defines the number test cases you
37092  have to generate to validate the function.
37093  The accepted industry standard for complexity number is 10, if the cyclomatic
37094  complexity reported by SDCC exceeds 10 you should think about simplification
37095  of the function logic.
37096  Note that the complexity level is not related to the number of lines of
37097  code in a function.
37098  Large functions can have low complexity, and small functions can have large
37099  complexity levels.
37100  
37101 \newline
37102
37103 \newline
37104 SDCC uses the following formula to compute the complexity:
37105 \newline
37106
37107 \end_layout
37108
37109 \begin_layout Standard
37110 complexity = (number of edges in control flow graph) - (number of nodes
37111  in control flow graph) + 2;
37112 \newline
37113
37114 \newline
37115 Having said that the industry standard is 10,
37116  you should be aware that in some cases it be may unavoidable to have a
37117  complexity level of less than 10.
37118  For example if you have switch statement with more than 10 case labels,
37119  each case label adds one to the complexity level.
37120  The complexity level is by no means an absolute measure of the algorithmic
37121  complexity of the function, it does however provide a good starting point
37122  for which functions you might look at for further optimization.
37123 \end_layout
37124
37125 \begin_layout Section
37126 Retargetting for other Processors
37127 \end_layout
37128
37129 \begin_layout Standard
37130 The issues for retargetting the compiler are far too numerous to be covered
37131  by this document.
37132  What follows is a brief description of each of the seven phases of the
37133  compiler and its MCU dependency.
37134 \end_layout
37135
37136 \begin_layout Itemize
37137 Parsing the source and building the annotated parse tree.
37138  This phase is largely MCU independent (except for the language extensions).
37139  Syntax & semantic checks are also done in this phase, along with some initial
37140  optimizations like back patching labels and the pattern matching optimizations
37141  like bit-rotation etc.
37142 \end_layout
37143
37144 \begin_layout Itemize
37145 The second phase involves generating an intermediate code which can be easy
37146  manipulated during the later phases.
37147  This phase is entirely MCU independent.
37148  The intermediate code generation assumes the target machine has unlimited
37149  number of registers, and designates them with the name iTemp.
37150  The compiler can be made to dump a human readable form of the code generated
37151  by using the -
37152 \begin_inset ERT
37153 status collapsed
37154
37155 \begin_layout Standard
37156
37157
37158 \backslash
37159 /
37160 \end_layout
37161
37162 \end_inset
37163
37164 -dumpraw option.
37165 \end_layout
37166
37167 \begin_layout Itemize
37168 This phase does the bulk of the standard optimizations and is also MCU independe
37169 nt.
37170  This phase can be broken down into several sub-phases:
37171 \newline
37172
37173 \newline
37174 Break down intermediate
37175  code (iCode) into basic blocks.
37176 \newline
37177 Do control flow & data flow analysis on the
37178  basic blocks.
37179 \newline
37180 Do local common subexpression elimination, then global subexpressio
37181 n elimination
37182 \newline
37183 Dead code elimination
37184 \newline
37185 Loop optimizations
37186 \newline
37187 If loop optimizations
37188  caused any changes then do 'global subexpression elimination' and 'dead
37189  code elimination' again.
37190 \end_layout
37191
37192 \begin_layout Itemize
37193 This phase determines the live-ranges; by live range I mean those iTemp
37194  variables defined by the compiler that still survive after all the optimization
37195 s.
37196  Live range analysis
37197 \begin_inset LatexCommand \index{Live range analysis}
37198
37199 \end_inset
37200
37201  is essential for register allocation, since these computation determines
37202  which of these iTemps will be assigned to registers, and for how long.
37203 \end_layout
37204
37205 \begin_layout Itemize
37206 Phase five is register allocation.
37207  There are two parts to this process.
37208 \newline
37209
37210 \newline
37211 The first part I call 'register packing'
37212  (for lack of a better term).
37213  In this case several MCU specific expression folding is done to reduce
37214  register pressure.
37215 \newline
37216
37217 \newline
37218 The second part is more MCU independent and deals with
37219  allocating registers to the remaining live ranges.
37220  A lot of MCU specific code does creep into this phase because of the limited
37221  number of index registers available in the 8051.
37222 \end_layout
37223
37224 \begin_layout Itemize
37225 The Code generation phase is (unhappily), entirely MCU dependent and very
37226  little (if any at all) of this code can be reused for other MCU.
37227  However the scheme for allocating a homogenized assembler operand for each
37228  iCode operand may be reused.
37229 \end_layout
37230
37231 \begin_layout Itemize
37232 As mentioned in the optimization section the peep-hole optimizer is rule
37233  based system, which can reprogrammed for other MCUs.
37234 \end_layout
37235
37236 \begin_layout Standard
37237 More information is available on SDCC Wiki
37238 \begin_inset LatexCommand \index{wiki}
37239
37240 \end_inset
37241
37242  (preliminary link 
37243 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37244
37245 \end_inset
37246
37247 ) and in the thread 
37248 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37249
37250 \end_inset
37251
37252  .
37253 \end_layout
37254
37255 \begin_layout Chapter
37256 Compiler internals
37257 \begin_inset LatexCommand \index{Compiler internals}
37258
37259 \end_inset
37260
37261
37262 \end_layout
37263
37264 \begin_layout Section
37265 The anatomy of the compiler
37266 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37267
37268 \end_inset
37269
37270
37271 \end_layout
37272
37273 \begin_layout Standard
37274
37275 \shape italic
37276 This is an excerpt from an article published in Circuit Cellar Magazine
37277  in 
37278 \series bold
37279 August 2000
37280 \series default
37281 .
37282  It's a little outdated (the compiler is much more efficient now and user/develo
37283 per friendly), but pretty well exposes the guts of it all.
37284 \shape default
37285
37286 \newline
37287
37288 \newline
37289 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37290  It is fairly easy to retarget for other 8-bit MCU.
37291  Here we take a look at some of the internals of the compiler.
37292  
37293 \end_layout
37294
37295 \begin_layout Paragraph*
37296 Parsing
37297 \begin_inset LatexCommand \index{Parsing}
37298
37299 \end_inset
37300
37301  
37302 \end_layout
37303
37304 \begin_layout Standard
37305 Parsing the input source file and creating an AST (Annotated Syntax Tree
37306 \begin_inset LatexCommand \index{Annotated syntax tree}
37307
37308 \end_inset
37309
37310 ).
37311  This phase also involves propagating types (annotating each node of the
37312  parse tree with type information) and semantic analysis.
37313  There are some MCU specific parsing rules.
37314  For example the storage classes, the extended storage classes are MCU specific
37315  while there may be a xdata storage class for 8051 there is no such storage
37316  class for z80 or Atmel AVR.
37317  SDCC allows MCU specific storage class extensions, i.e.
37318  xdata will be treated as a storage class specifier when parsing 8051 C
37319  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37320  C code.
37321 \end_layout
37322
37323 \begin_layout Paragraph*
37324 Generating iCode
37325 \begin_inset LatexCommand \index{iCode}
37326
37327 \end_inset
37328
37329
37330 \end_layout
37331
37332 \begin_layout Standard
37333 Intermediate code generation.
37334  In this phase the AST is broken down into three-operand form (iCode).
37335  These three operand forms are represented as doubly linked lists.
37336  ICode is the term given to the intermediate form generated by the compiler.
37337  ICode example section shows some examples of iCode generated for some simple
37338  C source functions.
37339 \end_layout
37340
37341 \begin_layout Paragraph*
37342 Optimizations
37343 \begin_inset LatexCommand \index{Optimizations}
37344
37345 \end_inset
37346
37347 .
37348 \end_layout
37349
37350 \begin_layout Standard
37351 Bulk of the target independent optimizations is performed in this phase.
37352  The optimizations include constant propagation, common sub-expression eliminati
37353 on, loop invariant code movement, strength reduction of loop induction variables
37354  and dead-code elimination.
37355 \end_layout
37356
37357 \begin_layout Paragraph*
37358 Live range analysis
37359 \begin_inset LatexCommand \index{Live range analysis}
37360
37361 \end_inset
37362
37363
37364 \end_layout
37365
37366 \begin_layout Standard
37367 During intermediate code generation phase, the compiler assumes the target
37368  machine has infinite number of registers and generates a lot of temporary
37369  variables.
37370  The live range computation determines the lifetime of each of these compiler-ge
37371 nerated temporaries.
37372  A picture speaks a thousand words.
37373  ICode example sections show the live range annotations for each of the
37374  operand.
37375  It is important to note here, each iCode is assigned a number in the order
37376  of its execution in the function.
37377  The live ranges are computed in terms of these numbers.
37378  The from number is the number of the iCode which first defines the operand
37379  and the to number signifies the iCode which uses this operand last.
37380 \end_layout
37381
37382 \begin_layout Paragraph*
37383 Register Allocation
37384 \begin_inset LatexCommand \index{Register allocation}
37385
37386 \end_inset
37387
37388
37389 \end_layout
37390
37391 \begin_layout Standard
37392 The register allocation determines the type and number of registers needed
37393  by each operand.
37394  In most MCUs only a few registers can be used for indirect addressing.
37395  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37396  address the internal ram and DPTR to indirectly address the external ram.
37397  The compiler will try to allocate the appropriate register to pointer variables
37398  if it can.
37399  ICode example section shows the operands annotated with the registers assigned
37400  to them.
37401  The compiler will try to keep operands in registers as much as possible;
37402  there are several schemes the compiler uses to do achieve this.
37403  When the compiler runs out of registers the compiler will check to see
37404  if there are any live operands which is not used or defined in the current
37405  basic block being processed, if there are any found then it will push that
37406  operand and use the registers in this block, the operand will then be popped
37407  at the end of the basic block.
37408  
37409 \end_layout
37410
37411 \begin_layout Standard
37412 There are other MCU specific considerations in this phase.
37413  Some MCUs have an accumulator; very short-lived operands could be assigned
37414  to the accumulator instead of a general-purpose register.
37415 \end_layout
37416
37417 \begin_layout Paragraph*
37418 Code generation
37419 \end_layout
37420
37421 \begin_layout Standard
37422 Figure II gives a table of iCode
37423 \begin_inset LatexCommand \index{iCode}
37424
37425 \end_inset
37426
37427  operations supported by the compiler.
37428  The code generation involves translating these operations into corresponding
37429  assembly code for the processor.
37430  This sounds overly simple but that is the essence of code generation.
37431  Some of the iCode operations are generated on a MCU specific manner for
37432  example, the z80 port does not use registers to pass parameters so the
37433  SEND and RECV iCode operations will not be generated, and it also does
37434  not support JUMPTABLES.
37435  
37436 \newline
37437
37438 \end_layout
37439
37440 \begin_layout Standard
37441
37442 \size footnotesize
37443 Figure II 
37444 \begin_inset Tabular
37445 <lyxtabular version="3" rows="39" columns="4">
37446 <features islongtable="true" headBottomDL="true">
37447 <column alignment="block" valignment="top" leftline="true" width="13col%">
37448 <column alignment="left" valignment="top" leftline="true" width="13col%">
37449 <column alignment="block" valignment="top" leftline="true" width="22col%">
37450 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37451 <row topline="true" bottomline="true" endhead="true">
37452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37453 \begin_inset Text
37454
37455 \begin_layout Standard
37456
37457 \series bold
37458 iCode
37459 \series default
37460
37461 \begin_inset LatexCommand \index{iCode}
37462
37463 \end_inset
37464
37465
37466 \end_layout
37467
37468 \end_inset
37469 </cell>
37470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37471 \begin_inset Text
37472
37473 \begin_layout Standard
37474
37475 \series bold
37476 Operands
37477 \end_layout
37478
37479 \end_inset
37480 </cell>
37481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37482 \begin_inset Text
37483
37484 \begin_layout Standard
37485
37486 \series bold
37487 Description
37488 \end_layout
37489
37490 \end_inset
37491 </cell>
37492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37493 \begin_inset Text
37494
37495 \begin_layout Standard
37496
37497 \series bold
37498 C Equivalent
37499 \end_layout
37500
37501 \end_inset
37502 </cell>
37503 </row>
37504 <row topline="true">
37505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37506 \begin_inset Text
37507
37508 \begin_layout Standard
37509
37510 \size footnotesize
37511 '!'
37512 \end_layout
37513
37514 \end_inset
37515 </cell>
37516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37517 \begin_inset Text
37518
37519 \begin_layout Standard
37520
37521 \size footnotesize
37522 IC_LEFT() IC_RESULT()
37523 \end_layout
37524
37525 \end_inset
37526 </cell>
37527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37528 \begin_inset Text
37529
37530 \begin_layout Standard
37531
37532 \size footnotesize
37533 NOT operation 
37534 \end_layout
37535
37536 \end_inset
37537 </cell>
37538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37539 \begin_inset Text
37540
37541 \begin_layout Standard
37542
37543 \size footnotesize
37544 IC_RESULT = ! IC_LEFT;
37545 \end_layout
37546
37547 \end_inset
37548 </cell>
37549 </row>
37550 <row topline="true">
37551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37552 \begin_inset Text
37553
37554 \begin_layout Standard
37555
37556 \size footnotesize
37557 '~'
37558 \end_layout
37559
37560 \end_inset
37561 </cell>
37562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37563 \begin_inset Text
37564
37565 \begin_layout Standard
37566
37567 \size footnotesize
37568 IC_LEFT() IC_RESULT()
37569 \end_layout
37570
37571 \end_inset
37572 </cell>
37573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37574 \begin_inset Text
37575
37576 \begin_layout Standard
37577
37578 \size footnotesize
37579 Bitwise complement of 
37580 \end_layout
37581
37582 \end_inset
37583 </cell>
37584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37585 \begin_inset Text
37586
37587 \begin_layout Standard
37588
37589 \size footnotesize
37590 IC_RESULT = ~IC_LEFT;
37591 \end_layout
37592
37593 \end_inset
37594 </cell>
37595 </row>
37596 <row topline="true">
37597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37598 \begin_inset Text
37599
37600 \begin_layout Standard
37601
37602 \size footnotesize
37603 RRC
37604 \end_layout
37605
37606 \end_inset
37607 </cell>
37608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37609 \begin_inset Text
37610
37611 \begin_layout Standard
37612
37613 \size footnotesize
37614 IC_LEFT() IC_RESULT()
37615 \end_layout
37616
37617 \end_inset
37618 </cell>
37619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37620 \begin_inset Text
37621
37622 \begin_layout Standard
37623
37624 \size footnotesize
37625 Rotate right with carry
37626 \end_layout
37627
37628 \end_inset
37629 </cell>
37630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37631 \begin_inset Text
37632
37633 \begin_layout Standard
37634
37635 \size footnotesize
37636 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37637 \end_layout
37638
37639 \end_inset
37640 </cell>
37641 </row>
37642 <row topline="true">
37643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37644 \begin_inset Text
37645
37646 \begin_layout Standard
37647
37648 \size footnotesize
37649 RLC
37650 \end_layout
37651
37652 \end_inset
37653 </cell>
37654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37655 \begin_inset Text
37656
37657 \begin_layout Standard
37658
37659 \size footnotesize
37660 IC_LEFT() IC_RESULT()
37661 \end_layout
37662
37663 \end_inset
37664 </cell>
37665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37666 \begin_inset Text
37667
37668 \begin_layout Standard
37669
37670 \size footnotesize
37671 Rotate left with carry
37672 \end_layout
37673
37674 \end_inset
37675 </cell>
37676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37677 \begin_inset Text
37678
37679 \begin_layout Standard
37680
37681 \size footnotesize
37682 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37683 \end_layout
37684
37685 \end_inset
37686 </cell>
37687 </row>
37688 <row topline="true">
37689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37690 \begin_inset Text
37691
37692 \begin_layout Standard
37693
37694 \size footnotesize
37695 GETHBIT
37696 \end_layout
37697
37698 \end_inset
37699 </cell>
37700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37701 \begin_inset Text
37702
37703 \begin_layout Standard
37704
37705 \size footnotesize
37706 IC_LEFT() IC_RESULT()
37707 \end_layout
37708
37709 \end_inset
37710 </cell>
37711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37712 \begin_inset Text
37713
37714 \begin_layout Standard
37715
37716 \size footnotesize
37717 Get the highest order bit of IC_LEFT
37718 \end_layout
37719
37720 \end_inset
37721 </cell>
37722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37723 \begin_inset Text
37724
37725 \begin_layout Standard
37726
37727 \size footnotesize
37728 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37729 \end_layout
37730
37731 \end_inset
37732 </cell>
37733 </row>
37734 <row topline="true">
37735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37736 \begin_inset Text
37737
37738 \begin_layout Standard
37739
37740 \size footnotesize
37741 UNARYMINUS
37742 \end_layout
37743
37744 \end_inset
37745 </cell>
37746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37747 \begin_inset Text
37748
37749 \begin_layout Standard
37750
37751 \size footnotesize
37752 IC_LEFT() IC_RESULT()
37753 \end_layout
37754
37755 \end_inset
37756 </cell>
37757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37758 \begin_inset Text
37759
37760 \begin_layout Standard
37761
37762 \size footnotesize
37763 Unary minus
37764 \end_layout
37765
37766 \end_inset
37767 </cell>
37768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37769 \begin_inset Text
37770
37771 \begin_layout Standard
37772
37773 \size footnotesize
37774 IC_RESULT = - IC_LEFT;
37775 \end_layout
37776
37777 \end_inset
37778 </cell>
37779 </row>
37780 <row topline="true">
37781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37782 \begin_inset Text
37783
37784 \begin_layout Standard
37785
37786 \size footnotesize
37787 IPUSH
37788 \end_layout
37789
37790 \end_inset
37791 </cell>
37792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37793 \begin_inset Text
37794
37795 \begin_layout Standard
37796
37797 \size footnotesize
37798 IC_LEFT()
37799 \end_layout
37800
37801 \end_inset
37802 </cell>
37803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37804 \begin_inset Text
37805
37806 \begin_layout Standard
37807
37808 \size footnotesize
37809 Push the operand into stack
37810 \end_layout
37811
37812 \end_inset
37813 </cell>
37814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37815 \begin_inset Text
37816
37817 \begin_layout Standard
37818
37819 \size footnotesize
37820 NONE
37821 \end_layout
37822
37823 \end_inset
37824 </cell>
37825 </row>
37826 <row topline="true">
37827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37828 \begin_inset Text
37829
37830 \begin_layout Standard
37831
37832 \size footnotesize
37833 IPOP
37834 \end_layout
37835
37836 \end_inset
37837 </cell>
37838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37839 \begin_inset Text
37840
37841 \begin_layout Standard
37842
37843 \size footnotesize
37844 IC_LEFT()
37845 \end_layout
37846
37847 \end_inset
37848 </cell>
37849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37850 \begin_inset Text
37851
37852 \begin_layout Standard
37853
37854 \size footnotesize
37855 Pop the operand from the stack 
37856 \end_layout
37857
37858 \end_inset
37859 </cell>
37860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37861 \begin_inset Text
37862
37863 \begin_layout Standard
37864
37865 \size footnotesize
37866 NONE
37867 \end_layout
37868
37869 \end_inset
37870 </cell>
37871 </row>
37872 <row topline="true">
37873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37874 \begin_inset Text
37875
37876 \begin_layout Standard
37877
37878 \size footnotesize
37879 CALL
37880 \end_layout
37881
37882 \end_inset
37883 </cell>
37884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37885 \begin_inset Text
37886
37887 \begin_layout Standard
37888
37889 \size footnotesize
37890 IC_LEFT() IC_RESULT()
37891 \end_layout
37892
37893 \end_inset
37894 </cell>
37895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37896 \begin_inset Text
37897
37898 \begin_layout Standard
37899
37900 \size footnotesize
37901 Call the function represented by IC_LEFT 
37902 \end_layout
37903
37904 \end_inset
37905 </cell>
37906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37907 \begin_inset Text
37908
37909 \begin_layout Standard
37910
37911 \size footnotesize
37912 IC_RESULT = IC_LEFT();
37913 \end_layout
37914
37915 \end_inset
37916 </cell>
37917 </row>
37918 <row topline="true">
37919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37920 \begin_inset Text
37921
37922 \begin_layout Standard
37923
37924 \size footnotesize
37925 PCALL
37926 \end_layout
37927
37928 \end_inset
37929 </cell>
37930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37931 \begin_inset Text
37932
37933 \begin_layout Standard
37934
37935 \size footnotesize
37936 IC_LEFT() IC_RESULT()
37937 \end_layout
37938
37939 \end_inset
37940 </cell>
37941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37942 \begin_inset Text
37943
37944 \begin_layout Standard
37945
37946 \size footnotesize
37947 Call via function pointer
37948 \end_layout
37949
37950 \end_inset
37951 </cell>
37952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37953 \begin_inset Text
37954
37955 \begin_layout Standard
37956
37957 \size footnotesize
37958 IC_RESULT = (*IC_LEFT)();
37959 \end_layout
37960
37961 \end_inset
37962 </cell>
37963 </row>
37964 <row topline="true">
37965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37966 \begin_inset Text
37967
37968 \begin_layout Standard
37969
37970 \size footnotesize
37971 RETURN
37972 \end_layout
37973
37974 \end_inset
37975 </cell>
37976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37977 \begin_inset Text
37978
37979 \begin_layout Standard
37980
37981 \size footnotesize
37982 IC_LEFT()
37983 \end_layout
37984
37985 \end_inset
37986 </cell>
37987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37988 \begin_inset Text
37989
37990 \begin_layout Standard
37991
37992 \size footnotesize
37993 Return the value in operand IC_LEFT 
37994 \end_layout
37995
37996 \end_inset
37997 </cell>
37998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37999 \begin_inset Text
38000
38001 \begin_layout Standard
38002
38003 \size footnotesize
38004 return IC_LEFT;
38005 \end_layout
38006
38007 \end_inset
38008 </cell>
38009 </row>
38010 <row topline="true">
38011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38012 \begin_inset Text
38013
38014 \begin_layout Standard
38015
38016 \size footnotesize
38017 LABEL
38018 \end_layout
38019
38020 \end_inset
38021 </cell>
38022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38023 \begin_inset Text
38024
38025 \begin_layout Standard
38026
38027 \size footnotesize
38028 IC_LABEL() 
38029 \end_layout
38030
38031 \end_inset
38032 </cell>
38033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38034 \begin_inset Text
38035
38036 \begin_layout Standard
38037
38038 \size footnotesize
38039 Label
38040 \end_layout
38041
38042 \end_inset
38043 </cell>
38044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38045 \begin_inset Text
38046
38047 \begin_layout Standard
38048
38049 \size footnotesize
38050 IC_LABEL:
38051 \end_layout
38052
38053 \end_inset
38054 </cell>
38055 </row>
38056 <row topline="true">
38057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38058 \begin_inset Text
38059
38060 \begin_layout Standard
38061
38062 \size footnotesize
38063 GOTO
38064 \end_layout
38065
38066 \end_inset
38067 </cell>
38068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38069 \begin_inset Text
38070
38071 \begin_layout Standard
38072
38073 \size footnotesize
38074 IC_LABEL() 
38075 \end_layout
38076
38077 \end_inset
38078 </cell>
38079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38080 \begin_inset Text
38081
38082 \begin_layout Standard
38083
38084 \size footnotesize
38085 Goto label
38086 \end_layout
38087
38088 \end_inset
38089 </cell>
38090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38091 \begin_inset Text
38092
38093 \begin_layout Standard
38094
38095 \size footnotesize
38096 goto IC_LABEL();
38097 \end_layout
38098
38099 \end_inset
38100 </cell>
38101 </row>
38102 <row topline="true">
38103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38104 \begin_inset Text
38105
38106 \begin_layout Standard
38107
38108 \size footnotesize
38109 '+'
38110 \end_layout
38111
38112 \end_inset
38113 </cell>
38114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38115 \begin_inset Text
38116
38117 \begin_layout Standard
38118
38119 \size footnotesize
38120 IC_LEFT() IC_RIGHT() IC_RESULT()
38121 \end_layout
38122
38123 \end_inset
38124 </cell>
38125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38126 \begin_inset Text
38127
38128 \begin_layout Standard
38129
38130 \size footnotesize
38131 Addition
38132 \end_layout
38133
38134 \end_inset
38135 </cell>
38136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38137 \begin_inset Text
38138
38139 \begin_layout Standard
38140
38141 \size footnotesize
38142 IC_RESULT = IC_LEFT + IC_RIGHT
38143 \end_layout
38144
38145 \end_inset
38146 </cell>
38147 </row>
38148 <row topline="true">
38149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38150 \begin_inset Text
38151
38152 \begin_layout Standard
38153
38154 \size footnotesize
38155 '-'
38156 \end_layout
38157
38158 \end_inset
38159 </cell>
38160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38161 \begin_inset Text
38162
38163 \begin_layout Standard
38164
38165 \size footnotesize
38166 IC_LEFT() IC_RIGHT() IC_RESULT()
38167 \end_layout
38168
38169 \end_inset
38170 </cell>
38171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38172 \begin_inset Text
38173
38174 \begin_layout Standard
38175
38176 \size footnotesize
38177 Subtraction
38178 \end_layout
38179
38180 \end_inset
38181 </cell>
38182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38183 \begin_inset Text
38184
38185 \begin_layout Standard
38186
38187 \size footnotesize
38188 IC_RESULT = IC_LEFT - IC_RIGHT 
38189 \end_layout
38190
38191 \end_inset
38192 </cell>
38193 </row>
38194 <row topline="true">
38195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38196 \begin_inset Text
38197
38198 \begin_layout Standard
38199
38200 \size footnotesize
38201 '*'
38202 \end_layout
38203
38204 \end_inset
38205 </cell>
38206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38207 \begin_inset Text
38208
38209 \begin_layout Standard
38210
38211 \size footnotesize
38212 IC_LEFT() IC_RIGHT() IC_RESULT()
38213 \end_layout
38214
38215 \end_inset
38216 </cell>
38217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38218 \begin_inset Text
38219
38220 \begin_layout Standard
38221
38222 \size footnotesize
38223 Multiplication 
38224 \end_layout
38225
38226 \end_inset
38227 </cell>
38228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38229 \begin_inset Text
38230
38231 \begin_layout Standard
38232
38233 \size footnotesize
38234 IC_RESULT = IC_LEFT * IC_RIGHT;
38235 \end_layout
38236
38237 \end_inset
38238 </cell>
38239 </row>
38240 <row topline="true">
38241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38242 \begin_inset Text
38243
38244 \begin_layout Standard
38245
38246 \size footnotesize
38247 '/'
38248 \end_layout
38249
38250 \end_inset
38251 </cell>
38252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38253 \begin_inset Text
38254
38255 \begin_layout Standard
38256
38257 \size footnotesize
38258 IC_LEFT() IC_RIGHT() IC_RESULT()
38259 \end_layout
38260
38261 \end_inset
38262 </cell>
38263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38264 \begin_inset Text
38265
38266 \begin_layout Standard
38267
38268 \size footnotesize
38269 Division
38270 \end_layout
38271
38272 \end_inset
38273 </cell>
38274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38275 \begin_inset Text
38276
38277 \begin_layout Standard
38278
38279 \size footnotesize
38280 IC_RESULT = IC_LEFT / IC_RIGHT;
38281 \end_layout
38282
38283 \end_inset
38284 </cell>
38285 </row>
38286 <row topline="true">
38287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38288 \begin_inset Text
38289
38290 \begin_layout Standard
38291
38292 \size footnotesize
38293 '%'
38294 \end_layout
38295
38296 \end_inset
38297 </cell>
38298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38299 \begin_inset Text
38300
38301 \begin_layout Standard
38302
38303 \size footnotesize
38304 IC_LEFT() IC_RIGHT() IC_RESULT()
38305 \end_layout
38306
38307 \end_inset
38308 </cell>
38309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38310 \begin_inset Text
38311
38312 \begin_layout Standard
38313
38314 \size footnotesize
38315 Modulus
38316 \end_layout
38317
38318 \end_inset
38319 </cell>
38320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38321 \begin_inset Text
38322
38323 \begin_layout Standard
38324
38325 \size footnotesize
38326 IC_RESULT = IC_LEFT % IC_RIGHT;
38327 \end_layout
38328
38329 \end_inset
38330 </cell>
38331 </row>
38332 <row topline="true">
38333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38334 \begin_inset Text
38335
38336 \begin_layout Standard
38337
38338 \size footnotesize
38339 '<'
38340 \end_layout
38341
38342 \end_inset
38343 </cell>
38344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38345 \begin_inset Text
38346
38347 \begin_layout Standard
38348
38349 \size footnotesize
38350 IC_LEFT() IC_RIGHT() IC_RESULT()
38351 \end_layout
38352
38353 \end_inset
38354 </cell>
38355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38356 \begin_inset Text
38357
38358 \begin_layout Standard
38359
38360 \size footnotesize
38361 Less than
38362 \end_layout
38363
38364 \end_inset
38365 </cell>
38366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38367 \begin_inset Text
38368
38369 \begin_layout Standard
38370
38371 \size footnotesize
38372 IC_RESULT = IC_LEFT < IC_RIGHT;
38373 \end_layout
38374
38375 \end_inset
38376 </cell>
38377 </row>
38378 <row topline="true">
38379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38380 \begin_inset Text
38381
38382 \begin_layout Standard
38383
38384 \size footnotesize
38385 '>'
38386 \end_layout
38387
38388 \end_inset
38389 </cell>
38390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38391 \begin_inset Text
38392
38393 \begin_layout Standard
38394
38395 \size footnotesize
38396 IC_LEFT() IC_RIGHT() IC_RESULT()
38397 \end_layout
38398
38399 \end_inset
38400 </cell>
38401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38402 \begin_inset Text
38403
38404 \begin_layout Standard
38405
38406 \size footnotesize
38407 Greater than 
38408 \end_layout
38409
38410 \end_inset
38411 </cell>
38412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38413 \begin_inset Text
38414
38415 \begin_layout Standard
38416
38417 \size footnotesize
38418 IC_RESULT = IC_LEFT > IC_RIGHT;
38419 \end_layout
38420
38421 \end_inset
38422 </cell>
38423 </row>
38424 <row topline="true">
38425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38426 \begin_inset Text
38427
38428 \begin_layout Standard
38429
38430 \size footnotesize
38431 EQ_OP
38432 \end_layout
38433
38434 \end_inset
38435 </cell>
38436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38437 \begin_inset Text
38438
38439 \begin_layout Standard
38440
38441 \size footnotesize
38442 IC_LEFT() IC_RIGHT() IC_RESULT()
38443 \end_layout
38444
38445 \end_inset
38446 </cell>
38447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38448 \begin_inset Text
38449
38450 \begin_layout Standard
38451
38452 \size footnotesize
38453 Equal to 
38454 \end_layout
38455
38456 \end_inset
38457 </cell>
38458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38459 \begin_inset Text
38460
38461 \begin_layout Standard
38462
38463 \size footnotesize
38464 IC_RESULT = IC_LEFT == IC_RIGHT;
38465 \end_layout
38466
38467 \end_inset
38468 </cell>
38469 </row>
38470 <row topline="true">
38471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38472 \begin_inset Text
38473
38474 \begin_layout Standard
38475
38476 \size footnotesize
38477 AND_OP
38478 \end_layout
38479
38480 \end_inset
38481 </cell>
38482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38483 \begin_inset Text
38484
38485 \begin_layout Standard
38486
38487 \size footnotesize
38488 IC_LEFT() IC_RIGHT() IC_RESULT() 
38489 \end_layout
38490
38491 \end_inset
38492 </cell>
38493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38494 \begin_inset Text
38495
38496 \begin_layout Standard
38497
38498 \size footnotesize
38499 Logical and operation
38500 \end_layout
38501
38502 \end_inset
38503 </cell>
38504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38505 \begin_inset Text
38506
38507 \begin_layout Standard
38508
38509 \size footnotesize
38510 IC_RESULT = IC_LEFT && IC_RIGHT; 
38511 \end_layout
38512
38513 \end_inset
38514 </cell>
38515 </row>
38516 <row topline="true">
38517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38518 \begin_inset Text
38519
38520 \begin_layout Standard
38521
38522 \size footnotesize
38523 OR_OP
38524 \end_layout
38525
38526 \end_inset
38527 </cell>
38528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38529 \begin_inset Text
38530
38531 \begin_layout Standard
38532
38533 \size footnotesize
38534 IC_LEFT() IC_RIGHT() IC_RESULT() 
38535 \end_layout
38536
38537 \end_inset
38538 </cell>
38539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38540 \begin_inset Text
38541
38542 \begin_layout Standard
38543
38544 \size footnotesize
38545 Logical or operation 
38546 \end_layout
38547
38548 \end_inset
38549 </cell>
38550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38551 \begin_inset Text
38552
38553 \begin_layout Standard
38554
38555 \size footnotesize
38556 IC_RESULT = IC_LEFT || IC_RIGHT; 
38557 \end_layout
38558
38559 \end_inset
38560 </cell>
38561 </row>
38562 <row topline="true">
38563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38564 \begin_inset Text
38565
38566 \begin_layout Standard
38567
38568 \size footnotesize
38569 '^'
38570 \end_layout
38571
38572 \end_inset
38573 </cell>
38574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38575 \begin_inset Text
38576
38577 \begin_layout Standard
38578
38579 \size footnotesize
38580 IC_LEFT() IC_RIGHT() IC_RESULT() 
38581 \end_layout
38582
38583 \end_inset
38584 </cell>
38585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38586 \begin_inset Text
38587
38588 \begin_layout Standard
38589
38590 \size footnotesize
38591 Exclusive OR
38592 \end_layout
38593
38594 \end_inset
38595 </cell>
38596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38597 \begin_inset Text
38598
38599 \begin_layout Standard
38600
38601 \size footnotesize
38602 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38603 \end_layout
38604
38605 \end_inset
38606 </cell>
38607 </row>
38608 <row topline="true">
38609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38610 \begin_inset Text
38611
38612 \begin_layout Standard
38613
38614 \size footnotesize
38615 '|'
38616 \end_layout
38617
38618 \end_inset
38619 </cell>
38620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38621 \begin_inset Text
38622
38623 \begin_layout Standard
38624
38625 \size footnotesize
38626 IC_LEFT() IC_RIGHT() IC_RESULT() 
38627 \end_layout
38628
38629 \end_inset
38630 </cell>
38631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38632 \begin_inset Text
38633
38634 \begin_layout Standard
38635
38636 \size footnotesize
38637 Bitwise OR 
38638 \end_layout
38639
38640 \end_inset
38641 </cell>
38642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38643 \begin_inset Text
38644
38645 \begin_layout Standard
38646
38647 \size footnotesize
38648 IC_RESULT = IC_LEFT | IC_RIGHT;
38649 \end_layout
38650
38651 \end_inset
38652 </cell>
38653 </row>
38654 <row topline="true">
38655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38656 \begin_inset Text
38657
38658 \begin_layout Standard
38659
38660 \size footnotesize
38661 BITWISEAND
38662 \end_layout
38663
38664 \end_inset
38665 </cell>
38666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38667 \begin_inset Text
38668
38669 \begin_layout Standard
38670
38671 \size footnotesize
38672 IC_LEFT() IC_RIGHT() IC_RESULT()
38673 \end_layout
38674
38675 \end_inset
38676 </cell>
38677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38678 \begin_inset Text
38679
38680 \begin_layout Standard
38681
38682 \size footnotesize
38683 Bitwise AND 
38684 \end_layout
38685
38686 \end_inset
38687 </cell>
38688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38689 \begin_inset Text
38690
38691 \begin_layout Standard
38692
38693 \size footnotesize
38694 IC_RESULT = IC_LEFT & IC_RIGHT;
38695 \end_layout
38696
38697 \end_inset
38698 </cell>
38699 </row>
38700 <row topline="true">
38701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38702 \begin_inset Text
38703
38704 \begin_layout Standard
38705
38706 \size footnotesize
38707 LEFT_OP
38708 \end_layout
38709
38710 \end_inset
38711 </cell>
38712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38713 \begin_inset Text
38714
38715 \begin_layout Standard
38716
38717 \size footnotesize
38718 IC_LEFT() IC_RIGHT() IC_RESULT()
38719 \end_layout
38720
38721 \end_inset
38722 </cell>
38723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38724 \begin_inset Text
38725
38726 \begin_layout Standard
38727
38728 \size footnotesize
38729 Left shift 
38730 \end_layout
38731
38732 \end_inset
38733 </cell>
38734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38735 \begin_inset Text
38736
38737 \begin_layout Standard
38738
38739 \size footnotesize
38740 IC_RESULT = IC_LEFT << IC_RIGHT 
38741 \end_layout
38742
38743 \end_inset
38744 </cell>
38745 </row>
38746 <row topline="true">
38747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38748 \begin_inset Text
38749
38750 \begin_layout Standard
38751
38752 \size footnotesize
38753 RIGHT_OP
38754 \end_layout
38755
38756 \end_inset
38757 </cell>
38758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38759 \begin_inset Text
38760
38761 \begin_layout Standard
38762
38763 \size footnotesize
38764 IC_LEFT() IC_RIGHT() IC_RESULT()
38765 \end_layout
38766
38767 \end_inset
38768 </cell>
38769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38770 \begin_inset Text
38771
38772 \begin_layout Standard
38773
38774 \size footnotesize
38775 Right shift
38776 \end_layout
38777
38778 \end_inset
38779 </cell>
38780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38781 \begin_inset Text
38782
38783 \begin_layout Standard
38784
38785 \size footnotesize
38786 IC_RESULT = IC_LEFT >> IC_RIGHT 
38787 \end_layout
38788
38789 \end_inset
38790 </cell>
38791 </row>
38792 <row topline="true">
38793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38794 \begin_inset Text
38795
38796 \begin_layout Standard
38797
38798 \size footnotesize
38799 GET_VALUE_
38800 \newline
38801 AT_ ADDRESS
38802 \end_layout
38803
38804 \end_inset
38805 </cell>
38806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38807 \begin_inset Text
38808
38809 \begin_layout Standard
38810
38811 \size footnotesize
38812 IC_LEFT() IC_RESULT()
38813 \end_layout
38814
38815 \end_inset
38816 </cell>
38817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38818 \begin_inset Text
38819
38820 \begin_layout Standard
38821
38822 \size footnotesize
38823 Indirect fetch 
38824 \end_layout
38825
38826 \end_inset
38827 </cell>
38828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38829 \begin_inset Text
38830
38831 \begin_layout Standard
38832
38833 \size footnotesize
38834 IC_RESULT = (*IC_LEFT);
38835 \end_layout
38836
38837 \end_inset
38838 </cell>
38839 </row>
38840 <row topline="true">
38841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38842 \begin_inset Text
38843
38844 \begin_layout Standard
38845
38846 \size footnotesize
38847 POINTER_SET
38848 \end_layout
38849
38850 \end_inset
38851 </cell>
38852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38853 \begin_inset Text
38854
38855 \begin_layout Standard
38856
38857 \size footnotesize
38858 IC_RIGHT() IC_RESULT() 
38859 \end_layout
38860
38861 \end_inset
38862 </cell>
38863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38864 \begin_inset Text
38865
38866 \begin_layout Standard
38867
38868 \size footnotesize
38869 Indirect set
38870 \end_layout
38871
38872 \end_inset
38873 </cell>
38874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38875 \begin_inset Text
38876
38877 \begin_layout Standard
38878
38879 \size footnotesize
38880 (*IC_RESULT) = IC_RIGHT;
38881 \end_layout
38882
38883 \end_inset
38884 </cell>
38885 </row>
38886 <row topline="true">
38887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38888 \begin_inset Text
38889
38890 \begin_layout Standard
38891
38892 \size footnotesize
38893 '='
38894 \end_layout
38895
38896 \end_inset
38897 </cell>
38898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38899 \begin_inset Text
38900
38901 \begin_layout Standard
38902
38903 \size footnotesize
38904 IC_RIGHT() IC_RESULT()
38905 \end_layout
38906
38907 \end_inset
38908 </cell>
38909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38910 \begin_inset Text
38911
38912 \begin_layout Standard
38913
38914 \size footnotesize
38915 Assignment
38916 \end_layout
38917
38918 \end_inset
38919 </cell>
38920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38921 \begin_inset Text
38922
38923 \begin_layout Standard
38924
38925 \size footnotesize
38926 IC_RESULT = IC_RIGHT;
38927 \end_layout
38928
38929 \end_inset
38930 </cell>
38931 </row>
38932 <row topline="true">
38933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38934 \begin_inset Text
38935
38936 \begin_layout Standard
38937
38938 \size footnotesize
38939 IFX
38940 \end_layout
38941
38942 \end_inset
38943 </cell>
38944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38945 \begin_inset Text
38946
38947 \begin_layout Standard
38948
38949 \size footnotesize
38950 IC_COND IC_TRUE IC_LABEL
38951 \end_layout
38952
38953 \end_inset
38954 </cell>
38955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38956 \begin_inset Text
38957
38958 \begin_layout Standard
38959
38960 \size footnotesize
38961 Conditional jump.
38962  If true label is present then jump to true label if condition is true else
38963  jump to false label if condition is false 
38964 \end_layout
38965
38966 \end_inset
38967 </cell>
38968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38969 \begin_inset Text
38970
38971 \begin_layout Standard
38972
38973 \size footnotesize
38974 if (IC_COND) goto IC_TRUE; 
38975 \newline
38976 \InsetSpace ~
38977 \InsetSpace ~
38978 Or 
38979 \newline
38980 If (!IC_COND) goto IC_FALSE;
38981 \end_layout
38982
38983 \end_inset
38984 </cell>
38985 </row>
38986 <row topline="true">
38987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38988 \begin_inset Text
38989
38990 \begin_layout Standard
38991
38992 \size footnotesize
38993 ADDRESS_OF
38994 \end_layout
38995
38996 \end_inset
38997 </cell>
38998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38999 \begin_inset Text
39000
39001 \begin_layout Standard
39002
39003 \size footnotesize
39004 IC_LEFT() IC_RESULT()
39005 \end_layout
39006
39007 \end_inset
39008 </cell>
39009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39010 \begin_inset Text
39011
39012 \begin_layout Standard
39013
39014 \size footnotesize
39015 Address of 
39016 \end_layout
39017
39018 \end_inset
39019 </cell>
39020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39021 \begin_inset Text
39022
39023 \begin_layout Standard
39024
39025 \size footnotesize
39026 IC_RESULT = &IC_LEFT();
39027 \end_layout
39028
39029 \end_inset
39030 </cell>
39031 </row>
39032 <row topline="true">
39033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39034 \begin_inset Text
39035
39036 \begin_layout Standard
39037
39038 \size footnotesize
39039 JUMPTABLE
39040 \end_layout
39041
39042 \end_inset
39043 </cell>
39044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39045 \begin_inset Text
39046
39047 \begin_layout Standard
39048
39049 \size footnotesize
39050 IC_JTCOND IC_JTLABELS
39051 \end_layout
39052
39053 \end_inset
39054 </cell>
39055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39056 \begin_inset Text
39057
39058 \begin_layout Standard
39059
39060 \size footnotesize
39061 Jump to list of labels depending on the value of JTCOND
39062 \end_layout
39063
39064 \end_inset
39065 </cell>
39066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39067 \begin_inset Text
39068
39069 \begin_layout Standard
39070
39071 \size footnotesize
39072 Switch statement
39073 \end_layout
39074
39075 \end_inset
39076 </cell>
39077 </row>
39078 <row topline="true">
39079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39080 \begin_inset Text
39081
39082 \begin_layout Standard
39083
39084 \size footnotesize
39085 CAST
39086 \end_layout
39087
39088 \end_inset
39089 </cell>
39090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39091 \begin_inset Text
39092
39093 \begin_layout Standard
39094
39095 \size footnotesize
39096 IC_RIGHT() IC_LEFT() IC_RESULT()
39097 \end_layout
39098
39099 \end_inset
39100 </cell>
39101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39102 \begin_inset Text
39103
39104 \begin_layout Standard
39105
39106 \size footnotesize
39107 Cast types 
39108 \end_layout
39109
39110 \end_inset
39111 </cell>
39112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39113 \begin_inset Text
39114
39115 \begin_layout Standard
39116
39117 \size footnotesize
39118 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39119 \end_layout
39120
39121 \end_inset
39122 </cell>
39123 </row>
39124 <row topline="true">
39125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39126 \begin_inset Text
39127
39128 \begin_layout Standard
39129
39130 \size footnotesize
39131 SEND
39132 \end_layout
39133
39134 \end_inset
39135 </cell>
39136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39137 \begin_inset Text
39138
39139 \begin_layout Standard
39140
39141 \size footnotesize
39142 IC_LEFT()
39143 \end_layout
39144
39145 \end_inset
39146 </cell>
39147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39148 \begin_inset Text
39149
39150 \begin_layout Standard
39151
39152 \size footnotesize
39153 This is used for passing parameters in registers; 
39154 \newline
39155 move IC_LEFT to the next
39156  available parameter register.
39157 \end_layout
39158
39159 \end_inset
39160 </cell>
39161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39162 \begin_inset Text
39163
39164 \begin_layout Standard
39165
39166 \size footnotesize
39167 None
39168 \end_layout
39169
39170 \end_inset
39171 </cell>
39172 </row>
39173 <row topline="true">
39174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39175 \begin_inset Text
39176
39177 \begin_layout Standard
39178
39179 \size footnotesize
39180 RECV
39181 \end_layout
39182
39183 \end_inset
39184 </cell>
39185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39186 \begin_inset Text
39187
39188 \begin_layout Standard
39189
39190 \size footnotesize
39191 IC_RESULT()
39192 \end_layout
39193
39194 \end_inset
39195 </cell>
39196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39197 \begin_inset Text
39198
39199 \begin_layout Standard
39200
39201 \size footnotesize
39202 This is used for receiving parameters passed in registers;
39203 \newline
39204 Move the values
39205  in the next parameter register to IC_RESULT 
39206 \end_layout
39207
39208 \end_inset
39209 </cell>
39210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39211 \begin_inset Text
39212
39213 \begin_layout Standard
39214
39215 \size footnotesize
39216 None
39217 \end_layout
39218
39219 \end_inset
39220 </cell>
39221 </row>
39222 <row topline="true" bottomline="true">
39223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39224 \begin_inset Text
39225
39226 \begin_layout Standard
39227
39228 \shape slanted
39229 \size footnotesize
39230 (some more have been added)
39231 \end_layout
39232
39233 \end_inset
39234 </cell>
39235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39236 \begin_inset Text
39237
39238 \begin_layout Standard
39239
39240 \end_layout
39241
39242 \end_inset
39243 </cell>
39244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39245 \begin_inset Text
39246
39247 \begin_layout Standard
39248
39249 \end_layout
39250
39251 \end_inset
39252 </cell>
39253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39254 \begin_inset Text
39255
39256 \begin_layout Standard
39257
39258 \shape slanted
39259 \size footnotesize
39260 see f.e.
39261  
39262 \family typewriter
39263 gen51Code()
39264 \family default
39265  in 
39266 \family typewriter
39267 src/mcs51/gen.c
39268 \end_layout
39269
39270 \end_inset
39271 </cell>
39272 </row>
39273 </lyxtabular>
39274
39275 \end_inset
39276
39277
39278 \end_layout
39279
39280 \begin_layout Standard
39281 \begin_inset Note Note
39282 status collapsed
39283
39284 \begin_layout Standard
39285 In the original article Figure II was announced to be downloadable on 
39286 \shape italic
39287 Circuit Cellar
39288 \shape default
39289 's web site.
39290  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39291 \end_layout
39292
39293 \end_inset
39294
39295
39296 \end_layout
39297
39298 \begin_layout Paragraph*
39299 ICode Example
39300 \begin_inset LatexCommand \index{iCode}
39301
39302 \end_inset
39303
39304
39305 \end_layout
39306
39307 \begin_layout Standard
39308 This section shows some details of iCode.
39309  The example C code does not do anything useful; it is used as an example
39310  to illustrate the intermediate code generated by the compiler.
39311 \end_layout
39312
39313 \begin_layout Verse
39314
39315 \family typewriter
39316 1.\InsetSpace ~
39317 xdata int * p;
39318 \newline
39319 2.\InsetSpace ~
39320 int gint;
39321 \newline
39322 3.\InsetSpace ~
39323 /* This function does nothing useful.
39324  It is used
39325 \newline
39326 4.\InsetSpace ~
39327 \InsetSpace ~
39328 \InsetSpace ~
39329 \InsetSpace ~
39330 for the purpose of explaining iCode */
39331 \newline
39332 5.\InsetSpace ~
39333 short function (data
39334  int *x)
39335 \newline
39336 6.\InsetSpace ~
39337 {
39338 \newline
39339 7.\InsetSpace ~
39340 \InsetSpace ~
39341 \InsetSpace ~
39342 short i=10; \InsetSpace ~
39343 \InsetSpace ~
39344 /* dead initialization eliminated */
39345 \newline
39346 8.\InsetSpace ~
39347 \InsetSpace ~
39348 \InsetSpace ~
39349 short sum=10;
39350  /* dead initialization eliminated */
39351 \newline
39352 9.\InsetSpace ~
39353 \InsetSpace ~
39354 \InsetSpace ~
39355 short mul;
39356 \newline
39357 10.\InsetSpace ~
39358 \InsetSpace ~
39359 int j ;
39360 \newline
39361 11.\InsetSpace ~
39362 \InsetSpace ~
39363 while (*x) *x++
39364  = *p++; 
39365 \newline
39366 12.\InsetSpace ~
39367 \InsetSpace ~
39368 \InsetSpace ~
39369 \InsetSpace ~
39370 sum = 0 ; 
39371 \newline
39372 13.\InsetSpace ~
39373 \InsetSpace ~
39374 mul = 0;
39375 \newline
39376 14.\InsetSpace ~
39377 \InsetSpace ~
39378 /* compiler detects i,j to be induction
39379  variables */
39380 \newline
39381 15.\InsetSpace ~
39382 \InsetSpace ~
39383 for (i = 0, j = 10 ; i < 10 ; i++, j
39384 \family default
39385 -
39386 \begin_inset ERT
39387 status collapsed
39388
39389 \begin_layout Standard
39390
39391
39392 \backslash
39393 /
39394 \end_layout
39395
39396 \end_inset
39397
39398 -
39399 \family typewriter
39400 ) {
39401 \newline
39402 16.\InsetSpace ~
39403 \InsetSpace ~
39404 \InsetSpace ~
39405 \InsetSpace ~
39406 sum += i;
39407 \newline
39408 17.\InsetSpace ~
39409 \InsetSpace ~
39410 \InsetSpace ~
39411 \InsetSpace ~
39412 mul += i * 3; \InsetSpace ~
39413 \InsetSpace ~
39414 /* this multiplication remains */
39415 \newline
39416 18.\InsetSpace ~
39417 \InsetSpace ~
39418 \InsetSpace ~
39419 \InsetSpace ~
39420 gint +=
39421  j * 3;\InsetSpace ~
39422 \InsetSpace ~
39423 /* this multiplication changed to addition */
39424 \newline
39425 19.\InsetSpace ~
39426 \InsetSpace ~
39427 }
39428 \newline
39429 20.\InsetSpace ~
39430 \InsetSpace ~
39431 return sum+mul;
39432 \newline
39433 21.\InsetSpace ~
39434 }
39435 \end_layout
39436
39437 \begin_layout Standard
39438 In addition to the operands each iCode contains information about the filename
39439  and line it corresponds to in the source file.
39440  The first field in the listing should be interpreted as follows:
39441 \newline
39442
39443 \shape italic
39444 \size footnotesize
39445 Filename(linenumber: iCode Execution sequence number : ICode hash table
39446  key : loop depth of the iCode).
39447 \shape default
39448 \size default
39449
39450 \newline
39451 Then follows the human readable form of the ICode operation.
39452  Each operand of this triplet form can be of three basic types a) compiler
39453  generated temporary b) user defined variable c) a constant value.
39454  Note that local variables and parameters are replaced by compiler generated
39455  temporaries.
39456  Live ranges
39457 \begin_inset LatexCommand \index{Live range analysis}
39458
39459 \end_inset
39460
39461  are computed only for temporaries (i.e.
39462  live ranges are not computed for global variables).
39463  Registers
39464 \begin_inset LatexCommand \index{Register allocation}
39465
39466 \end_inset
39467
39468  are allocated for temporaries only.
39469  Operands are formatted in the following manner:
39470 \newline
39471
39472 \shape italic
39473 \size footnotesize
39474 Operand Name [lr live-from : live-to ] { type information } [ registers
39475  allocated ].
39476 \shape default
39477 \size default
39478
39479 \newline
39480 As mentioned earlier the live ranges are computed in terms of the execution
39481  sequence number of the iCodes, for example 
39482 \newline
39483 the iTemp0 is live from (i.e.
39484  first defined in iCode with execution sequence number 3, and is last used
39485  in the iCode with sequence number 5).
39486  For induction variables such as iTemp21 the live range computation extends
39487  the lifetime from the start to the end of the loop.
39488 \newline
39489 The register allocator
39490  used the live range information to allocate registers, the same registers
39491  may be used for different temporaries if their live ranges do not overlap,
39492  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39493  ranges do not overlap.
39494  In addition the allocator also takes into consideration the type and usage
39495  of a temporary, for example itemp6 is a pointer to near space and is used
39496  as to fetch data from (i.e.
39497  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39498  Some short lived temporaries are allocated to special registers which have
39499  meaning to the code generator e.g.
39500  iTemp13 is allocated to a pseudo register CC which tells the back end that
39501  the temporary is used only for a conditional jump the code generation makes
39502  use of this information to optimize a compare and jump ICode.
39503 \newline
39504 There are several
39505  loop optimizations
39506 \begin_inset LatexCommand \index{Loop optimization}
39507
39508 \end_inset
39509
39510  performed by the compiler.
39511  It can detect induction variables iTemp21(i) and iTemp23(j).
39512  Also note the compiler does selective strength reduction
39513 \begin_inset LatexCommand \index{Strength reduction}
39514
39515 \end_inset
39516
39517 , i.e.
39518  the multiplication of an induction variable in line 18 (gint = j * 3) is
39519  changed to addition, a new temporary iTemp17 is allocated and assigned
39520  a initial value, a constant 3 is then added for each iteration of the loop.
39521  The compiler does not change the multiplication
39522 \begin_inset LatexCommand \index{Multiplication}
39523
39524 \end_inset
39525
39526  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39527 \newline
39528
39529 Note the dead code elimination
39530 \begin_inset LatexCommand \index{Dead-code elimination}
39531
39532 \end_inset
39533
39534  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39535  respectively.
39536 \newline
39537
39538 \end_layout
39539
39540 \begin_layout Standard
39541
39542 \size footnotesize
39543 Sample.c (5:1:0:0) _entry($9) :
39544 \end_layout
39545
39546 \begin_layout Standard
39547
39548 \size footnotesize
39549 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39550 \end_layout
39551
39552 \begin_layout Standard
39553
39554 \size footnotesize
39555 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39556 \end_layout
39557
39558 \begin_layout Standard
39559
39560 \size footnotesize
39561 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39562 \end_layout
39563
39564 \begin_layout Standard
39565
39566 \size footnotesize
39567 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39568  * int}[r2]
39569 \end_layout
39570
39571 \begin_layout Standard
39572
39573 \size footnotesize
39574 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39575 \end_layout
39576
39577 \begin_layout Standard
39578
39579 \size footnotesize
39580 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39581  int}[r0]]
39582 \end_layout
39583
39584 \begin_layout Standard
39585
39586 \size footnotesize
39587 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39588 \end_layout
39589
39590 \begin_layout Standard
39591
39592 \size footnotesize
39593 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39594  * int}
39595 \end_layout
39596
39597 \begin_layout Standard
39598
39599 \size footnotesize
39600 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39601  {short}
39602 \end_layout
39603
39604 \begin_layout Standard
39605
39606 \size footnotesize
39607 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39608  * int}[DPTR]]
39609 \end_layout
39610
39611 \begin_layout Standard
39612
39613 \size footnotesize
39614 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39615 }[r2 r3]
39616 \end_layout
39617
39618 \begin_layout Standard
39619
39620 \size footnotesize
39621 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39622  * int}[r0] + 0x2 {short}
39623 \end_layout
39624
39625 \begin_layout Standard
39626
39627 \size footnotesize
39628 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39629 \end_layout
39630
39631 \begin_layout Standard
39632
39633 \size footnotesize
39634 Sample.c(11:17:21:0)_whilebreak_0($3) :
39635 \end_layout
39636
39637 \begin_layout Standard
39638
39639 \size footnotesize
39640 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39641 \end_layout
39642
39643 \begin_layout Standard
39644
39645 \size footnotesize
39646 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39647 \end_layout
39648
39649 \begin_layout Standard
39650
39651 \size footnotesize
39652 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39653 \end_layout
39654
39655 \begin_layout Standard
39656
39657 \size footnotesize
39658 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39659 \end_layout
39660
39661 \begin_layout Standard
39662
39663 \size footnotesize
39664 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39665 \end_layout
39666
39667 \begin_layout Standard
39668
39669 \size footnotesize
39670 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39671 \end_layout
39672
39673 \begin_layout Standard
39674
39675 \size footnotesize
39676 Sample.c(15:24:26:1)_forcond_0($4) :
39677 \end_layout
39678
39679 \begin_layout Standard
39680
39681 \size footnotesize
39682 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39683  < 0xa {short}
39684 \end_layout
39685
39686 \begin_layout Standard
39687
39688 \size footnotesize
39689 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39690 \end_layout
39691
39692 \begin_layout Standard
39693
39694 \size footnotesize
39695 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39696  + ITemp21 [lr21:38]{short}[r4]
39697 \end_layout
39698
39699 \begin_layout Standard
39700
39701 \size footnotesize
39702 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39703  * 0x3 {short}
39704 \end_layout
39705
39706 \begin_layout Standard
39707
39708 \size footnotesize
39709 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39710  + iTemp15 [lr29:30]{short}[r1]
39711 \end_layout
39712
39713 \begin_layout Standard
39714
39715 \size footnotesize
39716 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39717  r0]- 0x3 {short}
39718 \end_layout
39719
39720 \begin_layout Standard
39721
39722 \size footnotesize
39723 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39724 int}[r7 r0]
39725 \end_layout
39726
39727 \begin_layout Standard
39728
39729 \size footnotesize
39730 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39731  + 0x1 {short}
39732 \end_layout
39733
39734 \begin_layout Standard
39735
39736 \size footnotesize
39737 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39738  r6]- 0x1 {short}
39739 \end_layout
39740
39741 \begin_layout Standard
39742
39743 \size footnotesize
39744 Sample.c(19:38:47:1) goto _forcond_0($4)
39745 \end_layout
39746
39747 \begin_layout Standard
39748
39749 \size footnotesize
39750 Sample.c(19:39:48:0)_forbreak_0($7) :
39751 \end_layout
39752
39753 \begin_layout Standard
39754
39755 \size footnotesize
39756 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39757  + ITemp11 [lr19:40]{short}[r3]
39758 \end_layout
39759
39760 \begin_layout Standard
39761
39762 \size footnotesize
39763 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39764 \end_layout
39765
39766 \begin_layout Standard
39767
39768 \size footnotesize
39769 Sample.c(20:42:51:0)_return($8) :
39770 \end_layout
39771
39772 \begin_layout Standard
39773
39774 \size footnotesize
39775 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39776 \size default
39777
39778 \newline
39779
39780 \newline
39781 Finally the code generated for this function:
39782 \newline
39783
39784 \end_layout
39785
39786 \begin_layout Standard
39787
39788 \size footnotesize
39789 .area DSEG (DATA)
39790 \end_layout
39791
39792 \begin_layout Standard
39793
39794 \size footnotesize
39795 _p::
39796 \end_layout
39797
39798 \begin_layout Standard
39799
39800 \size footnotesize
39801 \InsetSpace ~
39802 \InsetSpace ~
39803 .ds 2
39804 \end_layout
39805
39806 \begin_layout Standard
39807
39808 \size footnotesize
39809 _gint::
39810 \end_layout
39811
39812 \begin_layout Standard
39813
39814 \size footnotesize
39815 \InsetSpace ~
39816 \InsetSpace ~
39817 .ds 2
39818 \end_layout
39819
39820 \begin_layout Standard
39821
39822 \size footnotesize
39823 ; sample.c 5
39824 \end_layout
39825
39826 \begin_layout Standard
39827
39828 \size footnotesize
39829 ; ----------------------------------------------
39830 \end_layout
39831
39832 \begin_layout Standard
39833
39834 \size footnotesize
39835 ; function function
39836 \end_layout
39837
39838 \begin_layout Standard
39839
39840 \size footnotesize
39841 ; ----------------------------------------------
39842 \end_layout
39843
39844 \begin_layout Standard
39845
39846 \size footnotesize
39847 _function:
39848 \end_layout
39849
39850 \begin_layout Standard
39851
39852 \size footnotesize
39853 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
39854 \end_layout
39855
39856 \begin_layout Standard
39857
39858 \size footnotesize
39859 \InsetSpace ~
39860 \InsetSpace ~
39861 mov r2,dpl
39862 \end_layout
39863
39864 \begin_layout Standard
39865
39866 \size footnotesize
39867 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39868 \end_layout
39869
39870 \begin_layout Standard
39871
39872 \size footnotesize
39873 \InsetSpace ~
39874 \InsetSpace ~
39875 mov ar0,r2
39876 \end_layout
39877
39878 \begin_layout Standard
39879
39880 \size footnotesize
39881 ;_whilecontinue_0($1) :
39882 \end_layout
39883
39884 \begin_layout Standard
39885
39886 \size footnotesize
39887 00101$:
39888 \end_layout
39889
39890 \begin_layout Standard
39891
39892 \size footnotesize
39893 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39894 \end_layout
39895
39896 \begin_layout Standard
39897
39898 \size footnotesize
39899 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39900 \end_layout
39901
39902 \begin_layout Standard
39903
39904 \size footnotesize
39905 \InsetSpace ~
39906 \InsetSpace ~
39907 mov ar2,@r0
39908 \end_layout
39909
39910 \begin_layout Standard
39911
39912 \size footnotesize
39913 \InsetSpace ~
39914 \InsetSpace ~
39915 inc r0
39916 \end_layout
39917
39918 \begin_layout Standard
39919
39920 \size footnotesize
39921 \InsetSpace ~
39922 \InsetSpace ~
39923 mov ar3,@r0
39924 \end_layout
39925
39926 \begin_layout Standard
39927
39928 \size footnotesize
39929 \InsetSpace ~
39930 \InsetSpace ~
39931 dec r0
39932 \end_layout
39933
39934 \begin_layout Standard
39935
39936 \size footnotesize
39937 \InsetSpace ~
39938 \InsetSpace ~
39939 mov a,r2
39940 \end_layout
39941
39942 \begin_layout Standard
39943
39944 \size footnotesize
39945 \InsetSpace ~
39946 \InsetSpace ~
39947 orl a,r3
39948 \end_layout
39949
39950 \begin_layout Standard
39951
39952 \size footnotesize
39953 \InsetSpace ~
39954 \InsetSpace ~
39955 jz 00103$
39956 \end_layout
39957
39958 \begin_layout Standard
39959
39960 \size footnotesize
39961 00114$:
39962 \end_layout
39963
39964 \begin_layout Standard
39965
39966 \size footnotesize
39967 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39968 \end_layout
39969
39970 \begin_layout Standard
39971
39972 \size footnotesize
39973 \InsetSpace ~
39974 \InsetSpace ~
39975 mov dpl,_p
39976 \end_layout
39977
39978 \begin_layout Standard
39979
39980 \size footnotesize
39981 \InsetSpace ~
39982 \InsetSpace ~
39983 mov dph,(_p + 1)
39984 \end_layout
39985
39986 \begin_layout Standard
39987
39988 \size footnotesize
39989 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39990 \end_layout
39991
39992 \begin_layout Standard
39993
39994 \size footnotesize
39995 \InsetSpace ~
39996 \InsetSpace ~
39997 mov a,#0x02
39998 \end_layout
39999
40000 \begin_layout Standard
40001
40002 \size footnotesize
40003 \InsetSpace ~
40004 \InsetSpace ~
40005 add a,_p
40006 \end_layout
40007
40008 \begin_layout Standard
40009
40010 \size footnotesize
40011 \InsetSpace ~
40012 \InsetSpace ~
40013 mov _p,a
40014 \end_layout
40015
40016 \begin_layout Standard
40017
40018 \size footnotesize
40019 \InsetSpace ~
40020 \InsetSpace ~
40021 clr a
40022 \end_layout
40023
40024 \begin_layout Standard
40025
40026 \size footnotesize
40027 \InsetSpace ~
40028 \InsetSpace ~
40029 addc a,(_p + 1)
40030 \end_layout
40031
40032 \begin_layout Standard
40033
40034 \size footnotesize
40035 \InsetSpace ~
40036 \InsetSpace ~
40037 mov (_p + 1),a
40038 \end_layout
40039
40040 \begin_layout Standard
40041
40042 \size footnotesize
40043 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40044 \end_layout
40045
40046 \begin_layout Standard
40047
40048 \size footnotesize
40049 \InsetSpace ~
40050 \InsetSpace ~
40051 movx a,@dptr
40052 \end_layout
40053
40054 \begin_layout Standard
40055
40056 \size footnotesize
40057 \InsetSpace ~
40058 \InsetSpace ~
40059 mov r2,a
40060 \end_layout
40061
40062 \begin_layout Standard
40063
40064 \size footnotesize
40065 \InsetSpace ~
40066 \InsetSpace ~
40067 inc dptr
40068 \end_layout
40069
40070 \begin_layout Standard
40071
40072 \size footnotesize
40073 \InsetSpace ~
40074 \InsetSpace ~
40075 movx a,@dptr
40076 \end_layout
40077
40078 \begin_layout Standard
40079
40080 \size footnotesize
40081 \InsetSpace ~
40082 \InsetSpace ~
40083 mov r3,a
40084 \end_layout
40085
40086 \begin_layout Standard
40087
40088 \size footnotesize
40089 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40090 \end_layout
40091
40092 \begin_layout Standard
40093
40094 \size footnotesize
40095 \InsetSpace ~
40096 \InsetSpace ~
40097 mov @r0,ar2
40098 \end_layout
40099
40100 \begin_layout Standard
40101
40102 \size footnotesize
40103 \InsetSpace ~
40104 \InsetSpace ~
40105 inc r0
40106 \end_layout
40107
40108 \begin_layout Standard
40109
40110 \size footnotesize
40111 \InsetSpace ~
40112 \InsetSpace ~
40113 mov @r0,ar3
40114 \end_layout
40115
40116 \begin_layout Standard
40117
40118 \size footnotesize
40119 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40120 \end_layout
40121
40122 \begin_layout Standard
40123
40124 \size footnotesize
40125 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40126 \end_layout
40127
40128 \begin_layout Standard
40129
40130 \size footnotesize
40131 ; 0x2 {short}
40132 \end_layout
40133
40134 \begin_layout Standard
40135
40136 \size footnotesize
40137 \InsetSpace ~
40138 \InsetSpace ~
40139 inc r0
40140 \end_layout
40141
40142 \begin_layout Standard
40143
40144 \size footnotesize
40145 ; goto _whilecontinue_0($1)
40146 \end_layout
40147
40148 \begin_layout Standard
40149
40150 \size footnotesize
40151 \InsetSpace ~
40152 \InsetSpace ~
40153 sjmp 00101$
40154 \end_layout
40155
40156 \begin_layout Standard
40157
40158 \size footnotesize
40159 ; _whilebreak_0($3) :
40160 \end_layout
40161
40162 \begin_layout Standard
40163
40164 \size footnotesize
40165 00103$:
40166 \end_layout
40167
40168 \begin_layout Standard
40169
40170 \size footnotesize
40171 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40172 \end_layout
40173
40174 \begin_layout Standard
40175
40176 \size footnotesize
40177 \InsetSpace ~
40178 \InsetSpace ~
40179 mov r2,#0x00
40180 \end_layout
40181
40182 \begin_layout Standard
40183
40184 \size footnotesize
40185 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40186 \end_layout
40187
40188 \begin_layout Standard
40189
40190 \size footnotesize
40191 \InsetSpace ~
40192 \InsetSpace ~
40193 mov r3,#0x00
40194 \end_layout
40195
40196 \begin_layout Standard
40197
40198 \size footnotesize
40199 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40200 \end_layout
40201
40202 \begin_layout Standard
40203
40204 \size footnotesize
40205 \InsetSpace ~
40206 \InsetSpace ~
40207 mov r4,#0x00
40208 \end_layout
40209
40210 \begin_layout Standard
40211
40212 \size footnotesize
40213 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40214 \end_layout
40215
40216 \begin_layout Standard
40217
40218 \size footnotesize
40219 \InsetSpace ~
40220 \InsetSpace ~
40221 mov r5,#0x0A
40222 \end_layout
40223
40224 \begin_layout Standard
40225
40226 \size footnotesize
40227 \InsetSpace ~
40228 \InsetSpace ~
40229 mov r6,#0x00
40230 \end_layout
40231
40232 \begin_layout Standard
40233
40234 \size footnotesize
40235 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40236 \end_layout
40237
40238 \begin_layout Standard
40239
40240 \size footnotesize
40241 \InsetSpace ~
40242 \InsetSpace ~
40243 mov r7,#0x1E
40244 \end_layout
40245
40246 \begin_layout Standard
40247
40248 \size footnotesize
40249 \InsetSpace ~
40250 \InsetSpace ~
40251 mov r0,#0x00
40252 \end_layout
40253
40254 \begin_layout Standard
40255
40256 \size footnotesize
40257 ; _forcond_0($4) :
40258 \end_layout
40259
40260 \begin_layout Standard
40261
40262 \size footnotesize
40263 00104$:
40264 \end_layout
40265
40266 \begin_layout Standard
40267
40268 \size footnotesize
40269 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40270 \end_layout
40271
40272 \begin_layout Standard
40273
40274 \size footnotesize
40275 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40276 \end_layout
40277
40278 \begin_layout Standard
40279
40280 \size footnotesize
40281 \InsetSpace ~
40282 \InsetSpace ~
40283 clr c
40284 \end_layout
40285
40286 \begin_layout Standard
40287
40288 \size footnotesize
40289 \InsetSpace ~
40290 \InsetSpace ~
40291 mov a,r4
40292 \end_layout
40293
40294 \begin_layout Standard
40295
40296 \size footnotesize
40297 \InsetSpace ~
40298 \InsetSpace ~
40299 xrl a,#0x80
40300 \end_layout
40301
40302 \begin_layout Standard
40303
40304 \size footnotesize
40305 \InsetSpace ~
40306 \InsetSpace ~
40307 subb a,#0x8a
40308 \end_layout
40309
40310 \begin_layout Standard
40311
40312 \size footnotesize
40313 \InsetSpace ~
40314 \InsetSpace ~
40315 jnc 00107$
40316 \end_layout
40317
40318 \begin_layout Standard
40319
40320 \size footnotesize
40321 00115$:
40322 \end_layout
40323
40324 \begin_layout Standard
40325
40326 \size footnotesize
40327 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40328 \end_layout
40329
40330 \begin_layout Standard
40331
40332 \size footnotesize
40333 ; iTemp21 [lr21:38]{short}[r4]
40334 \end_layout
40335
40336 \begin_layout Standard
40337
40338 \size footnotesize
40339 \InsetSpace ~
40340 \InsetSpace ~
40341 mov a,r4
40342 \end_layout
40343
40344 \begin_layout Standard
40345
40346 \size footnotesize
40347 \InsetSpace ~
40348 \InsetSpace ~
40349 add a,r2
40350 \end_layout
40351
40352 \begin_layout Standard
40353
40354 \size footnotesize
40355 \InsetSpace ~
40356 \InsetSpace ~
40357 mov r2,a
40358 \end_layout
40359
40360 \begin_layout Standard
40361
40362 \size footnotesize
40363 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40364 \end_layout
40365
40366 \begin_layout Standard
40367
40368 \size footnotesize
40369 \InsetSpace ~
40370 \InsetSpace ~
40371 mov b,#0x03
40372 \end_layout
40373
40374 \begin_layout Standard
40375
40376 \size footnotesize
40377 \InsetSpace ~
40378 \InsetSpace ~
40379 mov a,r4
40380 \end_layout
40381
40382 \begin_layout Standard
40383
40384 \size footnotesize
40385 \InsetSpace ~
40386 \InsetSpace ~
40387 mul ab
40388 \end_layout
40389
40390 \begin_layout Standard
40391
40392 \size footnotesize
40393 \InsetSpace ~
40394 \InsetSpace ~
40395 mov r1,a
40396 \end_layout
40397
40398 \begin_layout Standard
40399
40400 \size footnotesize
40401 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40402 \end_layout
40403
40404 \begin_layout Standard
40405
40406 \size footnotesize
40407 ; iTemp15 [lr29:30]{short}[r1]
40408 \end_layout
40409
40410 \begin_layout Standard
40411
40412 \size footnotesize
40413 \InsetSpace ~
40414 \InsetSpace ~
40415 add a,r3
40416 \end_layout
40417
40418 \begin_layout Standard
40419
40420 \size footnotesize
40421 \InsetSpace ~
40422 \InsetSpace ~
40423 mov r3,a
40424 \end_layout
40425
40426 \begin_layout Standard
40427
40428 \size footnotesize
40429 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40430 \end_layout
40431
40432 \begin_layout Standard
40433
40434 \size footnotesize
40435 \InsetSpace ~
40436 \InsetSpace ~
40437 mov a,r7
40438 \end_layout
40439
40440 \begin_layout Standard
40441
40442 \size footnotesize
40443 \InsetSpace ~
40444 \InsetSpace ~
40445 add a,#0xfd
40446 \end_layout
40447
40448 \begin_layout Standard
40449
40450 \size footnotesize
40451 \InsetSpace ~
40452 \InsetSpace ~
40453 mov r7,a
40454 \end_layout
40455
40456 \begin_layout Standard
40457
40458 \size footnotesize
40459 \InsetSpace ~
40460 \InsetSpace ~
40461 mov a,r0
40462 \end_layout
40463
40464 \begin_layout Standard
40465
40466 \size footnotesize
40467 \InsetSpace ~
40468 \InsetSpace ~
40469 addc a,#0xff
40470 \end_layout
40471
40472 \begin_layout Standard
40473
40474 \size footnotesize
40475 \InsetSpace ~
40476 \InsetSpace ~
40477 mov r0,a
40478 \end_layout
40479
40480 \begin_layout Standard
40481
40482 \size footnotesize
40483 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40484 \end_layout
40485
40486 \begin_layout Standard
40487
40488 \size footnotesize
40489 \InsetSpace ~
40490 \InsetSpace ~
40491 mov a,r7
40492 \end_layout
40493
40494 \begin_layout Standard
40495
40496 \size footnotesize
40497 \InsetSpace ~
40498 \InsetSpace ~
40499 add a,_gint
40500 \end_layout
40501
40502 \begin_layout Standard
40503
40504 \size footnotesize
40505 \InsetSpace ~
40506 \InsetSpace ~
40507 mov _gint,a
40508 \end_layout
40509
40510 \begin_layout Standard
40511
40512 \size footnotesize
40513 \InsetSpace ~
40514 \InsetSpace ~
40515 mov a,r0
40516 \end_layout
40517
40518 \begin_layout Standard
40519
40520 \size footnotesize
40521 \InsetSpace ~
40522 \InsetSpace ~
40523 addc a,(_gint + 1)
40524 \end_layout
40525
40526 \begin_layout Standard
40527
40528 \size footnotesize
40529 \InsetSpace ~
40530 \InsetSpace ~
40531 mov (_gint + 1),a
40532 \end_layout
40533
40534 \begin_layout Standard
40535
40536 \size footnotesize
40537 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40538 \end_layout
40539
40540 \begin_layout Standard
40541
40542 \size footnotesize
40543 \InsetSpace ~
40544 \InsetSpace ~
40545 inc r4
40546 \end_layout
40547
40548 \begin_layout Standard
40549
40550 \size footnotesize
40551 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40552 \end_layout
40553
40554 \begin_layout Standard
40555
40556 \size footnotesize
40557 \InsetSpace ~
40558 \InsetSpace ~
40559 dec r5
40560 \end_layout
40561
40562 \begin_layout Standard
40563
40564 \size footnotesize
40565 \InsetSpace ~
40566 \InsetSpace ~
40567 cjne r5,#0xff,00104$
40568 \end_layout
40569
40570 \begin_layout Standard
40571
40572 \size footnotesize
40573 \InsetSpace ~
40574 \InsetSpace ~
40575 dec r6
40576 \end_layout
40577
40578 \begin_layout Standard
40579
40580 \size footnotesize
40581 ; goto _forcond_0($4)
40582 \end_layout
40583
40584 \begin_layout Standard
40585
40586 \size footnotesize
40587 \InsetSpace ~
40588 \InsetSpace ~
40589 sjmp 00104$
40590 \end_layout
40591
40592 \begin_layout Standard
40593
40594 \size footnotesize
40595 ; _forbreak_0($7) :
40596 \end_layout
40597
40598 \begin_layout Standard
40599
40600 \size footnotesize
40601 00107$:
40602 \end_layout
40603
40604 \begin_layout Standard
40605
40606 \size footnotesize
40607 ; ret iTemp24 [lr40:41]{short}
40608 \end_layout
40609
40610 \begin_layout Standard
40611
40612 \size footnotesize
40613 \InsetSpace ~
40614 \InsetSpace ~
40615 mov a,r3
40616 \end_layout
40617
40618 \begin_layout Standard
40619
40620 \size footnotesize
40621 \InsetSpace ~
40622 \InsetSpace ~
40623 add a,r2
40624 \end_layout
40625
40626 \begin_layout Standard
40627
40628 \size footnotesize
40629 \InsetSpace ~
40630 \InsetSpace ~
40631 mov dpl,a
40632 \end_layout
40633
40634 \begin_layout Standard
40635
40636 \size footnotesize
40637 ; _return($8) :
40638 \end_layout
40639
40640 \begin_layout Standard
40641
40642 \size footnotesize
40643 00108$:
40644 \end_layout
40645
40646 \begin_layout Standard
40647
40648 \size footnotesize
40649 \InsetSpace ~
40650 \InsetSpace ~
40651 ret
40652 \newline
40653
40654 \end_layout
40655
40656 \begin_layout Section
40657 A few words about basic block successors, predecessors and dominators
40658 \end_layout
40659
40660 \begin_layout Standard
40661 Successors are basic blocks
40662 \begin_inset LatexCommand \index{Basic blocks}
40663
40664 \end_inset
40665
40666  that might execute after this basic block.
40667 \newline
40668 Predecessors are basic blocks
40669  that might execute before reaching this basic block.
40670 \newline
40671 Dominators are basic
40672  blocks that WILL execute before reaching this basic block.
40673 \newline
40674
40675 \end_layout
40676
40677 \begin_layout Standard
40678 [basic block 1]
40679 \end_layout
40680
40681 \begin_layout Standard
40682 if (something)
40683 \end_layout
40684
40685 \begin_layout Standard
40686 \InsetSpace ~
40687 \InsetSpace ~
40688 \InsetSpace ~
40689 \InsetSpace ~
40690 [basic block 2]
40691 \end_layout
40692
40693 \begin_layout Standard
40694 else
40695 \end_layout
40696
40697 \begin_layout Standard
40698 \InsetSpace ~
40699 \InsetSpace ~
40700 \InsetSpace ~
40701 \InsetSpace ~
40702 [basic block 3]
40703 \end_layout
40704
40705 \begin_layout Standard
40706 [basic block 4]
40707 \newline
40708
40709 \end_layout
40710
40711 \begin_layout Standard
40712 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40713 \end_layout
40714
40715 \begin_layout Standard
40716 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40717 \end_layout
40718
40719 \begin_layout Standard
40720 c) domVect of [BB4] = BB1 ...
40721  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40722  was executed.
40723 \end_layout
40724
40725 \begin_layout Chapter
40726 Acknowledgments
40727 \end_layout
40728
40729 \begin_layout Standard
40730 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40731
40732 \end_inset
40733
40734
40735 \newline
40736
40737 \newline
40738
40739 \emph on
40740 Thanks to all the other volunteer developers who have helped with coding,
40741  testing, web-page creation, distribution sets, etc.
40742  You know who you are :-)
40743 \emph default
40744
40745 \newline
40746
40747 \newline
40748
40749 \emph on
40750 Thanks to Sourceforge 
40751 \begin_inset LatexCommand \url{http://www.sf.net}
40752
40753 \end_inset
40754
40755  which has hosted the project since 1999 and donates significant download
40756  bandwidth.
40757 \emph default
40758
40759 \newline
40760
40761 \newline
40762
40763 \emph on
40764 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40765  cycles and bandwidth for snapshot builds.
40766 \newline
40767
40768 \end_layout
40769
40770 \begin_layout Standard
40771 This document was initially written by Sandeep Dutta
40772 \end_layout
40773
40774 \begin_layout Standard
40775 All product names mentioned herein may be trademarks
40776 \begin_inset LatexCommand \index{Trademarks}
40777
40778 \end_inset
40779
40780  of their respective companies.
40781  
40782 \end_layout
40783
40784 \begin_layout Section*
40785 Alphabetical index
40786 \end_layout
40787
40788 \begin_layout Standard
40789 To avoid confusion, the installation and building options for SDCC itself
40790  (chapter 2) are not part of the index.
40791 \end_layout
40792
40793 \begin_layout Standard
40794 \begin_inset LatexCommand \printindex{}
40795
40796 \end_inset
40797
40798
40799 \end_layout
40800
40801 \end_body
40802 \end_document