sdcc:
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.4 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.6.5
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 --short-is-8b
840 its commandline option (see 
841 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
842
843 \end_inset
844
845 ).
846 \end_layout
847
848 \begin_layout Itemize
849 the default directory for gcc-builds where include, library and documentation
850  files are stored is now in /usr/local/share.
851 \end_layout
852
853 \begin_layout Itemize
854 char type parameters to vararg
855 \begin_inset LatexCommand \index{vararg, va\_arg}
856
857 \end_inset
858
859  functions are casted to int unless explicitly casted
860 \begin_inset Marginal
861 status collapsed
862
863 \begin_layout Standard
864
865 \series bold
866 \InsetSpace ~
867 !
868 \end_layout
869
870 \end_inset
871
872 , e.g.: 
873 \newline
874
875 \family typewriter
876 \InsetSpace ~
877 \InsetSpace ~
878 char a=3;
879 \newline
880 \InsetSpace ~
881 \InsetSpace ~
882 printf ("%d %c
883 \backslash
884 n", a, (char)a);
885 \family default
886
887 \newline
888  will push a as an int and as a char resp.
889 \end_layout
890
891 \begin_layout Itemize
892 option -
893 \begin_inset ERT
894 status collapsed
895
896 \begin_layout Standard
897
898
899 \backslash
900 /
901 \end_layout
902
903 \end_inset
904
905 -regextend has been removed.
906 \end_layout
907
908 \begin_layout Itemize
909 option -
910 \begin_inset ERT
911 status collapsed
912
913 \begin_layout Standard
914
915
916 \backslash
917 /
918 \end_layout
919
920 \end_inset
921
922 -noregparms has been removed.
923 \end_layout
924
925 \begin_layout Itemize
926 option -
927 \begin_inset ERT
928 status collapsed
929
930 \begin_layout Standard
931
932
933 \backslash
934 /
935 \end_layout
936
937 \end_inset
938
939 -stack-after-data has been removed.
940 \end_layout
941
942 \begin_layout Itemize
943 bit
944 \begin_inset LatexCommand \index{bit}
945
946 \end_inset
947
948  and sbit
949 \begin_inset LatexCommand \index{sbit}
950
951 \end_inset
952
953
954 \begin_inset LatexCommand \index{\_\_sbit}
955
956 \end_inset
957
958  types now consistently behave like the C99 _Bool type with respect to type
959  conversion
960 \begin_inset LatexCommand \index{type conversion}
961
962 \end_inset
963
964
965 \begin_inset LatexCommand \index{type promotion}
966
967 \end_inset
968
969 .
970  The most common incompatibility resulting from this change is related to
971  bit toggling
972 \begin_inset LatexCommand \index{Bit toggling}
973
974 \end_inset
975
976  idioms, e.g.:
977 \newline
978
979 \family typewriter
980 \InsetSpace ~
981 \InsetSpace ~
982 bit b;
983 \newline
984 \InsetSpace ~
985 \InsetSpace ~
986 b = ~
987 \begin_inset LatexCommand \index{\~\/ Operator}
988
989 \end_inset
990
991 b; /* equivalent to b=1 instead of toggling b */
992 \begin_inset Marginal
993 status collapsed
994
995 \begin_layout Standard
996
997 \series bold
998 \InsetSpace ~
999 !
1000 \end_layout
1001
1002 \end_inset
1003
1004
1005 \newline
1006 \InsetSpace ~
1007 \InsetSpace ~
1008 b = !b; /* toggles b */
1009 \newline
1010
1011 \family default
1012 In previous versions, both forms would have toggled the bit.
1013 \end_layout
1014
1015 \begin_layout Standard
1016
1017 \emph on
1018 <pending: more incompatibilities?>
1019 \end_layout
1020
1021 \begin_layout Section
1022 System Requirements
1023 \end_layout
1024
1025 \begin_layout Standard
1026 What do you need before you start installation of SDCC? A computer, and
1027  a desire to compute.
1028  The preferred method of installation is to compile SDCC from source using
1029  GNU gcc and make.
1030  For Windows some pre-compiled binary distributions are available for your
1031  convenience.
1032  You should have some experience with command line tools and compiler use.
1033 \end_layout
1034
1035 \begin_layout Section
1036 Other Resources
1037 \end_layout
1038
1039 \begin_layout Standard
1040 The SDCC home page at 
1041 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1042
1043 \end_inset
1044
1045  is a great place to find distribution sets.
1046  You can also find links to the user mailing lists that offer help or discuss
1047  SDCC with other SDCC users.
1048  Web links to other SDCC related sites can also be found here.
1049  This document can be found in the DOC directory of the source package as
1050  a text or HTML file.
1051  A pdf version of this document is available at 
1052 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1053
1054 \end_inset
1055
1056 .
1057  Some of the other tools (simulator and assembler) included with SDCC contain
1058  their own documentation and can be found in the source distribution.
1059  If you want the latest unreleased software, the complete source package
1060  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1061 sdcc/trunk/sdcc.
1062 \end_layout
1063
1064 \begin_layout Section
1065 Wishes for the future
1066 \end_layout
1067
1068 \begin_layout Standard
1069 There are (and always will be) some things that could be done.
1070  Here are some I can think of:
1071 \newline
1072
1073 \end_layout
1074
1075 \begin_layout Standard
1076
1077 \family typewriter
1078 char KernelFunction3(char p) at 0x340;
1079 \newline
1080
1081 \end_layout
1082
1083 \begin_layout Standard
1084
1085 \family typewriter
1086 better code banking
1087 \begin_inset LatexCommand \index{code banking (limited support)}
1088
1089 \end_inset
1090
1091  support for mcs51
1092 \newline
1093
1094 \newline
1095
1096 \family default
1097 If you can think of some more, please see the section 
1098 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1099
1100 \end_inset
1101
1102  about filing feature requests
1103 \begin_inset LatexCommand \index{Requesting features}
1104
1105 \end_inset
1106
1107
1108 \begin_inset LatexCommand \index{Feature request}
1109
1110 \end_inset
1111
1112 .
1113 \newline
1114
1115 \end_layout
1116
1117 \begin_layout Chapter
1118 Installing SDCC
1119 \begin_inset LatexCommand \index{Installation}
1120
1121 \end_inset
1122
1123
1124 \end_layout
1125
1126 \begin_layout Standard
1127 For most users it is sufficient to skip to either section 
1128 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1129
1130 \end_inset
1131
1132  (Unix) or section 
1133 \begin_inset LatexCommand \ref{sub:Windows-Install}
1134
1135 \end_inset
1136
1137  (Windows).
1138  More detailed instructions follow below.
1139 \end_layout
1140
1141 \begin_layout Section
1142 Configure Options
1143 \begin_inset LatexCommand \index{Options SDCC configuration}
1144
1145 \end_inset
1146
1147
1148 \end_layout
1149
1150 \begin_layout Standard
1151 The install paths, search paths and other options are defined when running
1152  'configure'.
1153  The defaults can be overridden by:
1154 \end_layout
1155
1156 \begin_layout List
1157 \labelwidthstring 00.00.0000
1158 -
1159 \begin_inset ERT
1160 status collapsed
1161
1162 \begin_layout Standard
1163
1164
1165 \backslash
1166 /
1167 \end_layout
1168
1169 \end_inset
1170
1171 -prefix see table below
1172 \end_layout
1173
1174 \begin_layout List
1175 \labelwidthstring 00.00.0000
1176 -
1177 \begin_inset ERT
1178 status collapsed
1179
1180 \begin_layout Standard
1181
1182
1183 \backslash
1184 /
1185 \end_layout
1186
1187 \end_inset
1188
1189 -exec_prefix see table below
1190 \end_layout
1191
1192 \begin_layout List
1193 \labelwidthstring 00.00.0000
1194 -
1195 \begin_inset ERT
1196 status collapsed
1197
1198 \begin_layout Standard
1199
1200
1201 \backslash
1202 /
1203 \end_layout
1204
1205 \end_inset
1206
1207 -bindir see table below
1208 \end_layout
1209
1210 \begin_layout List
1211 \labelwidthstring 00.00.0000
1212 -
1213 \begin_inset ERT
1214 status collapsed
1215
1216 \begin_layout Standard
1217
1218
1219 \backslash
1220 /
1221 \end_layout
1222
1223 \end_inset
1224
1225 -datadir see table below
1226 \end_layout
1227
1228 \begin_layout List
1229 \labelwidthstring 00.00.0000
1230 -
1231 \begin_inset ERT
1232 status collapsed
1233
1234 \begin_layout Standard
1235
1236
1237 \backslash
1238 /
1239 \end_layout
1240
1241 \end_inset
1242
1243 -datarootdir see table below
1244 \newline
1245
1246 \end_layout
1247
1248 \begin_layout List
1249 \labelwidthstring 00.00.0000
1250 \InsetSpace ~
1251 \InsetSpace ~
1252 docdir environment variable, see table below
1253 \end_layout
1254
1255 \begin_layout List
1256 \labelwidthstring 00.00.0000
1257 \InsetSpace ~
1258 \InsetSpace ~
1259 include_dir_suffix environment variable, see table below
1260 \end_layout
1261
1262 \begin_layout List
1263 \labelwidthstring 00.00.0000
1264 \InsetSpace ~
1265 \InsetSpace ~
1266 lib_dir_suffix environment variable, see table below
1267 \end_layout
1268
1269 \begin_layout List
1270 \labelwidthstring 00.00.0000
1271 \InsetSpace ~
1272 \InsetSpace ~
1273 sdccconf_h_dir_separator environment variable, either / or 
1274 \backslash
1275
1276 \backslash
1277  makes sense here.
1278  This character will only be used in sdccconf.h; don't forget it's a C-header,
1279  therefore a double-backslash is needed there.
1280 \newline
1281
1282 \end_layout
1283
1284 \begin_layout List
1285 \labelwidthstring 00.00.0000
1286 -
1287 \begin_inset ERT
1288 status collapsed
1289
1290 \begin_layout Standard
1291
1292
1293 \backslash
1294 /
1295 \end_layout
1296
1297 \end_inset
1298
1299 -disable-mcs51-port Excludes the Intel mcs51 port
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 -disable-gbz80-port Excludes the Gameboy gbz80 port
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 -disable-z80-port Excludes the z80 port
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 -disable-avr-port Excludes the AVR port
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 -disable-ds390-port Excludes the DS390 port
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 -disable-hc08-port Excludes the HC08 port
1390 \end_layout
1391
1392 \begin_layout List
1393 \labelwidthstring 00.00.0000
1394 -
1395 \begin_inset ERT
1396 status collapsed
1397
1398 \begin_layout Standard
1399
1400
1401 \backslash
1402 /
1403 \end_layout
1404
1405 \end_inset
1406
1407 -disable-pic-port Excludes the PIC port
1408 \end_layout
1409
1410 \begin_layout List
1411 \labelwidthstring 00.00.0000
1412 -
1413 \begin_inset ERT
1414 status collapsed
1415
1416 \begin_layout Standard
1417
1418
1419 \backslash
1420 /
1421 \end_layout
1422
1423 \end_inset
1424
1425 -disable-xa51-port Excludes the XA51 port
1426 \end_layout
1427
1428 \begin_layout List
1429 \labelwidthstring 00.00.0000
1430 -
1431 \begin_inset ERT
1432 status collapsed
1433
1434 \begin_layout Standard
1435
1436
1437 \backslash
1438 /
1439 \end_layout
1440
1441 \end_inset
1442
1443 -disable-ucsim Disables configuring and building of ucsim
1444 \end_layout
1445
1446 \begin_layout List
1447 \labelwidthstring 00.00.0000
1448 -
1449 \begin_inset ERT
1450 status collapsed
1451
1452 \begin_layout Standard
1453
1454
1455 \backslash
1456 /
1457 \end_layout
1458
1459 \end_inset
1460
1461 -disable-device-lib Disables automatically building device libraries
1462 \end_layout
1463
1464 \begin_layout List
1465 \labelwidthstring 00.00.0000
1466 -
1467 \begin_inset ERT
1468 status collapsed
1469
1470 \begin_layout Standard
1471
1472
1473 \backslash
1474 /
1475 \end_layout
1476
1477 \end_inset
1478
1479 -disable-packihx Disables building packihx
1480 \newline
1481
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 -enable-doc Build pdf, html and txt files from the lyx sources
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 -enable-libgc Use the Bohem memory allocator.
1518  Lower runtime footprint.
1519 \end_layout
1520
1521 \begin_layout Standard
1522 Furthermore the environment variables CC, CFLAGS, ...
1523  the tools and their arguments can be influenced.
1524  Please see `configure -
1525 \begin_inset ERT
1526 status collapsed
1527
1528 \begin_layout Standard
1529
1530
1531 \backslash
1532 /
1533 \end_layout
1534
1535 \end_inset
1536
1537 -help` and the man/info pages of `configure` for details.
1538 \newline
1539
1540 \newline
1541 The names of the
1542  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1543 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1544  SDCC_LIB_NAME are defined by `configure` too.
1545  At the moment it's not possible to change the default settings (it was
1546  simply never required).
1547 \newline
1548
1549 \newline
1550 These configure options are compiled into the binaries,
1551  and can only be changed by rerunning 'configure' and recompiling SDCC.
1552  The configure options are written in 
1553 \emph on
1554 italics
1555 \emph default
1556  to distinguish them from run time environment variables (see section search
1557  paths).
1558 \newline
1559
1560 \newline
1561 The settings for 
1562 \begin_inset Quotes sld
1563 \end_inset
1564
1565 Win32 builds
1566 \begin_inset Quotes srd
1567 \end_inset
1568
1569  are used by the SDCC team to build the official Win32 binaries.
1570  The SDCC team uses Mingw32 to build the official Windows binaries, because
1571  it's
1572 \end_layout
1573
1574 \begin_layout Enumerate
1575 open source, 
1576 \end_layout
1577
1578 \begin_layout Enumerate
1579 a gcc compiler and last but not least
1580 \end_layout
1581
1582 \begin_layout Enumerate
1583 the binaries can be built by cross compiling on SDCC Distributed Compile
1584  Farm.
1585 \end_layout
1586
1587 \begin_layout Standard
1588 See the examples, how to pass the Win32 settings to 'configure'.
1589  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1590  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1591  for Win32.
1592 \newline
1593
1594 \newline
1595 These defaults are:
1596 \newline
1597
1598 \end_layout
1599
1600 \begin_layout Standard
1601 \align center
1602 \begin_inset Tabular
1603 <lyxtabular version="3" rows="9" columns="3">
1604 <features>
1605 <column alignment="block" valignment="top" leftline="true" width="0in">
1606 <column alignment="block" valignment="top" leftline="true" width="0in">
1607 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1608 <row topline="true" bottomline="true">
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1610 \begin_inset Text
1611
1612 \begin_layout Standard
1613 Variable
1614 \end_layout
1615
1616 \end_inset
1617 </cell>
1618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1619 \begin_inset Text
1620
1621 \begin_layout Standard
1622 default
1623 \end_layout
1624
1625 \end_inset
1626 </cell>
1627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1628 \begin_inset Text
1629
1630 \begin_layout Standard
1631 Win32 builds
1632 \end_layout
1633
1634 \end_inset
1635 </cell>
1636 </row>
1637 <row topline="true">
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1639 \begin_inset Text
1640
1641 \begin_layout Standard
1642
1643 \emph on
1644 PREFIX
1645 \end_layout
1646
1647 \end_inset
1648 </cell>
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1650 \begin_inset Text
1651
1652 \begin_layout Standard
1653 /usr/local
1654 \end_layout
1655
1656 \end_inset
1657 </cell>
1658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1659 \begin_inset Text
1660
1661 \begin_layout Standard
1662
1663 \backslash
1664 sdcc
1665 \end_layout
1666
1667 \end_inset
1668 </cell>
1669 </row>
1670 <row topline="true">
1671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1672 \begin_inset Text
1673
1674 \begin_layout Standard
1675
1676 \emph on
1677 EXEC_PREFIX
1678 \end_layout
1679
1680 \end_inset
1681 </cell>
1682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1683 \begin_inset Text
1684
1685 \begin_layout Standard
1686
1687 \emph on
1688 $PREFIX
1689 \end_layout
1690
1691 \end_inset
1692 </cell>
1693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1694 \begin_inset Text
1695
1696 \begin_layout Standard
1697
1698 \emph on
1699 $PREFIX
1700 \end_layout
1701
1702 \end_inset
1703 </cell>
1704 </row>
1705 <row topline="true">
1706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1707 \begin_inset Text
1708
1709 \begin_layout Standard
1710
1711 \emph on
1712 BINDIR
1713 \end_layout
1714
1715 \end_inset
1716 </cell>
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1718 \begin_inset Text
1719
1720 \begin_layout Standard
1721
1722 \emph on
1723 $EXEC_PREFIX
1724 \emph default
1725 /bin
1726 \end_layout
1727
1728 \end_inset
1729 </cell>
1730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1731 \begin_inset Text
1732
1733 \begin_layout Standard
1734
1735 \emph on
1736 $EXEC_PREFIX
1737 \emph default
1738
1739 \backslash
1740 bin
1741 \end_layout
1742
1743 \end_inset
1744 </cell>
1745 </row>
1746 <row topline="true">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 \begin_inset Text
1749
1750 \begin_layout Standard
1751
1752 \emph on
1753 DATADIR
1754 \end_layout
1755
1756 \end_inset
1757 </cell>
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 \begin_inset Text
1760
1761 \begin_layout Standard
1762
1763 \emph on
1764 $DATAROOTDIR
1765 \end_layout
1766
1767 \end_inset
1768 </cell>
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1770 \begin_inset Text
1771
1772 \begin_layout Standard
1773
1774 \emph on
1775 $DATAROOTDIR
1776 \end_layout
1777
1778 \end_inset
1779 </cell>
1780 </row>
1781 <row topline="true">
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786
1787 \emph on
1788 DATAROOTDIR
1789 \end_layout
1790
1791 \end_inset
1792 </cell>
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 \begin_inset Text
1795
1796 \begin_layout Standard
1797
1798 \emph on
1799 $PREFIX
1800 \emph default
1801 /share
1802 \end_layout
1803
1804 \end_inset
1805 </cell>
1806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1807 \begin_inset Text
1808
1809 \begin_layout Standard
1810
1811 \emph on
1812 $PREFIX
1813 \end_layout
1814
1815 \end_inset
1816 </cell>
1817 </row>
1818 <row topline="true">
1819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1820 \begin_inset Text
1821
1822 \begin_layout Standard
1823
1824 \emph on
1825 DOCDIR
1826 \end_layout
1827
1828 \end_inset
1829 </cell>
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1831 \begin_inset Text
1832
1833 \begin_layout Standard
1834
1835 \emph on
1836 $DATAROOTDIR
1837 \emph default
1838 /sdcc/doc
1839 \end_layout
1840
1841 \end_inset
1842 </cell>
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1844 \begin_inset Text
1845
1846 \begin_layout Standard
1847
1848 \emph on
1849 $DATAROOTDIR
1850 \emph default
1851
1852 \backslash
1853 doc
1854 \end_layout
1855
1856 \end_inset
1857 </cell>
1858 </row>
1859 <row topline="true">
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1861 \begin_inset Text
1862
1863 \begin_layout Standard
1864
1865 \emph on
1866 INCLUDE_DIR_SUFFIX
1867 \end_layout
1868
1869 \end_inset
1870 </cell>
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1872 \begin_inset Text
1873
1874 \begin_layout Standard
1875 sdcc/include
1876 \end_layout
1877
1878 \end_inset
1879 </cell>
1880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1881 \begin_inset Text
1882
1883 \begin_layout Standard
1884 include
1885 \end_layout
1886
1887 \end_inset
1888 </cell>
1889 </row>
1890 <row topline="true" bottomline="true">
1891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1892 \begin_inset Text
1893
1894 \begin_layout Standard
1895
1896 \emph on
1897 LIB_DIR_SUFFIX
1898 \end_layout
1899
1900 \end_inset
1901 </cell>
1902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1903 \begin_inset Text
1904
1905 \begin_layout Standard
1906 sdcc/lib
1907 \end_layout
1908
1909 \end_inset
1910 </cell>
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915 lib
1916 \end_layout
1917
1918 \end_inset
1919 </cell>
1920 </row>
1921 </lyxtabular>
1922
1923 \end_inset
1924
1925
1926 \newline
1927
1928 \end_layout
1929
1930 \begin_layout Standard
1931 \noindent
1932 'configure' also computes relative paths.
1933  This is needed for full relocatability of a binary package and to complete
1934  search paths (see section search paths below):
1935 \newline
1936  
1937 \end_layout
1938
1939 \begin_layout Standard
1940 \align center
1941 \begin_inset Tabular
1942 <lyxtabular version="3" rows="4" columns="3">
1943 <features>
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" width="0in">
1946 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1947 <row topline="true" bottomline="true">
1948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1949 \begin_inset Text
1950
1951 \begin_layout Standard
1952 Variable (computed)
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 default
1962 \end_layout
1963
1964 \end_inset
1965 </cell>
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1967 \begin_inset Text
1968
1969 \begin_layout Standard
1970 Win32 builds
1971 \end_layout
1972
1973 \end_inset
1974 </cell>
1975 </row>
1976 <row topline="true" bottomline="true">
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1978 \begin_inset Text
1979
1980 \begin_layout Standard
1981
1982 \emph on
1983 BIN2DATA_DIR
1984 \end_layout
1985
1986 \end_inset
1987 </cell>
1988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1989 \begin_inset Text
1990
1991 \begin_layout Standard
1992 ../share
1993 \end_layout
1994
1995 \end_inset
1996 </cell>
1997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1998 \begin_inset Text
1999
2000 \begin_layout Standard
2001 ..
2002 \end_layout
2003
2004 \end_inset
2005 </cell>
2006 </row>
2007 <row bottomline="true">
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2009 \begin_inset Text
2010
2011 \begin_layout Standard
2012
2013 \emph on
2014 PREFIX2BIN_DIR
2015 \end_layout
2016
2017 \end_inset
2018 </cell>
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2020 \begin_inset Text
2021
2022 \begin_layout Standard
2023 bin
2024 \end_layout
2025
2026 \end_inset
2027 </cell>
2028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2029 \begin_inset Text
2030
2031 \begin_layout Standard
2032 bin
2033 \end_layout
2034
2035 \end_inset
2036 </cell>
2037 </row>
2038 <row bottomline="true">
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2040 \begin_inset Text
2041
2042 \begin_layout Standard
2043
2044 \emph on
2045 PREFIX2DATA_DIR
2046 \end_layout
2047
2048 \end_inset
2049 </cell>
2050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2051 \begin_inset Text
2052
2053 \begin_layout Standard
2054 share/sdcc
2055 \end_layout
2056
2057 \end_inset
2058 </cell>
2059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2060 \begin_inset Text
2061
2062 \begin_layout Standard
2063
2064 \end_layout
2065
2066 \end_inset
2067 </cell>
2068 </row>
2069 </lyxtabular>
2070
2071 \end_inset
2072
2073
2074 \newline
2075
2076 \end_layout
2077
2078 \begin_layout Standard
2079 \noindent
2080 Examples:
2081 \end_layout
2082
2083 \begin_layout LyX-Code
2084 ./configure
2085 \newline
2086 ./configure -
2087 \begin_inset ERT
2088 status collapsed
2089
2090 \begin_layout Standard
2091
2092
2093 \backslash
2094 /
2095 \end_layout
2096
2097 \end_inset
2098
2099 -prefix=
2100 \begin_inset Quotes srd
2101 \end_inset
2102
2103 /usr/bin
2104 \begin_inset Quotes srd
2105 \end_inset
2106
2107  -
2108 \begin_inset ERT
2109 status collapsed
2110
2111 \begin_layout Standard
2112
2113
2114 \backslash
2115 /
2116 \end_layout
2117
2118 \end_inset
2119
2120 -datarootdir=
2121 \begin_inset Quotes srd
2122 \end_inset
2123
2124 /usr/share
2125 \begin_inset Quotes srd
2126 \end_inset
2127
2128
2129 \newline
2130 ./configure -
2131 \begin_inset ERT
2132 status collapsed
2133
2134 \begin_layout Standard
2135
2136
2137 \backslash
2138 /
2139 \end_layout
2140
2141 \end_inset
2142
2143 -disable-avr-port -
2144 \begin_inset ERT
2145 status collapsed
2146
2147 \begin_layout Standard
2148
2149
2150 \backslash
2151 /
2152 \end_layout
2153
2154 \end_inset
2155
2156 -disable-xa51-port
2157 \end_layout
2158
2159 \begin_layout Standard
2160 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2161 32'):
2162 \end_layout
2163
2164 \begin_layout LyX-Code
2165 ./configure 
2166 \backslash
2167
2168 \newline
2169 CC=
2170 \begin_inset Quotes srd
2171 \end_inset
2172
2173 i586-mingw32msvc-gcc
2174 \begin_inset Quotes srd
2175 \end_inset
2176
2177  CXX=
2178 \begin_inset Quotes srd
2179 \end_inset
2180
2181 i586-mingw32msvc-g++
2182 \begin_inset Quotes srd
2183 \end_inset
2184
2185  
2186 \backslash
2187  
2188 \newline
2189 RANLIB=
2190 \begin_inset Quotes srd
2191 \end_inset
2192
2193 i586-mingw32msvc-ranlib
2194 \begin_inset Quotes srd
2195 \end_inset
2196
2197  
2198 \backslash
2199
2200 \newline
2201 STRIP=
2202 \begin_inset Quotes srd
2203 \end_inset
2204
2205 i586-mingw32msvc-strip
2206 \begin_inset Quotes srd
2207 \end_inset
2208
2209  
2210 \backslash
2211
2212 \newline
2213 -
2214 \begin_inset ERT
2215 status collapsed
2216
2217 \begin_layout Standard
2218
2219
2220 \backslash
2221 /
2222 \end_layout
2223
2224 \end_inset
2225
2226 -prefix=
2227 \begin_inset Quotes srd
2228 \end_inset
2229
2230 /sdcc
2231 \begin_inset Quotes srd
2232 \end_inset
2233
2234  
2235 \backslash
2236
2237 \newline
2238 -
2239 \begin_inset ERT
2240 status collapsed
2241
2242 \begin_layout Standard
2243
2244
2245 \backslash
2246 /
2247 \end_layout
2248
2249 \end_inset
2250
2251 -datarootdir=
2252 \begin_inset Quotes srd
2253 \end_inset
2254
2255 /sdcc
2256 \begin_inset Quotes srd
2257 \end_inset
2258
2259  
2260 \backslash
2261
2262 \newline
2263 docdir=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267
2268 \backslash
2269 ${datarootdir}/doc
2270 \begin_inset Quotes srd
2271 \end_inset
2272
2273  
2274 \backslash
2275
2276 \newline
2277 include_dir_suffix=
2278 \begin_inset Quotes srd
2279 \end_inset
2280
2281 include
2282 \begin_inset Quotes srd
2283 \end_inset
2284
2285  
2286 \backslash
2287
2288 \newline
2289 lib_dir_suffix=
2290 \begin_inset Quotes srd
2291 \end_inset
2292
2293 lib
2294 \begin_inset Quotes srd
2295 \end_inset
2296
2297  
2298 \backslash
2299
2300 \newline
2301 sdccconf_h_dir_separator=
2302 \begin_inset Quotes srd
2303 \end_inset
2304
2305
2306 \backslash
2307
2308 \backslash
2309
2310 \backslash
2311
2312 \backslash
2313
2314 \begin_inset Quotes srd
2315 \end_inset
2316
2317  
2318 \backslash
2319
2320 \newline
2321 -
2322 \begin_inset ERT
2323 status collapsed
2324
2325 \begin_layout Standard
2326
2327
2328 \backslash
2329 /
2330 \end_layout
2331
2332 \end_inset
2333
2334 -disable-device-lib
2335 \backslash
2336
2337 \newline
2338 -
2339 \begin_inset ERT
2340 status collapsed
2341
2342 \begin_layout Standard
2343
2344
2345 \backslash
2346 /
2347 \end_layout
2348
2349 \end_inset
2350
2351 -host=i586-mingw32msvc
2352 \backslash
2353
2354 \newline
2355 -
2356 \begin_inset ERT
2357 status collapsed
2358
2359 \begin_layout Standard
2360
2361
2362 \backslash
2363 /
2364 \end_layout
2365
2366 \end_inset
2367
2368 -build=unknown-unknown-linux-gnu
2369 \end_layout
2370
2371 \begin_layout Standard
2372 To 
2373 \begin_inset Quotes sld
2374 \end_inset
2375
2376 cross
2377 \begin_inset Quotes srd
2378 \end_inset
2379
2380 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2381 ):
2382 \end_layout
2383
2384 \begin_layout LyX-Code
2385 ./configure -C 
2386 \backslash
2387
2388 \newline
2389 -
2390 \begin_inset ERT
2391 status collapsed
2392
2393 \begin_layout Standard
2394
2395
2396 \backslash
2397 /
2398 \end_layout
2399
2400 \end_inset
2401
2402 -prefix=
2403 \begin_inset Quotes srd
2404 \end_inset
2405
2406 /sdcc
2407 \begin_inset Quotes srd
2408 \end_inset
2409
2410  
2411 \backslash
2412
2413 \newline
2414 -
2415 \begin_inset ERT
2416 status collapsed
2417
2418 \begin_layout Standard
2419
2420
2421 \backslash
2422 /
2423 \end_layout
2424
2425 \end_inset
2426
2427 -datarootdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431 /sdcc
2432 \begin_inset Quotes srd
2433 \end_inset
2434
2435  
2436 \backslash
2437
2438 \newline
2439 docdir=
2440 \begin_inset Quotes srd
2441 \end_inset
2442
2443
2444 \backslash
2445 ${datarootdir}/doc
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451  
2452 \newline
2453 include_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 include
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 lib_dir_suffix=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469 lib
2470 \begin_inset Quotes srd
2471 \end_inset
2472
2473  
2474 \backslash
2475
2476 \newline
2477 sdccconf_h_dir_separator=
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481
2482 \backslash
2483
2484 \backslash
2485
2486 \backslash
2487
2488 \backslash
2489
2490 \begin_inset Quotes srd
2491 \end_inset
2492
2493  
2494 \backslash
2495
2496 \newline
2497 CC=
2498 \begin_inset Quotes srd
2499 \end_inset
2500
2501 gcc -mno-cygwin
2502 \begin_inset Quotes srd
2503 \end_inset
2504
2505  
2506 \backslash
2507
2508 \newline
2509 CXX=
2510 \begin_inset Quotes srd
2511 \end_inset
2512
2513 g++ -mno-cygwin
2514 \begin_inset Quotes srd
2515 \end_inset
2516
2517  
2518 \end_layout
2519
2520 \begin_layout Standard
2521 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2522  The option '-
2523 \begin_inset ERT
2524 status collapsed
2525
2526 \begin_layout Standard
2527
2528
2529 \backslash
2530 /
2531 \end_layout
2532
2533 \end_inset
2534
2535 -C' turns on caching, which gives a little bit extra speed.
2536  However if options are changed, it can be necessary to delete the config.cache
2537  file.
2538 \end_layout
2539
2540 \begin_layout Section
2541 Install paths
2542 \begin_inset LatexCommand \label{sub:Install-paths}
2543
2544 \end_inset
2545
2546
2547 \begin_inset LatexCommand \index{Install paths}
2548
2549 \end_inset
2550
2551
2552 \end_layout
2553
2554 \begin_layout Standard
2555 \begin_inset VSpace medskip
2556 \end_inset
2557
2558
2559 \end_layout
2560
2561 \begin_layout Standard
2562 \align center
2563 \begin_inset Tabular
2564 <lyxtabular version="3" rows="5" columns="4">
2565 <features>
2566 <column alignment="left" valignment="top" leftline="true" width="0">
2567 <column alignment="left" valignment="top" leftline="true" width="0">
2568 <column alignment="left" valignment="top" leftline="true" width="0">
2569 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2570 <row topline="true" bottomline="true">
2571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2572 \begin_inset Text
2573
2574 \begin_layout Standard
2575
2576 \series bold
2577 Description
2578 \end_layout
2579
2580 \end_inset
2581 </cell>
2582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2583 \begin_inset Text
2584
2585 \begin_layout Standard
2586
2587 \series bold
2588 Path
2589 \end_layout
2590
2591 \end_inset
2592 </cell>
2593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2594 \begin_inset Text
2595
2596 \begin_layout Standard
2597
2598 \series bold
2599 Default
2600 \end_layout
2601
2602 \end_inset
2603 </cell>
2604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2605 \begin_inset Text
2606
2607 \begin_layout Standard
2608
2609 \series bold
2610 Win32 builds
2611 \end_layout
2612
2613 \end_inset
2614 </cell>
2615 </row>
2616 <row topline="true">
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2618 \begin_inset Text
2619
2620 \begin_layout Standard
2621 Binary files*
2622 \end_layout
2623
2624 \end_inset
2625 </cell>
2626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2627 \begin_inset Text
2628
2629 \begin_layout Standard
2630
2631 \emph on
2632 $EXEC_PREFIX
2633 \end_layout
2634
2635 \end_inset
2636 </cell>
2637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2638 \begin_inset Text
2639
2640 \begin_layout Standard
2641 /usr/local/bin
2642 \end_layout
2643
2644 \end_inset
2645 </cell>
2646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2647 \begin_inset Text
2648
2649 \begin_layout Standard
2650
2651 \backslash
2652 sdcc
2653 \backslash
2654 bin
2655 \end_layout
2656
2657 \end_inset
2658 </cell>
2659 </row>
2660 <row topline="true">
2661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2662 \begin_inset Text
2663
2664 \begin_layout Standard
2665 Include files
2666 \end_layout
2667
2668 \end_inset
2669 </cell>
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2671 \begin_inset Text
2672
2673 \begin_layout Standard
2674
2675 \emph on
2676 $DATADIR/ $INCLUDE_DIR_SUFFIX
2677 \end_layout
2678
2679 \end_inset
2680 </cell>
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 \begin_inset Text
2683
2684 \begin_layout Standard
2685 /usr/local/share/sdcc/include
2686 \end_layout
2687
2688 \end_inset
2689 </cell>
2690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2691 \begin_inset Text
2692
2693 \begin_layout Standard
2694
2695 \backslash
2696 sdcc
2697 \backslash
2698 include
2699 \end_layout
2700
2701 \end_inset
2702 </cell>
2703 </row>
2704 <row topline="true">
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2706 \begin_inset Text
2707
2708 \begin_layout Standard
2709 Library file**
2710 \end_layout
2711
2712 \end_inset
2713 </cell>
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2715 \begin_inset Text
2716
2717 \begin_layout Standard
2718
2719 \emph on
2720 $DATADIR/$LIB_DIR_SUFFIX
2721 \end_layout
2722
2723 \end_inset
2724 </cell>
2725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2726 \begin_inset Text
2727
2728 \begin_layout Standard
2729 /usr/local/share/sdcc/lib
2730 \end_layout
2731
2732 \end_inset
2733 </cell>
2734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2735 \begin_inset Text
2736
2737 \begin_layout Standard
2738
2739 \backslash
2740 sdcc
2741 \backslash
2742 lib
2743 \end_layout
2744
2745 \end_inset
2746 </cell>
2747 </row>
2748 <row topline="true" bottomline="true">
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2750 \begin_inset Text
2751
2752 \begin_layout Standard
2753 Documentation
2754 \end_layout
2755
2756 \end_inset
2757 </cell>
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2759 \begin_inset Text
2760
2761 \begin_layout Standard
2762
2763 \emph on
2764 $DOCDIR
2765 \end_layout
2766
2767 \end_inset
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \begin_layout Standard
2773 /usr/local/share/sdcc/doc
2774 \end_layout
2775
2776 \end_inset
2777 </cell>
2778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2779 \begin_inset Text
2780
2781 \begin_layout Standard
2782
2783 \backslash
2784 sdcc
2785 \backslash
2786 doc
2787 \end_layout
2788
2789 \end_inset
2790 </cell>
2791 </row>
2792 </lyxtabular>
2793
2794 \end_inset
2795
2796
2797 \end_layout
2798
2799 \begin_layout Verse
2800
2801 \size footnotesize
2802 *compiler, preprocessor, assembler, and linker
2803 \newline
2804 **the 
2805 \shape italic
2806 model
2807 \shape default
2808  is auto-appended by the compiler, e.g.
2809  small, large, z80, ds390 etc
2810 \end_layout
2811
2812 \begin_layout Standard
2813 \noindent
2814 The install paths can still be changed during `make install` with e.g.:
2815 \end_layout
2816
2817 \begin_layout LyX-Code
2818 make install prefix=$(HOME)/local/sdcc
2819 \end_layout
2820
2821 \begin_layout Standard
2822 Of course this doesn't change the search paths compiled into the binaries.
2823 \newline
2824
2825 \newline
2826 Moreove
2827 r the install path can be changed by defining DESTDIR
2828 \begin_inset LatexCommand \index{DESTDIR}
2829
2830 \end_inset
2831
2832 :
2833 \end_layout
2834
2835 \begin_layout LyX-Code
2836 make install DESTDIR=$(HOME)/sdcc.rpm/
2837 \end_layout
2838
2839 \begin_layout Standard
2840 Please note that DESTDIR must have a trailing slash!
2841 \end_layout
2842
2843 \begin_layout Section
2844 Search Paths
2845 \begin_inset LatexCommand \label{sub:Search-Paths}
2846
2847 \end_inset
2848
2849
2850 \begin_inset LatexCommand \index{Search path}
2851
2852 \end_inset
2853
2854
2855 \end_layout
2856
2857 \begin_layout Standard
2858 Some search paths or parts of them are determined by configure variables
2859  (in 
2860 \emph on
2861 italics
2862 \emph default
2863 , see section above).
2864  Further search paths are determined by environment variables during runtime.
2865  
2866 \newline
2867 The paths searched when running the compiler are as follows (the first
2868  catch wins):
2869 \newline
2870
2871 \newline
2872 1.
2873  Binary files (preprocessor, assembler and linker)
2874 \newline
2875
2876 \end_layout
2877
2878 \begin_layout Standard
2879 \align center
2880 \begin_inset Tabular
2881 <lyxtabular version="3" rows="4" columns="3">
2882 <features>
2883 <column alignment="block" valignment="top" leftline="true" width="0in">
2884 <column alignment="block" valignment="top" leftline="true" width="0in">
2885 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2886 <row topline="true" bottomline="true">
2887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2888 \begin_inset Text
2889
2890 \begin_layout Standard
2891 Search path
2892 \end_layout
2893
2894 \end_inset
2895 </cell>
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2897 \begin_inset Text
2898
2899 \begin_layout Standard
2900 default
2901 \end_layout
2902
2903 \end_inset
2904 </cell>
2905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2906 \begin_inset Text
2907
2908 \begin_layout Standard
2909 Win32 builds
2910 \end_layout
2911
2912 \end_inset
2913 </cell>
2914 </row>
2915 <row topline="true">
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2917 \begin_inset Text
2918
2919 \begin_layout Standard
2920 $SDCC_HOME/
2921 \emph on
2922 $PPREFIX2BIN_DIR
2923 \end_layout
2924
2925 \end_inset
2926 </cell>
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2928 \begin_inset Text
2929
2930 \begin_layout Standard
2931 $SDCC_HOME/bin
2932 \end_layout
2933
2934 \end_inset
2935 </cell>
2936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2937 \begin_inset Text
2938
2939 \begin_layout Standard
2940 $SDCC_HOME
2941 \backslash
2942 bin
2943 \end_layout
2944
2945 \end_inset
2946 </cell>
2947 </row>
2948 <row topline="true">
2949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2950 \begin_inset Text
2951
2952 \begin_layout Standard
2953 Path of argv[0] (if available)
2954 \end_layout
2955
2956 \end_inset
2957 </cell>
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2959 \begin_inset Text
2960
2961 \begin_layout Standard
2962 Path of argv[0]
2963 \end_layout
2964
2965 \end_inset
2966 </cell>
2967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2968 \begin_inset Text
2969
2970 \begin_layout Standard
2971 Path of argv[0]
2972 \end_layout
2973
2974 \end_inset
2975 </cell>
2976 </row>
2977 <row topline="true" bottomline="true">
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2979 \begin_inset Text
2980
2981 \begin_layout Standard
2982 $PATH
2983 \end_layout
2984
2985 \end_inset
2986 </cell>
2987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2988 \begin_inset Text
2989
2990 \begin_layout Standard
2991 $PATH
2992 \end_layout
2993
2994 \end_inset
2995 </cell>
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2997 \begin_inset Text
2998
2999 \begin_layout Standard
3000 $PATH
3001 \end_layout
3002
3003 \end_inset
3004 </cell>
3005 </row>
3006 </lyxtabular>
3007
3008 \end_inset
3009
3010  
3011 \newline
3012
3013 \end_layout
3014
3015 \begin_layout Standard
3016 \noindent
3017 2.
3018  Include files
3019 \newline
3020
3021 \end_layout
3022
3023 \begin_layout Standard
3024 \align center
3025 \begin_inset Tabular
3026 <lyxtabular version="3" rows="6" columns="3">
3027 <features>
3028 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3029 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3030 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3031 <row topline="true" bottomline="true">
3032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3033 \begin_inset Text
3034
3035 \begin_layout Standard
3036 Search path
3037 \end_layout
3038
3039 \end_inset
3040 </cell>
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3042 \begin_inset Text
3043
3044 \begin_layout Standard
3045 default
3046 \end_layout
3047
3048 \end_inset
3049 </cell>
3050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3051 \begin_inset Text
3052
3053 \begin_layout Standard
3054 Win32 builds
3055 \end_layout
3056
3057 \end_inset
3058 </cell>
3059 </row>
3060 <row topline="true">
3061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3062 \begin_inset Text
3063
3064 \begin_layout Standard
3065 -
3066 \begin_inset ERT
3067 status collapsed
3068
3069 \begin_layout Standard
3070
3071
3072 \backslash
3073 /
3074 \end_layout
3075
3076 \end_inset
3077
3078 -I dir
3079 \end_layout
3080
3081 \end_inset
3082 </cell>
3083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3084 \begin_inset Text
3085
3086 \begin_layout Standard
3087 -
3088 \begin_inset ERT
3089 status collapsed
3090
3091 \begin_layout Standard
3092
3093
3094 \backslash
3095 /
3096 \end_layout
3097
3098 \end_inset
3099
3100 -I dir
3101 \end_layout
3102
3103 \end_inset
3104 </cell>
3105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3106 \begin_inset Text
3107
3108 \begin_layout Standard
3109 -
3110 \begin_inset ERT
3111 status collapsed
3112
3113 \begin_layout Standard
3114
3115
3116 \backslash
3117 /
3118 \end_layout
3119
3120 \end_inset
3121
3122 -I dir
3123 \end_layout
3124
3125 \end_inset
3126 </cell>
3127 </row>
3128 <row topline="true">
3129 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3130 \begin_inset Text
3131
3132 \begin_layout Standard
3133 $SDCC_INCLUDE
3134 \end_layout
3135
3136 \end_inset
3137 </cell>
3138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3139 \begin_inset Text
3140
3141 \begin_layout Standard
3142 $SDCC_INCLUDE
3143 \end_layout
3144
3145 \end_inset
3146 </cell>
3147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3148 \begin_inset Text
3149
3150 \begin_layout Standard
3151 $SDCC_INCLUDE
3152 \end_layout
3153
3154 \end_inset
3155 </cell>
3156 </row>
3157 <row topline="true">
3158 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3159 \begin_inset Text
3160
3161 \begin_layout Standard
3162 $SDCC_HOME/
3163 \newline
3164
3165 \emph on
3166 $PREFIX2DATA_DIR/
3167 \newline
3168 $INCLUDE_DIR_SUFFIX
3169 \end_layout
3170
3171 \end_inset
3172 </cell>
3173 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3174 \begin_inset Text
3175
3176 \begin_layout Standard
3177 $SDCC_ HOME/
3178 \newline
3179 share/sdcc/
3180 \newline
3181 include
3182 \end_layout
3183
3184 \end_inset
3185 </cell>
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3187 \begin_inset Text
3188
3189 \begin_layout Standard
3190 $SDCC_HOME
3191 \backslash
3192 include
3193 \end_layout
3194
3195 \end_inset
3196 </cell>
3197 </row>
3198 <row topline="true">
3199 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3200 \begin_inset Text
3201
3202 \begin_layout Standard
3203 path(argv[0])/
3204 \newline
3205
3206 \emph on
3207 $BIN2DATADIR/
3208 \emph default
3209
3210 \newline
3211
3212 \emph on
3213 $INCLUDE_DIR_SUFFIX
3214 \end_layout
3215
3216 \end_inset
3217 </cell>
3218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3219 \begin_inset Text
3220
3221 \begin_layout Standard
3222 path(argv[0])/
3223 \newline
3224 ../sdcc/include
3225 \newline
3226 \InsetSpace ~
3227 \InsetSpace ~
3228 \InsetSpace ~
3229 \InsetSpace ~
3230 \InsetSpace ~
3231 \InsetSpace ~
3232 \InsetSpace ~
3233 \InsetSpace ~
3234 \InsetSpace ~
3235 \InsetSpace ~
3236 \InsetSpace ~
3237 \InsetSpace ~
3238 \InsetSpace ~
3239 \InsetSpace ~
3240 \InsetSpace ~
3241 \InsetSpace ~
3242 \InsetSpace ~
3243 \InsetSpace ~
3244 \InsetSpace ~
3245 \InsetSpace ~
3246 \InsetSpace ~
3247 \InsetSpace ~
3248 \InsetSpace ~
3249 \InsetSpace ~
3250 \InsetSpace ~
3251 \InsetSpace ~
3252 \InsetSpace ~
3253 \InsetSpace ~
3254 \InsetSpace ~
3255 \InsetSpace ~
3256 \InsetSpace ~
3257 \InsetSpace ~
3258 \InsetSpace ~
3259 \InsetSpace ~
3260 \InsetSpace ~
3261 \InsetSpace ~
3262 \InsetSpace ~
3263 \InsetSpace ~
3264
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 path(argv[0])
3274 \backslash
3275 ..
3276 \backslash
3277 include
3278 \end_layout
3279
3280 \end_inset
3281 </cell>
3282 </row>
3283 <row topline="true" bottomline="true">
3284 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3285 \begin_inset Text
3286
3287 \begin_layout Standard
3288
3289 \emph on
3290 $DATADIR/
3291 \emph default
3292
3293 \newline
3294
3295 \emph on
3296 $INCLUDE_DIR_SUFFIX
3297 \end_layout
3298
3299 \end_inset
3300 </cell>
3301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3302 \begin_inset Text
3303
3304 \begin_layout Standard
3305 /usr/local/share/sdcc/
3306 \newline
3307 include
3308 \end_layout
3309
3310 \end_inset
3311 </cell>
3312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3313 \begin_inset Text
3314
3315 \begin_layout Standard
3316 (not on Win32)
3317 \end_layout
3318
3319 \end_inset
3320 </cell>
3321 </row>
3322 </lyxtabular>
3323
3324 \end_inset
3325
3326  
3327 \newline
3328
3329 \end_layout
3330
3331 \begin_layout Standard
3332 \noindent
3333 The option -
3334 \begin_inset ERT
3335 status collapsed
3336
3337 \begin_layout Standard
3338
3339
3340 \backslash
3341 /
3342 \end_layout
3343
3344 \end_inset
3345
3346 -nostdinc disables the last two search paths.
3347 \newline
3348
3349 \newline
3350 3.
3351  Library files 
3352 \newline
3353
3354 \end_layout
3355
3356 \begin_layout Standard
3357 With the exception of 
3358 \begin_inset Quotes sld
3359 \end_inset
3360
3361 -
3362 \begin_inset ERT
3363 status collapsed
3364
3365 \begin_layout Standard
3366
3367
3368 \backslash
3369 /
3370 \end_layout
3371
3372 \end_inset
3373
3374 -L dir
3375 \begin_inset Quotes srd
3376 \end_inset
3377
3378  the 
3379 \shape italic
3380 model
3381 \shape default
3382  is auto-appended by the compiler (e.g.
3383  small, large, z80, ds390 etc.).
3384  
3385 \newline
3386
3387 \end_layout
3388
3389 \begin_layout Standard
3390 \align center
3391 \begin_inset Tabular
3392 <lyxtabular version="3" rows="6" columns="3">
3393 <features>
3394 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3395 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3396 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3397 <row topline="true" bottomline="true">
3398 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3399 \begin_inset Text
3400
3401 \begin_layout Standard
3402 Search path
3403 \end_layout
3404
3405 \end_inset
3406 </cell>
3407 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3408 \begin_inset Text
3409
3410 \begin_layout Standard
3411 default
3412 \end_layout
3413
3414 \end_inset
3415 </cell>
3416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3417 \begin_inset Text
3418
3419 \begin_layout Standard
3420 Win32 builds
3421 \end_layout
3422
3423 \end_inset
3424 </cell>
3425 </row>
3426 <row topline="true">
3427 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3428 \begin_inset Text
3429
3430 \begin_layout Standard
3431 -
3432 \begin_inset ERT
3433 status collapsed
3434
3435 \begin_layout Standard
3436
3437
3438 \backslash
3439 /
3440 \end_layout
3441
3442 \end_inset
3443
3444 -L dir
3445 \end_layout
3446
3447 \end_inset
3448 </cell>
3449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3450 \begin_inset Text
3451
3452 \begin_layout Standard
3453 -
3454 \begin_inset ERT
3455 status collapsed
3456
3457 \begin_layout Standard
3458
3459
3460 \backslash
3461 /
3462 \end_layout
3463
3464 \end_inset
3465
3466 -L dir
3467 \end_layout
3468
3469 \end_inset
3470 </cell>
3471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3472 \begin_inset Text
3473
3474 \begin_layout Standard
3475 -
3476 \begin_inset ERT
3477 status collapsed
3478
3479 \begin_layout Standard
3480
3481
3482 \backslash
3483 /
3484 \end_layout
3485
3486 \end_inset
3487
3488 -L dir
3489 \end_layout
3490
3491 \end_inset
3492 </cell>
3493 </row>
3494 <row topline="true">
3495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3496 \begin_inset Text
3497
3498 \begin_layout Standard
3499 $SDCC_LIB/
3500 \newline
3501
3502 \emph on
3503 <model>
3504 \end_layout
3505
3506 \end_inset
3507 </cell>
3508 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3509 \begin_inset Text
3510
3511 \begin_layout Standard
3512 $SDCC_LIB/
3513 \newline
3514
3515 \emph on
3516 <model>
3517 \end_layout
3518
3519 \end_inset
3520 </cell>
3521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3522 \begin_inset Text
3523
3524 \begin_layout Standard
3525 $SDCC_LIB
3526 \backslash
3527
3528 \newline
3529
3530 \emph on
3531 <model>
3532 \end_layout
3533
3534 \end_inset
3535 </cell>
3536 </row>
3537 <row topline="true">
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3539 \begin_inset Text
3540
3541 \begin_layout Standard
3542 $SDCC_HOME/
3543 \newline
3544
3545 \emph on
3546 $PREFIX2DATA_DIR/
3547 \newline
3548 $LIB_DIR_SUFFIX/<model>
3549 \end_layout
3550
3551 \end_inset
3552 </cell>
3553 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3554 \begin_inset Text
3555
3556 \begin_layout Standard
3557 $SDCC_HOME/
3558 \newline
3559 share/sdcc/
3560 \newline
3561 lib/
3562 \emph on
3563 <model>
3564 \end_layout
3565
3566 \end_inset
3567 </cell>
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3569 \begin_inset Text
3570
3571 \begin_layout Standard
3572 $SDCC_HOME
3573 \backslash
3574 lib
3575 \backslash
3576
3577 \emph on
3578
3579 \newline
3580 <model>
3581 \end_layout
3582
3583 \end_inset
3584 </cell>
3585 </row>
3586 <row topline="true">
3587 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3588 \begin_inset Text
3589
3590 \begin_layout Standard
3591 path(argv[0])/
3592 \newline
3593
3594 \emph on
3595 $BIN2DATADIR/
3596 \emph default
3597
3598 \newline
3599
3600 \emph on
3601 $LIB_DIR_SUFFIX/<model>
3602 \end_layout
3603
3604 \end_inset
3605 </cell>
3606 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3607 \begin_inset Text
3608
3609 \begin_layout Standard
3610 path(argv[0])/
3611 \newline
3612 ../sdcc/lib/
3613 \emph on
3614 <model>
3615 \newline
3616 \InsetSpace ~
3617 \InsetSpace ~
3618 \InsetSpace ~
3619 \InsetSpace ~
3620 \InsetSpace ~
3621 \InsetSpace ~
3622 \InsetSpace ~
3623 \InsetSpace ~
3624 \InsetSpace ~
3625 \InsetSpace ~
3626 \InsetSpace ~
3627 \InsetSpace ~
3628 \InsetSpace ~
3629 \InsetSpace ~
3630 \InsetSpace ~
3631 \InsetSpace ~
3632 \InsetSpace ~
3633 \InsetSpace ~
3634 \InsetSpace ~
3635 \InsetSpace ~
3636 \InsetSpace ~
3637 \InsetSpace ~
3638 \InsetSpace ~
3639 \InsetSpace ~
3640 \InsetSpace ~
3641 \InsetSpace ~
3642 \InsetSpace ~
3643 \InsetSpace ~
3644 \InsetSpace ~
3645 \InsetSpace ~
3646 \InsetSpace ~
3647 \InsetSpace ~
3648 \InsetSpace ~
3649 \InsetSpace ~
3650 \InsetSpace ~
3651 \InsetSpace ~
3652 \InsetSpace ~
3653 \InsetSpace ~
3654 \InsetSpace ~
3655
3656 \end_layout
3657
3658 \end_inset
3659 </cell>
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3661 \begin_inset Text
3662
3663 \begin_layout Standard
3664 path(argv[0])
3665 \backslash
3666
3667 \newline
3668 ..
3669 \backslash
3670 lib
3671 \backslash
3672
3673 \emph on
3674 <model>
3675 \newline
3676 \InsetSpace ~
3677 \InsetSpace ~
3678 \InsetSpace ~
3679 \InsetSpace ~
3680 \InsetSpace ~
3681 \InsetSpace ~
3682 \InsetSpace ~
3683 \InsetSpace ~
3684 \InsetSpace ~
3685 \InsetSpace ~
3686 \InsetSpace ~
3687 \InsetSpace ~
3688 \InsetSpace ~
3689 \InsetSpace ~
3690 \InsetSpace ~
3691 \InsetSpace ~
3692 \InsetSpace ~
3693 \InsetSpace ~
3694 \InsetSpace ~
3695 \InsetSpace ~
3696 \InsetSpace ~
3697 \InsetSpace ~
3698 \InsetSpace ~
3699 \InsetSpace ~
3700 \InsetSpace ~
3701 \InsetSpace ~
3702 \InsetSpace ~
3703 \InsetSpace ~
3704 \InsetSpace ~
3705 \InsetSpace ~
3706 \InsetSpace ~
3707 \InsetSpace ~
3708 \InsetSpace ~
3709 \InsetSpace ~
3710 \InsetSpace ~
3711
3712 \end_layout
3713
3714 \end_inset
3715 </cell>
3716 </row>
3717 <row topline="true" bottomline="true">
3718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3719 \begin_inset Text
3720
3721 \begin_layout Standard
3722
3723 \emph on
3724 $DATADIR/
3725 \newline
3726 $LIB_DIR_SUFFIX/<model>
3727 \end_layout
3728
3729 \end_inset
3730 </cell>
3731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3732 \begin_inset Text
3733
3734 \begin_layout Standard
3735 /usr/local/share/sdcc/
3736 \newline
3737 lib/
3738 \emph on
3739 <model>
3740 \end_layout
3741
3742 \end_inset
3743 </cell>
3744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3745 \begin_inset Text
3746
3747 \begin_layout Standard
3748 (not on Win32)
3749 \end_layout
3750
3751 \end_inset
3752 </cell>
3753 </row>
3754 </lyxtabular>
3755
3756 \end_inset
3757
3758
3759 \newline
3760
3761 \end_layout
3762
3763 \begin_layout Standard
3764 \begin_inset Note Note
3765 status collapsed
3766
3767 \begin_layout Standard
3768 Don't delete any of the stray spaces in the table above without checking
3769  the HTML output (last line)!
3770 \end_layout
3771
3772 \end_inset
3773
3774
3775 \end_layout
3776
3777 \begin_layout Standard
3778 \InsetSpace ~
3779
3780 \newline
3781 The option -
3782 \begin_inset ERT
3783 status collapsed
3784
3785 \begin_layout Standard
3786
3787
3788 \backslash
3789 /
3790 \end_layout
3791
3792 \end_inset
3793
3794 -nostdlib disables the last two search paths.
3795 \end_layout
3796
3797 \begin_layout Section
3798 Building SDCC
3799 \begin_inset LatexCommand \index{Building SDCC}
3800
3801 \end_inset
3802
3803
3804 \end_layout
3805
3806 \begin_layout Subsection
3807 Building SDCC on Linux
3808 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3809
3810 \end_inset
3811
3812
3813 \end_layout
3814
3815 \begin_layout Enumerate
3816
3817 \series medium
3818 Download the source package
3819 \series default
3820  either from the SDCC Subversion repository or from snapshot builds
3821 \series medium
3822 , it will be named something like sdcc
3823 \series default
3824 -src
3825 \series medium
3826 -yyyymmdd-rrrr.t
3827 \series default
3828 ar.
3829 \series medium
3830 bz2
3831 \series default
3832  
3833 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3834
3835 \end_inset
3836
3837 .
3838 \end_layout
3839
3840 \begin_layout Enumerate
3841
3842 \series medium
3843 Bring up a command line terminal, such as xterm.
3844 \end_layout
3845
3846 \begin_layout Enumerate
3847
3848 \series medium
3849 Unpack the file using a command like: 
3850 \family sans
3851 \series bold
3852 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3853 \begin_inset Quotes srd
3854 \end_inset
3855
3856
3857 \family default
3858 \series medium
3859 , this will create a sub-directory called sdcc with all of the sources.
3860 \end_layout
3861
3862 \begin_layout Enumerate
3863 Change directory into the main SDCC directory, for example type: 
3864 \family sans
3865 \series bold
3866 "cd sdcc
3867 \series default
3868 ".
3869 \end_layout
3870
3871 \begin_layout Enumerate
3872
3873 \series medium
3874 Type 
3875 \family sans
3876 \series bold
3877 "./configure
3878 \family default
3879 \series default
3880 ".
3881  This configures the package for compilation on your system.
3882 \end_layout
3883
3884 \begin_layout Enumerate
3885
3886 \series medium
3887 Type 
3888 \family sans
3889 \series bold
3890 "make
3891 \family default
3892 \series default
3893 "
3894 \series medium
3895 .
3896
3897 \series default
3898  All of the source packages will compile, this can take a while.
3899 \end_layout
3900
3901 \begin_layout Enumerate
3902
3903 \series medium
3904 Type 
3905 \family sans
3906 \series bold
3907 "make install"
3908 \family default
3909 \series default
3910  as root
3911 \series medium
3912 .
3913
3914 \series default
3915  This copies the binary executables, the include files, the libraries and
3916  the documentation to the install directories.
3917  Proceed with section 
3918 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3919
3920 \end_inset
3921
3922 .
3923 \end_layout
3924
3925 \begin_layout Subsection
3926 Building SDCC on OSX 2.x
3927 \end_layout
3928
3929 \begin_layout Standard
3930 Follow the instruction for Linux.
3931 \newline
3932
3933 \newline
3934 On OSX 2.x it was reported, that the default
3935  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3936  Fortunately there's also gcc 2.9.x installed, which works fine.
3937  This compiler can be selected by running 'configure' with:
3938 \end_layout
3939
3940 \begin_layout LyX-Code
3941 ./configure CC=gcc2 CXX=g++2
3942 \end_layout
3943
3944 \begin_layout Subsection
3945 Cross compiling SDCC on Linux for Windows
3946 \end_layout
3947
3948 \begin_layout Standard
3949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3950  See section 'Configure Options'.
3951 \end_layout
3952
3953 \begin_layout Subsection
3954 Building SDCC using Cygwin and Mingw32
3955 \end_layout
3956
3957 \begin_layout Standard
3958 For building and installing a Cygwin executable follow the instructions
3959  for Linux.
3960 \newline
3961
3962 \newline
3963 On Cygwin a 
3964 \begin_inset Quotes sld
3965 \end_inset
3966
3967 native
3968 \begin_inset Quotes srd
3969 \end_inset
3970
3971  Win32-binary can be built, which will not need the Cygwin-DLL.
3972  For the necessary 'configure' options see section 'configure options' or
3973  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3974 \newline
3975
3976 \newline
3977 In order to install
3978  Cygwin on Windows download setup.exe from 
3979 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3980
3981 \end_inset
3982
3983 .
3984  Run it, set the 
3985 \begin_inset Quotes sld
3986 \end_inset
3987
3988 default text file type
3989 \begin_inset Quotes srd
3990 \end_inset
3991
3992  to 
3993 \begin_inset Quotes sld
3994 \end_inset
3995
3996 unix
3997 \begin_inset Quotes srd
3998 \end_inset
3999
4000  and download/install at least the following packages.
4001  Some packages are selected by default, others will be automatically selected
4002  because of dependencies with the manually selected packages.
4003  Never deselect these packages!
4004 \end_layout
4005
4006 \begin_layout Itemize
4007 flex
4008 \end_layout
4009
4010 \begin_layout Itemize
4011 bison
4012 \end_layout
4013
4014 \begin_layout Itemize
4015 gcc ; version 3.x is fine, no need to use the old 2.9x
4016 \end_layout
4017
4018 \begin_layout Itemize
4019 binutils ; selected with gcc
4020 \end_layout
4021
4022 \begin_layout Itemize
4023 make
4024 \end_layout
4025
4026 \begin_layout Itemize
4027 rxvt ; a nice console, which makes life much easier under windoze (see below)
4028 \end_layout
4029
4030 \begin_layout Itemize
4031 man ; not really needed for building SDCC, but you'll miss it sooner or
4032  later
4033 \end_layout
4034
4035 \begin_layout Itemize
4036 less ; not really needed for building SDCC, but you'll miss it sooner or
4037  later
4038 \end_layout
4039
4040 \begin_layout Itemize
4041 svn ; only if you use Subversion access
4042 \end_layout
4043
4044 \begin_layout Standard
4045 If you want to develop something you'll need:
4046 \end_layout
4047
4048 \begin_layout Itemize
4049 python ; for the regression tests
4050 \end_layout
4051
4052 \begin_layout Itemize
4053 gdb ; the gnu debugger, together with the nice GUI 
4054 \begin_inset Quotes sld
4055 \end_inset
4056
4057 insight
4058 \begin_inset Quotes srd
4059 \end_inset
4060
4061
4062 \end_layout
4063
4064 \begin_layout Itemize
4065 openssh ; to access the CF or commit changes
4066 \end_layout
4067
4068 \begin_layout Itemize
4069 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4070  use autoconf-stable!
4071 \end_layout
4072
4073 \begin_layout Standard
4074 rxvt is a nice console with history.
4075  Replace in your cygwin.bat the line
4076 \end_layout
4077
4078 \begin_layout LyX-Code
4079 bash -
4080 \begin_inset ERT
4081 status collapsed
4082
4083 \begin_layout Standard
4084
4085
4086 \backslash
4087 /
4088 \end_layout
4089
4090 \end_inset
4091
4092 -login -i 
4093 \end_layout
4094
4095 \begin_layout Standard
4096 with (one line):
4097 \end_layout
4098
4099 \begin_layout LyX-Code
4100 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4101 \end_layout
4102
4103 \begin_layout LyX-Code
4104      -bg black -fg white -geometry 100x65 -e bash -
4105 \begin_inset ERT
4106 status collapsed
4107
4108 \begin_layout Standard
4109
4110
4111 \backslash
4112 /
4113 \end_layout
4114
4115 \end_inset
4116
4117 -login
4118 \end_layout
4119
4120 \begin_layout Standard
4121 Text selected with the mouse is automatically copied to the clipboard, pasting
4122  works with shift-insert.
4123 \newline
4124
4125 \newline
4126 The other good tip is to make sure you have no //c/-styl
4127 e paths anywhere, use /cygdrive/c/ instead.
4128  Using // invokes a network lookup which is very slow.
4129  If you think 
4130 \begin_inset Quotes sld
4131 \end_inset
4132
4133 cygdrive
4134 \begin_inset Quotes srd
4135 \end_inset
4136
4137  is too long, you can change it with e.g.
4138 \end_layout
4139
4140 \begin_layout LyX-Code
4141 mount -s -u -c /mnt
4142 \end_layout
4143
4144 \begin_layout Standard
4145 SDCC sources use the unix line ending LF.
4146  Life is much easier, if you store the source tree on a drive which is mounted
4147  in binary mode.
4148  And use an editor which can handle LF-only line endings.
4149  Make sure not to commit files with windows line endings.
4150  The tabulator spacing
4151 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4152
4153 \end_inset
4154
4155  used in the project is 8.
4156  Although a tabulator spacing of 8 is a sensible choice for programmers
4157  (it's a power of 2 and allows to display 8/16 bit signed variables without
4158  loosing columns) the plan is to move towards using only spaces in the source.
4159 \end_layout
4160
4161 \begin_layout Subsection
4162 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4163 \end_layout
4164
4165 \begin_layout Standard
4166
4167 \series medium
4168 Download the source package
4169 \series default
4170  either from the SDCC Subversion repository or from the 
4171 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4172
4173 \end_inset
4174
4175
4176 \series medium
4177 , it will be named something like sdcc
4178 \series default
4179 -src
4180 \series medium
4181 -yyyymmdd-rrrr.tar.bz2.
4182
4183 \series default
4184  SDCC is distributed with all the projects, workspaces, and files you need
4185  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4186  The workspace name is 'sdcc.dsw'.
4187  Please note that as it is now, all the executables are created in a folder
4188  called sdcc
4189 \backslash
4190 bin_vc.
4191  Once built you need to copy the executables from sdcc
4192 \backslash
4193 bin_vc to sdcc
4194 \backslash
4195 bin before running SDCC.
4196  
4197 \newline
4198
4199 \newline
4200 WARNING: Visual studio is very picky with line terminations; it expects
4201  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4202  When using the Subversion repository it's easiest to configure the svn
4203  client to convert automatically for you.
4204  If however you are getting a message such as "This makefile was not generated
4205  by Developer Studio etc.
4206  etc.
4207 \begin_inset Quotes srd
4208 \end_inset
4209
4210  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4211  need to convert the Unix style line endings to DOS style line endings.
4212  To do so you can use the 
4213 \begin_inset Quotes sld
4214 \end_inset
4215
4216 unix2dos
4217 \begin_inset Quotes srd
4218 \end_inset
4219
4220  utility freely available on the internet.
4221  Doug Hawkins reported in the sdcc-user list that this works:
4222 \newline
4223
4224 \newline
4225 C:
4226 \backslash
4227 Programming
4228 \backslash
4229 SDCC> unix2dos sdcc.dsw
4230 \newline
4231 C:
4232 \backslash
4233 Programming
4234 \backslash
4235 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4236 \newline
4237
4238 \newline
4239 In order to build SDCC with MSVC
4240  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4241  One good place to get them is 
4242 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4243
4244 \end_inset
4245
4246
4247 \newline
4248
4249 \newline
4250 Download the file UnxUtils
4251 \begin_inset LatexCommand \index{UnxUtils}
4252
4253 \end_inset
4254
4255 .zip.
4256  Now you have to install the utilities and setup MSVC so it can locate the
4257  required programs.
4258  Here there are two alternatives (choose one!):
4259 \end_layout
4260
4261 \begin_layout Enumerate
4262 The easy way:
4263 \newline
4264
4265 \newline
4266 a) Extract UnxUtils.zip to your C:
4267 \backslash
4268  hard disk PRESERVING the original paths, otherwise bison won't work.
4269  (If you are using WinZip make certain that 'Use folder names' is selected)
4270 \newline
4271
4272 \newline
4273 b)
4274  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4275  'Show directories for:' select 'Executable files', and in the directories
4276  window add a new path: 'C:
4277 \backslash
4278 user
4279 \backslash
4280 local
4281 \backslash
4282 wbin', click ok.
4283 \newline
4284
4285 \newline
4286 (As a side effect, you get a bunch of Unix utilities that
4287  could be useful, such as diff and patch.)
4288 \end_layout
4289
4290 \begin_layout Enumerate
4291 A more compact way:
4292 \newline
4293
4294 \newline
4295 This one avoids extracting a bunch of files you may not
4296  use, but requires some extra work:
4297 \newline
4298
4299 \newline
4300 a) Create a directory were to put the
4301  tools needed, or use a directory already present.
4302  Say for example 'C:
4303 \backslash
4304 util'.
4305 \newline
4306
4307 \newline
4308 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4309  gawk.exe to such directory WITHOUT preserving the original paths.
4310  (If you are using WinZip make certain that 'Use folder names' is not selected)
4311 \newline
4312
4313 \newline
4314 c
4315 ) Rename bison.exe to '_bison.exe'.
4316 \newline
4317
4318 \newline
4319 d) Create a batch file 'bison.bat' in 'C:
4320 \backslash
4321 util
4322 \backslash
4323 ' and add these lines: 
4324 \newline
4325 \InsetSpace ~
4326 \InsetSpace ~
4327 set BISON_SIMPLE=C:
4328 \backslash
4329 util
4330 \backslash
4331 bison.simple 
4332 \newline
4333 \InsetSpace ~
4334 \InsetSpace ~
4335 set BISON_HAIRY=C:
4336 \backslash
4337 util
4338 \backslash
4339 bison.hairy
4340 \newline
4341 \InsetSpace ~
4342 \InsetSpace ~
4343 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4344 \newline
4345
4346 \newline
4347 Steps 'c' and 'd' are needed
4348  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4349  reside in some weird Unix directory, '/usr/local/share/' I think.
4350  So it is necessary to tell bison where those files are located if they
4351  are not in such directory.
4352  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4353 \newline
4354
4355 \newline
4356 e
4357 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4358  in 'Show directories for:' select 'Executable files', and in the directories
4359  window add a new path: 'c:
4360 \backslash
4361 util', click ok.
4362  Note that you can use any other path instead of 'c:
4363 \backslash
4364 util', even the path where the Visual C++ tools are, probably: 'C:
4365 \backslash
4366 Program Files
4367 \backslash
4368 Microsoft Visual Studio
4369 \backslash
4370 Common
4371 \backslash
4372 Tools'.
4373  So you don't have to execute step 'e' :)
4374 \end_layout
4375
4376 \begin_layout Standard
4377 That is it.
4378  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4379  the executables from sdcc
4380 \backslash
4381 bin_vc to sdcc
4382 \backslash
4383 bin, and you can compile using SDCC.
4384 \end_layout
4385
4386 \begin_layout Subsection
4387 Building SDCC Using Borland
4388 \end_layout
4389
4390 \begin_layout Enumerate
4391 From the sdcc directory, run the command "make -f Makefile.bcc".
4392  This should regenerate all the .exe files in the bin directory except for
4393  SDCDB and ucSim.
4394 \end_layout
4395
4396 \begin_layout Enumerate
4397 If you modify any source files and need to rebuild, be aware that the dependenci
4398 es may not be correctly calculated.
4399  The safest option is to delete all .obj files and run the build again.
4400  From a Cygwin BASH prompt, this can easily be done with the command (be
4401  sure you are in the sdcc directory):
4402 \newline
4403
4404 \newline
4405
4406 \family sans
4407 \series bold
4408 find .
4409  
4410 \backslash
4411 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4412 \backslash
4413 ) -print -exec rm {} 
4414 \backslash
4415 ;
4416 \family default
4417 \series default
4418
4419 \newline
4420
4421 \newline
4422 or on Windows NT/2000/XP from the command prompt with the command:
4423 \newline
4424
4425 \family sans
4426 \series bold
4427
4428 \newline
4429 del /s *.obj *.lib *.rul
4430 \family default
4431 \series default
4432  from the sdcc directory.
4433 \end_layout
4434
4435 \begin_layout Subsection
4436 Windows Install Using a ZIP Package
4437 \end_layout
4438
4439 \begin_layout Enumerate
4440 Download the binary zip package from 
4441 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4442
4443 \end_inset
4444
4445  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4446  This should unpack to a group of sub-directories.
4447  An example directory structure after unpacking the mingw32 package is:
4448  c:
4449 \backslash
4450 sdcc
4451 \backslash
4452 bin for the executables, c:
4453 \backslash
4454 sdcc
4455 \backslash
4456 include and c:
4457 \backslash
4458 sdcc
4459 \backslash
4460 lib for the include and libraries.
4461 \end_layout
4462
4463 \begin_layout Enumerate
4464 Adjust your environment variable PATH to include the location of the bin
4465  directory or start sdcc using the full path.
4466 \end_layout
4467
4468 \begin_layout Subsection
4469 Windows Install Using the Setup Program
4470 \begin_inset LatexCommand \label{sub:Windows-Install}
4471
4472 \end_inset
4473
4474
4475 \end_layout
4476
4477 \begin_layout Standard
4478 Download the setup program 
4479 \emph on
4480 sdcc-x.y.z-setup.exe
4481 \emph default
4482  for an official release from 
4483 \newline
4484
4485 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4486
4487 \end_inset
4488
4489  or a setup program for one of the snapshots 
4490 \emph on
4491 sdcc-yyyymmdd-xxxx-setup.exe
4492 \emph default
4493  from 
4494 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4495
4496 \end_inset
4497
4498  and execute it.
4499  A windows typical installer will guide you through the installation process.
4500 \end_layout
4501
4502 \begin_layout Subsection
4503 VPATH
4504 \begin_inset LatexCommand \index{VPATH}
4505
4506 \end_inset
4507
4508  feature
4509 \end_layout
4510
4511 \begin_layout Standard
4512 SDCC supports the VPATH feature provided by configure and make.
4513  It allows to separate the source and build trees.
4514  Here's an example:
4515 \end_layout
4516
4517 \begin_layout Standard
4518
4519 \family typewriter
4520 cd ~\InsetSpace ~
4521 \InsetSpace ~
4522 \InsetSpace ~
4523 \InsetSpace ~
4524 \InsetSpace ~
4525 \InsetSpace ~
4526 \InsetSpace ~
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 \InsetSpace ~
4530 \InsetSpace ~
4531 \InsetSpace ~
4532 \InsetSpace ~
4533 \InsetSpace ~
4534 \InsetSpace ~
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 \InsetSpace ~
4538 \InsetSpace ~
4539 \InsetSpace ~
4540 \InsetSpace ~
4541 # cd $HOME
4542 \end_layout
4543
4544 \begin_layout Standard
4545
4546 \family typewriter
4547 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4548 # extract source to directory sdcc
4549 \end_layout
4550
4551 \begin_layout Standard
4552
4553 \family typewriter
4554 mkdir sdcc.build\InsetSpace ~
4555 \InsetSpace ~
4556 \InsetSpace ~
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 \InsetSpace ~
4560 \InsetSpace ~
4561 \InsetSpace ~
4562 \InsetSpace ~
4563 # put output in sdcc.build
4564 \end_layout
4565
4566 \begin_layout Standard
4567
4568 \family typewriter
4569 cd sdcc.build
4570 \end_layout
4571
4572 \begin_layout Standard
4573
4574 \family typewriter
4575 ../sdcc/configure\InsetSpace ~
4576 \InsetSpace ~
4577 \InsetSpace ~
4578 \InsetSpace ~
4579 \InsetSpace ~
4580 \InsetSpace ~
4581 \InsetSpace ~
4582 \InsetSpace ~
4583 # configure is doing all the magic!
4584 \end_layout
4585
4586 \begin_layout Standard
4587
4588 \family typewriter
4589 make
4590 \end_layout
4591
4592 \begin_layout Standard
4593 \noindent
4594 That's it! 
4595 \series bold
4596 configure
4597 \series default
4598  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4599  It automagically computes the variables srcdir, top_srcdir and top_buildir
4600  for each directory.
4601  After running 
4602 \series bold
4603 make
4604 \series default
4605  the generated files will be in ~/sdcc.build, while the source files stay
4606  in ~/sdcc.
4607 \newline
4608 This is not only usefull for building different binaries, e.g.
4609  when cross compiling.
4610  It also gives you a much better overview in the source tree when all the
4611  generated files are not scattered between the source files.
4612  And the best thing is: if you want to change a file you can leave the original
4613  file untouched in the source directory.
4614  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4615  Makefile.dep` and `make`.
4616  
4617 \series bold
4618 make
4619 \series default
4620  will do the rest for you!
4621 \end_layout
4622
4623 \begin_layout Section
4624 Building the Documentation
4625 \end_layout
4626
4627 \begin_layout Standard
4628 Add -
4629 \begin_inset ERT
4630 status collapsed
4631
4632 \begin_layout Standard
4633
4634
4635 \backslash
4636 /
4637 \end_layout
4638
4639 \end_inset
4640
4641 -enable-doc to the configure arguments to build the documentation together
4642  with all the other stuff.
4643  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4644  dvips and makeindex) to get the job done.
4645  Another possibility is to change to the doc directory and to type 
4646 \family sans
4647 \series bold
4648
4649 \begin_inset Quotes srd
4650 \end_inset
4651
4652 make
4653 \begin_inset Quotes srd
4654 \end_inset
4655
4656
4657 \family default
4658 \series default
4659  there.
4660  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4661 x).
4662  Using LyX 
4663 \begin_inset LatexCommand \url{http://www.lyx.org}
4664
4665 \end_inset
4666
4667  as editor is straightforward.
4668  Prebuilt documentation in html and pdf format is available from 
4669 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4670
4671 \end_inset
4672
4673 .
4674 \end_layout
4675
4676 \begin_layout Section
4677 Reading the Documentation
4678 \begin_inset LatexCommand \index{Documentation}
4679
4680 \end_inset
4681
4682
4683 \end_layout
4684
4685 \begin_layout Standard
4686 Currently reading the document in pdf format is recommended, as for unknown
4687  reason the hyperlinks are working there whereas in the html version they
4688  are not
4689 \begin_inset Foot
4690 status open
4691
4692 \begin_layout Standard
4693 If you should know why please drop us a note
4694 \end_layout
4695
4696 \end_inset
4697
4698 .
4699  
4700 \newline
4701 You'll find the pdf version
4702 \begin_inset LatexCommand \index{PDF version of this document}
4703
4704 \end_inset
4705
4706  at 
4707 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4708
4709 \end_inset
4710
4711 .
4712  
4713 \newline
4714 A html version
4715 \begin_inset LatexCommand \index{HTML version of this document}
4716
4717 \end_inset
4718
4719  should be online at 
4720 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4721
4722 \end_inset
4723
4724 .
4725 \newline
4726 This documentation is in some aspects different from a commercial documentation:
4727  
4728 \end_layout
4729
4730 \begin_layout Itemize
4731 It tries to document SDCC for several processor architectures in one document
4732  (commercially these probably would be separate documents/products).
4733  This document
4734 \begin_inset LatexCommand \index{Status of documentation}
4735
4736 \end_inset
4737
4738  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4739 on about f.e.
4740  Z80, PIC14, PIC16 and HC08.
4741 \end_layout
4742
4743 \begin_layout Itemize
4744 There are many references pointing away from this documentation.
4745  Don't let this distract you.
4746  If there f.e.
4747  was a reference like 
4748 \begin_inset LatexCommand \url{http://www.opencores.org}
4749
4750 \end_inset
4751
4752  together with a statement 
4753 \begin_inset Quotes sld
4754 \end_inset
4755
4756 some processors which are targetted by SDCC can be implemented in a 
4757 \emph on
4758 f
4759 \emph default
4760 ield 
4761 \emph on
4762 p
4763 \emph default
4764 rogrammable 
4765 \emph on
4766 g
4767 \emph default
4768 ate 
4769 \emph on
4770 a
4771 \emph default
4772 rray
4773 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4774
4775 \end_inset
4776
4777
4778 \begin_inset Quotes srd
4779 \end_inset
4780
4781  or 
4782 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4783
4784 \end_inset
4785
4786
4787 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4788
4789 \end_inset
4790
4791  
4792 \begin_inset Quotes sld
4793 \end_inset
4794
4795 have you ever heard of an open source compiler that compiles a subset of
4796  C for an FPGA?
4797 \begin_inset Quotes srd
4798 \end_inset
4799
4800  we expect you to have a quick look there and come back.
4801  If you read this you are on the right track.
4802 \end_layout
4803
4804 \begin_layout Itemize
4805 Some sections attribute more space to problems, restrictions and warnings
4806  than to the solution.
4807 \end_layout
4808
4809 \begin_layout Itemize
4810 The installation section and the section about the debugger is intimidating.
4811 \end_layout
4812
4813 \begin_layout Itemize
4814 There are still lots of typos and there are more different writing styles
4815  than pictures.
4816 \end_layout
4817
4818 \begin_layout Section
4819 Testing the SDCC Compiler
4820 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4821
4822 \end_inset
4823
4824
4825 \end_layout
4826
4827 \begin_layout Standard
4828 The first thing you should do after installing your SDCC compiler is to
4829  see if it runs.
4830  Type 
4831 \family sans
4832 \series bold
4833 "sdcc -
4834 \begin_inset ERT
4835 status collapsed
4836
4837 \begin_layout Standard
4838
4839
4840 \backslash
4841 /
4842 \end_layout
4843
4844 \end_inset
4845
4846 -version"
4847 \begin_inset LatexCommand \index{version}
4848
4849 \end_inset
4850
4851
4852 \family default
4853 \series default
4854  at the prompt, and the program should run and output its version like:
4855  
4856 \newline
4857
4858 \family typewriter
4859 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4860  (UNIX)
4861 \end_layout
4862
4863 \begin_layout Standard
4864 If it doesn't run, or gives a message about not finding sdcc program, then
4865  you need to check over your installation.
4866  Make sure that the sdcc bin directory is in your executable search path
4867  defined by the PATH environment setting (
4868 \series medium
4869 see 
4870 \series default
4871 section 
4872 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4873
4874 \end_inset
4875
4876 \InsetSpace ~
4877
4878 \series medium
4879 Install trouble-shooting for suggestions
4880 \series default
4881 ).
4882  Make sure that the sdcc program is in the bin folder, if not perhaps something
4883  did not install correctly.
4884 \newline
4885
4886 \newline
4887
4888 \series medium
4889 SDCC 
4890 \series default
4891 is commonly installed as described in section 
4892 \begin_inset Quotes sld
4893 \end_inset
4894
4895 Install and search paths
4896 \begin_inset Quotes srd
4897 \end_inset
4898
4899 .
4900 \newline
4901
4902 \newline
4903
4904 \series medium
4905 Make sure the compiler works on a very simple example.
4906  Type in the following test.c program using your favorite 
4907 \series default
4908 ASCII 
4909 \series medium
4910 editor:
4911 \end_layout
4912
4913 \begin_layout Verse
4914
4915 \family typewriter
4916 char test;
4917 \newline
4918
4919 \newline
4920 void main(void) {
4921 \newline
4922 \InsetSpace ~
4923 \InsetSpace ~
4924 \InsetSpace ~
4925 \InsetSpace ~
4926 test=0;
4927 \newline
4928 }
4929 \end_layout
4930
4931 \begin_layout Standard
4932
4933 \series medium
4934 Compile this using the following command: 
4935 \family sans
4936 \series bold
4937 "sdcc -c test.c".
4938
4939 \family default
4940 \series default
4941  
4942 \series medium
4943 If all goes well, the compiler will generate a test.asm and test.rel file.
4944  Congratulations, you've just compiled your first program with SDCC.
4945  We used the -c option to tell SDCC not to link the generated code, just
4946  to keep things simple for this step.
4947 \series default
4948
4949 \newline
4950
4951 \newline
4952
4953 \series medium
4954 The next step is to try it with the linker.
4955  Type in 
4956 \family sans
4957 \series bold
4958 "sdcc test.c
4959 \family default
4960 \series default
4961 "
4962 \series medium
4963 .
4964  If all goes well the compiler will link with the libraries and produce
4965  a test.ihx output file.
4966  If this step fails
4967 \series default
4968  
4969 \series medium
4970 (no test.ihx, and the linker generates warnings), then the problem is most
4971  likely that 
4972 \series default
4973 SDCC
4974 \series medium
4975  cannot find the 
4976 \series default
4977 /
4978 \series medium
4979 usr/local/share/sdcc/lib directory
4980 \series default
4981  
4982 \series medium
4983 (see 
4984 \series default
4985 section 
4986 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4987
4988 \end_inset
4989
4990 \InsetSpace ~
4991
4992 \series medium
4993 Install trouble-shooting for suggestions).
4994 \series default
4995
4996 \newline
4997
4998 \newline
4999
5000 \series medium
5001 The final test is to ensure 
5002 \series default
5003 SDCC
5004 \series medium
5005  can use the 
5006 \series default
5007 standard
5008 \series medium
5009  header files and libraries.
5010  Edit test.c and change it to the following:
5011 \end_layout
5012
5013 \begin_layout Verse
5014
5015 \family typewriter
5016 #include <string.h>
5017 \newline
5018
5019 \newline
5020 char str1[10];
5021 \newline
5022
5023 \newline
5024 void main(void) {
5025 \newline
5026 \InsetSpace ~
5027 \InsetSpace ~
5028 strcpy(str1, "testing");
5029 \newline
5030 }
5031 \end_layout
5032
5033 \begin_layout Standard
5034
5035 \series medium
5036 Compile this by typing 
5037 \family sans
5038 \series bold
5039 "sdcc test.c"
5040 \family default
5041 \series medium
5042 .
5043  This should generate a test.ihx output file, and it should give no warnings
5044  such as not finding the string.h file.
5045  If it cannot find the string.h file, then the problem is that 
5046 \series default
5047 SDCC
5048 \series medium
5049  cannot find the /usr/local/share/sdcc/include directory
5050 \series default
5051  
5052 \series medium
5053 (see the 
5054 \series default
5055 section 
5056 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5057
5058 \end_inset
5059
5060 \InsetSpace ~
5061
5062 \series medium
5063 Install trouble-shooting section for suggestions).
5064
5065 \series default
5066  Use option 
5067 \series bold
5068 -
5069 \begin_inset ERT
5070 status collapsed
5071
5072 \begin_layout Standard
5073
5074
5075 \backslash
5076 /
5077 \end_layout
5078
5079 \end_inset
5080
5081 -print-search-dirs
5082 \series default
5083
5084 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5085
5086 \end_inset
5087
5088  to find exactly where SDCC is looking for the include and lib files.
5089 \end_layout
5090
5091 \begin_layout Section
5092 Install Trouble-shooting
5093 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5094
5095 \end_inset
5096
5097
5098 \begin_inset LatexCommand \index{Install trouble-shooting}
5099
5100 \end_inset
5101
5102
5103 \end_layout
5104
5105 \begin_layout Subsection
5106 If SDCC does not build correctly
5107 \end_layout
5108
5109 \begin_layout Standard
5110 A thing to try is starting from scratch by unpacking the .tgz source package
5111  again in an empty directory.
5112  Configure it like:
5113 \newline
5114
5115 \newline
5116
5117 \family sans
5118 \series bold
5119 ./configure 2>&1 | tee configure.log
5120 \family default
5121 \series default
5122
5123 \newline
5124
5125 \newline
5126 and build it like:
5127 \newline
5128
5129 \newline
5130
5131 \family sans
5132 \series bold
5133 make 2>&1 | tee make.log
5134 \family default
5135 \series default
5136
5137 \newline
5138
5139 \newline
5140 If anything goes wrong, you can review the log files to locate the problem.
5141  Or a relevant part of this can be attached to an email that could be helpful
5142  when requesting help from the mailing list.
5143 \end_layout
5144
5145 \begin_layout Subsection
5146 What the 
5147 \begin_inset Quotes sld
5148 \end_inset
5149
5150 ./configure
5151 \begin_inset Quotes srd
5152 \end_inset
5153
5154  does
5155 \end_layout
5156
5157 \begin_layout Standard
5158 The 
5159 \begin_inset Quotes sld
5160 \end_inset
5161
5162 ./configure
5163 \begin_inset Quotes srd
5164 \end_inset
5165
5166  command is a script that analyzes your system and performs some configuration
5167  to ensure the source package compiles on your system.
5168  It will take a few minutes to run, and will compile a few tests to determine
5169  what compiler features are installed.
5170 \end_layout
5171
5172 \begin_layout Subsection
5173 What the 
5174 \begin_inset Quotes sld
5175 \end_inset
5176
5177 make
5178 \begin_inset Quotes srd
5179 \end_inset
5180
5181  does
5182 \end_layout
5183
5184 \begin_layout Standard
5185 This runs the GNU make tool, which automatically compiles all the source
5186  packages into the final installed binary executables.
5187 \end_layout
5188
5189 \begin_layout Subsection
5190 What the 
5191 \begin_inset Quotes sld
5192 \end_inset
5193
5194 make install
5195 \begin_inset Quotes erd
5196 \end_inset
5197
5198  command does.
5199 \end_layout
5200
5201 \begin_layout Standard
5202 This will install the compiler, other executables libraries and include
5203  files into the appropriate directories.
5204  See sections 
5205 \begin_inset LatexCommand \ref{sub:Install-paths}
5206
5207 \end_inset
5208
5209 ,\InsetSpace ~
5210
5211 \begin_inset LatexCommand \ref{sub:Search-Paths}
5212
5213 \end_inset
5214
5215 \InsetSpace ~
5216 about install and search paths.
5217 \newline
5218 On most systems you will need super-user privilege
5219 s to do this.
5220 \end_layout
5221
5222 \begin_layout Section
5223 Components of SDCC
5224 \end_layout
5225
5226 \begin_layout Standard
5227 SDCC is not just a compiler, but a collection of tools by various developers.
5228  These include linkers, assemblers, simulators and other components.
5229  Here is a summary of some of the components.
5230  Note that the included simulator and assembler have separate documentation
5231  which you can find in the source package in their respective directories.
5232  As SDCC grows to include support for other processors, other packages from
5233  various developers are included and may have their own sets of documentation.
5234 \newline
5235
5236 \newline
5237 You
5238  might want to look at the files which are installed in <installdir>.
5239  At the time of this writing, we find the following programs for gcc-builds:
5240 \newline
5241
5242  
5243 \newline
5244 In <installdir>/bin:
5245 \end_layout
5246
5247 \begin_layout Itemize
5248 sdcc - The compiler.
5249 \end_layout
5250
5251 \begin_layout Itemize
5252 sdcpp - The C preprocessor.
5253 \end_layout
5254
5255 \begin_layout Itemize
5256 asx8051 - The assembler for 8051 type processors.
5257 \end_layout
5258
5259 \begin_layout Itemize
5260 as-z80
5261 \series bold
5262
5263 \series default
5264 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5265 \end_layout
5266
5267 \begin_layout Itemize
5268 aslink -The linker for 8051 type processors.
5269 \end_layout
5270
5271 \begin_layout Itemize
5272 link-z80
5273 \series bold
5274
5275 \series default
5276 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5277 \end_layout
5278
5279 \begin_layout Itemize
5280 s51 - The ucSim 8051 simulator.
5281 \end_layout
5282
5283 \begin_layout Itemize
5284 sdcdb - The source debugger.
5285 \end_layout
5286
5287 \begin_layout Itemize
5288 packihx - A tool to pack (compress) Intel hex files.
5289 \end_layout
5290
5291 \begin_layout Standard
5292 In <installdir>/share/sdcc/include
5293 \end_layout
5294
5295 \begin_layout Itemize
5296 the include files
5297 \end_layout
5298
5299 \begin_layout Standard
5300 In <installdir>/share/sdcc/lib
5301 \end_layout
5302
5303 \begin_layout Itemize
5304 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5305  relocatables.
5306 \end_layout
5307
5308 \begin_layout Standard
5309 In <installdir>/share/sdcc/doc
5310 \end_layout
5311
5312 \begin_layout Itemize
5313 the documentation
5314 \end_layout
5315
5316 \begin_layout Standard
5317 As development for other processors proceeds, this list will expand to include
5318  executables to support processors like AVR, PIC, etc.
5319 \end_layout
5320
5321 \begin_layout Subsection
5322 sdcc - The Compiler
5323 \end_layout
5324
5325 \begin_layout Standard
5326 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5327  the assembler and linkage editor.
5328 \end_layout
5329
5330 \begin_layout Subsection
5331 sdcpp - The C-Preprocessor
5332 \end_layout
5333
5334 \begin_layout Standard
5335 The preprocessor
5336 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5337
5338 \end_inset
5339
5340  is a modified version of the GNU cpp
5341 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5342
5343 \end_inset
5344
5345  preprocessor 
5346 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5347
5348 \end_inset
5349
5350 .
5351  The C preprocessor is used to pull in #include sources, process #ifdef
5352  statements, #defines and so on.
5353 \end_layout
5354
5355 \begin_layout Subsection
5356 as
5357 \emph on
5358 xxxx
5359 \emph default
5360 , aslink, link-
5361 \emph on
5362 xxx
5363 \emph default
5364  - The Assemblers and Linkage Editors
5365 \end_layout
5366
5367 \begin_layout Standard
5368 This is retargettable assembler & linkage editor, it was developed by Alan
5369  Baldwin.
5370  John Hartman created the version for 8051, and I (Sandeep) have made some
5371  enhancements and bug fixes for it to work properly with SDCC.
5372 \end_layout
5373
5374 \begin_layout Subsection
5375 s51 - The Simulator
5376 \end_layout
5377
5378 \begin_layout Standard
5379 S51
5380 \begin_inset LatexCommand \index{s51}
5381
5382 \end_inset
5383
5384  is a free open source simulator developed by Daniel Drotos.
5385  The simulator is built as part of the build process.
5386  For more information visit Daniel's web site at: 
5387 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5388
5389 \end_inset
5390
5391 .
5392  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5393  XA51 family.
5394 \end_layout
5395
5396 \begin_layout Subsection
5397 sdcdb - Source Level Debugger
5398 \end_layout
5399
5400 \begin_layout Standard
5401 SDCDB
5402 \begin_inset LatexCommand \index{SDCDB (debugger)}
5403
5404 \end_inset
5405
5406  is the companion source level debugger.
5407  More about SDCDB in section 
5408 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5409
5410 \end_inset
5411
5412 .
5413  The current version of the debugger uses Daniel's Simulator S51
5414 \begin_inset LatexCommand \index{s51}
5415
5416 \end_inset
5417
5418 , but can be easily changed to use other simulators.
5419 \end_layout
5420
5421 \begin_layout Chapter
5422 Using SDCC
5423 \end_layout
5424
5425 \begin_layout Section
5426 Compiling
5427 \end_layout
5428
5429 \begin_layout Subsection
5430 Single Source File Projects
5431 \end_layout
5432
5433 \begin_layout Standard
5434 For single source file 8051 projects the process is very simple.
5435  Compile your programs with the following command 
5436 \family sans
5437 \series bold
5438 "sdcc sourcefile.c".
5439
5440 \family default
5441 \series default
5442  This will compile, assemble and link your source file.
5443  Output files are as follows:
5444 \end_layout
5445
5446 \begin_layout Itemize
5447 sourcefile.asm
5448 \begin_inset LatexCommand \index{<file>.asm}
5449
5450 \end_inset
5451
5452  - Assembler source
5453 \begin_inset LatexCommand \index{Assembler source}
5454
5455 \end_inset
5456
5457  file created by the compiler
5458 \end_layout
5459
5460 \begin_layout Itemize
5461 sourcefile.lst
5462 \begin_inset LatexCommand \index{<file>.lst}
5463
5464 \end_inset
5465
5466  - Assembler listing
5467 \begin_inset LatexCommand \index{Assembler listing}
5468
5469 \end_inset
5470
5471  file created by the Assembler
5472 \end_layout
5473
5474 \begin_layout Itemize
5475 sourcefile.rst
5476 \begin_inset LatexCommand \index{<file>.rst}
5477
5478 \end_inset
5479
5480  - Assembler listing
5481 \begin_inset LatexCommand \index{Assembler listing}
5482
5483 \end_inset
5484
5485  file updated with linkedit information, created by linkage editor
5486 \end_layout
5487
5488 \begin_layout Itemize
5489 sourcefile.sym
5490 \begin_inset LatexCommand \index{<file>.sym}
5491
5492 \end_inset
5493
5494  - symbol listing
5495 \begin_inset LatexCommand \index{Symbol listing}
5496
5497 \end_inset
5498
5499  for the sourcefile, created by the assembler
5500 \end_layout
5501
5502 \begin_layout Itemize
5503 sourcefile.rel
5504 \begin_inset LatexCommand \index{<file>.rel}
5505
5506 \end_inset
5507
5508  or sourcefile.o
5509 \begin_inset LatexCommand \index{<file>.o}
5510
5511 \end_inset
5512
5513  - Object file
5514 \begin_inset LatexCommand \index{Object file}
5515
5516 \end_inset
5517
5518  created by the assembler, input to Linkage editor
5519 \end_layout
5520
5521 \begin_layout Itemize
5522 sourcefile.map
5523 \begin_inset LatexCommand \index{<file>.map}
5524
5525 \end_inset
5526
5527  - The memory map
5528 \begin_inset LatexCommand \index{Memory map}
5529
5530 \end_inset
5531
5532  for the load module, created by the Linker
5533 \end_layout
5534
5535 \begin_layout Itemize
5536 sourcefile.mem
5537 \begin_inset LatexCommand \index{<file>.mem}
5538
5539 \end_inset
5540
5541  - A file with a summary of the memory usage
5542 \end_layout
5543
5544 \begin_layout Itemize
5545 sourcefile.ihx
5546 \begin_inset LatexCommand \index{<file>.ihx}
5547
5548 \end_inset
5549
5550  - The load module in Intel hex format
5551 \begin_inset LatexCommand \index{Intel hex format}
5552
5553 \end_inset
5554
5555  (you can select the Motorola S19 format
5556 \begin_inset LatexCommand \index{Motorola S19 format}
5557
5558 \end_inset
5559
5560  with -
5561 \begin_inset ERT
5562 status collapsed
5563
5564 \begin_layout Standard
5565
5566
5567 \backslash
5568 /
5569 \end_layout
5570
5571 \end_inset
5572
5573 -out-fmt-s19
5574 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5575
5576 \end_inset
5577
5578 .
5579  If you need another format you might want to use 
5580 \family sans
5581 \shape italic
5582 objdump
5583 \family default
5584 \shape default
5585
5586 \begin_inset LatexCommand \index{objdump (tool)}
5587
5588 \end_inset
5589
5590  or
5591 \family sans
5592 \shape italic
5593  srecord
5594 \family default
5595 \shape default
5596
5597 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5598
5599 \end_inset
5600
5601
5602 \begin_inset Note Note
5603 status collapsed
5604
5605 \begin_layout Standard
5606 hyperlinks needed
5607 \end_layout
5608
5609 \end_inset
5610
5611  - see also section 
5612 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5613
5614 \end_inset
5615
5616 ).
5617  Both formats are documented in the documentation of srecord
5618 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5619
5620 \end_inset
5621
5622
5623 \end_layout
5624
5625 \begin_layout Itemize
5626 sourcefile.adb
5627 \begin_inset LatexCommand \index{<file>.adb}
5628
5629 \end_inset
5630
5631  - An intermediate file containing debug information needed to create the
5632  .cdb file (with -
5633 \begin_inset ERT
5634 status collapsed
5635
5636 \begin_layout Standard
5637
5638
5639 \backslash
5640 /
5641 \end_layout
5642
5643 \end_inset
5644
5645 -debug
5646 \begin_inset LatexCommand \index{-\/-debug}
5647
5648 \end_inset
5649
5650
5651 \end_layout
5652
5653 \begin_layout Itemize
5654 sourcefile.cdb
5655 \begin_inset LatexCommand \index{<file>.cdb}
5656
5657 \end_inset
5658
5659  - An optional file (with -
5660 \begin_inset ERT
5661 status collapsed
5662
5663 \begin_layout Standard
5664
5665
5666 \backslash
5667 /
5668 \end_layout
5669
5670 \end_inset
5671
5672 -debug) containing debug information.
5673  The format is documented in cdbfileformat.pdf
5674 \end_layout
5675
5676 \begin_layout Itemize
5677 sourcefile.
5678  - (no extension)
5679 \begin_inset LatexCommand \index{<file> (no extension)}
5680
5681 \end_inset
5682
5683  An optional AOMF or AOMF51
5684 \begin_inset LatexCommand \index{AOMF, AOMF51}
5685
5686 \end_inset
5687
5688  
5689 \begin_inset LatexCommand \label{OMF file}
5690
5691 \end_inset
5692
5693 file containing debug information (generated with option -
5694 \begin_inset ERT
5695 status collapsed
5696
5697 \begin_layout Standard
5698
5699
5700 \backslash
5701 /
5702 \end_layout
5703
5704 \end_inset
5705
5706 -debug).
5707  The (Intel)
5708 \emph on
5709  a
5710 \emph default
5711 bsolute 
5712 \emph on
5713 o
5714 \emph default
5715 bject 
5716 \emph on
5717 m
5718 \emph default
5719 odule 
5720 \emph on
5721 f
5722 \emph default
5723 ormat is a subformat of the OMF51 format and is commonly used by third party
5724  tools (debuggers
5725 \begin_inset LatexCommand \index{Debugger}
5726
5727 \end_inset
5728
5729 , simulators, emulators).
5730 \end_layout
5731
5732 \begin_layout Itemize
5733 sourcefile.dump*
5734 \begin_inset LatexCommand \index{<file>.dump*}
5735
5736 \end_inset
5737
5738  - Dump file to debug the compiler it self (generated with option -
5739 \begin_inset ERT
5740 status collapsed
5741
5742 \begin_layout Standard
5743
5744
5745 \backslash
5746 /
5747 \end_layout
5748
5749 \end_inset
5750
5751 -dumpall) (see section 
5752 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5753
5754 \end_inset
5755
5756 \InsetSpace ~
5757  and section 
5758 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5759
5760 \end_inset
5761
5762 \InsetSpace ~
5763
5764 \begin_inset Quotes sld
5765 \end_inset
5766
5767 Anatomy of the compiler
5768 \begin_inset Quotes srd
5769 \end_inset
5770
5771 ).
5772 \end_layout
5773
5774 \begin_layout Subsection
5775 Postprocessing the Intel Hex
5776 \begin_inset LatexCommand \index{Intel hex format}
5777
5778 \end_inset
5779
5780  file
5781 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5782
5783 \end_inset
5784
5785
5786 \end_layout
5787
5788 \begin_layout Standard
5789 In most cases this won't be needed but the Intel Hex file
5790 \begin_inset LatexCommand \index{<file>.ihx}
5791
5792 \end_inset
5793
5794  which is generated by SDCC might include lines of varying length and the
5795  addresses within the file are not guaranteed to be strictly ascending.
5796  If your toolchain or a bootloader does not like this you can use the tool
5797  
5798 \family typewriter
5799 packihx
5800 \family default
5801
5802 \begin_inset LatexCommand \index{packihx (tool)}
5803
5804 \end_inset
5805
5806  which is part of the SDCC distribution: 
5807 \newline
5808
5809 \newline
5810
5811 \family sans
5812 \series bold
5813  packihx sourcefile.ihx >sourcefile.hex
5814 \family default
5815 \series default
5816
5817 \newline
5818
5819 \newline
5820 The separately available
5821 \emph on
5822  srecord
5823 \emph default
5824
5825 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5826
5827 \end_inset
5828
5829  package additionally allows to set undefined locations to a predefined
5830  value, to insert checksums
5831 \begin_inset LatexCommand \index{checksum}
5832
5833 \end_inset
5834
5835  of various flavours (crc, add, xor) and to perform other manipulations
5836  (convert, split, crop, offset, ...).
5837  
5838 \newline
5839
5840 \newline
5841
5842 \family sans
5843 \series bold
5844 srec_cat\InsetSpace ~
5845 \InsetSpace ~
5846 sourcefile.ihx -intel\InsetSpace ~
5847 \InsetSpace ~
5848 -o sourcefile.hex -intel
5849 \newline
5850
5851 \newline
5852
5853 \family default
5854 \series default
5855 An example for a more complex command line
5856 \begin_inset Foot
5857 status open
5858
5859 \begin_layout Standard
5860 the command backfills
5861 \begin_inset LatexCommand \index{backfill unused memory}
5862
5863 \end_inset
5864
5865  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5866  block is zero.
5867  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5868  will be interpreted as an 
5869 \family typewriter
5870 lcall
5871 \family default
5872  to address 
5873 \family typewriter
5874 0x1212
5875 \family default
5876  (where an emergency routine could sit).
5877 \end_layout
5878
5879 \end_inset
5880
5881  could look like:
5882 \newline
5883
5884 \newline
5885
5886 \family sans
5887 \series bold
5888 \size footnotesize
5889 srec_cat\InsetSpace ~
5890 sourcefile.ihx -intel\InsetSpace ~
5891 \InsetSpace ~
5892 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5893 -little-endian-checksum-nega
5894 tive 0xfffe 0x02 0x02\InsetSpace ~
5895 \InsetSpace ~
5896 -o sourcefile.hex -intel
5897 \size default
5898
5899 \newline
5900
5901 \newline
5902
5903 \family default
5904 \series default
5905 The srecord package is available at 
5906 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5907
5908 \end_inset
5909
5910  .
5911 \end_layout
5912
5913 \begin_layout Subsection
5914 Projects with Multiple Source Files
5915 \end_layout
5916
5917 \begin_layout Standard
5918 SDCC can compile only ONE file at a time.
5919  Let us for example assume that you have a project containing the following
5920  files:
5921 \newline
5922
5923 \newline
5924 foo1.c (contains some functions)
5925 \newline
5926 foo2.c (contains some more functions)
5927 \newline
5928 foomai
5929 n.c (contains more functions and the function main)
5930 \newline
5931
5932 \size footnotesize
5933
5934 \newline
5935
5936 \size default
5937 The first two files will need to be compiled separately with the commands:
5938 \size footnotesize
5939  
5940 \size default
5941
5942 \newline
5943
5944 \newline
5945
5946 \family sans
5947 \series bold
5948 sdcc\InsetSpace ~
5949 -c\InsetSpace ~
5950 foo1.c
5951 \family default
5952 \series default
5953 \size footnotesize
5954
5955 \newline
5956
5957 \family sans
5958 \series bold
5959 \size default
5960 sdcc\InsetSpace ~
5961 -c\InsetSpace ~
5962 foo2.c
5963 \family default
5964 \series default
5965
5966 \newline
5967
5968 \newline
5969 Then compile the source file containing the 
5970 \emph on
5971 main()
5972 \emph default
5973  function and link
5974 \begin_inset LatexCommand \index{Linker}
5975
5976 \end_inset
5977
5978  the files together with the following command: 
5979 \newline
5980
5981 \newline
5982
5983 \family sans
5984 \series bold
5985 sdcc\InsetSpace ~
5986 foomain.c\InsetSpace ~
5987 foo1.rel\InsetSpace ~
5988 foo2.rel
5989 \family default
5990 \series default
5991
5992 \begin_inset LatexCommand \index{<file>.rel}
5993
5994 \end_inset
5995
5996
5997 \newline
5998
5999 \newline
6000 Alternatively, 
6001 \emph on
6002 foomain.c 
6003 \emph default
6004 can be separately compiled as well: 
6005 \family sans
6006 \series bold
6007
6008 \newline
6009
6010 \newline
6011 sdcc\InsetSpace ~
6012 -c\InsetSpace ~
6013 foomain.c
6014 \newline
6015 sdcc foomain.rel foo1.rel foo2.rel
6016 \newline
6017
6018 \newline
6019
6020 \family default
6021 \series default
6022 The file containing the 
6023 \emph on
6024 main()
6025 \emph default
6026  function
6027 \emph on
6028  
6029 \emph default
6030 \noun on
6031 must
6032 \noun default
6033  be the 
6034 \noun on
6035 first
6036 \noun default
6037  file specified in the command line, since the linkage editor processes
6038  file in the order they are presented to it.
6039  The linker is invoked from SDCC using a script file with extension .lnk
6040 \begin_inset LatexCommand \index{<file>.lnk}
6041
6042 \end_inset
6043
6044 .
6045  You can view this file to troubleshoot linking problems such as those arising
6046  from missing libraries.
6047 \end_layout
6048
6049 \begin_layout Subsection
6050 Projects with Additional Libraries
6051 \begin_inset LatexCommand \index{Libraries}
6052
6053 \end_inset
6054
6055
6056 \end_layout
6057
6058 \begin_layout Standard
6059 Some reusable routines may be compiled into a library, see the documentation
6060  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6061  for how to create a 
6062 \emph on
6063 .lib
6064 \begin_inset LatexCommand \index{<file>.lib}
6065
6066 \end_inset
6067
6068
6069 \emph default
6070  library file.
6071  Libraries created in this manner can be included in the command line.
6072  Make sure you include the -L <library-path> option to tell the linker where
6073  to look for these files if they are not in the current directory.
6074  Here is an example, assuming you have the source file 
6075 \emph on
6076 foomain.c
6077 \emph default
6078  and a library
6079 \emph on
6080  foolib.lib
6081 \emph default
6082  in the directory 
6083 \emph on
6084 mylib
6085 \emph default
6086  (if that is not the same as your current project):
6087 \newline
6088
6089 \newline
6090
6091 \family sans
6092 \series bold
6093 sdcc foomain.c foolib.lib -L mylib
6094 \newline
6095
6096 \newline
6097
6098 \family default
6099 \series default
6100 Note here that
6101 \emph on
6102  mylib
6103 \emph default
6104  must be an absolute path name.
6105 \newline
6106
6107 \newline
6108 The most efficient way to use libraries is
6109  to keep separate modules in separate source files.
6110  The lib file now should name all the modules.rel
6111 \begin_inset LatexCommand \index{<file>.rel}
6112
6113 \end_inset
6114
6115  files.
6116  For an example see the standard library file 
6117 \emph on
6118 libsdcc.lib
6119 \emph default
6120  in the directory <installdir>/share/lib/small.
6121 \end_layout
6122
6123 \begin_layout Subsection
6124 Using sdcclib to Create and Manage Libraries
6125 \begin_inset LatexCommand \index{sdcclib}
6126
6127 \end_inset
6128
6129
6130 \end_layout
6131
6132 \begin_layout Standard
6133 Alternatively, instead of having a .rel file for each entry on the library
6134  file as described in the preceding section, sdcclib can be used to embed
6135  all the modules belonging to such library in the library file itself.
6136  This results in a larger library file, but it greatly reduces the number
6137  of disk files accessed by the linker.
6138   Additionally, the packed library file contains an index of all include
6139  modules and symbols that significantly speeds up the linking process.
6140  To display a list of options supported by sdcclib type:
6141 \newline
6142
6143 \end_layout
6144
6145 \begin_layout Standard
6146
6147 \family sans
6148 \series bold
6149 sdcclib -?
6150 \begin_inset LatexCommand \index{sdcclib}
6151
6152 \end_inset
6153
6154
6155 \newline
6156
6157 \newline
6158
6159 \family default
6160 \series default
6161 To create a new library file, start by compiling all the required modules.
6162  For example:
6163 \newline
6164
6165 \end_layout
6166
6167 \begin_layout Standard
6168
6169 \family sans
6170 \series bold
6171 sdcc -c _divsint.c
6172 \end_layout
6173
6174 \begin_layout Standard
6175
6176 \family sans
6177 \series bold
6178 sdcc -c _divuint.c
6179 \end_layout
6180
6181 \begin_layout Standard
6182
6183 \family sans
6184 \series bold
6185 sdcc -c _modsint.c
6186 \end_layout
6187
6188 \begin_layout Standard
6189
6190 \family sans
6191 \series bold
6192 sdcc -c _moduint.c
6193 \end_layout
6194
6195 \begin_layout Standard
6196
6197 \family sans
6198 \series bold
6199 sdcc -c _mulint.c
6200 \newline
6201
6202 \end_layout
6203
6204 \begin_layout Standard
6205 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6206  and _mulint.rel.
6207  The next step is to add the .rel files to the library file:
6208 \newline
6209
6210 \end_layout
6211
6212 \begin_layout Standard
6213
6214 \family sans
6215 \series bold
6216 sdcclib libint.lib _divsint.rel
6217 \family default
6218
6219 \begin_inset LatexCommand \index{sdcclib}
6220
6221 \end_inset
6222
6223
6224 \end_layout
6225
6226 \begin_layout Standard
6227
6228 \family sans
6229 \series bold
6230 sdcclib libint.lib _divuint.rel
6231 \end_layout
6232
6233 \begin_layout Standard
6234
6235 \family sans
6236 \series bold
6237 sdcclib libint.lib _modsint.rel
6238 \end_layout
6239
6240 \begin_layout Standard
6241
6242 \family sans
6243 \series bold
6244 sdcclib libint.lib _moduint.rel
6245 \end_layout
6246
6247 \begin_layout Standard
6248
6249 \family sans
6250 \series bold
6251 sdcclib libint.lib _mulint.rel
6252 \series default
6253
6254 \newline
6255
6256 \end_layout
6257
6258 \begin_layout Standard
6259 If the file already exists in the library, it will be replaced.
6260  To see what modules and symbols are included in the library, options -s
6261  and -m are available.
6262  For example:
6263 \newline
6264
6265 \newline
6266
6267 \family sans
6268 \series bold
6269 sdcclib -s libint.lib
6270 \family default
6271
6272 \begin_inset LatexCommand \index{sdcclib}
6273
6274 \end_inset
6275
6276
6277 \newline
6278
6279 \family typewriter
6280 \series default
6281 _divsint.rel:
6282 \end_layout
6283
6284 \begin_layout Standard
6285
6286 \family typewriter
6287 __divsint_a_1_1
6288 \end_layout
6289
6290 \begin_layout Standard
6291
6292 \family typewriter
6293 __divsint_PARM_2
6294 \end_layout
6295
6296 \begin_layout Standard
6297
6298 \family typewriter
6299 __divsint
6300 \newline
6301 _divuint.rel:
6302 \end_layout
6303
6304 \begin_layout Standard
6305
6306 \family typewriter
6307 __divuint_a_1_1
6308 \end_layout
6309
6310 \begin_layout Standard
6311
6312 \family typewriter
6313 __divuint_PARM_2
6314 \end_layout
6315
6316 \begin_layout Standard
6317
6318 \family typewriter
6319 __divuint_reste_1_1
6320 \end_layout
6321
6322 \begin_layout Standard
6323
6324 \family typewriter
6325 __divuint_count_1_1
6326 \end_layout
6327
6328 \begin_layout Standard
6329
6330 \family typewriter
6331 __divuint
6332 \newline
6333 _modsint.rel:
6334 \end_layout
6335
6336 \begin_layout Standard
6337
6338 \family typewriter
6339 __modsint_a_1_1
6340 \end_layout
6341
6342 \begin_layout Standard
6343
6344 \family typewriter
6345 __modsint_PARM_2
6346 \end_layout
6347
6348 \begin_layout Standard
6349
6350 \family typewriter
6351 __modsint
6352 \newline
6353 _moduint.rel:
6354 \end_layout
6355
6356 \begin_layout Standard
6357
6358 \family typewriter
6359 __moduint_a_1_1
6360 \end_layout
6361
6362 \begin_layout Standard
6363
6364 \family typewriter
6365 __moduint_PARM_2
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family typewriter
6371 __moduint_count_1_1
6372 \end_layout
6373
6374 \begin_layout Standard
6375
6376 \family typewriter
6377 __moduint
6378 \newline
6379 _mulint.rel:
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family typewriter
6385 __mulint_PARM_2
6386 \end_layout
6387
6388 \begin_layout Standard
6389
6390 \family typewriter
6391 __mulint
6392 \family default
6393 \series bold
6394
6395 \newline
6396
6397 \end_layout
6398
6399 \begin_layout Standard
6400 If the source files are compiled using -
6401 \begin_inset ERT
6402 status collapsed
6403
6404 \begin_layout Standard
6405
6406
6407 \backslash
6408 /
6409 \end_layout
6410
6411 \end_inset
6412
6413 -debug
6414 \begin_inset LatexCommand \index{-\/-debug}
6415
6416 \end_inset
6417
6418 , the corresponding debug information file .adb will be include in the library
6419  file as well.
6420  The library files created with sdcclib are plain text files, so they can
6421  be viewed with a text editor.
6422  It is not recomended to modify a library file created with sdcclib using
6423  a text editor, as there are file indexes numbers located accross the file
6424  used by the linker to quickly locate the required module to link.
6425  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6426  it can be safely deleted, since all the information required for linking
6427  is embedded in the library file itself.
6428  Library files created using sdcclib are used as described in the preceding
6429  sections.
6430 \begin_inset VSpace bigskip
6431 \end_inset
6432
6433
6434 \end_layout
6435
6436 \begin_layout Section
6437 Command Line Options
6438 \begin_inset LatexCommand \index{Command Line Options}
6439
6440 \end_inset
6441
6442
6443 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6444
6445 \end_inset
6446
6447
6448 \end_layout
6449
6450 \begin_layout Subsection
6451 Processor Selection Options
6452 \begin_inset LatexCommand \index{Options processor selection}
6453
6454 \end_inset
6455
6456
6457 \begin_inset LatexCommand \index{Processor selection options}
6458
6459 \end_inset
6460
6461
6462 \end_layout
6463
6464 \begin_layout List
6465 \labelwidthstring 00.00.0000
6466
6467 \series bold
6468 -mmcs51
6469 \begin_inset LatexCommand \index{-mmcs51}
6470
6471 \end_inset
6472
6473
6474 \series default
6475  Generate code for the Intel MCS51
6476 \begin_inset LatexCommand \index{MCS51}
6477
6478 \end_inset
6479
6480  family of processors.
6481  This is the default processor target.
6482 \end_layout
6483
6484 \begin_layout List
6485 \labelwidthstring 00.00.0000
6486
6487 \series bold
6488 -mds390
6489 \begin_inset LatexCommand \index{-mds390}
6490
6491 \end_inset
6492
6493
6494 \series default
6495  Generate code for the Dallas DS80C390
6496 \begin_inset LatexCommand \index{DS80C390}
6497
6498 \end_inset
6499
6500  processor.
6501 \end_layout
6502
6503 \begin_layout List
6504 \labelwidthstring 00.00.0000
6505
6506 \series bold
6507 -mds400
6508 \begin_inset LatexCommand \index{-mds400}
6509
6510 \end_inset
6511
6512
6513 \series default
6514  Generate code for the Dallas DS80C400
6515 \begin_inset LatexCommand \index{DS80C400}
6516
6517 \end_inset
6518
6519  processor.
6520 \end_layout
6521
6522 \begin_layout List
6523 \labelwidthstring 00.00.0000
6524
6525 \series bold
6526 -mhc08
6527 \begin_inset LatexCommand \index{-mhc08}
6528
6529 \end_inset
6530
6531
6532 \series default
6533  Generate code for the Freescale/Motorola HC08
6534 \begin_inset LatexCommand \index{HC08}
6535
6536 \end_inset
6537
6538  family of processors.
6539 \end_layout
6540
6541 \begin_layout List
6542 \labelwidthstring 00.00.0000
6543
6544 \series bold
6545 -mz80
6546 \begin_inset LatexCommand \index{-mz80}
6547
6548 \end_inset
6549
6550
6551 \series default
6552  Generate code for the Zilog Z80
6553 \begin_inset LatexCommand \index{Z80}
6554
6555 \end_inset
6556
6557  family of processors.
6558 \end_layout
6559
6560 \begin_layout List
6561 \labelwidthstring 00.00.0000
6562
6563 \series bold
6564 -mgbz80
6565 \begin_inset LatexCommand \index{-mgbz80}
6566
6567 \end_inset
6568
6569
6570 \series default
6571  Generate code for the GameBoy Z80
6572 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6573
6574 \end_inset
6575
6576  processor (Not actively maintained).
6577 \end_layout
6578
6579 \begin_layout List
6580 \labelwidthstring 00.00.0000
6581
6582 \series bold
6583 -mavr
6584 \begin_inset LatexCommand \index{-mavr}
6585
6586 \end_inset
6587
6588
6589 \series default
6590  Generate code for the Atmel AVR
6591 \begin_inset LatexCommand \index{AVR}
6592
6593 \end_inset
6594
6595  processor (Not maintained, not complete).
6596  AVR users should probably have a look at winavr 
6597 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6598
6599 \end_inset
6600
6601  or 
6602 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6603
6604 \end_inset
6605
6606 , which is based on AVR-port of the gcc compiler.
6607 \end_layout
6608
6609 \begin_layout Standard
6610 \begin_inset Note Note
6611 status collapsed
6612
6613 \begin_layout Standard
6614 I think it is fair to direct users there for now.
6615  Open source is also about avoiding unnecessary work .
6616  But I didn't find the 'official' link.
6617 \end_layout
6618
6619 \end_inset
6620
6621
6622 \end_layout
6623
6624 \begin_layout List
6625 \labelwidthstring 00.00.0000
6626
6627 \series bold
6628 -mpic14
6629 \begin_inset LatexCommand \index{-mpic14}
6630
6631 \end_inset
6632
6633
6634 \series default
6635  Generate code for the Microchip PIC 14
6636 \begin_inset LatexCommand \index{PIC14}
6637
6638 \end_inset
6639
6640 -bit processors (p16f84 and variants.
6641  In development, not complete).
6642 \end_layout
6643
6644 \begin_layout Standard
6645 \begin_inset Note Note
6646 status collapsed
6647
6648 \begin_layout Standard
6649 p16f627 p16f628 p16f84 p16f873 p16f877?
6650 \end_layout
6651
6652 \end_inset
6653
6654
6655 \end_layout
6656
6657 \begin_layout List
6658 \labelwidthstring 00.00.0000
6659
6660 \series bold
6661 -mpic16
6662 \begin_inset LatexCommand \index{-mpic16}
6663
6664 \end_inset
6665
6666
6667 \series default
6668  Generate code for the Microchip PIC 16
6669 \begin_inset LatexCommand \index{PIC16}
6670
6671 \end_inset
6672
6673 -bit processors (p18f452 and variants.
6674  In development, not complete).
6675 \end_layout
6676
6677 \begin_layout List
6678 \labelwidthstring 00.00.0000
6679
6680 \series bold
6681 -mtlcs900h
6682 \series default
6683  Generate code for the Toshiba TLCS-900H
6684 \begin_inset LatexCommand \index{TLCS-900H}
6685
6686 \end_inset
6687
6688  processor (Not maintained, not complete).
6689 \end_layout
6690
6691 \begin_layout List
6692 \labelwidthstring 00.00.0000
6693
6694 \series bold
6695 -mxa51
6696 \begin_inset LatexCommand \index{-mxa51}
6697
6698 \end_inset
6699
6700
6701 \series default
6702  Generate code for the Phillips XA51
6703 \begin_inset LatexCommand \index{XA51}
6704
6705 \end_inset
6706
6707  processor (Not maintained, not complete).
6708 \end_layout
6709
6710 \begin_layout Standard
6711 \begin_inset VSpace bigskip
6712 \end_inset
6713
6714
6715 \end_layout
6716
6717 \begin_layout Subsection
6718 Preprocessor Options
6719 \begin_inset LatexCommand \index{Options preprocessor}
6720
6721 \end_inset
6722
6723
6724 \begin_inset LatexCommand \index{Preprocessor options}
6725
6726 \end_inset
6727
6728
6729 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6730
6731 \end_inset
6732
6733
6734 \end_layout
6735
6736 \begin_layout List
6737 \labelwidthstring 00.00.0000
6738
6739 \series bold
6740 -I<path>
6741 \begin_inset LatexCommand \index{-I<path>}
6742
6743 \end_inset
6744
6745
6746 \series default
6747  The additional location where the preprocessor will look for <..h> or 
6748 \begin_inset Quotes eld
6749 \end_inset
6750
6751 ..h
6752 \begin_inset Quotes erd
6753 \end_inset
6754
6755  files.
6756 \end_layout
6757
6758 \begin_layout List
6759 \labelwidthstring 00.00.0000
6760
6761 \series bold
6762 -D<macro[=value]>
6763 \begin_inset LatexCommand \index{-D<macro[=value]>}
6764
6765 \end_inset
6766
6767
6768 \series default
6769  Command line definition of macros.
6770  Passed to the preprocessor.
6771 \end_layout
6772
6773 \begin_layout List
6774 \labelwidthstring 00.00.0000
6775
6776 \series bold
6777 -M
6778 \begin_inset LatexCommand \index{-M}
6779
6780 \end_inset
6781
6782
6783 \series default
6784  Tell the preprocessor to output a rule suitable for make describing the
6785  dependencies of each object file.
6786  For each source file, the preprocessor outputs one make-rule whose target
6787  is the object file name for that source file and whose dependencies are
6788  all the files `#include'd in it.
6789  This rule may be a single line or may be continued with `
6790 \backslash
6791 '-newline if it is long.
6792  The list of rules is printed on standard output instead of the preprocessed
6793  C program.
6794  `-M' implies `-E
6795 \begin_inset LatexCommand \index{-E}
6796
6797 \end_inset
6798
6799 '.
6800 \end_layout
6801
6802 \begin_layout List
6803 \labelwidthstring 00.00.0000
6804
6805 \series bold
6806 -C
6807 \begin_inset LatexCommand \index{-C}
6808
6809 \end_inset
6810
6811
6812 \series default
6813  Tell the preprocessor not to discard comments.
6814  Used with the `-E' option.
6815 \end_layout
6816
6817 \begin_layout List
6818 \labelwidthstring 00.00.0000
6819
6820 \series bold
6821 -MM
6822 \begin_inset LatexCommand \index{-MM}
6823
6824 \end_inset
6825
6826
6827 \size large
6828 \bar under
6829  
6830 \series default
6831 \size default
6832 \bar default
6833 Like `-M' but the output mentions only the user header files included with
6834  `#include 
6835 \begin_inset Quotes eld
6836 \end_inset
6837
6838 file"'.
6839  System header files included with `#include <file>' are omitted.
6840 \end_layout
6841
6842 \begin_layout List
6843 \labelwidthstring 00.00.0000
6844
6845 \series bold
6846 -Aquestion(answer)
6847 \begin_inset LatexCommand \index{-Aquestion(answer)}
6848
6849 \end_inset
6850
6851
6852 \series default
6853  Assert the answer answer for question, in case it is tested with a preprocessor
6854  conditional such as `#if #question(answer)'.
6855  `-A-' disables the standard assertions that normally describe the target
6856  machine.
6857 \end_layout
6858
6859 \begin_layout List
6860 \labelwidthstring 00.00.0000
6861
6862 \series bold
6863 -Umacro
6864 \begin_inset LatexCommand \index{-Umacro}
6865
6866 \end_inset
6867
6868
6869 \series default
6870  Undefine macro macro.
6871  `-U' options are evaluated after all `-D' options, but before any `-include'
6872  and `-imacros' options.
6873 \end_layout
6874
6875 \begin_layout List
6876 \labelwidthstring 00.00.0000
6877
6878 \series bold
6879 -dM
6880 \begin_inset LatexCommand \index{-dM}
6881
6882 \end_inset
6883
6884
6885 \series default
6886  Tell the preprocessor to output only a list of the macro definitions that
6887  are in effect at the end of preprocessing.
6888  Used with the `-E' option.
6889 \end_layout
6890
6891 \begin_layout List
6892 \labelwidthstring 00.00.0000
6893
6894 \series bold
6895 -dD
6896 \begin_inset LatexCommand \index{-dD}
6897
6898 \end_inset
6899
6900
6901 \series default
6902  Tell the preprocessor to pass all macro definitions into the output, in
6903  their proper sequence in the rest of the output.
6904 \end_layout
6905
6906 \begin_layout List
6907 \labelwidthstring 00.00.0000
6908
6909 \series bold
6910 -dN
6911 \begin_inset LatexCommand \index{-dN}
6912
6913 \end_inset
6914
6915
6916 \size large
6917 \bar under
6918  
6919 \series default
6920 \size default
6921 \bar default
6922 Like `-dD' except that the macro arguments and contents are omitted.
6923  Only `#define name' is included in the output.
6924 \end_layout
6925
6926 \begin_layout List
6927 \labelwidthstring 00.00.0000
6928
6929 \series bold
6930 -pedantic-parse-number
6931 \begin_inset LatexCommand \index{pedantic}
6932
6933 \end_inset
6934
6935
6936 \begin_inset LatexCommand \index{-pedantic-parse-number}
6937
6938 \end_inset
6939
6940
6941 \size large
6942 \bar under
6943
6944 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6945
6946 \end_inset
6947
6948  
6949 \series default
6950 \size default
6951 \bar default
6952 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6953  and the macro LO_B(3) gets expanded.
6954  See also #pragma pedantic_parse_number 
6955 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6956
6957 \end_inset
6958
6959  in section
6960 \begin_inset LatexCommand \ref{sec:Pragmas}
6961
6962 \end_inset
6963
6964  
6965 \emph on
6966 Note: this functionality is not in conformance with C99 standard!
6967 \end_layout
6968
6969 \begin_layout List
6970 \labelwidthstring 00.00.0000
6971
6972 \series bold
6973 -Wp\InsetSpace ~
6974 preprocessorOption[,preprocessorOption]
6975 \series default
6976
6977 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6978
6979 \end_inset
6980
6981 ...
6982  Pass the preprocessorOption to the preprocessor 
6983 \family typewriter
6984 sdcpp
6985 \family default
6986
6987 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6988
6989 \end_inset
6990
6991 .
6992  SDCC uses an adapted version of the preprocessor 
6993 \emph on
6994 cpp
6995 \emph default
6996  of the GNU Compiler Collection
6997 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6998
6999 \end_inset
7000
7001  (
7002 \emph on
7003 gcc
7004 \emph default
7005  
7006 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7007
7008 \end_inset
7009
7010 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7011 4.1.1\InsetSpace ~
7012 CPP\InsetSpace ~
7013 Manual
7014  at 
7015 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7016
7017 \end_inset
7018
7019 .
7020 \end_layout
7021
7022 \begin_layout Standard
7023 \begin_inset VSpace bigskip
7024 \end_inset
7025
7026
7027 \end_layout
7028
7029 \begin_layout Subsection
7030 Linker Options
7031 \begin_inset LatexCommand \index{Options linker}
7032
7033 \end_inset
7034
7035
7036 \begin_inset LatexCommand \index{Linker options}
7037
7038 \end_inset
7039
7040
7041 \end_layout
7042
7043 \begin_layout List
7044 \labelwidthstring 00.00.0000
7045
7046 \series bold
7047 -L\InsetSpace ~
7048 -
7049 \series default
7050
7051 \begin_inset ERT
7052 status collapsed
7053
7054 \begin_layout Standard
7055
7056
7057 \backslash
7058 /
7059 \end_layout
7060
7061 \end_inset
7062
7063
7064 \series bold
7065 -lib-path
7066 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7067
7068 \end_inset
7069
7070
7071 \begin_inset LatexCommand \index{-L -\/-lib-path}
7072
7073 \end_inset
7074
7075
7076 \series default
7077 \InsetSpace ~
7078 <absolute path to additional libraries> This option is passed to the linkage
7079  editor's additional libraries
7080 \begin_inset LatexCommand \index{Libraries}
7081
7082 \end_inset
7083
7084  search path.
7085  The path name must be absolute.
7086  Additional library files may be specified in the command line.
7087  See section Compiling programs for more details.
7088 \end_layout
7089
7090 \begin_layout List
7091 \labelwidthstring 00.00.0000
7092
7093 \series bold
7094 -
7095 \begin_inset ERT
7096 status collapsed
7097
7098 \begin_layout Standard
7099
7100
7101 \backslash
7102 /
7103 \end_layout
7104
7105 \end_inset
7106
7107 -xram-loc
7108 \series default
7109
7110 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7111
7112 \end_inset
7113
7114 \InsetSpace ~
7115 <Value> The start location of the external ram
7116 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7117
7118 \end_inset
7119
7120 , default value is 0.
7121  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7122 \begin_inset ERT
7123 status collapsed
7124
7125 \begin_layout Standard
7126
7127
7128 \backslash
7129 /
7130 \end_layout
7131
7132 \end_inset
7133
7134 -xram-loc 0x8000 or -
7135 \begin_inset ERT
7136 status collapsed
7137
7138 \begin_layout Standard
7139
7140
7141 \backslash
7142 /
7143 \end_layout
7144
7145 \end_inset
7146
7147 -xram-loc 32768.
7148 \end_layout
7149
7150 \begin_layout List
7151 \labelwidthstring 00.00.0000
7152
7153 \series bold
7154 -
7155 \begin_inset ERT
7156 status collapsed
7157
7158 \begin_layout Standard
7159
7160
7161 \backslash
7162 /
7163 \end_layout
7164
7165 \end_inset
7166
7167 -code-loc
7168 \series default
7169
7170 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7171
7172 \end_inset
7173
7174 \InsetSpace ~
7175 <Value> The start location of the code
7176 \begin_inset LatexCommand \index{code}
7177
7178 \end_inset
7179
7180  segment, default value 0.
7181  Note when this option is used the interrupt vector table
7182 \begin_inset LatexCommand \index{interrupt vector table}
7183
7184 \end_inset
7185
7186  is also relocated to the given address.
7187  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7188 \begin_inset ERT
7189 status collapsed
7190
7191 \begin_layout Standard
7192
7193
7194 \backslash
7195 /
7196 \end_layout
7197
7198 \end_inset
7199
7200 -code-loc 0x8000 or -
7201 \begin_inset ERT
7202 status collapsed
7203
7204 \begin_layout Standard
7205
7206
7207 \backslash
7208 /
7209 \end_layout
7210
7211 \end_inset
7212
7213 -code-loc 32768.
7214 \end_layout
7215
7216 \begin_layout List
7217 \labelwidthstring 00.00.0000
7218
7219 \series bold
7220 -
7221 \begin_inset ERT
7222 status collapsed
7223
7224 \begin_layout Standard
7225
7226
7227 \backslash
7228 /
7229 \end_layout
7230
7231 \end_inset
7232
7233 -stack-loc
7234 \series default
7235
7236 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7237
7238 \end_inset
7239
7240 \InsetSpace ~
7241 <Value> By default the stack
7242 \begin_inset LatexCommand \index{stack}
7243
7244 \end_inset
7245
7246  is placed after the data segment.
7247  Using this option the stack can be placed anywhere in the internal memory
7248  space of the 8051.
7249  The value entered can be in Hexadecimal or Decimal format, e.g.
7250  -
7251 \begin_inset ERT
7252 status collapsed
7253
7254 \begin_layout Standard
7255
7256
7257 \backslash
7258 /
7259 \end_layout
7260
7261 \end_inset
7262
7263 -stack-loc 0x20 or -
7264 \begin_inset ERT
7265 status collapsed
7266
7267 \begin_layout Standard
7268
7269
7270 \backslash
7271 /
7272 \end_layout
7273
7274 \end_inset
7275
7276 -stack-loc 32.
7277  Since the sp register is incremented before a push or call, the initial
7278  sp will be set to one byte prior the provided value.
7279  The provided value should not overlap any other memory areas such as used
7280  register banks or the data segment and with enough space for the current
7281  application.
7282  The 
7283 \series bold
7284 -
7285 \begin_inset ERT
7286 status collapsed
7287
7288 \begin_layout Standard
7289
7290
7291 \backslash
7292 /
7293 \end_layout
7294
7295 \end_inset
7296
7297 -pack-iram
7298 \series default
7299 \InsetSpace ~
7300
7301 \begin_inset LatexCommand \index{-\/-pack-iram}
7302
7303 \end_inset
7304
7305  option (which is now a default setting) will override this setting, so
7306  you should also specify the 
7307 \series bold
7308 -
7309 \begin_inset ERT
7310 status collapsed
7311
7312 \begin_layout Standard
7313
7314
7315 \backslash
7316 /
7317 \end_layout
7318
7319 \end_inset
7320
7321 -no-pack-iram
7322 \series default
7323 \InsetSpace ~
7324
7325 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7326
7327 \end_inset
7328
7329  option if you need to manually place the stack.
7330 \end_layout
7331
7332 \begin_layout List
7333 \labelwidthstring 00.00.0000
7334
7335 \series bold
7336 -
7337 \begin_inset ERT
7338 status collapsed
7339
7340 \begin_layout Standard
7341
7342
7343 \backslash
7344 /
7345 \end_layout
7346
7347 \end_inset
7348
7349 -xstack-loc
7350 \series default
7351
7352 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7353
7354 \end_inset
7355
7356 \InsetSpace ~
7357 <Value> By default the external stack
7358 \begin_inset LatexCommand \index{xstack}
7359
7360 \end_inset
7361
7362  is placed after the pdata
7363 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7364
7365 \end_inset
7366
7367  segment.
7368  Using this option the xstack can be placed anywhere in the external memory
7369  space of the 8051.
7370  The value entered can be in Hexadecimal or Decimal format, e.g.
7371  -
7372 \begin_inset ERT
7373 status collapsed
7374
7375 \begin_layout Standard
7376
7377
7378 \backslash
7379 /
7380 \end_layout
7381
7382 \end_inset
7383
7384 -xstack-loc 0x8000 or -
7385 \begin_inset ERT
7386 status collapsed
7387
7388 \begin_layout Standard
7389
7390
7391 \backslash
7392 /
7393 \end_layout
7394
7395 \end_inset
7396
7397 -stack-loc 32768.
7398  The provided value should not overlap any other memory areas such as the
7399  pdata or xdata segment and with enough space for the current application.
7400 \end_layout
7401
7402 \begin_layout List
7403 \labelwidthstring 00.00.0000
7404
7405 \series bold
7406 -
7407 \begin_inset ERT
7408 status collapsed
7409
7410 \begin_layout Standard
7411
7412
7413 \backslash
7414 /
7415 \end_layout
7416
7417 \end_inset
7418
7419 -data-loc
7420 \series default
7421
7422 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7423
7424 \end_inset
7425
7426 \InsetSpace ~
7427 <Value> The start location of the internal ram data
7428 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7429
7430 \end_inset
7431
7432  segment.
7433  The value entered can be in Hexadecimal or Decimal format, eg.
7434  -
7435 \begin_inset ERT
7436 status collapsed
7437
7438 \begin_layout Standard
7439
7440
7441 \backslash
7442 /
7443 \end_layout
7444
7445 \end_inset
7446
7447 -data-loc 0x20 or -
7448 \begin_inset ERT
7449 status collapsed
7450
7451 \begin_layout Standard
7452
7453
7454 \backslash
7455 /
7456 \end_layout
7457
7458 \end_inset
7459
7460 -data-loc 32.
7461  (By default, the start location of the internal ram data segment  is set
7462  as low as possible in memory, taking into account the used register banks
7463  and the bit segment at address 0x20.
7464  For example if register banks 0 and 1 are used without bit variables, the
7465  data segment will be set, if -
7466 \begin_inset ERT
7467 status collapsed
7468
7469 \begin_layout Standard
7470
7471
7472 \backslash
7473 /
7474 \end_layout
7475
7476 \end_inset
7477
7478 -data-loc is not used, to location 0x10.)
7479 \end_layout
7480
7481 \begin_layout List
7482 \labelwidthstring 00.00.0000
7483
7484 \series bold
7485 -
7486 \begin_inset ERT
7487 status collapsed
7488
7489 \begin_layout Standard
7490
7491
7492 \backslash
7493 /
7494 \end_layout
7495
7496 \end_inset
7497
7498 -idata-loc
7499 \series default
7500
7501 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7502
7503 \end_inset
7504
7505 \InsetSpace ~
7506 <Value> The start location of the indirectly addressable internal ram
7507 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7508
7509 \end_inset
7510
7511  of the 8051, default value is 0x80.
7512  The value entered can be in Hexadecimal or Decimal format, eg.
7513  -
7514 \begin_inset ERT
7515 status collapsed
7516
7517 \begin_layout Standard
7518
7519
7520 \backslash
7521 /
7522 \end_layout
7523
7524 \end_inset
7525
7526 -idata-loc 0x88 or -
7527 \begin_inset ERT
7528 status collapsed
7529
7530 \begin_layout Standard
7531
7532
7533 \backslash
7534 /
7535 \end_layout
7536
7537 \end_inset
7538
7539 -idata-loc 136.
7540 \end_layout
7541
7542 \begin_layout List
7543 \labelwidthstring 00.00.0000
7544
7545 \series bold
7546 -
7547 \begin_inset ERT
7548 status collapsed
7549
7550 \begin_layout Standard
7551
7552
7553 \backslash
7554 /
7555 \end_layout
7556
7557 \end_inset
7558
7559 -bit-loc
7560 \series default
7561 \InsetSpace ~
7562 <Value> The start location of the bit
7563 \begin_inset LatexCommand \index{bit}
7564
7565 \end_inset
7566
7567  addressable internal ram of the 8051.
7568  This is 
7569 \emph on
7570 not
7571 \emph default
7572  implemented yet.
7573  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7574 -bBSEG=<Value>.
7575 \end_layout
7576
7577 \begin_layout List
7578 \labelwidthstring 00.00.0000
7579
7580 \series bold
7581 -
7582 \begin_inset ERT
7583 status collapsed
7584
7585 \begin_layout Standard
7586
7587
7588 \backslash
7589 /
7590 \end_layout
7591
7592 \end_inset
7593
7594 -out-fmt-ihx
7595 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7596
7597 \end_inset
7598
7599
7600 \bar under
7601  
7602 \series default
7603 \bar default
7604 The linker output (final object code) is in Intel Hex format.
7605 \begin_inset LatexCommand \index{Intel hex format}
7606
7607 \end_inset
7608
7609  This is the default option.
7610  The format itself is documented in the documentation of srecord
7611 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7612
7613 \end_inset
7614
7615 .
7616 \end_layout
7617
7618 \begin_layout List
7619 \labelwidthstring 00.00.0000
7620
7621 \series bold
7622 -
7623 \begin_inset ERT
7624 status collapsed
7625
7626 \begin_layout Standard
7627
7628
7629 \backslash
7630 /
7631 \end_layout
7632
7633 \end_inset
7634
7635 -out-fmt-s19
7636 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7637
7638 \end_inset
7639
7640
7641 \bar under
7642  
7643 \series default
7644 \bar default
7645 The linker output (final object code) is in Motorola S19 format
7646 \begin_inset LatexCommand \index{Motorola S19 format}
7647
7648 \end_inset
7649
7650 .
7651  The format itself is documented in the documentation of srecord.
7652 \end_layout
7653
7654 \begin_layout List
7655 \labelwidthstring 00.00.0000
7656
7657 \series bold
7658 -
7659 \begin_inset ERT
7660 status collapsed
7661
7662 \begin_layout Standard
7663
7664
7665 \backslash
7666 /
7667 \end_layout
7668
7669 \end_inset
7670
7671 -out-fmt-elf
7672 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7673
7674 \end_inset
7675
7676
7677 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7678
7679 \end_inset
7680
7681
7682 \bar under
7683  
7684 \series default
7685 \bar default
7686 The linker output (final object code) is in ELF format
7687 \begin_inset LatexCommand \index{ELF format}
7688
7689 \end_inset
7690
7691 .
7692  (Currently only supported for the HC08
7693 \begin_inset LatexCommand \index{HC08}
7694
7695 \end_inset
7696
7697  processors)
7698 \end_layout
7699
7700 \begin_layout List
7701 \labelwidthstring 00.00.0000
7702
7703 \series bold
7704 -Wl\InsetSpace ~
7705 linkOption[,linkOption]
7706 \series default
7707
7708 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7709
7710 \end_inset
7711
7712 ...
7713  Pass the linkOption to the linker.
7714  If a bootloader is used an option like 
7715 \begin_inset Quotes sld
7716 \end_inset
7717
7718 -Wl\InsetSpace ~
7719 -bCSEG=0x1000
7720 \begin_inset Quotes srd
7721 \end_inset
7722
7723  would be typical to set the start of the code segment.
7724  See also #pragma constseg and #pragma codeseg in section 
7725 \begin_inset LatexCommand \ref{sec:Pragmas}
7726
7727 \end_inset
7728
7729  .
7730  File sdcc/as/doc/asxhtm.html has more on linker options.
7731 \end_layout
7732
7733 \begin_layout Standard
7734 \begin_inset VSpace bigskip
7735 \end_inset
7736
7737
7738 \end_layout
7739
7740 \begin_layout Subsection
7741 MCS51 Options
7742 \begin_inset LatexCommand \index{Options MCS51}
7743
7744 \end_inset
7745
7746
7747 \begin_inset LatexCommand \index{MCS51 options}
7748
7749 \end_inset
7750
7751
7752 \end_layout
7753
7754 \begin_layout List
7755 \labelwidthstring 00.00.0000
7756
7757 \series bold
7758 -
7759 \begin_inset ERT
7760 status collapsed
7761
7762 \begin_layout Standard
7763
7764
7765 \backslash
7766 /
7767 \end_layout
7768
7769 \end_inset
7770
7771 -model-small
7772 \begin_inset LatexCommand \index{-\/-model-small}
7773
7774 \end_inset
7775
7776
7777 \series default
7778 \size large
7779 \emph on
7780  
7781 \size default
7782 \emph default
7783 Generate code for Small Model programs, see section Memory Models for more
7784  details.
7785  This is the default model.
7786 \end_layout
7787
7788 \begin_layout List
7789 \labelwidthstring 00.00.0000
7790
7791 \series bold
7792 -
7793 \begin_inset ERT
7794 status collapsed
7795
7796 \begin_layout Standard
7797
7798
7799 \backslash
7800 /
7801 \end_layout
7802
7803 \end_inset
7804
7805 -model-medium
7806 \begin_inset LatexCommand \index{-\/-model-medium}
7807
7808 \end_inset
7809
7810
7811 \series default
7812  Generate code for Medium model programs, see section Memory Models for
7813  more details.
7814  If this option is used all source files in the project have to be compiled
7815  with this option.
7816  It must also be used when invoking the linker.
7817 \end_layout
7818
7819 \begin_layout List
7820 \labelwidthstring 00.00.0000
7821
7822 \series bold
7823 -
7824 \begin_inset ERT
7825 status collapsed
7826
7827 \begin_layout Standard
7828
7829
7830 \backslash
7831 /
7832 \end_layout
7833
7834 \end_inset
7835
7836 -model-large
7837 \begin_inset LatexCommand \index{-\/-model-large}
7838
7839 \end_inset
7840
7841
7842 \series default
7843  Generate code for Large model programs, see section Memory Models for more
7844  details.
7845  If this option is used all source files in the project have to be compiled
7846  with this option.
7847  It must also be used when invoking the linker.
7848 \end_layout
7849
7850 \begin_layout List
7851 \labelwidthstring 00.00.0000
7852
7853 \series bold
7854 -
7855 \begin_inset ERT
7856 status collapsed
7857
7858 \begin_layout Standard
7859
7860
7861 \backslash
7862 /
7863 \end_layout
7864
7865 \end_inset
7866
7867 -xstack
7868 \begin_inset LatexCommand \index{-\/-xstack}
7869
7870 \end_inset
7871
7872
7873 \series default
7874  Uses a pseudo stack in the pdata
7875 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7876
7877 \end_inset
7878
7879  area (usually the first 256 bytes in the external ram) for allocating variables
7880  and passing parameters.
7881  See section 
7882 \begin_inset LatexCommand \ref{sub:External-Stack}
7883
7884 \end_inset
7885
7886 \InsetSpace ~
7887  External Stack for more details.
7888 \end_layout
7889
7890 \begin_layout List
7891 \labelwidthstring 00.00.0000
7892
7893 \series bold
7894 -
7895 \begin_inset ERT
7896 status collapsed
7897
7898 \begin_layout Standard
7899
7900
7901 \backslash
7902 /
7903 \end_layout
7904
7905 \end_inset
7906
7907 -iram-size
7908 \series default
7909 \InsetSpace ~
7910 <Value>
7911 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7912
7913 \end_inset
7914
7915  Causes the linker to check if the internal ram usage is within limits of
7916  the given value.
7917 \end_layout
7918
7919 \begin_layout List
7920 \labelwidthstring 00.00.0000
7921
7922 \series bold
7923 -
7924 \begin_inset ERT
7925 status collapsed
7926
7927 \begin_layout Standard
7928
7929
7930 \backslash
7931 /
7932 \end_layout
7933
7934 \end_inset
7935
7936 -xram-size
7937 \series default
7938 \InsetSpace ~
7939 <Value>
7940 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7941
7942 \end_inset
7943
7944  Causes the linker to check if the external ram usage is within limits of
7945  the given value.
7946 \end_layout
7947
7948 \begin_layout List
7949 \labelwidthstring 00.00.0000
7950
7951 \series bold
7952 -
7953 \begin_inset ERT
7954 status collapsed
7955
7956 \begin_layout Standard
7957
7958
7959 \backslash
7960 /
7961 \end_layout
7962
7963 \end_inset
7964
7965 -code-size
7966 \series default
7967 \InsetSpace ~
7968 <Value>
7969 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7970
7971 \end_inset
7972
7973  Causes the linker to check if the code memory usage is within limits of
7974  the given value.
7975 \end_layout
7976
7977 \begin_layout List
7978 \labelwidthstring 00.00.0000
7979
7980 \series bold
7981 -
7982 \begin_inset ERT
7983 status collapsed
7984
7985 \begin_layout Standard
7986
7987
7988 \backslash
7989 /
7990 \end_layout
7991
7992 \end_inset
7993
7994 -stack-size
7995 \series default
7996 \InsetSpace ~
7997 <Value>
7998 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7999
8000 \end_inset
8001
8002  Causes the linker to check if there is at minimum <Value> bytes for stack.
8003 \end_layout
8004
8005 \begin_layout List
8006 \labelwidthstring 00.00.0000
8007
8008 \series bold
8009 -
8010 \begin_inset ERT
8011 status collapsed
8012
8013 \begin_layout Standard
8014
8015
8016 \backslash
8017 /
8018 \end_layout
8019
8020 \end_inset
8021
8022 -pack-iram
8023 \series default
8024 \InsetSpace ~
8025
8026 \begin_inset LatexCommand \index{-\/-pack-iram}
8027
8028 \end_inset
8029
8030  Causes the linker to use unused register banks for data variables and pack
8031  data, idata and stack together.
8032  This is the default now.
8033 \end_layout
8034
8035 \begin_layout List
8036 \labelwidthstring 00.00.0000
8037
8038 \series bold
8039 -
8040 \begin_inset ERT
8041 status collapsed
8042
8043 \begin_layout Standard
8044
8045
8046 \backslash
8047 /
8048 \end_layout
8049
8050 \end_inset
8051
8052 -no-pack-iram
8053 \series default
8054 \InsetSpace ~
8055
8056 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8057
8058 \end_inset
8059
8060  Causes the linker to use old style for allocating memory areas.
8061 \end_layout
8062
8063 \begin_layout Standard
8064 \begin_inset VSpace bigskip
8065 \end_inset
8066
8067
8068 \end_layout
8069
8070 \begin_layout Subsection
8071 DS390 / DS400 Options
8072 \begin_inset LatexCommand \index{Options DS390}
8073
8074 \end_inset
8075
8076
8077 \begin_inset LatexCommand \index{DS390}
8078
8079 \end_inset
8080
8081
8082 \end_layout
8083
8084 \begin_layout List
8085 \labelwidthstring 00.00.0000
8086
8087 \series bold
8088 -
8089 \begin_inset ERT
8090 status collapsed
8091
8092 \begin_layout Standard
8093
8094
8095 \backslash
8096 /
8097 \end_layout
8098
8099 \end_inset
8100
8101 -model-flat24
8102 \series default
8103
8104 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8105
8106 \end_inset
8107
8108
8109 \size large
8110 \emph on
8111  
8112 \size default
8113 \emph default
8114 Generate 24-bit flat mode code.
8115  This is the one and only that the ds390 code generator supports right now
8116  and is default when using 
8117 \emph on
8118 -mds390
8119 \emph default
8120 .
8121  See section Memory Models for more details.
8122 \end_layout
8123
8124 \begin_layout List
8125 \labelwidthstring 00.00.0000
8126
8127 \series bold
8128 -
8129 \begin_inset ERT
8130 status collapsed
8131
8132 \begin_layout Standard
8133
8134
8135 \backslash
8136 /
8137 \end_layout
8138
8139 \end_inset
8140
8141 -protect-sp-update
8142 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8143
8144 \end_inset
8145
8146
8147 \series default
8148  disable interrupts during ESP:SP updates.
8149 \end_layout
8150
8151 \begin_layout List
8152 \labelwidthstring 00.00.0000
8153
8154 \series bold
8155 -
8156 \begin_inset ERT
8157 status collapsed
8158
8159 \begin_layout Standard
8160
8161
8162 \backslash
8163 /
8164 \end_layout
8165
8166 \end_inset
8167
8168 -stack-10bit
8169 \series default
8170
8171 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8172
8173 \end_inset
8174
8175  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8176  This is the one and only that the ds390 code generator supports right now
8177  and is default when using 
8178 \emph on
8179 -mds390
8180 \emph default
8181 .
8182  In this mode, the stack is located in the lower 1K of the internal RAM,
8183  which is mapped to 0x400000.
8184  Note that the support is incomplete, since it still uses a single byte
8185  as the stack pointer.
8186  This means that only the lower 256 bytes of the potential 1K stack space
8187  will actually be used.
8188  However, this does allow you to reclaim the precious 256 bytes of low RAM
8189  for use for the DATA and IDATA segments.
8190  The compiler will not generate any code to put the processor into 10 bit
8191  stack mode.
8192  It is important to ensure that the processor is in this mode before calling
8193  any re-entrant functions compiled with this option.
8194  In principle, this should work with the 
8195 \emph on
8196 -
8197 \begin_inset ERT
8198 status collapsed
8199
8200 \begin_layout Standard
8201
8202
8203 \backslash
8204 /
8205 \end_layout
8206
8207 \end_inset
8208
8209 -stack-auto
8210 \begin_inset LatexCommand \index{-\/-stack-auto}
8211
8212 \end_inset
8213
8214
8215 \emph default
8216  option, but that has not been tested.
8217  It is incompatible with the 
8218 \emph on
8219 -
8220 \begin_inset ERT
8221 status collapsed
8222
8223 \begin_layout Standard
8224
8225
8226 \backslash
8227 /
8228 \end_layout
8229
8230 \end_inset
8231
8232 -xstack
8233 \begin_inset LatexCommand \index{-\/-xstack}
8234
8235 \end_inset
8236
8237
8238 \emph default
8239  option.
8240  It also only makes sense if the processor is in 24 bit contiguous addressing
8241  mode (see the 
8242 \emph on
8243 -
8244 \begin_inset ERT
8245 status collapsed
8246
8247 \begin_layout Standard
8248
8249
8250 \backslash
8251 /
8252 \end_layout
8253
8254 \end_inset
8255
8256 -model-flat24 option
8257 \emph default
8258 ).
8259 \series bold
8260
8261 \begin_inset Note Note
8262 status collapsed
8263
8264 \begin_layout List
8265 \labelwidthstring 00.00.0000
8266
8267 \series bold
8268 --stack-8-bit - switches off the 10-bit mode
8269 \end_layout
8270
8271 \end_inset
8272
8273
8274 \end_layout
8275
8276 \begin_layout List
8277 \labelwidthstring 00.00.0000
8278
8279 \series bold
8280 -
8281 \begin_inset ERT
8282 status collapsed
8283
8284 \begin_layout Standard
8285
8286
8287 \backslash
8288 /
8289 \end_layout
8290
8291 \end_inset
8292
8293 -stack-probe
8294 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8295
8296 \end_inset
8297
8298
8299 \series default
8300  insert call to function __stack_probe at each function prologue.
8301 \end_layout
8302
8303 \begin_layout List
8304 \labelwidthstring 00.00.0000
8305
8306 \series bold
8307 -
8308 \begin_inset ERT
8309 status collapsed
8310
8311 \begin_layout Standard
8312
8313
8314 \backslash
8315 /
8316 \end_layout
8317
8318 \end_inset
8319
8320 -tini-libid
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8322
8323 \end_inset
8324
8325
8326 \series default
8327  <nnnn> LibraryID used in -mTININative.
8328  
8329 \end_layout
8330
8331 \begin_layout List
8332 \labelwidthstring 00.00.0000
8333
8334 \series bold
8335 -
8336 \begin_inset ERT
8337 status collapsed
8338
8339 \begin_layout Standard
8340
8341
8342 \backslash
8343 /
8344 \end_layout
8345
8346 \end_inset
8347
8348 -use-accelerator
8349 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8350
8351 \end_inset
8352
8353
8354 \series default
8355  generate code for DS390 Arithmetic Accelerator.
8356  
8357 \end_layout
8358
8359 \begin_layout Standard
8360 \begin_inset VSpace bigskip
8361 \end_inset
8362
8363
8364 \end_layout
8365
8366 \begin_layout Subsection
8367 Z80 Options
8368 \begin_inset LatexCommand \index{Options Z80}
8369
8370 \end_inset
8371
8372
8373 \begin_inset LatexCommand \index{Z80}
8374
8375 \end_inset
8376
8377
8378 \end_layout
8379
8380 \begin_layout List
8381 \labelwidthstring 00.00.0000
8382
8383 \series bold
8384 -
8385 \begin_inset ERT
8386 status collapsed
8387
8388 \begin_layout Standard
8389
8390
8391 \backslash
8392 /
8393 \end_layout
8394
8395 \end_inset
8396
8397 -callee-saves-bc
8398 \series default
8399
8400 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8401
8402 \end_inset
8403
8404
8405 \size large
8406 \emph on
8407  
8408 \size default
8409 \emph default
8410 Force a called function to always save BC.
8411 \end_layout
8412
8413 \begin_layout List
8414 \labelwidthstring 00.00.0000
8415
8416 \series bold
8417 -
8418 \begin_inset ERT
8419 status collapsed
8420
8421 \begin_layout Standard
8422
8423
8424 \backslash
8425 /
8426 \end_layout
8427
8428 \end_inset
8429
8430 -no-std-crt0
8431 \series default
8432
8433 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8434
8435 \end_inset
8436
8437  When linking, skip the standard crt0.o object file.
8438  You must provide your own crt0.o for your system when linking.
8439  
8440 \end_layout
8441
8442 \begin_layout Standard
8443 \begin_inset VSpace bigskip
8444 \end_inset
8445
8446
8447 \end_layout
8448
8449 \begin_layout Subsection
8450 Optimization Options
8451 \begin_inset LatexCommand \index{Options optimization}
8452
8453 \end_inset
8454
8455
8456 \begin_inset LatexCommand \index{Optimization options}
8457
8458 \end_inset
8459
8460
8461 \end_layout
8462
8463 \begin_layout List
8464 \labelwidthstring 00.00.0000
8465
8466 \series bold
8467 -
8468 \begin_inset ERT
8469 status collapsed
8470
8471 \begin_layout Standard
8472
8473
8474 \backslash
8475 /
8476 \end_layout
8477
8478 \end_inset
8479
8480 -nogcse
8481 \begin_inset LatexCommand \index{-\/-nogcse}
8482
8483 \end_inset
8484
8485
8486 \series default
8487  Will not do global subexpression elimination, this option may be used when
8488  the compiler creates undesirably large stack/data spaces to store compiler
8489  temporaries (
8490 \emph on
8491 s
8492 \emph default
8493 pill 
8494 \emph on
8495 loc
8496 \emph default
8497 ations, sloc
8498 \begin_inset LatexCommand \index{sloc (spill location)}
8499
8500 \end_inset
8501
8502 ).
8503  A warning message will be generated when this happens and the compiler
8504  will indicate the number of extra bytes it allocated.
8505  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8506 nogcse
8507 \begin_inset LatexCommand \index{\#pragma nogcse}
8508
8509 \end_inset
8510
8511  can be used to turn off global subexpression elimination
8512 \begin_inset LatexCommand \index{Subexpression elimination}
8513
8514 \end_inset
8515
8516  for a given function only.
8517 \end_layout
8518
8519 \begin_layout List
8520 \labelwidthstring 00.00.0000
8521
8522 \series bold
8523 -
8524 \begin_inset ERT
8525 status collapsed
8526
8527 \begin_layout Standard
8528
8529
8530 \backslash
8531 /
8532 \end_layout
8533
8534 \end_inset
8535
8536 -noinvariant
8537 \begin_inset LatexCommand \index{-\/-noinvariant}
8538
8539 \end_inset
8540
8541
8542 \series default
8543  Will not do loop invariant optimizations, this may be turned off for reasons
8544  explained for the previous option.
8545  For more details of loop optimizations performed see Loop Invariants in
8546  section 
8547 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8548
8549 \end_inset
8550
8551 .
8552  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8553 noinvariant
8554 \begin_inset LatexCommand \index{\#pragma noinvariant}
8555
8556 \end_inset
8557
8558  can be used to turn off invariant optimizations for a given function only.
8559 \end_layout
8560
8561 \begin_layout List
8562 \labelwidthstring 00.00.0000
8563
8564 \series bold
8565 -
8566 \begin_inset ERT
8567 status collapsed
8568
8569 \begin_layout Standard
8570
8571
8572 \backslash
8573 /
8574 \end_layout
8575
8576 \end_inset
8577
8578 -noinduction
8579 \begin_inset LatexCommand \index{-\/-noinduction}
8580
8581 \end_inset
8582
8583
8584 \series default
8585  Will not do loop induction optimizations, see section strength reduction
8586  for more details.
8587  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8588 noinduction
8589 \begin_inset LatexCommand \index{\#pragma noinduction}
8590
8591 \end_inset
8592
8593  can be used to turn off induction optimizations for a given function only.
8594 \end_layout
8595
8596 \begin_layout List
8597 \labelwidthstring 00.00.0000
8598
8599 \series bold
8600 -
8601 \begin_inset ERT
8602 status collapsed
8603
8604 \begin_layout Standard
8605
8606
8607 \backslash
8608 /
8609 \end_layout
8610
8611 \end_inset
8612
8613 -nojtbound
8614 \begin_inset LatexCommand \index{-\/-nojtbound}
8615
8616 \end_inset
8617
8618
8619 \size large
8620 \bar under
8621  
8622 \series default
8623 \size default
8624 \bar default
8625  Will not generate boundary condition check when switch statements
8626 \begin_inset LatexCommand \index{switch statement}
8627
8628 \end_inset
8629
8630  are implemented using jump-tables.
8631  See section 
8632 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8633
8634 \end_inset
8635
8636 \InsetSpace ~
8637 Switch Statements for more details.
8638  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8639 nojtbound
8640 \begin_inset LatexCommand \index{\#pragma nojtbound}
8641
8642 \end_inset
8643
8644  can be used to turn off boundary checking for jump tables for a given function
8645  only.
8646 \end_layout
8647
8648 \begin_layout List
8649 \labelwidthstring 00.00.0000
8650
8651 \series bold
8652 -
8653 \begin_inset ERT
8654 status collapsed
8655
8656 \begin_layout Standard
8657
8658
8659 \backslash
8660 /
8661 \end_layout
8662
8663 \end_inset
8664
8665 -noloopreverse
8666 \begin_inset LatexCommand \index{-\/-noloopreverse}
8667
8668 \end_inset
8669
8670
8671 \series default
8672 \size large
8673  
8674 \size default
8675 Will not do loop reversal 
8676 \begin_inset LatexCommand \index{Loop reversing}
8677
8678 \end_inset
8679
8680 optimization.
8681 \end_layout
8682
8683 \begin_layout List
8684 \labelwidthstring 00.00.0000
8685 -
8686 \begin_inset ERT
8687 status collapsed
8688
8689 \begin_layout Standard
8690
8691
8692 \backslash
8693 /
8694 \end_layout
8695
8696 \end_inset
8697
8698 -
8699 \series bold
8700 nolabelopt
8701 \series default
8702  
8703 \begin_inset LatexCommand \index{-\/-nolabelopt }
8704
8705 \end_inset
8706
8707 Will not optimize labels (makes the dumpfiles more readable).
8708 \end_layout
8709
8710 \begin_layout List
8711 \labelwidthstring 00.00.0000
8712
8713 \series bold
8714 -
8715 \begin_inset ERT
8716 status collapsed
8717
8718 \begin_layout Standard
8719
8720
8721 \backslash
8722 /
8723 \end_layout
8724
8725 \end_inset
8726
8727 -no-xinit-opt
8728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8729
8730 \end_inset
8731
8732
8733 \series default
8734  Will not memcpy initialized data from code space into xdata space.
8735  This saves a few bytes in code space if you don't have initialized data
8736 \begin_inset LatexCommand \index{Variable initialization}
8737
8738 \end_inset
8739
8740 .
8741 \end_layout
8742
8743 \begin_layout List
8744 \labelwidthstring 00.00.0000
8745
8746 \series bold
8747 -
8748 \begin_inset ERT
8749 status collapsed
8750
8751 \begin_layout Standard
8752
8753
8754 \backslash
8755 /
8756 \end_layout
8757
8758 \end_inset
8759
8760 -nooverlay
8761 \begin_inset LatexCommand \index{-\/-nooverlay}
8762
8763 \end_inset
8764
8765
8766 \series default
8767   The compiler will not overlay parameters and local variables of any function,
8768  see section Parameters and local variables for more details.
8769 \end_layout
8770
8771 \begin_layout List
8772 \labelwidthstring 00.00.0000
8773
8774 \series bold
8775 -
8776 \begin_inset ERT
8777 status collapsed
8778
8779 \begin_layout Standard
8780
8781
8782 \backslash
8783 /
8784 \end_layout
8785
8786 \end_inset
8787
8788 -no-peep
8789 \begin_inset LatexCommand \index{-\/-no-peep}
8790
8791 \end_inset
8792
8793
8794 \series default
8795  Disable peep-hole optimization with built-in rules.
8796 \end_layout
8797
8798 \begin_layout List
8799 \labelwidthstring 00.00.0000
8800
8801 \series bold
8802 -
8803 \begin_inset ERT
8804 status collapsed
8805
8806 \begin_layout Standard
8807
8808
8809 \backslash
8810 /
8811 \end_layout
8812
8813 \end_inset
8814
8815 -peep-file
8816 \series default
8817
8818 \begin_inset LatexCommand \index{-\/-peep-file}
8819
8820 \end_inset
8821
8822 \InsetSpace ~
8823 <filename> This option can be used to use additional rules to be used by
8824  the peep hole optimizer.
8825  See section 
8826 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8827
8828 \end_inset
8829
8830 \InsetSpace ~
8831 Peep Hole optimizations for details on how to write these rules.
8832 \end_layout
8833
8834 \begin_layout List
8835 \labelwidthstring 00.00.0000
8836
8837 \series bold
8838 -
8839 \begin_inset ERT
8840 status collapsed
8841
8842 \begin_layout Standard
8843
8844
8845 \backslash
8846 /
8847 \end_layout
8848
8849 \end_inset
8850
8851 -peep-asm
8852 \begin_inset LatexCommand \index{-\/-peep-asm}
8853
8854 \end_inset
8855
8856
8857 \series default
8858  Pass the inline assembler code through the peep hole optimizer.
8859  This can cause unexpected changes to inline assembler code, please go through
8860  the peephole optimizer
8861 \begin_inset LatexCommand \index{Peephole optimizer}
8862
8863 \end_inset
8864
8865  rules defined in the source file tree '<target>/peeph.def' before using
8866  this option.
8867 \end_layout
8868
8869 \begin_layout List
8870 \labelwidthstring 00.00.0000
8871
8872 \series bold
8873 -
8874 \begin_inset ERT
8875 status collapsed
8876
8877 \begin_layout Standard
8878
8879
8880 \backslash
8881 /
8882 \end_layout
8883
8884 \end_inset
8885
8886 -opt-code-speed
8887 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8888
8889 \end_inset
8890
8891
8892 \series default
8893  The compiler will optimize code generation towards fast code, possibly
8894  at the expense of code size.
8895 \end_layout
8896
8897 \begin_layout List
8898 \labelwidthstring 00.00.0000
8899
8900 \series bold
8901 -
8902 \begin_inset ERT
8903 status collapsed
8904
8905 \begin_layout Standard
8906
8907
8908 \backslash
8909 /
8910 \end_layout
8911
8912 \end_inset
8913
8914 -opt-code-size
8915 \begin_inset LatexCommand \index{-\/-opt-code-size}
8916
8917 \end_inset
8918
8919
8920 \series default
8921  The compiler will optimize code generation towards compact code, possibly
8922  at the expense of code speed.
8923 \end_layout
8924
8925 \begin_layout Standard
8926 \begin_inset VSpace bigskip
8927 \end_inset
8928
8929
8930 \end_layout
8931
8932 \begin_layout Subsection
8933 Other Options
8934 \begin_inset LatexCommand \index{Options other}
8935
8936 \end_inset
8937
8938
8939 \end_layout
8940
8941 \begin_layout List
8942 \labelwidthstring 00.00.0000
8943
8944 \series bold
8945 -c\InsetSpace ~
8946 -
8947 \begin_inset ERT
8948 status collapsed
8949
8950 \begin_layout Standard
8951
8952
8953 \backslash
8954 /
8955 \end_layout
8956
8957 \end_inset
8958
8959 -compile-only
8960 \begin_inset LatexCommand \index{-\/-compile-only}
8961
8962 \end_inset
8963
8964
8965 \begin_inset LatexCommand \index{-c -\/-compile-only}
8966
8967 \end_inset
8968
8969
8970 \series default
8971  will compile and assemble the source, but will not call the linkage editor.
8972 \end_layout
8973
8974 \begin_layout List
8975 \labelwidthstring 00.00.0000
8976
8977 \series bold
8978 -
8979 \series default
8980
8981 \begin_inset ERT
8982 status collapsed
8983
8984 \begin_layout Standard
8985
8986
8987 \backslash
8988 /
8989 \end_layout
8990
8991 \end_inset
8992
8993
8994 \series bold
8995 -c1mode
8996 \begin_inset LatexCommand \index{-\/-c1mode}
8997
8998 \end_inset
8999
9000
9001 \series default
9002  reads the preprocessed source from standard input and compiles it.
9003  The file name for the assembler output must be specified using the -o option.
9004 \end_layout
9005
9006 \begin_layout List
9007 \labelwidthstring 00.00.0000
9008
9009 \series bold
9010 -E
9011 \begin_inset LatexCommand \index{-E}
9012
9013 \end_inset
9014
9015
9016 \series default
9017  Run only the C preprocessor.
9018  Preprocess all the C source files specified and output the results to standard
9019  output.
9020 \end_layout
9021
9022 \begin_layout List
9023 \labelwidthstring 00.00.0000
9024
9025 \series bold
9026 -o\InsetSpace ~
9027 <path/file>
9028 \begin_inset LatexCommand \index{-o <path/file>}
9029
9030 \end_inset
9031
9032  
9033 \series default
9034 The output path resp.
9035  file where everything will be placed.
9036  If the parameter is a path, it must have a trailing slash (or backslash
9037  for the Windows binaries) to be recognized as a path.
9038  
9039 \end_layout
9040
9041 \begin_layout List
9042 \labelwidthstring 00.00.0000
9043
9044 \series bold
9045 -
9046 \begin_inset ERT
9047 status collapsed
9048
9049 \begin_layout Standard
9050
9051
9052 \backslash
9053 /
9054 \end_layout
9055
9056 \end_inset
9057
9058 -stack-auto
9059 \begin_inset LatexCommand \index{-\/-stack-auto}
9060
9061 \end_inset
9062
9063
9064 \series default
9065 \size large
9066 \emph on
9067  
9068 \size default
9069 \emph default
9070 All functions in the source file will be compiled as 
9071 \emph on
9072 reentrant
9073 \emph default
9074
9075 \begin_inset LatexCommand \index{reentrant}
9076
9077 \end_inset
9078
9079 , i.e.
9080  the parameters and local variables will be allocated on the stack
9081 \begin_inset LatexCommand \index{stack}
9082
9083 \end_inset
9084
9085 .
9086  See section 
9087 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9088
9089 \end_inset
9090
9091  Parameters and Local Variables for more details.
9092  If this option is used all source files in the project should be compiled
9093  with this option.
9094  It automatically implies --int-long-reent and --float-reent.
9095  
9096 \end_layout
9097
9098 \begin_layout List
9099 \labelwidthstring 00.00.0000
9100
9101 \series bold
9102 -
9103 \begin_inset ERT
9104 status collapsed
9105
9106 \begin_layout Standard
9107
9108
9109 \backslash
9110 /
9111 \end_layout
9112
9113 \end_inset
9114
9115 -callee-saves
9116 \begin_inset LatexCommand \index{-\/-callee-saves}
9117
9118 \end_inset
9119
9120  
9121 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9122
9123 \end_inset
9124
9125 function1[,function2][,function3]....
9126
9127 \series default
9128  The compiler by default uses a caller saves convention for register saving
9129  across function calls, however this can cause unnecessary register pushing
9130  and popping when calling small functions from larger functions.
9131  This option can be used to switch the register saving convention for the
9132  function names specified.
9133  The compiler will not save registers when calling these functions, no extra
9134  code will be generated at the entry and exit (function prologue
9135 \series bold
9136
9137 \begin_inset LatexCommand \index{function prologue}
9138
9139 \end_inset
9140
9141
9142 \series default
9143  and epilogue
9144 \series bold
9145
9146 \begin_inset LatexCommand \index{function epilogue}
9147
9148 \end_inset
9149
9150
9151 \series default
9152 ) for these functions to save and restore the registers used by these functions,
9153  this can SUBSTANTIALLY reduce code and improve run time performance of
9154  the generated code.
9155  In the future the compiler (with inter procedural analysis) will be able
9156  to determine the appropriate scheme to use for each function call.
9157  DO NOT use this option for built-in functions such as _mulint..., if this
9158  option is used for a library function the appropriate library function
9159  needs to be recompiled with the same option.
9160  If the project consists of multiple source files then all the source file
9161  should be compiled with the same -
9162 \begin_inset ERT
9163 status collapsed
9164
9165 \begin_layout Standard
9166
9167
9168 \backslash
9169 /
9170 \end_layout
9171
9172 \end_inset
9173
9174 -callee-saves option string.
9175  Also see #pragma\InsetSpace ~
9176 callee_saves 
9177 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9178
9179 \end_inset
9180
9181  
9182 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9183
9184 \end_inset
9185
9186 .
9187 \end_layout
9188
9189 \begin_layout List
9190 \labelwidthstring 00.00.0000
9191
9192 \series bold
9193 -
9194 \begin_inset ERT
9195 status collapsed
9196
9197 \begin_layout Standard
9198
9199
9200 \backslash
9201 /
9202 \end_layout
9203
9204 \end_inset
9205
9206 -all-callee-saves
9207 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9208
9209 \end_inset
9210
9211  
9212 \series default
9213 Function of
9214 \series bold
9215  
9216 \series default
9217 -
9218 \begin_inset ERT
9219 status collapsed
9220
9221 \begin_layout Standard
9222
9223
9224 \backslash
9225 /
9226 \end_layout
9227
9228 \end_inset
9229
9230 -callee-saves will be applied to all functions by default.
9231 \end_layout
9232
9233 \begin_layout List
9234 \labelwidthstring 00.00.0000
9235
9236 \series bold
9237 -
9238 \begin_inset ERT
9239 status collapsed
9240
9241 \begin_layout Standard
9242
9243
9244 \backslash
9245 /
9246 \end_layout
9247
9248 \end_inset
9249
9250 -debug
9251 \begin_inset LatexCommand \index{-\/-debug}
9252
9253 \end_inset
9254
9255
9256 \bar under
9257  
9258 \series default
9259 \bar default
9260 When this option is used the compiler will generate debug information.
9261  The debug information collected in a file with .cdb extension can be used
9262  with the SDCDB.
9263  For more information see documentation for SDCDB.
9264  Another file with no extension contains debug information in AOMF or AOMF51
9265 \begin_inset LatexCommand \index{AOMF, AOMF51}
9266
9267 \end_inset
9268
9269  format which is commonly used by third party tools.
9270 \end_layout
9271
9272 \begin_layout List
9273 \labelwidthstring 00.00.0000
9274
9275 \series bold
9276 -S
9277 \begin_inset LatexCommand \index{-S}
9278
9279 \end_inset
9280
9281
9282 \size large
9283 \bar under
9284  
9285 \series default
9286 \size default
9287 \bar default
9288 Stop after the stage of compilation proper; do not assemble.
9289  The output is an assembler code file for the input file specified.
9290 \end_layout
9291
9292 \begin_layout List
9293 \labelwidthstring 00.00.0000
9294
9295 \series bold
9296 -
9297 \begin_inset ERT
9298 status collapsed
9299
9300 \begin_layout Standard
9301
9302
9303 \backslash
9304 /
9305 \end_layout
9306
9307 \end_inset
9308
9309 -int-long-reent
9310 \begin_inset LatexCommand \index{-\/-int-long-reent}
9311
9312 \end_inset
9313
9314
9315 \series default
9316  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9317  Note by default these libraries are compiled as non-reentrant.
9318  See section Installation for more details.
9319 \end_layout
9320
9321 \begin_layout List
9322 \labelwidthstring 00.00.0000
9323
9324 \series bold
9325 -
9326 \begin_inset ERT
9327 status collapsed
9328
9329 \begin_layout Standard
9330
9331
9332 \backslash
9333 /
9334 \end_layout
9335
9336 \end_inset
9337
9338 -cyclomatic
9339 \begin_inset LatexCommand \index{-\/-cyclomatic}
9340
9341 \end_inset
9342
9343
9344 \bar under
9345  
9346 \series default
9347 \bar default
9348 This option will cause the compiler to generate an information message for
9349  each function in the source file.
9350  The message contains some 
9351 \emph on
9352 important
9353 \emph default
9354  information about the function.
9355  The number of edges and nodes the compiler detected in the control flow
9356  graph of the function, and most importantly the 
9357 \emph on
9358 cyclomatic complexity
9359 \begin_inset LatexCommand \index{Cyclomatic complexity}
9360
9361 \end_inset
9362
9363
9364 \emph default
9365  see section on Cyclomatic Complexity for more details.
9366 \end_layout
9367
9368 \begin_layout List
9369 \labelwidthstring 00.00.0000
9370
9371 \series bold
9372 -
9373 \begin_inset ERT
9374 status collapsed
9375
9376 \begin_layout Standard
9377
9378
9379 \backslash
9380 /
9381 \end_layout
9382
9383 \end_inset
9384
9385 -float-reent
9386 \begin_inset LatexCommand \index{-\/-float-reent}
9387
9388 \end_inset
9389
9390
9391 \series default
9392  Floating point library is compiled as reentrant
9393 \begin_inset LatexCommand \index{reentrant}
9394
9395 \end_inset
9396
9397 .
9398  See section Installation for more details.
9399 \end_layout
9400
9401 \begin_layout List
9402 \labelwidthstring 00.00.0000
9403
9404 \series bold
9405 -
9406 \begin_inset ERT
9407 status collapsed
9408
9409 \begin_layout Standard
9410
9411
9412 \backslash
9413 /
9414 \end_layout
9415
9416 \end_inset
9417
9418 -funsigned-char
9419 \begin_inset LatexCommand \index{-\/-funsigned-char}
9420
9421 \end_inset
9422
9423
9424 \series default
9425  The default signedness for every type is
9426 \family typewriter
9427  signed
9428 \family default
9429 .
9430  In some embedded environments the default signedness of
9431 \family typewriter
9432  char
9433 \family default
9434  is
9435 \family typewriter
9436  unsigned
9437 \family default
9438 .
9439  To set the signess for characters to unsigned, use the option --funsigned-char.
9440  If this option is set and no signedness keyword (unsigned/signed) is given,
9441  a char will be signed.
9442  All other types are unaffected.
9443 \end_layout
9444
9445 \begin_layout List
9446 \labelwidthstring 00.00.0000
9447
9448 \series bold
9449 -
9450 \begin_inset ERT
9451 status collapsed
9452
9453 \begin_layout Standard
9454
9455
9456 \backslash
9457 /
9458 \end_layout
9459
9460 \end_inset
9461
9462 -main-return
9463 \begin_inset LatexCommand \index{-\/-main-return}
9464
9465 \end_inset
9466
9467
9468 \series default
9469  This option can be used if the code generated is called by a monitor program
9470  or if the main routine includes an endless loop.
9471  This option results in slightly smaller code and saves two bytes of stack
9472  space.
9473  The return from the 'main'
9474 \begin_inset LatexCommand \index{main return}
9475
9476 \end_inset
9477
9478  function will return to the function calling main.
9479  The default setting is to lock up i.e.
9480  generate a '
9481 \family typewriter
9482 sjmp .
9483 \family default
9484 '.
9485 \end_layout
9486
9487 \begin_layout List
9488 \labelwidthstring 00.00.0000
9489
9490 \series bold
9491 -
9492 \begin_inset ERT
9493 status collapsed
9494
9495 \begin_layout Standard
9496
9497
9498 \backslash
9499 /
9500 \end_layout
9501
9502 \end_inset
9503
9504 -nostdinc
9505 \begin_inset LatexCommand \index{-\/-nostdinc}
9506
9507 \end_inset
9508
9509
9510 \series default
9511  This will prevent the compiler from passing on the default include path
9512  to the preprocessor.
9513 \end_layout
9514
9515 \begin_layout List
9516 \labelwidthstring 00.00.0000
9517
9518 \series bold
9519 -
9520 \begin_inset ERT
9521 status collapsed
9522
9523 \begin_layout Standard
9524
9525
9526 \backslash
9527 /
9528 \end_layout
9529
9530 \end_inset
9531
9532 -nostdlib
9533 \begin_inset LatexCommand \index{-\/-nostdlib}
9534
9535 \end_inset
9536
9537
9538 \series default
9539  This will prevent the compiler from passing on the default library
9540 \begin_inset LatexCommand \index{Libraries}
9541
9542 \end_inset
9543
9544  path to the linker.
9545 \end_layout
9546
9547 \begin_layout List
9548 \labelwidthstring 00.00.0000
9549
9550 \series bold
9551 -
9552 \begin_inset ERT
9553 status collapsed
9554
9555 \begin_layout Standard
9556
9557
9558 \backslash
9559 /
9560 \end_layout
9561
9562 \end_inset
9563
9564 -verbose
9565 \begin_inset LatexCommand \index{-\/-verbose}
9566
9567 \end_inset
9568
9569
9570 \series default
9571  Shows the various actions the compiler is performing.
9572 \end_layout
9573
9574 \begin_layout List
9575 \labelwidthstring 00.00.0000
9576
9577 \series bold
9578 -V
9579 \begin_inset LatexCommand \index{-V}
9580
9581 \end_inset
9582
9583
9584 \series default
9585  Shows the actual commands the compiler is executing.
9586 \end_layout
9587
9588 \begin_layout List
9589 \labelwidthstring 00.00.0000
9590
9591 \series bold
9592 -
9593 \begin_inset ERT
9594 status collapsed
9595
9596 \begin_layout Standard
9597
9598
9599 \backslash
9600 /
9601 \end_layout
9602
9603 \end_inset
9604
9605 -no-c-code-in-asm
9606 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9607
9608 \end_inset
9609
9610
9611 \series default
9612  Hides your ugly and inefficient c-code from the asm file, so you can always
9613  blame the compiler :)
9614 \end_layout
9615
9616 \begin_layout List
9617 \labelwidthstring 00.00.0000
9618
9619 \series bold
9620 -
9621 \begin_inset ERT
9622 status collapsed
9623
9624 \begin_layout Standard
9625
9626
9627 \backslash
9628 /
9629 \end_layout
9630
9631 \end_inset
9632
9633 -no-peep-comments
9634 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9635
9636 \end_inset
9637
9638
9639 \series default
9640  Will not include peep-hole comments in the generated files.
9641 \end_layout
9642
9643 \begin_layout List
9644 \labelwidthstring 00.00.0000
9645
9646 \series bold
9647 -
9648 \begin_inset ERT
9649 status collapsed
9650
9651 \begin_layout Standard
9652
9653
9654 \backslash
9655 /
9656 \end_layout
9657
9658 \end_inset
9659
9660 -no-gen-comments
9661 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9662
9663 \end_inset
9664
9665
9666 \series default
9667  Will not include code generator comments in the generated files.
9668 \end_layout
9669
9670 \begin_layout List
9671 \labelwidthstring 00.00.0000
9672
9673 \series bold
9674 -
9675 \begin_inset ERT
9676 status collapsed
9677
9678 \begin_layout Standard
9679
9680
9681 \backslash
9682 /
9683 \end_layout
9684
9685 \end_inset
9686
9687 -i-code-in-asm
9688 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9689
9690 \end_inset
9691
9692
9693 \series default
9694  Include i-codes in the asm file.
9695  Sounds like noise but is most helpful for debugging the compiler itself.
9696 \end_layout
9697
9698 \begin_layout List
9699 \labelwidthstring 00.00.0000
9700
9701 \series bold
9702 -
9703 \begin_inset ERT
9704 status collapsed
9705
9706 \begin_layout Standard
9707
9708
9709 \backslash
9710 /
9711 \end_layout
9712
9713 \end_inset
9714
9715 -less-pedantic
9716 \begin_inset LatexCommand \index{pedantic}
9717
9718 \end_inset
9719
9720
9721 \begin_inset LatexCommand \index{-\/-less-pedantic}
9722
9723 \end_inset
9724
9725
9726 \series default
9727
9728 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9729
9730 \end_inset
9731
9732  Disable some of the more pedantic warnings
9733 \begin_inset LatexCommand \index{Warnings}
9734
9735 \end_inset
9736
9737 .
9738  For more details, see the less_pedantic pragma 
9739 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9740
9741 \end_inset
9742
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 -disable-warning\InsetSpace ~
9764 <nnnn>
9765 \begin_inset LatexCommand \index{-\/-disable-warning}
9766
9767 \end_inset
9768
9769
9770 \series default
9771  Disable specific warning with number <nnnn>.
9772 \end_layout
9773
9774 \begin_layout List
9775 \labelwidthstring 00.00.0000
9776
9777 \series bold
9778 -
9779 \begin_inset ERT
9780 status collapsed
9781
9782 \begin_layout Standard
9783
9784
9785 \backslash
9786 /
9787 \end_layout
9788
9789 \end_inset
9790
9791 -print-search-dirs
9792 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9793
9794 \end_inset
9795
9796
9797 \series default
9798  Display the directories in the compiler's search path
9799 \end_layout
9800
9801 \begin_layout List
9802 \labelwidthstring 00.00.0000
9803
9804 \series bold
9805 -
9806 \begin_inset ERT
9807 status collapsed
9808
9809 \begin_layout Standard
9810
9811
9812 \backslash
9813 /
9814 \end_layout
9815
9816 \end_inset
9817
9818 -vc
9819 \begin_inset LatexCommand \index{-\/-vc}
9820
9821 \end_inset
9822
9823
9824 \series default
9825  Display errors and warnings using MSVC style, so you can use SDCC with
9826  the visual studio IDE
9827 \begin_inset LatexCommand \index{IDE}
9828
9829 \end_inset
9830
9831 .
9832  With SDCC both offering a GCC-like (the default) and a MSVC-like
9833 \begin_inset LatexCommand \index{MSVC output style}
9834
9835 \end_inset
9836
9837  output style, integration into most programming editors should be straightforwa
9838 rd.
9839 \end_layout
9840
9841 \begin_layout List
9842 \labelwidthstring 00.00.0000
9843
9844 \series bold
9845 -
9846 \begin_inset ERT
9847 status collapsed
9848
9849 \begin_layout Standard
9850
9851
9852 \backslash
9853 /
9854 \end_layout
9855
9856 \end_inset
9857
9858 -use-stdout
9859 \begin_inset LatexCommand \index{-\/-use-stdout}
9860
9861 \end_inset
9862
9863
9864 \series default
9865  Send errors and warnings to stdout instead of stderr.
9866 \end_layout
9867
9868 \begin_layout List
9869 \labelwidthstring 00.00.0000
9870
9871 \series bold
9872 -Wa\InsetSpace ~
9873 asmOption[,asmOption]
9874 \series default
9875
9876 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9877
9878 \end_inset
9879
9880 ...
9881  Pass the asmOption to the assembler
9882 \begin_inset LatexCommand \index{Options assembler}
9883
9884 \end_inset
9885
9886
9887 \begin_inset LatexCommand \index{Assembler options}
9888
9889 \end_inset
9890
9891 .
9892  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9893 \end_layout
9894
9895 \begin_layout List
9896 \labelwidthstring 00.00.0000
9897
9898 \series bold
9899 -
9900 \begin_inset ERT
9901 status collapsed
9902
9903 \begin_layout Standard
9904
9905
9906 \backslash
9907 /
9908 \end_layout
9909
9910 \end_inset
9911
9912 -std-sdcc89
9913 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9914
9915 \end_inset
9916
9917
9918 \series default
9919  Generally follow the C89 standard, but allow SDCC features that conflict
9920  with the standard (default).
9921 \end_layout
9922
9923 \begin_layout List
9924 \labelwidthstring 00.00.0000
9925
9926 \series bold
9927 -
9928 \begin_inset ERT
9929 status collapsed
9930
9931 \begin_layout Standard
9932
9933
9934 \backslash
9935 /
9936 \end_layout
9937
9938 \end_inset
9939
9940 -std-c89
9941 \begin_inset LatexCommand \index{-\/-std-c89}
9942
9943 \end_inset
9944
9945
9946 \series default
9947  Follow the C89 standard and disable SDCC features that conflict with the
9948  standard.
9949 \end_layout
9950
9951 \begin_layout List
9952 \labelwidthstring 00.00.0000
9953
9954 \series bold
9955 -
9956 \begin_inset ERT
9957 status collapsed
9958
9959 \begin_layout Standard
9960
9961
9962 \backslash
9963 /
9964 \end_layout
9965
9966 \end_inset
9967
9968 -std-sdcc99
9969 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9970
9971 \end_inset
9972
9973
9974 \series default
9975  Generally follow the C99 standard, but allow SDCC features that conflict
9976  with the standard (incomplete support).
9977 \end_layout
9978
9979 \begin_layout List
9980 \labelwidthstring 00.00.0000
9981
9982 \series bold
9983 -
9984 \begin_inset ERT
9985 status collapsed
9986
9987 \begin_layout Standard
9988
9989
9990 \backslash
9991 /
9992 \end_layout
9993
9994 \end_inset
9995
9996 -std-c99
9997 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9998
9999 \end_inset
10000
10001
10002 \series default
10003  Follow the C99 standard and disable SDCC features that conflict with the
10004  standard (incomplete support).
10005 \end_layout
10006
10007 \begin_layout List
10008 \labelwidthstring 00.00.0000
10009
10010 \series bold
10011 -
10012 \begin_inset ERT
10013 status collapsed
10014
10015 \begin_layout Standard
10016
10017
10018 \backslash
10019 /
10020 \end_layout
10021
10022 \end_inset
10023
10024 -codeseg
10025 \series default
10026
10027 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10028
10029 \end_inset
10030
10031 \InsetSpace ~
10032 <Name> The name to be used for the code
10033 \begin_inset LatexCommand \index{code}
10034
10035 \end_inset
10036
10037  segment, default CSEG.
10038  This is useful if you need to tell the compiler to put the code in a special
10039  segment so you can later on tell the linker to put this segment in a special
10040  place in memory.
10041  Can be used for instance when using bank switching to put the code in a
10042  bank.
10043 \end_layout
10044
10045 \begin_layout List
10046 \labelwidthstring 00.00.0000
10047
10048 \series bold
10049 -
10050 \begin_inset ERT
10051 status collapsed
10052
10053 \begin_layout Standard
10054
10055
10056 \backslash
10057 /
10058 \end_layout
10059
10060 \end_inset
10061
10062 -constseg
10063 \series default
10064
10065 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10066
10067 \end_inset
10068
10069 \InsetSpace ~
10070 <Name> The name to be used for the const
10071 \begin_inset LatexCommand \index{code}
10072
10073 \end_inset
10074
10075  segment, default CONST.
10076  This is useful if you need to tell the compiler to put the const data in
10077  a special segment so you can later on tell the linker to put this segment
10078  in a special place in memory.
10079  Can be used for instance when using bank switching to put the const data
10080  in a bank.
10081 \end_layout
10082
10083 \begin_layout List
10084 \labelwidthstring 00.00.0000
10085
10086 \series bold
10087 -
10088 \begin_inset ERT
10089 status collapsed
10090
10091 \begin_layout Standard
10092
10093
10094 \backslash
10095 /
10096 \end_layout
10097
10098 \end_inset
10099
10100 -fdollars-in-identifiers
10101 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10102
10103 \end_inset
10104
10105
10106 \series default
10107  Permit '$' as an identifier character.
10108 \end_layout
10109
10110 \begin_layout List
10111 \labelwidthstring 00.00.0000
10112
10113 \series bold
10114 -
10115 \begin_inset ERT
10116 status collapsed
10117
10118 \begin_layout Standard
10119
10120
10121 \backslash
10122 /
10123 \end_layout
10124
10125 \end_inset
10126
10127 -more-pedantic
10128 \series default
10129
10130 \begin_inset LatexCommand \index{-\/-more-pedantic}
10131
10132 \end_inset
10133
10134
10135 \begin_inset LatexCommand \index{pedantic}
10136
10137 \end_inset
10138
10139  Actually this is 
10140 \series bold
10141 \emph on
10142 not
10143 \series default
10144 \emph default
10145  a SDCC compiler option but if you want 
10146 \emph on
10147 more
10148 \emph default
10149  warnings you can use a separate tool dedicated to syntax checking like
10150  splint
10151 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10152
10153 \end_inset
10154
10155
10156 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10157
10158 \end_inset
10159
10160  
10161 \begin_inset LatexCommand \url{http://www.splint.org}
10162
10163 \end_inset
10164
10165 .
10166  To make your source files parseable by splint you will have to include
10167  
10168 \family sans
10169 lint.h
10170 \family default
10171
10172 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10173
10174 \end_inset
10175
10176  in your source file and add brackets around extended keywords (like 
10177 \family sans
10178
10179 \begin_inset Quotes sld
10180 \end_inset
10181
10182 __at\InsetSpace ~
10183
10184 \series bold
10185 (
10186 \series default
10187 0xab
10188 \series bold
10189 )
10190 \series default
10191
10192 \begin_inset Quotes srd
10193 \end_inset
10194
10195
10196 \family default
10197  and 
10198 \family sans
10199
10200 \begin_inset Quotes sld
10201 \end_inset
10202
10203 __interrupt\InsetSpace ~
10204 (2)
10205 \begin_inset Quotes srd
10206 \end_inset
10207
10208
10209 \family default
10210 ).
10211  
10212 \newline
10213 Splint has an excellent on line manual at 
10214 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10215
10216 \end_inset
10217
10218  and it's capabilities go beyond pure syntax checking.
10219  You'll need to tell splint the location of SDCC's include files so a typical
10220  command line could look like this: 
10221 \newline
10222
10223 \family sans
10224 splint\InsetSpace ~
10225 -I\InsetSpace ~
10226 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10227 \InsetSpace ~
10228 myprogram.c
10229 \end_layout
10230
10231 \begin_layout List
10232 \labelwidthstring 00.00.0000
10233
10234 \series bold
10235 -
10236 \begin_inset ERT
10237 status collapsed
10238
10239 \begin_layout Standard
10240
10241
10242 \backslash
10243 /
10244 \end_layout
10245
10246 \end_inset
10247
10248 -short-is-8bits
10249 \series default
10250
10251 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10252
10253 \end_inset
10254
10255
10256 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10257
10258 \end_inset
10259
10260  Treat short as 8-bit (for backward compatibility with older versions of
10261  compiler - see section 
10262 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10263
10264 \end_inset
10265
10266 )
10267 \end_layout
10268
10269 \begin_layout Standard
10270 \begin_inset VSpace bigskip
10271 \end_inset
10272
10273
10274 \end_layout
10275
10276 \begin_layout Subsection
10277 Intermediate Dump Options
10278 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10279
10280 \end_inset
10281
10282
10283 \begin_inset LatexCommand \index{Options intermediate dump}
10284
10285 \end_inset
10286
10287
10288 \begin_inset LatexCommand \index{Intermediate dump options}
10289
10290 \end_inset
10291
10292
10293 \end_layout
10294
10295 \begin_layout Standard
10296 The following options are provided for the purpose of retargetting and debugging
10297  the compiler.
10298  They provide a means to dump the intermediate code (iCode
10299 \begin_inset LatexCommand \index{iCode}
10300
10301 \end_inset
10302
10303 ) generated by the compiler in human readable form at various stages of
10304  the compilation process.
10305  More on iCodes see chapter 
10306 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10307
10308 \end_inset
10309
10310  
10311 \begin_inset Quotes srd
10312 \end_inset
10313
10314 The anatomy of the compiler
10315 \begin_inset Quotes srd
10316 \end_inset
10317
10318 .
10319 \end_layout
10320
10321 \begin_layout List
10322 \labelwidthstring 00.00.0000
10323
10324 \series bold
10325 -
10326 \begin_inset ERT
10327 status collapsed
10328
10329 \begin_layout Standard
10330
10331
10332 \backslash
10333 /
10334 \end_layout
10335
10336 \end_inset
10337
10338 -dumpraw
10339 \begin_inset LatexCommand \index{-\/-dumpraw}
10340
10341 \end_inset
10342
10343
10344 \series default
10345  This option will cause the compiler to dump the intermediate code into
10346  a file of named 
10347 \emph on
10348 <source filename>.dumpraw
10349 \emph default
10350  just after the intermediate code has been generated for a function, i.e.
10351  before any optimizations are done.
10352  The basic blocks
10353 \begin_inset LatexCommand \index{Basic blocks}
10354
10355 \end_inset
10356
10357  at this stage ordered in the depth first number, so they may not be in
10358  sequence of execution.
10359 \end_layout
10360
10361 \begin_layout List
10362 \labelwidthstring 00.00.0000
10363
10364 \series bold
10365 -
10366 \begin_inset ERT
10367 status collapsed
10368
10369 \begin_layout Standard
10370
10371
10372 \backslash
10373 /
10374 \end_layout
10375
10376 \end_inset
10377
10378 -dumpgcse
10379 \begin_inset LatexCommand \index{-\/-dumpgcse}
10380
10381 \end_inset
10382
10383
10384 \series default
10385  Will create a dump of iCode's, after global subexpression elimination
10386 \begin_inset LatexCommand \index{Global subexpression elimination}
10387
10388 \end_inset
10389
10390 , into a file named 
10391 \emph on
10392 <source filename>.dumpgcse.
10393 \end_layout
10394
10395 \begin_layout List
10396 \labelwidthstring 00.00.0000
10397
10398 \series bold
10399 -
10400 \begin_inset ERT
10401 status collapsed
10402
10403 \begin_layout Standard
10404
10405
10406 \backslash
10407 /
10408 \end_layout
10409
10410 \end_inset
10411
10412 -dumpdeadcode
10413 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10414
10415 \end_inset
10416
10417
10418 \series default
10419  Will create a dump of iCode's, after deadcode elimination
10420 \begin_inset LatexCommand \index{Dead-code elimination}
10421
10422 \end_inset
10423
10424 , into a file named 
10425 \emph on
10426 <source filename>.dumpdeadcode.
10427 \end_layout
10428
10429 \begin_layout List
10430 \labelwidthstring 00.00.0000
10431
10432 \series bold
10433 -
10434 \begin_inset ERT
10435 status collapsed
10436
10437 \begin_layout Standard
10438
10439
10440 \backslash
10441 /
10442 \end_layout
10443
10444 \end_inset
10445
10446 -dumploop
10447 \begin_inset LatexCommand \index{-\/-dumploop}
10448
10449 \end_inset
10450
10451
10452 \series default
10453 \size large
10454  
10455 \size default
10456 Will create a dump of iCode's, after loop optimizations
10457 \begin_inset LatexCommand \index{Loop optimization}
10458
10459 \end_inset
10460
10461 , into a file named 
10462 \emph on
10463 <source filename>.dumploop.
10464 \end_layout
10465
10466 \begin_layout List
10467 \labelwidthstring 00.00.0000
10468
10469 \series bold
10470 -
10471 \begin_inset ERT
10472 status collapsed
10473
10474 \begin_layout Standard
10475
10476
10477 \backslash
10478 /
10479 \end_layout
10480
10481 \end_inset
10482
10483 -dumprange
10484 \begin_inset LatexCommand \index{-\/-dumprange}
10485
10486 \end_inset
10487
10488
10489 \series default
10490 \size large
10491  
10492 \size default
10493 Will create a dump of iCode's, after live range analysis
10494 \begin_inset LatexCommand \index{Live range analysis}
10495
10496 \end_inset
10497
10498 , into a file named 
10499 \emph on
10500 <source filename>.dumprange.
10501 \end_layout
10502
10503 \begin_layout List
10504 \labelwidthstring 00.00.0000
10505
10506 \series bold
10507 -
10508 \begin_inset ERT
10509 status collapsed
10510
10511 \begin_layout Standard
10512
10513
10514 \backslash
10515 /
10516 \end_layout
10517
10518 \end_inset
10519
10520 -dumlrange
10521 \begin_inset LatexCommand \index{-\/-dumlrange}
10522
10523 \end_inset
10524
10525
10526 \series default
10527  Will dump the life ranges
10528 \begin_inset LatexCommand \index{Live range analysis}
10529
10530 \end_inset
10531
10532  for all symbols.
10533 \end_layout
10534
10535 \begin_layout List
10536 \labelwidthstring 00.00.0000
10537
10538 \series bold
10539 -
10540 \begin_inset ERT
10541 status collapsed
10542
10543 \begin_layout Standard
10544
10545
10546 \backslash
10547 /
10548 \end_layout
10549
10550 \end_inset
10551
10552 -dumpregassign
10553 \begin_inset LatexCommand \index{-\/-dumpregassign}
10554
10555 \end_inset
10556
10557
10558 \bar under
10559  
10560 \series default
10561 \bar default
10562 Will create a dump of iCode's, after register assignment
10563 \begin_inset LatexCommand \index{Register assignment}
10564
10565 \end_inset
10566
10567 , into a file named 
10568 \emph on
10569 <source filename>.dumprassgn.
10570 \end_layout
10571
10572 \begin_layout List
10573 \labelwidthstring 00.00.0000
10574
10575 \series bold
10576 -
10577 \begin_inset ERT
10578 status collapsed
10579
10580 \begin_layout Standard
10581
10582
10583 \backslash
10584 /
10585 \end_layout
10586
10587 \end_inset
10588
10589 -dumplrange
10590 \begin_inset LatexCommand \index{-\/-dumplrange}
10591
10592 \end_inset
10593
10594
10595 \series default
10596  Will create a dump of the live ranges of iTemp's
10597 \end_layout
10598
10599 \begin_layout List
10600 \labelwidthstring 00.00.0000
10601
10602 \series bold
10603 -
10604 \begin_inset ERT
10605 status collapsed
10606
10607 \begin_layout Standard
10608
10609
10610 \backslash
10611 /
10612 \end_layout
10613
10614 \end_inset
10615
10616 -dumpall
10617 \begin_inset LatexCommand \index{-\/-dumpall}
10618
10619 \end_inset
10620
10621
10622 \size large
10623 \bar under
10624  
10625 \series default
10626 \size default
10627 \bar default
10628 Will cause all the above mentioned dumps to be created.
10629 \end_layout
10630
10631 \begin_layout Standard
10632 \begin_inset VSpace bigskip
10633 \end_inset
10634
10635
10636 \end_layout
10637
10638 \begin_layout Subsection
10639 Redirecting output on Windows Shells
10640 \end_layout
10641
10642 \begin_layout Standard
10643 By default SDCC writes it's error messages to 
10644 \begin_inset Quotes sld
10645 \end_inset
10646
10647 standard error
10648 \begin_inset Quotes srd
10649 \end_inset
10650
10651 .
10652  To force all messages to 
10653 \begin_inset Quotes sld
10654 \end_inset
10655
10656 standard output
10657 \begin_inset Quotes srd
10658 \end_inset
10659
10660  use 
10661 \series bold
10662 -
10663 \series default
10664 \emph on
10665
10666 \begin_inset ERT
10667 status collapsed
10668
10669 \begin_layout Standard
10670
10671
10672 \backslash
10673 /
10674 \end_layout
10675
10676 \end_inset
10677
10678
10679 \series bold
10680 \emph default
10681 -
10682 \series default
10683 use-stdout
10684 \begin_inset LatexCommand \index{-\/-use-stdout}
10685
10686 \end_inset
10687
10688 .
10689  Additionally, if you happen to have visual studio installed in your windows
10690  machine, you can use it to compile your sources using a custom build and
10691  the SDCC -
10692 \emph on
10693
10694 \begin_inset ERT
10695 status collapsed
10696
10697 \begin_layout Standard
10698
10699
10700 \backslash
10701 /
10702 \end_layout
10703
10704 \end_inset
10705
10706
10707 \emph default
10708 -vc
10709 \begin_inset LatexCommand \index{-\/-vc}
10710
10711 \end_inset
10712
10713  option.
10714  Something like this should work:
10715 \newline
10716
10717 \newline
10718
10719 \series bold
10720 c:
10721 \backslash
10722 sdcc
10723 \backslash
10724 bin
10725 \backslash
10726 sdcc.exe -
10727 \series default
10728 \emph on
10729
10730 \begin_inset ERT
10731 status collapsed
10732
10733 \begin_layout Standard
10734
10735
10736 \backslash
10737 /
10738 \end_layout
10739
10740 \end_inset
10741
10742
10743 \series bold
10744 \emph default
10745 -vc -
10746 \series default
10747 \emph on
10748
10749 \begin_inset ERT
10750 status collapsed
10751
10752 \begin_layout Standard
10753
10754
10755 \backslash
10756 /
10757 \end_layout
10758
10759 \end_inset
10760
10761
10762 \series bold
10763 \emph default
10764 -model-large -c $(InputPath)
10765 \series default
10766
10767 \begin_inset VSpace bigskip
10768 \end_inset
10769
10770
10771 \end_layout
10772
10773 \begin_layout Section
10774 Environment variables
10775 \begin_inset LatexCommand \index{Environment variables}
10776
10777 \end_inset
10778
10779
10780 \end_layout
10781
10782 \begin_layout Standard
10783 SDCC recognizes the following environment variables:
10784 \end_layout
10785
10786 \begin_layout List
10787 \labelwidthstring 00.00.0000
10788
10789 \series bold
10790 SDCC_LEAVE_SIGNALS
10791 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10792
10793 \end_inset
10794
10795
10796 \series default
10797  SDCC installs a signal handler
10798 \begin_inset LatexCommand \index{signal handler}
10799
10800 \end_inset
10801
10802  to be able to delete temporary files after an user break (^C) or an exception.
10803  If this environment variable is set, SDCC won't install the signal handler
10804  in order to be able to debug SDCC.
10805 \end_layout
10806
10807 \begin_layout List
10808 \labelwidthstring 00.00.0000
10809
10810 \series bold
10811 TMP,\InsetSpace ~
10812 TEMP,\InsetSpace ~
10813 TMPDIR
10814 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10815
10816 \end_inset
10817
10818
10819 \series default
10820  Path, where temporary files will be created.
10821  The order of the variables is the search order.
10822  In a standard *nix environment these variables are not set, and there's
10823  no need to set them.
10824  On Windows it's recommended to set one of them.
10825 \end_layout
10826
10827 \begin_layout List
10828 \labelwidthstring 00.00.0000
10829
10830 \series bold
10831 SDCC_HOME
10832 \begin_inset LatexCommand \index{SDCC\_HOME}
10833
10834 \end_inset
10835
10836
10837 \series default
10838  Path, see section 
10839 \begin_inset LatexCommand \ref{sub:Install-paths}
10840
10841 \end_inset
10842
10843 \InsetSpace ~
10844
10845 \begin_inset Quotes sld
10846 \end_inset
10847
10848  Install Paths
10849 \begin_inset Quotes srd
10850 \end_inset
10851
10852 .
10853 \end_layout
10854
10855 \begin_layout List
10856 \labelwidthstring 00.00.0000
10857
10858 \series bold
10859 SDCC_INCLUDE
10860 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10861
10862 \end_inset
10863
10864
10865 \series default
10866  Path, see section 
10867 \begin_inset LatexCommand \ref{sub:Search-Paths}
10868
10869 \end_inset
10870
10871 \InsetSpace ~
10872
10873 \begin_inset Quotes sld
10874 \end_inset
10875
10876 Search Paths
10877 \begin_inset Quotes srd
10878 \end_inset
10879
10880 .
10881 \end_layout
10882
10883 \begin_layout List
10884 \labelwidthstring 00.00.0000
10885
10886 \series bold
10887 SDCC_LIB
10888 \begin_inset LatexCommand \index{SDCC\_LIB}
10889
10890 \end_inset
10891
10892
10893 \series default
10894  Path, see section 
10895 \begin_inset LatexCommand \ref{sub:Search-Paths}
10896
10897 \end_inset
10898
10899 \InsetSpace ~
10900
10901 \begin_inset Quotes sld
10902 \end_inset
10903
10904 Search Paths
10905 \begin_inset Quotes srd
10906 \end_inset
10907
10908 ..
10909 \end_layout
10910
10911 \begin_layout Standard
10912 There are some more environment variables recognized by SDCC, but these
10913  are solely used for debugging purposes.
10914  They can change or disappear very quickly, and will never be documented.
10915 \begin_inset VSpace bigskip
10916 \end_inset
10917
10918
10919 \end_layout
10920
10921 \begin_layout Section
10922 Storage Class Language Extensions
10923 \end_layout
10924
10925 \begin_layout Subsection
10926 MCS51/DS390 Storage Class
10927 \begin_inset LatexCommand \index{Storage class}
10928
10929 \end_inset
10930
10931  Language Extensions
10932 \end_layout
10933
10934 \begin_layout Standard
10935 In addition to the ANSI storage classes SDCC allows the following MCS51
10936  specific storage classes:
10937 \end_layout
10938
10939 \begin_layout Subsubsection
10940 data
10941 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10942
10943 \end_inset
10944
10945
10946 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10947
10948 \end_inset
10949
10950  / near
10951 \begin_inset LatexCommand \index{near (storage class)}
10952
10953 \end_inset
10954
10955
10956 \begin_inset LatexCommand \index{\_\_near (storage class)}
10957
10958 \end_inset
10959
10960
10961 \end_layout
10962
10963 \begin_layout Standard
10964 This is the 
10965 \series bold
10966 default
10967 \series default
10968  storage class for the Small Memory model (
10969 \emph on
10970 data
10971 \emph default
10972  and 
10973 \emph on
10974 near
10975 \emph default
10976  or the more ANSI-C compliant forms 
10977 \emph on
10978 __data
10979 \emph default
10980  and 
10981 \emph on
10982 __near
10983 \emph default
10984  can be used synonymously).
10985  Variables declared with this storage class will be allocated in the directly
10986  addressable portion of the internal RAM of a 8051, e.g.:
10987 \end_layout
10988
10989 \begin_layout Verse
10990
10991 \family typewriter
10992 __data unsigned char test_data;
10993 \end_layout
10994
10995 \begin_layout Standard
10996 Writing 0x01 to this variable generates the assembly code:
10997 \end_layout
10998
10999 \begin_layout Verse
11000
11001 \family typewriter
11002 75*00 01\InsetSpace ~
11003 \InsetSpace ~
11004 \InsetSpace ~
11005 mov\InsetSpace ~
11006 \InsetSpace ~
11007 _test_data,#0x01
11008 \end_layout
11009
11010 \begin_layout Subsubsection
11011 xdata
11012 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11013
11014 \end_inset
11015
11016
11017 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11018
11019 \end_inset
11020
11021  / far
11022 \begin_inset LatexCommand \index{far (storage class)}
11023
11024 \end_inset
11025
11026
11027 \begin_inset LatexCommand \index{\_\_far (storage class)}
11028
11029 \end_inset
11030
11031
11032 \end_layout
11033
11034 \begin_layout Standard
11035 Variables declared with this storage class will be placed in the external
11036  RAM.
11037  This is the 
11038 \series bold
11039 default
11040 \series default
11041  storage class for the Large Memory model, e.g.:
11042 \end_layout
11043
11044 \begin_layout Verse
11045
11046 \family typewriter
11047 __xdata unsigned char test_xdata;
11048 \end_layout
11049
11050 \begin_layout Standard
11051 Writing 0x01 to this variable generates the assembly code:
11052 \end_layout
11053
11054 \begin_layout Verse
11055
11056 \family typewriter
11057 90s00r00\InsetSpace ~
11058 \InsetSpace ~
11059 \InsetSpace ~
11060 mov\InsetSpace ~
11061 \InsetSpace ~
11062 dptr,#_test_xdata 
11063 \newline
11064 74\InsetSpace ~
11065 01\InsetSpace ~
11066 \InsetSpace ~
11067 \InsetSpace ~
11068 \InsetSpace ~
11069 \InsetSpace ~
11070 \InsetSpace ~
11071 mov\InsetSpace ~
11072 \InsetSpace ~
11073 a,#0x01 
11074 \newline
11075 F0\InsetSpace ~
11076 \InsetSpace ~
11077 \InsetSpace ~
11078 \InsetSpace ~
11079 \InsetSpace ~
11080 \InsetSpace ~
11081 \InsetSpace ~
11082 \InsetSpace ~
11083 \InsetSpace ~
11084 movx\InsetSpace ~
11085 @dptr,a 
11086 \end_layout
11087
11088 \begin_layout Subsubsection
11089 idata
11090 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11091
11092 \end_inset
11093
11094
11095 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11096
11097 \end_inset
11098
11099
11100 \end_layout
11101
11102 \begin_layout Standard
11103 Variables declared with this storage class will be allocated into the indirectly
11104  addressable portion of the internal ram of a 8051, e.g.:
11105 \end_layout
11106
11107 \begin_layout Verse
11108
11109 \family typewriter
11110 __idata unsigned char test_idata;
11111 \end_layout
11112
11113 \begin_layout Standard
11114 Writing 0x01 to this variable generates the assembly code:
11115 \end_layout
11116
11117 \begin_layout Verse
11118
11119 \family typewriter
11120 78r00\InsetSpace ~
11121 \InsetSpace ~
11122 \InsetSpace ~
11123 \InsetSpace ~
11124 \InsetSpace ~
11125 \InsetSpace ~
11126 \InsetSpace ~
11127 mov\InsetSpace ~
11128 \InsetSpace ~
11129 r0,#_test_idata
11130 \newline
11131 76\InsetSpace ~
11132 01\InsetSpace ~
11133 \InsetSpace ~
11134 \InsetSpace ~
11135 \InsetSpace ~
11136 \InsetSpace ~
11137 \InsetSpace ~
11138 \InsetSpace ~
11139 mov\InsetSpace ~
11140 \InsetSpace ~
11141 @r0,#0x01
11142 \end_layout
11143
11144 \begin_layout Standard
11145 Please note, the first 128 byte of idata physically access the same RAM
11146  as the data memory.
11147  The original 8051 had 128 byte idata memory, nowadays most devices have
11148  256 byte idata memory.
11149  The stack
11150 \begin_inset LatexCommand \index{stack}
11151
11152 \end_inset
11153
11154  is located in idata memory.
11155 \end_layout
11156
11157 \begin_layout Subsubsection
11158 pdata
11159 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11160
11161 \end_inset
11162
11163
11164 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11165
11166 \end_inset
11167
11168
11169 \end_layout
11170
11171 \begin_layout Standard
11172 Paged xdata access is just as straightforward as using the other addressing
11173  modes of a 8051.
11174  It is typically located at the start of xdata and has a maximum size of
11175  256 bytes.
11176  The following example writes 0x01 to the pdata variable.
11177  Please note, pdata access physically accesses xdata memory.
11178  The high byte of the address is determined by port P2 
11179 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11180
11181 \end_inset
11182
11183 (or in case of some 8051 variants by a separate Special Function Register,
11184  see section 
11185 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11186
11187 \end_inset
11188
11189 ).
11190  This is the 
11191 \series bold
11192 default
11193 \series default
11194  storage class for the Medium Memory model, e.g.:
11195 \end_layout
11196
11197 \begin_layout Verse
11198
11199 \family typewriter
11200 __pdata unsigned char test_pdata;
11201 \end_layout
11202
11203 \begin_layout Standard
11204 Writing 0x01 to this variable generates the assembly code:
11205 \end_layout
11206
11207 \begin_layout Verse
11208
11209 \family typewriter
11210 78r00\InsetSpace ~
11211 \InsetSpace ~
11212 \InsetSpace ~
11213 \InsetSpace ~
11214 \InsetSpace ~
11215 \InsetSpace ~
11216 mov r0,#_test_pdata
11217 \newline
11218 74 01\InsetSpace ~
11219 \InsetSpace ~
11220 \InsetSpace ~
11221 \InsetSpace ~
11222 \InsetSpace ~
11223 \InsetSpace ~
11224 mov a,#0x01 
11225 \newline
11226 F2\InsetSpace ~
11227 \InsetSpace ~
11228 \InsetSpace ~
11229 \InsetSpace ~
11230 \InsetSpace ~
11231 \InsetSpace ~
11232 \InsetSpace ~
11233 \InsetSpace ~
11234 \InsetSpace ~
11235 movx @r0,a
11236 \end_layout
11237
11238 \begin_layout Standard
11239 If the -
11240 \begin_inset ERT
11241 status collapsed
11242
11243 \begin_layout Standard
11244
11245
11246 \backslash
11247 /
11248 \end_layout
11249
11250 \end_inset
11251
11252 -xstack
11253 \begin_inset LatexCommand \index{-\/-xstack}
11254
11255 \end_inset
11256
11257  option is used the pdata memory area is followed by the xstack memory area
11258  and the sum of their sizes is limited to 256 bytes.
11259 \end_layout
11260
11261 \begin_layout Subsubsection
11262 code
11263 \begin_inset LatexCommand \index{code}
11264
11265 \end_inset
11266
11267
11268 \begin_inset LatexCommand \index{\_\_code}
11269
11270 \end_inset
11271
11272
11273 \end_layout
11274
11275 \begin_layout Standard
11276 'Variables' declared with this storage class will be placed in the code
11277  memory:
11278 \end_layout
11279
11280 \begin_layout Verse
11281
11282 \family typewriter
11283 __code unsigned char test_code;
11284 \end_layout
11285
11286 \begin_layout Standard
11287 Read access to this variable generates the assembly code:
11288 \end_layout
11289
11290 \begin_layout Verse
11291
11292 \family typewriter
11293 90s00r6F\InsetSpace ~
11294 \InsetSpace ~
11295 \InsetSpace ~
11296 mov dptr,#_test_code
11297 \newline
11298 E4\InsetSpace ~
11299 \InsetSpace ~
11300 \InsetSpace ~
11301 \InsetSpace ~
11302 \InsetSpace ~
11303 \InsetSpace ~
11304 \InsetSpace ~
11305 \InsetSpace ~
11306 \InsetSpace ~
11307 clr a
11308 \newline
11309 93\InsetSpace ~
11310 \InsetSpace ~
11311 \InsetSpace ~
11312 \InsetSpace ~
11313 \InsetSpace ~
11314 \InsetSpace ~
11315 \InsetSpace ~
11316 \InsetSpace ~
11317 \InsetSpace ~
11318 movc a,@a+dptr 
11319 \end_layout
11320
11321 \begin_layout Standard
11322
11323 \family typewriter
11324 char
11325 \family default
11326  indexed arrays of characters in code memory can be accessed efficiently:
11327 \end_layout
11328
11329 \begin_layout Verse
11330
11331 \family typewriter
11332 __code char test_array[] = {'c','h','e','a','p'}; 
11333 \end_layout
11334
11335 \begin_layout Standard
11336 Read access to this array using an 8-bit unsigned index generates the assembly
11337  code:
11338 \end_layout
11339
11340 \begin_layout Verse
11341
11342 \family typewriter
11343 E5*00\InsetSpace ~
11344 \InsetSpace ~
11345 \InsetSpace ~
11346 \InsetSpace ~
11347 \InsetSpace ~
11348 \InsetSpace ~
11349 mov a,_index 
11350 \end_layout
11351
11352 \begin_layout Verse
11353
11354 \family typewriter
11355 90s00r41\InsetSpace ~
11356 \InsetSpace ~
11357 \InsetSpace ~
11358 mov dptr,#_test_array
11359 \end_layout
11360
11361 \begin_layout Verse
11362
11363 \family typewriter
11364 93\InsetSpace ~
11365 \InsetSpace ~
11366 \InsetSpace ~
11367 \InsetSpace ~
11368 \InsetSpace ~
11369 \InsetSpace ~
11370 \InsetSpace ~
11371 \InsetSpace ~
11372 \InsetSpace ~
11373 movc a,@a+dptr 
11374 \end_layout
11375
11376 \begin_layout Subsubsection
11377 bit
11378 \begin_inset LatexCommand \index{bit}
11379
11380 \end_inset
11381
11382
11383 \begin_inset LatexCommand \index{\_\_bit}
11384
11385 \end_inset
11386
11387
11388 \end_layout
11389
11390 \begin_layout Standard
11391 This is a data-type and a storage class specifier.
11392  When a variable is declared as a bit, it is allocated into the bit addressable
11393  memory of 8051, e.g.:
11394 \end_layout
11395
11396 \begin_layout Verse
11397
11398 \family typewriter
11399 __bit test_bit;
11400 \end_layout
11401
11402 \begin_layout Standard
11403 Writing 1 to this variable generates the assembly code:
11404 \end_layout
11405
11406 \begin_layout Verse
11407
11408 \family typewriter
11409 D2*00\InsetSpace ~
11410 \InsetSpace ~
11411 \InsetSpace ~
11412 \InsetSpace ~
11413 \InsetSpace ~
11414 \InsetSpace ~
11415 \InsetSpace ~
11416 setb\InsetSpace ~
11417 _test_bit
11418 \end_layout
11419
11420 \begin_layout Standard
11421 The bit addressable memory consists of 128 bits which are located from 0x20
11422  to 0x2f in data memory.
11423  
11424 \newline
11425 Apart from this 8051 specific storage class most architectures support
11426  ANSI-C bitfields
11427 \begin_inset LatexCommand \index{bitfields}
11428
11429 \end_inset
11430
11431
11432 \begin_inset Foot
11433 status open
11434
11435 \begin_layout Standard
11436 Not really meant as examples, but nevertheless showing what bitfields are
11437  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11438 \end_layout
11439
11440 \end_inset
11441
11442 .
11443  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11444  signed modifier are implemented as unsigned.
11445 \end_layout
11446
11447 \begin_layout Subsubsection
11448 sfr
11449 \begin_inset LatexCommand \index{sfr}
11450
11451 \end_inset
11452
11453
11454 \begin_inset LatexCommand \index{\_\_sfr}
11455
11456 \end_inset
11457
11458  / sfr16
11459 \begin_inset LatexCommand \index{sfr16}
11460
11461 \end_inset
11462
11463
11464 \begin_inset LatexCommand \index{\_\_sfr16}
11465
11466 \end_inset
11467
11468  / sfr32
11469 \begin_inset LatexCommand \index{sfr32}
11470
11471 \end_inset
11472
11473
11474 \begin_inset LatexCommand \index{\_\_sfr32}
11475
11476 \end_inset
11477
11478  / sbit
11479 \begin_inset LatexCommand \index{\_\_sbit}
11480
11481 \end_inset
11482
11483
11484 \begin_inset LatexCommand \index{sbit}
11485
11486 \end_inset
11487
11488
11489 \end_layout
11490
11491 \begin_layout Standard
11492 Like the bit keyword, 
11493 \emph on
11494 sfr / sfr16 / sfr32 / sbit 
11495 \emph default
11496 signify both a data-type and storage class, they are used to describe the
11497  
11498 \emph on
11499 s
11500 \emph default
11501 pecial 
11502 \emph on
11503 f
11504 \emph default
11505 unction 
11506 \emph on
11507 r
11508 \emph default
11509 egisters and 
11510 \emph on
11511 s
11512 \emph default
11513 pecial 
11514 \emph on
11515 bit
11516 \emph default
11517  variables of a 8051, eg:
11518 \end_layout
11519
11520 \begin_layout Verse
11521
11522 \family typewriter
11523 __sfr __at
11524 \begin_inset LatexCommand \index{at}
11525
11526 \end_inset
11527
11528
11529 \begin_inset LatexCommand \index{\_\_at}
11530
11531 \end_inset
11532
11533  (0x80) P0;\InsetSpace ~
11534  /* special function register P0 at location 0x80 */
11535 \newline
11536
11537 \newline
11538 /* 16 bit
11539  special function register combination for timer 0
11540 \newline
11541 \InsetSpace ~
11542 \InsetSpace ~
11543  with the high byte at
11544  location 0x8C and the low byte at location 0x8A */
11545 \newline
11546 __sfr16 __at (0x8C8A)
11547  TMR0;
11548 \newline
11549
11550 \newline
11551 __sbit __at
11552 \begin_inset LatexCommand \index{at}
11553
11554 \end_inset
11555
11556
11557 \begin_inset LatexCommand \index{\_\_at}
11558
11559 \end_inset
11560
11561  (0xd7) CY;\InsetSpace ~
11562  /* CY (Carry Flag
11563 \begin_inset LatexCommand \index{Flags}
11564
11565 \end_inset
11566
11567
11568 \begin_inset LatexCommand \index{Carry flag}
11569
11570 \end_inset
11571
11572 ) */
11573 \end_layout
11574
11575 \begin_layout Standard
11576 Special function registers which are located on an address dividable by
11577  8 are bit-addressable, an
11578 \emph on
11579  sbit
11580 \emph default
11581  addresses a specific bit within these sfr.
11582 \newline
11583 16 Bit and 32 bit special function
11584  register combinations which require a certain access order are better not
11585  declared using 
11586 \emph on
11587 sfr16
11588 \emph default
11589  or 
11590 \emph on
11591 sfr32.
11592
11593 \emph default
11594  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11595  this is not guaranteed.
11596 \newline
11597
11598 \end_layout
11599
11600 \begin_layout Standard
11601 Please note, if you use a header file which was written for another compiler
11602  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11603  likely be 
11604 \emph on
11605 not 
11606 \emph default
11607 compatible.
11608  Specifically the syntax 
11609 \family typewriter
11610 \InsetSpace ~
11611 sfr P0 = 0x80;\InsetSpace ~
11612
11613 \family default
11614  is compiled 
11615 \emph on
11616 without warning
11617 \emph default
11618  by SDCC to an assignment of 0x80 to a variable called P0 
11619 \family typewriter
11620
11621 \begin_inset Marginal
11622 status collapsed
11623
11624 \begin_layout Standard
11625
11626 \series bold
11627 \InsetSpace ~
11628 !
11629 \end_layout
11630
11631 \end_inset
11632
11633 .
11634  
11635 \family default
11636 Nevertheless it is possible to write header files
11637 \begin_inset LatexCommand \index{Header files}
11638
11639 \end_inset
11640
11641
11642 \begin_inset LatexCommand \index{Include files}
11643
11644 \end_inset
11645
11646  which can be shared among different compilers (see section 
11647 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11648
11649 \end_inset
11650
11651 ).
11652  
11653 \end_layout
11654
11655 \begin_layout Subsubsection
11656 Pointers
11657 \begin_inset LatexCommand \index{Pointer}
11658
11659 \end_inset
11660
11661  to MCS51/DS390 specific memory spaces
11662 \end_layout
11663
11664 \begin_layout Standard
11665 SDCC allows (via language extensions) pointers to explicitly point to any
11666  of the memory spaces
11667 \begin_inset LatexCommand \index{Memory model}
11668
11669 \end_inset
11670
11671  of the 8051.
11672  In addition to the explicit pointers, the compiler uses (by default) generic
11673  pointers which can be used to point to any of the memory spaces.
11674 \newline
11675
11676 \newline
11677 Pointer
11678  declaration examples:
11679 \end_layout
11680
11681 \begin_layout Verse
11682
11683 \family typewriter
11684 /* pointer physically in internal ram pointing to object in external ram
11685  */ 
11686 \newline
11687 __xdata unsigned char * __data p;
11688 \newline
11689
11690 \newline
11691 /* pointer physically in external ram
11692  pointing to object in internal ram */ 
11693 \newline
11694 __data unsigned char * __xdata p;
11695 \newline
11696
11697 \newline
11698 /*
11699  pointer physically in code rom pointing to data in xdata space */ 
11700 \newline
11701 __xdata
11702  unsigned char * __code p;
11703 \newline
11704
11705 \newline
11706 /* pointer physically in code space pointing to
11707  data in code space */ 
11708 \newline
11709 __code unsigned char * __code p;
11710 \newline
11711
11712 \newline
11713 /* generic pointer
11714  physically located in xdata space */
11715 \newline
11716 unsigned char * __xdata p;
11717 \newline
11718
11719 \newline
11720 /* generic
11721  pointer physically located in default memory space */
11722 \newline
11723 unsigned char * p;
11724 \newline
11725
11726 \newline
11727 /*
11728  the following is a function pointer
11729 \begin_inset LatexCommand \index{function pointer}
11730
11731 \end_inset
11732
11733  physically located in data space */
11734 \newline
11735 char (* __data fp)(void);
11736 \end_layout
11737
11738 \begin_layout Standard
11739 Well you get the idea.
11740  
11741 \newline
11742
11743 \newline
11744 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11745 \emph on
11746 generic
11747 \emph default
11748  pointers.
11749  
11750 \size small
11751
11752 \newline
11753
11754 \newline
11755
11756 \size default
11757 The highest order byte of the 
11758 \emph on
11759 generic
11760 \emph default
11761  pointers contains the data space information.
11762  Assembler support routines are called whenever data is stored or retrieved
11763  using 
11764 \emph on
11765 generic
11766 \emph default
11767  pointers.
11768  These are useful for developing reusable library
11769 \begin_inset LatexCommand \index{Libraries}
11770
11771 \end_inset
11772
11773  routines.
11774  Explicitly specifying the pointer
11775 \begin_inset LatexCommand \index{pointer}
11776
11777 \end_inset
11778
11779  type will generate the most efficient code.
11780 \end_layout
11781
11782 \begin_layout Subsubsection
11783 Notes on MCS51 memory
11784 \begin_inset LatexCommand \index{MCS51 memory}
11785
11786 \end_inset
11787
11788  layout
11789 \end_layout
11790
11791 \begin_layout Standard
11792 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11793  RAM memory which is structured as follows:
11794 \newline
11795
11796 \newline
11797 - Bytes 00-1F - 32 bytes to hold
11798  up to 4 banks of the registers R0 to R7, 
11799 \newline
11800 - Bytes 20-2F - 16 bytes to hold
11801  128 bit
11802 \begin_inset LatexCommand \index{bit}
11803
11804 \end_inset
11805
11806  variables and, 
11807 \newline
11808 - Bytes 30-7F - 80 bytes for general purpose use.
11809 \newline
11810
11811 \end_layout
11812
11813 \begin_layout Standard
11814 Additionally some members of the MCS51 family may have up to 128 bytes of
11815  additional, indirectly addressable, internal RAM memory (
11816 \emph on
11817 idata
11818 \emph default
11819
11820 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11821
11822 \end_inset
11823
11824
11825 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11826
11827 \end_inset
11828
11829 ).
11830  Furthermore, some chips may have some built in external memory (
11831 \emph on
11832 xdata
11833 \emph default
11834
11835 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11836
11837 \end_inset
11838
11839
11840 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11841
11842 \end_inset
11843
11844 ) which should not be confused with the internal, directly addressable RAM
11845  memory (
11846 \emph on
11847 data
11848 \emph default
11849
11850 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11851
11852 \end_inset
11853
11854
11855 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11856
11857 \end_inset
11858
11859 ).
11860  Sometimes this built in 
11861 \emph on
11862 xdata
11863 \emph default
11864  memory has to be activated before using it (you can probably find this
11865  information on the datasheet of the microcontroller your are using, see
11866  also section 
11867 \begin_inset LatexCommand \ref{sub:Startup-Code}
11868
11869 \end_inset
11870
11871 \InsetSpace ~
11872 Startup-Code).
11873 \end_layout
11874
11875 \begin_layout Standard
11876 Normally SDCC will only use the first bank
11877 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11878
11879 \end_inset
11880
11881  of registers (register bank 0), but it is possible to specify that other
11882  banks of registers (keyword 
11883 \emph on
11884 using
11885 \emph default
11886  
11887 \emph on
11888
11889 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11890
11891 \end_inset
11892
11893
11894 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11895
11896 \end_inset
11897
11898
11899 \emph default
11900 ) should be used for example in interrupt
11901 \begin_inset LatexCommand \index{interrupt}
11902
11903 \end_inset
11904
11905
11906 \begin_inset LatexCommand \index{\_\_interrupt}
11907
11908 \end_inset
11909
11910  routines.
11911  By default, the compiler will place the stack after the last byte of allocated
11912  memory for variables.
11913  For example, if the first 2 banks of registers are used, and only four
11914  bytes are used for 
11915 \emph on
11916 data
11917 \emph default
11918  variables, it will position the base of the internal stack at address 20
11919  (0x14).
11920  This implies that as the stack
11921 \begin_inset LatexCommand \index{stack}
11922
11923 \end_inset
11924
11925  grows, it will use up the remaining register banks, and the 16 bytes used
11926  by the 128 bit variables, and 80 bytes for general purpose use.
11927  If any bit variables are used, the data variables will be placed in unused
11928  register banks and after the byte holding the last bit variable.
11929  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11930  (two bytes used), 
11931 \emph on
11932 data
11933 \emph default
11934  variables will be placed starting from address 0x10 to 0x20 and continue
11935  at address 0x22.
11936  You can also use -
11937 \begin_inset ERT
11938 status collapsed
11939
11940 \begin_layout Standard
11941
11942
11943 \backslash
11944 /
11945 \end_layout
11946
11947 \end_inset
11948
11949 -data-loc
11950 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11951
11952 \end_inset
11953
11954  to specify the start address of the 
11955 \emph on
11956 data
11957 \emph default
11958  and -
11959 \begin_inset ERT
11960 status collapsed
11961
11962 \begin_layout Standard
11963
11964
11965 \backslash
11966 /
11967 \end_layout
11968
11969 \end_inset
11970
11971 -iram-size
11972 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11973
11974 \end_inset
11975
11976  to specify the size of the total internal RAM (
11977 \emph on
11978 data
11979 \emph default
11980 +
11981 \emph on
11982 idata
11983 \emph default
11984 ).
11985  
11986 \newline
11987
11988 \end_layout
11989
11990 \begin_layout Standard
11991 By default the 8051 linker will place the stack after the last byte of (i)data
11992  variables.
11993  Option -
11994 \begin_inset ERT
11995 status collapsed
11996
11997 \begin_layout Standard
11998
11999
12000 \backslash
12001 /
12002 \end_layout
12003
12004 \end_inset
12005
12006 -stack-loc
12007 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12008
12009 \end_inset
12010
12011  allows you to specify the start of the stack, i.e.
12012  you could start it after any data in the general purpose area.
12013  If your microcontroller has additional indirectly addressable internal
12014  RAM (
12015 \emph on
12016 idata
12017 \emph default
12018 ) you can place the stack on it.
12019  You may also need to use -
12020 \begin_inset ERT
12021 status collapsed
12022
12023 \begin_layout Standard
12024
12025
12026 \backslash
12027 /
12028 \end_layout
12029
12030 \end_inset
12031
12032 -xdata-loc
12033 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12034
12035 \end_inset
12036
12037  to set the start address of the external RAM (
12038 \emph on
12039 xdata
12040 \emph default
12041 ) and -
12042 \begin_inset ERT
12043 status collapsed
12044
12045 \begin_layout Standard
12046
12047
12048 \backslash
12049 /
12050 \end_layout
12051
12052 \end_inset
12053
12054 -xram-size
12055 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12056
12057 \end_inset
12058
12059  to specify its size.
12060  Same goes for the code memory, using -
12061 \begin_inset ERT
12062 status collapsed
12063
12064 \begin_layout Standard
12065
12066
12067 \backslash
12068 /
12069 \end_layout
12070
12071 \end_inset
12072
12073 -code-loc
12074 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12075
12076 \end_inset
12077
12078  and -
12079 \begin_inset ERT
12080 status collapsed
12081
12082 \begin_layout Standard
12083
12084
12085 \backslash
12086 /
12087 \end_layout
12088
12089 \end_inset
12090
12091 -code-size
12092 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12093
12094 \end_inset
12095
12096 .
12097  If in doubt, don't specify any options and see if the resulting memory
12098  layout is appropriate, then you can adjust it.
12099 \end_layout
12100
12101 \begin_layout Standard
12102 The linker generates two files with memory allocation information.
12103  The first, with extension .map
12104 \begin_inset LatexCommand \index{<file>.map}
12105
12106 \end_inset
12107
12108  shows all the variables and segments.
12109  The second with extension .mem
12110 \begin_inset LatexCommand \index{<file>.mem}
12111
12112 \end_inset
12113
12114  shows the final memory layout.
12115  The linker will complain either if memory segments overlap, there is not
12116  enough memory, or there is not enough space for stack.
12117  If you get any linking warnings and/or errors related to stack or segments
12118  allocation, take a look at either the .map or .mem files to find out what
12119  the problem is.
12120  The .mem file may even suggest a solution to the problem.
12121 \begin_inset VSpace bigskip
12122 \end_inset
12123
12124
12125 \end_layout
12126
12127 \begin_layout Subsection
12128 Z80/Z180 Storage Class
12129 \begin_inset LatexCommand \index{Z80!Storage class}
12130
12131 \end_inset
12132
12133  Language Extensions
12134 \end_layout
12135
12136 \begin_layout Subsubsection
12137 sfr
12138 \begin_inset LatexCommand \index{sfr}
12139
12140 \end_inset
12141
12142
12143 \begin_inset LatexCommand \index{\_\_sfr}
12144
12145 \end_inset
12146
12147  (in/out to 8-bit addresses)
12148 \end_layout
12149
12150 \begin_layout Standard
12151 The Z80
12152 \begin_inset LatexCommand \index{Z80}
12153
12154 \end_inset
12155
12156  family has separate address spaces for memory and 
12157 \emph on
12158 i
12159 \emph default
12160 nput/
12161 \emph on
12162 o
12163 \emph default
12164 utput memory.
12165  I/O memory
12166 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12167
12168 \end_inset
12169
12170
12171 \begin_inset LatexCommand \index{Z80!I/O memory}
12172
12173 \end_inset
12174
12175
12176 \begin_inset LatexCommand \index{Z180!I/O memory}
12177
12178 \end_inset
12179
12180  is accessed with special instructions, e.g.:
12181 \end_layout
12182
12183 \begin_layout Verse
12184
12185 \family typewriter
12186 sfr at 0x78 IoPort;\InsetSpace ~
12187 \InsetSpace ~
12188 /* define a var in I/O space at 78h called IoPort */
12189  
12190 \end_layout
12191
12192 \begin_layout Standard
12193 Writing 0x01 to this variable generates the assembly code:
12194 \end_layout
12195
12196 \begin_layout Verse
12197
12198 \family typewriter
12199 3E 01\InsetSpace ~
12200 \InsetSpace ~
12201 \InsetSpace ~
12202 \InsetSpace ~
12203 \InsetSpace ~
12204 \InsetSpace ~
12205 ld a,#0x01
12206 \newline
12207 D3 78\InsetSpace ~
12208 \InsetSpace ~
12209 \InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 out (_IoPort),a 
12214 \end_layout
12215
12216 \begin_layout Subsubsection
12217 banked sfr
12218 \begin_inset LatexCommand \index{sfr}
12219
12220 \end_inset
12221
12222
12223 \begin_inset LatexCommand \index{\_\_sfr}
12224
12225 \end_inset
12226
12227  (in/out to 16-bit addresses)
12228 \end_layout
12229
12230 \begin_layout Standard
12231 The keyword 
12232 \emph on
12233 banked
12234 \emph default
12235  is used to support 16 bit addresses in I/O memory e.g.:
12236 \end_layout
12237
12238 \begin_layout Verse
12239
12240 \family typewriter
12241 sfr banked at
12242 \begin_inset LatexCommand \index{at}
12243
12244 \end_inset
12245
12246
12247 \begin_inset LatexCommand \index{\_\_at}
12248
12249 \end_inset
12250
12251  0x123 IoPort; 
12252 \end_layout
12253
12254 \begin_layout Standard
12255 Writing 0x01 to this variable generates the assembly code:
12256 \end_layout
12257
12258 \begin_layout Verse
12259
12260 \family typewriter
12261 01 23 01\InsetSpace ~
12262 \InsetSpace ~
12263 \InsetSpace ~
12264 ld bc,#_IoPort
12265 \newline
12266 3E 01\InsetSpace ~
12267 \InsetSpace ~
12268 \InsetSpace ~
12269 \InsetSpace ~
12270 \InsetSpace ~
12271 \InsetSpace ~
12272 ld a,#0x01 
12273 \newline
12274 ED 79\InsetSpace ~
12275 \InsetSpace ~
12276 \InsetSpace ~
12277 \InsetSpace ~
12278 \InsetSpace ~
12279 \InsetSpace ~
12280 out (c),a 
12281 \end_layout
12282
12283 \begin_layout Subsubsection
12284 sfr
12285 \begin_inset LatexCommand \index{sfr}
12286
12287 \end_inset
12288
12289
12290 \begin_inset LatexCommand \index{\_\_sfr}
12291
12292 \end_inset
12293
12294  (in0/out0 to 8 bit addresses on Z180
12295 \begin_inset LatexCommand \index{Z180}
12296
12297 \end_inset
12298
12299 /HD64180
12300 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12301
12302 \end_inset
12303
12304 )
12305 \end_layout
12306
12307 \begin_layout Standard
12308 The compiler option -
12309 \begin_inset ERT
12310 status collapsed
12311
12312 \begin_layout Standard
12313
12314
12315 \backslash
12316 /
12317 \end_layout
12318
12319 \end_inset
12320
12321 -portmode
12322 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12323
12324 \end_inset
12325
12326 =180 (80) and a compiler #pragma\InsetSpace ~
12327 portmode
12328 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12329
12330 \end_inset
12331
12332  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12333 ns 
12334 \family typewriter
12335 in0/out0
12336 \family default
12337  instead of 
12338 \family typewriter
12339 in/out
12340 \family default
12341 .
12342  If you include the file z180.h this will be set automatically.
12343 \begin_inset VSpace bigskip
12344 \end_inset
12345
12346
12347 \end_layout
12348
12349 \begin_layout Subsection
12350 HC08 Storage Class
12351 \begin_inset LatexCommand \index{HC08!Storage class}
12352
12353 \end_inset
12354
12355  Language Extensions
12356 \end_layout
12357
12358 \begin_layout Subsubsection
12359 data
12360 \begin_inset LatexCommand \index{data (hc08 storage class)}
12361
12362 \end_inset
12363
12364
12365 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12366
12367 \end_inset
12368
12369  
12370 \end_layout
12371
12372 \begin_layout Standard
12373 The data storage class declares a variable that resides in the first 256
12374  bytes of memory (the direct page).
12375  The HC08
12376 \begin_inset LatexCommand \index{HC08}
12377
12378 \end_inset
12379
12380  is most efficient at accessing variables (especially pointers) stored here.
12381 \end_layout
12382
12383 \begin_layout Subsubsection
12384 xdata
12385 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12386
12387 \end_inset
12388
12389
12390 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12391
12392 \end_inset
12393
12394  
12395 \end_layout
12396
12397 \begin_layout Standard
12398 The xdata storage class declares a variable that can reside anywhere in
12399  memory.
12400  This is the default if no storage class is specified.
12401  
12402 \begin_inset VSpace bigskip
12403 \end_inset
12404
12405
12406 \end_layout
12407
12408 \begin_layout Section
12409 Absolute Addressing
12410 \begin_inset LatexCommand \index{Absolute addressing}
12411
12412 \end_inset
12413
12414
12415 \end_layout
12416
12417 \begin_layout Standard
12418 Data items can be assigned an absolute address with the 
12419 \emph on
12420 at
12421 \begin_inset LatexCommand \index{at}
12422
12423 \end_inset
12424
12425
12426 \begin_inset LatexCommand \index{\_\_at}
12427
12428 \end_inset
12429
12430  <address>
12431 \emph default
12432  keyword, in addition to a storage class, e.g.:
12433 \end_layout
12434
12435 \begin_layout Verse
12436
12437 \family typewriter
12438 xdata
12439 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12440
12441 \end_inset
12442
12443
12444 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12445
12446 \end_inset
12447
12448  at
12449 \begin_inset LatexCommand \index{at}
12450
12451 \end_inset
12452
12453
12454 \begin_inset LatexCommand \index{\_\_at}
12455
12456 \end_inset
12457
12458  0x7ffe unsigned int chksum;
12459 \end_layout
12460
12461 \begin_layout Standard
12462 or, better conforming to ISO/IEC 9899 C:
12463 \end_layout
12464
12465 \begin_layout Verse
12466
12467 \family typewriter
12468 __xdata __at (0x7ffe) unsigned int chksum;
12469 \end_layout
12470
12471 \begin_layout Standard
12472 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12473  of the external ram.
12474  The compiler does 
12475 \emph on
12476 not
12477 \emph default
12478  reserve any space for variables declared in this way
12479 \begin_inset Marginal
12480 status collapsed
12481
12482 \begin_layout Standard
12483
12484 \series bold
12485 \InsetSpace ~
12486 !
12487 \end_layout
12488
12489 \end_inset
12490
12491  (they are implemented with an equate in the assembler).
12492  Thus it is left to the programmer to make sure there are no overlaps with
12493  other variables that are declared without the absolute address.
12494  The assembler listing file (.lst
12495 \begin_inset LatexCommand \index{<file>.lst}
12496
12497 \end_inset
12498
12499 ) and the linker output files (.rst
12500 \begin_inset LatexCommand \index{<file>.rst}
12501
12502 \end_inset
12503
12504 ) and (.map
12505 \begin_inset LatexCommand \index{<file>.map}
12506
12507 \end_inset
12508
12509 ) are good places to look for such overlaps.
12510  Variables with an absolute address are 
12511 \emph on
12512 not
12513 \begin_inset Marginal
12514 status collapsed
12515
12516 \begin_layout Standard
12517
12518 \series bold
12519 \InsetSpace ~
12520 !
12521 \end_layout
12522
12523 \end_inset
12524
12525
12526 \emph default
12527  initialized
12528 \begin_inset LatexCommand \index{Variable initialization}
12529
12530 \end_inset
12531
12532 .
12533 \end_layout
12534
12535 \begin_layout Standard
12536 In case of memory mapped I/O devices the keyword 
12537 \emph on
12538 volatile
12539 \emph default
12540  has to be used to tell the compiler that accesses might not be removed:
12541 \end_layout
12542
12543 \begin_layout Verse
12544
12545 \family typewriter
12546 volatile
12547 \begin_inset LatexCommand \index{volatile}
12548
12549 \end_inset
12550
12551  __xdata
12552 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12553
12554 \end_inset
12555
12556  __at
12557 \begin_inset LatexCommand \index{at}
12558
12559 \end_inset
12560
12561  (0x8000) unsigned char PORTA_8255;
12562 \end_layout
12563
12564 \begin_layout Standard
12565 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12566 r) array
12567 \family typewriter
12568 \size footnotesize
12569
12570 \begin_inset LatexCommand \index{Aligned array}
12571
12572 \end_inset
12573
12574
12575 \family default
12576 \size default
12577  starts at a block (256 byte) boundary
12578 \begin_inset LatexCommand \index{block boundary}
12579
12580 \end_inset
12581
12582  (section 
12583 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12584
12585 \end_inset
12586
12587  has an example).
12588 \newline
12589 Absolute addresses can be specified for variables in all
12590  storage classes, e.g.:
12591 \end_layout
12592
12593 \begin_layout Verse
12594
12595 \family typewriter
12596 __bit
12597 \begin_inset LatexCommand \index{bit}
12598
12599 \end_inset
12600
12601  __at
12602 \begin_inset LatexCommand \index{at}
12603
12604 \end_inset
12605
12606  (0x02) bvar;
12607 \end_layout
12608
12609 \begin_layout Standard
12610 The above example will allocate the variable at offset 0x02 in the bit-addressab
12611 le space.
12612  There is no real advantage to assigning absolute addresses to variables
12613  in this manner, unless you want strict control over all the variables allocated.
12614  One possible use would be to write hardware portable code.
12615  For example, if you have a routine that uses one or more of the microcontroller
12616  I/O pins, and such pins are different for two different hardwares, you
12617  can declare the I/O pins in your routine using:
12618 \end_layout
12619
12620 \begin_layout Verse
12621
12622 \family typewriter
12623 extern volatile
12624 \begin_inset LatexCommand \index{volatile}
12625
12626 \end_inset
12627
12628  __bit MOSI;\InsetSpace ~
12629 \InsetSpace ~
12630 \InsetSpace ~
12631 \InsetSpace ~
12632 /* master out, slave in */
12633 \newline
12634 extern volatile __bit MISO;\InsetSpace ~
12635 \InsetSpace ~
12636 \InsetSpace ~
12637 \InsetSpace ~
12638 /* master
12639  in, slave out */
12640 \newline
12641 extern volatile __bit MCLK;\InsetSpace ~
12642 \InsetSpace ~
12643 \InsetSpace ~
12644 \InsetSpace ~
12645 /* master clock */
12646 \newline
12647
12648 \newline
12649 /* Input and
12650  Output of a byte on a 3-wire serial bus.
12651 \newline
12652 \InsetSpace ~
12653 \InsetSpace ~
12654 \InsetSpace ~
12655 If needed adapt polarity of clock,
12656  polarity of data and bit order
12657 \newline
12658 \InsetSpace ~
12659 */
12660 \newline
12661 unsigned char spi_io(unsigned char out_byte)
12662  
12663 \newline
12664
12665 \newline
12666 \InsetSpace ~
12667 \InsetSpace ~
12668 \InsetSpace ~
12669 \InsetSpace ~
12670 unsigned char i=8;
12671 \newline
12672 \InsetSpace ~
12673 \InsetSpace ~
12674 \InsetSpace ~
12675 \InsetSpace ~
12676 do { 
12677 \newline
12678 \InsetSpace ~
12679 \InsetSpace ~
12680 \InsetSpace ~
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 \InsetSpace ~
12686 MOSI = out_byte & 0x80; 
12687 \newline
12688 \InsetSpace ~
12689 \InsetSpace ~
12690 \InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 out_byte <<= 1;
12697 \newline
12698 \InsetSpace ~
12699 \InsetSpace ~
12700 \InsetSpace ~
12701 \InsetSpace ~
12702 \InsetSpace ~
12703 \InsetSpace ~
12704 \InsetSpace ~
12705 \InsetSpace ~
12706 MCLK =
12707  1; 
12708 \newline
12709 \InsetSpace ~
12710 \InsetSpace ~
12711 \InsetSpace ~
12712 \InsetSpace ~
12713 \InsetSpace ~
12714 \InsetSpace ~
12715 \InsetSpace ~
12716 \InsetSpace ~
12717 /* _asm nop _endasm; */\InsetSpace ~
12718 \InsetSpace ~
12719 \InsetSpace ~
12720 \InsetSpace ~
12721 \InsetSpace ~
12722 \InsetSpace ~
12723 \InsetSpace ~
12724 \InsetSpace ~
12725 /* for slow peripherals */
12726 \newline
12727 \InsetSpace ~
12728 \InsetSpace ~
12729 \InsetSpace ~
12730 \InsetSpace ~
12731 \InsetSpace ~
12732 \InsetSpace ~
12733 \InsetSpace ~
12734 \InsetSpace ~
12735 if(MISO) 
12736 \newline
12737 \InsetSpace ~
12738 \InsetSpace ~
12739 \InsetSpace ~
12740 \InsetSpace ~
12741 \InsetSpace ~
12742 \InsetSpace ~
12743 \InsetSpace ~
12744 \InsetSpace ~
12745 \InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 out_byte +=
12750  1; 
12751 \newline
12752 \InsetSpace ~
12753 \InsetSpace ~
12754 \InsetSpace ~
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 \InsetSpace ~
12759 \InsetSpace ~
12760 MCLK = 0; 
12761 \newline
12762 \InsetSpace ~
12763 \InsetSpace ~
12764 \InsetSpace ~
12765 \InsetSpace ~
12766 } while(--i);
12767 \newline
12768 \InsetSpace ~
12769 \InsetSpace ~
12770 \InsetSpace ~
12771 \InsetSpace ~
12772 return out_byte; 
12773 \newline
12774 }
12775 \end_layout
12776
12777 \begin_layout Standard
12778 Then, someplace in the code for the first hardware you would use
12779 \end_layout
12780
12781 \begin_layout Verse
12782
12783 \family typewriter
12784 __bit __at
12785 \begin_inset LatexCommand \index{at}
12786
12787 \end_inset
12788
12789
12790 \begin_inset LatexCommand \index{\_\_at}
12791
12792 \end_inset
12793
12794  (0x80) MOSI;\InsetSpace ~
12795 \InsetSpace ~
12796 \InsetSpace ~
12797 \InsetSpace ~
12798 /* I/O port 0, bit 0 */
12799 \newline
12800 __bit __at (0x81) MISO;\InsetSpace ~
12801 \InsetSpace ~
12802 \InsetSpace ~
12803 \InsetSpace ~
12804 /* I/O port 0,
12805  bit 1 */
12806 \newline
12807 __bit __at (0x82) MCLK;\InsetSpace ~
12808 \InsetSpace ~
12809 \InsetSpace ~
12810 \InsetSpace ~
12811 /* I/O port 0, bit 2 */
12812 \end_layout
12813
12814 \begin_layout Standard
12815 Similarly, for the second hardware you would use
12816 \end_layout
12817
12818 \begin_layout Verse
12819
12820 \family typewriter
12821 __bit __at (0x83) MOSI;\InsetSpace ~
12822 \InsetSpace ~
12823 \InsetSpace ~
12824 \InsetSpace ~
12825 /* I/O port 0, bit 3 */
12826 \newline
12827 __bit __at (0x91) MISO;\InsetSpace ~
12828 \InsetSpace ~
12829 \InsetSpace ~
12830 \InsetSpace ~
12831 /*
12832  I/O port 1, bit 1 */
12833 \newline
12834 __bit
12835 \begin_inset LatexCommand \index{bit}
12836
12837 \end_inset
12838
12839  __at (0x92) MCLK;\InsetSpace ~
12840 \InsetSpace ~
12841 \InsetSpace ~
12842 \InsetSpace ~
12843 /* I/O port 1, bit 2 */
12844 \end_layout
12845
12846 \begin_layout Standard
12847 and you can use the same hardware dependent routine without changes, as
12848  for example in a library.
12849  This is somehow similar to sbit, but only one absolute address has to be
12850  specified in the whole project.
12851 \begin_inset VSpace bigskip
12852 \end_inset
12853
12854
12855 \end_layout
12856
12857 \begin_layout Section
12858 Parameters
12859 \begin_inset LatexCommand \index{Parameters}
12860
12861 \end_inset
12862
12863
12864 \begin_inset LatexCommand \index{function parameter}
12865
12866 \end_inset
12867
12868  & Local Variables
12869 \begin_inset LatexCommand \index{local variables}
12870
12871 \end_inset
12872
12873
12874 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12875
12876 \end_inset
12877
12878
12879 \end_layout
12880
12881 \begin_layout Standard
12882 Automatic (local) variables and parameters to functions can either be placed
12883  on the stack or in data-space.
12884  The default action of the compiler is to place these variables in the internal
12885  RAM (for small model) or external RAM (for large model).
12886  This in fact makes them similar to 
12887 \emph on
12888 static
12889 \begin_inset LatexCommand \index{static}
12890
12891 \end_inset
12892
12893
12894 \emph default
12895  so by default functions are non-reentrant
12896 \begin_inset LatexCommand \index{reentrant}
12897
12898 \end_inset
12899
12900 .
12901  
12902 \newline
12903
12904 \newline
12905 They can be placed on the stack
12906 \begin_inset LatexCommand \index{stack}
12907
12908 \end_inset
12909
12910  by using the
12911 \emph on
12912  -
12913 \begin_inset ERT
12914 status collapsed
12915
12916 \begin_layout Standard
12917
12918
12919 \backslash
12920 /
12921 \end_layout
12922
12923 \end_inset
12924
12925 -stack-auto
12926 \begin_inset LatexCommand \index{-\/-stack-auto}
12927
12928 \end_inset
12929
12930
12931 \emph default
12932  option, by using 
12933 \emph on
12934 #pragma\InsetSpace ~
12935 stackauto
12936 \emph default
12937
12938 \begin_inset LatexCommand \index{\#pragma stackauto}
12939
12940 \end_inset
12941
12942  or by using the 
12943 \emph on
12944 reentrant
12945 \begin_inset LatexCommand \index{reentrant}
12946
12947 \end_inset
12948
12949
12950 \emph default
12951  keyword in the function declaration, e.g.:
12952 \end_layout
12953
12954 \begin_layout Verse
12955
12956 \family typewriter
12957 unsigned char foo(char i) __reentrant 
12958 \newline
12959
12960 \newline
12961 \InsetSpace ~
12962 \InsetSpace ~
12963 \InsetSpace ~
12964 \InsetSpace ~
12965 ...
12966  
12967 \newline
12968 }
12969 \end_layout
12970
12971 \begin_layout Standard
12972 Since stack space on 8051 is limited, the 
12973 \emph on
12974 reentrant 
12975 \emph default
12976 keyword or the
12977 \emph on
12978  -
12979 \begin_inset ERT
12980 status collapsed
12981
12982 \begin_layout Standard
12983
12984
12985 \backslash
12986 /
12987 \end_layout
12988
12989 \end_inset
12990
12991 -stack-auto
12992 \emph default
12993  option should be used sparingly.
12994  Note that the reentrant keyword just means that the parameters & local
12995  variables will be allocated to the stack, it 
12996 \emph on
12997 does not
12998 \emph default
12999  mean that the function is register bank
13000 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13001
13002 \end_inset
13003
13004  independent.
13005 \newline
13006
13007 \newline
13008 Local variables
13009 \begin_inset LatexCommand \index{local variables}
13010
13011 \end_inset
13012
13013  can be assigned storage classes and absolute
13014 \begin_inset LatexCommand \index{Absolute addressing}
13015
13016 \end_inset
13017
13018  addresses, e.g.: 
13019 \end_layout
13020
13021 \begin_layout Verse
13022
13023 \family typewriter
13024 unsigned char foo() 
13025 \newline
13026 {
13027 \newline
13028 \InsetSpace ~
13029 \InsetSpace ~
13030 \InsetSpace ~
13031 \InsetSpace ~
13032 __xdata unsigned char i;
13033 \newline
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 \InsetSpace ~
13037 \InsetSpace ~
13038 __bit bvar;
13039 \newline
13040 \InsetSpace ~
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 __data __at
13045 \begin_inset LatexCommand \index{at}
13046
13047 \end_inset
13048
13049  (0x31) unsigned char j;
13050 \newline
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 \InsetSpace ~
13055 ...
13056  
13057 \newline
13058 }
13059 \end_layout
13060
13061 \begin_layout Standard
13062 In the above example the variable 
13063 \emph on
13064 i
13065 \emph default
13066  will be allocated in the external ram, 
13067 \emph on
13068 bvar
13069 \emph default
13070  in bit addressable space and
13071 \emph on
13072  j
13073 \emph default
13074  in internal ram.
13075  When compiled with 
13076 \emph on
13077 -
13078 \begin_inset ERT
13079 status collapsed
13080
13081 \begin_layout Standard
13082
13083
13084 \backslash
13085 /
13086 \end_layout
13087
13088 \end_inset
13089
13090 -stack-auto
13091 \emph default
13092  or when a function is declared as 
13093 \emph on
13094 reentrant
13095 \emph default
13096  this should only be done for static variables.
13097 \end_layout
13098
13099 \begin_layout Standard
13100 Parameters
13101 \begin_inset LatexCommand \index{function parameter}
13102
13103 \end_inset
13104
13105  however are not allowed any storage class
13106 \begin_inset LatexCommand \index{Storage class}
13107
13108 \end_inset
13109
13110 , (storage classes for parameters will be ignored), their allocation is
13111  governed by the memory model in use, and the reentrancy options.
13112 \end_layout
13113
13114 \begin_layout Standard
13115 It is however allowed to use bit parameters in reentrant functions and also
13116  non-static local bit variables are supported.
13117  Efficient use is limited to 8 semi-bitregisters in bit space.
13118  They are pushed and popped to stack
13119 \begin_inset LatexCommand \index{stack}
13120
13121 \end_inset
13122
13123  as a single byte just like the normal registers.
13124 \end_layout
13125
13126 \begin_layout Section
13127 Overlaying
13128 \begin_inset LatexCommand \label{sub:Overlaying}
13129
13130 \end_inset
13131
13132
13133 \begin_inset LatexCommand \index{Overlaying}
13134
13135 \end_inset
13136
13137
13138 \end_layout
13139
13140 \begin_layout Standard
13141 For non-reentrant
13142 \begin_inset LatexCommand \index{reentrant}
13143
13144 \end_inset
13145
13146  functions SDCC will try to reduce internal ram space usage by overlaying
13147  parameters and local variables of a function (if possible).
13148  Parameters and local variables
13149 \begin_inset LatexCommand \index{local variables}
13150
13151 \end_inset
13152
13153  of a function will be allocated to an overlayable segment if the function
13154  has 
13155 \emph on
13156 no other function calls and the function is non-reentrant and the memory
13157  model
13158 \begin_inset LatexCommand \index{Memory model}
13159
13160 \end_inset
13161
13162  is small.
13163
13164 \emph default
13165  If an explicit storage class
13166 \begin_inset LatexCommand \index{Storage class}
13167
13168 \end_inset
13169
13170  is specified for a local variable, it will NOT be overlayed.
13171 \end_layout
13172
13173 \begin_layout Standard
13174 Note that the compiler (not the linkage editor) makes the decision for overlayin
13175 g the data items.
13176  Functions that are called from an interrupt service routine
13177 \begin_inset Marginal
13178 status collapsed
13179
13180 \begin_layout Standard
13181
13182 \series bold
13183 !
13184 \end_layout
13185
13186 \end_inset
13187
13188  should be preceded by a #pragma\InsetSpace ~
13189 nooverlay
13190 \begin_inset LatexCommand \index{\#pragma nooverlay}
13191
13192 \end_inset
13193
13194  if they are not reentrant.
13195 \end_layout
13196
13197 \begin_layout Standard
13198 Also note that the compiler does not do any processing of inline assembler
13199  code, so the compiler might incorrectly assign local variables and parameters
13200  of a function into the overlay segment if the inline assembler code calls
13201  other c-functions that might use the overlay.
13202  In that case the #pragma\InsetSpace ~
13203 nooverlay should be used.
13204 \end_layout
13205
13206 \begin_layout Standard
13207 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13208 tion
13209 \begin_inset LatexCommand \index{Multiplication}
13210
13211 \end_inset
13212
13213  or division
13214 \begin_inset LatexCommand \index{Division}
13215
13216 \end_inset
13217
13218  will NOT be overlayed since these are implemented using external functions,
13219  e.g.:
13220 \end_layout
13221
13222 \begin_layout Verse
13223
13224 \family typewriter
13225 #pragma save 
13226 \newline
13227 #pragma nooverlay
13228 \begin_inset LatexCommand \index{\#pragma nooverlay}
13229
13230 \end_inset
13231
13232  
13233 \newline
13234 void set_error(unsigned char errcd) 
13235 \newline
13236 {
13237 \newline
13238 \InsetSpace ~
13239 \InsetSpace ~
13240 \InsetSpace ~
13241 \InsetSpace ~
13242 P3 = errcd;
13243 \newline
13244
13245 \newline
13246 #pragma restore 
13247 \newline
13248
13249 \newline
13250 void
13251  some_isr () __interrupt
13252 \begin_inset LatexCommand \index{interrupt}
13253
13254 \end_inset
13255
13256  (2)
13257 \newline
13258 {
13259 \newline
13260 \InsetSpace ~
13261 \InsetSpace ~
13262 \InsetSpace ~
13263 \InsetSpace ~
13264 ...
13265 \newline
13266 \InsetSpace ~
13267 \InsetSpace ~
13268 \InsetSpace ~
13269 \InsetSpace ~
13270 set_error(10);
13271 \newline
13272 \InsetSpace ~
13273 \InsetSpace ~
13274 \InsetSpace ~
13275 \InsetSpace ~
13276 ...
13277  
13278 \newline
13279 }
13280 \end_layout
13281
13282 \begin_layout Standard
13283 In the above example the parameter 
13284 \emph on
13285 errcd
13286 \emph default
13287  for the function 
13288 \emph on
13289 set_error
13290 \emph default
13291  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13292 nooverlay was
13293  not present, this could cause unpredictable runtime behavior when called
13294  from an interrupt service routine.
13295  The #pragma\InsetSpace ~
13296 nooverlay ensures that the parameters and local variables for
13297  the function are NOT overlayed.
13298 \begin_inset VSpace bigskip
13299 \end_inset
13300
13301
13302 \end_layout
13303
13304 \begin_layout Section
13305 Interrupt Service Routines
13306 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13307
13308 \end_inset
13309
13310
13311 \end_layout
13312
13313 \begin_layout Subsection
13314 General Information
13315 \end_layout
13316
13317 \begin_layout Standard
13318 SDCC allows 
13319 \emph on
13320 i
13321 \emph default
13322 nterrupt 
13323 \emph on
13324 s
13325 \emph default
13326 ervice 
13327 \emph on
13328 r
13329 \emph default
13330 outines to be coded in C, with some extended keywords.
13331 \end_layout
13332
13333 \begin_layout Verse
13334
13335 \family typewriter
13336 void timer_isr (void) __interrupt (1) __using (1) 
13337 \newline
13338
13339 \newline
13340 \InsetSpace ~
13341 \InsetSpace ~
13342 \InsetSpace ~
13343 \InsetSpace ~
13344 ...
13345  
13346 \newline
13347 }
13348 \end_layout
13349
13350 \begin_layout Standard
13351 The optional number following the 
13352 \emph on
13353 interrupt
13354 \begin_inset LatexCommand \index{interrupt}
13355
13356 \end_inset
13357
13358
13359 \begin_inset LatexCommand \index{\_\_interrupt}
13360
13361 \end_inset
13362
13363
13364 \emph default
13365  keyword is the interrupt number this routine will service.
13366  When present, the compiler will insert a call to this routine in the interrupt
13367  vector table
13368 \begin_inset LatexCommand \index{interrupt vector table}
13369
13370 \end_inset
13371
13372  for the interrupt number specified.
13373  If you have multiple source files in your project, interrupt service routines
13374  can be present in any of them, but a prototype of the isr MUST be present
13375  or included in the file that contains the function 
13376 \emph on
13377 main
13378 \emph default
13379 .
13380  The optional (8051 specific) keyword 
13381 \emph on
13382 using
13383 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13384
13385 \end_inset
13386
13387
13388 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13389
13390 \end_inset
13391
13392
13393 \emph default
13394  can be used to tell the compiler to use the specified register bank when
13395  generating code for this function.
13396  
13397 \newline
13398 Interrupt service routines open the door for some very interesting bugs:
13399 \end_layout
13400
13401 \begin_layout Subsubsection
13402 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13403
13404 \end_inset
13405
13406 Common interrupt pitfall: variable not declared 
13407 \emph on
13408 volatile
13409 \end_layout
13410
13411 \begin_layout Standard
13412 If an interrupt service routine changes variables which are accessed by
13413  other functions these variables have to be declared 
13414 \emph on
13415 volatile
13416 \emph default
13417
13418 \begin_inset LatexCommand \index{volatile}
13419
13420 \end_inset
13421
13422 .
13423  See 
13424 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13425
13426 \end_inset
13427
13428  .
13429 \end_layout
13430
13431 \begin_layout Subsubsection
13432 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13433
13434 \end_inset
13435
13436 Common interrupt pitfall: 
13437 \emph on
13438 non-atomic access
13439 \end_layout
13440
13441 \begin_layout Standard
13442 If the access to these variables is not 
13443 \emph on
13444 atomic
13445 \begin_inset LatexCommand \index{atomic}
13446
13447 \end_inset
13448
13449
13450 \emph default
13451  (i.e.
13452  the processor needs more than one instruction for the access and could
13453  be interrupted while accessing the variable) the interrupt must be disabled
13454  during the access to avoid inconsistent data.
13455  
13456 \newline
13457 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13458  and should be protected by disabling interrupts.
13459  You're not automatically on the safe side if you use 8 bit variables though.
13460  We need an example here: f.e.
13461  on the 8051 the harmless looking 
13462 \begin_inset Quotes srd
13463 \end_inset
13464
13465
13466 \family typewriter
13467 flags\InsetSpace ~
13468 |=\InsetSpace ~
13469 0x80;
13470 \family default
13471
13472 \begin_inset Quotes sld
13473 \end_inset
13474
13475  is not atomic if 
13476 \family typewriter
13477 flags
13478 \family default
13479  resides in xdata.
13480  Setting 
13481 \begin_inset Quotes srd
13482 \end_inset
13483
13484
13485 \family typewriter
13486 flags\InsetSpace ~
13487 |=\InsetSpace ~
13488 0x40;
13489 \family default
13490
13491 \begin_inset Quotes sld
13492 \end_inset
13493
13494  from within an interrupt routine might get lost if the interrupt occurs
13495  at the wrong time.
13496  
13497 \begin_inset Quotes sld
13498 \end_inset
13499
13500
13501 \family typewriter
13502 counter\InsetSpace ~
13503 +=\InsetSpace ~
13504 8;
13505 \family default
13506
13507 \begin_inset Quotes srd
13508 \end_inset
13509
13510  is not atomic on the 8051 even if 
13511 \family typewriter
13512 counter
13513 \family default
13514  is located in data memory.
13515 \newline
13516 Bugs like these are hard to reproduce and can
13517  cause a lot of trouble.
13518  
13519 \end_layout
13520
13521 \begin_layout Subsubsection
13522 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13523
13524 \end_inset
13525
13526 Common interrupt pitfall: 
13527 \emph on
13528 stack overflow
13529 \end_layout
13530
13531 \begin_layout Standard
13532 The return address and the registers used in the interrupt service routine
13533  are saved on the stack
13534 \begin_inset LatexCommand \index{stack}
13535
13536 \end_inset
13537
13538  so there must be sufficient stack space.
13539  If there isn't variables or registers (or even the return address itself)
13540  will be corrupted.
13541  This 
13542 \emph on
13543 stack overflow
13544 \emph default
13545
13546 \begin_inset LatexCommand \index{stack overflow}
13547
13548 \end_inset
13549
13550  is most likely to happen if the interrupt occurs during the 
13551 \begin_inset Quotes sld
13552 \end_inset
13553
13554 deepest
13555 \begin_inset Quotes srd
13556 \end_inset
13557
13558  subroutine when the stack is already in use for f.e.
13559  many return addresses.
13560 \end_layout
13561
13562 \begin_layout Subsubsection
13563 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13564
13565 \end_inset
13566
13567 Common interrupt pitfall: 
13568 \emph on
13569 use of non-reentrant functions
13570 \end_layout
13571
13572 \begin_layout Standard
13573 A special note here, int (16 bit) and long (32 bit) integer division
13574 \begin_inset LatexCommand \index{Division}
13575
13576 \end_inset
13577
13578 , multiplication
13579 \begin_inset LatexCommand \index{Multiplication}
13580
13581 \end_inset
13582
13583  & modulus
13584 \begin_inset LatexCommand \index{Modulus}
13585
13586 \end_inset
13587
13588  and floating-point
13589 \begin_inset LatexCommand \index{Floating point support}
13590
13591 \end_inset
13592
13593  operations are implemented using external support routines.
13594  If an interrupt service routine needs to do any of these operations then
13595  the support routines (as mentioned in a following section) will have to
13596  be recompiled using the
13597 \emph on
13598  -
13599 \begin_inset ERT
13600 status collapsed
13601
13602 \begin_layout Standard
13603
13604
13605 \backslash
13606 /
13607 \end_layout
13608
13609 \end_inset
13610
13611 -stack-auto
13612 \begin_inset LatexCommand \index{-\/-stack-auto}
13613
13614 \end_inset
13615
13616
13617 \emph default
13618  option and the source file will need to be compiled using the 
13619 \emph on
13620 -
13621 \begin_inset ERT
13622 status collapsed
13623
13624 \begin_layout Standard
13625
13626
13627 \backslash
13628 /
13629 \end_layout
13630
13631 \end_inset
13632
13633 -int-long-reent
13634 \emph default
13635
13636 \begin_inset LatexCommand \index{-\/-int-long-reent}
13637
13638 \end_inset
13639
13640  compiler option.
13641  
13642 \newline
13643 Note, the type promotion
13644 \begin_inset LatexCommand \index{type promotion}
13645
13646 \end_inset
13647
13648  required by ANSI C can cause 16 bit routines to be used
13649 \begin_inset Marginal
13650 status collapsed
13651
13652 \begin_layout Standard
13653
13654 \series bold
13655 \InsetSpace ~
13656 !
13657 \end_layout
13658
13659 \end_inset
13660
13661  without the programmer being aware of it.
13662  See f.e.
13663  the cast 
13664 \family typewriter
13665 (unsigned char)(tail-1)
13666 \family default
13667  within the if clause in section 
13668 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13669
13670 \end_inset
13671
13672 .
13673 \end_layout
13674
13675 \begin_layout Standard
13676 Calling other functions from an interrupt service routine is not recommended,
13677  avoid it if possible.
13678  Note that when some function is called from an interrupt service routine
13679  it should be preceded by a #pragma\InsetSpace ~
13680 nooverlay
13681 \begin_inset LatexCommand \index{\#pragma nooverlay}
13682
13683 \end_inset
13684
13685  if it is not reentrant.
13686  Furthermore nonreentrant functions should not be called from the main program
13687  while the interrupt service routine might be active.
13688  They also must not be called from low priority interrupt service routines
13689  while a high priority interrupt service routine might be active.
13690  You could use semaphores or make the function
13691 \emph on
13692  critical
13693 \emph default
13694  if all parameters are passed in registers.
13695 \newline
13696  Also see section 
13697 \begin_inset LatexCommand \ref{sub:Overlaying}
13698
13699 \end_inset
13700
13701 \InsetSpace ~
13702 about Overlaying and section 
13703 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13704
13705 \end_inset
13706
13707 \InsetSpace ~
13708 about Functions using private register banks.
13709 \begin_inset VSpace bigskip
13710 \end_inset
13711
13712
13713 \end_layout
13714
13715 \begin_layout Subsection
13716 MCS51/DS390 Interrupt Service Routines
13717 \end_layout
13718
13719 \begin_layout Standard
13720 Interrupt
13721 \begin_inset LatexCommand \index{interrupt}
13722
13723 \end_inset
13724
13725  numbers and the corresponding address & descriptions for the Standard 8051/8052
13726  are listed below.
13727  SDCC will automatically adjust the 
13728 \begin_inset LatexCommand \index{interrupt vector table}
13729
13730 \end_inset
13731
13732  to the maximum interrupt number specified.
13733 \newline
13734
13735 \end_layout
13736
13737 \begin_layout Standard
13738 \align center
13739 \begin_inset Tabular
13740 <lyxtabular version="3" rows="9" columns="3">
13741 <features>
13742 <column alignment="center" valignment="top" leftline="true" width="0in">
13743 <column alignment="left" valignment="top" leftline="true" width="0in">
13744 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13745 <row topline="true" bottomline="true">
13746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13747 \begin_inset Text
13748
13749 \begin_layout Standard
13750 Interrupt #
13751 \end_layout
13752
13753 \end_inset
13754 </cell>
13755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13756 \begin_inset Text
13757
13758 \begin_layout Standard
13759 Description
13760 \end_layout
13761
13762 \end_inset
13763 </cell>
13764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13765 \begin_inset Text
13766
13767 \begin_layout Standard
13768 Vector Address
13769 \end_layout
13770
13771 \end_inset
13772 </cell>
13773 </row>
13774 <row topline="true">
13775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13776 \begin_inset Text
13777
13778 \begin_layout Standard
13779 0
13780 \end_layout
13781
13782 \end_inset
13783 </cell>
13784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13785 \begin_inset Text
13786
13787 \begin_layout Standard
13788 External 0
13789 \end_layout
13790
13791 \end_inset
13792 </cell>
13793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13794 \begin_inset Text
13795
13796 \begin_layout Standard
13797 0x0003
13798 \end_layout
13799
13800 \end_inset
13801 </cell>
13802 </row>
13803 <row topline="true">
13804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13805 \begin_inset Text
13806
13807 \begin_layout Standard
13808 1
13809 \end_layout
13810
13811 \end_inset
13812 </cell>
13813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13814 \begin_inset Text
13815
13816 \begin_layout Standard
13817 Timer 0
13818 \end_layout
13819
13820 \end_inset
13821 </cell>
13822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13823 \begin_inset Text
13824
13825 \begin_layout Standard
13826 0x000b
13827 \end_layout
13828
13829 \end_inset
13830 </cell>
13831 </row>
13832 <row topline="true">
13833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13834 \begin_inset Text
13835
13836 \begin_layout Standard
13837 2
13838 \end_layout
13839
13840 \end_inset
13841 </cell>
13842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13843 \begin_inset Text
13844
13845 \begin_layout Standard
13846 External 1
13847 \end_layout
13848
13849 \end_inset
13850 </cell>
13851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13852 \begin_inset Text
13853
13854 \begin_layout Standard
13855 0x0013
13856 \end_layout
13857
13858 \end_inset
13859 </cell>
13860 </row>
13861 <row topline="true">
13862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13863 \begin_inset Text
13864
13865 \begin_layout Standard
13866 3
13867 \end_layout
13868
13869 \end_inset
13870 </cell>
13871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13872 \begin_inset Text
13873
13874 \begin_layout Standard
13875 Timer 1
13876 \end_layout
13877
13878 \end_inset
13879 </cell>
13880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13881 \begin_inset Text
13882
13883 \begin_layout Standard
13884 0x001b
13885 \end_layout
13886
13887 \end_inset
13888 </cell>
13889 </row>
13890 <row topline="true">
13891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13892 \begin_inset Text
13893
13894 \begin_layout Standard
13895 4
13896 \end_layout
13897
13898 \end_inset
13899 </cell>
13900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13901 \begin_inset Text
13902
13903 \begin_layout Standard
13904 Serial
13905 \end_layout
13906
13907 \end_inset
13908 </cell>
13909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13910 \begin_inset Text
13911
13912 \begin_layout Standard
13913 0x0023
13914 \end_layout
13915
13916 \end_inset
13917 </cell>
13918 </row>
13919 <row topline="true">
13920 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13921 \begin_inset Text
13922
13923 \begin_layout Standard
13924 5
13925 \end_layout
13926
13927 \end_inset
13928 </cell>
13929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13930 \begin_inset Text
13931
13932 \begin_layout Standard
13933 Timer 2 (8052)
13934 \end_layout
13935
13936 \end_inset
13937 </cell>
13938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13939 \begin_inset Text
13940
13941 \begin_layout Standard
13942 0x002b
13943 \end_layout
13944
13945 \end_inset
13946 </cell>
13947 </row>
13948 <row topline="true">
13949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13950 \begin_inset Text
13951
13952 \begin_layout Standard
13953 ...
13954 \end_layout
13955
13956 \end_inset
13957 </cell>
13958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13959 \begin_inset Text
13960
13961 \begin_layout Standard
13962
13963 \end_layout
13964
13965 \end_inset
13966 </cell>
13967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13968 \begin_inset Text
13969
13970 \begin_layout Standard
13971 ...
13972 \end_layout
13973
13974 \end_inset
13975 </cell>
13976 </row>
13977 <row topline="true" bottomline="true">
13978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13979 \begin_inset Text
13980
13981 \begin_layout Standard
13982 n
13983 \end_layout
13984
13985 \end_inset
13986 </cell>
13987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13988 \begin_inset Text
13989
13990 \begin_layout Standard
13991
13992 \end_layout
13993
13994 \end_inset
13995 </cell>
13996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13997 \begin_inset Text
13998
13999 \begin_layout Standard
14000 0x0003 + 8*n
14001 \end_layout
14002
14003 \end_inset
14004 </cell>
14005 </row>
14006 </lyxtabular>
14007
14008 \end_inset
14009
14010
14011 \newline
14012
14013 \end_layout
14014
14015 \begin_layout Standard
14016 If the interrupt service routine is defined without 
14017 \emph on
14018 using
14019 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14020
14021 \end_inset
14022
14023
14024 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14025
14026 \end_inset
14027
14028
14029 \emph default
14030  a register bank or with register bank 0 (
14031 \emph on
14032 using
14033 \emph default
14034  0), the compiler will save the registers used by itself on the stack upon
14035  entry and restore them at exit, however if such an interrupt service routine
14036  calls another function then the entire register bank will be saved on the
14037  stack.
14038  This scheme may be advantageous for small interrupt service routines which
14039  have low register usage.
14040 \end_layout
14041
14042 \begin_layout Standard
14043 If the interrupt service routine is defined to be using a specific register
14044  bank then only 
14045 \emph on
14046 a, b, dptr
14047 \emph default
14048  & psw are saved and restored, if such an interrupt service routine calls
14049  another function (using another register bank) then the entire register
14050  bank of the called function will be saved on the stack
14051 \begin_inset LatexCommand \index{stack}
14052
14053 \end_inset
14054
14055 .
14056  This scheme is recommended for larger interrupt service routines.
14057 \begin_inset VSpace bigskip
14058 \end_inset
14059
14060
14061 \end_layout
14062
14063 \begin_layout Subsection
14064 HC08
14065 \begin_inset LatexCommand \index{HC08}
14066
14067 \end_inset
14068
14069  Interrupt Service Routines
14070 \end_layout
14071
14072 \begin_layout Standard
14073 Since the number of interrupts
14074 \begin_inset LatexCommand \index{HC08!interrupt}
14075
14076 \end_inset
14077
14078  available is chip specific and the interrupt vector table always ends at
14079  the last byte of memory, the interrupt numbers corresponds to the interrupt
14080  vectors in reverse order of address.
14081  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14082  2 will use the interrupt vector at 0xfffa, and so on.
14083  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14084  this way; instead see section 
14085 \begin_inset LatexCommand \ref{sub:Startup-Code}
14086
14087 \end_inset
14088
14089  for details on customizing startup.
14090 \begin_inset VSpace bigskip
14091 \end_inset
14092
14093
14094 \end_layout
14095
14096 \begin_layout Subsection
14097 Z80 Interrupt Service Routines
14098 \end_layout
14099
14100 \begin_layout Standard
14101 The Z80
14102 \begin_inset LatexCommand \index{Z80}
14103
14104 \end_inset
14105
14106  uses several different methods for determining the correct interrupt
14107 \begin_inset LatexCommand \index{Z80!interrupt}
14108
14109 \end_inset
14110
14111  vector depending on the hardware implementation.
14112  Therefore, SDCC ignores the optional interrupt number and does not attempt
14113  to generate an interrupt vector table.
14114 \end_layout
14115
14116 \begin_layout Standard
14117 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14118  instruction to return from the interrupt.
14119  To write an interrupt handler for the non-maskable interrupt, which needs
14120  a RETN instruction instead, add the 
14121 \emph on
14122 critical
14123 \emph default
14124  keyword:
14125 \end_layout
14126
14127 \begin_layout Verse
14128
14129 \family typewriter
14130 void nmi_isr (void) critical interrupt
14131 \newline
14132
14133 \newline
14134 \InsetSpace ~
14135 \InsetSpace ~
14136 \InsetSpace ~
14137 \InsetSpace ~
14138 ...
14139  
14140 \newline
14141 }
14142 \end_layout
14143
14144 \begin_layout Standard
14145 However if you need to create a non-interruptable interrupt service routine
14146  you would also require the 
14147 \emph on
14148 critical
14149 \emph default
14150  keyword.
14151  To distinguish between this and an nmi_isr you must provide an interrupt
14152  number.
14153 \begin_inset VSpace bigskip
14154 \end_inset
14155
14156
14157 \end_layout
14158
14159 \begin_layout Section
14160 Enabling and Disabling Interrupts
14161 \end_layout
14162
14163 \begin_layout Subsection
14164 Critical Functions and Critical Statements
14165 \end_layout
14166
14167 \begin_layout Standard
14168 A special keyword may be associated with a block or a function declaring
14169  it as 
14170 \emph on
14171 critical
14172 \emph default
14173 .
14174  SDCC will generate code to disable all interrupts
14175 \begin_inset LatexCommand \index{interrupt}
14176
14177 \end_inset
14178
14179  upon entry to a critical function and restore the interrupt enable to the
14180  previous state before returning.
14181  Nesting critical functions will need one additional byte on the stack
14182 \begin_inset LatexCommand \index{stack}
14183
14184 \end_inset
14185
14186  for each call.
14187 \end_layout
14188
14189 \begin_layout Verse
14190
14191 \family typewriter
14192 int foo () __critical
14193 \begin_inset LatexCommand \index{critical}
14194
14195 \end_inset
14196
14197
14198 \begin_inset LatexCommand \index{\_\_critical}
14199
14200 \end_inset
14201
14202  
14203 \newline
14204
14205 \newline
14206 \InsetSpace ~
14207 \InsetSpace ~
14208 \InsetSpace ~
14209 \InsetSpace ~
14210 ...
14211  
14212 \newline
14213 \InsetSpace ~
14214 \InsetSpace ~
14215 \InsetSpace ~
14216 \InsetSpace ~
14217 ...
14218  
14219 \newline
14220 }
14221 \end_layout
14222
14223 \begin_layout Standard
14224 The critical attribute maybe used with other attributes like 
14225 \emph on
14226 reentrant.
14227 \emph default
14228
14229 \newline
14230 The keyword 
14231 \emph on
14232 critical
14233 \emph default
14234  may also be used to disable interrupts more locally:
14235 \end_layout
14236
14237 \begin_layout Verse
14238
14239 \family typewriter
14240 __critical{ i++; }
14241 \end_layout
14242
14243 \begin_layout Standard
14244 More than one statement could have been included in the block.
14245 \end_layout
14246
14247 \begin_layout Subsection
14248 Enabling and Disabling Interrupts directly
14249 \end_layout
14250
14251 \begin_layout Standard
14252 Interrupts
14253 \begin_inset LatexCommand \index{interrupt}
14254
14255 \end_inset
14256
14257  can also be disabled and enabled directly (8051):
14258 \end_layout
14259
14260 \begin_layout Verse
14261
14262 \family typewriter
14263 EA = 0;\InsetSpace ~
14264 \InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 \InsetSpace ~
14268 \InsetSpace ~
14269 \InsetSpace ~
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 \InsetSpace ~
14274 \InsetSpace ~
14275 or:\InsetSpace ~
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 \InsetSpace ~
14281 \InsetSpace ~
14282 \InsetSpace ~
14283 \InsetSpace ~
14284 \InsetSpace ~
14285 \InsetSpace ~
14286 EA_SAVE = EA;
14287 \end_layout
14288
14289 \begin_layout Verse
14290
14291 \family typewriter
14292 ...\InsetSpace ~
14293 \InsetSpace ~
14294 \InsetSpace ~
14295 \InsetSpace ~
14296 \InsetSpace ~
14297 \InsetSpace ~
14298 \InsetSpace ~
14299 \InsetSpace ~
14300 \InsetSpace ~
14301 \InsetSpace ~
14302 \InsetSpace ~
14303 \InsetSpace ~
14304 \InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 \InsetSpace ~
14308 \InsetSpace ~
14309 \InsetSpace ~
14310 \InsetSpace ~
14311 \InsetSpace ~
14312 \InsetSpace ~
14313 \InsetSpace ~
14314 \InsetSpace ~
14315 \InsetSpace ~
14316 \InsetSpace ~
14317 \InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 \InsetSpace ~
14321 \InsetSpace ~
14322 EA = 0;
14323 \end_layout
14324
14325 \begin_layout Verse
14326
14327 \family typewriter
14328 EA = 1;\InsetSpace ~
14329 \InsetSpace ~
14330 \InsetSpace ~
14331 \InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 \InsetSpace ~
14335 \InsetSpace ~
14336 \InsetSpace ~
14337 \InsetSpace ~
14338 \InsetSpace ~
14339 \InsetSpace ~
14340 \InsetSpace ~
14341 \InsetSpace ~
14342 \InsetSpace ~
14343 \InsetSpace ~
14344 \InsetSpace ~
14345 \InsetSpace ~
14346 \InsetSpace ~
14347 \InsetSpace ~
14348 \InsetSpace ~
14349 \InsetSpace ~
14350 \InsetSpace ~
14351 \InsetSpace ~
14352 \InsetSpace ~
14353 \InsetSpace ~
14354 ...
14355 \end_layout
14356
14357 \begin_layout Verse
14358
14359 \family typewriter
14360 \InsetSpace ~
14361 \InsetSpace ~
14362 \InsetSpace ~
14363 \InsetSpace ~
14364 \InsetSpace ~
14365 \InsetSpace ~
14366 \InsetSpace ~
14367 \InsetSpace ~
14368 \InsetSpace ~
14369 \InsetSpace ~
14370 \InsetSpace ~
14371 \InsetSpace ~
14372 \InsetSpace ~
14373 \InsetSpace ~
14374 \InsetSpace ~
14375 \InsetSpace ~
14376 \InsetSpace ~
14377 \InsetSpace ~
14378 \InsetSpace ~
14379 \InsetSpace ~
14380 \InsetSpace ~
14381 \InsetSpace ~
14382 \InsetSpace ~
14383 \InsetSpace ~
14384 \InsetSpace ~
14385 \InsetSpace ~
14386 \InsetSpace ~
14387 \InsetSpace ~
14388 \InsetSpace ~
14389 \InsetSpace ~
14390 \InsetSpace ~
14391 \InsetSpace ~
14392 \InsetSpace ~
14393 EA = EA_SAVE;
14394 \end_layout
14395
14396 \begin_layout Standard
14397 On other architectures which have seperate opcodes for enabling and disabling
14398  interrupts you might want to make use of defines with inline assembly
14399 \begin_inset LatexCommand \index{Assembler routines}
14400
14401 \end_inset
14402
14403  (HC08
14404 \begin_inset LatexCommand \index{HC08!interrupt}
14405
14406 \end_inset
14407
14408 ):
14409 \end_layout
14410
14411 \begin_layout Verse
14412
14413 \family typewriter
14414 #define CLI _asm
14415 \begin_inset LatexCommand \index{\_asm}
14416
14417 \end_inset
14418
14419 \InsetSpace ~
14420 \InsetSpace ~
14421 cli\InsetSpace ~
14422 \InsetSpace ~
14423 _endasm
14424 \begin_inset LatexCommand \index{\_endasm}
14425
14426 \end_inset
14427
14428
14429 \end_layout
14430
14431 \begin_layout Verse
14432
14433 \family typewriter
14434 #define SEI _asm\InsetSpace ~
14435 \InsetSpace ~
14436 sei\InsetSpace ~
14437 \InsetSpace ~
14438 _endasm; 
14439 \end_layout
14440
14441 \begin_layout Verse
14442
14443 \family typewriter
14444 ...
14445 \end_layout
14446
14447 \begin_layout Standard
14448 Note: it is sometimes sufficient to disable only a specific interrupt source
14449  like f.e.
14450  a timer or serial interrupt by manipulating an 
14451 \emph on
14452 interrupt mask
14453 \begin_inset LatexCommand \index{interrupt mask}
14454
14455 \end_inset
14456
14457
14458 \emph default
14459  register.
14460  
14461 \end_layout
14462
14463 \begin_layout Standard
14464 Usually the time during which interrupts are disabled should be kept as
14465  short as possible.
14466  This minimizes both 
14467 \emph on
14468 interrupt latency
14469 \emph default
14470
14471 \begin_inset LatexCommand \index{interrupt latency}
14472
14473 \end_inset
14474
14475  (the time between the occurrence of the interrupt and the execution of
14476  the first code in the interrupt routine) and 
14477 \emph on
14478 interrupt jitter
14479 \emph default
14480
14481 \begin_inset LatexCommand \index{interrupt jitter}
14482
14483 \end_inset
14484
14485  (the difference between the shortest and the longest interrupt latency).
14486  These really are something different, f.e.
14487  a serial interrupt has to be served before its buffer overruns so it cares
14488  for the maximum interrupt latency, whereas it does not care about jitter.
14489  On a loudspeaker driven via a digital to analog converter which is fed
14490  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14491  a much smaller jitter will be very audible.
14492 \end_layout
14493
14494 \begin_layout Standard
14495 You can reenable interrupts within an interrupt routine and on some architecture
14496 s you can make use of two (or more) levels of 
14497 \emph on
14498 interrupt priorities
14499 \emph default
14500
14501 \begin_inset LatexCommand \index{interrupt priority}
14502
14503 \end_inset
14504
14505 .
14506  On some architectures which don't support interrupt priorities these can
14507  be implemented by manipulating the interrupt mask and reenabling interrupts
14508  within the interrupt routine.
14509  Check there is sufficient space on the stack
14510 \begin_inset LatexCommand \index{stack}
14511
14512 \end_inset
14513
14514  and don't add complexity unless you have to.
14515  
14516 \end_layout
14517
14518 \begin_layout Subsection
14519 Semaphore
14520 \begin_inset LatexCommand \index{semaphore}
14521
14522 \end_inset
14523
14524  locking (mcs51/ds390)
14525 \end_layout
14526
14527 \begin_layout Standard
14528 Some architectures (mcs51/ds390) have an atomic
14529 \begin_inset LatexCommand \index{atomic}
14530
14531 \end_inset
14532
14533  bit test and
14534 \emph on
14535  
14536 \emph default
14537 clear
14538 \emph on
14539  
14540 \emph default
14541 instruction.
14542  These type of instructions are typically used in preemptive multitasking
14543  systems, where a routine f.e.
14544  claims the use of a data structure ('acquires a lock
14545 \begin_inset LatexCommand \index{lock}
14546
14547 \end_inset
14548
14549  on it'), makes some modifications and then releases the lock when the data
14550  structure is consistent again.
14551  The instruction may also be used if interrupt and non-interrupt code have
14552  to compete for a resource.
14553  With the atomic bit test and clear instruction interrupts
14554 \begin_inset LatexCommand \index{interrupt}
14555
14556 \end_inset
14557
14558  don't have to be disabled for the locking operation.
14559  
14560 \end_layout
14561
14562 \begin_layout Standard
14563 SDCC generates this instruction if the source follows this pattern:
14564 \end_layout
14565
14566 \begin_layout Verse
14567
14568 \family typewriter
14569 volatile
14570 \begin_inset LatexCommand \index{volatile}
14571
14572 \end_inset
14573
14574  bit resource_is_free; 
14575 \newline
14576
14577 \newline
14578 if (resource_is_free) 
14579 \newline
14580 \InsetSpace ~
14581 \InsetSpace ~
14582
14583 \newline
14584 \InsetSpace ~
14585 \InsetSpace ~
14586 \InsetSpace ~
14587 \InsetSpace ~
14588 resource_is_free=0; 
14589 \newline
14590 \InsetSpace ~
14591 \InsetSpace ~
14592 \InsetSpace ~
14593 \InsetSpace ~
14594 ...
14595  
14596 \newline
14597 \InsetSpace ~
14598 \InsetSpace ~
14599 \InsetSpace ~
14600 \InsetSpace ~
14601 resource_is_free=1;
14602 \newline
14603 \InsetSpace ~
14604 \InsetSpace ~
14605
14606 \end_layout
14607
14608 \begin_layout Standard
14609 Note, mcs51 and ds390 support only an atomic
14610 \begin_inset LatexCommand \index{atomic}
14611
14612 \end_inset
14613
14614  bit test and 
14615 \emph on
14616 clear
14617 \emph default
14618  instruction (as opposed to atomic bit test and 
14619 \emph on
14620 set).
14621 \end_layout
14622
14623 \begin_layout Section
14624 Functions using private register banks
14625 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14626
14627 \end_inset
14628
14629  (mcs51/ds390)
14630 \end_layout
14631
14632 \begin_layout Standard
14633 Some architectures have support for quickly changing register sets.
14634  SDCC supports this feature with the 
14635 \emph on
14636 using
14637 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14638
14639 \end_inset
14640
14641
14642 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14643
14644 \end_inset
14645
14646
14647 \emph default
14648  attribute (which tells the compiler to use a register bank
14649 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14650
14651 \end_inset
14652
14653  other than the default bank zero).
14654  It should only be applied to 
14655 \emph on
14656 interrupt
14657 \begin_inset LatexCommand \index{interrupt}
14658
14659 \end_inset
14660
14661
14662 \emph default
14663  functions (see footnote below).
14664  This will in most circumstances make the generated ISR code more efficient
14665  since it will not have to save registers on the stack.
14666 \end_layout
14667
14668 \begin_layout Standard
14669 The 
14670 \emph on
14671 using
14672 \emph default
14673  attribute will have no effect on the generated code for a 
14674 \emph on
14675 non-interrupt
14676 \emph default
14677  function (but may occasionally be useful anyway
14678 \begin_inset Foot
14679 status open
14680
14681 \begin_layout Standard
14682 possible exception: if a function is called ONLY from 'interrupt' functions
14683  using a particular bank, it can be declared with the same 'using' attribute
14684  as the calling 'interrupt' functions.
14685  For instance, if you have several ISRs using bank one, and all of them
14686  call memcpy(), it might make sense to create a specialized version of memcpy()
14687  'using 1', since this would prevent the ISR from having to save bank zero
14688  to the stack on entry and switch to bank zero before calling the function
14689 \end_layout
14690
14691 \end_inset
14692
14693 ).
14694 \newline
14695
14696 \emph on
14697 (pending: Note, nowadays the 
14698 \emph default
14699 using
14700 \emph on
14701  attribute has an effect on
14702 \emph default
14703  
14704 \emph on
14705 the generated code for a 
14706 \emph default
14707 non-interrupt
14708 \emph on
14709  function
14710 \emph default
14711 .
14712 \emph on
14713 )
14714 \end_layout
14715
14716 \begin_layout Standard
14717 An 
14718 \emph on
14719 interrupt
14720 \emph default
14721  function using a non-zero bank will assume that it can trash that register
14722  bank, and will not save it.
14723  Since high-priority interrupts
14724 \begin_inset LatexCommand \index{interrupts}
14725
14726 \end_inset
14727
14728
14729 \begin_inset LatexCommand \index{interrupt priority}
14730
14731 \end_inset
14732
14733  can interrupt low-priority ones on the 8051 and friends, this means that
14734  if a high-priority ISR 
14735 \emph on
14736 using
14737 \emph default
14738  a particular bank occurs while processing a low-priority ISR 
14739 \emph on
14740 using
14741 \emph default
14742  the same bank, terrible and bad things can happen.
14743  To prevent this, no single register bank should be 
14744 \emph on
14745 used
14746 \emph default
14747  by both a high priority and a low priority ISR.
14748  This is probably most easily done by having all high priority ISRs use
14749  one bank and all low priority ISRs use another.
14750  If you have an ISR which can change priority at runtime, you're on your
14751  own: I suggest using the default bank zero and taking the small performance
14752  hit.
14753 \end_layout
14754
14755 \begin_layout Standard
14756 It is most efficient if your ISR calls no other functions.
14757  If your ISR must call other functions, it is most efficient if those functions
14758  use the same bank as the ISR (see note 1 below); the next best is if the
14759  called functions use bank zero.
14760  It is very inefficient to call a function using a different, non-zero bank
14761  from an ISR.
14762  
14763 \begin_inset VSpace bigskip
14764 \end_inset
14765
14766
14767 \end_layout
14768
14769 \begin_layout Section
14770 Startup Code
14771 \begin_inset LatexCommand \label{sub:Startup-Code}
14772
14773 \end_inset
14774
14775
14776 \begin_inset LatexCommand \index{Startup code}
14777
14778 \end_inset
14779
14780
14781 \end_layout
14782
14783 \begin_layout Subsection
14784 MCS51/DS390 Startup Code
14785 \end_layout
14786
14787 \begin_layout Standard
14788 The compiler triggers the linker to link certain initialization modules
14789  from the runtime library
14790 \begin_inset LatexCommand \index{Runtime library}
14791
14792 \end_inset
14793
14794  called crt<something>.
14795  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14796  GSINIT5) is not linked unless the --xstack option is used.
14797  These modules are highly entangled by the use of special segments/areas,
14798  but a common layout is shown below:
14799 \end_layout
14800
14801 \begin_layout Verse
14802
14803 \family typewriter
14804 \series bold
14805 \size footnotesize
14806 (main.asm)
14807 \end_layout
14808
14809 \begin_layout Verse
14810
14811 \family typewriter
14812 \size footnotesize
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 \InsetSpace ~
14816 \InsetSpace ~
14817 \InsetSpace ~
14818 \InsetSpace ~
14819 \InsetSpace ~
14820 \InsetSpace ~
14821 .area HOME (CODE)
14822 \newline
14823 __interrupt_vect:
14824 \newline
14825 \InsetSpace ~
14826 \InsetSpace ~
14827 \InsetSpace ~
14828 \InsetSpace ~
14829 \InsetSpace ~
14830 \InsetSpace ~
14831 \InsetSpace ~
14832 \InsetSpace ~
14833 ljmp __sdcc_gsinit_startup
14834 \end_layout
14835
14836 \begin_layout Verse
14837
14838 \family typewriter
14839 \series bold
14840 \size footnotesize
14841 (crtstart.asm)
14842 \end_layout
14843
14844 \begin_layout Verse
14845
14846 \family typewriter
14847 \size footnotesize
14848 \InsetSpace ~
14849 \InsetSpace ~
14850 \InsetSpace ~
14851 \InsetSpace ~
14852 \InsetSpace ~
14853 \InsetSpace ~
14854 \InsetSpace ~
14855 \InsetSpace ~
14856 .area GSINIT0 (CODE)
14857 \newline
14858 __sdcc_gsinit_startup::
14859 \newline
14860 \InsetSpace ~
14861 \InsetSpace ~
14862 \InsetSpace ~
14863 \InsetSpace ~
14864 \InsetSpace ~
14865 \InsetSpace ~
14866 \InsetSpace ~
14867 \InsetSpace ~
14868 mov sp,#__start__stack - 1
14869 \end_layout
14870
14871 \begin_layout Verse
14872
14873 \family typewriter
14874 \series bold
14875 \size footnotesize
14876 (crtxstack.asm)
14877 \end_layout
14878
14879 \begin_layout Verse
14880
14881 \family typewriter
14882 \size footnotesize
14883 \InsetSpace ~
14884 \InsetSpace ~
14885 \InsetSpace ~
14886 \InsetSpace ~
14887 \InsetSpace ~
14888 \InsetSpace ~
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 .area GSINIT1 (CODE)
14892 \newline
14893 __sdcc_init_xstack::
14894 \newline
14895 ; Need to initialize in GSINIT1 in
14896  case the user's __sdcc_external_startup uses the xstack.
14897 \newline
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 \InsetSpace ~
14903 \InsetSpace ~
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 mov __XPAGE,#(__start__x
14907 stack >> 8)
14908 \newline
14909 \InsetSpace ~
14910 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 mov _spx,#__start__xstack
14918 \end_layout
14919
14920 \begin_layout Verse
14921
14922 \family typewriter
14923 \series bold
14924 \size footnotesize
14925 (crtstart.asm)
14926 \end_layout
14927
14928 \begin_layout Verse
14929
14930 \family typewriter
14931 \size footnotesize
14932 \InsetSpace ~
14933 \InsetSpace ~
14934 \InsetSpace ~
14935 \InsetSpace ~
14936 \InsetSpace ~
14937 \InsetSpace ~
14938 \InsetSpace ~
14939 \InsetSpace ~
14940 .area GSINIT2 (CODE)
14941 \newline
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 \InsetSpace ~
14950 lcall __sdcc_external_startup
14951 \newline
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 mov a,dpl
14961 \newline
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 \InsetSpace ~
14970 jz __sdcc_init_data
14971 \newline
14972 \InsetSpace ~
14973 \InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 \InsetSpace ~
14980 ljmp
14981  __sdcc_program_startup
14982 \newline
14983 __sdcc_init_data:
14984 \end_layout
14985
14986 \begin_layout Verse
14987
14988 \family typewriter
14989 \series bold
14990 \size footnotesize
14991 (crtxinit.asm)
14992 \end_layout
14993
14994 \begin_layout Verse
14995
14996 \family typewriter
14997 \size footnotesize
14998 \InsetSpace ~
14999 \InsetSpace ~
15000 \InsetSpace ~
15001 \InsetSpace ~
15002 \InsetSpace ~
15003 \InsetSpace ~
15004 \InsetSpace ~
15005 \InsetSpace ~
15006 .area GSINIT3 (CODE)
15007 \newline
15008 __mcs51_genXINIT::
15009 \newline
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 mov r1,#l_XINIT
15019 \newline
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 \InsetSpace ~
15028 mov a,r1
15029 \newline
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 \InsetSpace ~
15038 orl a,#(l_XINIT
15039  >> 8)
15040 \newline
15041 \InsetSpace ~
15042 \InsetSpace ~
15043 \InsetSpace ~
15044 \InsetSpace ~
15045 \InsetSpace ~
15046 \InsetSpace ~
15047 \InsetSpace ~
15048 \InsetSpace ~
15049 jz 00003$
15050 \newline
15051 \InsetSpace ~
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 \InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 \InsetSpace ~
15059 mov r2,#((l_XINIT+255) >> 8)
15060 \newline
15061 \InsetSpace ~
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 \InsetSpace ~
15069 mov dptr,#s_XINIT
15070 \newline
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 mov r0,#s_XISEG
15080 \newline
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 mov
15090  __XPAGE,#(s_XISEG >> 8)
15091 \newline
15092 00001$:\InsetSpace ~
15093 clr a
15094 \newline
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 movc a,@a+dptr
15104 \newline
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 movx @r0,a
15114 \newline
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 inc dptr
15124 \newline
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 inc
15134  r0
15135 \newline
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 cjne r0,#0,00002$
15145 \newline
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 inc __XPAGE
15155 \newline
15156 00002$:\InsetSpace ~
15157 djnz r1,00001$
15158 \newline
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 djnz r2,00001$
15168 \newline
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 mov __XPAGE,#0
15178 xFF
15179 \newline
15180 00003$:
15181 \end_layout
15182
15183 \begin_layout Verse
15184
15185 \family typewriter
15186 \series bold
15187 \size footnotesize
15188 (crtclear.asm)
15189 \end_layout
15190
15191 \begin_layout Verse
15192
15193 \family typewriter
15194 \size footnotesize
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 .area GSINIT4 (CODE)
15204 \newline
15205 __mcs51_genRAMCLEAR::
15206 \newline
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 clr a
15216 \newline
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 mov r0,#(l_IRAM-1)
15226 \newline
15227 00004$:\InsetSpace ~
15228 mov
15229  @r0,a
15230 \newline
15231 \InsetSpace ~
15232 \InsetSpace ~
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 djnz r0,00004$
15240 \newline
15241 ; _mcs51_genRAMCLEAR() end
15242 \end_layout
15243
15244 \begin_layout Verse
15245
15246 \family typewriter
15247 \series bold
15248 \size footnotesize
15249 (crtxclear.asm)
15250 \end_layout
15251
15252 \begin_layout Verse
15253
15254 \family typewriter
15255 \size footnotesize
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 .area GSINIT4 (CODE)
15265 \newline
15266 __mcs51_genXRAMCLEAR::
15267 \newline
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 \InsetSpace ~
15276 mov r0,#l_PSEG
15277 \newline
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 \InsetSpace ~
15286 mov a,r0
15287 \newline
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 \InsetSpace ~
15296 jz 00006$
15297 \newline
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 \InsetSpace ~
15304 \InsetSpace ~
15305 \InsetSpace ~
15306 mov
15307  r1,#s_PSEG
15308 \newline
15309 \InsetSpace ~
15310 \InsetSpace ~
15311 \InsetSpace ~
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 \InsetSpace ~
15317 mov __XPAGE,#(s_PSEG >> 8)
15318 \newline
15319 \InsetSpace ~
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 clr a
15328 \newline
15329 00005$:\InsetSpace ~
15330 movx @r1,a
15331 \newline
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 \InsetSpace ~
15340 inc r1
15341 \newline
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 djnz r0,00005$
15351 \newline
15352 0
15353 0006$:
15354 \newline
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 \InsetSpace ~
15363 mov r0,#l_XSEG
15364 \newline
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 mov a,r0
15374 \newline
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 \InsetSpace ~
15383 orl a,#(l_XSEG >> 8)
15384 \newline
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 jz 00008$
15394 \newline
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 mov r1,#((l_XSEG
15404  + 255) >> 8)
15405 \newline
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 \InsetSpace ~
15414 mov dptr,#s_XSEG
15415 \newline
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 \InsetSpace ~
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 clr a
15425 \newline
15426 00007$:\InsetSpace ~
15427 movx @dptr,a
15428 \newline
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 \InsetSpace ~
15437 inc dptr
15438 \newline
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 \InsetSpace ~
15447 djnz r0,00007$
15448 \newline
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 \InsetSpace ~
15457 djnz
15458  r1,00007$
15459 \newline
15460 00008$:
15461 \end_layout
15462
15463 \begin_layout Verse
15464
15465 \family typewriter
15466 \series bold
15467 \size footnotesize
15468 (crtxstack.asm)
15469 \end_layout
15470
15471 \begin_layout Verse
15472
15473 \family typewriter
15474 \size footnotesize
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 .area GSINIT5 (CODE)
15484 \newline
15485 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15486  modifies __XPAGE
15487 \newline
15488 ; and __mcs51_genRAMCLEAR modifies _spx.
15489 \newline
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 \InsetSpace ~
15497 \InsetSpace ~
15498 mov __XPAGE,#(__start__x
15499 stack >> 8)
15500 \newline
15501 \InsetSpace ~
15502 \InsetSpace ~
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 \InsetSpace ~
15508 \InsetSpace ~
15509 mov _spx,#__start__xstack
15510 \end_layout
15511
15512 \begin_layout Verse
15513
15514 \family typewriter
15515 \series bold
15516 \size footnotesize
15517 (application modules)
15518 \end_layout
15519
15520 \begin_layout Verse
15521
15522 \family typewriter
15523 \size footnotesize
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 \InsetSpace ~
15530 \InsetSpace ~
15531 \InsetSpace ~
15532 .area GSINIT (CODE)
15533 \end_layout
15534
15535 \begin_layout Verse
15536
15537 \family typewriter
15538 \series bold
15539 \size footnotesize
15540 (main.asm)
15541 \end_layout
15542
15543 \begin_layout Verse
15544
15545 \family typewriter
15546 \size footnotesize
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 \InsetSpace ~
15554 \InsetSpace ~
15555 .area GSFINAL (CODE)
15556 \newline
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 \InsetSpace ~
15565 ljmp __sdcc_program_startup
15566 \newline
15567 ;---------------------------------
15568 -----------------------
15569 \newline
15570 ; Home
15571 \newline
15572 ;--------------------------------------------------
15573 ------
15574 \newline
15575 \InsetSpace ~
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 \InsetSpace ~
15582 \InsetSpace ~
15583 .area HOME (CODE)
15584 \newline
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 \InsetSpace ~
15593 .area CSEG (CODE)
15594 \newline
15595 __sdcc_program_startup:
15596 \newline
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 \InsetSpace ~
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 lcall _main
15606 \newline
15607 ;
15608  return from main will lock up
15609 \newline
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 sjmp .
15619 \end_layout
15620
15621 \begin_layout Standard
15622 One of these modules (crtstart.asm) contains a call to the C routine 
15623 \emph on
15624 _sdcc_external_startup()
15625 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15626
15627 \end_inset
15628
15629
15630 \series bold
15631 \emph default
15632  
15633 \series default
15634 at the start of the CODE area.
15635  This routine is also in the runtime library
15636 \begin_inset LatexCommand \index{Runtime library}
15637
15638 \end_inset
15639
15640  and returns 0 by default.
15641  If this routine returns a non-zero value, the static & global variable
15642  initialization will be skipped and the function main will be invoked.
15643  Otherwise static & global variables will be initialized before the function
15644  main is invoked.
15645  You could add an 
15646 \emph on
15647 _sdcc_external_startup()
15648 \emph default
15649  routine to your program to override the default if you need to setup hardware
15650  or perform some other critical operation prior to static & global variable
15651  initialization
15652 \begin_inset LatexCommand \index{Variable initialization}
15653
15654 \end_inset
15655
15656 .
15657  On some mcs51 variants xdata
15658 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15659
15660 \end_inset
15661
15662  memory has to be explicitly enabled before it can be accessed or if the
15663  watchdog
15664 \begin_inset LatexCommand \index{watchdog}
15665
15666 \end_inset
15667
15668  needs to be disabled, this is the place to do it.
15669  The startup code clears all internal data memory, 256 bytes by default,
15670  but from 0 to n-1 if 
15671 \emph on
15672 -
15673 \begin_inset ERT
15674 status collapsed
15675
15676 \begin_layout Standard
15677
15678
15679 \backslash
15680 /
15681 \end_layout
15682
15683 \end_inset
15684
15685 -iram-size
15686 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15687
15688 \end_inset
15689
15690 n
15691 \emph default
15692  is used.
15693  (recommended for Chipcon CC1010).
15694 \end_layout
15695
15696 \begin_layout Standard
15697 See also the compiler options 
15698 \emph on
15699 -
15700 \begin_inset ERT
15701 status collapsed
15702
15703 \begin_layout Standard
15704
15705
15706 \backslash
15707 /
15708 \end_layout
15709
15710 \end_inset
15711
15712 -no-xinit
15713 \emph default
15714 -
15715 \emph on
15716 opt
15717 \emph default
15718
15719 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15720
15721 \end_inset
15722
15723
15724 \emph on
15725 -
15726 \begin_inset ERT
15727 status collapsed
15728
15729 \begin_layout Standard
15730
15731
15732 \backslash
15733 /
15734 \end_layout
15735
15736 \end_inset
15737
15738 -main-return
15739 \emph default
15740
15741 \begin_inset LatexCommand \index{-\/-main-return}
15742
15743 \end_inset
15744
15745  and section 
15746 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15747
15748 \end_inset
15749
15750  about MCS51-variants.
15751 \begin_inset VSpace bigskip
15752 \end_inset
15753
15754
15755 \end_layout
15756
15757 \begin_layout Subsection
15758 HC08 Startup Code
15759 \end_layout
15760
15761 \begin_layout Standard
15762 The HC08
15763 \begin_inset LatexCommand \index{HC08}
15764
15765 \end_inset
15766
15767  startup code follows the same scheme as the MCS51 startup code.
15768 \begin_inset VSpace bigskip
15769 \end_inset
15770
15771
15772 \end_layout
15773
15774 \begin_layout Subsection
15775 Z80 Startup Code
15776 \end_layout
15777
15778 \begin_layout Standard
15779 On the Z80
15780 \begin_inset LatexCommand \index{Z80}
15781
15782 \end_inset
15783
15784  the startup code is inserted by linking with crt0.o which is generated from
15785  sdcc/device/lib/z80/crt0.s.
15786  If you need a different startup code you can use the compiler option 
15787 \emph on
15788 -
15789 \series bold
15790 \emph default
15791
15792 \begin_inset ERT
15793 status collapsed
15794
15795 \begin_layout Standard
15796
15797
15798 \backslash
15799 /
15800 \end_layout
15801
15802 \end_inset
15803
15804
15805 \series default
15806 \emph on
15807 -no-std-crt0
15808 \emph default
15809
15810 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15811
15812 \end_inset
15813
15814  and provide your own crt0.o.
15815  
15816 \begin_inset VSpace bigskip
15817 \end_inset
15818
15819
15820 \end_layout
15821
15822 \begin_layout Section
15823 Inline Assembler Code
15824 \begin_inset LatexCommand \index{Assembler routines}
15825
15826 \end_inset
15827
15828
15829 \end_layout
15830
15831 \begin_layout Subsection
15832 A Step by Step Introduction
15833 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15834
15835 \end_inset
15836
15837
15838 \end_layout
15839
15840 \begin_layout Standard
15841 Starting from a small snippet of c-code this example shows for the MCS51
15842  how to use inline assembly, access variables, a function parameter and
15843  an array in xdata memory.
15844  The example uses an MCS51 here but is easily adapted for other architectures.
15845  This is a buffer routine which should be optimized:
15846 \end_layout
15847
15848 \begin_layout Verse
15849
15850 \family typewriter
15851 \size footnotesize
15852 unsigned char __far
15853 \begin_inset LatexCommand \index{far (storage class)}
15854
15855 \end_inset
15856
15857
15858 \begin_inset LatexCommand \index{\_\_far (storage class)}
15859
15860 \end_inset
15861
15862  __at
15863 \begin_inset LatexCommand \index{at}
15864
15865 \end_inset
15866
15867
15868 \begin_inset LatexCommand \index{\_\_at}
15869
15870 \end_inset
15871
15872 (0x7f00) buf[0x100];
15873 \begin_inset LatexCommand \index{Aligned array}
15874
15875 \end_inset
15876
15877
15878 \newline
15879 unsigned char head, tail;\InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 /* if interrupts
15897 \begin_inset LatexCommand \index{interrupt}
15898
15899 \end_inset
15900
15901  are involved see
15902 \newline
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 section 
15949 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15950
15951 \end_inset
15952
15953  about
15954 \series bold
15955  volatile
15956 \series default
15957  */
15958 \newline
15959
15960 \newline
15961 void to_buffer( unsigned char c ) 
15962 \newline
15963 {
15964 \newline
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 if( head != (unsigned char)(tail-1)
15970  )\InsetSpace ~
15971 /* cast 
15972 \series bold
15973 needed
15974 \series default
15975  to avoid promotion
15976 \begin_inset LatexCommand \index{promotion to signed int}
15977
15978 \end_inset
15979
15980
15981 \begin_inset LatexCommand \index{type promotion}
15982
15983 \end_inset
15984
15985  to integer */
15986 \begin_inset Marginal
15987 status collapsed
15988
15989 \begin_layout Standard
15990
15991 \series bold
15992 \InsetSpace ~
15993 !
15994 \end_layout
15995
15996 \end_inset
15997
15998
15999 \newline
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 buf[ head++ ] = c;\InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 /* access to a 256 byte aligned array */
16025 \newline
16026
16027 \end_layout
16028
16029 \begin_layout Standard
16030 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16031  then a corresponding buffer.asm file is generated.
16032  We define a new function 
16033 \family typewriter
16034 to_buffer_asm()
16035 \family default
16036  in file buffer.c in which we cut and paste the generated code, removing
16037  unwanted comments and some ':'.
16038  Then add 
16039 \begin_inset Quotes sld
16040 \end_inset
16041
16042
16043 \series bold
16044 _asm
16045 \series default
16046
16047 \begin_inset Quotes srd
16048 \end_inset
16049
16050  and 
16051 \begin_inset Quotes sld
16052 \end_inset
16053
16054
16055 \series bold
16056 _endasm;
16057 \series default
16058
16059 \begin_inset Quotes srd
16060 \end_inset
16061
16062
16063 \begin_inset Foot
16064 status open
16065
16066 \begin_layout Standard
16067 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16068  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16069  has to be used.
16070  The latter is also used in the library functions.
16071 \end_layout
16072
16073 \end_inset
16074
16075  to the beginning and the end of the function body:
16076 \end_layout
16077
16078 \begin_layout Verse
16079
16080 \family typewriter
16081 \size footnotesize
16082 /* With a cut and paste from the .asm file, we have something to start with.
16083 \newline
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 The
16088  function is not yet OK! (registers aren't saved) */ 
16089 \newline
16090 void to_buffer_asm(
16091  unsigned char c ) 
16092 \newline
16093
16094 \newline
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 _asm
16100 \begin_inset LatexCommand \index{\_asm}
16101
16102 \end_inset
16103
16104
16105 \begin_inset LatexCommand \index{\_\_asm}
16106
16107 \end_inset
16108
16109
16110 \newline
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 mov\InsetSpace ~
16116 \InsetSpace ~
16117 r2,dpl 
16118 \newline
16119 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16120 /* cast 
16121 \series bold
16122 needed
16123 \series default
16124  to avoid promotion
16125 \begin_inset LatexCommand \index{promotion to signed int}
16126
16127 \end_inset
16128
16129
16130 \begin_inset LatexCommand \index{type promotion}
16131
16132 \end_inset
16133
16134  to integer */
16135 \newline
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 mov\InsetSpace ~
16141 \InsetSpace ~
16142 a,_tail 
16143 \newline
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 dec\InsetSpace ~
16149 \InsetSpace ~
16150
16151 \newline
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 mov\InsetSpace ~
16157 \InsetSpace ~
16158 r3,a 
16159 \newline
16160 \InsetSpace ~
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 mov\InsetSpace ~
16165 \InsetSpace ~
16166 a,_head 
16167 \newline
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 cjne a,ar3,00106$ 
16173 \newline
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 ret
16179 \newline
16180 00106$:
16181  
16182 \newline
16183 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16184 \begin_inset LatexCommand \index{Aligned array}
16185
16186 \end_inset
16187
16188
16189 \newline
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 mov\InsetSpace ~
16195 \InsetSpace ~
16196 r3,_head 
16197 \newline
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 inc\InsetSpace ~
16203 \InsetSpace ~
16204 _head 
16205 \newline
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 mov\InsetSpace ~
16211 \InsetSpace ~
16212 dpl,r3 
16213 \newline
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 mov\InsetSpace ~
16219 \InsetSpace ~
16220 dph,#(_buf >> 8) 
16221 \newline
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 mov\InsetSpace ~
16227 \InsetSpace ~
16228 a,r2 
16229 \newline
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 movx @dptr,a
16235  
16236 \newline
16237 00103$: 
16238 \newline
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 ret
16244 \newline
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 _endasm
16250 \begin_inset LatexCommand \index{\_endasm}
16251
16252 \end_inset
16253
16254
16255 \begin_inset LatexCommand \index{\_\_endasm}
16256
16257 \end_inset
16258
16259 ;
16260 \newline
16261
16262 \end_layout
16263
16264 \begin_layout Standard
16265 The new file buffer.c should compile with only one warning about the unreferenced
16266  function argument 'c'.
16267  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16268  (1) and finally have:
16269 \end_layout
16270
16271 \begin_layout Verse
16272
16273 \family typewriter
16274 \size footnotesize
16275 unsigned char __far __at(0x7f00) buf[0x100];
16276 \newline
16277 unsigned char head, tail;
16278 \newline
16279 #define
16280  USE_ASSEMBLY (1)
16281 \newline
16282
16283 \newline
16284 #if !USE_ASSEMBLY
16285 \newline
16286
16287 \newline
16288 void to_buffer( unsigned char c )
16289 \newline
16290 {
16291 \newline
16292 \InsetSpace ~
16293 \InsetSpace ~
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 if(
16297  head != (unsigned char)(tail-1) )
16298 \newline
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 \InsetSpace ~
16306 \InsetSpace ~
16307 buf[ head++ ] = c;
16308 \newline
16309 }
16310 \newline
16311
16312 \newline
16313 #else
16314 \newline
16315
16316 \newline
16317 void to_buffer(
16318  unsigned char c )
16319 \newline
16320 {
16321 \newline
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 c; // to avoid warning: unreferenced function argument
16327 \newline
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 _asm
16333 \begin_inset LatexCommand \index{\_asm}
16334
16335 \end_inset
16336
16337
16338 \begin_inset LatexCommand \index{\_\_asm}
16339
16340 \end_inset
16341
16342
16343 \newline
16344 \InsetSpace ~
16345 \InsetSpace ~
16346 \InsetSpace ~
16347 \InsetSpace ~
16348 \InsetSpace ~
16349 \InsetSpace ~
16350 \InsetSpace ~
16351 \InsetSpace ~
16352 ; save used registers here.
16353  
16354 \newline
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 \InsetSpace ~
16363 ; If we were still using r2,r3 we would have to push them here.
16364  
16365 \newline
16366 ; if( head != (unsigned char)(tail-1) )
16367 \newline
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 \InsetSpace ~
16376 mov\InsetSpace ~
16377  a,_tail
16378 \newline
16379 \InsetSpace ~
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 dec\InsetSpace ~
16388  a
16389 \newline
16390 \InsetSpace ~
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 xrl\InsetSpace ~
16399  a,_head
16400 \newline
16401 \InsetSpace ~
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 ; we
16410  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16411 \newline
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 \InsetSpace ~
16418 \InsetSpace ~
16419 \InsetSpace ~
16420 jz\InsetSpace ~
16421 \InsetSpace ~
16422  t_b_end$
16423 \newline
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 ;
16433 \newline
16434 ;
16435  buf[ head++ ] = c;
16436 \newline
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 \InsetSpace ~
16440 \InsetSpace ~
16441 \InsetSpace ~
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 mov\InsetSpace ~
16446  a,dpl \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 ; dpl holds lower byte of function argument
16454 \newline
16455 \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 \InsetSpace ~
16463 mov\InsetSpace ~
16464
16465  dpl,_head \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 ; buf is 0x100 byte aligned so head can be used directly
16469 \newline
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 \InsetSpace ~
16474 \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 mov\InsetSpace ~
16479  dph,#(_bu
16480 f>>8)
16481 \newline
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 \InsetSpace ~
16487 \InsetSpace ~
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 movx @dptr,a
16491 \newline
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 \InsetSpace ~
16500 inc \InsetSpace ~
16501 _head
16502 \newline
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 \InsetSpace ~
16510 \InsetSpace ~
16511 ; we could do an ANL _head,#0x0f here to use a
16512  smaller buffer (see above)
16513 \newline
16514 t_b_end$:
16515 \newline
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 ; restore used registers here 
16525 \newline
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 _endasm
16531 \begin_inset LatexCommand \index{\_endasm}
16532
16533 \end_inset
16534
16535
16536 \begin_inset LatexCommand \index{\_\_endasm}
16537
16538 \end_inset
16539
16540 ;
16541 \newline
16542 }
16543 \newline
16544 #endif
16545 \end_layout
16546
16547 \begin_layout Standard
16548 The inline assembler code can contain any valid code understood by the assembler
16549 , this includes any assembler directives and comment lines.
16550  The assembler does not like some characters like ':' or ''' in comments.
16551  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16552 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16553
16554 \end_inset
16555
16556
16557 \begin_inset LatexCommand \index{Assembler documentation}
16558
16559 \end_inset
16560
16561  or online at 
16562 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16563
16564 \end_inset
16565
16566 \InsetSpace ~
16567 .
16568 \end_layout
16569
16570 \begin_layout Standard
16571 The compiler does not do any validation of the code within the 
16572 \family typewriter
16573 _asm
16574 \begin_inset LatexCommand \index{\_asm}
16575
16576 \end_inset
16577
16578
16579 \begin_inset LatexCommand \index{\_\_asm}
16580
16581 \end_inset
16582
16583  ...
16584  _endasm
16585 \size footnotesize
16586
16587 \begin_inset LatexCommand \index{\_endasm}
16588
16589 \end_inset
16590
16591
16592 \begin_inset LatexCommand \index{\_\_endasm}
16593
16594 \end_inset
16595
16596
16597 \size default
16598 ;
16599 \family default
16600  keyword pair.
16601  Specifically it will not know which registers are used and thus register
16602  pushing/popping
16603 \begin_inset LatexCommand \index{push/pop}
16604
16605 \end_inset
16606
16607  has to be done manually.
16608  
16609 \end_layout
16610
16611 \begin_layout Standard
16612 It is recommended that each assembly instruction (including labels) be placed
16613  in a separate line (as the example shows).
16614  When the -
16615 \begin_inset ERT
16616 status collapsed
16617
16618 \begin_layout Standard
16619
16620
16621 \backslash
16622 /
16623 \end_layout
16624
16625 \end_inset
16626
16627 -
16628 \emph on
16629 peep-asm
16630 \begin_inset LatexCommand \index{-\/-peep-asm}
16631
16632 \end_inset
16633
16634
16635 \emph default
16636  command line option is used, the inline assembler code will be passed through
16637  the peephole optimizer
16638 \begin_inset LatexCommand \index{Peephole optimizer}
16639
16640 \end_inset
16641
16642 .
16643  There are only a few (if any) cases where this option makes sense, it might
16644  cause some unexpected changes in the inline assembler code.
16645  Please go through the peephole optimizer rules defined in file 
16646 \emph on
16647 SDCCpeeph.def
16648 \emph default
16649  before using this option.
16650 \end_layout
16651
16652 \begin_layout Subsection
16653 Naked Functions
16654 \begin_inset LatexCommand \label{sub:Naked-Functions}
16655
16656 \end_inset
16657
16658
16659 \begin_inset LatexCommand \index{Naked functions}
16660
16661 \end_inset
16662
16663
16664 \end_layout
16665
16666 \begin_layout Standard
16667 A special keyword may be associated with a function declaring it as 
16668 \emph on
16669 _naked
16670 \begin_inset LatexCommand \index{\_naked}
16671
16672 \end_inset
16673
16674
16675 \begin_inset LatexCommand \index{\_\_naked}
16676
16677 \end_inset
16678
16679 .
16680  
16681 \emph default
16682 The 
16683 \emph on
16684 _naked
16685 \emph default
16686  function modifier attribute prevents the compiler from generating prologue
16687 \begin_inset LatexCommand \index{function prologue}
16688
16689 \end_inset
16690
16691  and epilogue
16692 \begin_inset LatexCommand \index{function epilogue}
16693
16694 \end_inset
16695
16696  code for that function.
16697  This means that the user is entirely responsible for such things as saving
16698  any registers that may need to be preserved, selecting the proper register
16699  bank, generating the 
16700 \emph on
16701 return
16702 \emph default
16703  instruction at the end, etc.
16704  Practically, this means that the contents of the function must be written
16705  in inline assembler.
16706  This is particularly useful for interrupt functions, which can have a large
16707  (and often unnecessary) prologue/epilogue.
16708  For example, compare the code generated by these two functions:
16709 \end_layout
16710
16711 \begin_layout Verse
16712
16713 \family typewriter
16714 volatile
16715 \begin_inset LatexCommand \index{volatile}
16716
16717 \end_inset
16718
16719  data unsigned char counter;
16720 \newline
16721
16722 \newline
16723 void simpleInterrupt(void) __interrupt
16724 \begin_inset LatexCommand \index{interrupt}
16725
16726 \end_inset
16727
16728
16729 \begin_inset LatexCommand \index{\_\_interrupt}
16730
16731 \end_inset
16732
16733  (1)
16734 \newline
16735 {
16736 \newline
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 counter++;
16742 \newline
16743 }
16744 \newline
16745
16746 \newline
16747 void nakedInterrupt(void) __interrupt (2) __naked
16748 \newline
16749 {
16750 \newline
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 _asm
16756 \begin_inset LatexCommand \index{\_asm}
16757
16758 \end_inset
16759
16760
16761 \begin_inset LatexCommand \index{\_\_asm}
16762
16763 \end_inset
16764
16765
16766 \newline
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 inc\InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 _counter ; does not change flags, no need to save psw
16779 \newline
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 reti\InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 ; MUST explicitly
16791  include ret or reti in _naked function.
16792 \newline
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 _endasm
16798 \begin_inset LatexCommand \index{\_endasm}
16799
16800 \end_inset
16801
16802
16803 \begin_inset LatexCommand \index{\_\_endasm}
16804
16805 \end_inset
16806
16807 ;
16808 \newline
16809 }
16810 \end_layout
16811
16812 \begin_layout Standard
16813 For an 8051 target, the generated simpleInterrupt looks like:
16814 \end_layout
16815
16816 \begin_layout Verse
16817
16818 \family typewriter
16819 Note, this is an 
16820 \emph on
16821 outdated
16822 \emph default
16823  example, recent versions of SDCC generate
16824 \newline
16825 the 
16826 \emph on
16827 same
16828 \emph default
16829  code for simpleInterrupt() and nakedInterrupt()!
16830 \newline
16831
16832 \newline
16833 _simpleInterrupt:
16834 \newline
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 push\InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 acc
16844 \newline
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 push\InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 b
16854 \newline
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 pu
16860 sh\InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 dpl
16865 \newline
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 push\InsetSpace ~
16871 \InsetSpace ~
16872 \InsetSpace ~
16873 \InsetSpace ~
16874 dph
16875 \newline
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 push\InsetSpace ~
16881 \InsetSpace ~
16882 \InsetSpace ~
16883 \InsetSpace ~
16884 psw
16885 \newline
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 mov\InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 \InsetSpace ~
16895 psw,#0x00
16896 \newline
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 inc\InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 _counter
16907 \newline
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 pop\InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 psw
16918 \newline
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 pop\InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 \InsetSpace ~
16928 dph
16929 \newline
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 pop\InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 dpl
16940 \newline
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 pop\InsetSpace ~
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 b
16951 \newline
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 \InsetSpace ~
16956 pop\InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 acc
16962 \newline
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 reti
16968 \end_layout
16969
16970 \begin_layout Standard
16971 whereas nakedInterrupt looks like:
16972 \end_layout
16973
16974 \begin_layout Verse
16975
16976 \family typewriter
16977 _nakedInterrupt:
16978 \newline
16979 \InsetSpace ~
16980 \InsetSpace ~
16981 \InsetSpace ~
16982 \InsetSpace ~
16983 inc\InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 _counter ; does not change flags, no need to save psw
16988 \newline
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 \InsetSpace ~
16993 reti\InsetSpace ~
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 \InsetSpace ~
17004 \InsetSpace ~
17005 ;
17006  MUST explicitly include ret or reti in _naked function
17007 \end_layout
17008
17009 \begin_layout Standard
17010 The related directive #pragma exclude
17011 \begin_inset LatexCommand \index{\#pragma exclude}
17012
17013 \end_inset
17014
17015  allows a more fine grained control over pushing & popping
17016 \begin_inset LatexCommand \index{push/pop}
17017
17018 \end_inset
17019
17020  the registers.
17021 \end_layout
17022
17023 \begin_layout Standard
17024 While there is nothing preventing you from writing C code inside a 
17025 \family typewriter
17026 _naked
17027 \family default
17028  function, there are many ways to shoot yourself in the foot doing this,
17029  and it is recommended that you stick to inline assembler.
17030 \end_layout
17031
17032 \begin_layout Subsection
17033 Use of Labels within Inline Assembler
17034 \end_layout
17035
17036 \begin_layout Standard
17037 SDCC allows the use of in-line assembler with a few restrictions regarding
17038  labels.
17039  In older versions of the compiler all labels defined within inline assembler
17040  code had to be of the form 
17041 \emph on
17042 nnnnn$
17043 \emph default
17044  where nnnnn is a number less than 100 (which implies a limit of utmost
17045  100 inline assembler labels 
17046 \emph on
17047 per function
17048 \emph default
17049 \noun on
17050 )
17051 \noun default
17052 .
17053  
17054 \end_layout
17055
17056 \begin_layout Verse
17057
17058 \family typewriter
17059 _asm
17060 \begin_inset LatexCommand \index{\_asm}
17061
17062 \end_inset
17063
17064
17065 \begin_inset LatexCommand \index{\_\_asm}
17066
17067 \end_inset
17068
17069  
17070 \newline
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 mov\InsetSpace ~
17076 \InsetSpace ~
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 b,#10 
17081 \newline
17082 00001$: 
17083 \newline
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 djnz\InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 b,00001$ 
17093 \newline
17094 _endasm
17095 \begin_inset LatexCommand \index{\_endasm}
17096
17097 \end_inset
17098
17099
17100 \begin_inset LatexCommand \index{\_\_endasm}
17101
17102 \end_inset
17103
17104  ;
17105 \end_layout
17106
17107 \begin_layout Standard
17108 Inline assembler code cannot reference any C-labels, however it can reference
17109  labels
17110 \begin_inset LatexCommand \index{Labels}
17111
17112 \end_inset
17113
17114  defined by the inline assembler, e.g.:
17115 \end_layout
17116
17117 \begin_layout Verse
17118
17119 \family typewriter
17120 foo() { 
17121 \newline
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 /* some c code */ 
17127 \newline
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 _asm 
17133 \newline
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 ; some assembler code 
17141 \newline
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 ljmp $0003 
17149 \newline
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 _endasm;
17155  
17156 \newline
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 /* some more c code */ 
17162 \newline
17163 clabel:\InsetSpace ~
17164 \InsetSpace ~
17165 /* inline assembler cannot reference this
17166  label */ 
17167 \newline
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 _asm
17173 \newline
17174 \InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 $0003: ;label (can be referenced by inline assembler only)
17179  
17180 \newline
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 \InsetSpace ~
17185 _endasm
17186 \begin_inset LatexCommand \index{\_endasm}
17187
17188 \end_inset
17189
17190
17191 \begin_inset LatexCommand \index{\_\_endasm}
17192
17193 \end_inset
17194
17195  ; 
17196 \newline
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 /* some more c code */
17202 \newline
17203 }
17204 \end_layout
17205
17206 \begin_layout Standard
17207 In other words inline assembly code can access labels defined in inline
17208  assembly within the scope of the function.
17209  The same goes the other way, i.e.
17210  labels defines in inline assembly can not be accessed by C statements.
17211 \end_layout
17212
17213 \begin_layout Section
17214 Interfacing with Assembler Code
17215 \begin_inset LatexCommand \index{Assembler routines}
17216
17217 \end_inset
17218
17219
17220 \end_layout
17221
17222 \begin_layout Subsection
17223 Global Registers used for Parameter Passing
17224 \begin_inset LatexCommand \index{Parameter passing}
17225
17226 \end_inset
17227
17228
17229 \end_layout
17230
17231 \begin_layout Standard
17232 The compiler always uses the global registers 
17233 \emph on
17234 DPL, DPH
17235 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17236
17237 \end_inset
17238
17239
17240 \begin_inset LatexCommand \index{DPTR}
17241
17242 \end_inset
17243
17244 , B
17245 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17246
17247 \end_inset
17248
17249  
17250 \emph default
17251 and
17252 \emph on
17253  ACC
17254 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17255
17256 \end_inset
17257
17258
17259 \emph default
17260  to pass the first parameter to a function, and also to pass the return
17261  value 
17262 \begin_inset LatexCommand \index{return value}
17263
17264 \end_inset
17265
17266 of function; according to the following scheme: one byte return value in
17267  
17268 \emph on
17269 DPL
17270 \emph default
17271 , two byte value in 
17272 \emph on
17273 DPL
17274 \emph default
17275  (LSB) and 
17276 \emph on
17277 DPH
17278 \emph default
17279  (MSB).
17280  three byte values (generic pointers) in 
17281 \emph on
17282 DPH
17283 \emph default
17284
17285 \emph on
17286 DPL
17287 \emph default
17288  and 
17289 \emph on
17290 B
17291 \emph default
17292 , and four byte values in 
17293 \emph on
17294 DPH
17295 \emph default
17296
17297 \emph on
17298 DPL
17299 \emph default
17300 ,
17301 \emph on
17302  B
17303 \emph default
17304  and 
17305 \emph on
17306 ACC
17307 \emph default
17308 .
17309  Generic pointers
17310 \begin_inset LatexCommand \index{generic pointer}
17311
17312 \end_inset
17313
17314  contain type of accessed memory in 
17315 \emph on
17316 B
17317 \emph default
17318
17319 \series bold
17320 0x00
17321 \series default
17322  -- xdata/far, 
17323 \series bold
17324 0x40
17325 \series default
17326  -- idata/near -- , 
17327 \series bold
17328 0x60
17329 \series default
17330  -- pdata, 
17331 \series bold
17332 0x80
17333 \series default
17334  -- code
17335 \begin_inset Note Note
17336 status collapsed
17337
17338 \begin_layout Standard
17339 This might not be the case of certain memory models (medium???)
17340 \end_layout
17341
17342 \end_inset
17343
17344 .
17345 \end_layout
17346
17347 \begin_layout Standard
17348 The second parameter onwards is either allocated on the stack (for reentrant
17349  routines or if -
17350 \begin_inset ERT
17351 status collapsed
17352
17353 \begin_layout Standard
17354
17355
17356 \backslash
17357 /
17358 \end_layout
17359
17360 \end_inset
17361
17362 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17363  
17364 \end_layout
17365
17366 \begin_layout Subsection
17367 Registers usage
17368 \end_layout
17369
17370 \begin_layout Standard
17371 Unless the called function is declared as 
17372 \family typewriter
17373 _naked
17374 \family default
17375
17376 \begin_inset LatexCommand \index{naked}
17377
17378 \end_inset
17379
17380 , or the -
17381 \begin_inset ERT
17382 status collapsed
17383
17384 \begin_layout Standard
17385
17386
17387 \backslash
17388 /
17389 \end_layout
17390
17391 \end_inset
17392
17393 -callee-saves
17394 \begin_inset LatexCommand \index{-\/-callee-saves}
17395
17396 \end_inset
17397
17398 /-
17399 \begin_inset ERT
17400 status collapsed
17401
17402 \begin_layout Standard
17403
17404
17405 \backslash
17406 /
17407 \end_layout
17408
17409 \end_inset
17410
17411 -all-callee-saves command line option or the corresponding callee_saves
17412  pragma are used, the caller will save the registers (
17413 \emph on
17414 R0-R7
17415 \emph default
17416 ) around the call, so the called function can destroy they content freely.
17417 \end_layout
17418
17419 \begin_layout Standard
17420 If the called function is not declared as 
17421 \family typewriter
17422 _naked
17423 \family default
17424 , the caller will swap register banks around the call, if caller and callee
17425  use different register banks (having them defined by the 
17426 \family typewriter
17427 _using
17428 \family default
17429  modifier).
17430  
17431 \end_layout
17432
17433 \begin_layout Standard
17434 The called function can also use 
17435 \emph on
17436 DPL
17437 \emph default
17438
17439 \emph on
17440 DPH
17441 \emph default
17442
17443 \emph on
17444 B
17445 \emph default
17446  and 
17447 \emph on
17448 ACC
17449 \emph default
17450  observing that they are used for parameter/return value passing.
17451 \end_layout
17452
17453 \begin_layout Subsection
17454 Assembler Routine (non-reentrant)
17455 \end_layout
17456
17457 \begin_layout Standard
17458 In the following example
17459 \begin_inset LatexCommand \index{reentrant}
17460
17461 \end_inset
17462
17463
17464 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17465
17466 \end_inset
17467
17468  the function c_func calls an assembler routine asm_func, which takes two
17469  parameters
17470 \begin_inset LatexCommand \index{function parameter}
17471
17472 \end_inset
17473
17474 .
17475 \end_layout
17476
17477 \begin_layout Verse
17478
17479 \family typewriter
17480 extern int asm_func(unsigned char, unsigned char);
17481 \newline
17482
17483 \newline
17484 int c_func (unsigned char
17485  i, unsigned char j)
17486 \newline
17487 {
17488 \newline
17489 \InsetSpace ~
17490 \InsetSpace ~
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 return asm_func(i,j);
17494 \newline
17495 }
17496 \newline
17497
17498 \newline
17499 int main()
17500 \newline
17501 {
17502 \newline
17503 \InsetSpace ~
17504 \InsetSpace ~
17505 \InsetSpace ~
17506 \InsetSpace ~
17507 return c_func(10,9);
17508 \newline
17509 }
17510 \end_layout
17511
17512 \begin_layout Standard
17513 The corresponding assembler function is:
17514 \end_layout
17515
17516 \begin_layout Verse
17517
17518 \family typewriter
17519 .globl _asm_func_PARM_2 
17520 \newline
17521 \InsetSpace ~
17522 \InsetSpace ~
17523 \InsetSpace ~
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 \InsetSpace ~
17528 \InsetSpace ~
17529 .globl _asm_func 
17530 \newline
17531 \InsetSpace ~
17532 \InsetSpace ~
17533 \InsetSpace ~
17534 \InsetSpace ~
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 \InsetSpace ~
17539 .area OSEG 
17540 \newline
17541 _asm_func_PARM_2:
17542 \newline
17543 \InsetSpace ~
17544 \InsetSpace ~
17545 \InsetSpace ~
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 \InsetSpace ~
17549 \InsetSpace ~
17550 \InsetSpace ~
17551 .ds   
17552  1 
17553 \newline
17554 \InsetSpace ~
17555 \InsetSpace ~
17556 \InsetSpace ~
17557 \InsetSpace ~
17558 \InsetSpace ~
17559 \InsetSpace ~
17560 \InsetSpace ~
17561 \InsetSpace ~
17562 .area CSEG 
17563 \newline
17564 _asm_func: 
17565 \newline
17566 \InsetSpace ~
17567 \InsetSpace ~
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 \InsetSpace ~
17572 \InsetSpace ~
17573 \InsetSpace ~
17574 mov\InsetSpace ~
17575 \InsetSpace ~
17576 \InsetSpace ~
17577 \InsetSpace ~
17578 a,dpl 
17579 \newline
17580 \InsetSpace ~
17581 \InsetSpace ~
17582 \InsetSpace ~
17583 \InsetSpace ~
17584 \InsetSpace ~
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 \InsetSpace ~
17588 add\InsetSpace ~
17589 \InsetSpace ~
17590 \InsetSpace ~
17591 \InsetSpace ~
17592 a,_asm_func_PARM_2 
17593 \newline
17594 \InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 mov\InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 dpl,a 
17607 \newline
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 \InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 \InsetSpace ~
17616 mov\InsetSpace ~
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 dph
17621 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17622
17623 \end_inset
17624
17625 ,#0x00 
17626 \newline
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 ret
17636 \end_layout
17637
17638 \begin_layout Standard
17639 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17640  the parameter number starting from 1, and counting from the left.
17641  The first parameter is passed in 
17642 \emph on
17643 DPH
17644 \emph default
17645
17646 \emph on
17647 DPL
17648 \emph default
17649
17650 \emph on
17651 B
17652 \emph default
17653  and 
17654 \emph on
17655 ACC
17656 \emph default
17657  according to the description above.
17658  The variable name for the second parameter will be _<function_name>_PARM_2.
17659 \newline
17660
17661 \newline
17662 Assem
17663 ble the assembler routine with the following command:
17664 \newline
17665
17666 \newline
17667
17668 \family sans
17669 \series bold
17670 asx8051 -losg asmfunc.asm
17671 \newline
17672
17673 \newline
17674
17675 \family default
17676 \series default
17677 Then compile and link the assembler routine to the C source file with the
17678  following command:
17679 \newline
17680
17681 \newline
17682
17683 \family sans
17684 \series bold
17685 sdcc cfunc.c asmfunc.rel
17686 \end_layout
17687
17688 \begin_layout Subsection
17689 Assembler Routine (reentrant)
17690 \end_layout
17691
17692 \begin_layout Standard
17693 In this case
17694 \begin_inset LatexCommand \index{reentrant}
17695
17696 \end_inset
17697
17698
17699 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17700
17701 \end_inset
17702
17703  the second parameter
17704 \begin_inset LatexCommand \index{function parameter}
17705
17706 \end_inset
17707
17708  onwards will be passed on the stack, the parameters are pushed from right
17709  to left i.e.
17710  before the call the second leftmost parameter will be on the top of the
17711  stack (the leftmost parameter is passed in registers).
17712  Here is an example:
17713 \end_layout
17714
17715 \begin_layout Verse
17716
17717 \family typewriter
17718 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17719 \newline
17720
17721 \newline
17722 int
17723  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
17724 \newline
17725 {
17726  
17727 \newline
17728 \InsetSpace ~
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 return asm_func(i,j,k); 
17733 \newline
17734
17735 \newline
17736
17737 \newline
17738 int main() 
17739 \newline
17740
17741 \newline
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 return c_func(10,9,8); 
17747 \newline
17748 }
17749 \end_layout
17750
17751 \begin_layout Standard
17752 The corresponding (unoptimized) assembler routine is:
17753 \end_layout
17754
17755 \begin_layout Verse
17756
17757 \family typewriter
17758 .globl _asm_func 
17759 \newline
17760 _asm_func: 
17761 \newline
17762 \InsetSpace ~
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 push\InsetSpace ~
17767 _bp 
17768 \newline
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 mov\InsetSpace ~
17774 \InsetSpace ~
17775 _bp,sp\InsetSpace ~
17776 \InsetSpace ~
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 ;stack contains: _bp, return
17782  address, second parameter, third parameter
17783 \newline
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 \InsetSpace ~
17788 mov\InsetSpace ~
17789 \InsetSpace ~
17790 r2,dpl
17791 \newline
17792 \InsetSpace ~
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 mov\InsetSpace ~
17797 \InsetSpace ~
17798 a,_bp
17799 \newline
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 \InsetSpace ~
17804 add\InsetSpace ~
17805 \InsetSpace ~
17806 a,#0xfd\InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 \InsetSpace ~
17810 \InsetSpace ~
17811 ;calculate
17812  pointer to the second parameter
17813 \newline
17814 \InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 mov\InsetSpace ~
17819 \InsetSpace ~
17820 r0,a 
17821 \newline
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 mov\InsetSpace ~
17827 \InsetSpace ~
17828 a,_bp 
17829 \newline
17830 \InsetSpace ~
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 add\InsetSpace ~
17835 \InsetSpace ~
17836 a,#0xfc\InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 ;calculate pointer
17842  to the rightmost parameter
17843 \newline
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 mov\InsetSpace ~
17849 \InsetSpace ~
17850 r1,a 
17851 \newline
17852 \InsetSpace ~
17853 \InsetSpace ~
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 mov\InsetSpace ~
17857 \InsetSpace ~
17858 a,@r0
17859 \newline
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 add\InsetSpace ~
17865 \InsetSpace ~
17866 a,@r1
17867 \newline
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 add\InsetSpace ~
17873 \InsetSpace ~
17874 a,r2\InsetSpace ~
17875 \InsetSpace ~
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 ;calculate the
17883  result (= sum of all three parameters)
17884 \newline
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 mov\InsetSpace ~
17890 \InsetSpace ~
17891 dpl,a\InsetSpace ~
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 ;return value goes into dptr
17899  (cast into int)
17900 \newline
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 mov\InsetSpace ~
17906 \InsetSpace ~
17907 dph,#0x00 
17908 \newline
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 mov\InsetSpace ~
17914 \InsetSpace ~
17915 sp,_bp 
17916 \newline
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 \InsetSpace ~
17921 pop\InsetSpace ~
17922 \InsetSpace ~
17923 _bp 
17924 \newline
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 ret
17930 \end_layout
17931
17932 \begin_layout Standard
17933 The compiling and linking procedure remains the same, however note the extra
17934  entry & exit linkage required for the assembler code, _bp is the stack
17935  frame pointer and is used to compute the offset into the stack for parameters
17936  and local variables.
17937 \begin_inset VSpace bigskip
17938 \end_inset
17939
17940
17941 \end_layout
17942
17943 \begin_layout Section
17944 int (16 bit)
17945 \begin_inset LatexCommand \index{int (16 bit)}
17946
17947 \end_inset
17948
17949  and long (32 bit)
17950 \begin_inset LatexCommand \index{long (32 bit)}
17951
17952 \end_inset
17953
17954  Support
17955 \end_layout
17956
17957 \begin_layout Standard
17958 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17959  multiplication and modulus operations are implemented by support routines.
17960  These support routines are all developed in ANSI-C to facilitate porting
17961  to other MCUs, although some model specific assembler optimizations are
17962  used.
17963  The following files contain the described routines, all of them can be
17964  found in <installdir>/share/sdcc/lib.
17965 \newline
17966
17967 \end_layout
17968
17969 \begin_layout Standard
17970 \align center
17971 \begin_inset Tabular
17972 <lyxtabular version="3" rows="11" columns="2">
17973 <features>
17974 <column alignment="left" valignment="top" leftline="true" width="0">
17975 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17976 <row topline="true" bottomline="true">
17977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17978 \begin_inset Text
17979
17980 \begin_layout Standard
17981
17982 \series bold
17983 Function
17984 \end_layout
17985
17986 \end_inset
17987 </cell>
17988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17989 \begin_inset Text
17990
17991 \begin_layout Standard
17992
17993 \series bold
17994 Description
17995 \end_layout
17996
17997 \end_inset
17998 </cell>
17999 </row>
18000 <row topline="true">
18001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18002 \begin_inset Text
18003
18004 \begin_layout Standard
18005 _mulint.c 
18006 \end_layout
18007
18008 \end_inset
18009 </cell>
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18011 \begin_inset Text
18012
18013 \begin_layout Standard
18014 16 bit multiplication
18015 \end_layout
18016
18017 \end_inset
18018 </cell>
18019 </row>
18020 <row topline="true">
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18022 \begin_inset Text
18023
18024 \begin_layout Standard
18025 _divsint.c 
18026 \end_layout
18027
18028 \end_inset
18029 </cell>
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18031 \begin_inset Text
18032
18033 \begin_layout Standard
18034  signed 16 bit division (calls _divuint)
18035 \end_layout
18036
18037 \end_inset
18038 </cell>
18039 </row>
18040 <row topline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18042 \begin_inset Text
18043
18044 \begin_layout Standard
18045 _divuint.c 
18046 \end_layout
18047
18048 \end_inset
18049 </cell>
18050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18051 \begin_inset Text
18052
18053 \begin_layout Standard
18054  unsigned 16 bit division
18055 \end_layout
18056
18057 \end_inset
18058 </cell>
18059 </row>
18060 <row topline="true">
18061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18062 \begin_inset Text
18063
18064 \begin_layout Standard
18065 _modsint.c
18066 \end_layout
18067
18068 \end_inset
18069 </cell>
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18071 \begin_inset Text
18072
18073 \begin_layout Standard
18074 signed 16 bit modulus (calls _moduint)
18075 \end_layout
18076
18077 \end_inset
18078 </cell>
18079 </row>
18080 <row topline="true">
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18082 \begin_inset Text
18083
18084 \begin_layout Standard
18085 _moduint.c
18086 \end_layout
18087
18088 \end_inset
18089 </cell>
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18091 \begin_inset Text
18092
18093 \begin_layout Standard
18094 unsigned 16 bit modulus
18095 \end_layout
18096
18097 \end_inset
18098 </cell>
18099 </row>
18100 <row topline="true">
18101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18102 \begin_inset Text
18103
18104 \begin_layout Standard
18105 _mullong.c
18106 \end_layout
18107
18108 \end_inset
18109 </cell>
18110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18111 \begin_inset Text
18112
18113 \begin_layout Standard
18114 32 bit multiplication
18115 \end_layout
18116
18117 \end_inset
18118 </cell>
18119 </row>
18120 <row topline="true">
18121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18122 \begin_inset Text
18123
18124 \begin_layout Standard
18125 _divslong.c 
18126 \end_layout
18127
18128 \end_inset
18129 </cell>
18130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18131 \begin_inset Text
18132
18133 \begin_layout Standard
18134  signed 32 division (calls _divulong)
18135 \end_layout
18136
18137 \end_inset
18138 </cell>
18139 </row>
18140 <row topline="true">
18141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18142 \begin_inset Text
18143
18144 \begin_layout Standard
18145 _divulong.c 
18146 \end_layout
18147
18148 \end_inset
18149 </cell>
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18151 \begin_inset Text
18152
18153 \begin_layout Standard
18154 unsigned 32 division
18155 \end_layout
18156
18157 \end_inset
18158 </cell>
18159 </row>
18160 <row topline="true">
18161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18162 \begin_inset Text
18163
18164 \begin_layout Standard
18165 _modslong.c
18166 \end_layout
18167
18168 \end_inset
18169 </cell>
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18171 \begin_inset Text
18172
18173 \begin_layout Standard
18174  signed 32 bit modulus (calls _modulong)
18175 \end_layout
18176
18177 \end_inset
18178 </cell>
18179 </row>
18180 <row topline="true" bottomline="true">
18181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18182 \begin_inset Text
18183
18184 \begin_layout Standard
18185 _modulong.c
18186 \end_layout
18187
18188 \end_inset
18189 </cell>
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18191 \begin_inset Text
18192
18193 \begin_layout Standard
18194 unsigned 32 bit modulus
18195 \end_layout
18196
18197 \end_inset
18198 </cell>
18199 </row>
18200 </lyxtabular>
18201
18202 \end_inset
18203
18204
18205 \newline
18206
18207 \end_layout
18208
18209 \begin_layout Standard
18210 Since they are compiled as 
18211 \emph on
18212 non-reentrant
18213 \emph default
18214
18215 \begin_inset LatexCommand \index{reentrant}
18216
18217 \end_inset
18218
18219 , interrupt
18220 \begin_inset LatexCommand \index{interrupt}
18221
18222 \end_inset
18223
18224  service routines should not do any of the above operations.
18225  If this is unavoidable then the above routines will need to be compiled
18226  with the 
18227 \emph on
18228 -
18229 \begin_inset ERT
18230 status collapsed
18231
18232 \begin_layout Standard
18233
18234
18235 \backslash
18236 /
18237 \end_layout
18238
18239 \end_inset
18240
18241 -stack-auto
18242 \begin_inset LatexCommand \index{-\/-stack-auto}
18243
18244 \end_inset
18245
18246
18247 \emph default
18248  option, after which the source program will have to be compiled with 
18249 \emph on
18250 -
18251 \begin_inset ERT
18252 status collapsed
18253
18254 \begin_layout Standard
18255
18256
18257 \backslash
18258 /
18259 \end_layout
18260
18261 \end_inset
18262
18263 -int-long-reent
18264 \begin_inset LatexCommand \index{-\/-int-long-reent}
18265
18266 \end_inset
18267
18268
18269 \emph default
18270  option.
18271  Notice that you don't have to call these routines directly.
18272  The compiler will use them automatically every time an integer operation
18273  is required.
18274 \end_layout
18275
18276 \begin_layout Section
18277 Floating Point Support
18278 \begin_inset LatexCommand \index{Floating point support}
18279
18280 \end_inset
18281
18282
18283 \end_layout
18284
18285 \begin_layout Standard
18286 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18287  The floating point support routines are derived from gcc's floatlib.c and
18288  consist of the following routines:
18289 \newline
18290
18291 \end_layout
18292
18293 \begin_layout Standard
18294 \align center
18295
18296 \size footnotesize
18297 \begin_inset Tabular
18298 <lyxtabular version="3" rows="17" columns="2">
18299 <features>
18300 <column alignment="left" valignment="top" leftline="true" width="0">
18301 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18302 <row topline="true" bottomline="true">
18303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18304 \begin_inset Text
18305
18306 \begin_layout Standard
18307
18308 \family roman
18309 \series medium
18310 \shape up
18311 \size normal
18312 \emph off
18313 \bar no
18314 \noun off
18315 \color none
18316 Function 
18317 \end_layout
18318
18319 \end_inset
18320 </cell>
18321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18322 \begin_inset Text
18323
18324 \begin_layout Standard
18325 Description
18326 \end_layout
18327
18328 \end_inset
18329 </cell>
18330 </row>
18331 <row topline="true">
18332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18333 \begin_inset Text
18334
18335 \begin_layout Standard
18336
18337 \family roman
18338 \series medium
18339 \shape up
18340 \size normal
18341 \emph off
18342 \bar no
18343 \noun off
18344 \color none
18345 _fsadd.c
18346 \end_layout
18347
18348 \end_inset
18349 </cell>
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18351 \begin_inset Text
18352
18353 \begin_layout Standard
18354
18355 \family roman
18356 \series medium
18357 \shape up
18358 \size normal
18359 \emph off
18360 \bar no
18361 \noun off
18362 \color none
18363 add floating point numbers
18364 \end_layout
18365
18366 \end_inset
18367 </cell>
18368 </row>
18369 <row topline="true">
18370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18371 \begin_inset Text
18372
18373 \begin_layout Standard
18374
18375 \family roman
18376 \series medium
18377 \shape up
18378 \size normal
18379 \emph off
18380 \bar no
18381 \noun off
18382 \color none
18383 _fssub.c 
18384 \end_layout
18385
18386 \end_inset
18387 </cell>
18388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18389 \begin_inset Text
18390
18391 \begin_layout Standard
18392
18393 \family roman
18394 \series medium
18395 \shape up
18396 \size normal
18397 \emph off
18398 \bar no
18399 \noun off
18400 \color none
18401 subtract floating point numbers 
18402 \end_layout
18403
18404 \end_inset
18405 </cell>
18406 </row>
18407 <row topline="true">
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18409 \begin_inset Text
18410
18411 \begin_layout Standard
18412
18413 \family roman
18414 \series medium
18415 \shape up
18416 \size normal
18417 \emph off
18418 \bar no
18419 \noun off
18420 \color none
18421 _fsdiv.c 
18422 \end_layout
18423
18424 \end_inset
18425 </cell>
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18427 \begin_inset Text
18428
18429 \begin_layout Standard
18430
18431 \family roman
18432 \series medium
18433 \shape up
18434 \size normal
18435 \emph off
18436 \bar no
18437 \noun off
18438 \color none
18439 divide floating point numbers 
18440 \end_layout
18441
18442 \end_inset
18443 </cell>
18444 </row>
18445 <row topline="true">
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18447 \begin_inset Text
18448
18449 \begin_layout Standard
18450
18451 \family roman
18452 \series medium
18453 \shape up
18454 \size normal
18455 \emph off
18456 \bar no
18457 \noun off
18458 \color none
18459 _fsmul.c 
18460 \end_layout
18461
18462 \end_inset
18463 </cell>
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18465 \begin_inset Text
18466
18467 \begin_layout Standard
18468
18469 \family roman
18470 \series medium
18471 \shape up
18472 \size normal
18473 \emph off
18474 \bar no
18475 \noun off
18476 \color none
18477 multiply floating point numbers 
18478 \end_layout
18479
18480 \end_inset
18481 </cell>
18482 </row>
18483 <row topline="true">
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18485 \begin_inset Text
18486
18487 \begin_layout Standard
18488
18489 \family roman
18490 \series medium
18491 \shape up
18492 \size normal
18493 \emph off
18494 \bar no
18495 \noun off
18496 \color none
18497 _fs2uchar.c
18498 \end_layout
18499
18500 \end_inset
18501 </cell>
18502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18503 \begin_inset Text
18504
18505 \begin_layout Standard
18506
18507 \family roman
18508 \series medium
18509 \shape up
18510 \size normal
18511 \emph off
18512 \bar no
18513 \noun off
18514 \color none
18515 convert floating point to unsigned char
18516 \end_layout
18517
18518 \end_inset
18519 </cell>
18520 </row>
18521 <row topline="true">
18522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18523 \begin_inset Text
18524
18525 \begin_layout Standard
18526
18527 \family roman
18528 \series medium
18529 \shape up
18530 \size normal
18531 \emph off
18532 \bar no
18533 \noun off
18534 \color none
18535 _fs2char.c
18536 \end_layout
18537
18538 \end_inset
18539 </cell>
18540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18541 \begin_inset Text
18542
18543 \begin_layout Standard
18544
18545 \family roman
18546 \series medium
18547 \shape up
18548 \size normal
18549 \emph off
18550 \bar no
18551 \noun off
18552 \color none
18553 convert floating point to signed char
18554 \end_layout
18555
18556 \end_inset
18557 </cell>
18558 </row>
18559 <row topline="true">
18560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18561 \begin_inset Text
18562
18563 \begin_layout Standard
18564
18565 \family roman
18566 \series medium
18567 \shape up
18568 \size normal
18569 \emph off
18570 \bar no
18571 \noun off
18572 \color none
18573 _fs2uint.c
18574 \end_layout
18575
18576 \end_inset
18577 </cell>
18578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18579 \begin_inset Text
18580
18581 \begin_layout Standard
18582
18583 \family roman
18584 \series medium
18585 \shape up
18586 \size normal
18587 \emph off
18588 \bar no
18589 \noun off
18590 \color none
18591 convert floating point to unsigned int
18592 \end_layout
18593
18594 \end_inset
18595 </cell>
18596 </row>
18597 <row topline="true">
18598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18599 \begin_inset Text
18600
18601 \begin_layout Standard
18602
18603 \family roman
18604 \series medium
18605 \shape up
18606 \size normal
18607 \emph off
18608 \bar no
18609 \noun off
18610 \color none
18611 _fs2int.c
18612 \end_layout
18613
18614 \end_inset
18615 </cell>
18616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18617 \begin_inset Text
18618
18619 \begin_layout Standard
18620
18621 \family roman
18622 \series medium
18623 \shape up
18624 \size normal
18625 \emph off
18626 \bar no
18627 \noun off
18628 \color none
18629 convert floating point to signed int
18630 \end_layout
18631
18632 \end_inset
18633 </cell>
18634 </row>
18635 <row topline="true">
18636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18637 \begin_inset Text
18638
18639 \begin_layout Standard
18640
18641 \family roman
18642 \series medium
18643 \shape up
18644 \size normal
18645 \emph off
18646 \bar no
18647 \noun off
18648 \color none
18649 _fs2ulong.
18650 \family default
18651 \series default
18652 \shape default
18653 \size default
18654 \emph default
18655 \bar default
18656 \noun default
18657 c
18658 \end_layout
18659
18660 \end_inset
18661 </cell>
18662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18663 \begin_inset Text
18664
18665 \begin_layout Standard
18666
18667 \family roman
18668 \series medium
18669 \shape up
18670 \size normal
18671 \emph off
18672 \bar no
18673 \noun off
18674 \color none
18675 convert floating point to unsigned long
18676 \end_layout
18677
18678 \end_inset
18679 </cell>
18680 </row>
18681 <row topline="true">
18682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18683 \begin_inset Text
18684
18685 \begin_layout Standard
18686
18687 \family roman
18688 \series medium
18689 \shape up
18690 \size normal
18691 \emph off
18692 \bar no
18693 \noun off
18694 \color none
18695 _fs2long.c
18696 \end_layout
18697
18698 \end_inset
18699 </cell>
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18701 \begin_inset Text
18702
18703 \begin_layout Standard
18704
18705 \family roman
18706 \series medium
18707 \shape up
18708 \size normal
18709 \emph off
18710 \bar no
18711 \noun off
18712 \color none
18713 convert floating point to signed long
18714 \end_layout
18715
18716 \end_inset
18717 </cell>
18718 </row>
18719 <row topline="true">
18720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18721 \begin_inset Text
18722
18723 \begin_layout Standard
18724
18725 \family roman
18726 \series medium
18727 \shape up
18728 \size normal
18729 \emph off
18730 \bar no
18731 \noun off
18732 \color none
18733 _uchar2fs.c
18734 \end_layout
18735
18736 \end_inset
18737 </cell>
18738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18739 \begin_inset Text
18740
18741 \begin_layout Standard
18742
18743 \family roman
18744 \series medium
18745 \shape up
18746 \size normal
18747 \emph off
18748 \bar no
18749 \noun off
18750 \color none
18751 convert unsigned char to floating point
18752 \end_layout
18753
18754 \end_inset
18755 </cell>
18756 </row>
18757 <row topline="true">
18758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18759 \begin_inset Text
18760
18761 \begin_layout Standard
18762
18763 \family roman
18764 \series medium
18765 \shape up
18766 \size normal
18767 \emph off
18768 \bar no
18769 \noun off
18770 \color none
18771 _char2fs.c
18772 \end_layout
18773
18774 \end_inset
18775 </cell>
18776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18777 \begin_inset Text
18778
18779 \begin_layout Standard
18780
18781 \family roman
18782 \series medium
18783 \shape up
18784 \size normal
18785 \emph off
18786 \bar no
18787 \noun off
18788 \color none
18789 convert char to floating point number
18790 \end_layout
18791
18792 \end_inset
18793 </cell>
18794 </row>
18795 <row topline="true">
18796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18797 \begin_inset Text
18798
18799 \begin_layout Standard
18800
18801 \family roman
18802 \series medium
18803 \shape up
18804 \size normal
18805 \emph off
18806 \bar no
18807 \noun off
18808 \color none
18809 _uint2fs.c
18810 \end_layout
18811
18812 \end_inset
18813 </cell>
18814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18815 \begin_inset Text
18816
18817 \begin_layout Standard
18818
18819 \family roman
18820 \series medium
18821 \shape up
18822 \size normal
18823 \emph off
18824 \bar no
18825 \noun off
18826 \color none
18827 convert unsigned int to floating point
18828 \end_layout
18829
18830 \end_inset
18831 </cell>
18832 </row>
18833 <row topline="true">
18834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18835 \begin_inset Text
18836
18837 \begin_layout Standard
18838
18839 \family roman
18840 \series medium
18841 \shape up
18842 \size normal
18843 \emph off
18844 \bar no
18845 \noun off
18846 \color none
18847 _int2fs.c
18848 \end_layout
18849
18850 \end_inset
18851 </cell>
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18853 \begin_inset Text
18854
18855 \begin_layout Standard
18856
18857 \family roman
18858 \series medium
18859 \shape up
18860 \size normal
18861 \emph off
18862 \bar no
18863 \noun off
18864 \color none
18865 convert int to floating point numbers
18866 \end_layout
18867
18868 \end_inset
18869 </cell>
18870 </row>
18871 <row topline="true">
18872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18873 \begin_inset Text
18874
18875 \begin_layout Standard
18876
18877 \family roman
18878 \series medium
18879 \shape up
18880 \size normal
18881 \emph off
18882 \bar no
18883 \noun off
18884 \color none
18885 _ulong2fs.c
18886 \end_layout
18887
18888 \end_inset
18889 </cell>
18890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18891 \begin_inset Text
18892
18893 \begin_layout Standard
18894
18895 \family roman
18896 \series medium
18897 \shape up
18898 \size normal
18899 \emph off
18900 \bar no
18901 \noun off
18902 \color none
18903 convert unsigned long to floating point number
18904 \end_layout
18905
18906 \end_inset
18907 </cell>
18908 </row>
18909 <row topline="true" bottomline="true">
18910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18911 \begin_inset Text
18912
18913 \begin_layout Standard
18914
18915 \family roman
18916 \series medium
18917 \shape up
18918 \size normal
18919 \emph off
18920 \bar no
18921 \noun off
18922 \color none
18923 _long2fs.c
18924 \end_layout
18925
18926 \end_inset
18927 </cell>
18928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18929 \begin_inset Text
18930
18931 \begin_layout Standard
18932
18933 \family roman
18934 \series medium
18935 \shape up
18936 \size normal
18937 \emph off
18938 \bar no
18939 \noun off
18940 \color none
18941 convert long to floating point number
18942 \end_layout
18943
18944 \end_inset
18945 </cell>
18946 </row>
18947 </lyxtabular>
18948
18949 \end_inset
18950
18951
18952 \newline
18953
18954 \end_layout
18955
18956 \begin_layout Standard
18957 These support routines are developed in ANSI-C so there is room for space
18958  and speed improvement
18959 \begin_inset Foot
18960 status open
18961
18962 \begin_layout Standard
18963 These floating point routines (
18964 \emph on
18965 not
18966 \emph default
18967  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18968  
18969 \end_layout
18970
18971 \end_inset
18972
18973 .
18974  Note if all these routines are used simultaneously the data space might
18975  overflow.
18976  For serious floating point usage the large model might be needed.
18977  Also notice that you don't have to call this routines directly.
18978  The compiler will use them automatically every time a floating point operation
18979  is required.
18980 \begin_inset VSpace bigskip
18981 \end_inset
18982
18983
18984 \end_layout
18985
18986 \begin_layout Section
18987 Library Routines
18988 \begin_inset LatexCommand \index{Libraries}
18989
18990 \end_inset
18991
18992
18993 \end_layout
18994
18995 \begin_layout Standard
18996
18997 \emph on
18998 <pending: this is messy and incomplete - a little more information is in
18999  sdcc/doc/libdoc.txt
19000 \emph default
19001  >
19002 \end_layout
19003
19004 \begin_layout Subsection
19005 Compiler support routines (_gptrget, _mulint etc.)
19006 \end_layout
19007
19008 \begin_layout Subsection
19009 Stdclib functions (puts, printf, strcat etc.)
19010 \end_layout
19011
19012 \begin_layout Subsubsection
19013 <stdio.h>
19014 \end_layout
19015
19016 \begin_layout Paragraph
19017 getchar(), putchar()
19018 \end_layout
19019
19020 \begin_layout Standard
19021 \begin_inset LatexCommand \index{<stdio.h>}
19022
19023 \end_inset
19024
19025 As usual on embedded systems you have to provide your own 
19026 \family typewriter
19027 getchar()
19028 \begin_inset LatexCommand \index{getchar()}
19029
19030 \end_inset
19031
19032  
19033 \family default
19034 and 
19035 \family typewriter
19036 putchar()
19037 \begin_inset LatexCommand \index{putchar()}
19038
19039 \end_inset
19040
19041
19042 \family default
19043  routines.
19044  SDCC does not know whether the system connects to a serial line with or
19045  without handshake, LCD, keyboard or other device.
19046  And whether a 
19047 \family typewriter
19048 lf
19049 \family default
19050  to 
19051 \family typewriter
19052 crlf
19053 \family default
19054  conversion within 
19055 \family typewriter
19056 putchar()
19057 \family default
19058  is intended.
19059  You'll find examples for serial routines f.e.
19060  in sdcc/device/lib.
19061  For the mcs51 this minimalistic polling 
19062 \family typewriter
19063 putchar()
19064 \family default
19065  routine might be a start:
19066 \end_layout
19067
19068 \begin_layout Verse
19069
19070 \family typewriter
19071 void putchar (char c) { 
19072 \newline
19073 \InsetSpace ~
19074 \InsetSpace ~
19075 \InsetSpace ~
19076 \InsetSpace ~
19077 while (!TI)\InsetSpace ~
19078 \InsetSpace ~
19079 \InsetSpace ~
19080  /* assumes UART is initialized */
19081 \newline
19082 \InsetSpace ~
19083 \InsetSpace ~
19084 \InsetSpace ~
19085 \InsetSpace ~
19086 \InsetSpace ~
19087 \InsetSpace ~
19088 \InsetSpace ~
19089 \InsetSpace ~
19090 ;
19091 \newline
19092 \InsetSpace ~
19093 \InsetSpace ~
19094 \InsetSpace ~
19095 \InsetSpace ~
19096 TI
19097  = 0;
19098 \newline
19099 \InsetSpace ~
19100 \InsetSpace ~
19101 \InsetSpace ~
19102 \InsetSpace ~
19103 SBUF = c;
19104 \newline
19105 }
19106 \end_layout
19107
19108 \begin_layout Paragraph
19109 printf()
19110 \end_layout
19111
19112 \begin_layout Standard
19113 The default
19114 \family typewriter
19115  printf()
19116 \begin_inset LatexCommand \index{printf()}
19117
19118 \end_inset
19119
19120
19121 \family default
19122  implementation in
19123 \family typewriter
19124  printf_large.c
19125 \family default
19126  does not support float (except on ds390).
19127  To enable this recompile it with the option 
19128 \emph on
19129 -
19130 \begin_inset ERT
19131 status collapsed
19132
19133 \begin_layout Standard
19134
19135
19136 \backslash
19137 /
19138 \end_layout
19139
19140 \end_inset
19141
19142 DUSE_FLOATS=1
19143 \begin_inset LatexCommand \index{USE\_FLOATS}
19144
19145 \end_inset
19146
19147
19148 \emph default
19149  on the command line.
19150  Use
19151 \emph on
19152  -
19153 \begin_inset ERT
19154 status collapsed
19155
19156 \begin_layout Standard
19157
19158
19159 \backslash
19160 /
19161 \end_layout
19162
19163 \end_inset
19164
19165 -model-large
19166 \begin_inset LatexCommand \index{-\/-model-large}
19167
19168 \end_inset
19169
19170
19171 \emph default
19172  for the mcs51 port, since this uses a lot of memory.
19173 \end_layout
19174
19175 \begin_layout Standard
19176 If you're short on code memory you might want to use 
19177 \family typewriter
19178 printf_small()
19179 \begin_inset LatexCommand \index{printf\_small()}
19180
19181 \end_inset
19182
19183
19184 \family default
19185  
19186 \emph on
19187 instead
19188 \emph default
19189  of
19190 \family typewriter
19191  printf().
19192
19193 \family default
19194  For the mcs51 there additionally are assembly versions 
19195 \family typewriter
19196 printf_tiny()
19197 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19198
19199 \end_inset
19200
19201
19202 \family default
19203  (subset of printf using less than 270 bytes) and 
19204 \family typewriter
19205 printf_fast()
19206 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19207
19208 \end_inset
19209
19210  
19211 \family default
19212 and
19213 \family typewriter
19214  printf_fast_f()
19215 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19216
19217 \end_inset
19218
19219
19220 \family default
19221  (floating-point aware version of printf_fast) which should fit the requirements
19222  of many embedded systems (printf_fast() can be customized by unsetting
19223  #defines to 
19224 \emph on
19225 not
19226 \emph default
19227  support long variables and field widths).
19228  Be sure to use only one of these printf options within a project.
19229 \newline
19230
19231 \end_layout
19232
19233 \begin_layout Standard
19234 Feature matrix of different 
19235 \emph on
19236 printf
19237 \emph default
19238  options on mcs51.
19239 \end_layout
19240
19241 \begin_layout Standard
19242 \begin_inset Tabular
19243 <lyxtabular version="3" rows="14" columns="7">
19244 <features islongtable="true">
19245 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19246 <column alignment="center" valignment="top" leftline="true" width="0">
19247 <column alignment="center" valignment="top" leftline="true" width="12col%">
19248 <column alignment="center" valignment="top" leftline="true" width="10col%">
19249 <column alignment="center" valignment="top" leftline="true" width="0">
19250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19251 <column alignment="center" valignment="top" rightline="true" width="0">
19252 <row topline="true" bottomline="true" endhead="true">
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19254 \begin_inset Text
19255
19256 \begin_layout Standard
19257
19258 \series bold
19259 \size large
19260 mcs51
19261 \end_layout
19262
19263 \end_inset
19264 </cell>
19265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19266 \begin_inset Text
19267
19268 \begin_layout Standard
19269 printf
19270 \begin_inset LatexCommand \index{printf}
19271
19272 \end_inset
19273
19274
19275 \end_layout
19276
19277 \end_inset
19278 </cell>
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \begin_layout Standard
19283 printf 
19284 \size scriptsize
19285 USE_FLOATS=1
19286 \end_layout
19287
19288 \end_inset
19289 </cell>
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \begin_layout Standard
19294 printf_small
19295 \end_layout
19296
19297 \end_inset
19298 </cell>
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19300 \begin_inset Text
19301
19302 \begin_layout Standard
19303 printf_fast
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 printf_fast_f
19313 \end_layout
19314
19315 \end_inset
19316 </cell>
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19318 \begin_inset Text
19319
19320 \begin_layout Standard
19321 printf_tiny
19322 \end_layout
19323
19324 \end_inset
19325 </cell>
19326 </row>
19327 <row topline="true" endhead="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \begin_layout Standard
19332 filename
19333 \end_layout
19334
19335 \end_inset
19336 </cell>
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19338 \begin_inset Text
19339
19340 \begin_layout Standard
19341
19342 \size scriptsize
19343 printf_large.c
19344 \end_layout
19345
19346 \end_inset
19347 </cell>
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19349 \begin_inset Text
19350
19351 \begin_layout Standard
19352
19353 \size scriptsize
19354 printf_large.c
19355 \end_layout
19356
19357 \end_inset
19358 </cell>
19359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19360 \begin_inset Text
19361
19362 \begin_layout Standard
19363
19364 \size scriptsize
19365 printfl.c
19366 \end_layout
19367
19368 \end_inset
19369 </cell>
19370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19371 \begin_inset Text
19372
19373 \begin_layout Standard
19374
19375 \size scriptsize
19376 printf_fast.c
19377 \end_layout
19378
19379 \end_inset
19380 </cell>
19381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19382 \begin_inset Text
19383
19384 \begin_layout Standard
19385
19386 \size scriptsize
19387 printf_fast_f.c
19388 \end_layout
19389
19390 \end_inset
19391 </cell>
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19393 \begin_inset Text
19394
19395 \begin_layout Standard
19396
19397 \size scriptsize
19398 printf_tiny.c
19399 \end_layout
19400
19401 \end_inset
19402 </cell>
19403 </row>
19404 <row topline="true" endhead="true">
19405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19406 \begin_inset Text
19407
19408 \begin_layout Standard
19409 \begin_inset Quotes sld
19410 \end_inset
19411
19412 Hello World
19413 \begin_inset Quotes srd
19414 \end_inset
19415
19416  size
19417 \end_layout
19418
19419 \begin_layout Standard
19420 small / large
19421 \end_layout
19422
19423 \end_inset
19424 </cell>
19425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19426 \begin_inset Text
19427
19428 \begin_layout Standard
19429 1.7k / 2.4k
19430 \end_layout
19431
19432 \end_inset
19433 </cell>
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19435 \begin_inset Text
19436
19437 \begin_layout Standard
19438 4.3k / 5.6k
19439 \end_layout
19440
19441 \end_inset
19442 </cell>
19443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19444 \begin_inset Text
19445
19446 \begin_layout Standard
19447 1.2k / 1.8k
19448 \end_layout
19449
19450 \end_inset
19451 </cell>
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19453 \begin_inset Text
19454
19455 \begin_layout Standard
19456 1.3k / 1.3k
19457 \end_layout
19458
19459 \end_inset
19460 </cell>
19461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19462 \begin_inset Text
19463
19464 \begin_layout Standard
19465 1.9k / 1.9k
19466 \end_layout
19467
19468 \end_inset
19469 </cell>
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19471 \begin_inset Text
19472
19473 \begin_layout Standard
19474 0.44k / 0.44k
19475 \end_layout
19476
19477 \end_inset
19478 </cell>
19479 </row>
19480 <row topline="true" endhead="true">
19481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19482 \begin_inset Text
19483
19484 \begin_layout Standard
19485 code size
19486 \end_layout
19487
19488 \begin_layout Standard
19489 small / large
19490 \end_layout
19491
19492 \end_inset
19493 </cell>
19494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19495 \begin_inset Text
19496
19497 \begin_layout Standard
19498 1.4k / 2.0k
19499 \end_layout
19500
19501 \end_inset
19502 </cell>
19503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19504 \begin_inset Text
19505
19506 \begin_layout Standard
19507 2.8k / 3.7k
19508 \end_layout
19509
19510 \end_inset
19511 </cell>
19512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19513 \begin_inset Text
19514
19515 \begin_layout Standard
19516 0.45k / 0.47k (+ _ltoa)
19517 \end_layout
19518
19519 \end_inset
19520 </cell>
19521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19522 \begin_inset Text
19523
19524 \begin_layout Standard
19525 1.2k / 1.2k
19526 \end_layout
19527
19528 \end_inset
19529 </cell>
19530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19531 \begin_inset Text
19532
19533 \begin_layout Standard
19534 1.6k / 1.6k
19535 \end_layout
19536
19537 \end_inset
19538 </cell>
19539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19540 \begin_inset Text
19541
19542 \begin_layout Standard
19543 0.26k / 0.26k
19544 \end_layout
19545
19546 \end_inset
19547 </cell>
19548 </row>
19549 <row topline="true">
19550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19551 \begin_inset Text
19552
19553 \begin_layout Standard
19554 formats
19555 \end_layout
19556
19557 \end_inset
19558 </cell>
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19560 \begin_inset Text
19561
19562 \begin_layout Standard
19563 cdi
19564 \emph on
19565 o
19566 \emph default
19567 psux
19568 \end_layout
19569
19570 \end_inset
19571 </cell>
19572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19573 \begin_inset Text
19574
19575 \begin_layout Standard
19576
19577 \family roman
19578 \series medium
19579 \shape up
19580 \size normal
19581 \emph off
19582 \bar no
19583 \noun off
19584 \color none
19585 cd
19586 \family default
19587 \series default
19588 \shape default
19589 \size default
19590 \emph default
19591 \bar default
19592 \noun default
19593 f
19594 \family roman
19595 \series medium
19596 \shape up
19597 \size normal
19598 \emph off
19599 \bar no
19600 \noun off
19601 i
19602 \family default
19603 \series default
19604 \shape default
19605 \size default
19606 \emph on
19607 \bar default
19608 \noun default
19609 o
19610 \family roman
19611 \series medium
19612 \shape up
19613 \size normal
19614 \emph off
19615 \bar no
19616 \noun off
19617 psux
19618 \end_layout
19619
19620 \end_inset
19621 </cell>
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19623 \begin_inset Text
19624
19625 \begin_layout Standard
19626 c
19627 \family roman
19628 \series medium
19629 \shape up
19630 \size normal
19631 \emph off
19632 \bar no
19633 \noun off
19634 \color none
19635 d
19636 \family default
19637 \series default
19638 \shape default
19639 \size default
19640 \emph on
19641 \bar default
19642 \noun default
19643 o
19644 \family roman
19645 \series medium
19646 \shape up
19647 \size normal
19648 \emph off
19649 \bar no
19650 \noun off
19651 s
19652 \family default
19653 \series default
19654 \shape default
19655 \size default
19656 \emph default
19657 \bar default
19658 \noun default
19659 x
19660 \end_layout
19661
19662 \end_inset
19663 </cell>
19664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19665 \begin_inset Text
19666
19667 \begin_layout Standard
19668 cdsux
19669 \end_layout
19670
19671 \end_inset
19672 </cell>
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19674 \begin_inset Text
19675
19676 \begin_layout Standard
19677 cdfsux
19678 \end_layout
19679
19680 \end_inset
19681 </cell>
19682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19683 \begin_inset Text
19684
19685 \begin_layout Standard
19686 cdsux
19687 \end_layout
19688
19689 \end_inset
19690 </cell>
19691 </row>
19692 <row topline="true">
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19694 \begin_inset Text
19695
19696 \begin_layout Standard
19697 long (32 bit) support
19698 \end_layout
19699
19700 \end_inset
19701 </cell>
19702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19703 \begin_inset Text
19704
19705 \begin_layout Standard
19706 x
19707 \end_layout
19708
19709 \end_inset
19710 </cell>
19711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19712 \begin_inset Text
19713
19714 \begin_layout Standard
19715 x
19716 \end_layout
19717
19718 \end_inset
19719 </cell>
19720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19721 \begin_inset Text
19722
19723 \begin_layout Standard
19724 x
19725 \end_layout
19726
19727 \end_inset
19728 </cell>
19729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19730 \begin_inset Text
19731
19732 \begin_layout Standard
19733 x
19734 \end_layout
19735
19736 \end_inset
19737 </cell>
19738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19739 \begin_inset Text
19740
19741 \begin_layout Standard
19742
19743 \family roman
19744 \series medium
19745 \shape up
19746 \size normal
19747 \emph off
19748 \bar no
19749 \noun off
19750 \color none
19751 x
19752 \end_layout
19753
19754 \end_inset
19755 </cell>
19756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19757 \begin_inset Text
19758
19759 \begin_layout Standard
19760 -
19761 \end_layout
19762
19763 \end_inset
19764 </cell>
19765 </row>
19766 <row topline="true">
19767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19768 \begin_inset Text
19769
19770 \begin_layout Standard
19771 byte arguments on stack
19772 \end_layout
19773
19774 \end_inset
19775 </cell>
19776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19777 \begin_inset Text
19778
19779 \begin_layout Standard
19780 b
19781 \end_layout
19782
19783 \end_inset
19784 </cell>
19785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19786 \begin_inset Text
19787
19788 \begin_layout Standard
19789 b
19790 \end_layout
19791
19792 \end_inset
19793 </cell>
19794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19795 \begin_inset Text
19796
19797 \begin_layout Standard
19798 -
19799 \end_layout
19800
19801 \end_inset
19802 </cell>
19803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19804 \begin_inset Text
19805
19806 \begin_layout Standard
19807 -
19808 \end_layout
19809
19810 \end_inset
19811 </cell>
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19813 \begin_inset Text
19814
19815 \begin_layout Standard
19816 -
19817 \end_layout
19818
19819 \end_inset
19820 </cell>
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19822 \begin_inset Text
19823
19824 \begin_layout Standard
19825 -
19826 \end_layout
19827
19828 \end_inset
19829 </cell>
19830 </row>
19831 <row topline="true">
19832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19833 \begin_inset Text
19834
19835 \begin_layout Standard
19836 float format
19837 \begin_inset LatexCommand \index{Floating point support}
19838
19839 \end_inset
19840
19841
19842 \end_layout
19843
19844 \end_inset
19845 </cell>
19846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19847 \begin_inset Text
19848
19849 \begin_layout Standard
19850 -
19851 \end_layout
19852
19853 \end_inset
19854 </cell>
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19856 \begin_inset Text
19857
19858 \begin_layout Standard
19859 %f
19860 \end_layout
19861
19862 \end_inset
19863 </cell>
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19865 \begin_inset Text
19866
19867 \begin_layout Standard
19868 -
19869 \end_layout
19870
19871 \end_inset
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \begin_layout Standard
19877 -
19878 \end_layout
19879
19880 \end_inset
19881 </cell>
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19883 \begin_inset Text
19884
19885 \begin_layout Standard
19886 %f
19887 \begin_inset Foot
19888 status collapsed
19889
19890 \begin_layout Standard
19891 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19892 \end_layout
19893
19894 \end_inset
19895
19896
19897 \end_layout
19898
19899 \end_inset
19900 </cell>
19901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19902 \begin_inset Text
19903
19904 \begin_layout Standard
19905 -
19906 \end_layout
19907
19908 \end_inset
19909 </cell>
19910 </row>
19911 <row topline="true">
19912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19913 \begin_inset Text
19914
19915 \begin_layout Standard
19916 float formats %e %g
19917 \end_layout
19918
19919 \end_inset
19920 </cell>
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19922 \begin_inset Text
19923
19924 \begin_layout Standard
19925 -
19926 \end_layout
19927
19928 \end_inset
19929 </cell>
19930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_inset Text
19932
19933 \begin_layout Standard
19934 -
19935 \end_layout
19936
19937 \end_inset
19938 </cell>
19939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19940 \begin_inset Text
19941
19942 \begin_layout Standard
19943 -
19944 \end_layout
19945
19946 \end_inset
19947 </cell>
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \begin_layout Standard
19952 -
19953 \end_layout
19954
19955 \end_inset
19956 </cell>
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19958 \begin_inset Text
19959
19960 \begin_layout Standard
19961 -
19962 \end_layout
19963
19964 \end_inset
19965 </cell>
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19967 \begin_inset Text
19968
19969 \begin_layout Standard
19970 -
19971 \end_layout
19972
19973 \end_inset
19974 </cell>
19975 </row>
19976 <row topline="true" bottomline="true">
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19978 \begin_inset Text
19979
19980 \begin_layout Standard
19981 field width
19982 \end_layout
19983
19984 \end_inset
19985 </cell>
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19987 \begin_inset Text
19988
19989 \begin_layout Standard
19990 x
19991 \end_layout
19992
19993 \end_inset
19994 </cell>
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19996 \begin_inset Text
19997
19998 \begin_layout Standard
19999 x
20000 \end_layout
20001
20002 \end_inset
20003 </cell>
20004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20005 \begin_inset Text
20006
20007 \begin_layout Standard
20008 -
20009 \end_layout
20010
20011 \end_inset
20012 </cell>
20013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20014 \begin_inset Text
20015
20016 \begin_layout Standard
20017 x
20018 \end_layout
20019
20020 \end_inset
20021 </cell>
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20023 \begin_inset Text
20024
20025 \begin_layout Standard
20026 x
20027 \end_layout
20028
20029 \end_inset
20030 </cell>
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20032 \begin_inset Text
20033
20034 \begin_layout Standard
20035 -
20036 \end_layout
20037
20038 \end_inset
20039 </cell>
20040 </row>
20041 <row bottomline="true">
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20043 \begin_inset Text
20044
20045 \begin_layout Standard
20046 string speed
20047 \begin_inset Foot
20048 status collapsed
20049
20050 \begin_layout Standard
20051 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20052 \backslash
20053 r', '
20054 \backslash
20055 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20056 \end_layout
20057
20058 \end_inset
20059
20060 ,
20061 \end_layout
20062
20063 \begin_layout Standard
20064 small / large
20065 \end_layout
20066
20067 \end_inset
20068 </cell>
20069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20070 \begin_inset Text
20071
20072 \begin_layout Standard
20073 1.52 / 2.59 ms
20074 \end_layout
20075
20076 \end_inset
20077 </cell>
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_inset Text
20080
20081 \begin_layout Standard
20082 1.53 / 2.62 ms
20083 \end_layout
20084
20085 \end_inset
20086 </cell>
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20088 \begin_inset Text
20089
20090 \begin_layout Standard
20091 0.92 / 0.93 ms
20092 \end_layout
20093
20094 \end_inset
20095 </cell>
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20097 \begin_inset Text
20098
20099 \begin_layout Standard
20100 0.45 / 0.45 ms
20101 \end_layout
20102
20103 \end_inset
20104 </cell>
20105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20106 \begin_inset Text
20107
20108 \begin_layout Standard
20109 0.46 / 0.46 ms
20110 \end_layout
20111
20112 \end_inset
20113 </cell>
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20115 \begin_inset Text
20116
20117 \begin_layout Standard
20118 0.45 / 0.45 ms
20119 \end_layout
20120
20121 \end_inset
20122 </cell>
20123 </row>
20124 <row bottomline="true">
20125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20126 \begin_inset Text
20127
20128 \begin_layout Standard
20129 int speed
20130 \begin_inset Foot
20131 status collapsed
20132
20133 \begin_layout Standard
20134 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20135  putchar()
20136 \end_layout
20137
20138 \end_inset
20139
20140 ,
20141 \end_layout
20142
20143 \begin_layout Standard
20144 small / large
20145 \end_layout
20146
20147 \end_inset
20148 </cell>
20149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20150 \begin_inset Text
20151
20152 \begin_layout Standard
20153 3.01 / 3.61 ms
20154 \end_layout
20155
20156 \end_inset
20157 </cell>
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20159 \begin_inset Text
20160
20161 \begin_layout Standard
20162 3.01 / 3.61 ms
20163 \end_layout
20164
20165 \end_inset
20166 </cell>
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20168 \begin_inset Text
20169
20170 \begin_layout Standard
20171 3.51 / 18.13 ms
20172 \end_layout
20173
20174 \end_inset
20175 </cell>
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20177 \begin_inset Text
20178
20179 \begin_layout Standard
20180 0.22 / 0.22 ms
20181 \end_layout
20182
20183 \end_inset
20184 </cell>
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20186 \begin_inset Text
20187
20188 \begin_layout Standard
20189 0.23 / 0.23 ms
20190 \end_layout
20191
20192 \end_inset
20193 </cell>
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20195 \begin_inset Text
20196
20197 \begin_layout Standard
20198 0.25 / 0.25 ms
20199 \begin_inset Foot
20200 status collapsed
20201
20202 \begin_layout Standard
20203 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20204 \end_layout
20205
20206 \end_inset
20207
20208
20209 \end_layout
20210
20211 \end_inset
20212 </cell>
20213 </row>
20214 <row bottomline="true">
20215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20216 \begin_inset Text
20217
20218 \begin_layout Standard
20219 long speed
20220 \begin_inset Foot
20221 status collapsed
20222
20223 \begin_layout Standard
20224 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20225  empty putchar()
20226 \end_layout
20227
20228 \end_inset
20229
20230 ,
20231 \end_layout
20232
20233 \begin_layout Standard
20234 small / large
20235 \end_layout
20236
20237 \end_inset
20238 </cell>
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20240 \begin_inset Text
20241
20242 \begin_layout Standard
20243 5.37 / 6.31 ms
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 5.37 / 6.31 ms
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 8.71 / 40.65 ms
20262 \end_layout
20263
20264 \end_inset
20265 </cell>
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20267 \begin_inset Text
20268
20269 \begin_layout Standard
20270 0.40 / 0.40 ms
20271 \end_layout
20272
20273 \end_inset
20274 </cell>
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20276 \begin_inset Text
20277
20278 \begin_layout Standard
20279 0.40 / 0.40 ms
20280 \end_layout
20281
20282 \end_inset
20283 </cell>
20284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20285 \begin_inset Text
20286
20287 \begin_layout Standard
20288 -
20289 \end_layout
20290
20291 \end_inset
20292 </cell>
20293 </row>
20294 <row bottomline="true">
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20296 \begin_inset Text
20297
20298 \begin_layout Standard
20299 float speed
20300 \begin_inset Foot
20301 status collapsed
20302
20303 \begin_layout Standard
20304 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20305  empty putchar()
20306 \end_layout
20307
20308 \end_inset
20309
20310 ,
20311 \end_layout
20312
20313 \begin_layout Standard
20314 small / large
20315 \end_layout
20316
20317 \end_inset
20318 </cell>
20319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20320 \begin_inset Text
20321
20322 \begin_layout Standard
20323 -
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 7.49 / 22.47 ms
20333 \end_layout
20334
20335 \end_inset
20336 </cell>
20337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20338 \begin_inset Text
20339
20340 \begin_layout Standard
20341 -
20342 \end_layout
20343
20344 \end_inset
20345 </cell>
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20347 \begin_inset Text
20348
20349 \begin_layout Standard
20350 -
20351 \end_layout
20352
20353 \end_inset
20354 </cell>
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_inset Text
20357
20358 \begin_layout Standard
20359 1.04 / 1.04 ms
20360 \end_layout
20361
20362 \end_inset
20363 </cell>
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20365 \begin_inset Text
20366
20367 \begin_layout Standard
20368 -
20369 \end_layout
20370
20371 \end_inset
20372 </cell>
20373 </row>
20374 </lyxtabular>
20375
20376 \end_inset
20377
20378
20379 \end_layout
20380
20381 \begin_layout Subsubsection
20382 <malloc.h>
20383 \begin_inset LatexCommand \index{malloc.h}
20384
20385 \end_inset
20386
20387
20388 \end_layout
20389
20390 \begin_layout Standard
20391 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20392  using dynamic memory allocation
20393 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20394
20395 \end_inset
20396
20397  and a default heap
20398 \begin_inset LatexCommand \index{heap (malloc)}
20399
20400 \end_inset
20401
20402  space of 1024 bytes is provided for malloc to allocate memory from.
20403  If you need a different heap size you need to recompile _heap.c with the
20404  required size defined in HEAP_SIZE.
20405  It is recommended to make a copy of this file into your project directory
20406  and compile it there with:
20407 \end_layout
20408
20409 \begin_layout Verse
20410
20411 \family typewriter
20412 sdcc -c _heap.c -D HEAD_SIZE=2048
20413 \end_layout
20414
20415 \begin_layout Standard
20416 And then link it with:
20417 \end_layout
20418
20419 \begin_layout Verse
20420
20421 \family typewriter
20422 sdcc main.rel _heap.rel
20423 \end_layout
20424
20425 \begin_layout Subsection
20426 Math functions (sinf, powf, sqrtf etc.)
20427 \end_layout
20428
20429 \begin_layout Subsubsection
20430 <math.h>
20431 \end_layout
20432
20433 \begin_layout Standard
20434 See definitions in file <math.h>.
20435 \end_layout
20436
20437 \begin_layout Subsection
20438 Other libraries
20439 \end_layout
20440
20441 \begin_layout Standard
20442 Libraries
20443 \begin_inset LatexCommand \index{Libraries}
20444
20445 \end_inset
20446
20447  included in SDCC should have a license at least as liberal as the GNU Lesser
20448  General Public License
20449 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20450
20451 \end_inset
20452
20453  
20454 \emph on
20455 LGPL
20456 \emph default
20457 .
20458 \end_layout
20459
20460 \begin_layout Standard
20461 \begin_inset Note Note
20462 status collapsed
20463
20464 \begin_layout Standard
20465 license statements for the libraries are missing.
20466  sdcc/device/lib/ser_ir.c
20467 \end_layout
20468
20469 \begin_layout Standard
20470 or _decdptr f.e.
20471  come with a GPL (as opposed to LGPL) License - this will not be liberal
20472  enough for many embedded programmers.
20473 \end_layout
20474
20475 \end_inset
20476
20477
20478 \end_layout
20479
20480 \begin_layout Standard
20481 If you have ported some library or want to share experience about some code
20482  which f.e.
20483  falls into any of these categories Busses (I
20484 \begin_inset Formula $^{\textrm{2}}$
20485 \end_inset
20486
20487 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20488  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20489  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20490 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20491
20492 \end_inset
20493
20494 \InsetSpace ~
20495 would certainly like to hear about it.
20496 \end_layout
20497
20498 \begin_layout Standard
20499 Programmers coding for embedded systems are not especially famous for being
20500  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20501 e these references are very valuable.
20502  Let's help to create a climate where information is shared.
20503 \begin_inset VSpace bigskip
20504 \end_inset
20505
20506
20507 \end_layout
20508
20509 \begin_layout Section
20510 Memory Models
20511 \end_layout
20512
20513 \begin_layout Subsection
20514 MCS51 Memory Models
20515 \begin_inset LatexCommand \index{Memory model}
20516
20517 \end_inset
20518
20519
20520 \begin_inset LatexCommand \index{MCS51 memory model}
20521
20522 \end_inset
20523
20524
20525 \end_layout
20526
20527 \begin_layout Subsubsection
20528 Small, Medium and Large
20529 \end_layout
20530
20531 \begin_layout Standard
20532 SDCC allows three memory models for MCS51 code, 
20533 \shape slanted
20534 small, medium
20535 \shape default
20536  and 
20537 \shape slanted
20538 large
20539 \shape default
20540 .
20541  Modules compiled with different memory models should 
20542 \emph on
20543 never
20544 \emph default
20545  be combined together or the results would be unpredictable.
20546  The library routines supplied with the compiler are compiled as small,
20547  medium and large.
20548  The compiled library modules are contained in separate directories as small,
20549  medium and large so that you can link to the appropriate set.
20550 \end_layout
20551
20552 \begin_layout Standard
20553 When the medium or large model is used all variables declared without a
20554  storage class will be allocated into the external ram, this includes all
20555  parameters and local variables (for non-reentrant
20556 \begin_inset LatexCommand \index{reentrant}
20557
20558 \end_inset
20559
20560  functions).
20561  When the small model is used variables without storage class are allocated
20562  in the internal ram.
20563 \end_layout
20564
20565 \begin_layout Standard
20566 Judicious usage of the processor specific storage classes
20567 \begin_inset LatexCommand \index{Storage class}
20568
20569 \end_inset
20570
20571  and the 'reentrant' function type will yield much more efficient code,
20572  than using the large model.
20573  Several optimizations are disabled when the program is compiled using the
20574  large model, it is therefore recommended that the small model be used unless
20575  absolutely required.
20576 \end_layout
20577
20578 \begin_layout Subsubsection
20579 External Stack
20580 \begin_inset LatexCommand \label{sub:External-Stack}
20581
20582 \end_inset
20583
20584
20585 \begin_inset LatexCommand \index{stack}
20586
20587 \end_inset
20588
20589
20590 \begin_inset LatexCommand \index{External stack (mcs51)}
20591
20592 \end_inset
20593
20594
20595 \end_layout
20596
20597 \begin_layout Standard
20598 The external stack (-
20599 \begin_inset ERT
20600 status collapsed
20601
20602 \begin_layout Standard
20603
20604
20605 \backslash
20606 /
20607 \end_layout
20608
20609 \end_inset
20610
20611 -xstack option
20612 \begin_inset LatexCommand \index{-\/-xstack}
20613
20614 \end_inset
20615
20616 ) is located in pdata
20617 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20618
20619 \end_inset
20620
20621  memory (usually at the start of the external ram segment) and uses all
20622  unused space in pdata (max.
20623  256 bytes).
20624  When -
20625 \begin_inset ERT
20626 status collapsed
20627
20628 \begin_layout Standard
20629
20630
20631 \backslash
20632 /
20633 \end_layout
20634
20635 \end_inset
20636
20637 -xstack option is used to compile the program, the parameters and local
20638  variables
20639 \begin_inset LatexCommand \index{local variables}
20640
20641 \end_inset
20642
20643  of all reentrant functions are allocated in this area.
20644  This option is provided for programs with large stack space requirements.
20645  When used with the -
20646 \begin_inset ERT
20647 status collapsed
20648
20649 \begin_layout Standard
20650
20651
20652 \backslash
20653 /
20654 \end_layout
20655
20656 \end_inset
20657
20658 -stack-auto
20659 \begin_inset LatexCommand \index{-\/-stack-auto}
20660
20661 \end_inset
20662
20663  option, all parameters and local variables are allocated on the external
20664  stack (note: support libraries will need to be recompiled with the same
20665  options.
20666  There is a predefined target in the library makefile).
20667 \end_layout
20668
20669 \begin_layout Standard
20670 The compiler outputs the higher order address byte of the external ram segment
20671  into port P2
20672 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20673
20674 \end_inset
20675
20676  (see also section 
20677 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20678
20679 \end_inset
20680
20681 ), therefore when using the External Stack option, this port 
20682 \emph on
20683 may not
20684 \emph default
20685  be used by the application program.
20686 \end_layout
20687
20688 \begin_layout Subsection
20689 DS390 Memory Model
20690 \begin_inset LatexCommand \index{Memory model}
20691
20692 \end_inset
20693
20694
20695 \begin_inset LatexCommand \index{DS390 memory model}
20696
20697 \end_inset
20698
20699
20700 \end_layout
20701
20702 \begin_layout Standard
20703 The only model supported is Flat 24
20704 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20705
20706 \end_inset
20707
20708 .
20709  This generates code for the 24 bit contiguous addressing mode of the Dallas
20710  DS80C390 part.
20711  In this mode, up to four meg of external RAM or code space can be directly
20712  addressed.
20713  See the data sheets at www.dalsemi.com for further information on this part.
20714 \newline
20715
20716 \newline
20717 Note
20718  that the compiler does not generate any code to place the processor into
20719  24 bitmode (although 
20720 \emph on
20721 tinibios
20722 \emph default
20723  in the ds390 libraries will do that for you).
20724  If you don't use 
20725 \emph on
20726 tinibios
20727 \emph default
20728
20729 \begin_inset LatexCommand \index{Tinibios (DS390)}
20730
20731 \end_inset
20732
20733 , the boot loader or similar code must ensure that the processor is in 24
20734  bit contiguous addressing mode before calling the SDCC startup code.
20735 \newline
20736
20737 \newline
20738 Like
20739  the 
20740 \emph on
20741 -
20742 \begin_inset ERT
20743 status collapsed
20744
20745 \begin_layout Standard
20746
20747
20748 \backslash
20749 /
20750 \end_layout
20751
20752 \end_inset
20753
20754 -model-large
20755 \emph default
20756  option, variables will by default be placed into the XDATA segment.
20757  
20758 \newline
20759
20760 \newline
20761 Segments may be placed anywhere in the 4 meg address space using the usual
20762  -
20763 \begin_inset ERT
20764 status collapsed
20765
20766 \begin_layout Standard
20767
20768
20769 \backslash
20770 /
20771 \end_layout
20772
20773 \end_inset
20774
20775 -*-loc options.
20776  Note that if any segments are located above 64K, the -r flag must be passed
20777  to the linker to generate the proper segment relocations, and the Intel
20778  HEX output format must be used.
20779  The -r flag can be passed to the linker by using the option 
20780 \emph on
20781 -Wl-r
20782 \emph default
20783  on the SDCC command line.
20784  However, currently the linker can not handle code segments > 64k.
20785 \end_layout
20786
20787 \begin_layout Section
20788 Pragmas
20789 \begin_inset LatexCommand \label{sec:Pragmas}
20790
20791 \end_inset
20792
20793
20794 \begin_inset LatexCommand \index{Pragmas}
20795
20796 \end_inset
20797
20798
20799 \end_layout
20800
20801 \begin_layout Standard
20802 Pragmas are used to turn on and/or off certain compiler options.
20803  Some of them are closely related to corresponding command-line options
20804  (see section 
20805 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20806
20807 \end_inset
20808
20809 ).
20810 \newline
20811 Pragmas should be placed before and/or after a function, placing pragmas
20812  inside a function body could have unpredictable results.
20813 \newline
20814
20815 \newline
20816 SDCC supports the
20817  following #pragma directives:
20818 \end_layout
20819
20820 \begin_layout Itemize
20821
20822 \series bold
20823 save
20824 \series default
20825
20826 \begin_inset LatexCommand \index{\#pragma save}
20827
20828 \end_inset
20829
20830  - this will save most current options to the save/restore stack.
20831  See #pragma\InsetSpace ~
20832 restore.
20833 \end_layout
20834
20835 \begin_layout Itemize
20836
20837 \series bold
20838 restore
20839 \series default
20840
20841 \begin_inset LatexCommand \index{\#pragma restore}
20842
20843 \end_inset
20844
20845  - will restore saved options from the last save.
20846  saves & restores can be nested.
20847  SDCC uses a save/restore stack: save pushes current options to the stack,
20848  restore pulls current options from the stack.
20849  See #pragma\InsetSpace ~
20850 save.
20851 \newline
20852
20853 \end_layout
20854
20855 \begin_layout Itemize
20856
20857 \series bold
20858 callee_saves
20859 \series default
20860
20861 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20862
20863 \end_inset
20864
20865
20866 \begin_inset LatexCommand \index{function prologue}
20867
20868 \end_inset
20869
20870  function1[,function2[,function3...]] 
20871 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20872
20873 \end_inset
20874
20875 - The compiler by default uses a caller saves convention for register saving
20876  across function calls, however this can cause unnecessary register pushing
20877  and popping
20878 \begin_inset LatexCommand \index{push/pop}
20879
20880 \end_inset
20881
20882  when calling small functions from larger functions.
20883  This option can be used to switch off the register saving convention for
20884  the function names specified.
20885  The compiler will not save registers when calling these functions, extra
20886  code need to be manually inserted at the entry and exit for these functions
20887  to save and restore the registers used by these functions, this can SUBSTANTIAL
20888 LY reduce code and improve run time performance of the generated code.
20889  In the future the compiler (with inter procedural analysis) may be able
20890  to determine the appropriate scheme to use for each function call.
20891  If -
20892 \begin_inset ERT
20893 status collapsed
20894
20895 \begin_layout Standard
20896
20897
20898 \backslash
20899 /
20900 \end_layout
20901
20902 \end_inset
20903
20904 -callee-saves command line option is used (see page 
20905 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20906
20907 \end_inset
20908
20909 ), the function names specified in #pragma\InsetSpace ~
20910 callee_saves
20911 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20912
20913 \end_inset
20914
20915  is appended to the list of functions specified in the command line.
20916 \end_layout
20917
20918 \begin_layout Itemize
20919
20920 \series bold
20921 exclude
20922 \series default
20923
20924 \begin_inset LatexCommand \index{\#pragma exclude}
20925
20926 \end_inset
20927
20928  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20929  of pairs of push/pop
20930 \begin_inset LatexCommand \index{push/pop}
20931
20932 \end_inset
20933
20934  instructions in 
20935 \emph on
20936 I
20937 \emph default
20938 nterrupt
20939 \begin_inset LatexCommand \index{interrupt}
20940
20941 \end_inset
20942
20943  
20944 \emph on
20945 S
20946 \emph default
20947 ervice 
20948 \emph on
20949 R
20950 \emph default
20951 outines.
20952  The directive should be placed immediately before the ISR function definition
20953  and it affects ALL ISR functions following it.
20954  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20955 exclude\InsetSpace ~
20956 none
20957 \begin_inset LatexCommand \index{\#pragma exclude}
20958
20959 \end_inset
20960
20961 .
20962  See also the related keyword _naked
20963 \begin_inset LatexCommand \index{\_naked}
20964
20965 \end_inset
20966
20967
20968 \begin_inset LatexCommand \index{\_\_naked}
20969
20970 \end_inset
20971
20972 .
20973 \end_layout
20974
20975 \begin_layout Itemize
20976
20977 \series bold
20978 less_pedantic
20979 \series default
20980
20981 \begin_inset LatexCommand \index{pedantic}
20982
20983 \end_inset
20984
20985
20986 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20987
20988 \end_inset
20989
20990  
20991 \begin_inset LatexCommand \label{ite:less_pedantic}
20992
20993 \end_inset
20994
20995 - the compiler will not warn you anymore for obvious mistakes, you'r on
20996  your own now ;-( .
20997  See also the command line option -
20998 \begin_inset ERT
20999 status collapsed
21000
21001 \begin_layout Standard
21002
21003
21004 \backslash
21005 /
21006 \end_layout
21007
21008 \end_inset
21009
21010 -less-pedantic 
21011 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21012
21013 \end_inset
21014
21015 .
21016  
21017 \newline
21018 More specifically, the following warnings will be disabled: 
21019 \shape italic
21020 comparison is always [true/false] due to limited range of data type
21021 \shape default
21022  (94); 
21023 \shape italic
21024 overflow in implicit constant conversion
21025 \shape default
21026  (158); [the (in)famous] 
21027 \shape italic
21028 conditional flow changed by optimizer: so said EVELYN the modified DOG
21029 \shape default
21030  (110); 
21031 \shape italic
21032 function '[function name]' must return value
21033 \shape default
21034  (59).
21035  
21036 \newline
21037 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21038  level) are disabled, too, namely: 
21039 \shape italic
21040 constant value '[
21041 \begin_inset Note Note
21042 status collapsed
21043
21044 \begin_layout Standard
21045 dunno what comes here - this warning appears to be unused altogether
21046 \end_layout
21047
21048 \end_inset
21049
21050 ]', out of range
21051 \shape default
21052  (81); 
21053 \shape italic
21054 [left/right] shifting more than size of object changed to zero
21055 \shape default
21056  (116); 
21057 \shape italic
21058 unreachable code
21059 \shape default
21060  (126); 
21061 \shape italic
21062 integer overflow in expression
21063 \shape default
21064  (165); 
21065 \shape italic
21066 unmatched #pragma save and #pragma restore
21067 \shape default
21068  (170); 
21069 \shape italic
21070 comparison of 'signed char' with 'unsigned char' requires promotion to int
21071 \shape default
21072  (185); 
21073 \shape italic
21074 ISO C90 does not support flexible array members
21075 \shape default
21076  (187); 
21077 \shape italic
21078 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21079 nam
21080 e]':\InsetSpace ~
21081 [
21082 \begin_inset Note Note
21083 status collapsed
21084
21085 \begin_layout Standard
21086 appears to be always blank - what was supposed to be here?
21087 \end_layout
21088
21089 \end_inset
21090
21091 ]
21092 \shape default
21093  (114); 
21094 \shape italic
21095 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21096  complexity [number]
21097 \shape default
21098  (121).
21099 \end_layout
21100
21101 \begin_layout Itemize
21102
21103 \series bold
21104 disable_warning
21105 \series default
21106  <nnnn>
21107 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21108
21109 \end_inset
21110
21111  - the compiler will not warn you anymore about warning number <nnnn>.
21112  
21113 \begin_inset Note Note
21114 status open
21115
21116 \begin_layout Itemize
21117 \begin_inset Quotes sld
21118 \end_inset
21119
21120 For list of warnings and corresponding codes, see err_warn.txt
21121 \begin_inset Quotes srd
21122 \end_inset
21123
21124  This list should probably be part of the manual? See Patch #1697136 
21125 \end_layout
21126
21127 \end_inset
21128
21129 .
21130 \end_layout
21131
21132 \begin_layout Itemize
21133
21134 \series bold
21135 nogcse
21136 \series default
21137
21138 \begin_inset LatexCommand \index{\#pragma nogcse}
21139
21140 \end_inset
21141
21142  - will stop global common subexpression elimination.
21143 \end_layout
21144
21145 \begin_layout Itemize
21146
21147 \series bold
21148 noinduction
21149 \series default
21150
21151 \begin_inset LatexCommand \index{\#pragma noinduction}
21152
21153 \end_inset
21154
21155  - will stop loop induction optimizations.
21156 \end_layout
21157
21158 \begin_layout Itemize
21159
21160 \series bold
21161 noinvariant
21162 \series default
21163
21164 \begin_inset LatexCommand \index{\#pragma noinvariant}
21165
21166 \end_inset
21167
21168  - will not do loop invariant optimizations.
21169  For more details see Loop Invariants in section
21170 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21171
21172 \end_inset
21173
21174 .
21175 \end_layout
21176
21177 \begin_layout Itemize
21178
21179 \series bold
21180 noiv
21181 \series default
21182
21183 \begin_inset LatexCommand \index{\#pragma noiv}
21184
21185 \end_inset
21186
21187  - Do not generate interrupt
21188 \begin_inset LatexCommand \index{interrupt}
21189
21190 \end_inset
21191
21192  vector table
21193 \begin_inset LatexCommand \index{interrupt vector table}
21194
21195 \end_inset
21196
21197  entries for all ISR functions defined after the pragma.
21198  This is useful in cases where the interrupt vector table must be defined
21199  manually, or when there is a secondary, manually defined interrupt vector
21200  table (e.g.
21201  for the autovector feature of the Cypress EZ-USB FX2).
21202  More elegantly this can be achieved by obmitting the optional interrupt
21203  number after the interrupt keyword, see section 
21204 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21205
21206 \end_inset
21207
21208 \InsetSpace ~
21209 about interrupts.
21210 \end_layout
21211
21212 \begin_layout Itemize
21213
21214 \series bold
21215 nojtbound
21216 \series default
21217
21218 \begin_inset LatexCommand \index{\#pragma nojtbound}
21219
21220 \end_inset
21221
21222  - will not generate code for boundary value checking, when switch statements
21223  are turned into jump-tables (dangerous).
21224  For more details see section 
21225 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21226
21227 \end_inset
21228
21229 .
21230 \end_layout
21231
21232 \begin_layout Itemize
21233
21234 \series bold
21235 noloopreverse
21236 \series default
21237
21238 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21239
21240 \end_inset
21241
21242  - Will not do loop reversal optimization
21243 \end_layout
21244
21245 \begin_layout Itemize
21246
21247 \series bold
21248 nooverlay
21249 \series default
21250
21251 \begin_inset LatexCommand \index{\#pragma nooverlay}
21252
21253 \end_inset
21254
21255  - the compiler will not overlay the parameters and local variables of a
21256  function.
21257 \end_layout
21258
21259 \begin_layout Itemize
21260
21261 \series bold
21262 stackauto
21263 \series default
21264
21265 \begin_inset LatexCommand \index{\#pragma stackauto}
21266
21267 \end_inset
21268
21269 - See option -
21270 \begin_inset ERT
21271 status collapsed
21272
21273 \begin_layout Standard
21274
21275
21276 \backslash
21277 /
21278 \end_layout
21279
21280 \end_inset
21281
21282 -stack-auto
21283 \begin_inset LatexCommand \index{-\/-stack-auto}
21284
21285 \end_inset
21286
21287  and section 
21288 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21289
21290 \end_inset
21291
21292  Parameters and Local Variables.
21293 \end_layout
21294
21295 \begin_layout Itemize
21296
21297 \series bold
21298 opt_code_speed
21299 \series default
21300  
21301 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21302
21303 \end_inset
21304
21305 - The compiler will optimize code generation towards fast code, possibly
21306  at the expense of code size.
21307  Currently this has little effect.
21308 \end_layout
21309
21310 \begin_layout Itemize
21311
21312 \series bold
21313 opt_code_size
21314 \series default
21315  
21316 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21317
21318 \end_inset
21319
21320 - The compiler will optimize code generation towards compact code, possibly
21321  at the expense of code speed.
21322  Currently this has little effect.
21323 \end_layout
21324
21325 \begin_layout Itemize
21326
21327 \series bold
21328 opt_code_balanced
21329 \series default
21330  
21331 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21332
21333 \end_inset
21334
21335 - The compiler will attempt to generate code that is both compact and fast,
21336  as long as meeting one goal is not a detriment to the other (this is the
21337  default).
21338  
21339 \end_layout
21340
21341 \begin_layout Itemize
21342
21343 \series bold
21344 std_sdcc89
21345 \series default
21346  
21347 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21348
21349 \end_inset
21350
21351 - Generally follow the C89 standard, but allow SDCC features that conflict
21352  with the standard (default).
21353 \end_layout
21354
21355 \begin_layout Itemize
21356
21357 \series bold
21358 std_c89
21359 \series default
21360  
21361 \begin_inset LatexCommand \index{\#pragma std\_c89}
21362
21363 \end_inset
21364
21365 - Follow the C89 standard and disable SDCC features that conflict with the
21366  standard.
21367 \end_layout
21368
21369 \begin_layout Itemize
21370
21371 \series bold
21372 std_sdcc99
21373 \series default
21374  
21375 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21376
21377 \end_inset
21378
21379 - Generally follow the C99 standard, but allow SDCC features that conflict
21380  with the standard (incomplete support).
21381 \end_layout
21382
21383 \begin_layout Itemize
21384
21385 \series bold
21386 std_c99
21387 \series default
21388  
21389 \begin_inset LatexCommand \index{\#pragma std\_c99}
21390
21391 \end_inset
21392
21393 - Follow the C99 standard and disable SDCC features that conflict with the
21394  standard (incomplete support).
21395 \end_layout
21396
21397 \begin_layout Itemize
21398
21399 \series bold
21400 codeseg
21401 \series default
21402  <name>
21403 \begin_inset LatexCommand \index{\#pragma codeseg}
21404
21405 \end_inset
21406
21407 - Use this name (max.
21408  8 characters) for the code segment.
21409  See option -
21410 \begin_inset ERT
21411 status collapsed
21412
21413 \begin_layout Standard
21414
21415
21416 \backslash
21417 /
21418 \end_layout
21419
21420 \end_inset
21421
21422 -codeseg.
21423 \end_layout
21424
21425 \begin_layout Itemize
21426
21427 \series bold
21428 constseg
21429 \series default
21430  <name>
21431 \begin_inset LatexCommand \index{\#pragma constseg}
21432
21433 \end_inset
21434
21435 - Use this name (max.
21436  8 characters) for the const segment.
21437  See option -
21438 \begin_inset ERT
21439 status collapsed
21440
21441 \begin_layout Standard
21442
21443
21444 \backslash
21445 /
21446 \end_layout
21447
21448 \end_inset
21449
21450 -constseg.
21451 \end_layout
21452
21453 \begin_layout Standard
21454 The preprocessor SDCPP
21455 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21456
21457 \end_inset
21458
21459  supports the following #pragma directives:
21460 \end_layout
21461
21462 \begin_layout Itemize
21463
21464 \series bold
21465 pedantic_parse_number
21466 \series default
21467
21468 \begin_inset LatexCommand \index{pedantic}
21469
21470 \end_inset
21471
21472
21473 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21474
21475 \end_inset
21476
21477  (+ | -) 
21478 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21479
21480 \end_inset
21481
21482 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21483  properly and the macro LO_B(3) gets expanded.
21484  Default is off.
21485  See also the -
21486 \begin_inset ERT
21487 status collapsed
21488
21489 \begin_layout Standard
21490
21491
21492 \backslash
21493 /
21494 \end_layout
21495
21496 \end_inset
21497
21498 -pedantic-parse-number command line option 
21499 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21500
21501 \end_inset
21502
21503 .
21504  
21505 \newline
21506 Below is an example on how to use this pragma.
21507
21508 \emph on
21509  Note: this functionality is not in conformance with standard!
21510 \end_layout
21511
21512 \begin_layout Verse
21513
21514 \family typewriter
21515 #pragma pedantic_parse_number +
21516 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21517
21518 \end_inset
21519
21520
21521 \newline
21522
21523 \newline
21524 #define LO_B(x) ((x) & 0xff)
21525 \newline
21526
21527 \newline
21528 unsigned char foo(void)
21529 \newline
21530 {
21531 \newline
21532 \InsetSpace ~
21533 \InsetSpace ~
21534 \InsetSpace ~
21535 unsigned char c=0xfe-LO_B(3)
21536 ;
21537 \newline
21538
21539 \newline
21540 \InsetSpace ~
21541 \InsetSpace ~
21542 \InsetSpace ~
21543 return c;
21544 \newline
21545 }
21546 \newline
21547
21548 \end_layout
21549
21550 \begin_layout Itemize
21551
21552 \series bold
21553 preproc_asm
21554 \series default
21555
21556 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21557
21558 \end_inset
21559
21560  (+ | -) - switch _asm _endasm block preprocessing on / off.
21561  Default is on.
21562  You use this prama to define multilines of assembly code.
21563  This will prevent the preprocessor from changing the formating required
21564  by assembly code.
21565  Below is an example on how to use this pragma.
21566 \end_layout
21567
21568 \begin_layout Verse
21569
21570 \family typewriter
21571 #pragma preproc_asm -
21572 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21573
21574 \end_inset
21575
21576
21577 \newline
21578 #define MYDELAY _asm
21579 \newline
21580 \InsetSpace ~
21581 \InsetSpace ~
21582 \InsetSpace ~
21583 nop ;my assembly comment...
21584 \newline
21585 \InsetSpace ~
21586 \InsetSpace ~
21587 \InsetSpace ~
21588 nop
21589 \newline
21590 \InsetSpace ~
21591 \InsetSpace ~
21592 \InsetSpace ~
21593 nop
21594 \newline
21595 _endasm
21596 \newline
21597 #pragma preproc_asm
21598  +
21599 \newline
21600
21601 \newline
21602 void foo (void) 
21603 \newline
21604
21605 \newline
21606 \InsetSpace ~
21607 \InsetSpace ~
21608 \InsetSpace ~
21609  ...
21610  
21611 \newline
21612 \InsetSpace ~
21613 \InsetSpace ~
21614 \InsetSpace ~
21615  MYDELAY;
21616 \newline
21617 \InsetSpace ~
21618 \InsetSpace ~
21619 \InsetSpace ~
21620  ...
21621  
21622 \newline
21623
21624 \newline
21625
21626 \end_layout
21627
21628 \begin_layout Itemize
21629
21630 \series bold
21631 sdcc_hash
21632 \series default
21633
21634 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21635
21636 \end_inset
21637
21638  (+ | -) - Allow "naked" hash in macro definition, for example:
21639 \newline
21640
21641 \family typewriter
21642 #define DIR_LO(x) #(x & 0xff)
21643 \family default
21644
21645 \newline
21646 Default is off.
21647  Below is an example on how to use this pragma.
21648 \end_layout
21649
21650 \begin_layout Verse
21651
21652 \family typewriter
21653 #pragma preproc_asm +
21654 \newline
21655 #pragma sdcc_hash +
21656 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21657
21658 \end_inset
21659
21660
21661 \newline
21662
21663 \newline
21664 #define ROMCALL(x) 
21665 \backslash
21666
21667 \newline
21668 \InsetSpace ~
21669 \InsetSpace ~
21670 \InsetSpace ~
21671 mov R6_B3, #(x & 0xff) 
21672 \backslash
21673
21674 \newline
21675 \InsetSpace ~
21676 \InsetSpace ~
21677 \InsetSpace ~
21678 mov R7_B3, #((x >> 8) & 0xff) 
21679 \backslash
21680
21681 \newline
21682 \InsetSpace ~
21683 \InsetSpace ~
21684 \InsetSpace ~
21685 lcall __romcall
21686 \newline
21687
21688 \newline
21689 ...
21690 \newline
21691 _asm
21692 \newline
21693 ROMCALL(72)
21694 \newline
21695 _endasm;
21696 \newline
21697 ...
21698 \newline
21699
21700 \end_layout
21701
21702 \begin_layout Standard
21703 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21704 ons which might cause the compiler to generate extra stack and/or data space
21705  to store compiler generated temporary variables.
21706  This usually happens in large functions.
21707  Pragma directives should be used as shown in the following example, they
21708  are used to control options and optimizations for a given function.
21709  
21710 \end_layout
21711
21712 \begin_layout Verse
21713
21714 \family typewriter
21715 #pragma save
21716 \begin_inset LatexCommand \index{\#pragma save}
21717
21718 \end_inset
21719
21720  \InsetSpace ~
21721 \InsetSpace ~
21722 \InsetSpace ~
21723 \InsetSpace ~
21724 \InsetSpace ~
21725 \InsetSpace ~
21726 \InsetSpace ~
21727 /* save the current settings */ 
21728 \newline
21729 #pragma nogcse
21730 \begin_inset LatexCommand \index{\#pragma nogcse}
21731
21732 \end_inset
21733
21734  \InsetSpace ~
21735 \InsetSpace ~
21736 \InsetSpace ~
21737 \InsetSpace ~
21738 \InsetSpace ~
21739 /* turnoff global subexpression elimination */ 
21740 \newline
21741 #pragma noinduction
21742 \begin_inset LatexCommand \index{\#pragma noinduction}
21743
21744 \end_inset
21745
21746  /* turn off induction optimizations */ 
21747 \newline
21748 int foo () 
21749 \newline
21750
21751 \newline
21752 \InsetSpace ~
21753  \InsetSpace ~
21754  ...
21755  
21756 \newline
21757 \InsetSpace ~
21758  \InsetSpace ~
21759  /* large code */ 
21760 \newline
21761 \InsetSpace ~
21762  \InsetSpace ~
21763  ...
21764  
21765 \newline
21766
21767 \newline
21768 #pragma restore
21769 \begin_inset LatexCommand \index{\#pragma restore}
21770
21771 \end_inset
21772
21773  /* turn the optimizations back on */
21774 \end_layout
21775
21776 \begin_layout Standard
21777 The compiler will generate a warning message when extra space is allocated.
21778  It is strongly recommended that the save and restore pragma's be used when
21779  changing options for a function.
21780 \newline
21781
21782 \newline
21783
21784 \newline
21785
21786 \end_layout
21787
21788 \begin_layout Section
21789 Defines Created by the Compiler
21790 \end_layout
21791
21792 \begin_layout Standard
21793 The compiler creates the following #defines
21794 \begin_inset LatexCommand \index{\#defines}
21795
21796 \end_inset
21797
21798
21799 \begin_inset LatexCommand \index{Defines created by the compiler}
21800
21801 \end_inset
21802
21803 :
21804 \newline
21805
21806 \end_layout
21807
21808 \begin_layout Standard
21809 \begin_inset Tabular
21810 <lyxtabular version="3" rows="11" columns="2">
21811 <features>
21812 <column alignment="left" valignment="top" leftline="true" width="3in">
21813 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21814 <row topline="true" bottomline="true">
21815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21816 \begin_inset Text
21817
21818 \begin_layout Standard
21819
21820 \series bold
21821 #define
21822 \end_layout
21823
21824 \end_inset
21825 </cell>
21826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21827 \begin_inset Text
21828
21829 \begin_layout Standard
21830
21831 \series bold
21832 Description
21833 \end_layout
21834
21835 \end_inset
21836 </cell>
21837 </row>
21838 <row topline="true">
21839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21840 \begin_inset Text
21841
21842 \begin_layout Standard
21843 SDCC
21844 \begin_inset LatexCommand \index{SDCC}
21845
21846 \end_inset
21847
21848  
21849 \end_layout
21850
21851 \end_inset
21852 </cell>
21853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21854 \begin_inset Text
21855
21856 \begin_layout Standard
21857 Always defined.
21858  Since version 2.5.6 the version number as an int (ex.
21859  256)
21860 \end_layout
21861
21862 \end_inset
21863 </cell>
21864 </row>
21865 <row topline="true">
21866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21867 \begin_inset Text
21868
21869 \begin_layout Standard
21870 SDCC_mcs51
21871 \begin_inset LatexCommand \index{SDCC\_mcs51}
21872
21873 \end_inset
21874
21875  or SDCC_ds390
21876 \begin_inset LatexCommand \index{SDCC\_ds390}
21877
21878 \end_inset
21879
21880  or SDCC_z80
21881 \begin_inset LatexCommand \index{SDCC\_z80}
21882
21883 \end_inset
21884
21885 , etc.
21886 \end_layout
21887
21888 \end_inset
21889 </cell>
21890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21891 \begin_inset Text
21892
21893 \begin_layout Standard
21894 depending on the model used (e.g.: -mds390)
21895 \end_layout
21896
21897 \end_inset
21898 </cell>
21899 </row>
21900 <row topline="true">
21901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21902 \begin_inset Text
21903
21904 \begin_layout Standard
21905 __mcs51
21906 \begin_inset LatexCommand \index{\_\_mcs51}
21907
21908 \end_inset
21909
21910 , __ds390
21911 \begin_inset LatexCommand \index{\_\_ds390}
21912
21913 \end_inset
21914
21915 , __hc08
21916 \begin_inset LatexCommand \index{\_\_hc08}
21917
21918 \end_inset
21919
21920 , __z80
21921 \begin_inset LatexCommand \index{\_\_z80}
21922
21923 \end_inset
21924
21925 , etc
21926 \end_layout
21927
21928 \end_inset
21929 </cell>
21930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21931 \begin_inset Text
21932
21933 \begin_layout Standard
21934 depending on the model used (e.g.
21935  -mz80)
21936 \end_layout
21937
21938 \end_inset
21939 </cell>
21940 </row>
21941 <row topline="true">
21942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21943 \begin_inset Text
21944
21945 \begin_layout Standard
21946 SDCC_STACK_AUTO
21947 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21948
21949 \end_inset
21950
21951
21952 \end_layout
21953
21954 \end_inset
21955 </cell>
21956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21957 \begin_inset Text
21958
21959 \begin_layout Standard
21960 when 
21961 \emph on
21962 -
21963 \begin_inset ERT
21964 status collapsed
21965
21966 \begin_layout Standard
21967
21968
21969 \backslash
21970 /
21971 \end_layout
21972
21973 \end_inset
21974
21975 -stack-auto
21976 \emph default
21977  option is used
21978 \end_layout
21979
21980 \end_inset
21981 </cell>
21982 </row>
21983 <row topline="true">
21984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21985 \begin_inset Text
21986
21987 \begin_layout Standard
21988 SDCC_MODEL_SMALL
21989 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21990
21991 \end_inset
21992
21993
21994 \end_layout
21995
21996 \end_inset
21997 </cell>
21998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21999 \begin_inset Text
22000
22001 \begin_layout Standard
22002 when 
22003 \emph on
22004 -
22005 \begin_inset ERT
22006 status collapsed
22007
22008 \begin_layout Standard
22009
22010
22011 \backslash
22012 /
22013 \end_layout
22014
22015 \end_inset
22016
22017 -model-small
22018 \emph default
22019  is used
22020 \end_layout
22021
22022 \end_inset
22023 </cell>
22024 </row>
22025 <row topline="true">
22026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22027 \begin_inset Text
22028
22029 \begin_layout Standard
22030 SDCC_MODEL_MEDIUM
22031 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22032
22033 \end_inset
22034
22035
22036 \end_layout
22037
22038 \end_inset
22039 </cell>
22040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22041 \begin_inset Text
22042
22043 \begin_layout Standard
22044 when 
22045 \emph on
22046 -
22047 \begin_inset ERT
22048 status collapsed
22049
22050 \begin_layout Standard
22051
22052
22053 \backslash
22054 /
22055 \end_layout
22056
22057 \end_inset
22058
22059 -model-medium
22060 \emph default
22061  is used
22062 \end_layout
22063
22064 \end_inset
22065 </cell>
22066 </row>
22067 <row topline="true">
22068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22069 \begin_inset Text
22070
22071 \begin_layout Standard
22072 SDCC_MODEL_LARGE
22073 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22074
22075 \end_inset
22076
22077
22078 \end_layout
22079
22080 \end_inset
22081 </cell>
22082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22083 \begin_inset Text
22084
22085 \begin_layout Standard
22086 when 
22087 \emph on
22088 -
22089 \begin_inset ERT
22090 status collapsed
22091
22092 \begin_layout Standard
22093
22094
22095 \backslash
22096 /
22097 \end_layout
22098
22099 \end_inset
22100
22101 -model-large
22102 \emph default
22103  is used
22104 \end_layout
22105
22106 \end_inset
22107 </cell>
22108 </row>
22109 <row topline="true">
22110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22111 \begin_inset Text
22112
22113 \begin_layout Standard
22114 SDCC_USE_XSTACK
22115 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22116
22117 \end_inset
22118
22119
22120 \end_layout
22121
22122 \end_inset
22123 </cell>
22124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22125 \begin_inset Text
22126
22127 \begin_layout Standard
22128 when 
22129 \emph on
22130 -
22131 \begin_inset ERT
22132 status collapsed
22133
22134 \begin_layout Standard
22135
22136
22137 \backslash
22138 /
22139 \end_layout
22140
22141 \end_inset
22142
22143 -xstack
22144 \emph default
22145  option is used
22146 \end_layout
22147
22148 \end_inset
22149 </cell>
22150 </row>
22151 <row topline="true">
22152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22153 \begin_inset Text
22154
22155 \begin_layout Standard
22156 SDCC_STACK_TENBIT
22157 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22158
22159 \end_inset
22160
22161  
22162 \end_layout
22163
22164 \end_inset
22165 </cell>
22166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22167 \begin_inset Text
22168
22169 \begin_layout Standard
22170 when 
22171 \emph on
22172 -mds390
22173 \emph default
22174  is used
22175 \end_layout
22176
22177 \end_inset
22178 </cell>
22179 </row>
22180 <row topline="true" bottomline="true">
22181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22182 \begin_inset Text
22183
22184 \begin_layout Standard
22185 SDCC_MODEL_FLAT24
22186 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22187
22188 \end_inset
22189
22190
22191 \end_layout
22192
22193 \end_inset
22194 </cell>
22195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22196 \begin_inset Text
22197
22198 \begin_layout Standard
22199 when 
22200 \emph on
22201 -mds390
22202 \emph default
22203  is used
22204 \end_layout
22205
22206 \end_inset
22207 </cell>
22208 </row>
22209 </lyxtabular>
22210
22211 \end_inset
22212
22213
22214 \end_layout
22215
22216 \begin_layout Chapter
22217 Notes on supported Processors
22218 \end_layout
22219
22220 \begin_layout Section
22221 MCS51 variants
22222 \begin_inset LatexCommand \label{sub:MCS51-variants}
22223
22224 \end_inset
22225
22226
22227 \begin_inset LatexCommand \index{MCS51 variants}
22228
22229 \end_inset
22230
22231
22232 \end_layout
22233
22234 \begin_layout Standard
22235 MCS51 processors are available from many vendors and come in many different
22236  flavours.
22237  While they might differ considerably in respect to Special Function Registers
22238  the core MCS51 is usually not modified or is kept compatible.
22239  
22240 \end_layout
22241
22242 \begin_layout Subsection
22243 pdata access by SFR 
22244 \end_layout
22245
22246 \begin_layout Standard
22247 With the upcome of devices with internal xdata and flash memory devices
22248  using port P2
22249 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22250
22251 \end_inset
22252
22253  as dedicated I/O port is becoming more popular.
22254  Switching the high byte for pdata
22255 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22256
22257 \end_inset
22258
22259  access which was formerly done by port P2 is then achieved by a Special
22260  Function Register
22261 \begin_inset LatexCommand \index{sfr}
22262
22263 \end_inset
22264
22265 .
22266  In well-established MCS51 tradition the address of this 
22267 \emph on
22268 sfr
22269 \emph default
22270  is where the chip designers decided to put it.
22271  Needless to say that they didn't agree on a common name either.
22272  So that the startup code can correctly initialize xdata variables, you
22273  should define an sfr with the name _XPAGE
22274 \family typewriter
22275
22276 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22277
22278 \end_inset
22279
22280
22281 \family default
22282  at the appropriate location if the default, port P2, is not used for this.
22283  Some examples are:
22284 \end_layout
22285
22286 \begin_layout Verse
22287
22288 \family typewriter
22289 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22290  MPAGE */
22291 \end_layout
22292
22293 \begin_layout Verse
22294
22295 \family typewriter
22296 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22297  a.k.a.
22298  MPAGE */
22299 \end_layout
22300
22301 \begin_layout Verse
22302
22303 \family typewriter
22304 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22305  XPAGE */
22306 \end_layout
22307
22308 \begin_layout Verse
22309
22310 \family typewriter
22311 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22312  EMI0CN */
22313 \end_layout
22314
22315 \begin_layout Verse
22316
22317 \family typewriter
22318 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22319  EMI0CN */
22320 \end_layout
22321
22322 \begin_layout Standard
22323 For more exotic implementations further customizations may be needed.
22324  See section 
22325 \begin_inset LatexCommand \ref{sub:Startup-Code}
22326
22327 \end_inset
22328
22329  for other possibilities.
22330 \end_layout
22331
22332 \begin_layout Subsection
22333 Other Features available by SFR
22334 \end_layout
22335
22336 \begin_layout Standard
22337 Some MCS51 variants offer features like Double DPTR
22338 \begin_inset LatexCommand \index{DPTR}
22339
22340 \end_inset
22341
22342 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22343  These are currently not used for the MCS51 port.
22344  If you absolutely need them you can fall back to inline assembly or submit
22345  a patch to SDCC.
22346 \begin_inset VSpace bigskip
22347 \end_inset
22348
22349
22350 \end_layout
22351
22352 \begin_layout Section
22353 DS400 port
22354 \end_layout
22355
22356 \begin_layout Standard
22357 The DS80C400
22358 \begin_inset LatexCommand \index{DS80C400}
22359
22360 \end_inset
22361
22362
22363 \begin_inset LatexCommand \index{DS400}
22364
22365 \end_inset
22366
22367  microcontroller has a rich set of peripherals.
22368  In its built-in ROM library it includes functions to access some of the
22369  features, among them is a TCP stack with IP4 and IP6 support.
22370  Library headers (currently in beta status) and other files are provided
22371  at 
22372 \size footnotesize
22373
22374 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22375
22376 \end_inset
22377
22378 .
22379  
22380 \begin_inset VSpace bigskip
22381 \end_inset
22382
22383
22384 \end_layout
22385
22386 \begin_layout Section
22387 The Z80 and gbz80 port
22388 \end_layout
22389
22390 \begin_layout Standard
22391 SDCC can target both the Zilog Z80
22392 \begin_inset LatexCommand \index{Z80}
22393
22394 \end_inset
22395
22396  and the Nintendo Gameboy's Z80-like gbz80
22397 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22398
22399 \end_inset
22400
22401 .
22402  The Z80 port is passed through the same 
22403 \emph on
22404 regressions tests
22405 \begin_inset LatexCommand \index{Regression test}
22406
22407 \end_inset
22408
22409
22410 \emph default
22411  (see section 
22412 \begin_inset LatexCommand \ref{sec:Quality-control}
22413
22414 \end_inset
22415
22416 ) as the MCS51 and DS390 ports, so floating point support, support for long
22417  variables and bitfield support is fine.
22418  See mailing lists and forums about interrupt routines.
22419 \end_layout
22420
22421 \begin_layout Standard
22422 As always, the code is the authoritative reference - see z80/ralloc.c and
22423  z80/gen.c.
22424  The stack
22425 \begin_inset LatexCommand \index{Z80!stack}
22426
22427 \end_inset
22428
22429  frame is similar to that generated by the IAR Z80 compiler.
22430  IX is used as the base pointer, HL and IY are used as a temporary registers,
22431  and BC and DE are available for holding variables.
22432  Return values
22433 \begin_inset LatexCommand \index{Z80!return value}
22434
22435 \end_inset
22436
22437  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22438  bytes).
22439  The gbz80 port use the same set of registers for the return values, but
22440  in a different order of significance: E (one byte), DE (two bytes), or
22441  HLDE (four bytes).
22442 \begin_inset VSpace bigskip
22443 \end_inset
22444
22445
22446 \end_layout
22447
22448 \begin_layout Section
22449 The HC08 port
22450 \end_layout
22451
22452 \begin_layout Standard
22453 The port to the Freescale/Motorola HC08
22454 \begin_inset LatexCommand \index{HC08}
22455
22456 \end_inset
22457
22458  family has been added in October 2003, and is still undergoing some basic
22459  development.
22460  The code generator is complete, but the register allocation is still quite
22461  unoptimized.
22462  Some of the SDCC's standard C library functions have embedded non-HC08
22463  inline assembly and so are not yet usable.
22464 \end_layout
22465
22466 \begin_layout Standard
22467 The HC08 port passes the regression test suite (see section 
22468 \begin_inset LatexCommand \ref{sec:Quality-control}
22469
22470 \end_inset
22471
22472 ).
22473 \begin_inset VSpace bigskip
22474 \end_inset
22475
22476
22477 \newpage
22478
22479 \end_layout
22480
22481 \begin_layout Section
22482 The PIC14 port
22483 \end_layout
22484
22485 \begin_layout Standard
22486 The 14bit PIC
22487 \begin_inset LatexCommand \index{PIC14}
22488
22489 \end_inset
22490
22491  port still requires a major effort from the development community.
22492  However it can work for simple code.
22493  It passes its (smaller set of) regression tests
22494 \begin_inset LatexCommand \index{Regression test (PIC14)}
22495
22496 \end_inset
22497
22498  in the directory 
22499 \shape italic
22500 sdcc/src/regression
22501 \shape default
22502 .
22503 \end_layout
22504
22505 \begin_layout Subsection
22506 C code and 14bit PIC code page
22507 \begin_inset LatexCommand \index{code page (pic14)}
22508
22509 \end_inset
22510
22511  and RAM banks
22512 \begin_inset LatexCommand \index{RAM bank (pic14)}
22513
22514 \end_inset
22515
22516
22517 \end_layout
22518
22519 \begin_layout Standard
22520 The linker organizes allocation for the code page and RAM banks.
22521  It does not have intimate knowledge of the code flow.
22522  It will put all the code section of a single asm file into a single code
22523  page.
22524  In order to make use of multiple code pages, separate asm files must be
22525  used.
22526  The compiler treats all functions of a single C file as being in the same
22527  code page unless it is non static.
22528 \newline
22529
22530 \newline
22531 To get the best follow these guide lines:
22532 \end_layout
22533
22534 \begin_layout Enumerate
22535 Make local functions static, as non static functions require code page selection
22536  overhead.
22537 \end_layout
22538
22539 \begin_layout Enumerate
22540 For devices that have multiple code pages it is more efficient to use the
22541  same number of files as pages, i.e.
22542  for the 16F877 use 4 separate files and i.e.
22543  for the 16F874 use 2 separate files.
22544  This way the linker can put the code for each file into different code
22545  pages and there's less page selection overhead.
22546 \end_layout
22547
22548 \begin_layout Enumerate
22549 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22550  instruction set), use 'unsigned char' whereever possible instead of 'int'.
22551 \end_layout
22552
22553 \begin_layout Subsection
22554 Creating a device include file 
22555 \end_layout
22556
22557 \begin_layout Standard
22558 For generating a device include file
22559 \begin_inset LatexCommand \index{PIC14!Header files}
22560
22561 \end_inset
22562
22563  use the support perl script inc2h.pl kept in directory support/script.
22564 \end_layout
22565
22566 \begin_layout Subsection
22567 Interrupt code
22568 \end_layout
22569
22570 \begin_layout Standard
22571 For the interrupt function, use the keyword '__interrupt'
22572 \begin_inset LatexCommand \index{PIC14!interrupt}
22573
22574 \end_inset
22575
22576  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22577  there to avoid a syntax error - it ought to be fixed).
22578  E.g.:
22579 \end_layout
22580
22581 \begin_layout Verse
22582
22583 \family typewriter
22584 void Intr(void) __interrupt 0
22585 \newline
22586 {
22587 \newline
22588 \InsetSpace ~
22589 \InsetSpace ~
22590 T0IF = 0; /* Clear timer interrupt */
22591 \newline
22592 }
22593 \end_layout
22594
22595 \begin_layout Subsection
22596 Linking and assembling
22597 \end_layout
22598
22599 \begin_layout Standard
22600 For assembling you can use either GPUTILS'
22601 \begin_inset LatexCommand \index{gputils (pic tools)}
22602
22603 \end_inset
22604
22605  gpasm.exe or MPLAB's mpasmwin.exe.
22606  GPUTILS is available from 
22607 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22608
22609 \end_inset
22610
22611 .
22612  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22613  If you use MPLAB and an interrupt function then the linker script file
22614  vectors section will need to be enlarged to link with mplink.
22615 \newline
22616
22617 \newline
22618 Here is a 
22619 \family typewriter
22620 Makefile
22621 \family default
22622  using GPUTILS:
22623 \end_layout
22624
22625 \begin_layout Verse
22626
22627 \family typewriter
22628 .c.o:
22629 \newline
22630 \InsetSpace ~
22631 \InsetSpace ~
22632 \InsetSpace ~
22633 \InsetSpace ~
22634 \InsetSpace ~
22635 \InsetSpace ~
22636 \InsetSpace ~
22637 \InsetSpace ~
22638 sdcc -S -V -mpic14 -p16F877 $< 
22639 \newline
22640 \InsetSpace ~
22641 \InsetSpace ~
22642 \InsetSpace ~
22643 \InsetSpace ~
22644 \InsetSpace ~
22645 \InsetSpace ~
22646 \InsetSpace ~
22647 \InsetSpace ~
22648 gpasm -c $*.asm
22649 \newline
22650
22651 \newline
22652 $(PRJ).hex: $(OBJS) 
22653 \newline
22654 \InsetSpace ~
22655 \InsetSpace ~
22656 \InsetSpace ~
22657 \InsetSpace ~
22658 \InsetSpace ~
22659 \InsetSpace ~
22660 \InsetSpace ~
22661 \InsetSpace ~
22662 gplink
22663  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22664 \end_layout
22665
22666 \begin_layout Standard
22667 Here is a 
22668 \family typewriter
22669 Makefile
22670 \family default
22671  using MPLAB:
22672 \end_layout
22673
22674 \begin_layout Verse
22675
22676 \family typewriter
22677 .c.o: 
22678 \newline
22679 \InsetSpace ~
22680 \InsetSpace ~
22681 \InsetSpace ~
22682 \InsetSpace ~
22683 \InsetSpace ~
22684 \InsetSpace ~
22685 \InsetSpace ~
22686 \InsetSpace ~
22687 sdcc -S -V -mpic14 -p16F877 $< 
22688 \newline
22689 \InsetSpace ~
22690 \InsetSpace ~
22691 \InsetSpace ~
22692 \InsetSpace ~
22693 \InsetSpace ~
22694 \InsetSpace ~
22695 \InsetSpace ~
22696 \InsetSpace ~
22697 mpasmwin /q /o $*.asm
22698 \newline
22699
22700 \newline
22701 $(PRJ).hex: $(OBJS)
22702  
22703 \newline
22704 \InsetSpace ~
22705 \InsetSpace ~
22706 \InsetSpace ~
22707 \InsetSpace ~
22708 \InsetSpace ~
22709 \InsetSpace ~
22710 \InsetSpace ~
22711 \InsetSpace ~
22712 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22713 \end_layout
22714
22715 \begin_layout Standard
22716 Please note that indentations within a
22717 \family typewriter
22718  Makefile
22719 \family default
22720  have to be done with a tabulator character.
22721 \end_layout
22722
22723 \begin_layout Subsection
22724 Command-line options
22725 \end_layout
22726
22727 \begin_layout Standard
22728 Besides the switches common to all SDCC backends, the PIC14 port accepts
22729  the following options (for an updated list see sdcc -
22730 \begin_inset ERT
22731 status collapsed
22732
22733 \begin_layout Standard
22734
22735
22736 \backslash
22737 /
22738 \end_layout
22739
22740 \end_inset
22741
22742 -help):
22743 \end_layout
22744
22745 \begin_layout List
22746 \labelwidthstring 00.00.0000
22747 -
22748 \begin_inset ERT
22749 status collapsed
22750
22751 \begin_layout Standard
22752
22753
22754 \backslash
22755 /
22756 \end_layout
22757
22758 \end_inset
22759
22760 -debug-extra
22761 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22762
22763 \end_inset
22764
22765  emit debug info in assembly output
22766 \end_layout
22767
22768 \begin_layout List
22769 \labelwidthstring 00.00.0000
22770 -
22771 \begin_inset ERT
22772 status collapsed
22773
22774 \begin_layout Standard
22775
22776
22777 \backslash
22778 /
22779 \end_layout
22780
22781 \end_inset
22782
22783 -no-pcode-opt
22784 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22785
22786 \end_inset
22787
22788  disable (slightly faulty) optimization on pCode
22789 \end_layout
22790
22791 \begin_layout List
22792 \labelwidthstring 00.00.0000
22793 -
22794 \begin_inset ERT
22795 status collapsed
22796
22797 \begin_layout Standard
22798
22799
22800 \backslash
22801 /
22802 \end_layout
22803
22804 \end_inset
22805
22806 -stack-loc
22807 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22808
22809 \end_inset
22810
22811  sets the lowest address of the argument passing stack (defaults to a suitably
22812  large shared databank to reduce BANKSEL overhead)
22813 \end_layout
22814
22815 \begin_layout List
22816 \labelwidthstring 00.00.0000
22817 -
22818 \begin_inset ERT
22819 status collapsed
22820
22821 \begin_layout Standard
22822
22823
22824 \backslash
22825 /
22826 \end_layout
22827
22828 \end_inset
22829
22830 -stack-size
22831 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22832
22833 \end_inset
22834
22835  sets the size if the argument passing stack (default: 16, minimum: 4)
22836 \end_layout
22837
22838 \begin_layout Subsection
22839 The library
22840 \end_layout
22841
22842 \begin_layout Subsubsection
22843 error: missing definition for symbol 
22844 \begin_inset Quotes sld
22845 \end_inset
22846
22847 __gptrget1
22848 \begin_inset Quotes srd
22849 \end_inset
22850
22851
22852 \end_layout
22853
22854 \begin_layout Standard
22855 The PIC14 port uses library routines to provide more complex operations
22856  like multiplication, division/modulus and (generic) pointer dereferencing.
22857  In order to add these routines to your project, you must link with PIC14's
22858  
22859 \family typewriter
22860 libsdcc.lib
22861 \family default
22862 .
22863  For single source file projects this is done automatically, more complex
22864  projects must add 
22865 \family typewriter
22866 libsdcc.lib
22867 \family default
22868  to the linker's arguments.
22869  Make sure you also add an include path for the library (using the -I switch
22870  to the linker)!
22871 \end_layout
22872
22873 \begin_layout Subsubsection
22874 Processor mismatch in file 
22875 \begin_inset Quotes sld
22876 \end_inset
22877
22878 XXX
22879 \begin_inset Quotes srd
22880 \end_inset
22881
22882 .
22883 \end_layout
22884
22885 \begin_layout Standard
22886 This warning can usually be ignored due to the very good compatibility amongst
22887  14 bit PIC
22888 \begin_inset LatexCommand \index{PIC14}
22889
22890 \end_inset
22891
22892  devices.
22893 \end_layout
22894
22895 \begin_layout Standard
22896 You might also consider recompiling the library for your specific device
22897  by changing the ARCH=p16f877 (default target) entry in 
22898 \family typewriter
22899 device/lib/pic/Makefile.in
22900 \family default
22901  and 
22902 \family typewriter
22903 device/lib/pic/Makefile
22904 \family default
22905  to reflect your device.
22906  This might even improve performance for smaller devices as unneccesary
22907  BANKSELs migth be removed.
22908 \end_layout
22909
22910 \begin_layout Subsection
22911 Known bugs
22912 \end_layout
22913
22914 \begin_layout Subsubsection
22915 initialized data
22916 \end_layout
22917
22918 \begin_layout Standard
22919 Currently, data can only be initialized if it resides in the source file
22920  together with 
22921 \emph on
22922 main()
22923 \emph default
22924 .
22925  Data in other source files will silently 
22926 \series bold
22927 not
22928 \series default
22929  be initialized.
22930 \family typewriter
22931 \size footnotesize
22932
22933 \begin_inset Marginal
22934 status collapsed
22935
22936 \begin_layout Standard
22937
22938 \series bold
22939 \InsetSpace ~
22940 !
22941 \end_layout
22942
22943 \end_inset
22944
22945
22946 \family default
22947
22948 \newpage
22949
22950 \end_layout
22951
22952 \begin_layout Section
22953 The PIC16
22954 \begin_inset LatexCommand \index{PIC16}
22955
22956 \end_inset
22957
22958  port
22959 \end_layout
22960
22961 \begin_layout Standard
22962 The PIC16
22963 \begin_inset LatexCommand \index{PIC16}
22964
22965 \end_inset
22966
22967  port is the portion of SDCC that is responsible to produce code for the
22968  Microchip
22969 \begin_inset LatexCommand \index{Microchip}
22970
22971 \end_inset
22972
22973 (TM) microcontrollers with 16 bit core.
22974  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22975  Currently supported devices are:
22976 \end_layout
22977
22978 \begin_layout Standard
22979 \align center
22980 \begin_inset Tabular
22981 <lyxtabular version="3" rows="4" columns="6">
22982 <features>
22983 <column alignment="center" valignment="top" leftline="true" width="0">
22984 <column alignment="center" valignment="top" leftline="true" width="0">
22985 <column alignment="center" valignment="top" leftline="true" width="0">
22986 <column alignment="center" valignment="top" leftline="true" width="0">
22987 <column alignment="center" valignment="top" leftline="true" width="0">
22988 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22989 <row topline="true">
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22991 \begin_inset Text
22992
22993 \begin_layout Standard
22994 18F242
22995 \end_layout
22996
22997 \end_inset
22998 </cell>
22999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23000 \begin_inset Text
23001
23002 \begin_layout Standard
23003 18F248
23004 \end_layout
23005
23006 \end_inset
23007 </cell>
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \begin_layout Standard
23012 18F252
23013 \end_layout
23014
23015 \end_inset
23016 </cell>
23017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23018 \begin_inset Text
23019
23020 \begin_layout Standard
23021 18F258
23022 \end_layout
23023
23024 \end_inset
23025 </cell>
23026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23027 \begin_inset Text
23028
23029 \begin_layout Standard
23030 18F442
23031 \end_layout
23032
23033 \end_inset
23034 </cell>
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23036 \begin_inset Text
23037
23038 \begin_layout Standard
23039 18F448
23040 \end_layout
23041
23042 \end_inset
23043 </cell>
23044 </row>
23045 <row topline="true">
23046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23047 \begin_inset Text
23048
23049 \begin_layout Standard
23050 18F452
23051 \end_layout
23052
23053 \end_inset
23054 </cell>
23055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23056 \begin_inset Text
23057
23058 \begin_layout Standard
23059 18F458
23060 \end_layout
23061
23062 \end_inset
23063 </cell>
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \begin_layout Standard
23068 18F1220
23069 \end_layout
23070
23071 \end_inset
23072 </cell>
23073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23074 \begin_inset Text
23075
23076 \begin_layout Standard
23077 18F2220
23078 \end_layout
23079
23080 \end_inset
23081 </cell>
23082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23083 \begin_inset Text
23084
23085 \begin_layout Standard
23086 18F2550
23087 \end_layout
23088
23089 \end_inset
23090 </cell>
23091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23092 \begin_inset Text
23093
23094 \begin_layout Standard
23095 18F4331
23096 \end_layout
23097
23098 \end_inset
23099 </cell>
23100 </row>
23101 <row topline="true">
23102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23103 \begin_inset Text
23104
23105 \begin_layout Standard
23106 18F4455
23107 \end_layout
23108
23109 \end_inset
23110 </cell>
23111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23112 \begin_inset Text
23113
23114 \begin_layout Standard
23115 18F6520
23116 \end_layout
23117
23118 \end_inset
23119 </cell>
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23121 \begin_inset Text
23122
23123 \begin_layout Standard
23124 18F6620
23125 \end_layout
23126
23127 \end_inset
23128 </cell>
23129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23130 \begin_inset Text
23131
23132 \begin_layout Standard
23133 18F6680
23134 \end_layout
23135
23136 \end_inset
23137 </cell>
23138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23139 \begin_inset Text
23140
23141 \begin_layout Standard
23142 18F6720
23143 \end_layout
23144
23145 \end_inset
23146 </cell>
23147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23148 \begin_inset Text
23149
23150 \begin_layout Standard
23151 18F8520
23152 \end_layout
23153
23154 \end_inset
23155 </cell>
23156 </row>
23157 <row topline="true" bottomline="true">
23158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23159 \begin_inset Text
23160
23161 \begin_layout Standard
23162 18F8620
23163 \end_layout
23164
23165 \end_inset
23166 </cell>
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23168 \begin_inset Text
23169
23170 \begin_layout Standard
23171 18F8680
23172 \end_layout
23173
23174 \end_inset
23175 </cell>
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \begin_layout Standard
23180 18F8720
23181 \end_layout
23182
23183 \end_inset
23184 </cell>
23185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23186 \begin_inset Text
23187
23188 \begin_layout Standard
23189
23190 \end_layout
23191
23192 \end_inset
23193 </cell>
23194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23195 \begin_inset Text
23196
23197 \begin_layout Standard
23198
23199 \end_layout
23200
23201 \end_inset
23202 </cell>
23203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23204 \begin_inset Text
23205
23206 \begin_layout Standard
23207
23208 \end_layout
23209
23210 \end_inset
23211 </cell>
23212 </row>
23213 </lyxtabular>
23214
23215 \end_inset
23216
23217
23218 \end_layout
23219
23220 \begin_layout Subsection
23221 Global Options
23222 \end_layout
23223
23224 \begin_layout Standard
23225 PIC16 port supports the standard command line arguments as supposed, with
23226  the exception of certain cases that will be mentioned in the following
23227  list:
23228 \end_layout
23229
23230 \begin_layout List
23231 \labelwidthstring 00.00.0000
23232 -
23233 \begin_inset ERT
23234 status collapsed
23235
23236 \begin_layout Standard
23237
23238
23239 \backslash
23240 /
23241 \end_layout
23242
23243 \end_inset
23244
23245 -callee-saves
23246 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23247
23248 \end_inset
23249
23250  See -
23251 \begin_inset ERT
23252 status collapsed
23253
23254 \begin_layout Standard
23255
23256
23257 \backslash
23258 /
23259 \end_layout
23260
23261 \end_inset
23262
23263 -all-callee-saves
23264 \end_layout
23265
23266 \begin_layout List
23267 \labelwidthstring 00.00.0000
23268 -
23269 \begin_inset ERT
23270 status collapsed
23271
23272 \begin_layout Standard
23273
23274
23275 \backslash
23276 /
23277 \end_layout
23278
23279 \end_inset
23280
23281 -fommit-frame-pointer
23282 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23283
23284 \end_inset
23285
23286  Frame pointer will be omitted when the function uses no local variables.
23287 \end_layout
23288
23289 \begin_layout Subsection
23290 Port Specific Options
23291 \begin_inset LatexCommand \index{Options PIC16}
23292
23293 \end_inset
23294
23295
23296 \end_layout
23297
23298 \begin_layout Standard
23299 The port specific options appear after the global options in the sdcc --help
23300  output.
23301 \end_layout
23302
23303 \begin_layout Subsubsection
23304 General Options
23305 \end_layout
23306
23307 \begin_layout Standard
23308 General options enable certain port features and optimizations.
23309 \end_layout
23310
23311 \begin_layout List
23312 \labelwidthstring 00.00.0000
23313 -
23314 \begin_inset ERT
23315 status collapsed
23316
23317 \begin_layout Standard
23318
23319
23320 \backslash
23321 /
23322 \end_layout
23323
23324 \end_inset
23325
23326 -pstack-model=[model] Used in conjuction with the command above.
23327  Defines the stack model to be used, valid stack models are : 
23328 \end_layout
23329
23330 \begin_deeper
23331 \begin_layout List
23332 \labelwidthstring 00.00.0000
23333
23334 \emph on
23335 small
23336 \emph default
23337  Selects small stack model.
23338  8 bit stack and frame pointers.
23339  Supports 256 bytes stack size.
23340 \end_layout
23341
23342 \begin_layout List
23343 \labelwidthstring 00.00.0000
23344
23345 \emph on
23346 large
23347 \emph default
23348  Selects large stack model.
23349  16 bit stack and frame pointers.
23350  Supports 65536 bytes stack size.
23351 \end_layout
23352
23353 \end_deeper
23354 \begin_layout List
23355 \labelwidthstring 00.00.0000
23356 -
23357 \begin_inset ERT
23358 status collapsed
23359
23360 \begin_layout Standard
23361
23362
23363 \backslash
23364 /
23365 \end_layout
23366
23367 \end_inset
23368
23369 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23370  unitialized data variables with [kword].
23371  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23372 \end_layout
23373
23374 \begin_layout List
23375 \labelwidthstring 00.00.0000
23376 -
23377 \begin_inset ERT
23378 status collapsed
23379
23380 \begin_layout Standard
23381
23382
23383 \backslash
23384 /
23385 \end_layout
23386
23387 \end_inset
23388
23389 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23390  Useful for bootloaders.
23391 \end_layout
23392
23393 \begin_layout List
23394 \labelwidthstring 00.00.0000
23395 -
23396 \begin_inset ERT
23397 status collapsed
23398
23399 \begin_layout Standard
23400
23401
23402 \backslash
23403 /
23404 \end_layout
23405
23406 \end_inset
23407
23408 -asm= sets the full path and name of an external assembler to call.
23409 \end_layout
23410
23411 \begin_layout List
23412 \labelwidthstring 00.00.0000
23413 -
23414 \begin_inset ERT
23415 status collapsed
23416
23417 \begin_layout Standard
23418
23419
23420 \backslash
23421 /
23422 \end_layout
23423
23424 \end_inset
23425
23426 -link= sets the full path and name of an external linker to call.
23427 \end_layout
23428
23429 \begin_layout List
23430 \labelwidthstring 00.00.0000
23431 -
23432 \begin_inset ERT
23433 status collapsed
23434
23435 \begin_layout Standard
23436
23437
23438 \backslash
23439 /
23440 \end_layout
23441
23442 \end_inset
23443
23444 -mplab-comp MPLAB
23445 \begin_inset LatexCommand \index{PIC16!MPLAB}
23446
23447 \end_inset
23448
23449  compatibility option.
23450  Currently only suppresses special gpasm directives.
23451 \end_layout
23452
23453 \begin_layout Subsubsection
23454 Optimization Options
23455 \end_layout
23456
23457 \begin_layout List
23458 \labelwidthstring 00.00.0000
23459 -
23460 \begin_inset ERT
23461 status collapsed
23462
23463 \begin_layout Standard
23464
23465
23466 \backslash
23467 /
23468 \end_layout
23469
23470 \end_inset
23471
23472 -optimize-goto Try to use (conditional) BRA instead of GOTO
23473 \end_layout
23474
23475 \begin_layout List
23476 \labelwidthstring 00.00.0000
23477 -
23478 \begin_inset ERT
23479 status collapsed
23480
23481 \begin_layout Standard
23482
23483
23484 \backslash
23485 /
23486 \end_layout
23487
23488 \end_inset
23489
23490 -optimize-cmp Try to optimize some compares.
23491 \end_layout
23492
23493 \begin_layout List
23494 \labelwidthstring 00.00.0000
23495 -
23496 \begin_inset ERT
23497 status collapsed
23498
23499 \begin_layout Standard
23500
23501
23502 \backslash
23503 /
23504 \end_layout
23505
23506 \end_inset
23507
23508 -optimize-df Analyze the dataflow of the generated code and improve it.
23509 \end_layout
23510
23511 \begin_layout List
23512 \labelwidthstring 00.00.0000
23513 -
23514 \begin_inset ERT
23515 status collapsed
23516
23517 \begin_layout Standard
23518
23519
23520 \backslash
23521 /
23522 \end_layout
23523
23524 \end_inset
23525
23526 -obanksel=nn Set optimization level for inserting BANKSELs.
23527 \newline
23528
23529 \end_layout
23530
23531 \begin_deeper
23532 \begin_layout List
23533 \labelwidthstring 00.00.0000
23534 0 no optimization
23535 \end_layout
23536
23537 \begin_layout List
23538 \labelwidthstring 00.00.0000
23539 1 checks previous used register and if it is the same then does not emit
23540  BANKSEL, accounts only for labels.
23541 \end_layout
23542
23543 \begin_layout List
23544 \labelwidthstring 00.00.0000
23545 2 tries to check the location of (even different) symbols and removes BANKSELs
23546  if they are in the same bank.
23547  
23548 \newline
23549
23550 \emph on
23551 Important: There might be problems if the linker script has data sections
23552  across bank borders!
23553 \end_layout
23554
23555 \end_deeper
23556 \begin_layout Subsubsection
23557 Linking Options
23558 \end_layout
23559
23560 \begin_layout List
23561 \labelwidthstring 00.00.0000
23562 -
23563 \begin_inset ERT
23564 status collapsed
23565
23566 \begin_layout Standard
23567
23568
23569 \backslash
23570 /
23571 \end_layout
23572
23573 \end_inset
23574
23575 -nodefaultlibs do not link default libraries when linking
23576 \end_layout
23577
23578 \begin_layout List
23579 \labelwidthstring 00.00.0000
23580 -
23581 \begin_inset ERT
23582 status collapsed
23583
23584 \begin_layout Standard
23585
23586
23587 \backslash
23588 /
23589 \end_layout
23590
23591 \end_inset
23592
23593 -no-crt Don't link the default run-time modules
23594 \end_layout
23595
23596 \begin_layout List
23597 \labelwidthstring 00.00.0000
23598 -
23599 \begin_inset ERT
23600 status collapsed
23601
23602 \begin_layout Standard
23603
23604
23605 \backslash
23606 /
23607 \end_layout
23608
23609 \end_inset
23610
23611 -use-crt= Use a custom run-time module instead of the defaults.
23612 \end_layout
23613
23614 \begin_layout Subsubsection
23615 Debugging Options
23616 \end_layout
23617
23618 \begin_layout Standard
23619 Debugging options enable extra debugging information in the output files.
23620 \end_layout
23621
23622 \begin_layout List
23623 \labelwidthstring 00.00.0000
23624 -
23625 \begin_inset ERT
23626 status collapsed
23627
23628 \begin_layout Standard
23629
23630
23631 \backslash
23632 /
23633 \end_layout
23634
23635 \end_inset
23636
23637 -debug-xtra Similar to -
23638 \begin_inset ERT
23639 status collapsed
23640
23641 \begin_layout Standard
23642
23643
23644 \backslash
23645 /
23646 \end_layout
23647
23648 \end_inset
23649
23650 -debug
23651 \begin_inset LatexCommand \index{-\/-debug}
23652
23653 \end_inset
23654
23655 , but dumps more information.
23656 \end_layout
23657
23658 \begin_layout List
23659 \labelwidthstring 00.00.0000
23660 -
23661 \begin_inset ERT
23662 status collapsed
23663
23664 \begin_layout Standard
23665
23666
23667 \backslash
23668 /
23669 \end_layout
23670
23671 \end_inset
23672
23673 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23674  information.
23675  <source> is the name of the file compiled.
23676 \end_layout
23677
23678 \begin_layout List
23679 \labelwidthstring 00.00.0000
23680 -
23681 \begin_inset ERT
23682 status collapsed
23683
23684 \begin_layout Standard
23685
23686
23687 \backslash
23688 /
23689 \end_layout
23690
23691 \end_inset
23692
23693 -pcode-verbose Enable pcode debugging information in translation.
23694 \end_layout
23695
23696 \begin_layout List
23697 \labelwidthstring 00.00.0000
23698 -
23699 \begin_inset ERT
23700 status collapsed
23701
23702 \begin_layout Standard
23703
23704
23705 \backslash
23706 /
23707 \end_layout
23708
23709 \end_inset
23710
23711 -denable-peeps Force the usage of peepholes.
23712  Use with care.
23713 \end_layout
23714
23715 \begin_layout List
23716 \labelwidthstring 00.00.0000
23717 -
23718 \begin_inset ERT
23719 status collapsed
23720
23721 \begin_layout Standard
23722
23723
23724 \backslash
23725 /
23726 \end_layout
23727
23728 \end_inset
23729
23730 -gstack Trace push/pops for stack pointer overflow
23731 \end_layout
23732
23733 \begin_layout List
23734 \labelwidthstring 00.00.0000
23735 -
23736 \begin_inset ERT
23737 status collapsed
23738
23739 \begin_layout Standard
23740
23741
23742 \backslash
23743 /
23744 \end_layout
23745
23746 \end_inset
23747
23748 -call-tree dump call tree in .calltree file
23749 \end_layout
23750
23751 \begin_layout Subsection
23752 Enviromental Variables
23753 \end_layout
23754
23755 \begin_layout Standard
23756 There is a number of enviromental variables that can be used when running
23757  SDCC to enable certain optimizations or force a specific program behaviour.
23758  these variables are primarily for debugging purposes so they can be enabled/dis
23759 abled at will.
23760 \end_layout
23761
23762 \begin_layout Standard
23763 Currently there is only two such variables available:
23764 \end_layout
23765
23766 \begin_layout List
23767 \labelwidthstring 00.00.0000
23768 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23769  bitfields is optimized by directly loading FSR0 with the address of the
23770  bitfield structure.
23771  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23772  then load FSR0.
23773  This step saves data ram and code space for functions that perform heavy
23774  use of bitfields.
23775  (ie.
23776  80 bytes of code space are saved when compiling malloc.c with this option).
23777  
23778 \end_layout
23779
23780 \begin_layout List
23781 \labelwidthstring 00.00.0000
23782 NO_REG_OPT do not perform pCode registers optimization.
23783  This should be used for debugging purposes.
23784  In some where bugs in the pcode optimizer are found, users can benefit
23785  from temporarily disabling the optimizer until the bug is fixed.
23786 \end_layout
23787
23788 \begin_layout Subsection
23789 Preprocessor Macros
23790 \end_layout
23791
23792 \begin_layout Standard
23793 PIC16
23794 \begin_inset LatexCommand \index{PIC16}
23795
23796 \end_inset
23797
23798  port defines the following preprocessor macros while translating a source.
23799 \end_layout
23800
23801 \begin_layout Standard
23802 \align center
23803 \begin_inset Tabular
23804 <lyxtabular version="3" rows="6" columns="2">
23805 <features>
23806 <column alignment="center" valignment="top" leftline="true" width="0">
23807 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23808 <row topline="true" bottomline="true">
23809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23810 \begin_inset Text
23811
23812 \begin_layout Standard
23813 Macro
23814 \end_layout
23815
23816 \end_inset
23817 </cell>
23818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23819 \begin_inset Text
23820
23821 \begin_layout Standard
23822 Description
23823 \end_layout
23824
23825 \end_inset
23826 </cell>
23827 </row>
23828 <row topline="true">
23829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23830 \begin_inset Text
23831
23832 \begin_layout Standard
23833 SDCC_pic16
23834 \end_layout
23835
23836 \end_inset
23837 </cell>
23838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23839 \begin_inset Text
23840
23841 \begin_layout Standard
23842 Port identification
23843 \end_layout
23844
23845 \end_inset
23846 </cell>
23847 </row>
23848 <row topline="true">
23849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23850 \begin_inset Text
23851
23852 \begin_layout Standard
23853 _
23854 \begin_inset ERT
23855 status collapsed
23856
23857 \begin_layout Standard
23858
23859
23860 \backslash
23861 /
23862 \end_layout
23863
23864 \end_inset
23865
23866 _pic16
23867 \end_layout
23868
23869 \end_inset
23870 </cell>
23871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23872 \begin_inset Text
23873
23874 \begin_layout Standard
23875 Port identification (same as above)
23876 \end_layout
23877
23878 \end_inset
23879 </cell>
23880 </row>
23881 <row topline="true">
23882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23883 \begin_inset Text
23884
23885 \begin_layout Standard
23886 pic18fxxxx
23887 \end_layout
23888
23889 \end_inset
23890 </cell>
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23892 \begin_inset Text
23893
23894 \begin_layout Standard
23895 MCU Identification.
23896  
23897 \emph on
23898 xxxx
23899 \emph default
23900  is the microcontrol identification number, i.e.
23901  452, 6620, etc
23902 \end_layout
23903
23904 \end_inset
23905 </cell>
23906 </row>
23907 <row topline="true">
23908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23909 \begin_inset Text
23910
23911 \begin_layout Standard
23912 _
23913 \begin_inset ERT
23914 status collapsed
23915
23916 \begin_layout Standard
23917
23918
23919 \backslash
23920 /
23921 \end_layout
23922
23923 \end_inset
23924
23925 _18Fxxxx
23926 \end_layout
23927
23928 \end_inset
23929 </cell>
23930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23931 \begin_inset Text
23932
23933 \begin_layout Standard
23934 MCU Identification (same as above)
23935 \end_layout
23936
23937 \end_inset
23938 </cell>
23939 </row>
23940 <row topline="true" bottomline="true">
23941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23942 \begin_inset Text
23943
23944 \begin_layout Standard
23945 STACK_MODEL_nnn
23946 \end_layout
23947
23948 \end_inset
23949 </cell>
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23951 \begin_inset Text
23952
23953 \begin_layout Standard
23954 nnn = SMALL or LARGE respectively according to the stack model used
23955 \end_layout
23956
23957 \end_inset
23958 </cell>
23959 </row>
23960 </lyxtabular>
23961
23962 \end_inset
23963
23964
23965 \end_layout
23966
23967 \begin_layout Standard
23968 In addition the following macros are defined when calling assembler:
23969 \end_layout
23970
23971 \begin_layout Standard
23972 \align center
23973 \begin_inset Tabular
23974 <lyxtabular version="3" rows="4" columns="2">
23975 <features>
23976 <column alignment="center" valignment="top" leftline="true" width="0">
23977 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23978 <row topline="true" bottomline="true">
23979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23980 \begin_inset Text
23981
23982 \begin_layout Standard
23983 Macro
23984 \end_layout
23985
23986 \end_inset
23987 </cell>
23988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23989 \begin_inset Text
23990
23991 \begin_layout Standard
23992 Description
23993 \end_layout
23994
23995 \end_inset
23996 </cell>
23997 </row>
23998 <row topline="true">
23999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24000 \begin_inset Text
24001
24002 \begin_layout Standard
24003 __18Fxxxx
24004 \end_layout
24005
24006 \end_inset
24007 </cell>
24008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24009 \begin_inset Text
24010
24011 \begin_layout Standard
24012 MCU Identification.
24013  
24014 \emph on
24015 xxxx
24016 \emph default
24017  is the microcontrol identification number, i.e.
24018  452, 6620, etc
24019 \end_layout
24020
24021 \end_inset
24022 </cell>
24023 </row>
24024 <row topline="true">
24025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24026 \begin_inset Text
24027
24028 \begin_layout Standard
24029 SDCC_MODEL_nnn
24030 \end_layout
24031
24032 \end_inset
24033 </cell>
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24035 \begin_inset Text
24036
24037 \begin_layout Standard
24038 nnn = SMALL or LARGE respectively according to the memory model used for
24039  SDCC
24040 \end_layout
24041
24042 \end_inset
24043 </cell>
24044 </row>
24045 <row topline="true" bottomline="true">
24046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24047 \begin_inset Text
24048
24049 \begin_layout Standard
24050 STACK_MODEL_nnn
24051 \end_layout
24052
24053 \end_inset
24054 </cell>
24055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24056 \begin_inset Text
24057
24058 \begin_layout Standard
24059 nnn = SMALL or LARGE respectively according to the stack model used
24060 \end_layout
24061
24062 \end_inset
24063 </cell>
24064 </row>
24065 </lyxtabular>
24066
24067 \end_inset
24068
24069
24070 \end_layout
24071
24072 \begin_layout Subsection
24073 Directories
24074 \end_layout
24075
24076 \begin_layout Standard
24077 PIC16
24078 \begin_inset LatexCommand \index{PIC16}
24079
24080 \end_inset
24081
24082  port uses the following directories for searching header files and libraries.
24083 \end_layout
24084
24085 \begin_layout Standard
24086 \align center
24087 \begin_inset Tabular
24088 <lyxtabular version="3" rows="3" columns="4">
24089 <features>
24090 <column alignment="center" valignment="top" leftline="true" width="0">
24091 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24092 <column alignment="center" valignment="top" width="0">
24093 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24094 <row topline="true" bottomline="true">
24095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24096 \begin_inset Text
24097
24098 \begin_layout Standard
24099 Directory
24100 \end_layout
24101
24102 \end_inset
24103 </cell>
24104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24105 \begin_inset Text
24106
24107 \begin_layout Standard
24108 Description
24109 \end_layout
24110
24111 \end_inset
24112 </cell>
24113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24114 \begin_inset Text
24115
24116 \begin_layout Standard
24117 Target
24118 \end_layout
24119
24120 \end_inset
24121 </cell>
24122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24123 \begin_inset Text
24124
24125 \begin_layout Standard
24126 Command prefix
24127 \end_layout
24128
24129 \end_inset
24130 </cell>
24131 </row>
24132 <row topline="true">
24133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24134 \begin_inset Text
24135
24136 \begin_layout Standard
24137 PREFIX/sdcc/include/pic16
24138 \end_layout
24139
24140 \end_inset
24141 </cell>
24142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24143 \begin_inset Text
24144
24145 \begin_layout Standard
24146 PIC16 specific headers
24147 \end_layout
24148
24149 \end_inset
24150 </cell>
24151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24152 \begin_inset Text
24153
24154 \begin_layout Standard
24155 Compiler
24156 \end_layout
24157
24158 \end_inset
24159 </cell>
24160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24161 \begin_inset Text
24162
24163 \begin_layout Standard
24164 -I
24165 \end_layout
24166
24167 \end_inset
24168 </cell>
24169 </row>
24170 <row topline="true" bottomline="true">
24171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24172 \begin_inset Text
24173
24174 \begin_layout Standard
24175 PREFIX/sdcc/lib/pic16
24176 \end_layout
24177
24178 \end_inset
24179 </cell>
24180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24181 \begin_inset Text
24182
24183 \begin_layout Standard
24184 PIC16 specific libraries
24185 \end_layout
24186
24187 \end_inset
24188 </cell>
24189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24190 \begin_inset Text
24191
24192 \begin_layout Standard
24193 Linker
24194 \end_layout
24195
24196 \end_inset
24197 </cell>
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24199 \begin_inset Text
24200
24201 \begin_layout Standard
24202 -L
24203 \end_layout
24204
24205 \end_inset
24206 </cell>
24207 </row>
24208 </lyxtabular>
24209
24210 \end_inset
24211
24212
24213 \end_layout
24214
24215 \begin_layout Subsection
24216 Pragmas
24217 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24218
24219 \end_inset
24220
24221
24222 \end_layout
24223
24224 \begin_layout Standard
24225 PIC16
24226 \begin_inset LatexCommand \index{PIC16}
24227
24228 \end_inset
24229
24230  port currently supports the following pragmas:
24231 \end_layout
24232
24233 \begin_layout List
24234 \labelwidthstring 00.00.0000
24235 stack
24236 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24237
24238 \end_inset
24239
24240  pragma stack
24241 \begin_inset LatexCommand \index{PIC16!stack}
24242
24243 \end_inset
24244
24245  forces the code generator to initialize the stack & frame pointers at a
24246  specific address.
24247  This is an adhoc solution for cases where no STACK directive is available
24248  in the linker script or gplink is not instructed to create a stack section.
24249 \newline
24250 The
24251  stack pragma should be used only once in a project.
24252  Multiple pragmas may result in indeterminate behaviour of the program.
24253 \begin_inset Foot
24254 status open
24255
24256 \begin_layout Standard
24257 The old format (ie.
24258  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24259  cross page boundaries (or even exceed the available data RAM) and crash
24260  the program.
24261  Make sure that stack does not cross page boundaries when using the SMALL
24262  stack model.
24263 \end_layout
24264
24265 \end_inset
24266
24267
24268 \newline
24269 The format is as follows:
24270 \end_layout
24271
24272 \begin_layout LyX-Code
24273 #pragma stack bottom_address [stack_size]
24274 \end_layout
24275
24276 \begin_layout Standard
24277
24278 \emph on
24279 bottom_address
24280 \emph default
24281  is the lower bound of the stack section.
24282  The stack pointer initially will point at address (bottom_address+stack_size-1).
24283 \end_layout
24284
24285 \begin_layout LyX-Code
24286 Example:
24287 \end_layout
24288
24289 \begin_layout LyX-Code
24290
24291 \end_layout
24292
24293 \begin_layout LyX-Code
24294 /* initializes stack of 100 bytes at RAM address 0x200 */
24295 \end_layout
24296
24297 \begin_layout LyX-Code
24298 #pragma stack 0x200 100
24299 \end_layout
24300
24301 \begin_layout Standard
24302 If the stack_size field is omitted then a stack is created with the default
24303  size of 64.
24304  This size might be enough for most programs, but its not enough for operations
24305  with deep function nesting or excessive stack usage.
24306 \end_layout
24307
24308 \begin_layout List
24309 \labelwidthstring 00.00.0000
24310 code
24311 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24312
24313 \end_inset
24314
24315  place a function symbol at static FLASH address
24316 \end_layout
24317
24318 \begin_layout LyX-Code
24319 Example:
24320 \end_layout
24321
24322 \begin_layout LyX-Code
24323
24324 \end_layout
24325
24326 \begin_layout LyX-Code
24327 /* place function test_func at 0x4000 */
24328 \end_layout
24329
24330 \begin_layout LyX-Code
24331 #pragma code test_func 0x4000
24332 \end_layout
24333
24334 \begin_layout LyX-Code
24335
24336 \end_layout
24337
24338 \begin_layout List
24339 \labelwidthstring 00.00.0000
24340 library instructs the linker to use a library module.
24341 \newline
24342 Usage:
24343 \end_layout
24344
24345 \begin_layout LyX-Code
24346 #pragma library module_name
24347 \end_layout
24348
24349 \begin_layout Standard
24350
24351 \emph on
24352 module_name
24353 \emph default
24354  can be any library or object file (including its path).
24355  Note that there are four reserved keywords which have special meaning.
24356  These are:
24357 \end_layout
24358
24359 \begin_layout Standard
24360 \align center
24361 \begin_inset Tabular
24362 <lyxtabular version="3" rows="6" columns="3">
24363 <features>
24364 <column alignment="center" valignment="top" leftline="true" width="0">
24365 <column alignment="block" valignment="top" leftline="true" width="20page%">
24366 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24367 <row topline="true" bottomline="true">
24368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24369 \begin_inset Text
24370
24371 \begin_layout Standard
24372 Keyword
24373 \end_layout
24374
24375 \end_inset
24376 </cell>
24377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24378 \begin_inset Text
24379
24380 \begin_layout Standard
24381 Description
24382 \end_layout
24383
24384 \end_inset
24385 </cell>
24386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24387 \begin_inset Text
24388
24389 \begin_layout Standard
24390 Module to link
24391 \end_layout
24392
24393 \end_inset
24394 </cell>
24395 </row>
24396 <row topline="true">
24397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24398 \begin_inset Text
24399
24400 \begin_layout Standard
24401
24402 \series bold
24403 ignore
24404 \end_layout
24405
24406 \end_inset
24407 </cell>
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24409 \begin_inset Text
24410
24411 \begin_layout Standard
24412 ignore all library pragmas
24413 \end_layout
24414
24415 \end_inset
24416 </cell>
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24418 \begin_inset Text
24419
24420 \begin_layout Standard
24421
24422 \emph on
24423 (none)
24424 \end_layout
24425
24426 \end_inset
24427 </cell>
24428 </row>
24429 <row topline="true">
24430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24431 \begin_inset Text
24432
24433 \begin_layout Standard
24434
24435 \series bold
24436 c
24437 \end_layout
24438
24439 \end_inset
24440 </cell>
24441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24442 \begin_inset Text
24443
24444 \begin_layout Standard
24445 link the C library
24446 \end_layout
24447
24448 \end_inset
24449 </cell>
24450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24451 \begin_inset Text
24452
24453 \begin_layout Standard
24454
24455 \emph on
24456 libc18f
24457 \emph default
24458 .lib
24459 \end_layout
24460
24461 \end_inset
24462 </cell>
24463 </row>
24464 <row topline="true">
24465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24466 \begin_inset Text
24467
24468 \begin_layout Standard
24469
24470 \series bold
24471 math
24472 \end_layout
24473
24474 \end_inset
24475 </cell>
24476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24477 \begin_inset Text
24478
24479 \begin_layout Standard
24480 link the Math libarary
24481 \end_layout
24482
24483 \end_inset
24484 </cell>
24485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24486 \begin_inset Text
24487
24488 \begin_layout Standard
24489
24490 \emph on
24491 libm18f
24492 \emph default
24493 .lib
24494 \end_layout
24495
24496 \end_inset
24497 </cell>
24498 </row>
24499 <row topline="true">
24500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24501 \begin_inset Text
24502
24503 \begin_layout Standard
24504
24505 \series bold
24506 io
24507 \end_layout
24508
24509 \end_inset
24510 </cell>
24511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24512 \begin_inset Text
24513
24514 \begin_layout Standard
24515 link the I/O library
24516 \end_layout
24517
24518 \end_inset
24519 </cell>
24520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24521 \begin_inset Text
24522
24523 \begin_layout Standard
24524
24525 \emph on
24526 libio18f*
24527 \emph default
24528 .lib
24529 \end_layout
24530
24531 \end_inset
24532 </cell>
24533 </row>
24534 <row topline="true" bottomline="true">
24535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24536 \begin_inset Text
24537
24538 \begin_layout Standard
24539
24540 \series bold
24541 debug
24542 \end_layout
24543
24544 \end_inset
24545 </cell>
24546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24547 \begin_inset Text
24548
24549 \begin_layout Standard
24550 link the debug library
24551 \end_layout
24552
24553 \end_inset
24554 </cell>
24555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24556 \begin_inset Text
24557
24558 \begin_layout Standard
24559
24560 \emph on
24561 libdebug
24562 \emph default
24563 .lib
24564 \end_layout
24565
24566 \end_inset
24567 </cell>
24568 </row>
24569 </lyxtabular>
24570
24571 \end_inset
24572
24573
24574 \newline
24575 * is the device number, i.e.
24576  452 for PIC18F452 MCU.
24577 \end_layout
24578
24579 \begin_layout Standard
24580 This feature allows for linking with specific libraries withoug having to
24581  explicit name them in the command line.
24582  Note that the 
24583 \noun on
24584 ignore
24585 \noun default
24586  keyword will reject all modules specified by the library pragma.
24587 \end_layout
24588
24589 \begin_layout List
24590 \labelwidthstring 00.00.0000
24591 udata pragma udata instructs the compiler to emit code so that linker will
24592  place a variable at a specific memory bank
24593 \end_layout
24594
24595 \begin_layout LyX-Code
24596 Example:
24597 \end_layout
24598
24599 \begin_layout LyX-Code
24600
24601 \end_layout
24602
24603 \begin_layout LyX-Code
24604 /* places variable foo at bank2 */
24605 \end_layout
24606
24607 \begin_layout LyX-Code
24608 #pragma udata bank2 foo
24609 \end_layout
24610
24611 \begin_layout LyX-Code
24612 char foo;
24613 \end_layout
24614
24615 \begin_layout Standard
24616 In order for this pragma to work extra SECTION directives should be added
24617  in the .lkr script.
24618  In the following example a sample .lkr file is shown:
24619 \end_layout
24620
24621 \begin_layout LyX-Code
24622
24623 \end_layout
24624
24625 \begin_layout LyX-Code
24626 // Sample linker script for the PIC18F452 processor
24627 \end_layout
24628
24629 \begin_layout LyX-Code
24630 LIBPATH .
24631 \end_layout
24632
24633 \begin_layout LyX-Code
24634 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24635 \end_layout
24636
24637 \begin_layout LyX-Code
24638 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24639 \end_layout
24640
24641 \begin_layout LyX-Code
24642 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24643 \end_layout
24644
24645 \begin_layout LyX-Code
24646 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24647 \end_layout
24648
24649 \begin_layout LyX-Code
24650 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24651 \end_layout
24652
24653 \begin_layout LyX-Code
24654 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24655 \end_layout
24656
24657 \begin_layout LyX-Code
24658 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24659 \end_layout
24660
24661 \begin_layout LyX-Code
24662
24663 \end_layout
24664
24665 \begin_layout LyX-Code
24666 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24667 \end_layout
24668
24669 \begin_layout LyX-Code
24670 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24671 \end_layout
24672
24673 \begin_layout LyX-Code
24674 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24675 \end_layout
24676
24677 \begin_layout LyX-Code
24678 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24679 \end_layout
24680
24681 \begin_layout LyX-Code
24682 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24683 \end_layout
24684
24685 \begin_layout LyX-Code
24686 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24687 \end_layout
24688
24689 \begin_layout LyX-Code
24690 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24691 \end_layout
24692
24693 \begin_layout LyX-Code
24694
24695 \end_layout
24696
24697 \begin_layout LyX-Code
24698 SECTION    NAME=CONFIG     ROM=config
24699 \end_layout
24700
24701 \begin_layout LyX-Code
24702
24703 \end_layout
24704
24705 \begin_layout LyX-Code
24706 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24707 \end_layout
24708
24709 \begin_layout LyX-Code
24710 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24711 \end_layout
24712
24713 \begin_layout LyX-Code
24714 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24715 \end_layout
24716
24717 \begin_layout LyX-Code
24718 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24719 \end_layout
24720
24721 \begin_layout LyX-Code
24722 SECTION    NAME=bank4      RAM=gpr4
24723 \end_layout
24724
24725 \begin_layout LyX-Code
24726 SECTION    NAME=bank5      RAM=gpr5
24727 \end_layout
24728
24729 \begin_layout Standard
24730 The linker will recognise the section name set in the pragma statement and
24731  will position the variable at the memory bank set with the RAM field at
24732  the SECTION line in the linker script file.
24733 \end_layout
24734
24735 \begin_layout Subsection
24736 Header Files
24737 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24738
24739 \end_inset
24740
24741
24742 \end_layout
24743
24744 \begin_layout Standard
24745 There is one main header file
24746 \begin_inset LatexCommand \index{PIC16!Header files}
24747
24748 \end_inset
24749
24750  that can be included to the source files using the pic16
24751 \begin_inset LatexCommand \index{PIC16}
24752
24753 \end_inset
24754
24755  port.
24756  That file is the 
24757 \series bold
24758 pic18fregs.h
24759 \series default
24760 .
24761  This header file contains the definitions for the processor special registers,
24762  so it is necessary if the source accesses them.
24763  It can be included by adding the following line in the beginning of the
24764  file:
24765 \end_layout
24766
24767 \begin_layout LyX-Code
24768 #include <pic18fregs.h>
24769 \end_layout
24770
24771 \begin_layout Standard
24772 The specific microcontroller is selected within the pic18fregs.h automatically,
24773  so the same source can be used with a variety of devices.
24774 \end_layout
24775
24776 \begin_layout Subsection
24777 Libraries
24778 \end_layout
24779
24780 \begin_layout Standard
24781 The libraries
24782 \begin_inset LatexCommand \index{PIC16!Libraries}
24783
24784 \end_inset
24785
24786  that PIC16
24787 \begin_inset LatexCommand \index{PIC16}
24788
24789 \end_inset
24790
24791  port depends on are the microcontroller device libraries which contain
24792  the symbol definitions for the microcontroller special function registers.
24793  These libraries have the format pic18fxxxx.lib, where 
24794 \emph on
24795 xxxx
24796 \emph default
24797  is the microcontroller identification number.
24798  The specific library is selected automatically by the compiler at link
24799  stage according to the selected device.
24800 \end_layout
24801
24802 \begin_layout Standard
24803 Libraries are created with gplib which is part of the gputils package 
24804 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24805
24806 \end_inset
24807
24808 .
24809 \end_layout
24810
24811 \begin_layout Subsubsection*
24812 Building the libraries
24813 \end_layout
24814
24815 \begin_layout Standard
24816 Before using SDCC/pic16 there are some libraries that need to be compiled.
24817  This process is not done automatically by SDCC since not all users use
24818  SDCC for pic16 projects.
24819  So each user should compile the libraries separately.
24820 \end_layout
24821
24822 \begin_layout Standard
24823 The steps to compile the pic16 libraries under Linux are:
24824 \end_layout
24825
24826 \begin_layout LyX-Code
24827 cd device/lib/pic16
24828 \end_layout
24829
24830 \begin_layout LyX-Code
24831 ./configure
24832 \end_layout
24833
24834 \begin_layout LyX-Code
24835 make
24836 \end_layout
24837
24838 \begin_layout LyX-Code
24839 cd ..
24840 \end_layout
24841
24842 \begin_layout LyX-Code
24843 make model-pic16
24844 \end_layout
24845
24846 \begin_layout LyX-Code
24847 su -c 'make install'     # install the libraries, you need the root password
24848 \end_layout
24849
24850 \begin_layout Standard
24851 If you need to install the headers too, do:
24852 \end_layout
24853
24854 \begin_layout LyX-Code
24855 cd device/include
24856 \end_layout
24857
24858 \begin_layout LyX-Code
24859 su -c 'make install'     # install the headers, you need the root password
24860 \end_layout
24861
24862 \begin_layout Standard
24863 There exist a special target to build the I/O libraries.
24864  This target is not automatically build because it will build the I/O library
24865  for 
24866 \emph on
24867 every
24868 \emph default
24869  supported device.
24870  This way building will take quite a lot of time.
24871  Users are advised to edit the 
24872 \series bold
24873 device/lib/pic16/pics.build
24874 \series default
24875  file and then execute:
24876 \end_layout
24877
24878 \begin_layout LyX-Code
24879 make lib-io
24880 \end_layout
24881
24882 \begin_layout Subsection
24883 Memory Models
24884 \end_layout
24885
24886 \begin_layout Standard
24887 The following memory models are supported by the PIC16 port:
24888 \end_layout
24889
24890 \begin_layout Itemize
24891 small model
24892 \end_layout
24893
24894 \begin_layout Itemize
24895 large model
24896 \end_layout
24897
24898 \begin_layout Standard
24899 Memory model affects the default size of pointers within the source.
24900  The sizes are shown in the next table:
24901 \end_layout
24902
24903 \begin_layout Standard
24904 \align center
24905 \begin_inset Tabular
24906 <lyxtabular version="3" rows="3" columns="3">
24907 <features>
24908 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24909 <column alignment="center" valignment="top" leftline="true" width="0">
24910 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24911 <row topline="true" bottomline="true">
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24913 \begin_inset Text
24914
24915 \begin_layout Standard
24916 Pointer sizes according to memory model
24917 \end_layout
24918
24919 \end_inset
24920 </cell>
24921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24922 \begin_inset Text
24923
24924 \begin_layout Standard
24925 small model
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 large model
24935 \end_layout
24936
24937 \end_inset
24938 </cell>
24939 </row>
24940 <row topline="true" bottomline="true">
24941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24942 \begin_inset Text
24943
24944 \begin_layout Standard
24945 code pointers
24946 \end_layout
24947
24948 \end_inset
24949 </cell>
24950 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24951 \begin_inset Text
24952
24953 \begin_layout Standard
24954 16-bits
24955 \end_layout
24956
24957 \end_inset
24958 </cell>
24959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24960 \begin_inset Text
24961
24962 \begin_layout Standard
24963 24-bits
24964 \end_layout
24965
24966 \end_inset
24967 </cell>
24968 </row>
24969 <row topline="true" bottomline="true">
24970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24971 \begin_inset Text
24972
24973 \begin_layout Standard
24974 data pointers
24975 \end_layout
24976
24977 \end_inset
24978 </cell>
24979 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24980 \begin_inset Text
24981
24982 \begin_layout Standard
24983 16-bits
24984 \end_layout
24985
24986 \end_inset
24987 </cell>
24988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24989 \begin_inset Text
24990
24991 \begin_layout Standard
24992 16-bits
24993 \end_layout
24994
24995 \end_inset
24996 </cell>
24997 </row>
24998 </lyxtabular>
24999
25000 \end_inset
25001
25002
25003 \end_layout
25004
25005 \begin_layout Standard
25006 It is advisable that all sources within a project are compiled with the
25007  same memory model.
25008  If one wants to override the default memory model, this can be done by
25009  declaring a pointer as 
25010 \series bold
25011 far
25012 \series default
25013  or 
25014 \series bold
25015 near
25016 \series default
25017 .
25018  Far selects large memory model's pointers, while near selects small memory
25019  model's pointers.
25020 \end_layout
25021
25022 \begin_layout Standard
25023 The standard device libraries (see 
25024 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25025
25026 \end_inset
25027
25028 ) contain no reference to pointers, so they can be used with both memory
25029  models.
25030 \end_layout
25031
25032 \begin_layout Subsection
25033 Stack
25034 \end_layout
25035
25036 \begin_layout Standard
25037 The stack
25038 \begin_inset LatexCommand \index{PIC16!stack}
25039
25040 \end_inset
25041
25042  implementation for the PIC16 port uses two indirect registers, FSR1 and
25043  FSR2.
25044 \end_layout
25045
25046 \begin_layout List
25047 \labelwidthstring 00.00.0000
25048 FSR1 is assigned as stack pointer
25049 \end_layout
25050
25051 \begin_layout List
25052 \labelwidthstring 00.00.0000
25053 FSR2 is assigned as frame pointer
25054 \end_layout
25055
25056 \begin_layout Standard
25057 The following stack models are supported by the PIC16 port
25058 \end_layout
25059
25060 \begin_layout Itemize
25061
25062 \noun on
25063 small
25064 \noun default
25065  model
25066 \end_layout
25067
25068 \begin_layout Itemize
25069
25070 \noun on
25071 large
25072 \noun default
25073  model
25074 \end_layout
25075
25076 \begin_layout Standard
25077
25078 \noun on
25079 Small
25080 \noun default
25081  model means that only the FSRxL byte is used to access stack and frame,
25082  while 
25083 \emph on
25084 \noun on
25085 large
25086 \emph default
25087 \noun default
25088  uses both FSRxL and FSRxH registers.
25089  The following table shows the stack/frame pointers sizes according to stack
25090  model and the maximum space they can address:
25091 \end_layout
25092
25093 \begin_layout Standard
25094 \align center
25095 \begin_inset Tabular
25096 <lyxtabular version="3" rows="3" columns="3">
25097 <features>
25098 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25099 <column alignment="center" valignment="top" leftline="true" width="0">
25100 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25101 <row topline="true" bottomline="true">
25102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25103 \begin_inset Text
25104
25105 \begin_layout Standard
25106 Stack & Frame pointer sizes according to stack model
25107 \end_layout
25108
25109 \end_inset
25110 </cell>
25111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25112 \begin_inset Text
25113
25114 \begin_layout Standard
25115 small
25116 \end_layout
25117
25118 \end_inset
25119 </cell>
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25121 \begin_inset Text
25122
25123 \begin_layout Standard
25124 large
25125 \end_layout
25126
25127 \end_inset
25128 </cell>
25129 </row>
25130 <row topline="true">
25131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25132 \begin_inset Text
25133
25134 \begin_layout Standard
25135 Stack pointer FSR1
25136 \end_layout
25137
25138 \end_inset
25139 </cell>
25140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25141 \begin_inset Text
25142
25143 \begin_layout Standard
25144 8-bits
25145 \end_layout
25146
25147 \end_inset
25148 </cell>
25149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25150 \begin_inset Text
25151
25152 \begin_layout Standard
25153 16-bits
25154 \end_layout
25155
25156 \end_inset
25157 </cell>
25158 </row>
25159 <row topline="true" bottomline="true">
25160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25161 \begin_inset Text
25162
25163 \begin_layout Standard
25164 Frame pointer FSR2
25165 \end_layout
25166
25167 \end_inset
25168 </cell>
25169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25170 \begin_inset Text
25171
25172 \begin_layout Standard
25173 8-bits
25174 \end_layout
25175
25176 \end_inset
25177 </cell>
25178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25179 \begin_inset Text
25180
25181 \begin_layout Standard
25182 16-bits
25183 \end_layout
25184
25185 \end_inset
25186 </cell>
25187 </row>
25188 </lyxtabular>
25189
25190 \end_inset
25191
25192
25193 \end_layout
25194
25195 \begin_layout Standard
25196
25197 \noun on
25198 Large 
25199 \noun default
25200 stack model is currently not working properly throughout the code generator.
25201  So its use is not advised.
25202  Also there are some other points that need special care:
25203 \newline
25204
25205 \end_layout
25206
25207 \begin_layout Enumerate
25208 Do not create stack sections with size more than one physical bank (that
25209  is 256 bytes)
25210 \end_layout
25211
25212 \begin_layout Enumerate
25213 Stack sections should no cross physical bank limits (i.e.
25214  #pragma stack 0x50 0x100)
25215 \end_layout
25216
25217 \begin_layout Standard
25218 These limitations are caused by the fact that only FSRxL is modified when
25219  using SMALL stack model, so no more than 256 bytes of stack can be used.
25220  This problem will disappear after LARGE model is fully implemented.
25221 \end_layout
25222
25223 \begin_layout Subsection
25224 Functions
25225 \end_layout
25226
25227 \begin_layout Standard
25228 In addition to the standard SDCC function keywords, PIC16
25229 \begin_inset LatexCommand \index{PIC16}
25230
25231 \end_inset
25232
25233  port makes available two more:
25234 \end_layout
25235
25236 \begin_layout List
25237 \labelwidthstring 00.00.0000
25238 wparam
25239 \begin_inset LatexCommand \index{PIC16!wparam}
25240
25241 \end_inset
25242
25243  Use the WREG to pass one byte of the first function argument.
25244  This improves speed but you may not use this for functions with arguments
25245  that are called via function pointers, otherwise the first byte of the
25246  first parameter will get lost.
25247  Usage:
25248 \end_layout
25249
25250 \begin_layout LyX-Code
25251 void func_wparam(int a) wparam
25252 \end_layout
25253
25254 \begin_layout LyX-Code
25255 {
25256 \end_layout
25257
25258 \begin_layout LyX-Code
25259     /* WREG hold the lower part of a */
25260 \end_layout
25261
25262 \begin_layout LyX-Code
25263     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25264  */
25265 \end_layout
25266
25267 \begin_layout LyX-Code
25268 ...
25269 \end_layout
25270
25271 \begin_layout LyX-Code
25272 }
25273 \end_layout
25274
25275 \begin_layout List
25276 \labelwidthstring 00.00.0000
25277 shadowregs
25278 \begin_inset LatexCommand \index{PIC16!shadowregs}
25279
25280 \end_inset
25281
25282  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25283  hardware shadow registers which hold the values of WREG, STATUS and BSR
25284  registers.
25285  This can be done by adding the keyword 
25286 \emph on
25287 shadowregs
25288 \emph default
25289  before the 
25290 \emph on
25291 interrupt
25292 \emph default
25293  keyword in the function's header.
25294 \end_layout
25295
25296 \begin_layout LyX-Code
25297 void isr_shadow(void) shadowregs interrupt 1
25298 \end_layout
25299
25300 \begin_layout LyX-Code
25301 {
25302 \end_layout
25303
25304 \begin_layout LyX-Code
25305 ...
25306 \end_layout
25307
25308 \begin_layout LyX-Code
25309 }
25310 \end_layout
25311
25312 \begin_layout Standard
25313
25314 \emph on
25315 shadowregs
25316 \emph default
25317  instructs the code generator not to store/restore WREG, STATUS, BSR when
25318  entering/exiting the ISR.
25319 \end_layout
25320
25321 \begin_layout Subsection
25322 Function return values
25323 \end_layout
25324
25325 \begin_layout Standard
25326 Return values from functions are placed to the appropriate registers following
25327  a modified Microchip policy optimized for SDCC.
25328  The following table shows these registers:
25329 \end_layout
25330
25331 \begin_layout Standard
25332 \align center
25333 \begin_inset Tabular
25334 <lyxtabular version="3" rows="6" columns="2">
25335 <features>
25336 <column alignment="center" valignment="top" leftline="true" width="0">
25337 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25338 <row topline="true" bottomline="true">
25339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25340 \begin_inset Text
25341
25342 \begin_layout Standard
25343 size
25344 \end_layout
25345
25346 \end_inset
25347 </cell>
25348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25349 \begin_inset Text
25350
25351 \begin_layout Standard
25352 destination register
25353 \end_layout
25354
25355 \end_inset
25356 </cell>
25357 </row>
25358 <row topline="true">
25359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25360 \begin_inset Text
25361
25362 \begin_layout Standard
25363 8 bits
25364 \end_layout
25365
25366 \end_inset
25367 </cell>
25368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25369 \begin_inset Text
25370
25371 \begin_layout Standard
25372 WREG
25373 \end_layout
25374
25375 \end_inset
25376 </cell>
25377 </row>
25378 <row topline="true">
25379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25380 \begin_inset Text
25381
25382 \begin_layout Standard
25383 16 bits
25384 \end_layout
25385
25386 \end_inset
25387 </cell>
25388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25389 \begin_inset Text
25390
25391 \begin_layout Standard
25392 PRODL:WREG
25393 \end_layout
25394
25395 \end_inset
25396 </cell>
25397 </row>
25398 <row topline="true">
25399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25400 \begin_inset Text
25401
25402 \begin_layout Standard
25403 24 bits
25404 \end_layout
25405
25406 \end_inset
25407 </cell>
25408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25409 \begin_inset Text
25410
25411 \begin_layout Standard
25412 PRODH:PRODL:WREG
25413 \end_layout
25414
25415 \end_inset
25416 </cell>
25417 </row>
25418 <row topline="true">
25419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25420 \begin_inset Text
25421
25422 \begin_layout Standard
25423 32 bits
25424 \end_layout
25425
25426 \end_inset
25427 </cell>
25428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25429 \begin_inset Text
25430
25431 \begin_layout Standard
25432 FSR0L:PRODH:PRODL:WREG
25433 \end_layout
25434
25435 \end_inset
25436 </cell>
25437 </row>
25438 <row topline="true" bottomline="true">
25439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25440 \begin_inset Text
25441
25442 \begin_layout Standard
25443 >32 bits
25444 \end_layout
25445
25446 \end_inset
25447 </cell>
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25449 \begin_inset Text
25450
25451 \begin_layout Standard
25452 on stack, FSR0 points to the beginning
25453 \end_layout
25454
25455 \end_inset
25456 </cell>
25457 </row>
25458 </lyxtabular>
25459
25460 \end_inset
25461
25462
25463 \end_layout
25464
25465 \begin_layout Subsection
25466 Interrupts
25467 \end_layout
25468
25469 \begin_layout Standard
25470 An interrupt
25471 \begin_inset LatexCommand \index{PIC16!interrupt}
25472
25473 \end_inset
25474
25475  service routine (ISR) is declared using the 
25476 \emph on
25477 interrupt
25478 \emph default
25479  keyword.
25480 \end_layout
25481
25482 \begin_layout LyX-Code
25483 void isr(void) interrupt 
25484 \emph on
25485 n
25486 \end_layout
25487
25488 \begin_layout LyX-Code
25489 {
25490 \end_layout
25491
25492 \begin_layout LyX-Code
25493 ...
25494 \end_layout
25495
25496 \begin_layout LyX-Code
25497 }
25498 \end_layout
25499
25500 \begin_layout Standard
25501
25502 \emph on
25503 n
25504 \emph default
25505  is the interrupt number, which for PIC18F devices can be:
25506 \end_layout
25507
25508 \begin_layout Standard
25509 \align center
25510 \begin_inset Tabular
25511 <lyxtabular version="3" rows="4" columns="3">
25512 <features>
25513 <column alignment="center" valignment="top" leftline="true" width="0">
25514 <column alignment="center" valignment="top" leftline="true" width="0">
25515 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25516 <row topline="true" bottomline="true">
25517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25518 \begin_inset Text
25519
25520 \begin_layout Standard
25521
25522 \emph on
25523 n
25524 \end_layout
25525
25526 \end_inset
25527 </cell>
25528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25529 \begin_inset Text
25530
25531 \begin_layout Standard
25532 Interrupt Vector
25533 \end_layout
25534
25535 \end_inset
25536 </cell>
25537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25538 \begin_inset Text
25539
25540 \begin_layout Standard
25541 Interrupt Vector Address
25542 \end_layout
25543
25544 \end_inset
25545 </cell>
25546 </row>
25547 <row topline="true">
25548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25549 \begin_inset Text
25550
25551 \begin_layout Standard
25552 0
25553 \end_layout
25554
25555 \end_inset
25556 </cell>
25557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25558 \begin_inset Text
25559
25560 \begin_layout Standard
25561 RESET vector
25562 \end_layout
25563
25564 \end_inset
25565 </cell>
25566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25567 \begin_inset Text
25568
25569 \begin_layout Standard
25570 0x000000
25571 \end_layout
25572
25573 \end_inset
25574 </cell>
25575 </row>
25576 <row topline="true">
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25578 \begin_inset Text
25579
25580 \begin_layout Standard
25581
25582 \family roman
25583 \series medium
25584 \shape up
25585 \size normal
25586 \emph off
25587 \bar no
25588 \noun off
25589 \color none
25590 1
25591 \end_layout
25592
25593 \end_inset
25594 </cell>
25595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25596 \begin_inset Text
25597
25598 \begin_layout Standard
25599
25600 \family roman
25601 \series medium
25602 \shape up
25603 \size normal
25604 \emph off
25605 \bar no
25606 \noun off
25607 \color none
25608 HIGH priority interrupts
25609 \end_layout
25610
25611 \end_inset
25612 </cell>
25613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25614 \begin_inset Text
25615
25616 \begin_layout Standard
25617 0x000008
25618 \end_layout
25619
25620 \end_inset
25621 </cell>
25622 </row>
25623 <row topline="true" bottomline="true">
25624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25625 \begin_inset Text
25626
25627 \begin_layout Standard
25628 2
25629 \end_layout
25630
25631 \end_inset
25632 </cell>
25633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25634 \begin_inset Text
25635
25636 \begin_layout Standard
25637 LOW priority interrupts
25638 \end_layout
25639
25640 \end_inset
25641 </cell>
25642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25643 \begin_inset Text
25644
25645 \begin_layout Standard
25646 0x000018
25647 \end_layout
25648
25649 \end_inset
25650 </cell>
25651 </row>
25652 </lyxtabular>
25653
25654 \end_inset
25655
25656
25657 \end_layout
25658
25659 \begin_layout Standard
25660 When generating assembly code for ISR the code generator places a 
25661 \noun on
25662 goto 
25663 \noun default
25664 instruction at the 
25665 \emph on
25666 Interrupt Vector Address
25667 \emph default
25668  which points at the genetated ISR.
25669  This single GOTO instruction is part of an automatically generated 
25670 \emph on
25671 interrupt entry point
25672 \emph default
25673  function.
25674  The actuall ISR code is placed as normally would in the code space.
25675  Upon interrupt request, the GOTO instruction is executed which jumps to
25676  the ISR code.
25677  When declaring interrupt functions as _naked this GOTO instruction is 
25678 \series bold
25679 not
25680 \series default
25681  generated.
25682  The whole interrupt functions is therefore placed at the Interrupt Vector
25683  Address of the specific interrupt.
25684  This is not a problem for the LOW priority interrupts, but it is a problem
25685  for the RESET and the HIGH priority interrupts because code may be written
25686  at the next interrupt´s vector address and cause undeterminate program
25687  behaviour if that interrupt is raised.
25688 \begin_inset Foot
25689 status open
25690
25691 \begin_layout Standard
25692 This is not a problem when
25693 \end_layout
25694
25695 \begin_layout Enumerate
25696 this is a HIGH interrupt ISR and LOW interrupts are 
25697 \emph on
25698 disabled
25699 \emph default
25700  or not used.
25701 \end_layout
25702
25703 \begin_layout Enumerate
25704 when the ISR is small enough not to reach the next interrupt´s vector address.
25705 \end_layout
25706
25707 \end_inset
25708
25709
25710 \end_layout
25711
25712 \begin_layout Standard
25713
25714 \emph on
25715 n
25716 \emph default
25717  is possible to be omitted.
25718  This way a function is generated similar to an ISR, but it is not assigned
25719  to any interrupt.
25720 \end_layout
25721
25722 \begin_layout Standard
25723 When entering an interrupt, currently the PIC16
25724 \begin_inset LatexCommand \index{PIC16}
25725
25726 \end_inset
25727
25728  port automatically saves the following registers:
25729 \end_layout
25730
25731 \begin_layout Itemize
25732 WREG
25733 \end_layout
25734
25735 \begin_layout Itemize
25736 STATUS
25737 \end_layout
25738
25739 \begin_layout Itemize
25740 BSR
25741 \end_layout
25742
25743 \begin_layout Itemize
25744 PROD (PRODL and PRODH)
25745 \end_layout
25746
25747 \begin_layout Itemize
25748 FSR0 (FSR0L and FSR0H)
25749 \end_layout
25750
25751 \begin_layout Standard
25752 These registers are restored upon return from the interrupt routine.
25753 \begin_inset Foot
25754 status open
25755
25756 \begin_layout Standard
25757 NOTE that when the _naked attribute is specified for an interrupt routine,
25758  then NO registers are stored or restored.
25759 \end_layout
25760
25761 \end_inset
25762
25763
25764 \end_layout
25765
25766 \begin_layout Subsection
25767 Generic Pointers
25768 \end_layout
25769
25770 \begin_layout Standard
25771 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25772  There are 3 types of generic pointers currently implemented data, code
25773  and eeprom pointers.
25774  They are differentiated by the value of the 7th and 6th bits of the upper
25775  byte:
25776 \end_layout
25777
25778 \begin_layout Standard
25779 \align center
25780 \begin_inset Tabular
25781 <lyxtabular version="3" rows="5" columns="5">
25782 <features>
25783 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25784 <column alignment="center" valignment="top" width="0">
25785 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25786 <column alignment="center" valignment="top" width="0">
25787 <column alignment="left" valignment="top" rightline="true" width="0">
25788 <row topline="true" bottomline="true">
25789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25790 \begin_inset Text
25791
25792 \begin_layout Standard
25793 pointer type
25794 \end_layout
25795
25796 \end_inset
25797 </cell>
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25799 \begin_inset Text
25800
25801 \begin_layout Standard
25802 7th bit
25803 \end_layout
25804
25805 \end_inset
25806 </cell>
25807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25808 \begin_inset Text
25809
25810 \begin_layout Standard
25811 6th bit
25812 \end_layout
25813
25814 \end_inset
25815 </cell>
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25817 \begin_inset Text
25818
25819 \begin_layout Standard
25820 rest of the pointer
25821 \end_layout
25822
25823 \end_inset
25824 </cell>
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25826 \begin_inset Text
25827
25828 \begin_layout Standard
25829 description
25830 \end_layout
25831
25832 \end_inset
25833 </cell>
25834 </row>
25835 <row topline="true" bottomline="true">
25836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25837 \begin_inset Text
25838
25839 \begin_layout Standard
25840 data 
25841 \end_layout
25842
25843 \end_inset
25844 </cell>
25845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25846 \begin_inset Text
25847
25848 \begin_layout Standard
25849 1
25850 \end_layout
25851
25852 \end_inset
25853 </cell>
25854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25855 \begin_inset Text
25856
25857 \begin_layout Standard
25858 0
25859 \end_layout
25860
25861 \end_inset
25862 </cell>
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25864 \begin_inset Text
25865
25866 \begin_layout Standard
25867
25868 \family typewriter
25869 \shape slanted
25870 \emph on
25871 uuuuuu uuuuxxxx xxxxxxxx
25872 \end_layout
25873
25874 \end_inset
25875 </cell>
25876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25877 \begin_inset Text
25878
25879 \begin_layout Standard
25880 a 12-bit data pointer in data RAM memory
25881 \end_layout
25882
25883 \end_inset
25884 </cell>
25885 </row>
25886 <row bottomline="true">
25887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25888 \begin_inset Text
25889
25890 \begin_layout Standard
25891 code
25892 \end_layout
25893
25894 \end_inset
25895 </cell>
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25897 \begin_inset Text
25898
25899 \begin_layout Standard
25900 0
25901 \end_layout
25902
25903 \end_inset
25904 </cell>
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25906 \begin_inset Text
25907
25908 \begin_layout Standard
25909 0
25910 \end_layout
25911
25912 \end_inset
25913 </cell>
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25915 \begin_inset Text
25916
25917 \begin_layout Standard
25918
25919 \family typewriter
25920 \shape slanted
25921 \emph on
25922 uxxxxx xxxxxxxx xxxxxxxx
25923 \end_layout
25924
25925 \end_inset
25926 </cell>
25927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25928 \begin_inset Text
25929
25930 \begin_layout Standard
25931 a 21-bit code pointer in FLASH memory
25932 \end_layout
25933
25934 \end_inset
25935 </cell>
25936 </row>
25937 <row bottomline="true">
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25939 \begin_inset Text
25940
25941 \begin_layout Standard
25942 eeprom
25943 \end_layout
25944
25945 \end_inset
25946 </cell>
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25948 \begin_inset Text
25949
25950 \begin_layout Standard
25951 0
25952 \end_layout
25953
25954 \end_inset
25955 </cell>
25956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25957 \begin_inset Text
25958
25959 \begin_layout Standard
25960 1
25961 \end_layout
25962
25963 \end_inset
25964 </cell>
25965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25966 \begin_inset Text
25967
25968 \begin_layout Standard
25969
25970 \family typewriter
25971 \shape slanted
25972 \emph on
25973 uuuuuu uuuuuuxx xxxxxxxx
25974 \end_layout
25975
25976 \end_inset
25977 </cell>
25978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25979 \begin_inset Text
25980
25981 \begin_layout Standard
25982 a 10-bit eeprom pointer in EEPROM memory
25983 \end_layout
25984
25985 \end_inset
25986 </cell>
25987 </row>
25988 <row bottomline="true">
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25990 \begin_inset Text
25991
25992 \begin_layout Standard
25993 (unimplemented)
25994 \end_layout
25995
25996 \end_inset
25997 </cell>
25998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25999 \begin_inset Text
26000
26001 \begin_layout Standard
26002 1
26003 \end_layout
26004
26005 \end_inset
26006 </cell>
26007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26008 \begin_inset Text
26009
26010 \begin_layout Standard
26011 1
26012 \end_layout
26013
26014 \end_inset
26015 </cell>
26016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26017 \begin_inset Text
26018
26019 \begin_layout Standard
26020
26021 \family typewriter
26022 \shape slanted
26023 \emph on
26024 xxxxxx xxxxxxxx xxxxxxxx
26025 \end_layout
26026
26027 \end_inset
26028 </cell>
26029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26030 \begin_inset Text
26031
26032 \begin_layout Standard
26033 unimplemented pointer type
26034 \end_layout
26035
26036 \end_inset
26037 </cell>
26038 </row>
26039 </lyxtabular>
26040
26041 \end_inset
26042
26043
26044 \end_layout
26045
26046 \begin_layout Standard
26047 Generic pointer are read and written with a set of library functions which
26048  read/write 1, 2, 3, 4 bytes.
26049 \end_layout
26050
26051 \begin_layout Subsection
26052 PIC16 C Libraries
26053 \end_layout
26054
26055 \begin_layout Subsubsection
26056 Standard I/O Streams
26057 \end_layout
26058
26059 \begin_layout Standard
26060 In the 
26061 \emph on
26062 stdio.h
26063 \emph default
26064  the type FILE is defined as:
26065 \end_layout
26066
26067 \begin_layout LyX-Code
26068 typedef char * FILE;
26069 \end_layout
26070
26071 \begin_layout Standard
26072 This type is the stream type implemented I/O in the PIC18F devices.
26073  Also the standard input and output streams are declared in stdio.h:
26074 \end_layout
26075
26076 \begin_layout LyX-Code
26077 extern FILE * stdin;
26078 \end_layout
26079
26080 \begin_layout LyX-Code
26081 extern FILE * stdout;
26082 \end_layout
26083
26084 \begin_layout Standard
26085 The FILE type is actually a generic pointer which defines one more type
26086  of generic pointers, the 
26087 \emph on
26088 stream 
26089 \emph default
26090 pointer.
26091  This new type has the format:
26092 \end_layout
26093
26094 \begin_layout Standard
26095 \align center
26096 \begin_inset Tabular
26097 <lyxtabular version="3" rows="2" columns="7">
26098 <features>
26099 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26100 <column alignment="center" valignment="top" width="0">
26101 <column alignment="center" valignment="top" leftline="true" width="0">
26102 <column alignment="center" valignment="top" leftline="true" width="0">
26103 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26104 <column alignment="center" valignment="top" width="0">
26105 <column alignment="left" valignment="top" rightline="true" width="0">
26106 <row topline="true" bottomline="true">
26107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26108 \begin_inset Text
26109
26110 \begin_layout Standard
26111 pointer type
26112 \end_layout
26113
26114 \end_inset
26115 </cell>
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26117 \begin_inset Text
26118
26119 \begin_layout Standard
26120 <7:6>
26121 \end_layout
26122
26123 \end_inset
26124 </cell>
26125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26126 \begin_inset Text
26127
26128 \begin_layout Standard
26129 <5>
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 <4>
26139 \end_layout
26140
26141 \end_inset
26142 </cell>
26143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26144 \begin_inset Text
26145
26146 \begin_layout Standard
26147 <3:0>
26148 \end_layout
26149
26150 \end_inset
26151 </cell>
26152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26153 \begin_inset Text
26154
26155 \begin_layout Standard
26156 rest of the pointer
26157 \end_layout
26158
26159 \end_inset
26160 </cell>
26161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26162 \begin_inset Text
26163
26164 \begin_layout Standard
26165 descrption
26166 \end_layout
26167
26168 \end_inset
26169 </cell>
26170 </row>
26171 <row topline="true" bottomline="true">
26172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26173 \begin_inset Text
26174
26175 \begin_layout Standard
26176 stream
26177 \end_layout
26178
26179 \end_inset
26180 </cell>
26181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26182 \begin_inset Text
26183
26184 \begin_layout Standard
26185 00
26186 \end_layout
26187
26188 \end_inset
26189 </cell>
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26191 \begin_inset Text
26192
26193 \begin_layout Standard
26194 1
26195 \end_layout
26196
26197 \end_inset
26198 </cell>
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26200 \begin_inset Text
26201
26202 \begin_layout Standard
26203 0
26204 \end_layout
26205
26206 \end_inset
26207 </cell>
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26209 \begin_inset Text
26210
26211 \begin_layout Standard
26212 nnnn
26213 \end_layout
26214
26215 \end_inset
26216 </cell>
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26218 \begin_inset Text
26219
26220 \begin_layout Standard
26221
26222 \family typewriter
26223 \shape slanted
26224 \emph on
26225 uuuuuuuu uuuuuuuu
26226 \end_layout
26227
26228 \end_inset
26229 </cell>
26230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26231 \begin_inset Text
26232
26233 \begin_layout Standard
26234 upper byte high nubble is 0x2n, the rest are zeroes
26235 \end_layout
26236
26237 \end_inset
26238 </cell>
26239 </row>
26240 </lyxtabular>
26241
26242 \end_inset
26243
26244
26245 \end_layout
26246
26247 \begin_layout Standard
26248 Currently implemented there are 3 types of streams defined:
26249 \end_layout
26250
26251 \begin_layout Standard
26252 \align center
26253 \begin_inset Tabular
26254 <lyxtabular version="3" rows="4" columns="4">
26255 <features>
26256 <column alignment="center" valignment="top" leftline="true" width="0">
26257 <column alignment="center" valignment="top" leftline="true" width="0">
26258 <column alignment="center" valignment="top" leftline="true" width="0">
26259 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26260 <row topline="true" bottomline="true">
26261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26262 \begin_inset Text
26263
26264 \begin_layout Standard
26265 stream type
26266 \end_layout
26267
26268 \end_inset
26269 </cell>
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26271 \begin_inset Text
26272
26273 \begin_layout Standard
26274 value
26275 \end_layout
26276
26277 \end_inset
26278 </cell>
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26280 \begin_inset Text
26281
26282 \begin_layout Standard
26283 module
26284 \end_layout
26285
26286 \end_inset
26287 </cell>
26288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26289 \begin_inset Text
26290
26291 \begin_layout Standard
26292 description
26293 \end_layout
26294
26295 \end_inset
26296 </cell>
26297 </row>
26298 <row topline="true">
26299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26300 \begin_inset Text
26301
26302 \begin_layout Standard
26303 STREAM_USART
26304 \end_layout
26305
26306 \end_inset
26307 </cell>
26308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26309 \begin_inset Text
26310
26311 \begin_layout Standard
26312
26313 \family typewriter
26314 0x200000UL
26315 \end_layout
26316
26317 \end_inset
26318 </cell>
26319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26320 \begin_inset Text
26321
26322 \begin_layout Standard
26323 USART
26324 \end_layout
26325
26326 \end_inset
26327 </cell>
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26329 \begin_inset Text
26330
26331 \begin_layout Standard
26332 Writes/Reads characters via the USART peripheral
26333 \end_layout
26334
26335 \end_inset
26336 </cell>
26337 </row>
26338 <row topline="true">
26339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26340 \begin_inset Text
26341
26342 \begin_layout Standard
26343 STREAM_MSSP
26344 \end_layout
26345
26346 \end_inset
26347 </cell>
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26349 \begin_inset Text
26350
26351 \begin_layout Standard
26352
26353 \family typewriter
26354 0x210000UL
26355 \end_layout
26356
26357 \end_inset
26358 </cell>
26359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26360 \begin_inset Text
26361
26362 \begin_layout Standard
26363 MSSP
26364 \end_layout
26365
26366 \end_inset
26367 </cell>
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26369 \begin_inset Text
26370
26371 \begin_layout Standard
26372 Writes/Reads characters via the MSSP peripheral
26373 \end_layout
26374
26375 \end_inset
26376 </cell>
26377 </row>
26378 <row topline="true" bottomline="true">
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26380 \begin_inset Text
26381
26382 \begin_layout Standard
26383 STREAM_USER
26384 \end_layout
26385
26386 \end_inset
26387 </cell>
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26389 \begin_inset Text
26390
26391 \begin_layout Standard
26392
26393 \family typewriter
26394 0x2f0000UL
26395 \end_layout
26396
26397 \end_inset
26398 </cell>
26399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26400 \begin_inset Text
26401
26402 \begin_layout Standard
26403 (none)
26404 \end_layout
26405
26406 \end_inset
26407 </cell>
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26409 \begin_inset Text
26410
26411 \begin_layout Standard
26412 Writes/Reads characters via used defined functions
26413 \end_layout
26414
26415 \end_inset
26416 </cell>
26417 </row>
26418 </lyxtabular>
26419
26420 \end_inset
26421
26422
26423 \end_layout
26424
26425 \begin_layout Standard
26426 The stream identifiers are declared as macros in the stdio.h header.
26427 \end_layout
26428
26429 \begin_layout Standard
26430 In the libc library there exist the functions that are used to write to
26431  each of the above streams.
26432  These are
26433 \end_layout
26434
26435 \begin_layout List
26436 \labelwidthstring 00.00.0000
26437 _
26438 \begin_inset ERT
26439 status collapsed
26440
26441 \begin_layout Standard
26442
26443
26444 \backslash
26445 /
26446 \end_layout
26447
26448 \end_inset
26449
26450 _stream_usart_putchar writes a character at the USART stream
26451 \end_layout
26452
26453 \begin_layout List
26454 \labelwidthstring 00.00.0000
26455 _
26456 \begin_inset ERT
26457 status collapsed
26458
26459 \begin_layout Standard
26460
26461
26462 \backslash
26463 /
26464 \end_layout
26465
26466 \end_inset
26467
26468 _stream_mssp_putchar writes a character at the MSSP stream
26469 \end_layout
26470
26471 \begin_layout List
26472 \labelwidthstring 00.00.0000
26473 putchar dummy function.
26474  This writes a character to a user specified manner.
26475 \end_layout
26476
26477 \begin_layout Standard
26478 In order to increase performance 
26479 \emph on
26480 putchar 
26481 \emph default
26482 is declared in stdio.h as having its parameter in WREG (it has the wparam
26483  keyword).
26484  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26485  in a user-friendly way.
26486  
26487 \emph on
26488 arg
26489 \emph default
26490  is the name of the variable that holds the character to print.
26491  An example follows:
26492 \end_layout
26493
26494 \begin_layout LyX-Code
26495 #include <pic18fregs.h>
26496 \newline
26497 #include <stdio.h>
26498 \newline
26499
26500 \newline
26501 PUTCHAR( c )
26502 \end_layout
26503
26504 \begin_layout LyX-Code
26505 {
26506 \end_layout
26507
26508 \begin_layout LyX-Code
26509     PORTA = c;    /* dump character c to PORTA */
26510 \end_layout
26511
26512 \begin_layout LyX-Code
26513
26514 \newline
26515
26516 \newline
26517 void main(void)
26518 \end_layout
26519
26520 \begin_layout LyX-Code
26521 {
26522 \end_layout
26523
26524 \begin_layout LyX-Code
26525     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26526 \end_layout
26527
26528 \begin_layout LyX-Code
26529                               * by default to STREAM_USER */
26530 \end_layout
26531
26532 \begin_layout LyX-Code
26533     printf (¨This is a printf test
26534 \backslash
26535 n¨);
26536 \end_layout
26537
26538 \begin_layout LyX-Code
26539 }
26540 \end_layout
26541
26542 \begin_layout LyX-Code
26543
26544 \end_layout
26545
26546 \begin_layout Subsubsection
26547 Printing functions
26548 \end_layout
26549
26550 \begin_layout Standard
26551 PIC16 contains an implementation of the printf-family of functions.
26552  There exist the following functions:
26553 \end_layout
26554
26555 \begin_layout LyX-Code
26556 extern unsigned int sprintf(char *buf, char *fmt, ...);
26557 \end_layout
26558
26559 \begin_layout LyX-Code
26560 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26561 \end_layout
26562
26563 \begin_layout LyX-Code
26564
26565 \end_layout
26566
26567 \begin_layout LyX-Code
26568 extern unsigned int printf(char *fmt, ...);
26569 \end_layout
26570
26571 \begin_layout LyX-Code
26572 extern unsigned int vprintf(char *fmt, va_lista ap);
26573 \end_layout
26574
26575 \begin_layout LyX-Code
26576
26577 \end_layout
26578
26579 \begin_layout LyX-Code
26580 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26581 \end_layout
26582
26583 \begin_layout LyX-Code
26584 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26585 \end_layout
26586
26587 \begin_layout Standard
26588 For sprintf and vsprintf 
26589 \emph on
26590 buf 
26591 \emph default
26592 should normally be a data pointer where the resulting string will be placed.
26593  No range checking is done so the user should allocate the necessery buffer.
26594  For fprintf and vfprintf 
26595 \emph on
26596 fp
26597 \emph default
26598  should be a stream pointer (i.e.
26599  stdout, STREAM_MSSP, etc...).
26600 \end_layout
26601
26602 \begin_layout Subsubsection
26603 Signals
26604 \end_layout
26605
26606 \begin_layout Standard
26607 The PIC18F family of microcontrollers supports a number of interrupt sources.
26608  A list of these interrupts is shown in the following table:
26609 \end_layout
26610
26611 \begin_layout Standard
26612 \align center
26613 \begin_inset Tabular
26614 <lyxtabular version="3" rows="11" columns="4">
26615 <features>
26616 <column alignment="left" valignment="top" leftline="true" width="0">
26617 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26618 <column alignment="left" valignment="top" leftline="true" width="0">
26619 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26620 <row topline="true" bottomline="true">
26621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26622 \begin_inset Text
26623
26624 \begin_layout Standard
26625 signal name
26626 \end_layout
26627
26628 \end_inset
26629 </cell>
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26631 \begin_inset Text
26632
26633 \begin_layout Standard
26634 description
26635 \end_layout
26636
26637 \end_inset
26638 </cell>
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26640 \begin_inset Text
26641
26642 \begin_layout Standard
26643 signal name
26644 \end_layout
26645
26646 \end_inset
26647 </cell>
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26649 \begin_inset Text
26650
26651 \begin_layout Standard
26652 descritpion
26653 \end_layout
26654
26655 \end_inset
26656 </cell>
26657 </row>
26658 <row topline="true">
26659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26660 \begin_inset Text
26661
26662 \begin_layout Standard
26663 SIG_RB
26664 \end_layout
26665
26666 \end_inset
26667 </cell>
26668 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26669 \begin_inset Text
26670
26671 \begin_layout Standard
26672 PORTB change interrupt
26673 \end_layout
26674
26675 \end_inset
26676 </cell>
26677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26678 \begin_inset Text
26679
26680 \begin_layout Standard
26681 SIG_EE
26682 \end_layout
26683
26684 \end_inset
26685 </cell>
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26687 \begin_inset Text
26688
26689 \begin_layout Standard
26690 EEPROM/FLASH write complete interrupt
26691 \end_layout
26692
26693 \end_inset
26694 </cell>
26695 </row>
26696 <row topline="true">
26697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26698 \begin_inset Text
26699
26700 \begin_layout Standard
26701 SIG_INT0
26702 \end_layout
26703
26704 \end_inset
26705 </cell>
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26707 \begin_inset Text
26708
26709 \begin_layout Standard
26710 INT0 external interrupt
26711 \end_layout
26712
26713 \end_inset
26714 </cell>
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26716 \begin_inset Text
26717
26718 \begin_layout Standard
26719 SIG_BCOL
26720 \end_layout
26721
26722 \end_inset
26723 </cell>
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26725 \begin_inset Text
26726
26727 \begin_layout Standard
26728 Bus collision interrupt
26729 \end_layout
26730
26731 \end_inset
26732 </cell>
26733 </row>
26734 <row topline="true">
26735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26736 \begin_inset Text
26737
26738 \begin_layout Standard
26739 SIG_INT1
26740 \end_layout
26741
26742 \end_inset
26743 </cell>
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26745 \begin_inset Text
26746
26747 \begin_layout Standard
26748 INT1 external interrupt
26749 \end_layout
26750
26751 \end_inset
26752 </cell>
26753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26754 \begin_inset Text
26755
26756 \begin_layout Standard
26757 SIG_LVD
26758 \end_layout
26759
26760 \end_inset
26761 </cell>
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26763 \begin_inset Text
26764
26765 \begin_layout Standard
26766 Low voltage detect interrupt
26767 \end_layout
26768
26769 \end_inset
26770 </cell>
26771 </row>
26772 <row topline="true">
26773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26774 \begin_inset Text
26775
26776 \begin_layout Standard
26777 SIG_INT2
26778 \end_layout
26779
26780 \end_inset
26781 </cell>
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26783 \begin_inset Text
26784
26785 \begin_layout Standard
26786 INT2 external interrupt
26787 \end_layout
26788
26789 \end_inset
26790 </cell>
26791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26792 \begin_inset Text
26793
26794 \begin_layout Standard
26795 SIG_PSP
26796 \end_layout
26797
26798 \end_inset
26799 </cell>
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26801 \begin_inset Text
26802
26803 \begin_layout Standard
26804 Parallel slave port interrupt
26805 \end_layout
26806
26807 \end_inset
26808 </cell>
26809 </row>
26810 <row topline="true">
26811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26812 \begin_inset Text
26813
26814 \begin_layout Standard
26815 SIG_CCP1
26816 \end_layout
26817
26818 \end_inset
26819 </cell>
26820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26821 \begin_inset Text
26822
26823 \begin_layout Standard
26824 CCP1 module interrupt
26825 \end_layout
26826
26827 \end_inset
26828 </cell>
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26830 \begin_inset Text
26831
26832 \begin_layout Standard
26833 SIG_AD
26834 \end_layout
26835
26836 \end_inset
26837 </cell>
26838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26839 \begin_inset Text
26840
26841 \begin_layout Standard
26842 AD convertion complete interrupt
26843 \end_layout
26844
26845 \end_inset
26846 </cell>
26847 </row>
26848 <row topline="true">
26849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26850 \begin_inset Text
26851
26852 \begin_layout Standard
26853 SIG_CCP2
26854 \end_layout
26855
26856 \end_inset
26857 </cell>
26858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26859 \begin_inset Text
26860
26861 \begin_layout Standard
26862 CCP2 module interrupt
26863 \end_layout
26864
26865 \end_inset
26866 </cell>
26867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26868 \begin_inset Text
26869
26870 \begin_layout Standard
26871 SIG_RC
26872 \end_layout
26873
26874 \end_inset
26875 </cell>
26876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26877 \begin_inset Text
26878
26879 \begin_layout Standard
26880 USART receive interrupt
26881 \end_layout
26882
26883 \end_inset
26884 </cell>
26885 </row>
26886 <row topline="true">
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26888 \begin_inset Text
26889
26890 \begin_layout Standard
26891 SIG_TMR0
26892 \end_layout
26893
26894 \end_inset
26895 </cell>
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26897 \begin_inset Text
26898
26899 \begin_layout Standard
26900 TMR0 overflow interrupt
26901 \end_layout
26902
26903 \end_inset
26904 </cell>
26905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26906 \begin_inset Text
26907
26908 \begin_layout Standard
26909 SIG_TX
26910 \end_layout
26911
26912 \end_inset
26913 </cell>
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26915 \begin_inset Text
26916
26917 \begin_layout Standard
26918 USART transmit interrupt
26919 \end_layout
26920
26921 \end_inset
26922 </cell>
26923 </row>
26924 <row topline="true">
26925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26926 \begin_inset Text
26927
26928 \begin_layout Standard
26929 SIG_TMR1
26930 \end_layout
26931
26932 \end_inset
26933 </cell>
26934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26935 \begin_inset Text
26936
26937 \begin_layout Standard
26938 TMR1 overflow interrupt
26939 \end_layout
26940
26941 \end_inset
26942 </cell>
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26944 \begin_inset Text
26945
26946 \begin_layout Standard
26947 SIG_MSSP
26948 \end_layout
26949
26950 \end_inset
26951 </cell>
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26953 \begin_inset Text
26954
26955 \begin_layout Standard
26956 SSP receive/transmit interrupt
26957 \end_layout
26958
26959 \end_inset
26960 </cell>
26961 </row>
26962 <row topline="true">
26963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26964 \begin_inset Text
26965
26966 \begin_layout Standard
26967 SIG_TMR2
26968 \end_layout
26969
26970 \end_inset
26971 </cell>
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26973 \begin_inset Text
26974
26975 \begin_layout Standard
26976 TMR2 matches PR2 interrupt
26977 \end_layout
26978
26979 \end_inset
26980 </cell>
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26982 \begin_inset Text
26983
26984 \begin_layout Standard
26985
26986 \end_layout
26987
26988 \end_inset
26989 </cell>
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26991 \begin_inset Text
26992
26993 \begin_layout Standard
26994
26995 \end_layout
26996
26997 \end_inset
26998 </cell>
26999 </row>
27000 <row topline="true" bottomline="true">
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27002 \begin_inset Text
27003
27004 \begin_layout Standard
27005 SIG_TMR3
27006 \end_layout
27007
27008 \end_inset
27009 </cell>
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27011 \begin_inset Text
27012
27013 \begin_layout Standard
27014 TMR3 overflow interrupt
27015 \end_layout
27016
27017 \end_inset
27018 </cell>
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27020 \begin_inset Text
27021
27022 \begin_layout Standard
27023
27024 \end_layout
27025
27026 \end_inset
27027 </cell>
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27029 \begin_inset Text
27030
27031 \begin_layout Standard
27032
27033 \end_layout
27034
27035 \end_inset
27036 </cell>
27037 </row>
27038 </lyxtabular>
27039
27040 \end_inset
27041
27042
27043 \end_layout
27044
27045 \begin_layout Standard
27046 The prototypes for these names are defined in the header file 
27047 \emph on
27048 signal.h
27049 \emph default
27050  .
27051 \end_layout
27052
27053 \begin_layout Standard
27054 In order to simplify signal handling, a number of macros is provided:
27055 \end_layout
27056
27057 \begin_layout List
27058 \labelwidthstring 00.00.0000
27059 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27060  high priority interrupts.
27061  
27062 \emph on
27063 name
27064 \emph default
27065  is the function name to use.
27066 \end_layout
27067
27068 \begin_layout List
27069 \labelwidthstring 00.00.0000
27070 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27071  low priority interrupt.
27072  
27073 \emph on
27074 name
27075 \emph default
27076  is the function name to use.
27077 \end_layout
27078
27079 \begin_layout List
27080 \labelwidthstring 00.00.0000
27081 DEF_HANDLER(sig,handler) define a handler for signal 
27082 \emph on
27083 sig.
27084 \end_layout
27085
27086 \begin_layout List
27087 \labelwidthstring 00.00.0000
27088 END_DEF end the declaration of the dispatch table.
27089 \end_layout
27090
27091 \begin_layout Standard
27092 Additionally there are two more macros to simplify the declaration of the
27093  signal handler:
27094 \end_layout
27095
27096 \begin_layout List
27097 \labelwidthstring 00.00.0000
27098
27099 \series medium
27100 SIGHANDLER(handler) 
27101 \series default
27102 this declares the function prototype for the 
27103 \emph on
27104 handler
27105 \emph default
27106  function.
27107 \end_layout
27108
27109 \begin_layout List
27110 \labelwidthstring 00.00.0000
27111 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27112 \end_layout
27113
27114 \begin_layout Standard
27115 An example of using the macros above is shown below:
27116 \end_layout
27117
27118 \begin_layout LyX-Code
27119 #include <pic18fregs.h>
27120 \end_layout
27121
27122 \begin_layout LyX-Code
27123 #include <signal.h>
27124 \newline
27125
27126 \newline
27127 DEF_INTHIGH(high_int)
27128 \end_layout
27129
27130 \begin_layout LyX-Code
27131 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27132 \end_layout
27133
27134 \begin_layout LyX-Code
27135 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27136 \end_layout
27137
27138 \begin_layout LyX-Code
27139 END_DEF
27140 \newline
27141
27142 \newline
27143 SIGHANDLER(_tmr0_handler)
27144 \end_layout
27145
27146 \begin_layout LyX-Code
27147 {
27148 \end_layout
27149
27150 \begin_layout LyX-Code
27151   /* action to be taken when timer 0 overflows */
27152 \end_layout
27153
27154 \begin_layout LyX-Code
27155 }
27156 \newline
27157
27158 \newline
27159 SIGHANDLERNAKED(_bcol_handler)
27160 \end_layout
27161
27162 \begin_layout LyX-Code
27163 {
27164 \end_layout
27165
27166 \begin_layout LyX-Code
27167   _asm
27168 \end_layout
27169
27170 \begin_layout LyX-Code
27171     /* action to be taken when bus collision occurs */
27172 \end_layout
27173
27174 \begin_layout LyX-Code
27175     retfie
27176 \end_layout
27177
27178 \begin_layout LyX-Code
27179  _endasm;
27180 \end_layout
27181
27182 \begin_layout LyX-Code
27183 }
27184 \end_layout
27185
27186 \begin_layout Standard
27187
27188 \series bold
27189 NOTES:
27190 \series default
27191  Special care should be taken when using the above scheme:
27192 \end_layout
27193
27194 \begin_layout Itemize
27195 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27196 \end_layout
27197
27198 \begin_layout Itemize
27199 when declaring SIGHANDLERNAKED handler never forget to use 
27200 \emph on
27201 retfie
27202 \emph default
27203  for proper returning.
27204 \end_layout
27205
27206 \begin_layout Subsection
27207 PIC16 Port -- Tips
27208 \end_layout
27209
27210 \begin_layout Standard
27211 Here you can find some general tips for compiling programs with SDCC/pic16.
27212 \end_layout
27213
27214 \begin_layout Subsubsection
27215 Stack size
27216 \end_layout
27217
27218 \begin_layout Standard
27219 The default stack
27220 \begin_inset LatexCommand \index{PIC16!stack}
27221
27222 \end_inset
27223
27224  size (that is 64 bytes) probably is enough for many programs.
27225  One must take care that when there are many levels of function nesting,
27226  or there is excessive usage of stack, its size should be extended.
27227  An example of such a case is the printf/sprintf family of functions.
27228  If you encounter problems like not being able to print integers, then you
27229  need to set the stack size around the maximum (256 for small stack model).
27230  The following diagram shows what happens when calling printf to print an
27231  integer:
27232 \end_layout
27233
27234 \begin_layout LyX-Code
27235 printf () --> ltoa () --> ultoa () --> divschar ()
27236 \end_layout
27237
27238 \begin_layout Standard
27239 It is should be understood that stack is easily consumed when calling complicate
27240 d functions.
27241  Using command line arguments like -
27242 \begin_inset ERT
27243 status collapsed
27244
27245 \begin_layout Standard
27246
27247
27248 \backslash
27249 /
27250 \end_layout
27251
27252 \end_inset
27253
27254 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27255  stack frames.
27256  Other ways to reduce stack usage may exist.
27257 \end_layout
27258
27259 \begin_layout Subsection
27260 Known bugs
27261 \end_layout
27262
27263 \begin_layout Standard
27264 The PIC16 Port currently does not pass SDCC's regression test
27265 \begin_inset LatexCommand \index{Regression test (PIC16)}
27266
27267 \end_inset
27268
27269  suite (see section 
27270 \begin_inset LatexCommand \ref{sec:Quality-control}
27271
27272 \end_inset
27273
27274 ) and thus the snapshot build regression tests for the PIC16 target are
27275  currently disabled for all hosts
27276 \emph on
27277 .
27278 \end_layout
27279
27280 \begin_layout Chapter
27281 Debugging
27282 \end_layout
27283
27284 \begin_layout Standard
27285 There are several approaches to debugging your code.
27286  This chapter is meant to show your options and to give detail on some of
27287  them:
27288 \newline
27289
27290 \newline
27291 When writing your code:
27292 \end_layout
27293
27294 \begin_layout Itemize
27295 write your code with debugging in mind (avoid duplicating code, put conceptually
27296  similar variables into structs, use structured code, have strategic points
27297  within your code where all variables are consistent, ...)
27298 \end_layout
27299
27300 \begin_layout Itemize
27301 run a syntax-checking tool like splint
27302 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27303
27304 \end_inset
27305
27306
27307 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27308
27309 \end_inset
27310
27311  (see -
27312 \begin_inset ERT
27313 status collapsed
27314
27315 \begin_layout Standard
27316
27317
27318 \backslash
27319 /
27320 \end_layout
27321
27322 \end_inset
27323
27324 -more-pedantic 
27325 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27326
27327 \end_inset
27328
27329 ) over the code.
27330 \end_layout
27331
27332 \begin_layout Itemize
27333 for the high level code use a C-compiler (like f.e.
27334  GCC) to compile run and debug the code on your host.
27335  See (see -
27336 \begin_inset ERT
27337 status collapsed
27338
27339 \begin_layout Standard
27340
27341
27342 \backslash
27343 /
27344 \end_layout
27345
27346 \end_inset
27347
27348 -more-pedantic 
27349 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27350
27351 \end_inset
27352
27353 ) on how to handle syntax extensions like __xdata, __at(), ...
27354  
27355 \end_layout
27356
27357 \begin_layout Itemize
27358 use another C-compiler to compile code for your target.
27359  Always an option but not recommended:) And not very likely to help you.
27360  If you seriously consider walking this path you should at least occasionally
27361  check portability of your code.
27362  Most commercial compiler vendors will offer an evaluation version so you
27363  can test compile your code or snippets of your code.
27364 \end_layout
27365
27366 \begin_layout Standard
27367 Debugging on a simulator:
27368 \end_layout
27369
27370 \begin_layout Itemize
27371 there is a separate section about SDCDB (section 
27372 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27373
27374 \end_inset
27375
27376 ) below.
27377 \end_layout
27378
27379 \begin_layout Itemize
27380 or (8051 specific) use a freeware/commercial simulator which interfaces
27381  to the AOMF
27382 \begin_inset LatexCommand \index{AOMF, AOMF51}
27383
27384 \end_inset
27385
27386  file (see 
27387 \begin_inset LatexCommand \ref{OMF file}
27388
27389 \end_inset
27390
27391 ) optionally generated by SDCC.
27392 \end_layout
27393
27394 \begin_layout Standard
27395 Debugging On-target: 
27396 \end_layout
27397
27398 \begin_layout Itemize
27399 use a MCU port pin to serially output debug data to the RS232 port of your
27400  host.
27401  You'll probably want some level shifting device typically involving a MAX232
27402  or similar IC.
27403  If the hardware serial port of the MCU is not available search for 'Software
27404  UART' in your favourite search machine.
27405 \end_layout
27406
27407 \begin_layout Itemize
27408 use an on-target monitor.
27409  In this context a monitor is a small program which usually accepts commands
27410  via a serial line and allows to set program counter, to single step through
27411  a program and read/write memory locations.
27412  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27413  
27414 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27415
27416 \end_inset
27417
27418 ).
27419 \end_layout
27420
27421 \begin_layout Itemize
27422 toggle MCU port pins at strategic points within your code and use an oscilloscop
27423 e.
27424  A 
27425 \emph on
27426 digital oscilloscope
27427 \emph default
27428
27429 \begin_inset LatexCommand \index{Oscilloscope}
27430
27431 \end_inset
27432
27433  with deep trace memory is really helpful especially if you have to debug
27434  a realtime application.
27435  If you need to monitor more pins than your oscilloscope provides you can
27436  sometimes get away with a small R-2R network.
27437  On a single channel oscilloscope you could f.e.
27438  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27439 k
27440 \begin_inset Formula $\Omega$
27441 \end_inset
27442
27443  resistor and the other one by a 5\InsetSpace ~
27444 k
27445 \begin_inset Formula $\Omega$
27446 \end_inset
27447
27448  resistor to the oscilloscope probe (check output drive capability of the
27449  pins you want to monitor).
27450  If you need to monitor many more pins a 
27451 \emph on
27452 logic analyzer
27453 \emph default
27454  will be handy.
27455 \end_layout
27456
27457 \begin_layout Itemize
27458 use an ICE (
27459 \emph on
27460 i
27461 \emph default
27462
27463 \emph on
27464 c
27465 \emph default
27466 ircuit 
27467 \emph on
27468 e
27469 \emph default
27470 mulator
27471 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27472
27473 \end_inset
27474
27475 ).
27476  Usually very expensive.
27477  And very nice to have too.
27478  And usually locks you (for years...) to the devices the ICE can emulate.
27479  
27480 \end_layout
27481
27482 \begin_layout Itemize
27483 use a remote debugger.
27484  In most 8-bit systems the symbol information is not available on the target,
27485  and a complete debugger is too bulky for the target system.
27486  Therefore usually a debugger on the host system connects to an on-target
27487  debugging stub which accepts only primitive commands.
27488  
27489 \newline
27490 Terms to enter into your favourite search engine could be 'remote debugging',
27491  'gdb stub' or 'inferior debugger'.
27492  (is there one?)
27493 \end_layout
27494
27495 \begin_layout Itemize
27496 use an on target hardware debugger.
27497  Some of the more modern MCUs include hardware support for setting break
27498  points and monitoring/changing variables by using dedicated hardware pins.
27499  This facility doesn't require additional code to run on the target and
27500  
27501 \emph on
27502 usually
27503 \emph default
27504  doesn't affect runtime behaviour until a breakpoint is hit.
27505  For the mcs51 most hardware debuggers use the AOMF
27506 \begin_inset LatexCommand \index{AOMF, AOMF51}
27507
27508 \end_inset
27509
27510  file (see 
27511 \begin_inset LatexCommand \ref{OMF file}
27512
27513 \end_inset
27514
27515 ) as input file.
27516  
27517 \end_layout
27518
27519 \begin_layout Standard
27520 Last not least:
27521 \end_layout
27522
27523 \begin_layout Itemize
27524 if you are not familiar with any of the following terms you're likely to
27525  run into problems rather sooner than later: 
27526 \emph on
27527 volatile
27528 \emph default
27529
27530 \emph on
27531 atomic
27532 \emph default
27533
27534 \emph on
27535 memory map
27536 \emph default
27537
27538 \emph on
27539 overlay
27540 \emph default
27541 .
27542  As an embedded programmer you 
27543 \emph on
27544 have
27545 \emph default
27546  to know them so why not look them up 
27547 \emph on
27548 before
27549 \emph default
27550  you have problems?)
27551 \end_layout
27552
27553 \begin_layout Itemize
27554 tell someone else about your problem (actually this is a surprisingly effective
27555  means to hunt down the bug even if the listener is not familiar with your
27556  environment).
27557  As 'failure to communicate' is probably one of the job-induced deformations
27558  of an embedded programmer this is highly encouraged.
27559 \end_layout
27560
27561 \begin_layout Section
27562 Debugging with SDCDB
27563 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27564
27565 \end_inset
27566
27567
27568 \begin_inset LatexCommand \index{SDCDB (debugger)}
27569
27570 \end_inset
27571
27572  
27573 \end_layout
27574
27575 \begin_layout Standard
27576 SDCC is distributed with a source level debugger
27577 \begin_inset LatexCommand \index{Debugger}
27578
27579 \end_inset
27580
27581 .
27582  The debugger uses a command line interface, the command repertoire of the
27583  debugger has been kept as close to gdb
27584 \begin_inset LatexCommand \index{gdb}
27585
27586 \end_inset
27587
27588  (the GNU debugger) as possible.
27589  The configuration and build process is part of the standard compiler installati
27590 on, which also builds and installs the debugger in the target directory
27591  specified during configuration.
27592  The debugger allows you debug BOTH at the C source and at the ASM source
27593  level.
27594 \end_layout
27595
27596 \begin_layout Subsection
27597 Compiling for Debugging
27598 \end_layout
27599
27600 \begin_layout Standard
27601 The -
27602 \begin_inset ERT
27603 status collapsed
27604
27605 \begin_layout Standard
27606
27607
27608 \backslash
27609 /
27610 \end_layout
27611
27612 \end_inset
27613
27614 -debug
27615 \begin_inset LatexCommand \index{-\/-debug}
27616
27617 \end_inset
27618
27619  option must be specified for all files for which debug information is to
27620  be generated.
27621  The compiler generates a .adb file for each of these files.
27622  The linker creates the .cdb
27623 \begin_inset LatexCommand \index{<file>.cdb}
27624
27625 \end_inset
27626
27627  file from the .adb
27628 \begin_inset LatexCommand \index{<file>.adb}
27629
27630 \end_inset
27631
27632  files and the address information.
27633  This .cdb is used by the debugger.
27634 \end_layout
27635
27636 \begin_layout Subsection
27637 How the Debugger Works
27638 \end_layout
27639
27640 \begin_layout Standard
27641 When the -
27642 \begin_inset ERT
27643 status collapsed
27644
27645 \begin_layout Standard
27646
27647
27648 \backslash
27649 /
27650 \end_layout
27651
27652 \end_inset
27653
27654 -debug option is specified the compiler generates extra symbol information
27655  some of which are put into the assembler source and some are put into the
27656  .adb file.
27657  Then the linker creates the .cdb file from the individual .adb files with
27658  the address information for the symbols.
27659  The debugger reads the symbolic information generated by the compiler &
27660  the address information generated by the linker.
27661  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27662  execution is controlled by the debugger.
27663  When a command is issued for the debugger, it translates it into appropriate
27664  commands for the simulator.
27665  (Currently SDCDM only connects to the simulator but 
27666 \emph on
27667 newcdb
27668 \emph default
27669  at 
27670 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27671
27672 \end_inset
27673
27674  is an effort to connect directly to the hardware.) 
27675 \end_layout
27676
27677 \begin_layout Subsection
27678 Starting the Debugger SDCDB
27679 \end_layout
27680
27681 \begin_layout Standard
27682 The debugger can be started using the following command line.
27683  (Assume the file you are debugging has the file name foo).
27684 \newline
27685
27686 \newline
27687
27688 \family sans
27689 \series bold
27690 sdcdb foo
27691 \newline
27692
27693 \family default
27694 \series default
27695
27696 \newline
27697 The debugger will look for the following files.
27698 \end_layout
27699
27700 \begin_layout Itemize
27701 foo.c - the source file.
27702 \end_layout
27703
27704 \begin_layout Itemize
27705 foo.cdb - the debugger symbol information file.
27706 \end_layout
27707
27708 \begin_layout Itemize
27709 foo.ihx - the Intel hex format
27710 \begin_inset LatexCommand \index{Intel hex format}
27711
27712 \end_inset
27713
27714  object file.
27715 \end_layout
27716
27717 \begin_layout Subsection
27718 SDCDB Command Line Options
27719 \end_layout
27720
27721 \begin_layout Itemize
27722 -
27723 \begin_inset ERT
27724 status collapsed
27725
27726 \begin_layout Standard
27727
27728
27729 \backslash
27730 /
27731 \end_layout
27732
27733 \end_inset
27734
27735 -directory=<source file directory> this option can used to specify the directory
27736  search list.
27737  The debugger will look into the directory list specified for source, cdb
27738  & ihx files.
27739  The items in the directory list must be separated by ':', e.g.
27740  if the source files can be in the directories /home/src1 and /home/src2,
27741  the -
27742 \begin_inset ERT
27743 status collapsed
27744
27745 \begin_layout Standard
27746
27747
27748 \backslash
27749 /
27750 \end_layout
27751
27752 \end_inset
27753
27754 -directory option should be -
27755 \begin_inset ERT
27756 status collapsed
27757
27758 \begin_layout Standard
27759
27760
27761 \backslash
27762 /
27763 \end_layout
27764
27765 \end_inset
27766
27767 -directory=/home/src1:/home/src2.
27768  Note there can be no spaces in the option.
27769  
27770 \end_layout
27771
27772 \begin_layout Itemize
27773 -cd <directory> - change to the <directory>.
27774 \end_layout
27775
27776 \begin_layout Itemize
27777 -fullname - used by GUI front ends.
27778 \end_layout
27779
27780 \begin_layout Itemize
27781 -cpu <cpu-type> - this argument is passed to the simulator please see the
27782  simulator docs for details.
27783 \end_layout
27784
27785 \begin_layout Itemize
27786 -X <Clock frequency > this options is passed to the simulator please see
27787  the simulator docs for details.
27788 \end_layout
27789
27790 \begin_layout Itemize
27791 -s <serial port file> passed to simulator see the simulator docs for details.
27792 \end_layout
27793
27794 \begin_layout Itemize
27795 -S <serial in,out> passed to simulator see the simulator docs for details.
27796 \end_layout
27797
27798 \begin_layout Itemize
27799 -k <port number> passed to simulator see the simulator docs for details.
27800 \end_layout
27801
27802 \begin_layout Subsection
27803 SDCDB Debugger Commands
27804 \end_layout
27805
27806 \begin_layout Standard
27807 As mentioned earlier the command interface for the debugger has been deliberatel
27808 y kept as close the GNU debugger gdb, as possible.
27809  This will help the integration with existing graphical user interfaces
27810  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27811  If you use a graphical user interface for the debugger you can skip this
27812  section.
27813 \end_layout
27814
27815 \begin_layout Subsubsection*
27816 break [line | file:line | function | file:function]
27817 \end_layout
27818
27819 \begin_layout Standard
27820 Set breakpoint at specified line or function:
27821 \newline
27822
27823 \newline
27824
27825 \family sans
27826 \series bold
27827 sdcdb>break 100 
27828 \newline
27829 sdcdb>break foo.c:100
27830 \newline
27831 sdcdb>break funcfoo
27832 \newline
27833 sdcdb>break foo.c:funcfoo
27834 \end_layout
27835
27836 \begin_layout Subsubsection*
27837 clear [line | file:line | function | file:function ]
27838 \end_layout
27839
27840 \begin_layout Standard
27841 Clear breakpoint at specified line or function:
27842 \newline
27843
27844 \newline
27845
27846 \family sans
27847 \series bold
27848 sdcdb>clear 100
27849 \newline
27850 sdcdb>clear foo.c:100
27851 \newline
27852 sdcdb>clear funcfoo
27853 \newline
27854 sdcdb>clear foo.c:funcfoo
27855 \end_layout
27856
27857 \begin_layout Subsubsection*
27858 continue
27859 \end_layout
27860
27861 \begin_layout Standard
27862 Continue program being debugged, after breakpoint.
27863 \end_layout
27864
27865 \begin_layout Subsubsection*
27866 finish
27867 \end_layout
27868
27869 \begin_layout Standard
27870 Execute till the end of the current function.
27871 \end_layout
27872
27873 \begin_layout Subsubsection*
27874 delete [n]
27875 \end_layout
27876
27877 \begin_layout Standard
27878 Delete breakpoint number 'n'.
27879  If used without any option clear ALL user defined break points.
27880 \end_layout
27881
27882 \begin_layout Subsubsection*
27883 info [break | stack | frame | registers ]
27884 \end_layout
27885
27886 \begin_layout Itemize
27887 info break - list all breakpoints
27888 \end_layout
27889
27890 \begin_layout Itemize
27891 info stack - show the function call stack.
27892 \end_layout
27893
27894 \begin_layout Itemize
27895 info frame - show information about the current execution frame.
27896 \end_layout
27897
27898 \begin_layout Itemize
27899 info registers - show content of all registers.
27900 \end_layout
27901
27902 \begin_layout Subsubsection*
27903 step
27904 \end_layout
27905
27906 \begin_layout Standard
27907 Step program until it reaches a different source line.
27908  Note: pressing <return> repeats the last command.
27909 \end_layout
27910
27911 \begin_layout Subsubsection*
27912 next
27913 \end_layout
27914
27915 \begin_layout Standard
27916 Step program, proceeding through subroutine calls.
27917 \end_layout
27918
27919 \begin_layout Subsubsection*
27920 run
27921 \end_layout
27922
27923 \begin_layout Standard
27924 Start debugged program.
27925 \end_layout
27926
27927 \begin_layout Subsubsection*
27928 ptype variable 
27929 \end_layout
27930
27931 \begin_layout Standard
27932 Print type information of the variable.
27933 \end_layout
27934
27935 \begin_layout Subsubsection*
27936 print variable
27937 \end_layout
27938
27939 \begin_layout Standard
27940 print value of variable.
27941 \end_layout
27942
27943 \begin_layout Subsubsection*
27944 file filename
27945 \end_layout
27946
27947 \begin_layout Standard
27948 load the given file name.
27949  Note this is an alternate method of loading file for debugging.
27950 \end_layout
27951
27952 \begin_layout Subsubsection*
27953 frame
27954 \end_layout
27955
27956 \begin_layout Standard
27957 print information about current frame.
27958 \end_layout
27959
27960 \begin_layout Subsubsection*
27961 set srcmode
27962 \end_layout
27963
27964 \begin_layout Standard
27965 Toggle between C source & assembly source.
27966 \end_layout
27967
27968 \begin_layout Subsubsection*
27969 ! simulator command
27970 \end_layout
27971
27972 \begin_layout Standard
27973 Send the string following '!' to the simulator, the simulator response is
27974  displayed.
27975  Note the debugger does not interpret the command being sent to the simulator,
27976  so if a command like 'go' is sent the debugger can loose its execution
27977  context and may display incorrect values.
27978 \end_layout
27979
27980 \begin_layout Subsubsection*
27981 quit
27982 \end_layout
27983
27984 \begin_layout Standard
27985 "Watch me now.
27986  Iam going Down.
27987  My name is Bobby Brown"
27988 \end_layout
27989
27990 \begin_layout Subsection
27991 Interfacing SDCDB with DDD
27992 \end_layout
27993
27994 \begin_layout Standard
27995 \begin_inset Note Note
27996 status collapsed
27997
27998 \begin_layout Standard
27999 The screenshot was converted from png to eps with: 
28000 \begin_inset Quotes sld
28001 \end_inset
28002
28003 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28004 \begin_inset Quotes srd
28005 \end_inset
28006
28007  which produces a pretty compact eps file which is free from compression
28008  artifacts.
28009 \end_layout
28010
28011 \begin_layout Standard
28012 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28013  as this broke the build system on Sourceforge (pdf-file was broken.
28014  pdflatex does not accept eps files).
28015 \end_layout
28016
28017 \end_inset
28018
28019
28020 \end_layout
28021
28022 \begin_layout Standard
28023 The 
28024 \emph on
28025 p
28026 \emph default
28027 ortable 
28028 \emph on
28029 n
28030 \emph default
28031 etwork 
28032 \emph on
28033 g
28034 \emph default
28035 raphics File 
28036 \size footnotesize
28037
28038 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28039
28040 \end_inset
28041
28042
28043 \size default
28044  shows a screenshot of a debugging session with DDD
28045 \begin_inset LatexCommand \index{DDD (debugger)}
28046
28047 \end_inset
28048
28049  (Unix only) on a simulated 8032.
28050  The debugging session might not run as smoothly as the screenshot suggests.
28051  The debugger allows setting of breakpoints, displaying and changing variables,
28052  single stepping through C and assembler code.
28053  
28054 \newline
28055 The source was compiled with 
28056 \family sans
28057 \series bold
28058
28059 \newline
28060
28061 \newline
28062 sdcc -
28063 \family default
28064 \series default
28065
28066 \begin_inset ERT
28067 status collapsed
28068
28069 \begin_layout Standard
28070
28071
28072 \backslash
28073 /
28074 \end_layout
28075
28076 \end_inset
28077
28078
28079 \family sans
28080 \series bold
28081 -debug ddd_example.c
28082 \family default
28083 \series default
28084  
28085 \family sans
28086 \series bold
28087
28088 \newline
28089
28090 \family default
28091 \series default
28092
28093 \newline
28094 and DDD was invoked with 
28095 \family sans
28096 \series bold
28097
28098 \newline
28099
28100 \newline
28101 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28102 \end_layout
28103
28104 \begin_layout Standard
28105 \begin_inset Note Note
28106 status open
28107
28108 \begin_layout Standard
28109 Check that the double quotes or an apostroph within the command line survive
28110  the LyX tool chain.
28111  Previously the apostrophs got slanted in the PDF output so a cut and paste
28112  did not work.
28113 \end_layout
28114
28115 \end_inset
28116
28117
28118 \end_layout
28119
28120 \begin_layout Subsection
28121 Interfacing SDCDB with XEmacs
28122 \begin_inset LatexCommand \index{XEmacs}
28123
28124 \end_inset
28125
28126
28127 \begin_inset LatexCommand \index{Emacs}
28128
28129 \end_inset
28130
28131
28132 \end_layout
28133
28134 \begin_layout Standard
28135 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28136  sdcdb.el and sdcdbsrc.el.
28137  These two files can be found in the $(prefix)/bin directory after the installat
28138 ion is complete.
28139  These files need to be loaded into XEmacs for the interface to work.
28140  This can be done at XEmacs startup time by inserting the following into
28141  your '.xemacs' file (which can be found in your HOME directory): 
28142 \newline
28143
28144 \newline
28145
28146 \family typewriter
28147 (load-file sdcdbsrc.el) 
28148 \family default
28149
28150 \newline
28151
28152 \newline
28153 .xemacs is a lisp file so the () around the command is REQUIRED.
28154  The files can also be loaded dynamically while XEmacs is running, set the
28155  environment variable 'EMACSLOADPATH' to the installation bin directory
28156  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28157  To start the interface enter the following command: 
28158 \newline
28159
28160 \newline
28161
28162 \family sans
28163 \series bold
28164 ESC-x sdcdbsrc
28165 \family default
28166 \series default
28167
28168 \newline
28169
28170 \newline
28171 You will prompted to enter the file name to be debugged.
28172  
28173 \newline
28174
28175 \newline
28176 The command line options that are passed to the simulator directly are
28177  bound to default values in the file sdcdbsrc.el.
28178  The variables are listed below, these values maybe changed as required.
28179 \end_layout
28180
28181 \begin_layout Itemize
28182 sdcdbsrc-cpu-type '51
28183 \end_layout
28184
28185 \begin_layout Itemize
28186 sdcdbsrc-frequency '11059200
28187 \end_layout
28188
28189 \begin_layout Itemize
28190 sdcdbsrc-serial nil
28191 \end_layout
28192
28193 \begin_layout Standard
28194 The following is a list of key mapping for the debugger interface.
28195 \end_layout
28196
28197 \begin_layout Standard
28198 \InsetSpace ~
28199
28200 \family typewriter
28201
28202 \newline
28203 ;;\InsetSpace ~
28204 Current Listing :: 
28205 \newline
28206 ;;key\InsetSpace ~
28207 \InsetSpace ~
28208 \InsetSpace ~
28209 \InsetSpace ~
28210 \InsetSpace ~
28211 \InsetSpace ~
28212 \InsetSpace ~
28213 \InsetSpace ~
28214 \InsetSpace ~
28215 \InsetSpace ~
28216 \InsetSpace ~
28217 \InsetSpace ~
28218 \InsetSpace ~
28219 \InsetSpace ~
28220 binding\InsetSpace ~
28221 \InsetSpace ~
28222 \InsetSpace ~
28223 \InsetSpace ~
28224 \InsetSpace ~
28225 \InsetSpace ~
28226 \InsetSpace ~
28227 \InsetSpace ~
28228 \InsetSpace ~
28229 \InsetSpace ~
28230 \InsetSpace ~
28231 \InsetSpace ~
28232 \InsetSpace ~
28233 \InsetSpace ~
28234 \InsetSpace ~
28235 \InsetSpace ~
28236 \InsetSpace ~
28237 \InsetSpace ~
28238 \InsetSpace ~
28239 \InsetSpace ~
28240 \InsetSpace ~
28241 \InsetSpace ~
28242 Comment 
28243 \newline
28244 ;;---\InsetSpace ~
28245 \InsetSpace ~
28246 \InsetSpace ~
28247 \InsetSpace ~
28248 \InsetSpace ~
28249 \InsetSpace ~
28250 \InsetSpace ~
28251 \InsetSpace ~
28252 \InsetSpace ~
28253 \InsetSpace ~
28254 \InsetSpace ~
28255 \InsetSpace ~
28256 \InsetSpace ~
28257 \InsetSpace ~
28258 -------\InsetSpace ~
28259 \InsetSpace ~
28260 \InsetSpace ~
28261 \InsetSpace ~
28262 \InsetSpace ~
28263 \InsetSpace ~
28264 \InsetSpace ~
28265 \InsetSpace ~
28266 \InsetSpace ~
28267 \InsetSpace ~
28268 \InsetSpace ~
28269 \InsetSpace ~
28270 \InsetSpace ~
28271 \InsetSpace ~
28272 \InsetSpace ~
28273 \InsetSpace ~
28274 \InsetSpace ~
28275 \InsetSpace ~
28276 \InsetSpace ~
28277 \InsetSpace ~
28278 \InsetSpace ~
28279 \InsetSpace ~
28280 -------
28281 \newline
28282 ;; 
28283 \newline
28284 ;;\InsetSpace ~
28285 n\InsetSpace ~
28286 \InsetSpace ~
28287 \InsetSpace ~
28288 \InsetSpace ~
28289 \InsetSpace ~
28290 \InsetSpace ~
28291 \InsetSpace ~
28292 \InsetSpace ~
28293 \InsetSpace ~
28294 \InsetSpace ~
28295 \InsetSpace ~
28296 \InsetSpace ~
28297 \InsetSpace ~
28298 \InsetSpace ~
28299 \InsetSpace ~
28300 sdcdb-next-fro
28301 m-src\InsetSpace ~
28302 \InsetSpace ~
28303 \InsetSpace ~
28304 \InsetSpace ~
28305 \InsetSpace ~
28306 \InsetSpace ~
28307 \InsetSpace ~
28308 \InsetSpace ~
28309 \InsetSpace ~
28310 \InsetSpace ~
28311 SDCDB next command 
28312 \newline
28313 ;;\InsetSpace ~
28314 b\InsetSpace ~
28315 \InsetSpace ~
28316 \InsetSpace ~
28317 \InsetSpace ~
28318 \InsetSpace ~
28319 \InsetSpace ~
28320 \InsetSpace ~
28321 \InsetSpace ~
28322 \InsetSpace ~
28323 \InsetSpace ~
28324 \InsetSpace ~
28325 \InsetSpace ~
28326 \InsetSpace ~
28327 \InsetSpace ~
28328 \InsetSpace ~
28329 sdcdb-back-from-src\InsetSpace ~
28330 \InsetSpace ~
28331 \InsetSpace ~
28332 \InsetSpace ~
28333 \InsetSpace ~
28334 \InsetSpace ~
28335 \InsetSpace ~
28336 \InsetSpace ~
28337 \InsetSpace ~
28338 \InsetSpace ~
28339 SDCDB back command 
28340 \newline
28341 ;;\InsetSpace ~
28342 c\InsetSpace ~
28343 \InsetSpace ~
28344 \InsetSpace ~
28345 \InsetSpace ~
28346 \InsetSpace ~
28347 \InsetSpace ~
28348 \InsetSpace ~
28349 \InsetSpace ~
28350 \InsetSpace ~
28351 \InsetSpace ~
28352 \InsetSpace ~
28353 \InsetSpace ~
28354 \InsetSpace ~
28355 \InsetSpace ~
28356 \InsetSpace ~
28357 sdcdb-cont-f
28358 rom-src\InsetSpace ~
28359 \InsetSpace ~
28360 \InsetSpace ~
28361 \InsetSpace ~
28362 \InsetSpace ~
28363 \InsetSpace ~
28364 \InsetSpace ~
28365 \InsetSpace ~
28366 \InsetSpace ~
28367 \InsetSpace ~
28368 SDCDB continue command
28369 \newline
28370 ;;\InsetSpace ~
28371 s\InsetSpace ~
28372 \InsetSpace ~
28373 \InsetSpace ~
28374 \InsetSpace ~
28375 \InsetSpace ~
28376 \InsetSpace ~
28377 \InsetSpace ~
28378 \InsetSpace ~
28379 \InsetSpace ~
28380 \InsetSpace ~
28381 \InsetSpace ~
28382 \InsetSpace ~
28383 \InsetSpace ~
28384 \InsetSpace ~
28385 \InsetSpace ~
28386 sdcdb-step-from-src\InsetSpace ~
28387 \InsetSpace ~
28388 \InsetSpace ~
28389 \InsetSpace ~
28390 \InsetSpace ~
28391 \InsetSpace ~
28392 \InsetSpace ~
28393 \InsetSpace ~
28394 \InsetSpace ~
28395 \InsetSpace ~
28396 SDCDB step command 
28397 \newline
28398 ;;\InsetSpace ~
28399 ?\InsetSpace ~
28400 \InsetSpace ~
28401 \InsetSpace ~
28402 \InsetSpace ~
28403 \InsetSpace ~
28404 \InsetSpace ~
28405 \InsetSpace ~
28406 \InsetSpace ~
28407 \InsetSpace ~
28408 \InsetSpace ~
28409 \InsetSpace ~
28410 \InsetSpace ~
28411 \InsetSpace ~
28412 \InsetSpace ~
28413 \InsetSpace ~
28414 sdcdb-w
28415 hatis-c-sexp\InsetSpace ~
28416 \InsetSpace ~
28417 \InsetSpace ~
28418 \InsetSpace ~
28419 \InsetSpace ~
28420 \InsetSpace ~
28421 \InsetSpace ~
28422 \InsetSpace ~
28423 \InsetSpace ~
28424 \InsetSpace ~
28425 SDCDB ptypecommand for data at 
28426 \newline
28427 ;;\InsetSpace ~
28428 \InsetSpace ~
28429 \InsetSpace ~
28430 \InsetSpace ~
28431 \InsetSpace ~
28432 \InsetSpace ~
28433 \InsetSpace ~
28434 \InsetSpace ~
28435 \InsetSpace ~
28436 \InsetSpace ~
28437 \InsetSpace ~
28438 \InsetSpace ~
28439 \InsetSpace ~
28440 \InsetSpace ~
28441 \InsetSpace ~
28442 \InsetSpace ~
28443 \InsetSpace ~
28444 \InsetSpace ~
28445 \InsetSpace ~
28446 \InsetSpace ~
28447 \InsetSpace ~
28448 \InsetSpace ~
28449 \InsetSpace ~
28450 \InsetSpace ~
28451 \InsetSpace ~
28452 \InsetSpace ~
28453 \InsetSpace ~
28454 \InsetSpace ~
28455 \InsetSpace ~
28456 \InsetSpace ~
28457 \InsetSpace ~
28458 \InsetSpace ~
28459 \InsetSpace ~
28460 \InsetSpace ~
28461 \InsetSpace ~
28462 \InsetSpace ~
28463 \InsetSpace ~
28464 \InsetSpace ~
28465 \InsetSpace ~
28466 \InsetSpace ~
28467 \InsetSpace ~
28468 \InsetSpace ~
28469 \InsetSpace ~
28470 \InsetSpace ~
28471 \InsetSpace ~
28472 \InsetSpace ~
28473 \InsetSpace ~
28474 buffer point 
28475 \newline
28476 ;;\InsetSpace ~
28477 x\InsetSpace ~
28478 \InsetSpace ~
28479 \InsetSpace ~
28480 \InsetSpace ~
28481 \InsetSpace ~
28482 \InsetSpace ~
28483 \InsetSpace ~
28484 \InsetSpace ~
28485 \InsetSpace ~
28486 \InsetSpace ~
28487 \InsetSpace ~
28488 \InsetSpace ~
28489 \InsetSpace ~
28490 \InsetSpace ~
28491 \InsetSpace ~
28492 sdcdbsrc-delete\InsetSpace ~
28493 \InsetSpace ~
28494 \InsetSpace ~
28495 \InsetSpace ~
28496 \InsetSpace ~
28497 \InsetSpace ~
28498 \InsetSpace ~
28499 \InsetSpace ~
28500 \InsetSpace ~
28501 \InsetSpace ~
28502 \InsetSpace ~
28503 \InsetSpace ~
28504 \InsetSpace ~
28505 \InsetSpace ~
28506 SDCD
28507 B Delete all breakpoints if no arg 
28508 \newline
28509 ;;\InsetSpace ~
28510 \InsetSpace ~
28511 \InsetSpace ~
28512 \InsetSpace ~
28513 \InsetSpace ~
28514 \InsetSpace ~
28515 \InsetSpace ~
28516 \InsetSpace ~
28517 \InsetSpace ~
28518 \InsetSpace ~
28519 \InsetSpace ~
28520 \InsetSpace ~
28521 \InsetSpace ~
28522 \InsetSpace ~
28523 \InsetSpace ~
28524 \InsetSpace ~
28525 \InsetSpace ~
28526 \InsetSpace ~
28527 \InsetSpace ~
28528 \InsetSpace ~
28529 \InsetSpace ~
28530 \InsetSpace ~
28531 \InsetSpace ~
28532 \InsetSpace ~
28533 \InsetSpace ~
28534 \InsetSpace ~
28535 \InsetSpace ~
28536 \InsetSpace ~
28537 \InsetSpace ~
28538 \InsetSpace ~
28539 \InsetSpace ~
28540 \InsetSpace ~
28541 \InsetSpace ~
28542 \InsetSpace ~
28543 \InsetSpace ~
28544 \InsetSpace ~
28545 \InsetSpace ~
28546 \InsetSpace ~
28547 \InsetSpace ~
28548 \InsetSpace ~
28549 \InsetSpace ~
28550 \InsetSpace ~
28551 \InsetSpace ~
28552 \InsetSpace ~
28553 \InsetSpace ~
28554 \InsetSpace ~
28555 \InsetSpace ~
28556 given or delete arg (C-u arg x) 
28557 \newline
28558 ;;\InsetSpace ~
28559 m\InsetSpace ~
28560 \InsetSpace ~
28561 \InsetSpace ~
28562 \InsetSpace ~
28563 \InsetSpace ~
28564 \InsetSpace ~
28565 \InsetSpace ~
28566 \InsetSpace ~
28567 \InsetSpace ~
28568 \InsetSpace ~
28569 \InsetSpace ~
28570 \InsetSpace ~
28571 \InsetSpace ~
28572 \InsetSpace ~
28573 \InsetSpace ~
28574 sdcdbsrc
28575 -frame\InsetSpace ~
28576 \InsetSpace ~
28577 \InsetSpace ~
28578 \InsetSpace ~
28579 \InsetSpace ~
28580 \InsetSpace ~
28581 \InsetSpace ~
28582 \InsetSpace ~
28583 \InsetSpace ~
28584 \InsetSpace ~
28585 \InsetSpace ~
28586 \InsetSpace ~
28587 \InsetSpace ~
28588 \InsetSpace ~
28589 \InsetSpace ~
28590 SDCDB Display current frame if no arg, 
28591 \newline
28592 ;;\InsetSpace ~
28593 \InsetSpace ~
28594 \InsetSpace ~
28595 \InsetSpace ~
28596 \InsetSpace ~
28597 \InsetSpace ~
28598 \InsetSpace ~
28599 \InsetSpace ~
28600 \InsetSpace ~
28601 \InsetSpace ~
28602 \InsetSpace ~
28603 \InsetSpace ~
28604 \InsetSpace ~
28605 \InsetSpace ~
28606 \InsetSpace ~
28607 \InsetSpace ~
28608 \InsetSpace ~
28609 \InsetSpace ~
28610 \InsetSpace ~
28611 \InsetSpace ~
28612 \InsetSpace ~
28613 \InsetSpace ~
28614 \InsetSpace ~
28615 \InsetSpace ~
28616 \InsetSpace ~
28617 \InsetSpace ~
28618 \InsetSpace ~
28619 \InsetSpace ~
28620 \InsetSpace ~
28621 \InsetSpace ~
28622 \InsetSpace ~
28623 \InsetSpace ~
28624 \InsetSpace ~
28625 \InsetSpace ~
28626 \InsetSpace ~
28627 \InsetSpace ~
28628 \InsetSpace ~
28629 \InsetSpace ~
28630 \InsetSpace ~
28631 \InsetSpace ~
28632 \InsetSpace ~
28633 \InsetSpace ~
28634 \InsetSpace ~
28635 \InsetSpace ~
28636 \InsetSpace ~
28637 \InsetSpace ~
28638 \InsetSpace ~
28639 given or display frame arg
28640  
28641 \newline
28642 ;;\InsetSpace ~
28643 \InsetSpace ~
28644 \InsetSpace ~
28645 \InsetSpace ~
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 \InsetSpace ~
28649 \InsetSpace ~
28650 \InsetSpace ~
28651 \InsetSpace ~
28652 \InsetSpace ~
28653 \InsetSpace ~
28654 \InsetSpace ~
28655 \InsetSpace ~
28656 \InsetSpace ~
28657 \InsetSpace ~
28658 \InsetSpace ~
28659 \InsetSpace ~
28660 \InsetSpace ~
28661 \InsetSpace ~
28662 \InsetSpace ~
28663 \InsetSpace ~
28664 \InsetSpace ~
28665 \InsetSpace ~
28666 \InsetSpace ~
28667 \InsetSpace ~
28668 \InsetSpace ~
28669 \InsetSpace ~
28670 \InsetSpace ~
28671 \InsetSpace ~
28672 \InsetSpace ~
28673 \InsetSpace ~
28674 \InsetSpace ~
28675 \InsetSpace ~
28676 \InsetSpace ~
28677 \InsetSpace ~
28678 \InsetSpace ~
28679 \InsetSpace ~
28680 \InsetSpace ~
28681 \InsetSpace ~
28682 \InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 buffer point 
28690 \newline
28691 ;;\InsetSpace ~
28692 !\InsetSpace ~
28693 \InsetSpace ~
28694 \InsetSpace ~
28695 \InsetSpace ~
28696 \InsetSpace ~
28697 \InsetSpace ~
28698 \InsetSpace ~
28699 \InsetSpace ~
28700 \InsetSpace ~
28701 \InsetSpace ~
28702 \InsetSpace ~
28703 \InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 \InsetSpace ~
28707 sdcdbsrc-goto-sdcdb\InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 \InsetSpace ~
28711 \InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 \InsetSpace ~
28716 \InsetSpace ~
28717 Goto the SDCDB output buffer 
28718 \newline
28719 ;;\InsetSpace ~
28720 p\InsetSpace ~
28721 \InsetSpace ~
28722 \InsetSpace ~
28723 \InsetSpace ~
28724 \InsetSpace ~
28725 \InsetSpace ~
28726 \InsetSpace ~
28727 \InsetSpace ~
28728 \InsetSpace ~
28729 \InsetSpace ~
28730 \InsetSpace ~
28731 \InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734 \InsetSpace ~
28735 sdcdb-prin
28736 t-c-sexp\InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 \InsetSpace ~
28745 \InsetSpace ~
28746 \InsetSpace ~
28747 SDCDB print command for data at 
28748 \newline
28749 ;;\InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 \InsetSpace ~
28753 \InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 \InsetSpace ~
28757 \InsetSpace ~
28758 \InsetSpace ~
28759 \InsetSpace ~
28760 \InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 \InsetSpace ~
28764 \InsetSpace ~
28765 \InsetSpace ~
28766 \InsetSpace ~
28767 \InsetSpace ~
28768 \InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 \InsetSpace ~
28773 \InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 \InsetSpace ~
28779 \InsetSpace ~
28780 \InsetSpace ~
28781 \InsetSpace ~
28782 \InsetSpace ~
28783 \InsetSpace ~
28784 \InsetSpace ~
28785 \InsetSpace ~
28786 \InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 \InsetSpace ~
28792 \InsetSpace ~
28793 \InsetSpace ~
28794 \InsetSpace ~
28795 \InsetSpace ~
28796 buffer point 
28797 \newline
28798 ;;\InsetSpace ~
28799 g\InsetSpace ~
28800 \InsetSpace ~
28801 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 \InsetSpace ~
28807 \InsetSpace ~
28808 \InsetSpace ~
28809 \InsetSpace ~
28810 \InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
28813 \InsetSpace ~
28814 sdcdbsrc-goto-sdcdb\InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 \InsetSpace ~
28821 \InsetSpace ~
28822 \InsetSpace ~
28823 \InsetSpace ~
28824 Got
28825 o the SDCDB output buffer 
28826 \newline
28827 ;;\InsetSpace ~
28828 t\InsetSpace ~
28829 \InsetSpace ~
28830 \InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 \InsetSpace ~
28834 \InsetSpace ~
28835 \InsetSpace ~
28836 \InsetSpace ~
28837 \InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 \InsetSpace ~
28841 \InsetSpace ~
28842 \InsetSpace ~
28843 sdcdbsrc-mode\InsetSpace ~
28844 \InsetSpace ~
28845 \InsetSpace ~
28846 \InsetSpace ~
28847 \InsetSpace ~
28848 \InsetSpace ~
28849 \InsetSpace ~
28850 \InsetSpace ~
28851 \InsetSpace ~
28852 \InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 \InsetSpace ~
28859 Toggles Sdcdbsrc mode (turns it
28860  off) 
28861 \newline
28862 ;; 
28863 \newline
28864 ;;\InsetSpace ~
28865 C-c\InsetSpace ~
28866 C-f\InsetSpace ~
28867 \InsetSpace ~
28868 \InsetSpace ~
28869 \InsetSpace ~
28870 \InsetSpace ~
28871 \InsetSpace ~
28872 \InsetSpace ~
28873 \InsetSpace ~
28874 \InsetSpace ~
28875 sdcdb-finish-from-src\InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 \InsetSpace ~
28880 \InsetSpace ~
28881 \InsetSpace ~
28882 \InsetSpace ~
28883 SDCDB finish command 
28884 \newline
28885 ;; 
28886 \newline
28887 ;;\InsetSpace ~
28888 C-x\InsetSpace ~
28889 SPC\InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 \InsetSpace ~
28898 sdcdb-brea
28899 k\InsetSpace ~
28900 \InsetSpace ~
28901 \InsetSpace ~
28902 \InsetSpace ~
28903 \InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 \InsetSpace ~
28908 \InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 Set break for line with point 
28918 \newline
28919 ;;\InsetSpace ~
28920 ESC\InsetSpace ~
28921 t\InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 \InsetSpace ~
28932 sdcdbsrc-mode\InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 \InsetSpace ~
28947 \InsetSpace ~
28948 Toggle Sdcdbsrc mode 
28949 \newline
28950 ;;\InsetSpace ~
28951 ESC\InsetSpace ~
28952 m\InsetSpace ~
28953 \InsetSpace ~
28954 \InsetSpace ~
28955 \InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 \InsetSpace ~
28960 \InsetSpace ~
28961 \InsetSpace ~
28962 \InsetSpace ~
28963 sdc
28964 dbsrc-srcmode\InsetSpace ~
28965 \InsetSpace ~
28966 \InsetSpace ~
28967 \InsetSpace ~
28968 \InsetSpace ~
28969 \InsetSpace ~
28970 \InsetSpace ~
28971 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 Toggle list mode 
28978 \newline
28979 ;; 
28980 \newline
28981
28982 \family default
28983
28984 \newpage
28985
28986 \end_layout
28987
28988 \begin_layout Chapter
28989 TIPS
28990 \end_layout
28991
28992 \begin_layout Standard
28993 Here are a few guidelines that will help the compiler generate more efficient
28994  code, some of the tips are specific to this compiler others are generally
28995  good programming practice.
28996 \end_layout
28997
28998 \begin_layout Itemize
28999 Use the smallest data type to represent your data-value.
29000  If it is known in advance that the value is going to be less than 256 then
29001  use an 'unsigned char' instead of a 'short' or 'int'.
29002  Please note, that ANSI C requires both signed and unsigned chars to be
29003  promoted to 'signed int'
29004 \begin_inset LatexCommand \index{promotion to signed int}
29005
29006 \end_inset
29007
29008
29009 \begin_inset Marginal
29010 status collapsed
29011
29012 \begin_layout Standard
29013
29014 \series bold
29015 \InsetSpace ~
29016 !
29017 \end_layout
29018
29019 \end_inset
29020
29021  before doing any operation.
29022  This promotion
29023 \begin_inset LatexCommand \index{type promotion}
29024
29025 \end_inset
29026
29027
29028 \begin_inset LatexCommand \label{type promotion}
29029
29030 \end_inset
29031
29032  can be omitted, if the result is the same.
29033  The effect of the promotion rules together with the sign-extension is often
29034  surprising:
29035 \end_layout
29036
29037 \begin_deeper
29038 \begin_layout Verse
29039
29040 \family typewriter
29041 unsigned char uc = 0xfe;
29042 \newline
29043 if (uc * uc < 0) /* this is true! */
29044 \newline
29045 {
29046 \newline
29047 \InsetSpace ~
29048 \InsetSpace ~
29049 \InsetSpace ~
29050 \InsetSpace ~
29051 ....
29052 \newline
29053 }
29054 \end_layout
29055
29056 \begin_layout Standard
29057
29058 \family typewriter
29059 uc * uc
29060 \family default
29061  is evaluated as 
29062 \family typewriter
29063 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29064 \family default
29065 .
29066  
29067 \newline
29068 Another one:
29069 \end_layout
29070
29071 \begin_layout Verse
29072
29073 \family typewriter
29074 (unsigned char) -12 / (signed char) -3 = ...
29075 \end_layout
29076
29077 \begin_layout Standard
29078 No, the result is not 4:
29079 \end_layout
29080
29081 \begin_layout Verse
29082
29083 \family typewriter
29084 (int) (unsigned char) -12 / (int) (signed char) -3 =
29085 \newline
29086 (int) (unsigned char)
29087  0xf4 / (int) (signed char) 0xfd =
29088 \newline
29089 (int) 0x00f4 / (int) 0xfffd =
29090 \newline
29091 (int) 0x00f4
29092  / (int) 0xfffd =
29093 \newline
29094 (int) 244 / (int) -3 =
29095 \newline
29096 (int) -81 = (int) 0xffaf;
29097 \end_layout
29098
29099 \begin_layout Standard
29100 Don't complain, that gcc gives you a different result.
29101  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29102  Therefore the results are different.
29103 \newline
29104 From 
29105 \begin_inset Quotes sld
29106 \end_inset
29107
29108 comp.lang.c FAQ
29109 \begin_inset Quotes srd
29110 \end_inset
29111
29112 :
29113 \end_layout
29114
29115 \begin_layout Quote
29116
29117 \emph on
29118 If well-defined overflow characteristics are important and negative values
29119  are not, or if you want to steer clear of sign-extension problems when
29120  manipulating bits or bytes, use one of the corresponding unsigned types.
29121  (Beware when mixing signed and unsigned values in expressions, though.)
29122 \newline
29123 Although
29124  character types (especially unsigned char) can be used as "tiny" integers,
29125  doing so is sometimes more trouble than it's worth, due to unpredictable
29126  sign extension and increased code size.
29127 \end_layout
29128
29129 \end_deeper
29130 \begin_layout Itemize
29131 Use unsigned when it is known in advance that the value is not going to
29132  be negative.
29133  This helps especially if you are doing division or multiplication, bit-shifting
29134  or are using an array index.
29135 \end_layout
29136
29137 \begin_layout Itemize
29138 NEVER jump into a LOOP.
29139 \end_layout
29140
29141 \begin_layout Itemize
29142 Declare the variables to be local
29143 \begin_inset LatexCommand \index{local variables}
29144
29145 \end_inset
29146
29147  whenever possible, especially loop control variables (induction).
29148 \end_layout
29149
29150 \begin_layout Itemize
29151 Have a look at the assembly listing to get a 
29152 \begin_inset Quotes sld
29153 \end_inset
29154
29155 feeling
29156 \begin_inset Quotes srd
29157 \end_inset
29158
29159  for the code generation.
29160 \end_layout
29161
29162 \begin_layout Section
29163 Porting code from or to other compilers
29164 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29165
29166 \end_inset
29167
29168
29169 \end_layout
29170
29171 \begin_layout Itemize
29172 check whether endianness of the compilers differs and adapt where needed.
29173 \end_layout
29174
29175 \begin_layout Itemize
29176 check the device specific header files
29177 \begin_inset LatexCommand \index{Header files}
29178
29179 \end_inset
29180
29181
29182 \begin_inset LatexCommand \index{Include files}
29183
29184 \end_inset
29185
29186  for compiler specific syntax.
29187  Eventually include the file <compiler.h
29188 \begin_inset LatexCommand \index{compiler.h (include file)}
29189
29190 \end_inset
29191
29192
29193 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29194
29195 \end_inset
29196
29197  to allow using common header files.
29198  (see f.e.
29199  cc2510fx.h 
29200 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29201
29202 \end_inset
29203
29204 ).
29205 \end_layout
29206
29207 \begin_layout Itemize
29208 check whether the startup code contains the correct initialization (watchdog,
29209  peripherals).
29210 \end_layout
29211
29212 \begin_layout Itemize
29213 check whether the sizes of short, int, long match.
29214 \end_layout
29215
29216 \begin_layout Itemize
29217 check if some 16 or 32 bit hardware registers require a specific addressing
29218  order (least significant or most significant byte first) and adapt if needed
29219  (
29220 \emph on
29221 first
29222 \emph default
29223  and 
29224 \emph on
29225 last
29226 \emph default
29227  relate to time and not to lower/upper memory location here, so this is
29228  
29229 \emph on
29230 not
29231 \emph default
29232  the same as endianness).
29233 \end_layout
29234
29235 \begin_layout Itemize
29236 check whether the keyword 
29237 \emph on
29238 volatile
29239 \emph default
29240  is used where needed.
29241  The compilers might differ in their optimization characteristics (as different
29242  versions of the same compiler might also use more clever optimizations
29243  this is good idea anyway).
29244  See section 
29245 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29246
29247 \end_inset
29248
29249 .
29250 \end_layout
29251
29252 \begin_layout Itemize
29253 check that the compilers are not told to supress warnings.
29254 \end_layout
29255
29256 \begin_layout Itemize
29257 check and convert compiler specific extensions (interrupts, memory areas,
29258  pragmas etc.).
29259 \end_layout
29260
29261 \begin_layout Itemize
29262 check for differences in type promotion.
29263  Especially check for math operations on 
29264 \family typewriter
29265 char
29266 \family default
29267  or 
29268 \family typewriter
29269 unsigned char
29270 \family default
29271  variables.
29272  For the sake of C99 compatibility SDCC will probably promote these to 
29273 \family typewriter
29274 int
29275 \family default
29276  more often than other compilers.
29277  Eventually insert explicit casts to 
29278 \family typewriter
29279 (char) 
29280 \family default
29281 or
29282 \family typewriter
29283  (unsigned char)
29284 \family default
29285 .
29286  Also check that the ~\InsetSpace ~
29287 operator
29288 \begin_inset LatexCommand \index{\~\/ Operator}
29289
29290 \end_inset
29291
29292  is not used on 
29293 \family typewriter
29294 bit
29295 \begin_inset LatexCommand \index{bit}
29296
29297 \end_inset
29298
29299
29300 \family default
29301  variables, use the !\InsetSpace ~
29302 operator instead.
29303  See sections 
29304 \begin_inset LatexCommand \ref{type promotion}
29305
29306 \end_inset
29307
29308  and 
29309 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29310
29311 \end_inset
29312
29313 .
29314 \end_layout
29315
29316 \begin_layout Itemize
29317 check the assembly code generated for interrupt routines (f.e.
29318  for calls to possibly non-reentrant library functions).
29319 \end_layout
29320
29321 \begin_layout Itemize
29322 check whether timing loops result in proper timing (or preferably consider
29323  a rewrite of the code with timer based delays instead).
29324 \end_layout
29325
29326 \begin_layout Itemize
29327 check for differences in printf parameters (some compilers push (va_arg
29328 \begin_inset LatexCommand \index{vararg, va\_arg}
29329
29330 \end_inset
29331
29332 ) char variables as 
29333 \family typewriter
29334 int
29335 \family default
29336  others push them as 
29337 \family typewriter
29338 char
29339 \family default
29340 .
29341  See section 
29342 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29343
29344 \end_inset
29345
29346 ).
29347 \end_layout
29348
29349 \begin_layout Itemize
29350 check the resulting memory map
29351 \begin_inset LatexCommand \index{Memory map}
29352
29353 \end_inset
29354
29355 .
29356  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29357 ly idata, pdata, xdata).
29358  Eventually check if unexpected library functions are included.
29359 \end_layout
29360
29361 \begin_layout Section
29362 Tools
29363 \begin_inset LatexCommand \index{Tools}
29364
29365 \end_inset
29366
29367  included in the distribution
29368 \end_layout
29369
29370 \begin_layout Standard
29371 \align left
29372 \begin_inset Tabular
29373 <lyxtabular version="3" rows="12" columns="3">
29374 <features>
29375 <column alignment="left" valignment="top" leftline="true" width="0pt">
29376 <column alignment="left" valignment="top" leftline="true" width="0pt">
29377 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29378 <row topline="true" bottomline="true">
29379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29380 \begin_inset Text
29381
29382 \begin_layout Standard
29383
29384 \series bold
29385 Name
29386 \end_layout
29387
29388 \end_inset
29389 </cell>
29390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29391 \begin_inset Text
29392
29393 \begin_layout Standard
29394
29395 \series bold
29396 Purpose
29397 \end_layout
29398
29399 \end_inset
29400 </cell>
29401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29402 \begin_inset Text
29403
29404 \begin_layout Standard
29405
29406 \series bold
29407 Directory
29408 \end_layout
29409
29410 \end_inset
29411 </cell>
29412 </row>
29413 <row topline="true">
29414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29415 \begin_inset Text
29416
29417 \begin_layout Standard
29418 uCsim
29419 \begin_inset LatexCommand \index{uCsim}
29420
29421 \end_inset
29422
29423
29424 \end_layout
29425
29426 \end_inset
29427 </cell>
29428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29429 \begin_inset Text
29430
29431 \begin_layout Standard
29432 Simulator for various architectures
29433 \end_layout
29434
29435 \end_inset
29436 </cell>
29437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29438 \begin_inset Text
29439
29440 \begin_layout Standard
29441 sdcc/sim/ucsim
29442 \end_layout
29443
29444 \end_inset
29445 </cell>
29446 </row>
29447 <row topline="true">
29448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29449 \begin_inset Text
29450
29451 \begin_layout Standard
29452 keil2sdcc.pl
29453 \end_layout
29454
29455 \end_inset
29456 </cell>
29457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29458 \begin_inset Text
29459
29460 \begin_layout Standard
29461 header file
29462 \begin_inset LatexCommand \index{Header files}
29463
29464 \end_inset
29465
29466
29467 \begin_inset LatexCommand \index{Include files}
29468
29469 \end_inset
29470
29471  conversion
29472 \end_layout
29473
29474 \end_inset
29475 </cell>
29476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29477 \begin_inset Text
29478
29479 \begin_layout Standard
29480 sdcc/support/scripts
29481 \end_layout
29482
29483 \end_inset
29484 </cell>
29485 </row>
29486 <row topline="true">
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29488 \begin_inset Text
29489
29490 \begin_layout Standard
29491 mh2h.c
29492 \end_layout
29493
29494 \end_inset
29495 </cell>
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29497 \begin_inset Text
29498
29499 \begin_layout Standard
29500 header file conversion
29501 \end_layout
29502
29503 \end_inset
29504 </cell>
29505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29506 \begin_inset Text
29507
29508 \begin_layout Standard
29509 sdcc/support/scripts
29510 \end_layout
29511
29512 \end_inset
29513 </cell>
29514 </row>
29515 <row topline="true">
29516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29517 \begin_inset Text
29518
29519 \begin_layout Standard
29520 as-gbz80
29521 \end_layout
29522
29523 \end_inset
29524 </cell>
29525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29526 \begin_inset Text
29527
29528 \begin_layout Standard
29529 Assembler
29530 \end_layout
29531
29532 \end_inset
29533 </cell>
29534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29535 \begin_inset Text
29536
29537 \begin_layout Standard
29538
29539 \family roman
29540 \series medium
29541 \shape up
29542 \size normal
29543 \emph off
29544 \bar no
29545 \noun off
29546 \color none
29547 sdcc/bin
29548 \end_layout
29549
29550 \end_inset
29551 </cell>
29552 </row>
29553 <row topline="true">
29554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29555 \begin_inset Text
29556
29557 \begin_layout Standard
29558 as-z80
29559 \end_layout
29560
29561 \end_inset
29562 </cell>
29563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29564 \begin_inset Text
29565
29566 \begin_layout Standard
29567 Assembler
29568 \end_layout
29569
29570 \end_inset
29571 </cell>
29572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29573 \begin_inset Text
29574
29575 \begin_layout Standard
29576
29577 \family roman
29578 \series medium
29579 \shape up
29580 \size normal
29581 \emph off
29582 \bar no
29583 \noun off
29584 \color none
29585 sdcc/bin
29586 \end_layout
29587
29588 \end_inset
29589 </cell>
29590 </row>
29591 <row topline="true">
29592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29593 \begin_inset Text
29594
29595 \begin_layout Standard
29596 asx8051
29597 \end_layout
29598
29599 \end_inset
29600 </cell>
29601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29602 \begin_inset Text
29603
29604 \begin_layout Standard
29605 Assembler
29606 \end_layout
29607
29608 \end_inset
29609 </cell>
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29611 \begin_inset Text
29612
29613 \begin_layout Standard
29614
29615 \family roman
29616 \series medium
29617 \shape up
29618 \size normal
29619 \emph off
29620 \bar no
29621 \noun off
29622 \color none
29623 sdcc/bin
29624 \end_layout
29625
29626 \end_inset
29627 </cell>
29628 </row>
29629 <row topline="true">
29630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29631 \begin_inset Text
29632
29633 \begin_layout Standard
29634 SDCDB
29635 \end_layout
29636
29637 \end_inset
29638 </cell>
29639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29640 \begin_inset Text
29641
29642 \begin_layout Standard
29643 Simulator
29644 \end_layout
29645
29646 \end_inset
29647 </cell>
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29649 \begin_inset Text
29650
29651 \begin_layout Standard
29652
29653 \family roman
29654 \series medium
29655 \shape up
29656 \size normal
29657 \emph off
29658 \bar no
29659 \noun off
29660 \color none
29661 sdcc/bin
29662 \end_layout
29663
29664 \end_inset
29665 </cell>
29666 </row>
29667 <row topline="true">
29668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29669 \begin_inset Text
29670
29671 \begin_layout Standard
29672 aslink
29673 \end_layout
29674
29675 \end_inset
29676 </cell>
29677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29678 \begin_inset Text
29679
29680 \begin_layout Standard
29681 Linker
29682 \end_layout
29683
29684 \end_inset
29685 </cell>
29686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29687 \begin_inset Text
29688
29689 \begin_layout Standard
29690
29691 \family roman
29692 \series medium
29693 \shape up
29694 \size normal
29695 \emph off
29696 \bar no
29697 \noun off
29698 \color none
29699 sdcc/bin
29700 \end_layout
29701
29702 \end_inset
29703 </cell>
29704 </row>
29705 <row topline="true">
29706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29707 \begin_inset Text
29708
29709 \begin_layout Standard
29710 link-z80
29711 \end_layout
29712
29713 \end_inset
29714 </cell>
29715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29716 \begin_inset Text
29717
29718 \begin_layout Standard
29719 Linker
29720 \end_layout
29721
29722 \end_inset
29723 </cell>
29724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29725 \begin_inset Text
29726
29727 \begin_layout Standard
29728
29729 \family roman
29730 \series medium
29731 \shape up
29732 \size normal
29733 \emph off
29734 \bar no
29735 \noun off
29736 \color none
29737 sdcc/bin
29738 \end_layout
29739
29740 \end_inset
29741 </cell>
29742 </row>
29743 <row topline="true">
29744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29745 \begin_inset Text
29746
29747 \begin_layout Standard
29748 link-gbz80
29749 \end_layout
29750
29751 \end_inset
29752 </cell>
29753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29754 \begin_inset Text
29755
29756 \begin_layout Standard
29757 Linker
29758 \end_layout
29759
29760 \end_inset
29761 </cell>
29762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29763 \begin_inset Text
29764
29765 \begin_layout Standard
29766
29767 \family roman
29768 \series medium
29769 \shape up
29770 \size normal
29771 \emph off
29772 \bar no
29773 \noun off
29774 \color none
29775 sdcc/bin
29776 \end_layout
29777
29778 \end_inset
29779 </cell>
29780 </row>
29781 <row topline="true" bottomline="true">
29782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29783 \begin_inset Text
29784
29785 \begin_layout Standard
29786 packihx
29787 \end_layout
29788
29789 \end_inset
29790 </cell>
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29792 \begin_inset Text
29793
29794 \begin_layout Standard
29795 Intel Hex packer 
29796 \begin_inset LatexCommand \index{packihx (tool)}
29797
29798 \end_inset
29799
29800
29801 \end_layout
29802
29803 \end_inset
29804 </cell>
29805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29806 \begin_inset Text
29807
29808 \begin_layout Standard
29809
29810 \family roman
29811 \series medium
29812 \shape up
29813 \size normal
29814 \emph off
29815 \bar no
29816 \noun off
29817 \color none
29818 sdcc/bin
29819 \end_layout
29820
29821 \end_inset
29822 </cell>
29823 </row>
29824 </lyxtabular>
29825
29826 \end_inset
29827
29828
29829 \newline
29830
29831 \end_layout
29832
29833 \begin_layout Section
29834 Documentation
29835 \begin_inset LatexCommand \index{Documentation}
29836
29837 \end_inset
29838
29839  included in the distribution
29840 \end_layout
29841
29842 \begin_layout Standard
29843 \align left
29844 \begin_inset Tabular
29845 <lyxtabular version="3" rows="10" columns="2">
29846 <features>
29847 <column alignment="block" valignment="top" leftline="true" width="40col%">
29848 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29849 <row topline="true" bottomline="true" endhead="true">
29850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29851 \begin_inset Text
29852
29853 \begin_layout Standard
29854
29855 \series bold
29856 Subject / Title
29857 \end_layout
29858
29859 \end_inset
29860 </cell>
29861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29862 \begin_inset Text
29863
29864 \begin_layout Standard
29865
29866 \series bold
29867 Filename / Where to get
29868 \end_layout
29869
29870 \end_inset
29871 </cell>
29872 </row>
29873 <row topline="true">
29874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29875 \begin_inset Text
29876
29877 \begin_layout Standard
29878 SDCC Compiler User Guide
29879 \end_layout
29880
29881 \end_inset
29882 </cell>
29883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29884 \begin_inset Text
29885
29886 \begin_layout Standard
29887 You're reading it right now
29888 \emph on
29889  \InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892
29893 \hfill
29894 online at:
29895 \emph default
29896
29897 \newline
29898
29899 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29900
29901 \end_inset
29902
29903
29904 \end_layout
29905
29906 \end_inset
29907 </cell>
29908 </row>
29909 <row topline="true">
29910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29911 \begin_inset Text
29912
29913 \begin_layout Standard
29914 Changelog of SDCC
29915 \end_layout
29916
29917 \end_inset
29918 </cell>
29919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29920 \begin_inset Text
29921
29922 \begin_layout Standard
29923 sdcc/Changelog
29924 \emph on
29925  \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928
29929 \hfill
29930 online at:
29931 \emph default
29932
29933 \newline
29934
29935 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29936
29937 \end_inset
29938
29939
29940 \end_layout
29941
29942 \end_inset
29943 </cell>
29944 </row>
29945 <row topline="true">
29946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29947 \begin_inset Text
29948
29949 \begin_layout Standard
29950 ASXXXX
29951 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29952
29953 \end_inset
29954
29955
29956 \begin_inset LatexCommand \index{Assembler documentation}
29957
29958 \end_inset
29959
29960  Assemblers and
29961 \newline
29962 ASLINK
29963 \begin_inset LatexCommand \index{aslink}
29964
29965 \end_inset
29966
29967
29968 \begin_inset LatexCommand \index{Linker documentation}
29969
29970 \end_inset
29971
29972  Relocating Linker
29973 \end_layout
29974
29975 \end_inset
29976 </cell>
29977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29978 \begin_inset Text
29979
29980 \begin_layout Standard
29981 sdcc/as/doc/asxhtm.html 
29982 \emph on
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 \InsetSpace ~
29986
29987 \hfill
29988 online at:
29989 \emph default
29990
29991 \newline
29992
29993 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
29994
29995 \end_inset
29996
29997
29998 \end_layout
29999
30000 \end_inset
30001 </cell>
30002 </row>
30003 <row topline="true">
30004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30005 \begin_inset Text
30006
30007 \begin_layout Standard
30008 SDCC regression test
30009 \begin_inset LatexCommand \index{Regression test}
30010
30011 \end_inset
30012
30013
30014 \end_layout
30015
30016 \end_inset
30017 </cell>
30018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30019 \begin_inset Text
30020
30021 \begin_layout Standard
30022 sdcc/doc/test_suite_spec.pdf 
30023 \emph on
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027
30028 \hfill
30029 online at:
30030 \emph default
30031
30032 \newline
30033
30034 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30035
30036 \end_inset
30037
30038
30039 \end_layout
30040
30041 \end_inset
30042 </cell>
30043 </row>
30044 <row topline="true">
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30046 \begin_inset Text
30047
30048 \begin_layout Standard
30049 Various notes
30050 \end_layout
30051
30052 \end_inset
30053 </cell>
30054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30055 \begin_inset Text
30056
30057 \begin_layout Standard
30058 sdcc/doc/* 
30059 \emph on
30060 \InsetSpace ~
30061 \InsetSpace ~
30062 \InsetSpace ~
30063
30064 \hfill
30065 online at:
30066 \emph default
30067
30068 \newline
30069
30070 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30071
30072 \end_inset
30073
30074
30075 \end_layout
30076
30077 \end_inset
30078 </cell>
30079 </row>
30080 <row topline="true">
30081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30082 \begin_inset Text
30083
30084 \begin_layout Standard
30085 Notes on debugging with SDCDB
30086 \begin_inset LatexCommand \index{SDCDB (debugger)}
30087
30088 \end_inset
30089
30090
30091 \end_layout
30092
30093 \end_inset
30094 </cell>
30095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30096 \begin_inset Text
30097
30098 \begin_layout Standard
30099 sdcc/debugger/README 
30100 \emph on
30101 \InsetSpace ~
30102 \InsetSpace ~
30103 \InsetSpace ~
30104
30105 \hfill
30106 online at
30107 \emph default
30108 :
30109 \newline
30110
30111 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30112
30113 \end_inset
30114
30115
30116 \end_layout
30117
30118 \end_inset
30119 </cell>
30120 </row>
30121 <row topline="true">
30122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30123 \begin_inset Text
30124
30125 \begin_layout Standard
30126 uCsim
30127 \begin_inset LatexCommand \index{uCsim}
30128
30129 \end_inset
30130
30131  Software simulator for microcontrollers
30132 \end_layout
30133
30134 \end_inset
30135 </cell>
30136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30137 \begin_inset Text
30138
30139 \begin_layout Standard
30140
30141 \family roman
30142 \series medium
30143 \shape up
30144 \size normal
30145 \emph off
30146 \bar no
30147 \noun off
30148 \color none
30149 sdcc/sim/ucsim/doc
30150 \family default
30151 \series default
30152 \shape default
30153 \size default
30154 \emph default
30155 \bar default
30156 \noun default
30157 /index.html 
30158 \emph on
30159 \InsetSpace ~
30160 \InsetSpace ~
30161 \InsetSpace ~
30162
30163 \hfill
30164 online at:
30165 \emph default
30166
30167 \newline
30168
30169 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30170
30171 \end_inset
30172
30173
30174 \end_layout
30175
30176 \end_inset
30177 </cell>
30178 </row>
30179 <row topline="true">
30180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30181 \begin_inset Text
30182
30183 \begin_layout Standard
30184 Temporary notes on the pic16
30185 \begin_inset LatexCommand \index{PIC16}
30186
30187 \end_inset
30188
30189  port
30190 \end_layout
30191
30192 \end_inset
30193 </cell>
30194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30195 \begin_inset Text
30196
30197 \begin_layout Standard
30198 sdcc/src/pic16/NOTES 
30199 \emph on
30200 \InsetSpace ~
30201 \InsetSpace ~
30202 \InsetSpace ~
30203
30204 \hfill
30205 online at:
30206 \newline
30207
30208 \emph default
30209
30210 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30211
30212 \end_inset
30213
30214
30215 \end_layout
30216
30217 \end_inset
30218 </cell>
30219 </row>
30220 <row topline="true" bottomline="true">
30221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30222 \begin_inset Text
30223
30224 \begin_layout Standard
30225 SDCC internal documentation (debugging file format)
30226 \end_layout
30227
30228 \end_inset
30229 </cell>
30230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30231 \begin_inset Text
30232
30233 \begin_layout Standard
30234 sdcc/doc/
30235 \family roman
30236 \series medium
30237 \shape up
30238 \size normal
30239 \emph off
30240 \bar no
30241 \noun off
30242 \color none
30243 cdbfileformat.pd
30244 \family default
30245 \series default
30246 \shape default
30247 \size default
30248 \emph default
30249 \bar default
30250 \noun default
30251 f
30252 \emph on
30253  \InsetSpace ~
30254 \InsetSpace ~
30255 \InsetSpace ~
30256
30257 \hfill
30258 online at:
30259 \emph default
30260
30261 \newline
30262
30263 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30264
30265 \end_inset
30266
30267
30268 \end_layout
30269
30270 \end_inset
30271 </cell>
30272 </row>
30273 </lyxtabular>
30274
30275 \end_inset
30276
30277
30278 \newline
30279
30280 \end_layout
30281
30282 \begin_layout Section
30283 Related open source tools
30284 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30285
30286 \end_inset
30287
30288
30289 \begin_inset LatexCommand \index{Related tools}
30290
30291 \end_inset
30292
30293
30294 \end_layout
30295
30296 \begin_layout Standard
30297 \align left
30298 \begin_inset Tabular
30299 <lyxtabular version="3" rows="14" columns="3">
30300 <features>
30301 <column alignment="left" valignment="top" leftline="true" width="0pt">
30302 <column alignment="block" valignment="top" leftline="true" width="30line%">
30303 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30304 <row topline="true" bottomline="true">
30305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30306 \begin_inset Text
30307
30308 \begin_layout Standard
30309
30310 \series bold
30311 Name
30312 \end_layout
30313
30314 \end_inset
30315 </cell>
30316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30317 \begin_inset Text
30318
30319 \begin_layout Standard
30320
30321 \series bold
30322 Purpose
30323 \end_layout
30324
30325 \end_inset
30326 </cell>
30327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30328 \begin_inset Text
30329
30330 \begin_layout Standard
30331
30332 \series bold
30333 Where to get
30334 \end_layout
30335
30336 \end_inset
30337 </cell>
30338 </row>
30339 <row topline="true">
30340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30341 \begin_inset Text
30342
30343 \begin_layout Standard
30344 gpsim
30345 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30346
30347 \end_inset
30348
30349
30350 \end_layout
30351
30352 \end_inset
30353 </cell>
30354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30355 \begin_inset Text
30356
30357 \begin_layout Standard
30358 PIC simulator
30359 \end_layout
30360
30361 \end_inset
30362 </cell>
30363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30364 \begin_inset Text
30365
30366 \begin_layout Standard
30367 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30368
30369 \end_inset
30370
30371
30372 \end_layout
30373
30374 \end_inset
30375 </cell>
30376 </row>
30377 <row topline="true">
30378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30379 \begin_inset Text
30380
30381 \begin_layout Standard
30382 gputils
30383 \begin_inset LatexCommand \index{gputils (pic tools)}
30384
30385 \end_inset
30386
30387
30388 \end_layout
30389
30390 \end_inset
30391 </cell>
30392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30393 \begin_inset Text
30394
30395 \begin_layout Standard
30396 GNU PIC utilities
30397 \end_layout
30398
30399 \end_inset
30400 </cell>
30401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30402 \begin_inset Text
30403
30404 \begin_layout Standard
30405 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30406
30407 \end_inset
30408
30409
30410 \end_layout
30411
30412 \end_inset
30413 </cell>
30414 </row>
30415 <row topline="true">
30416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30417 \begin_inset Text
30418
30419 \begin_layout Standard
30420 flP5
30421 \end_layout
30422
30423 \end_inset
30424 </cell>
30425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30426 \begin_inset Text
30427
30428 \begin_layout Standard
30429 PIC programmer
30430 \end_layout
30431
30432 \end_inset
30433 </cell>
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30435 \begin_inset Text
30436
30437 \begin_layout Standard
30438 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30439
30440 \end_inset
30441
30442
30443 \end_layout
30444
30445 \end_inset
30446 </cell>
30447 </row>
30448 <row topline="true">
30449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30450 \begin_inset Text
30451
30452 \begin_layout Standard
30453 ec2drv/newcdb
30454 \end_layout
30455
30456 \end_inset
30457 </cell>
30458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30459 \begin_inset Text
30460
30461 \begin_layout Standard
30462 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30463  (Unix only)
30464 \end_layout
30465
30466 \end_inset
30467 </cell>
30468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30469 \begin_inset Text
30470
30471 \begin_layout Standard
30472 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30473
30474 \end_inset
30475
30476
30477 \end_layout
30478
30479 \end_inset
30480 </cell>
30481 </row>
30482 <row topline="true">
30483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30484 \begin_inset Text
30485
30486 \begin_layout Standard
30487 indent
30488 \begin_inset LatexCommand \index{indent (source formatting tool)}
30489
30490 \end_inset
30491
30492
30493 \end_layout
30494
30495 \end_inset
30496 </cell>
30497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30498 \begin_inset Text
30499
30500 \begin_layout Standard
30501 Formats C source - Master of the white spaces
30502 \end_layout
30503
30504 \end_inset
30505 </cell>
30506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30507 \begin_inset Text
30508
30509 \begin_layout Standard
30510 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30511
30512 \end_inset
30513
30514
30515 \end_layout
30516
30517 \end_inset
30518 </cell>
30519 </row>
30520 <row topline="true">
30521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30522 \begin_inset Text
30523
30524 \begin_layout Standard
30525 srecord
30526 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30527
30528 \end_inset
30529
30530
30531 \end_layout
30532
30533 \end_inset
30534 </cell>
30535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30536 \begin_inset Text
30537
30538 \begin_layout Standard
30539 Object file conversion, checksumming, ...
30540 \end_layout
30541
30542 \end_inset
30543 </cell>
30544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30545 \begin_inset Text
30546
30547 \begin_layout Standard
30548 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30549
30550 \end_inset
30551
30552
30553 \end_layout
30554
30555 \end_inset
30556 </cell>
30557 </row>
30558 <row topline="true">
30559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30560 \begin_inset Text
30561
30562 \begin_layout Standard
30563 objdump
30564 \begin_inset LatexCommand \index{objdump (tool)}
30565
30566 \end_inset
30567
30568
30569 \end_layout
30570
30571 \end_inset
30572 </cell>
30573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30574 \begin_inset Text
30575
30576 \begin_layout Standard
30577 Object file conversion, ...
30578 \end_layout
30579
30580 \end_inset
30581 </cell>
30582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30583 \begin_inset Text
30584
30585 \begin_layout Standard
30586 Part of binutils (should be there anyway)
30587 \end_layout
30588
30589 \end_inset
30590 </cell>
30591 </row>
30592 <row topline="true">
30593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30594 \begin_inset Text
30595
30596 \begin_layout Standard
30597 cmon51
30598 \end_layout
30599
30600 \end_inset
30601 </cell>
30602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30603 \begin_inset Text
30604
30605 \begin_layout Standard
30606 8051 monitor (hex up-/download, single step, disassemble)
30607 \end_layout
30608
30609 \end_inset
30610 </cell>
30611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30612 \begin_inset Text
30613
30614 \begin_layout Standard
30615 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30616
30617 \end_inset
30618
30619
30620 \end_layout
30621
30622 \end_inset
30623 </cell>
30624 </row>
30625 <row topline="true">
30626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30627 \begin_inset Text
30628
30629 \begin_layout Standard
30630 doxygen
30631 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30632
30633 \end_inset
30634
30635
30636 \end_layout
30637
30638 \end_inset
30639 </cell>
30640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30641 \begin_inset Text
30642
30643 \begin_layout Standard
30644 Source code documentation system
30645 \end_layout
30646
30647 \end_inset
30648 </cell>
30649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30650 \begin_inset Text
30651
30652 \begin_layout Standard
30653 \begin_inset LatexCommand \url{http://www.doxygen.org}
30654
30655 \end_inset
30656
30657
30658 \end_layout
30659
30660 \end_inset
30661 </cell>
30662 </row>
30663 <row topline="true">
30664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30665 \begin_inset Text
30666
30667 \begin_layout Standard
30668 kdevelop
30669 \end_layout
30670
30671 \end_inset
30672 </cell>
30673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30674 \begin_inset Text
30675
30676 \begin_layout Standard
30677 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30678 \end_layout
30679
30680 \end_inset
30681 </cell>
30682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30683 \begin_inset Text
30684
30685 \begin_layout Standard
30686 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30687
30688 \end_inset
30689
30690
30691 \end_layout
30692
30693 \end_inset
30694 </cell>
30695 </row>
30696 <row topline="true">
30697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30698 \begin_inset Text
30699
30700 \begin_layout Standard
30701 paulmon
30702 \end_layout
30703
30704 \end_inset
30705 </cell>
30706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30707 \begin_inset Text
30708
30709 \begin_layout Standard
30710 8051 monitor (hex up-/download, single step, disassemble)
30711 \end_layout
30712
30713 \end_inset
30714 </cell>
30715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30716 \begin_inset Text
30717
30718 \begin_layout Standard
30719 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30720
30721 \end_inset
30722
30723
30724 \end_layout
30725
30726 \end_inset
30727 </cell>
30728 </row>
30729 <row topline="true">
30730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30731 \begin_inset Text
30732
30733 \begin_layout Standard
30734 splint
30735 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30736
30737 \end_inset
30738
30739
30740 \end_layout
30741
30742 \end_inset
30743 </cell>
30744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30745 \begin_inset Text
30746
30747 \begin_layout Standard
30748 Statically checks c sources (see 
30749 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30750
30751 \end_inset
30752
30753 )
30754 \end_layout
30755
30756 \end_inset
30757 </cell>
30758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30759 \begin_inset Text
30760
30761 \begin_layout Standard
30762 \begin_inset LatexCommand \url{http://www.splint.org}
30763
30764 \end_inset
30765
30766
30767 \end_layout
30768
30769 \end_inset
30770 </cell>
30771 </row>
30772 <row topline="true" bottomline="true">
30773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30774 \begin_inset Text
30775
30776 \begin_layout Standard
30777 ddd
30778 \begin_inset LatexCommand \index{DDD (debugger)}
30779
30780 \end_inset
30781
30782
30783 \end_layout
30784
30785 \end_inset
30786 </cell>
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30788 \begin_inset Text
30789
30790 \begin_layout Standard
30791 Debugger, serves nicely as GUI to SDCDB
30792 \begin_inset LatexCommand \index{SDCDB (debugger)}
30793
30794 \end_inset
30795
30796  (Unix only)
30797 \end_layout
30798
30799 \end_inset
30800 </cell>
30801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30802 \begin_inset Text
30803
30804 \begin_layout Standard
30805 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30806
30807 \end_inset
30808
30809
30810 \end_layout
30811
30812 \end_inset
30813 </cell>
30814 </row>
30815 </lyxtabular>
30816
30817 \end_inset
30818
30819
30820 \newline
30821
30822 \end_layout
30823
30824 \begin_layout Section
30825 Related documentation / recommended reading
30826 \end_layout
30827
30828 \begin_layout Standard
30829 \align left
30830 \begin_inset Tabular
30831 <lyxtabular version="3" rows="7" columns="3">
30832 <features>
30833 <column alignment="left" valignment="top" leftline="true" width="0pt">
30834 <column alignment="left" valignment="top" leftline="true" width="0">
30835 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30836 <row topline="true" bottomline="true">
30837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30838 \begin_inset Text
30839
30840 \begin_layout Standard
30841
30842 \series bold
30843 Name
30844 \end_layout
30845
30846 \end_inset
30847 </cell>
30848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30849 \begin_inset Text
30850
30851 \begin_layout Standard
30852
30853 \series bold
30854 Subject / Title
30855 \end_layout
30856
30857 \end_inset
30858 </cell>
30859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30860 \begin_inset Text
30861
30862 \begin_layout Standard
30863
30864 \series bold
30865 Where to get
30866 \end_layout
30867
30868 \end_inset
30869 </cell>
30870 </row>
30871 <row topline="true">
30872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30873 \begin_inset Text
30874
30875 \begin_layout Standard
30876
30877 \family roman
30878 \series medium
30879 \shape up
30880 \size normal
30881 \emph off
30882 \bar no
30883 \noun off
30884 \color none
30885 c-refcard.pdf
30886 \end_layout
30887
30888 \end_inset
30889 </cell>
30890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30891 \begin_inset Text
30892
30893 \begin_layout Standard
30894 C Reference Card
30895 \begin_inset LatexCommand \index{C Reference card}
30896
30897 \end_inset
30898
30899 , 2 pages
30900 \end_layout
30901
30902 \end_inset
30903 </cell>
30904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30905 \begin_inset Text
30906
30907 \begin_layout Standard
30908 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30909
30910 \end_inset
30911
30912
30913 \end_layout
30914
30915 \end_inset
30916 </cell>
30917 </row>
30918 <row topline="true">
30919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30920 \begin_inset Text
30921
30922 \begin_layout Standard
30923 c-faq
30924 \end_layout
30925
30926 \end_inset
30927 </cell>
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30929 \begin_inset Text
30930
30931 \begin_layout Standard
30932 C-FAQ
30933 \begin_inset LatexCommand \index{C FAQ}
30934
30935 \end_inset
30936
30937
30938 \end_layout
30939
30940 \end_inset
30941 </cell>
30942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30943 \begin_inset Text
30944
30945 \begin_layout Standard
30946 \begin_inset LatexCommand \url{http://www.c-faq.com}
30947
30948 \end_inset
30949
30950
30951 \end_layout
30952
30953 \end_inset
30954 </cell>
30955 </row>
30956 <row topline="true">
30957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30958 \begin_inset Text
30959
30960 \begin_layout Standard
30961 ISO/IEC 9899:TC2
30962 \end_layout
30963
30964 \end_inset
30965 </cell>
30966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30967 \begin_inset Text
30968
30969 \begin_layout Standard
30970 \begin_inset Quotes sld
30971 \end_inset
30972
30973 C-Standard
30974 \begin_inset Quotes srd
30975 \end_inset
30976
30977
30978 \end_layout
30979
30980 \end_inset
30981 </cell>
30982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30983 \begin_inset Text
30984
30985 \begin_layout Standard
30986
30987 \size footnotesize
30988 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30989
30990 \end_inset
30991
30992
30993 \end_layout
30994
30995 \end_inset
30996 </cell>
30997 </row>
30998 <row topline="true">
30999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31000 \begin_inset Text
31001
31002 \begin_layout Standard
31003 ISO/IEC DTR 18037
31004 \end_layout
31005
31006 \end_inset
31007 </cell>
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31009 \begin_inset Text
31010
31011 \begin_layout Standard
31012 \begin_inset Quotes sld
31013 \end_inset
31014
31015 Extensions for Embedded C
31016 \begin_inset Quotes srd
31017 \end_inset
31018
31019
31020 \end_layout
31021
31022 \end_inset
31023 </cell>
31024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31025 \begin_inset Text
31026
31027 \begin_layout Standard
31028
31029 \size footnotesize
31030 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31031
31032 \end_inset
31033
31034
31035 \end_layout
31036
31037 \end_inset
31038 </cell>
31039 </row>
31040 <row topline="true">
31041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31042 \begin_inset Text
31043
31044 \begin_layout Standard
31045
31046 \end_layout
31047
31048 \end_inset
31049 </cell>
31050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31051 \begin_inset Text
31052
31053 \begin_layout Standard
31054 Latest datasheet of target CPU
31055 \end_layout
31056
31057 \end_inset
31058 </cell>
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31060 \begin_inset Text
31061
31062 \begin_layout Standard
31063 vendor
31064 \end_layout
31065
31066 \end_inset
31067 </cell>
31068 </row>
31069 <row topline="true" bottomline="true">
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31071 \begin_inset Text
31072
31073 \begin_layout Standard
31074
31075 \end_layout
31076
31077 \end_inset
31078 </cell>
31079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31080 \begin_inset Text
31081
31082 \begin_layout Standard
31083 Revision history of datasheet
31084 \end_layout
31085
31086 \end_inset
31087 </cell>
31088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31089 \begin_inset Text
31090
31091 \begin_layout Standard
31092 vendor
31093 \end_layout
31094
31095 \end_inset
31096 </cell>
31097 </row>
31098 </lyxtabular>
31099
31100 \end_inset
31101
31102
31103 \newline
31104
31105 \end_layout
31106
31107 \begin_layout Section
31108 Application notes specifically for SDCC
31109 \end_layout
31110
31111 \begin_layout Standard
31112 SDCC makes no claims about the completeness of this list and about up-to-datenes
31113 s or correctness of the application notes
31114 \begin_inset LatexCommand \index{Application notes}
31115
31116 \end_inset
31117
31118 .
31119 \end_layout
31120
31121 \begin_layout Standard
31122 \align left
31123
31124 \size footnotesize
31125 \begin_inset Tabular
31126 <lyxtabular version="3" rows="7" columns="3">
31127 <features>
31128 <column alignment="block" valignment="top" leftline="true" width="17col%">
31129 <column alignment="block" valignment="top" leftline="true" width="27col%">
31130 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31131 <row topline="true" bottomline="true">
31132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31133 \begin_inset Text
31134
31135 \begin_layout Standard
31136
31137 \series bold
31138 \size footnotesize
31139 Vendor
31140 \end_layout
31141
31142 \end_inset
31143 </cell>
31144 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31145 \begin_inset Text
31146
31147 \begin_layout Standard
31148
31149 \series bold
31150 \size footnotesize
31151 Subject / Title
31152 \end_layout
31153
31154 \end_inset
31155 </cell>
31156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31157 \begin_inset Text
31158
31159 \begin_layout Standard
31160
31161 \series bold
31162 \size footnotesize
31163 Where to get
31164 \end_layout
31165
31166 \end_inset
31167 </cell>
31168 </row>
31169 <row topline="true">
31170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31171 \begin_inset Text
31172
31173 \begin_layout Standard
31174
31175 \size footnotesize
31176 Maxim / Dallas
31177 \end_layout
31178
31179 \end_inset
31180 </cell>
31181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31182 \begin_inset Text
31183
31184 \begin_layout Standard
31185
31186 \size footnotesize
31187 Using the SDCC Compiler for the DS80C400
31188 \begin_inset LatexCommand \index{DS80C400}
31189
31190 \end_inset
31191
31192
31193 \end_layout
31194
31195 \end_inset
31196 </cell>
31197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31198 \begin_inset Text
31199
31200 \begin_layout Standard
31201
31202 \size footnotesize
31203 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31204
31205 \end_inset
31206
31207
31208 \end_layout
31209
31210 \end_inset
31211 </cell>
31212 </row>
31213 <row topline="true">
31214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31215 \begin_inset Text
31216
31217 \begin_layout Standard
31218
31219 \size footnotesize
31220 Maxim / Dallas
31221 \end_layout
31222
31223 \end_inset
31224 </cell>
31225 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31226 \begin_inset Text
31227
31228 \begin_layout Standard
31229
31230 \size footnotesize
31231 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31232 \begin_inset LatexCommand \index{DS89C4x0}
31233
31234 \end_inset
31235
31236  Family of Microcontrollers
31237 \end_layout
31238
31239 \end_inset
31240 </cell>
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31242 \begin_inset Text
31243
31244 \begin_layout Standard
31245
31246 \size footnotesize
31247 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31248
31249 \end_inset
31250
31251
31252 \end_layout
31253
31254 \end_inset
31255 </cell>
31256 </row>
31257 <row topline="true">
31258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31259 \begin_inset Text
31260
31261 \begin_layout Standard
31262
31263 \size footnotesize
31264 Silicon Laboratories / Cygnal
31265 \end_layout
31266
31267 \end_inset
31268 </cell>
31269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31270 \begin_inset Text
31271
31272 \begin_layout Standard
31273
31274 \size footnotesize
31275 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31276 \begin_inset LatexCommand \index{IDE}
31277
31278 \end_inset
31279
31280
31281 \end_layout
31282
31283 \end_inset
31284 </cell>
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31286 \begin_inset Text
31287
31288 \begin_layout Standard
31289
31290 \size footnotesize
31291 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31292
31293 \end_inset
31294
31295
31296 \end_layout
31297
31298 \end_inset
31299 </cell>
31300 </row>
31301 <row topline="true">
31302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31303 \begin_inset Text
31304
31305 \begin_layout Standard
31306
31307 \size footnotesize
31308 Ramtron / Goal Semiconductor
31309 \end_layout
31310
31311 \end_inset
31312 </cell>
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31314 \begin_inset Text
31315
31316 \begin_layout Standard
31317
31318 \size footnotesize
31319 Interfacing SDCC to Syn and Textpad
31320 \end_layout
31321
31322 \end_inset
31323 </cell>
31324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31325 \begin_inset Text
31326
31327 \begin_layout Standard
31328
31329 \size footnotesize
31330 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31331
31332 \end_inset
31333
31334
31335 \end_layout
31336
31337 \end_inset
31338 </cell>
31339 </row>
31340 <row topline="true">
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31342 \begin_inset Text
31343
31344 \begin_layout Standard
31345
31346 \size footnotesize
31347 Ramtron / Goal Semiconductor
31348 \end_layout
31349
31350 \end_inset
31351 </cell>
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31353 \begin_inset Text
31354
31355 \begin_layout Standard
31356
31357 \size footnotesize
31358 Installing and Configuring SDCC and Crimson Editor 
31359 \end_layout
31360
31361 \end_inset
31362 </cell>
31363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31364 \begin_inset Text
31365
31366 \begin_layout Standard
31367
31368 \size footnotesize
31369 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31370
31371 \end_inset
31372
31373
31374 \end_layout
31375
31376 \end_inset
31377 </cell>
31378 </row>
31379 <row topline="true" bottomline="true">
31380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31381 \begin_inset Text
31382
31383 \begin_layout Standard
31384
31385 \size footnotesize
31386 Texas Instruments
31387 \end_layout
31388
31389 \end_inset
31390 </cell>
31391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31392 \begin_inset Text
31393
31394 \begin_layout Standard
31395
31396 \size footnotesize
31397 MSC12xx Programming with SDCC
31398 \end_layout
31399
31400 \end_inset
31401 </cell>
31402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31403 \begin_inset Text
31404
31405 \begin_layout Standard
31406
31407 \size footnotesize
31408 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31409
31410 \end_inset
31411
31412
31413 \end_layout
31414
31415 \end_inset
31416 </cell>
31417 </row>
31418 </lyxtabular>
31419
31420 \end_inset
31421
31422
31423 \end_layout
31424
31425 \begin_layout Section
31426 Some Questions
31427 \end_layout
31428
31429 \begin_layout Standard
31430 Some questions answered, some pointers given - it might be time to in turn
31431  ask 
31432 \emph on
31433 you
31434 \emph default
31435  some questions: 
31436 \end_layout
31437
31438 \begin_layout Itemize
31439 can you solve your project with the selected microcontroller? Would you
31440  find out early or rather late that your target is too small/slow/whatever?
31441  Can you switch to a slightly better device if it doesn't fit?
31442 \end_layout
31443
31444 \begin_layout Itemize
31445 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31446  and/or another programming language be more adequate? Would an operating
31447  system on the target device help?
31448 \end_layout
31449
31450 \begin_layout Itemize
31451 if you solved the problem, will the marketing department be happy?
31452 \end_layout
31453
31454 \begin_layout Itemize
31455 if the marketing department is happy, will customers be happy?
31456 \end_layout
31457
31458 \begin_layout Itemize
31459 if you're the project manager, marketing department and maybe even the customer
31460  in one person, have you tried to see the project from the outside?
31461 \end_layout
31462
31463 \begin_layout Itemize
31464 is the project done if you think it is done? Or is just that other interface/pro
31465 tocol/feature/configuration/option missing? How about website, manual(s),
31466  internationali(z|s)ation, packaging, labels, 2nd source for components,
31467  electromagnetic compatability/interference, documentation for production,
31468  production test software, update mechanism, patent issues?
31469 \end_layout
31470
31471 \begin_layout Itemize
31472 is your project adequately positioned in that magic triangle: fame, fortune,
31473  fun?
31474 \end_layout
31475
31476 \begin_layout Standard
31477 Maybe not all answers to these questions are known and some answers may
31478  even be 
31479 \emph on
31480 no
31481 \emph default
31482 , nevertheless knowing these questions may help you to avoid burnout
31483 \begin_inset Foot
31484 status open
31485
31486 \begin_layout Standard
31487 burnout is bad for electronic devices, programmers and motorcycle tyres
31488 \end_layout
31489
31490 \end_inset
31491
31492 .
31493  Chances are you didn't want to hear some of them...
31494 \end_layout
31495
31496 \begin_layout Chapter
31497 Support
31498 \begin_inset LatexCommand \index{Support}
31499
31500 \end_inset
31501
31502
31503 \end_layout
31504
31505 \begin_layout Standard
31506 SDCC has grown to be a large project.
31507  The compiler alone (without the preprocessor, assembler and linker) is
31508  well over 150,000 lines of code (blank stripped).
31509  The open source nature of this project is a key to its continued growth
31510  and support.
31511  You gain the benefit and support of many active software developers and
31512  end users.
31513  Is SDCC perfect? No, that's why we need your help.
31514  The developers take pride in fixing reported bugs.
31515  You can help by reporting the bugs and helping other SDCC users.
31516  There are lots of ways to contribute, and we encourage you to take part
31517  in making SDCC a great software package.
31518  
31519 \end_layout
31520
31521 \begin_layout Standard
31522 The SDCC project is hosted on the SDCC sourceforge site at 
31523 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31524
31525 \end_inset
31526
31527 .
31528  You'll find the complete set of mailing lists
31529 \begin_inset LatexCommand \index{Mailing list(s)}
31530
31531 \end_inset
31532
31533 , forums, bug reporting system, patch submission
31534 \begin_inset LatexCommand \index{Patch submission}
31535
31536 \end_inset
31537
31538  system, download
31539 \begin_inset LatexCommand \index{download}
31540
31541 \end_inset
31542
31543  area and Subversion code repository
31544 \begin_inset LatexCommand \index{Subversion code repository}
31545
31546 \end_inset
31547
31548  there.
31549 \end_layout
31550
31551 \begin_layout Section
31552 Reporting Bugs
31553 \begin_inset LatexCommand \index{Bug reporting}
31554
31555 \end_inset
31556
31557
31558 \begin_inset LatexCommand \index{Reporting bugs}
31559
31560 \end_inset
31561
31562
31563 \end_layout
31564
31565 \begin_layout Standard
31566 The recommended way of reporting bugs is using the infrastructure of the
31567  sourceforge site.
31568  You can follow the status of bug reports there and have an overview about
31569  the known bugs.
31570 \end_layout
31571
31572 \begin_layout Standard
31573 Bug reports are automatically forwarded to the developer mailing list and
31574  will be fixed ASAP.
31575  When reporting a bug, it is very useful to include a small test program
31576  (the smaller the better) which reproduces the problem.
31577  If you can isolate the problem by looking at the generated assembly code,
31578  this can be very helpful.
31579  Compiling your program with the -
31580 \begin_inset ERT
31581 status collapsed
31582
31583 \begin_layout Standard
31584
31585
31586 \backslash
31587 /
31588 \end_layout
31589
31590 \end_inset
31591
31592 -dumpall
31593 \begin_inset LatexCommand \index{-\/-dumpall}
31594
31595 \end_inset
31596
31597  option can sometimes be useful in locating optimization problems.
31598  When reporting a bug please make sure you:
31599 \end_layout
31600
31601 \begin_layout Enumerate
31602 Attach the code you are compiling with SDCC.
31603  
31604 \end_layout
31605
31606 \begin_layout Enumerate
31607 Specify the exact command you use to run SDCC, or attach your Makefile.
31608  
31609 \end_layout
31610
31611 \begin_layout Enumerate
31612 Specify the SDCC version (type "
31613 \family sans
31614 \series bold
31615 sdcc -v
31616 \family default
31617 \series default
31618 "), your platform, and operating system.
31619  
31620 \end_layout
31621
31622 \begin_layout Enumerate
31623 Provide an exact copy of any error message or incorrect output.
31624  
31625 \end_layout
31626
31627 \begin_layout Enumerate
31628 Put something meaningful in the subject of your message.
31629 \end_layout
31630
31631 \begin_layout Standard
31632 Please attempt to include these 5 important parts, as applicable, in all
31633  requests for support or when reporting any problems or bugs with SDCC.
31634  Though this will make your message lengthy, it will greatly improve your
31635  chance that SDCC users and developers will be able to help you.
31636  Some SDCC developers are frustrated by bug reports without code provided
31637  that they can use to reproduce and ultimately fix the problem, so please
31638  be sure to provide sample code if you are reporting a bug! 
31639 \end_layout
31640
31641 \begin_layout Standard
31642 Please have a short check that you are using a recent version of SDCC and
31643  the bug is not yet known.
31644  This is the link for reporting bugs: 
31645 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31646
31647 \end_inset
31648
31649 .
31650  With SDCC on average having more than 200 downloads
31651 \begin_inset LatexCommand \index{download}
31652
31653 \end_inset
31654
31655  on sourceforge per day
31656 \begin_inset Foot
31657 status open
31658
31659 \begin_layout Standard
31660 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31661  between 2002 and 2005.
31662  This does not include other methods of distribution.
31663 \end_layout
31664
31665 \end_inset
31666
31667  there must be some users.
31668  So it's not exactly easy to find a new bug.
31669  If you find one we need it: 
31670 \emph on
31671 reporting bugs is good
31672 \emph default
31673 .
31674 \end_layout
31675
31676 \begin_layout Section
31677 Requesting Features
31678 \begin_inset LatexCommand \label{sub:Requesting-Features}
31679
31680 \end_inset
31681
31682
31683 \begin_inset LatexCommand \index{Feature request}
31684
31685 \end_inset
31686
31687
31688 \begin_inset LatexCommand \index{Requesting features}
31689
31690 \end_inset
31691
31692
31693 \end_layout
31694
31695 \begin_layout Standard
31696 Like bug reports feature requests are forwarded to the developer mailing
31697  list.
31698  This is the link for requesting features: 
31699 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31700
31701 \end_inset
31702
31703 .
31704 \end_layout
31705
31706 \begin_layout Section
31707 Submitting patches
31708 \end_layout
31709
31710 \begin_layout Standard
31711 Like bug reports contributed patches are forwarded to the developer mailing
31712  list.
31713  This is the link for submitting patches
31714 \begin_inset LatexCommand \index{Patch submission}
31715
31716 \end_inset
31717
31718
31719 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31720
31721 \end_inset
31722
31723 .
31724 \end_layout
31725
31726 \begin_layout Standard
31727 You need to specify some parameters to the 
31728 \family typewriter
31729 diff
31730 \family default
31731  command for the patches to be useful.
31732  If you modified more than one file a patch created f.e.
31733  with 
31734 \family sans
31735 \series bold
31736
31737 \begin_inset Quotes sld
31738 \end_inset
31739
31740 diff -Naur unmodified_directory modified_directory >my_changes.patch
31741 \begin_inset Quotes srd
31742 \end_inset
31743
31744
31745 \family default
31746 \series default
31747  will be fine, otherwise 
31748 \family sans
31749 \series bold
31750
31751 \begin_inset Quotes sld
31752 \end_inset
31753
31754 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31755 \begin_inset Quotes srd
31756 \end_inset
31757
31758
31759 \series default
31760  
31761 \family default
31762 will do.
31763 \end_layout
31764
31765 \begin_layout Section
31766 Getting Help
31767 \end_layout
31768
31769 \begin_layout Standard
31770 These links should take you directly to the 
31771 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31772
31773 \end_inset
31774
31775
31776 \begin_inset Foot
31777 status open
31778
31779 \begin_layout Standard
31780 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31781  automated messages (mid 2003)
31782 \end_layout
31783
31784 \end_inset
31785
31786  and the 
31787 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31788
31789 \end_inset
31790
31791 , lists
31792 \begin_inset LatexCommand \index{Mailing list(s)}
31793
31794 \end_inset
31795
31796  and forums are archived and searchable so if you are lucky someone already
31797  had a similar problem.
31798  While mails to the lists themselves are delivered promptly their web front
31799  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31800  if you're seriously using SDCC please consider subscribing to the lists.
31801 \end_layout
31802
31803 \begin_layout Section
31804 ChangeLog
31805 \end_layout
31806
31807 \begin_layout Standard
31808 You can follow the status of the Subversion version
31809 \begin_inset LatexCommand \index{version}
31810
31811 \end_inset
31812
31813  of SDCC by watching the Changelog
31814 \begin_inset LatexCommand \index{Changelog}
31815
31816 \end_inset
31817
31818  in the Subversion repository
31819 \size footnotesize
31820  
31821 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31822
31823 \end_inset
31824
31825 .
31826 \end_layout
31827
31828 \begin_layout Section
31829 Subversion Source Code Repository
31830 \end_layout
31831
31832 \begin_layout Standard
31833 The output of 
31834 \family sans
31835 \series bold
31836 sdcc --version
31837 \family default
31838 \series default
31839  or the filenames of the snapshot versions of SDCC include date and its
31840  Subversion
31841 \begin_inset LatexCommand \index{Subversion code repository}
31842
31843 \end_inset
31844
31845  number.
31846  Subversion allows to download the source of recent or previous versions
31847  
31848 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31849
31850 \end_inset
31851
31852  (by number or by date).
31853  An on-line source code browser and detailled instructions are also available
31854  there.
31855  SDCC versions starting from 1999 up to now are available (currently the
31856  versions prior to the conversion from cvs
31857 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31858
31859 \end_inset
31860
31861  to Subversion (April 2006) are either by accessible by Subversion or by
31862  cvs).
31863 \end_layout
31864
31865 \begin_layout Section
31866 Release policy
31867 \begin_inset LatexCommand \index{Release policy}
31868
31869 \end_inset
31870
31871
31872 \end_layout
31873
31874 \begin_layout Standard
31875 Historically there often were long delays between official releases and
31876  the sourceforge download area tends to get not updated at all.
31877  Excuses in the past might have referred to problems with live range analysis,
31878  but as this was fixed a while ago, the current problem is that another
31879  excuse has to be found.
31880  Kidding aside, we have to get better there! On the other hand there are
31881  daily snapshots available at 
31882 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31883
31884 \end_inset
31885
31886 , and you can always build the very last version (hopefully with many bugs
31887  fixed, and features added) from the source code available at 
31888 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31889
31890 \end_inset
31891
31892 .
31893  A release wiki
31894 \begin_inset LatexCommand \index{wiki}
31895
31896 \end_inset
31897
31898
31899 \begin_inset LatexCommand \index{Release wiki}
31900
31901 \end_inset
31902
31903  at 
31904 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31905
31906 \end_inset
31907
31908  also holds some information about past and future releases.
31909 \end_layout
31910
31911 \begin_layout Section
31912 Examples
31913 \begin_inset LatexCommand \index{Examples}
31914
31915 \end_inset
31916
31917
31918 \end_layout
31919
31920 \begin_layout Standard
31921 You'll find some small examples in the directory 
31922 \emph on
31923 sdcc/device/examples/.
31924  
31925 \emph default
31926 More examples and libraries are available at
31927 \emph on
31928  The SDCC Open Knowledge Resource 
31929 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31930
31931 \end_inset
31932
31933  
31934 \emph default
31935 web site or at 
31936 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31937
31938 \end_inset
31939
31940 .
31941 \end_layout
31942
31943 \begin_layout Standard
31944 \begin_inset Note Note
31945 status collapsed
31946
31947 \begin_layout Standard
31948 I did insert a reference to Paul's web site here although it seems rather
31949  dedicated to a specific 8032 board (I think it's okay because it f.e.
31950  shows LCD/Harddisc interface and has a free 8051 monitor.
31951  Independent 8032 board vendors face hard competition of heavily subsidized
31952  development boards anyway).
31953 \end_layout
31954
31955 \begin_layout Standard
31956 Maybe we should include some links to real world applications.
31957  Preferably pointer to pointers (one for each architecture) so this stays
31958  manageable here?
31959 \end_layout
31960
31961 \end_inset
31962
31963
31964 \end_layout
31965
31966 \begin_layout Section
31967 Quality control
31968 \begin_inset LatexCommand \label{sec:Quality-control}
31969
31970 \end_inset
31971
31972
31973 \begin_inset LatexCommand \index{Quality control}
31974
31975 \end_inset
31976
31977
31978 \end_layout
31979
31980 \begin_layout Standard
31981 The compiler is passed through snaphot build compile and build checks.
31982  The so called 
31983 \shape italic
31984 regression tests
31985 \shape default
31986
31987 \begin_inset LatexCommand \index{Regression test}
31988
31989 \end_inset
31990
31991  check that SDCC itself compiles flawlessly on several host platforms (i386,
31992  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
31993  the quality of the code generated by SDCC by running the code for several
31994  target platforms through simulators.
31995  The regression test suite comprises more than 100 files which expand to
31996  more than 500 test cases which include more than 4500 tests.
31997  The results of these tests are published daily on SDCC's snapshot page
31998  (click on the red or green symbols on the right side of 
31999 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32000
32001 \end_inset
32002
32003 ).
32004 \end_layout
32005
32006 \begin_layout Standard
32007 There is a separate document 
32008 \shape italic
32009 test_suite.pdf 
32010 \begin_inset LatexCommand \index{Test suite}
32011
32012 \end_inset
32013
32014
32015 \shape default
32016  
32017 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32018
32019 \end_inset
32020
32021  about the regression test suite.
32022 \end_layout
32023
32024 \begin_layout Standard
32025 You'll find the test code in the directory 
32026 \shape italic
32027 sdcc/support/regression
32028 \shape default
32029 .
32030  You can run these tests manually by running 
32031 \family sans
32032 make
32033 \family default
32034  in this directory (or f.e.
32035  
32036 \family sans
32037 \series bold
32038
32039 \begin_inset Quotes sld
32040 \end_inset
32041
32042 make test-mcs51
32043 \begin_inset Quotes srd
32044 \end_inset
32045
32046
32047 \family default
32048 \series default
32049  if you don't want to run the complete tests).
32050  The test code might also be interesting if you want to look for examples
32051 \begin_inset LatexCommand \index{Examples}
32052
32053 \end_inset
32054
32055  checking corner cases of SDCC or if you plan to submit patches
32056 \begin_inset LatexCommand \index{Patch submission}
32057
32058 \end_inset
32059
32060 .
32061 \end_layout
32062
32063 \begin_layout Standard
32064 The 14bit pic port uses a different set of regression tests 
32065 \begin_inset LatexCommand \index{Regression test (PIC14)}
32066
32067 \end_inset
32068
32069 , you'll find them in the directory 
32070 \shape italic
32071 sdcc/src/regression
32072 \shape default
32073 .
32074 \end_layout
32075
32076 \begin_layout Section
32077 Use of SDCC in Education
32078 \end_layout
32079
32080 \begin_layout Standard
32081 In short: 
32082 \emph on
32083 highly
32084 \emph default
32085  encouraged
32086 \begin_inset Foot
32087 status open
32088
32089 \begin_layout Standard
32090 the phrase "use in education" might evoke the association "
32091 \emph on
32092 only
32093 \emph default
32094  fit for use in education".
32095  This connotation is not intended but nevertheless risked as the licensing
32096  of SDCC makes it difficult to offer educational discounts
32097 \end_layout
32098
32099 \end_inset
32100
32101 .
32102  If your rationales are to:
32103 \end_layout
32104
32105 \begin_layout Enumerate
32106 give students a chance to understand the 
32107 \emph on
32108 complete
32109 \emph default
32110  steps of code generation
32111 \end_layout
32112
32113 \begin_layout Enumerate
32114 have a curriculum that can be extended for years.
32115  Then you could use an fpga board as target and your curriculum will seamlessly
32116  extend from logic synthesis (
32117 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32118
32119 \end_inset
32120
32121
32122 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32123
32124 \end_inset
32125
32126 ), over assembly programming, to C to FPGA compilers (
32127 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32128
32129 \end_inset
32130
32131 ) and to C.
32132 \end_layout
32133
32134 \begin_layout Enumerate
32135 be able to insert excursions about skills like using a revision control
32136  system, submitting/applying patches, using a type-setting (as opposed to
32137  word-processing) engine LyX/LaTeX, using 
32138 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32139
32140 \end_inset
32141
32142 , following some 
32143 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32144
32145 \end_inset
32146
32147 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32148  Source Software, CPU simulation, compiler regression tests
32149 \begin_inset LatexCommand \index{Regression test}
32150
32151 \end_inset
32152
32153 .
32154  
32155 \newline
32156 And if there should be a shortage of ideas then you can always point students
32157  to the ever-growing feature request list 
32158 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32159
32160 \end_inset
32161
32162 .
32163 \end_layout
32164
32165 \begin_layout Enumerate
32166 not tie students to a specific host platform and instead allow them to use
32167  a host platform of 
32168 \emph on
32169 their
32170 \emph default
32171  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
32172  eventually 
32173 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32174
32175 \end_inset
32176
32177 )
32178 \end_layout
32179
32180 \begin_layout Enumerate
32181 not encourage students to use illegal copies of educational software
32182 \end_layout
32183
32184 \begin_layout Enumerate
32185 be immune to licensing/availability/price changes of the chosen tool chain
32186 \end_layout
32187
32188 \begin_layout Enumerate
32189 be able to change to a new target platform without having to adopt a new
32190  tool chain
32191 \end_layout
32192
32193 \begin_layout Enumerate
32194 have complete control over and insight into the tool chain
32195 \end_layout
32196
32197 \begin_layout Enumerate
32198 make your students aware about the pros and cons of open source software
32199  development
32200 \end_layout
32201
32202 \begin_layout Enumerate
32203 give back to the public as you are probably at least partially publically
32204  funded
32205 \end_layout
32206
32207 \begin_layout Enumerate
32208 give students a chance to publically prove their skills and to possibly
32209  see a world wide impact
32210 \end_layout
32211
32212 \begin_layout Standard
32213 then SDCC is probably among the first choices.
32214  Well, probably SDCC might be the only choice.
32215 \newpage
32216
32217 \end_layout
32218
32219 \begin_layout Chapter
32220 SDCC Technical Data
32221 \end_layout
32222
32223 \begin_layout Section
32224 Optimizations
32225 \begin_inset LatexCommand \index{Optimizations}
32226
32227 \end_inset
32228
32229
32230 \end_layout
32231
32232 \begin_layout Standard
32233 SDCC performs a host of standard optimizations in addition to some MCU specific
32234  optimizations.
32235  
32236 \end_layout
32237
32238 \begin_layout Subsection
32239 Sub-expression Elimination
32240 \begin_inset LatexCommand \index{Subexpression elimination}
32241
32242 \end_inset
32243
32244
32245 \end_layout
32246
32247 \begin_layout Standard
32248 The compiler does local and 
32249 \emph on
32250 g
32251 \emph default
32252 lobal 
32253 \emph on
32254 c
32255 \emph default
32256 ommon 
32257 \emph on
32258 s
32259 \emph default
32260 ubexpression 
32261 \emph on
32262 e
32263 \emph default
32264 limination, e.g.: 
32265 \end_layout
32266
32267 \begin_layout Verse
32268
32269 \family typewriter
32270 i = x + y + 1; 
32271 \newline
32272 j = x + y;
32273 \end_layout
32274
32275 \begin_layout Standard
32276 will be translated to
32277 \end_layout
32278
32279 \begin_layout Verse
32280
32281 \family typewriter
32282 iTemp = x + y; 
32283 \newline
32284 i = iTemp + 1; 
32285 \newline
32286 j = iTemp;
32287 \end_layout
32288
32289 \begin_layout Standard
32290 Some subexpressions are not as obvious as the above example, e.g.:
32291 \end_layout
32292
32293 \begin_layout Verse
32294
32295 \family typewriter
32296 a->b[i].c = 10; 
32297 \newline
32298 a->b[i].d = 11;
32299 \end_layout
32300
32301 \begin_layout Standard
32302 In this case the address arithmetic a->b[i] will be computed only once;
32303  the equivalent code in C would be.
32304 \end_layout
32305
32306 \begin_layout Verse
32307
32308 \family typewriter
32309 iTemp = a->b[i]; 
32310 \newline
32311 iTemp.c = 10; 
32312 \newline
32313 iTemp.d = 11;
32314 \end_layout
32315
32316 \begin_layout Standard
32317 The compiler will try to keep these temporary variables in registers.
32318 \end_layout
32319
32320 \begin_layout Subsection
32321 Dead-Code Elimination
32322 \begin_inset LatexCommand \index{Dead-code elimination}
32323
32324 \end_inset
32325
32326
32327 \end_layout
32328
32329 \begin_layout Verse
32330
32331 \family typewriter
32332 int global;
32333 \newline
32334
32335 \newline
32336 void f () { 
32337 \newline
32338 \InsetSpace ~
32339 \InsetSpace ~
32340 int i; 
32341 \newline
32342 \InsetSpace ~
32343 \InsetSpace ~
32344 i = 1; \InsetSpace ~
32345 \InsetSpace ~
32346 \InsetSpace ~
32347 \InsetSpace ~
32348 \InsetSpace ~
32349 /* dead store */ 
32350 \newline
32351 \InsetSpace ~
32352 \InsetSpace ~
32353 global = 1;\InsetSpace ~
32354 /* dead
32355  store */ 
32356 \newline
32357 \InsetSpace ~
32358 \InsetSpace ~
32359 global = 2; 
32360 \newline
32361 \InsetSpace ~
32362 \InsetSpace ~
32363 return; 
32364 \newline
32365 \InsetSpace ~
32366 \InsetSpace ~
32367 global = 3;\InsetSpace ~
32368 /* unreachable */ 
32369 \newline
32370 }
32371 \end_layout
32372
32373 \begin_layout Standard
32374 will be changed to
32375 \end_layout
32376
32377 \begin_layout Verse
32378
32379 \family typewriter
32380 int global;
32381 \newline
32382
32383 \newline
32384 void f () {
32385 \newline
32386 \InsetSpace ~
32387 \InsetSpace ~
32388 global = 2; 
32389 \newline
32390 }
32391 \end_layout
32392
32393 \begin_layout Subsection
32394 Copy-Propagation
32395 \begin_inset LatexCommand \index{Copy propagation}
32396
32397 \end_inset
32398
32399
32400 \end_layout
32401
32402 \begin_layout Verse
32403
32404 \family typewriter
32405 int f() { 
32406 \newline
32407 \InsetSpace ~
32408 \InsetSpace ~
32409 int i, j; 
32410 \newline
32411 \InsetSpace ~
32412 \InsetSpace ~
32413 i = 10; 
32414 \newline
32415 \InsetSpace ~
32416 \InsetSpace ~
32417 j = i; 
32418 \newline
32419 \InsetSpace ~
32420 \InsetSpace ~
32421 return j; 
32422 \newline
32423 }
32424 \end_layout
32425
32426 \begin_layout Standard
32427 will be changed to 
32428 \end_layout
32429
32430 \begin_layout Verse
32431
32432 \family typewriter
32433 int f() { 
32434 \newline
32435 \InsetSpace ~
32436 \InsetSpace ~
32437 int i, j; 
32438 \newline
32439 \InsetSpace ~
32440 \InsetSpace ~
32441 i = 10; 
32442 \newline
32443 \InsetSpace ~
32444 \InsetSpace ~
32445 j = 10; 
32446 \newline
32447 \InsetSpace ~
32448 \InsetSpace ~
32449 return 10; 
32450 \newline
32451 }
32452 \end_layout
32453
32454 \begin_layout Standard
32455 Note: the dead stores created by this copy propagation will be eliminated
32456  by dead-code elimination.
32457 \end_layout
32458
32459 \begin_layout Subsection
32460 Loop Optimizations
32461 \begin_inset LatexCommand \index{Loop optimization}
32462
32463 \end_inset
32464
32465
32466 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32467
32468 \end_inset
32469
32470
32471 \end_layout
32472
32473 \begin_layout Standard
32474 Two types of loop optimizations are done by SDCC 
32475 \emph on
32476 loop invariant
32477 \emph default
32478  lifting and
32479 \emph on
32480  strength reduction
32481 \emph default
32482  of loop induction variables.
32483  In addition to the strength reduction the optimizer marks the induction
32484  variables and the register allocator tries to keep the induction variables
32485  in registers for the duration of the loop.
32486  Because of this preference of the register allocator
32487 \begin_inset LatexCommand \index{Register allocation}
32488
32489 \end_inset
32490
32491 , loop induction optimization causes an increase in register pressure, which
32492  may cause unwanted spilling of other temporary variables into the stack
32493 \begin_inset LatexCommand \index{stack}
32494
32495 \end_inset
32496
32497  / data space.
32498  The compiler will generate a warning message when it is forced to allocate
32499  extra space either on the stack or data space.
32500  If this extra space allocation is undesirable then induction optimization
32501  can be eliminated either for the entire source file (with -
32502 \begin_inset ERT
32503 status collapsed
32504
32505 \begin_layout Standard
32506
32507
32508 \backslash
32509 /
32510 \end_layout
32511
32512 \end_inset
32513
32514 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32515 noinduction
32516 \begin_inset LatexCommand \index{\#pragma noinduction}
32517
32518 \end_inset
32519
32520 .
32521 \newline
32522
32523 \newline
32524 Loop Invariant:
32525 \end_layout
32526
32527 \begin_layout Verse
32528
32529 \family typewriter
32530 for (i = 0 ; i < 100 ; i ++) 
32531 \newline
32532 \InsetSpace ~
32533 \InsetSpace ~
32534 \InsetSpace ~
32535 \InsetSpace ~
32536 f += k + l;
32537 \end_layout
32538
32539 \begin_layout Standard
32540 changed to
32541 \end_layout
32542
32543 \begin_layout Verse
32544
32545 \family typewriter
32546 itemp = k + l; 
32547 \newline
32548 for (i = 0; i < 100; i++) 
32549 \newline
32550 \InsetSpace ~
32551 \InsetSpace ~
32552 \InsetSpace ~
32553 \InsetSpace ~
32554 f += itemp;
32555 \end_layout
32556
32557 \begin_layout Standard
32558 As mentioned previously some loop invariants are not as apparent, all static
32559  address computations are also moved out of the loop.
32560 \newline
32561
32562 \newline
32563 Strength Reduction
32564 \begin_inset LatexCommand \index{Strength reduction}
32565
32566 \end_inset
32567
32568 , this optimization substitutes an expression by a cheaper expression:
32569 \end_layout
32570
32571 \begin_layout Verse
32572
32573 \family typewriter
32574 for (i=0;i < 100; i++)
32575 \newline
32576 \InsetSpace ~
32577 \InsetSpace ~
32578 \InsetSpace ~
32579 \InsetSpace ~
32580 ar[i*5] = i*3;
32581 \end_layout
32582
32583 \begin_layout Standard
32584 changed to
32585 \end_layout
32586
32587 \begin_layout Verse
32588
32589 \family typewriter
32590 itemp1 = 0; 
32591 \newline
32592 itemp2 = 0; 
32593 \newline
32594 for (i=0;i< 100;i++) { 
32595 \newline
32596 \InsetSpace ~
32597 \InsetSpace ~
32598 \InsetSpace ~
32599 \InsetSpace ~
32600 ar[itemp1] = itemp2; 
32601 \newline
32602 \InsetSpace ~
32603 \InsetSpace ~
32604 \InsetSpace ~
32605 \InsetSpace ~
32606 itemp1
32607  += 5; 
32608 \newline
32609 \InsetSpace ~
32610 \InsetSpace ~
32611 \InsetSpace ~
32612 \InsetSpace ~
32613 itemp2 += 3; 
32614 \newline
32615 }
32616 \end_layout
32617
32618 \begin_layout Standard
32619 The more expensive multiplication
32620 \begin_inset LatexCommand \index{Multiplication}
32621
32622 \end_inset
32623
32624  is changed to a less expensive addition.
32625 \end_layout
32626
32627 \begin_layout Subsection
32628 Loop Reversing
32629 \begin_inset LatexCommand \index{Loop reversing}
32630
32631 \end_inset
32632
32633
32634 \end_layout
32635
32636 \begin_layout Standard
32637 This optimization is done to reduce the overhead of checking loop boundaries
32638  for every iteration.
32639  Some simple loops can be reversed and implemented using a 
32640 \begin_inset Quotes eld
32641 \end_inset
32642
32643 decrement and jump if not zero
32644 \begin_inset Quotes erd
32645 \end_inset
32646
32647  instruction.
32648  SDCC checks for the following criterion to determine if a loop is reversible
32649  (note: more sophisticated compilers use data-dependency analysis to make
32650  this determination, SDCC uses a more simple minded analysis).
32651 \end_layout
32652
32653 \begin_layout Itemize
32654 The 'for' loop is of the form 
32655 \newline
32656
32657 \newline
32658
32659 \family typewriter
32660 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32661  += 1])
32662 \newline
32663 \InsetSpace ~
32664 \InsetSpace ~
32665 \InsetSpace ~
32666 \InsetSpace ~
32667 <for body>
32668 \end_layout
32669
32670 \begin_layout Itemize
32671 The <for body> does not contain 
32672 \begin_inset Quotes eld
32673 \end_inset
32674
32675 continue
32676 \begin_inset Quotes erd
32677 \end_inset
32678
32679  or 'break
32680 \begin_inset Quotes erd
32681 \end_inset
32682
32683 .
32684 \end_layout
32685
32686 \begin_layout Itemize
32687 All goto's are contained within the loop.
32688 \end_layout
32689
32690 \begin_layout Itemize
32691 No function calls within the loop.
32692 \end_layout
32693
32694 \begin_layout Itemize
32695 The loop control variable <sym> is not assigned any value within the loop
32696 \end_layout
32697
32698 \begin_layout Itemize
32699 The loop control variable does NOT participate in any arithmetic operation
32700  within the loop.
32701 \end_layout
32702
32703 \begin_layout Itemize
32704 There are NO switch statements in the loop.
32705 \end_layout
32706
32707 \begin_layout Subsection
32708 Algebraic Simplifications
32709 \end_layout
32710
32711 \begin_layout Standard
32712 SDCC does numerous algebraic simplifications, the following is a small sub-set
32713  of these optimizations.
32714 \end_layout
32715
32716 \begin_layout Verse
32717
32718 \family typewriter
32719 i = j + 0;\InsetSpace ~
32720 \InsetSpace ~
32721 \InsetSpace ~
32722 \InsetSpace ~
32723  /* changed to: */\InsetSpace ~
32724 \InsetSpace ~
32725 \InsetSpace ~
32726 \InsetSpace ~
32727  i = j; 
32728 \newline
32729 i /= 2;\InsetSpace ~
32730 \InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734 \InsetSpace ~
32735 \InsetSpace ~
32736  /* changed to: */\InsetSpace ~
32737 \InsetSpace ~
32738 \InsetSpace ~
32739 \InsetSpace ~
32740  i >>= 1; 
32741 \newline
32742 i
32743  = j - j;\InsetSpace ~
32744 \InsetSpace ~
32745 \InsetSpace ~
32746 \InsetSpace ~
32747  /* changed to: */\InsetSpace ~
32748 \InsetSpace ~
32749 \InsetSpace ~
32750 \InsetSpace ~
32751  i = 0; 
32752 \newline
32753 i = j / 1;\InsetSpace ~
32754 \InsetSpace ~
32755 \InsetSpace ~
32756 \InsetSpace ~
32757  /* changed to: */\InsetSpace ~
32758 \InsetSpace ~
32759 \InsetSpace ~
32760 \InsetSpace ~
32761  i = j;
32762 \end_layout
32763
32764 \begin_layout Standard
32765 Note the subexpressions
32766 \begin_inset LatexCommand \index{Subexpression}
32767
32768 \end_inset
32769
32770  given above are generally introduced by macro expansions or as a result
32771  of copy/constant propagation.
32772 \end_layout
32773
32774 \begin_layout Subsection
32775 'switch' Statements
32776 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32777
32778 \end_inset
32779
32780
32781 \begin_inset LatexCommand \index{switch statement}
32782
32783 \end_inset
32784
32785
32786 \end_layout
32787
32788 \begin_layout Standard
32789 SDCC can optimize switch statements to jump tables
32790 \begin_inset LatexCommand \index{jump tables}
32791
32792 \end_inset
32793
32794 .
32795  It makes the decision based on an estimate of the generated code size.
32796  SDCC is quite liberal in the requirements for jump table generation: 
32797 \end_layout
32798
32799 \begin_layout Itemize
32800 The labels need not be in order, and the starting number need not be one
32801  or zero, the case labels are in numerical sequence or not too many case
32802  labels are missing.
32803 \end_layout
32804
32805 \begin_deeper
32806 \begin_layout Verse
32807
32808 \family typewriter
32809 switch(i) {\InsetSpace ~
32810 \InsetSpace ~
32811 \InsetSpace ~
32812 \InsetSpace ~
32813 \InsetSpace ~
32814 \InsetSpace ~
32815 \InsetSpace ~
32816 \InsetSpace ~
32817 \InsetSpace ~
32818 \InsetSpace ~
32819 \InsetSpace ~
32820 \InsetSpace ~
32821 \InsetSpace ~
32822 \InsetSpace ~
32823 \InsetSpace ~
32824 \InsetSpace ~
32825 \InsetSpace ~
32826 \InsetSpace ~
32827 \InsetSpace ~
32828 \InsetSpace ~
32829 \InsetSpace ~
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 \InsetSpace ~
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 switch (i) { 
32836 \newline
32837 \InsetSpace ~
32838 \InsetSpace ~
32839 \InsetSpace ~
32840 case 4: ...\InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 \InsetSpace ~
32845 \InsetSpace ~
32846 \InsetSpace ~
32847 \InsetSpace ~
32848 \InsetSpace ~
32849 \InsetSpace ~
32850 \InsetSpace ~
32851 \InsetSpace ~
32852 \InsetSpace ~
32853 \InsetSpace ~
32854 \InsetSpace ~
32855 \InsetSpace ~
32856 \InsetSpace ~
32857 \InsetSpace ~
32858 \InsetSpace ~
32859 \InsetSpace ~
32860 \InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 \InsetSpace ~
32865 \InsetSpace ~
32866 case 0: ...
32867  
32868 \newline
32869 \InsetSpace ~
32870 \InsetSpace ~
32871 \InsetSpace ~
32872 case 5: ...\InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 \InsetSpace ~
32876 \InsetSpace ~
32877 \InsetSpace ~
32878 \InsetSpace ~
32879 \InsetSpace ~
32880 \InsetSpace ~
32881 \InsetSpace ~
32882 \InsetSpace ~
32883 \InsetSpace ~
32884 \InsetSpace ~
32885 \InsetSpace ~
32886 \InsetSpace ~
32887 \InsetSpace ~
32888 \InsetSpace ~
32889 \InsetSpace ~
32890 \InsetSpace ~
32891 \InsetSpace ~
32892 \InsetSpace ~
32893 \InsetSpace ~
32894 \InsetSpace ~
32895 \InsetSpace ~
32896 \InsetSpace ~
32897 \InsetSpace ~
32898 case 1: ...
32899  
32900 \newline
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904 case 3: ...\InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907 \InsetSpace ~
32908 \InsetSpace ~
32909 \InsetSpace ~
32910 \InsetSpace ~
32911 \InsetSpace ~
32912 \InsetSpace ~
32913 \InsetSpace ~
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 \InsetSpace ~
32918 \InsetSpace ~
32919 \InsetSpace ~
32920 \InsetSpace ~
32921 \InsetSpace ~
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 \InsetSpace ~
32925 \InsetSpace ~
32926 \InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930
32931 \newline
32932 \InsetSpace ~
32933 \InsetSpace ~
32934 \InsetSpace ~
32935 case 6: ...\InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 \InsetSpace ~
32945 \InsetSpace ~
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 \InsetSpace ~
32951 \InsetSpace ~
32952 \InsetSpace ~
32953 \InsetSpace ~
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959 \InsetSpace ~
32960 \InsetSpace ~
32961 case 3: ...
32962  
32963 \newline
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 case 7: ...\InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976 \InsetSpace ~
32977 \InsetSpace ~
32978 \InsetSpace ~
32979 \InsetSpace ~
32980 \InsetSpace ~
32981 \InsetSpace ~
32982 \InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987 \InsetSpace ~
32988 \InsetSpace ~
32989 \InsetSpace ~
32990 \InsetSpace ~
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 case 4: ...
32994  
32995 \newline
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 case 8: ...\InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 \InsetSpace ~
33003 \InsetSpace ~
33004 \InsetSpace ~
33005 \InsetSpace ~
33006 \InsetSpace ~
33007 \InsetSpace ~
33008 \InsetSpace ~
33009 \InsetSpace ~
33010 \InsetSpace ~
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 \InsetSpace ~
33014 \InsetSpace ~
33015 \InsetSpace ~
33016 \InsetSpace ~
33017 \InsetSpace ~
33018 \InsetSpace ~
33019 \InsetSpace ~
33020 \InsetSpace ~
33021 \InsetSpace ~
33022 \InsetSpace ~
33023 \InsetSpace ~
33024 \InsetSpace ~
33025 case 5: ...
33026  
33027 \newline
33028 \InsetSpace ~
33029 \InsetSpace ~
33030 \InsetSpace ~
33031 case 9: ...\InsetSpace ~
33032 \InsetSpace ~
33033 \InsetSpace ~
33034 \InsetSpace ~
33035 \InsetSpace ~
33036 \InsetSpace ~
33037 \InsetSpace ~
33038 \InsetSpace ~
33039 \InsetSpace ~
33040 \InsetSpace ~
33041 \InsetSpace ~
33042 \InsetSpace ~
33043 \InsetSpace ~
33044 \InsetSpace ~
33045 \InsetSpace ~
33046 \InsetSpace ~
33047 \InsetSpace ~
33048 \InsetSpace ~
33049 \InsetSpace ~
33050 \InsetSpace ~
33051 \InsetSpace ~
33052 \InsetSpace ~
33053 \InsetSpace ~
33054 \InsetSpace ~
33055 \InsetSpace ~
33056 \InsetSpace ~
33057 case 6: ...
33058  
33059 \newline
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 \InsetSpace ~
33063 case 10: ...\InsetSpace ~
33064 \InsetSpace ~
33065 \InsetSpace ~
33066 \InsetSpace ~
33067 \InsetSpace ~
33068 \InsetSpace ~
33069 \InsetSpace ~
33070 \InsetSpace ~
33071 \InsetSpace ~
33072 \InsetSpace ~
33073 \InsetSpace ~
33074 \InsetSpace ~
33075 \InsetSpace ~
33076 \InsetSpace ~
33077 \InsetSpace ~
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 \InsetSpace ~
33081 \InsetSpace ~
33082 \InsetSpace ~
33083 \InsetSpace ~
33084 \InsetSpace ~
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 \InsetSpace ~
33088 case 7: ...
33089  
33090 \newline
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 \InsetSpace ~
33094 case 11: ...\InsetSpace ~
33095 \InsetSpace ~
33096 \InsetSpace ~
33097 \InsetSpace ~
33098 \InsetSpace ~
33099 \InsetSpace ~
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 \InsetSpace ~
33103 \InsetSpace ~
33104 \InsetSpace ~
33105 \InsetSpace ~
33106 \InsetSpace ~
33107 \InsetSpace ~
33108 \InsetSpace ~
33109 \InsetSpace ~
33110 \InsetSpace ~
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114 \InsetSpace ~
33115 \InsetSpace ~
33116 \InsetSpace ~
33117 \InsetSpace ~
33118 \InsetSpace ~
33119 case 8: ...
33120  
33121 \newline
33122 }\InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 \InsetSpace ~
33129 \InsetSpace ~
33130 \InsetSpace ~
33131 \InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 \InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 \InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144 \InsetSpace ~
33145 \InsetSpace ~
33146 \InsetSpace ~
33147 \InsetSpace ~
33148 \InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157 \InsetSpace ~
33158 }
33159 \end_layout
33160
33161 \begin_layout Standard
33162 Both the above switch statements will be implemented using a jump-table.
33163  The example to the right side is slightly more efficient as the check for
33164  the lower boundary of the jump-table is not needed.
33165 \end_layout
33166
33167 \end_deeper
33168 \begin_layout Itemize
33169 The number of case labels is not larger than supported by the target architectur
33170 e.
33171 \end_layout
33172
33173 \begin_layout Itemize
33174 If the case labels are not in numerical sequence ('gaps' between cases)
33175  SDCC checks whether a jump table with additionally inserted dummy cases
33176  is still attractive.
33177  
33178 \end_layout
33179
33180 \begin_layout Itemize
33181 If the starting number is not zero and a check for the lower boundary of
33182  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33183  ...
33184  .
33185 \end_layout
33186
33187 \begin_layout Standard
33188 Switch statements which have large gaps in the numeric sequence or those
33189  that have too many case labels can be split into more than one switch statement
33190  for efficient code generation, e.g.:
33191 \end_layout
33192
33193 \begin_layout Verse
33194
33195 \family typewriter
33196 switch (i) { 
33197 \newline
33198 \InsetSpace ~
33199 \InsetSpace ~
33200 case 1: ...
33201  
33202 \newline
33203 \InsetSpace ~
33204 \InsetSpace ~
33205 case 2: ...
33206  
33207 \newline
33208 \InsetSpace ~
33209 \InsetSpace ~
33210 case 3: ...
33211  
33212 \newline
33213 \InsetSpace ~
33214 \InsetSpace ~
33215 case 4: ...
33216  
33217 \newline
33218 \InsetSpace ~
33219 \InsetSpace ~
33220 case 5: ...
33221  
33222 \newline
33223 \InsetSpace ~
33224 \InsetSpace ~
33225 case 6: ...
33226  
33227 \newline
33228 \InsetSpace ~
33229 \InsetSpace ~
33230 case 7: ...
33231  
33232 \newline
33233 \InsetSpace ~
33234 \InsetSpace ~
33235 case 101: ...
33236  
33237 \newline
33238 \InsetSpace ~
33239 \InsetSpace ~
33240 case 102: ...
33241  
33242 \newline
33243 \InsetSpace ~
33244 \InsetSpace ~
33245 case 103: ...
33246  
33247 \newline
33248 \InsetSpace ~
33249 \InsetSpace ~
33250 case 104: ...
33251  
33252 \newline
33253 \InsetSpace ~
33254 \InsetSpace ~
33255 case 105: ...
33256  
33257 \newline
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 case 106: ...
33261  
33262 \newline
33263 \InsetSpace ~
33264 \InsetSpace ~
33265 case 107: ...
33266  
33267 \newline
33268 }
33269 \end_layout
33270
33271 \begin_layout Standard
33272 If the above switch statement is broken down into two switch statements
33273 \end_layout
33274
33275 \begin_layout Verse
33276
33277 \family typewriter
33278 switch (i) { 
33279 \newline
33280 \InsetSpace ~
33281 \InsetSpace ~
33282 case 1: ...
33283  
33284 \newline
33285 \InsetSpace ~
33286 \InsetSpace ~
33287 case 2: ...
33288  
33289 \newline
33290 \InsetSpace ~
33291 \InsetSpace ~
33292 case 3: ...
33293  
33294 \newline
33295 \InsetSpace ~
33296 \InsetSpace ~
33297 case 4: ...
33298  
33299 \newline
33300 \InsetSpace ~
33301 \InsetSpace ~
33302 case 5: ...
33303  
33304 \newline
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 case 6: ...
33308  
33309 \newline
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 case 7: ...
33313  
33314 \newline
33315 }
33316 \end_layout
33317
33318 \begin_layout Standard
33319 and
33320 \end_layout
33321
33322 \begin_layout Verse
33323
33324 \family typewriter
33325 switch (i) { 
33326 \newline
33327 \InsetSpace ~
33328 \InsetSpace ~
33329 case 101: ...
33330  
33331 \newline
33332 \InsetSpace ~
33333 \InsetSpace ~
33334 case 102: ...
33335  
33336 \newline
33337 \InsetSpace ~
33338 \InsetSpace ~
33339 case 103: ...
33340  
33341 \newline
33342 \InsetSpace ~
33343 \InsetSpace ~
33344 case 104: ...
33345  
33346 \newline
33347 \InsetSpace ~
33348 \InsetSpace ~
33349 case 105: ...
33350  
33351 \newline
33352 \InsetSpace ~
33353 \InsetSpace ~
33354 case 106: ...
33355  
33356 \newline
33357 \InsetSpace ~
33358 \InsetSpace ~
33359 case 107: ...
33360  
33361 \newline
33362 }
33363 \end_layout
33364
33365 \begin_layout Standard
33366 then both the switch statements will be implemented using jump-tables whereas
33367  the unmodified switch statement will not be.
33368 \end_layout
33369
33370 \begin_layout Standard
33371 \begin_inset Note Note
33372 status collapsed
33373
33374 \begin_layout Standard
33375 There might be reasons which SDCC cannot know about to either favour or
33376  not favour jump tables.
33377  If the target system has to be as quick for the last switch case as for
33378  the first (pro jump table), or if the switch argument is known to be zero
33379  in the majority of the cases (contra jump table).
33380 \end_layout
33381
33382 \end_inset
33383
33384
33385 \end_layout
33386
33387 \begin_layout Standard
33388 The pragma nojtbound
33389 \begin_inset LatexCommand \index{\#pragma nojtbound}
33390
33391 \end_inset
33392
33393  can be used to turn off checking the 
33394 \emph on
33395 j
33396 \emph default
33397 ump 
33398 \emph on
33399 t
33400 \emph default
33401 able 
33402 \emph on
33403 bound
33404 \emph default
33405 aries.
33406  It has no effect if a default label is supplied.
33407  Use of this pragma is dangerous: if the switch
33408 \begin_inset LatexCommand \index{switch statement}
33409
33410 \end_inset
33411
33412  argument is not matched by a case statement the processor will happily
33413  jump into Nirvana.
33414 \end_layout
33415
33416 \begin_layout Subsection
33417 Bit-shifting Operations
33418 \begin_inset LatexCommand \index{Bit shifting}
33419
33420 \end_inset
33421
33422 .
33423 \end_layout
33424
33425 \begin_layout Standard
33426 Bit shifting is one of the most frequently used operation in embedded programmin
33427 g.
33428  SDCC tries to implement bit-shift operations in the most efficient way
33429  possible, e.g.:
33430 \end_layout
33431
33432 \begin_layout Verse
33433
33434 \family typewriter
33435 unsigned char i;
33436 \newline
33437 ...
33438  
33439 \newline
33440 i >>= 4; 
33441 \newline
33442 ...
33443 \end_layout
33444
33445 \begin_layout Standard
33446 generates the following code:
33447 \end_layout
33448
33449 \begin_layout Verse
33450
33451 \family typewriter
33452 mov\InsetSpace ~
33453  a,_i 
33454 \newline
33455 swap a 
33456 \newline
33457 anl\InsetSpace ~
33458  a,#0x0f 
33459 \newline
33460 mov\InsetSpace ~
33461  _i,a
33462 \end_layout
33463
33464 \begin_layout Standard
33465 In general SDCC will never setup a loop if the shift count is known.
33466  Another example:
33467 \end_layout
33468
33469 \begin_layout Verse
33470
33471 \family typewriter
33472 unsigned int i; 
33473 \newline
33474 ...
33475  
33476 \newline
33477 i >>= 9; 
33478 \newline
33479 ...
33480 \end_layout
33481
33482 \begin_layout Standard
33483 will generate:
33484 \end_layout
33485
33486 \begin_layout Verse
33487
33488 \family typewriter
33489 mov\InsetSpace ~
33490 \InsetSpace ~
33491 a,(_i + 1) 
33492 \newline
33493 mov\InsetSpace ~
33494 \InsetSpace ~
33495 (_i + 1),#0x00 
33496 \newline
33497 clr\InsetSpace ~
33498 \InsetSpace ~
33499
33500 \newline
33501 rrc\InsetSpace ~
33502 \InsetSpace ~
33503
33504 \newline
33505 mov\InsetSpace ~
33506 \InsetSpace ~
33507 _i,a
33508 \end_layout
33509
33510 \begin_layout Subsection
33511 Bit-rotation
33512 \begin_inset LatexCommand \index{Bit rotation}
33513
33514 \end_inset
33515
33516
33517 \end_layout
33518
33519 \begin_layout Standard
33520 A special case of the bit-shift operation is bit rotation
33521 \begin_inset LatexCommand \index{rotating bits}
33522
33523 \end_inset
33524
33525 , SDCC recognizes the following expression to be a left bit-rotation:
33526 \end_layout
33527
33528 \begin_layout Verse
33529
33530 \family typewriter
33531 \series bold
33532 unsigned
33533 \series default
33534 \InsetSpace ~
33535 \InsetSpace ~
33536 char i;\InsetSpace ~
33537 \InsetSpace ~
33538 \InsetSpace ~
33539 \InsetSpace ~
33540 \InsetSpace ~
33541 \InsetSpace ~
33542 \InsetSpace ~
33543 \InsetSpace ~
33544 \InsetSpace ~
33545 \InsetSpace ~
33546 \InsetSpace ~
33547 /* unsigned is needed for rotation */ 
33548 \newline
33549 ...
33550  
33551 \newline
33552 i = ((i << 1) | (i >> 7)); 
33553 \family default
33554
33555 \newline
33556
33557 \family typewriter
33558 ...
33559 \end_layout
33560
33561 \begin_layout Standard
33562 will generate the following code:
33563 \end_layout
33564
33565 \begin_layout Verse
33566
33567 \family typewriter
33568 mov\InsetSpace ~
33569 \InsetSpace ~
33570 a,_i 
33571 \newline
33572 rl\InsetSpace ~
33573 \InsetSpace ~
33574 \InsetSpace ~
33575
33576 \newline
33577 mov\InsetSpace ~
33578 \InsetSpace ~
33579 _i,a
33580 \end_layout
33581
33582 \begin_layout Standard
33583 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33584 ns of this case will also be recognized as bit-rotation, i.e.: 
33585 \end_layout
33586
33587 \begin_layout Verse
33588
33589 \family typewriter
33590 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33591 \end_layout
33592
33593 \begin_layout Subsection
33594 Nibble and Byte Swapping
33595 \end_layout
33596
33597 \begin_layout Standard
33598 Other special cases of the bit-shift operations are nibble or byte swapping
33599 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33600
33601 \end_inset
33602
33603 , SDCC recognizes the following expressions:
33604 \end_layout
33605
33606 \begin_layout Verse
33607
33608 \family typewriter
33609 \series bold
33610 unsigned
33611 \series default
33612 \InsetSpace ~
33613 \InsetSpace ~
33614 char i; 
33615 \newline
33616
33617 \series bold
33618 unsigned
33619 \series default
33620 \InsetSpace ~
33621 \InsetSpace ~
33622 int j; 
33623 \newline
33624 ...
33625  
33626 \newline
33627 i = ((i << 4) | (i >> 4)); 
33628 \family default
33629
33630 \newline
33631
33632 \family typewriter
33633 j = ((j << 8) | (j >> 8)); 
33634 \end_layout
33635
33636 \begin_layout Standard
33637 and generates a swap instruction for the nibble swapping
33638 \begin_inset LatexCommand \index{Nibble swapping}
33639
33640 \end_inset
33641
33642  or move instructions for the byte swapping
33643 \begin_inset LatexCommand \index{Byte swapping}
33644
33645 \end_inset
33646
33647 .
33648  The 
33649 \begin_inset Quotes sld
33650 \end_inset
33651
33652 j
33653 \begin_inset Quotes srd
33654 \end_inset
33655
33656  example can be used to convert from little to big-endian or vice versa.
33657  If you want to change the endianness of a 
33658 \emph on
33659 signed
33660 \emph default
33661  integer you have to cast to 
33662 \family typewriter
33663 (unsigned int)
33664 \family default
33665  first.
33666 \end_layout
33667
33668 \begin_layout Standard
33669 Note that SDCC stores numbers in little-endian
33670 \begin_inset Foot
33671 status open
33672
33673 \begin_layout Standard
33674 Usually 8-bit processors don't care much about endianness.
33675  This is not the case for the standard 8051 which only has an instruction
33676  to increment its 
33677 \emph on
33678 dptr
33679 \emph default
33680
33681 \begin_inset LatexCommand \index{DPTR}
33682
33683 \end_inset
33684
33685 -datapointer
33686 \emph on
33687  
33688 \emph default
33689 so little-endian is the more efficient byte order.
33690 \end_layout
33691
33692 \end_inset
33693
33694
33695 \begin_inset LatexCommand \index{little-endian}
33696
33697 \end_inset
33698
33699
33700 \begin_inset LatexCommand \index{Endianness}
33701
33702 \end_inset
33703
33704  format (i.e.
33705  lowest order first).
33706 \end_layout
33707
33708 \begin_layout Subsection
33709 Highest Order Bit
33710 \begin_inset LatexCommand \index{Highest Order Bit}
33711
33712 \end_inset
33713
33714  / Any Order Bit
33715 \begin_inset LatexCommand \index{Any Order Bit}
33716
33717 \end_inset
33718
33719
33720 \end_layout
33721
33722 \begin_layout Standard
33723 It is frequently required to obtain the highest order bit of an integral
33724  type (long, int, short or char types).
33725  Also obtaining any other order bit is not uncommon.
33726  SDCC recognizes the following expressions to yield the highest order bit
33727  and generates optimized code for it, e.g.:
33728 \end_layout
33729
33730 \begin_layout Verse
33731
33732 \family typewriter
33733 unsigned int gint; 
33734 \newline
33735
33736 \newline
33737 foo () { 
33738 \newline
33739 \InsetSpace ~
33740 \InsetSpace ~
33741 unsigned char hob1, aob1; 
33742 \newline
33743 \InsetSpace ~
33744 \InsetSpace ~
33745 bit hob2, hob3, aob2,
33746  aob3; 
33747 \newline
33748 \InsetSpace ~
33749 \InsetSpace ~
33750 ...
33751  
33752 \newline
33753 \InsetSpace ~
33754 \InsetSpace ~
33755 hob1 = (gint >> 15) & 1; 
33756 \newline
33757 \InsetSpace ~
33758 \InsetSpace ~
33759 hob2 = (gint >> 15) & 1; 
33760 \newline
33761 \InsetSpace ~
33762 \InsetSpace ~
33763 hob3 = gint & 0x8000;
33764  
33765 \newline
33766 \InsetSpace ~
33767 \InsetSpace ~
33768 aob1 = (gint >> 9) & 1; 
33769 \newline
33770 \InsetSpace ~
33771 \InsetSpace ~
33772 aob2 = (gint >> 8) & 1; 
33773 \newline
33774 \InsetSpace ~
33775 \InsetSpace ~
33776 aob3 = gint & 0x0800; 
33777 \newline
33778 \InsetSpace ~
33779 \InsetSpace ~
33780 ..
33781  
33782 \newline
33783 }
33784 \end_layout
33785
33786 \begin_layout Standard
33787 will generate the following code:
33788 \end_layout
33789
33790 \begin_layout Verse
33791
33792 \family typewriter
33793 \InsetSpace ~
33794 \InsetSpace ~
33795 \InsetSpace ~
33796 \InsetSpace ~
33797 \InsetSpace ~
33798 \InsetSpace ~
33799 \InsetSpace ~
33800 \InsetSpace ~
33801 \InsetSpace ~
33802 \InsetSpace ~
33803 \InsetSpace ~
33804 \InsetSpace ~
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 \InsetSpace ~
33808 \InsetSpace ~
33809 \InsetSpace ~
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 \InsetSpace ~
33813 \InsetSpace ~
33814 \InsetSpace ~
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818  61 ;\InsetSpace ~
33819  hob.c 7 
33820 \newline
33821 000A E5*01\InsetSpace ~
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 \InsetSpace ~
33827 \InsetSpace ~
33828 \InsetSpace ~
33829 \InsetSpace ~
33830 \InsetSpace ~
33831 \InsetSpace ~
33832 \InsetSpace ~
33833 \InsetSpace ~
33834 \InsetSpace ~
33835 \InsetSpace ~
33836  62\InsetSpace ~
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844  mov\InsetSpace ~
33845 \InsetSpace ~
33846  a,(_gint + 1) 
33847 \newline
33848 000C 23\InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 \InsetSpace ~
33855 \InsetSpace ~
33856 \InsetSpace ~
33857 \InsetSpace ~
33858 \InsetSpace ~
33859 \InsetSpace ~
33860 \InsetSpace ~
33861 \InsetSpace ~
33862 \InsetSpace ~
33863 \InsetSpace ~
33864 \InsetSpace ~
33865 \InsetSpace ~
33866  63\InsetSpace ~
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 \InsetSpace ~
33873 \InsetSpace ~
33874  rl\InsetSpace ~
33875 \InsetSpace ~
33876 \InsetSpace ~
33877  a 
33878 \newline
33879 000D 54 01\InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 \InsetSpace ~
33883 \InsetSpace ~
33884 \InsetSpace ~
33885 \InsetSpace ~
33886 \InsetSpace ~
33887 \InsetSpace ~
33888 \InsetSpace ~
33889 \InsetSpace ~
33890 \InsetSpace ~
33891 \InsetSpace ~
33892 \InsetSpace ~
33893 \InsetSpace ~
33894
33895  64\InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902 \InsetSpace ~
33903  anl\InsetSpace ~
33904 \InsetSpace ~
33905  a,#0x01 
33906 \newline
33907 000F F5*02\InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912 \InsetSpace ~
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 \InsetSpace ~
33920 \InsetSpace ~
33921 \InsetSpace ~
33922  65\InsetSpace ~
33923 \InsetSpace ~
33924 \InsetSpace ~
33925 \InsetSpace ~
33926 \InsetSpace ~
33927 \InsetSpace ~
33928 \InsetSpace ~
33929 \InsetSpace ~
33930  mov\InsetSpace ~
33931 \InsetSpace ~
33932  _foo_hob1_1_1,a 
33933 \newline
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 \InsetSpace ~
33949 \InsetSpace ~
33950 \InsetSpace ~
33951 \InsetSpace ~
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 \InsetSpace ~
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959  66 ;\InsetSpace ~
33960  hob.c 8 
33961 \newline
33962 0011 E5*01\InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 \InsetSpace ~
33970 \InsetSpace ~
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977
33978  67\InsetSpace ~
33979 \InsetSpace ~
33980 \InsetSpace ~
33981 \InsetSpace ~
33982 \InsetSpace ~
33983 \InsetSpace ~
33984 \InsetSpace ~
33985 \InsetSpace ~
33986  mov\InsetSpace ~
33987 \InsetSpace ~
33988  a,(_gint + 1) 
33989 \newline
33990 0013 33\InsetSpace ~
33991 \InsetSpace ~
33992 \InsetSpace ~
33993 \InsetSpace ~
33994 \InsetSpace ~
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 \InsetSpace ~
33998 \InsetSpace ~
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 \InsetSpace ~
34002 \InsetSpace ~
34003 \InsetSpace ~
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 \InsetSpace ~
34007 \InsetSpace ~
34008  68\InsetSpace ~
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 \InsetSpace ~
34012 \InsetSpace ~
34013 \InsetSpace ~
34014 \InsetSpace ~
34015 \InsetSpace ~
34016  rlc\InsetSpace ~
34017 \InsetSpace ~
34018  a 
34019 \newline
34020 0014 92*00\InsetSpace ~
34021 \InsetSpace ~
34022 \InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 \InsetSpace ~
34034 \InsetSpace ~
34035  69\InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 \InsetSpace ~
34043  mov\InsetSpace ~
34044 \InsetSpace ~
34045  _foo_hob2_1_1,c
34046  
34047 \newline
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 \InsetSpace ~
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 \InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 \InsetSpace ~
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073  66 ;\InsetSpace ~
34074  hob.c 9 
34075 \newline
34076 0016 E5*01\InsetSpace ~
34077 \InsetSpace ~
34078 \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  67\InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099  mov\InsetSpace ~
34100 \InsetSpace ~
34101  a,(_gint + 1) 
34102 \newline
34103 0018 33\InsetSpace ~
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 \InsetSpace ~
34114 \InsetSpace ~
34115 \InsetSpace ~
34116 \InsetSpace ~
34117 \InsetSpace ~
34118 \InsetSpace ~
34119 \InsetSpace ~
34120 \InsetSpace ~
34121  68\InsetSpace ~
34122 \InsetSpace ~
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 \InsetSpace ~
34128 \InsetSpace ~
34129  rlc\InsetSpace ~
34130 \InsetSpace ~
34131  a 
34132 \newline
34133 0019 92*01\InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 \InsetSpace ~
34141 \InsetSpace ~
34142 \InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 \InsetSpace ~
34146 \InsetSpace ~
34147 \InsetSpace ~
34148
34149  69\InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 \InsetSpace ~
34157  mov\InsetSpace ~
34158 \InsetSpace ~
34159  _foo_hob3_1_1,c 
34160 \newline
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 \InsetSpace ~
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 \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  70 ;\InsetSpace ~
34187  hob.c 10 
34188 \newline
34189 001B E5*01\InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202 \InsetSpace ~
34203 \InsetSpace ~
34204  71\InsetSpace ~
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212  mov\InsetSpace ~
34213 \InsetSpace ~
34214  a,(_gint + 1) 
34215 \newline
34216 001D
34217  03\InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235  72\InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243  rr\InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246  a 
34247 \newline
34248 001E 54 01\InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261 \InsetSpace ~
34262 \InsetSpace ~
34263  73\InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270 \InsetSpace ~
34271  anl\InsetSpace ~
34272 \InsetSpace ~
34273  a,#0x01 
34274 \newline
34275 0020 F5*03\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  74\InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297 \InsetSpace ~
34298  mov\InsetSpace ~
34299 \InsetSpace ~
34300  _foo_aob1_1_1,a
34301  
34302 \newline
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 \InsetSpace ~
34327 \InsetSpace ~
34328  75 ;\InsetSpace ~
34329  hob.c 11 
34330 \newline
34331 0022 E5*01\InsetSpace ~
34332 \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  76\InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354  mov\InsetSpace ~
34355 \InsetSpace ~
34356  a,(_gint + 1) 
34357 \newline
34358 0024 13\InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374 \InsetSpace ~
34375 \InsetSpace ~
34376  77\InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384  rrc\InsetSpace ~
34385 \InsetSpace ~
34386  a 
34387 \newline
34388 0025 92*02\InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
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
34404  78\InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412  mov\InsetSpace ~
34413 \InsetSpace ~
34414  _foo_aob2_1_1,c 
34415 \newline
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431 \InsetSpace ~
34432 \InsetSpace ~
34433 \InsetSpace ~
34434 \InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441  79 ;\InsetSpace ~
34442  hob.c 12 
34443 \newline
34444 0027 E5*01\InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 \InsetSpace ~
34459  80\InsetSpace ~
34460 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467  mov\InsetSpace ~
34468 \InsetSpace ~
34469  a,(_gint + 1) 
34470 \newline
34471 0029
34472  A2 E3\InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487  81\InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495  mov\InsetSpace ~
34496 \InsetSpace ~
34497  c,acc[3] 
34498 \newline
34499 002B 92*03\InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514  82\InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522  mov\InsetSpace ~
34523 \InsetSpace ~
34524  _foo_aob3_1_1,c 
34525 \end_layout
34526
34527 \begin_layout Standard
34528 Other variations of these cases however will 
34529 \emph on
34530 not
34531 \emph default
34532  be recognized.
34533  They are standard C expressions, so I heartily recommend these be the only
34534  way to get the highest order bit, (it is portable).
34535  Of course it will be recognized even if it is embedded in other expressions,
34536  e.g.:
34537 \end_layout
34538
34539 \begin_layout Verse
34540
34541 \family typewriter
34542 xyz = gint + ((gint >> 15) & 1);
34543 \end_layout
34544
34545 \begin_layout Standard
34546 will still be recognized.
34547 \end_layout
34548
34549 \begin_layout Subsection
34550 Higher Order Byte
34551 \begin_inset LatexCommand \index{Higher Order Byte}
34552
34553 \end_inset
34554
34555  / Higher Order Word
34556 \begin_inset LatexCommand \index{Higher Order Word}
34557
34558 \end_inset
34559
34560
34561 \end_layout
34562
34563 \begin_layout Standard
34564 It is also frequently required to obtain a higher order byte or word of
34565  a larger integral type (long, int or short types).
34566  SDCC recognizes the following expressions to yield the higher order byte
34567  or word and generates optimized code for it, e.g.:
34568 \end_layout
34569
34570 \begin_layout Verse
34571
34572 \family typewriter
34573 unsigned int gint; 
34574 \newline
34575 unsigned long int glong; 
34576 \newline
34577
34578 \newline
34579 foo () { 
34580 \newline
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 unsigned char hob1,
34584  hob2; 
34585 \newline
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 unsigned int how1, how2; 
34589 \newline
34590 \InsetSpace ~
34591 \InsetSpace ~
34592 ...
34593  
34594 \newline
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 hob1 = (gint >> 8) & 0xFF; 
34598 \newline
34599 \InsetSpace ~
34600 \InsetSpace ~
34601 hob2 = glong >> 24; 
34602 \newline
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 how1 = (glong >> 16) & 0xFFFF;
34606  
34607 \newline
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 how2 = glong >> 8; 
34611 \newline
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 ..
34615  
34616 \newline
34617 }
34618 \end_layout
34619
34620 \begin_layout Standard
34621 will generate the following code:
34622 \end_layout
34623
34624 \begin_layout Verse
34625
34626 \family typewriter
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652  91 ;\InsetSpace ~
34653  hob.c 15 
34654 \newline
34655 0037 85*01*06\InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667  92\InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675  mov\InsetSpace ~
34676 \InsetSpace ~
34677  _foo_hob1_1_1,(_gint + 1) 
34678 \newline
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704  93 ;\InsetSpace ~
34705  hob.c
34706  16 
34707 \newline
34708 003A 85*05*07\InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720  94\InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728  mov\InsetSpace ~
34729 \InsetSpace ~
34730  _foo_hob2_1_1,(_glong + 3) 
34731 \newline
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757  95 ;\InsetSpace ~
34758  hob.c 17 
34759 \newline
34760 003D 85*04*08\InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772
34773  96\InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781  mov\InsetSpace ~
34782 \InsetSpace ~
34783  _foo_how1_1_1,(_glong + 2) 
34784 \newline
34785 0040 85*05*09\InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791 \InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797  97\InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805  mov\InsetSpace ~
34806 \InsetSpace ~
34807  (_foo_how1_1_1 +
34808  1),(_glong + 3) 
34809 \newline
34810 0043 85*03*0A\InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822  98\InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 \InsetSpace ~
34830  mov\InsetSpace ~
34831 \InsetSpace ~
34832  _foo_how2_1_1,(_glong + 1) 
34833 \newline
34834 0046 85*04*0B\InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846
34847  99\InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855  mov\InsetSpace ~
34856 \InsetSpace ~
34857  (_foo_how2_1_1 + 1),(_glong + 2) 
34858 \end_layout
34859
34860 \begin_layout Standard
34861 Again, variations of these cases may 
34862 \emph on
34863 not
34864 \emph default
34865  be recognized.
34866  They are standard C expressions, so I heartily recommend these be the only
34867  way to get the higher order byte/word, (it is portable).
34868  Of course it will be recognized even if it is embedded in other expressions,
34869  e.g.:
34870 \end_layout
34871
34872 \begin_layout Verse
34873
34874 \family typewriter
34875 xyz = gint + ((gint >> 8) & 0xFF);
34876 \end_layout
34877
34878 \begin_layout Standard
34879 will still be recognized.
34880 \end_layout
34881
34882 \begin_layout Subsection
34883 Peephole Optimizer
34884 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34885
34886 \end_inset
34887
34888
34889 \begin_inset LatexCommand \index{Peephole optimizer}
34890
34891 \end_inset
34892
34893
34894 \end_layout
34895
34896 \begin_layout Standard
34897 The compiler uses a rule based, pattern matching and re-writing mechanism
34898  for peep-hole optimization.
34899  It is inspired by 
34900 \emph on
34901 copt
34902 \emph default
34903  a peep-hole optimizer by Christopher W.
34904  Fraser (cwfraser\InsetSpace ~
34905 @\InsetSpace ~
34906 microsoft.com).
34907  A default set of rules are compiled into the compiler, additional rules
34908  may be added with the 
34909 \emph on
34910 -
34911 \begin_inset ERT
34912 status collapsed
34913
34914 \begin_layout Standard
34915
34916
34917 \backslash
34918 /
34919 \end_layout
34920
34921 \end_inset
34922
34923 -peep-file
34924 \begin_inset LatexCommand \index{-\/-peep-file}
34925
34926 \end_inset
34927
34928  <filename>
34929 \emph default
34930  option.
34931  The rule language is best illustrated with examples.
34932 \end_layout
34933
34934 \begin_layout Verse
34935
34936 \family typewriter
34937 replace { 
34938 \newline
34939 \InsetSpace ~
34940 \InsetSpace ~
34941 mov %1,a 
34942 \newline
34943 \InsetSpace ~
34944 \InsetSpace ~
34945 mov a,%1
34946 \newline
34947 } by {
34948 \newline
34949 \InsetSpace ~
34950 \InsetSpace ~
34951 mov %1,a
34952 \newline
34953 }
34954 \end_layout
34955
34956 \begin_layout Standard
34957 The above rule will change the following assembly
34958 \begin_inset LatexCommand \index{Assembler routines}
34959
34960 \end_inset
34961
34962  sequence:
34963 \end_layout
34964
34965 \begin_layout Verse
34966
34967 \family typewriter
34968 mov r1,a 
34969 \newline
34970 mov a,r1
34971 \end_layout
34972
34973 \begin_layout Standard
34974 to
34975 \end_layout
34976
34977 \begin_layout Verse
34978
34979 \family typewriter
34980 mov r1,a
34981 \end_layout
34982
34983 \begin_layout Standard
34984 Note: All occurrences of a 
34985 \emph on
34986 %n
34987 \emph default
34988  (pattern variable) must denote the same string.
34989  With the above rule, the assembly sequence:
34990 \end_layout
34991
34992 \begin_layout Verse
34993
34994 \family typewriter
34995 mov r1,a 
34996 \newline
34997 mov a,r2
34998 \end_layout
34999
35000 \begin_layout Standard
35001 will remain unmodified.
35002 \newline
35003
35004 \newline
35005 Other special case optimizations may be added by the
35006  user (via 
35007 \emph on
35008 -
35009 \begin_inset ERT
35010 status collapsed
35011
35012 \begin_layout Standard
35013
35014
35015 \backslash
35016 /
35017 \end_layout
35018
35019 \end_inset
35020
35021 -peep-file option
35022 \emph default
35023 ).
35024  E.g.
35025  some variants of the 8051 MCU
35026 \begin_inset LatexCommand \index{MCS51 variants}
35027
35028 \end_inset
35029
35030  allow only 
35031 \family typewriter
35032 ajmp
35033 \family default
35034  and 
35035 \family typewriter
35036 acall
35037 \family default
35038 .
35039  The following two rules will change all 
35040 \family typewriter
35041 ljmp
35042 \family default
35043  and 
35044 \family typewriter
35045 lcall
35046 \family default
35047  to 
35048 \family typewriter
35049 ajmp
35050 \family default
35051  and 
35052 \family typewriter
35053 acall
35054 \end_layout
35055
35056 \begin_layout Verse
35057
35058 \family typewriter
35059 replace { lcall %1 } by { acall %1 } 
35060 \newline
35061 replace { ljmp %1 } by { ajmp %1 }
35062 \end_layout
35063
35064 \begin_layout Standard
35065 The 
35066 \emph on
35067 inline-assembler code
35068 \emph default
35069  is also passed through the peep hole optimizer, thus the peephole optimizer
35070  can also be used as an assembly level macro expander.
35071  The rules themselves are MCU dependent whereas the rule language infra-structur
35072 e is MCU independent.
35073  Peephole optimization rules for other MCU can be easily programmed using
35074  the rule language.
35075 \newline
35076
35077 \newline
35078 The syntax for a rule is as follows:
35079 \end_layout
35080
35081 \begin_layout Verse
35082
35083 \family typewriter
35084 rule := replace [ restart ] '{' <assembly sequence> '
35085 \backslash
35086 n' 
35087 \newline
35088 \InsetSpace ~
35089  \InsetSpace ~
35090  \InsetSpace ~
35091  \InsetSpace ~
35092  \InsetSpace ~
35093  \InsetSpace ~
35094  \InsetSpace ~
35095  \InsetSpace ~
35096  \InsetSpace ~
35097  \InsetSpace ~
35098  \InsetSpace ~
35099  \InsetSpace ~
35100  \InsetSpace ~
35101  \InsetSpace ~
35102  '}' by '{' '
35103 \backslash
35104 n' 
35105 \newline
35106 \InsetSpace ~
35107  \InsetSpace ~
35108  \InsetSpace ~
35109  \InsetSpace ~
35110  \InsetSpace ~
35111  \InsetSpace ~
35112  \InsetSpace ~
35113  \InsetSpace ~
35114  \InsetSpace ~
35115  \InsetSpace ~
35116  \InsetSpace ~
35117  \InsetSpace ~
35118  \InsetSpace ~
35119  \InsetSpace ~
35120  \InsetSpace ~
35121  \InsetSpace ~
35122  <assembly sequence> '
35123 \backslash
35124 n' 
35125 \newline
35126 \InsetSpace ~
35127  \InsetSpace ~
35128  \InsetSpace ~
35129  \InsetSpace ~
35130  \InsetSpace ~
35131  \InsetSpace ~
35132  \InsetSpace ~
35133  \InsetSpace ~
35134  \InsetSpace ~
35135  \InsetSpace ~
35136  \InsetSpace ~
35137  \InsetSpace ~
35138  \InsetSpace ~
35139  \InsetSpace ~
35140  '}' [if <functionName> ] '
35141 \backslash
35142 n' 
35143 \end_layout
35144
35145 \begin_layout Standard
35146 <assembly sequence> := assembly instruction (each instruction including
35147  labels must be on a separate line).
35148 \newline
35149
35150 \newline
35151 The optimizer will apply to the rules
35152  one by one from the top in the sequence of their appearance, it will terminate
35153  when all rules are exhausted.
35154  If the 'restart' option is specified, then the optimizer will start matching
35155  the rules again from the top, this option for a rule is expensive (performance)
35156 , it is intended to be used in situations where a transformation will trigger
35157  the same rule again.
35158  An example of this (not a good one, it has side effects) is the following
35159  rule:
35160 \end_layout
35161
35162 \begin_layout Verse
35163
35164 \family typewriter
35165 replace restart { 
35166 \newline
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 pop %1 
35170 \newline
35171 \InsetSpace ~
35172 \InsetSpace ~
35173 push %1 } by { 
35174 \newline
35175 \InsetSpace ~
35176 \InsetSpace ~
35177 ; nop 
35178 \newline
35179 }
35180 \end_layout
35181
35182 \begin_layout Standard
35183 Note that the replace pattern cannot be a blank, but can be a comment line.
35184  Without the 'restart' option only the innermost 'pop' 'push' pair would
35185  be eliminated, i.e.:
35186 \end_layout
35187
35188 \begin_layout Verse
35189
35190 \family typewriter
35191 pop ar1 
35192 \newline
35193 pop ar2 
35194 \newline
35195 push ar2 
35196 \newline
35197 push ar1
35198 \end_layout
35199
35200 \begin_layout Standard
35201 would result in:
35202 \end_layout
35203
35204 \begin_layout Verse
35205
35206 \family typewriter
35207 pop ar1 
35208 \newline
35209 ; nop 
35210 \newline
35211 push ar1
35212 \end_layout
35213
35214 \begin_layout Standard
35215
35216 \emph on
35217 with
35218 \emph default
35219  the restart option the rule will be applied again to the resulting code
35220  and then all the pop-push pairs will be eliminated to yield:
35221 \end_layout
35222
35223 \begin_layout Verse
35224
35225 \family typewriter
35226 ; nop 
35227 \newline
35228 ; nop
35229 \end_layout
35230
35231 \begin_layout Standard
35232 A conditional function can be attached to a rule.
35233  Attaching rules are somewhat more involved, let me illustrate this with
35234  an example.
35235 \end_layout
35236
35237 \begin_layout Verse
35238
35239 \family typewriter
35240 replace { 
35241 \newline
35242 \InsetSpace ~
35243  \InsetSpace ~
35244  \InsetSpace ~
35245 ljmp %5 
35246 \newline
35247 %2:
35248 \newline
35249 } by { 
35250 \newline
35251 \InsetSpace ~
35252  \InsetSpace ~
35253  \InsetSpace ~
35254 sjmp %5 
35255 \newline
35256 %2:
35257 \newline
35258 } if labelInRange
35259 \end_layout
35260
35261 \begin_layout Standard
35262 The optimizer does a look-up of a function name table defined in function
35263  
35264 \emph on
35265 callFuncByName
35266 \emph default
35267  in the source file SDCCpeeph.c, with the name 
35268 \emph on
35269 labelInRange
35270 \emph default
35271 .
35272  If it finds a corresponding entry the function is called.
35273  Note there can be no parameters specified for these functions, in this
35274  case the use of 
35275 \emph on
35276 %5
35277 \emph default
35278  is crucial, since the function 
35279 \emph on
35280 labelInRange
35281 \emph default
35282  expects to find the label in that particular variable (the hash table containin
35283 g the variable bindings is passed as a parameter).
35284  If you want to code more such functions, take a close look at the function
35285  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35286  Currently implemented are 
35287 \emph on
35288 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35289  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35290 \emph default
35291 and
35292 \emph on
35293  notVolatile
35294 \emph default
35295 .
35296 \end_layout
35297
35298 \begin_layout Standard
35299 I know this whole thing is a little kludgey, but maybe some day we will
35300  have some better means.
35301  If you are looking at this file, you will see the default rules that are
35302  compiled into the compiler, you can add your own rules in the default set
35303  there if you get tired of specifying the -
35304 \begin_inset ERT
35305 status collapsed
35306
35307 \begin_layout Standard
35308
35309
35310 \backslash
35311 /
35312 \end_layout
35313
35314 \end_inset
35315
35316 -peep-file option.
35317 \end_layout
35318
35319 \begin_layout Section
35320 ANSI-Compliance
35321 \begin_inset LatexCommand \index{ANSI-compliance}
35322
35323 \end_inset
35324
35325
35326 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35327
35328 \end_inset
35329
35330
35331 \end_layout
35332
35333 \begin_layout Standard
35334 The latest publically available version of the standard 
35335 \emph on
35336 ISO/IEC 9899 - Programming languages - C
35337 \emph default
35338  should be available at: 
35339 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35340
35341 \end_inset
35342
35343 .
35344 \newline
35345
35346 \end_layout
35347
35348 \begin_layout Standard
35349 Deviations from the compliance:
35350 \end_layout
35351
35352 \begin_layout Itemize
35353 functions are not reentrant
35354 \begin_inset LatexCommand \index{reentrant}
35355
35356 \end_inset
35357
35358  unless explicitly declared as such or the 
35359 \series bold
35360 -
35361 \begin_inset ERT
35362 status collapsed
35363
35364 \begin_layout Standard
35365
35366
35367 \backslash
35368 /
35369 \end_layout
35370
35371 \end_inset
35372
35373 -stack-auto
35374 \begin_inset LatexCommand \index{-\/-stack-auto}
35375
35376 \end_inset
35377
35378
35379 \series default
35380  command line option is specified.
35381 \end_layout
35382
35383 \begin_layout Itemize
35384 structures
35385 \begin_inset LatexCommand \index{struct}
35386
35387 \end_inset
35388
35389  and unions
35390 \begin_inset LatexCommand \index{union}
35391
35392 \end_inset
35393
35394  cannot be assigned values directly, cannot be passed as function parameters
35395  or assigned to each other and cannot be a return value
35396 \begin_inset LatexCommand \index{return value}
35397
35398 \end_inset
35399
35400  from a function, e.g.:
35401 \end_layout
35402
35403 \begin_deeper
35404 \begin_layout Verse
35405
35406 \family typewriter
35407 struct s { ...
35408  }; 
35409 \newline
35410 struct s s1, s2; 
35411 \newline
35412 foo() 
35413 \newline
35414
35415 \newline
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419 \InsetSpace ~
35420 ...
35421  
35422 \newline
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35428 \newline
35429 \InsetSpace ~
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 ...
35434  
35435 \newline
35436 }
35437 \newline
35438
35439 \series bold
35440 struct
35441 \series default
35442  s foo1 (
35443 \series bold
35444 struct
35445 \series default
35446  s parms) /* invalid in SDCC although allowed in ANSI */
35447 \newline
35448
35449 \newline
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 struct s rets;
35455  
35456 \newline
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 ...
35462  
35463 \newline
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35469 \newline
35470 }
35471 \end_layout
35472
35473 \end_deeper
35474 \begin_layout Itemize
35475 initialization of structure arrays must be fully braced.
35476 \end_layout
35477
35478 \begin_deeper
35479 \begin_layout Verse
35480
35481 \family typewriter
35482 struct s { char x } a[] = {1, 2};\InsetSpace ~
35483 \InsetSpace ~
35484 \InsetSpace ~
35485 \InsetSpace ~
35486 \InsetSpace ~
35487 /* invalid in SDCC */
35488 \newline
35489 struct s { char x
35490  } a[] = {{1}, {2}}; /* OK */
35491 \end_layout
35492
35493 \end_deeper
35494 \begin_layout Itemize
35495 'long long
35496 \begin_inset LatexCommand \index{long long (not supported)}
35497
35498 \end_inset
35499
35500 ' (64 bit integers
35501 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35502
35503 \end_inset
35504
35505 ) not supported.
35506 \end_layout
35507
35508 \begin_layout Itemize
35509 'double
35510 \begin_inset LatexCommand \index{double (not supported)}
35511
35512 \end_inset
35513
35514 ' precision floating point 
35515 \begin_inset LatexCommand \index{Floating point support}
35516
35517 \end_inset
35518
35519 not supported.
35520 \end_layout
35521
35522 \begin_layout Itemize
35523 Old K&R style
35524 \begin_inset LatexCommand \index{K\&R style}
35525
35526 \end_inset
35527
35528  function declarations are NOT allowed.
35529 \end_layout
35530
35531 \begin_deeper
35532 \begin_layout Verse
35533
35534 \family typewriter
35535 foo(i,j) /* this old style of function declarations */ 
35536 \newline
35537 int i,j; /* are valid
35538  in ANSI but not valid in SDCC */ 
35539 \newline
35540
35541 \newline
35542 \InsetSpace ~
35543 \InsetSpace ~
35544 \InsetSpace ~
35545 \InsetSpace ~
35546 ...
35547  
35548 \newline
35549 }
35550 \end_layout
35551
35552 \end_deeper
35553 \begin_layout Itemize
35554 Most enhancements in C99 are not supported, f.e.:
35555 \end_layout
35556
35557 \begin_deeper
35558 \begin_layout Verse
35559
35560 \family typewriter
35561 \series bold
35562 inline
35563 \begin_inset LatexCommand \index{inline (not supported)}
35564
35565 \end_inset
35566
35567
35568 \series default
35569  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35570  in C99.
35571  An empty define 
35572 \emph on
35573 #define inline
35574 \emph default
35575  can be used as a work around */
35576 \newline
35577
35578 \newline
35579 for (
35580 \series bold
35581 int
35582 \series default
35583  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35584 \end_layout
35585
35586 \end_deeper
35587 \begin_layout Itemize
35588 Certain words that are valid identifiers in the standard may be reserved
35589  words in SDCC unless the 
35590 \series bold
35591 -
35592 \begin_inset ERT
35593 status collapsed
35594
35595 \begin_layout Standard
35596
35597
35598 \backslash
35599 /
35600 \end_layout
35601
35602 \end_inset
35603
35604 -std-c89
35605 \begin_inset LatexCommand \index{-\/-std-c89}
35606
35607 \end_inset
35608
35609  or -
35610 \begin_inset ERT
35611 status collapsed
35612
35613 \begin_layout Standard
35614
35615
35616 \backslash
35617 /
35618 \end_layout
35619
35620 \end_inset
35621
35622 -std-c99
35623 \begin_inset LatexCommand \index{-\/-std-c99}
35624
35625 \end_inset
35626
35627
35628 \series default
35629  command line options are used.
35630  These may include (depending on the selected processor): 'at', 'banked',
35631  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35632 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35633  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35634  '_naked'.
35635  Compliant equivalents of these keywords are always available in a form
35636  that begin with two underscores
35637 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35638
35639 \end_inset
35640
35641 , f.e.
35642  '__data' instead of 'data'.
35643 \end_layout
35644
35645 \begin_layout Section
35646 Cyclomatic Complexity
35647 \begin_inset LatexCommand \index{Cyclomatic complexity}
35648
35649 \end_inset
35650
35651
35652 \end_layout
35653
35654 \begin_layout Standard
35655 Cyclomatic complexity of a function is defined as the number of independent
35656  paths the program can take during execution of the function.
35657  This is an important number since it defines the number test cases you
35658  have to generate to validate the function.
35659  The accepted industry standard for complexity number is 10, if the cyclomatic
35660  complexity reported by SDCC exceeds 10 you should think about simplification
35661  of the function logic.
35662  Note that the complexity level is not related to the number of lines of
35663  code in a function.
35664  Large functions can have low complexity, and small functions can have large
35665  complexity levels.
35666  
35667 \newline
35668
35669 \newline
35670 SDCC uses the following formula to compute the complexity:
35671 \newline
35672
35673 \end_layout
35674
35675 \begin_layout Standard
35676 complexity = (number of edges in control flow graph) - (number of nodes
35677  in control flow graph) + 2;
35678 \newline
35679
35680 \newline
35681 Having said that the industry standard is 10,
35682  you should be aware that in some cases it be may unavoidable to have a
35683  complexity level of less than 10.
35684  For example if you have switch statement with more than 10 case labels,
35685  each case label adds one to the complexity level.
35686  The complexity level is by no means an absolute measure of the algorithmic
35687  complexity of the function, it does however provide a good starting point
35688  for which functions you might look at for further optimization.
35689 \end_layout
35690
35691 \begin_layout Section
35692 Retargetting for other Processors
35693 \end_layout
35694
35695 \begin_layout Standard
35696 The issues for retargetting the compiler are far too numerous to be covered
35697  by this document.
35698  What follows is a brief description of each of the seven phases of the
35699  compiler and its MCU dependency.
35700 \end_layout
35701
35702 \begin_layout Itemize
35703 Parsing the source and building the annotated parse tree.
35704  This phase is largely MCU independent (except for the language extensions).
35705  Syntax & semantic checks are also done in this phase, along with some initial
35706  optimizations like back patching labels and the pattern matching optimizations
35707  like bit-rotation etc.
35708 \end_layout
35709
35710 \begin_layout Itemize
35711 The second phase involves generating an intermediate code which can be easy
35712  manipulated during the later phases.
35713  This phase is entirely MCU independent.
35714  The intermediate code generation assumes the target machine has unlimited
35715  number of registers, and designates them with the name iTemp.
35716  The compiler can be made to dump a human readable form of the code generated
35717  by using the -
35718 \begin_inset ERT
35719 status collapsed
35720
35721 \begin_layout Standard
35722
35723
35724 \backslash
35725 /
35726 \end_layout
35727
35728 \end_inset
35729
35730 -dumpraw option.
35731 \end_layout
35732
35733 \begin_layout Itemize
35734 This phase does the bulk of the standard optimizations and is also MCU independe
35735 nt.
35736  This phase can be broken down into several sub-phases:
35737 \newline
35738
35739 \newline
35740 Break down intermediate
35741  code (iCode) into basic blocks.
35742 \newline
35743 Do control flow & data flow analysis on the
35744  basic blocks.
35745 \newline
35746 Do local common subexpression elimination, then global subexpressio
35747 n elimination
35748 \newline
35749 Dead code elimination
35750 \newline
35751 Loop optimizations
35752 \newline
35753 If loop optimizations
35754  caused any changes then do 'global subexpression elimination' and 'dead
35755  code elimination' again.
35756 \end_layout
35757
35758 \begin_layout Itemize
35759 This phase determines the live-ranges; by live range I mean those iTemp
35760  variables defined by the compiler that still survive after all the optimization
35761 s.
35762  Live range analysis
35763 \begin_inset LatexCommand \index{Live range analysis}
35764
35765 \end_inset
35766
35767  is essential for register allocation, since these computation determines
35768  which of these iTemps will be assigned to registers, and for how long.
35769 \end_layout
35770
35771 \begin_layout Itemize
35772 Phase five is register allocation.
35773  There are two parts to this process.
35774 \newline
35775
35776 \newline
35777 The first part I call 'register packing'
35778  (for lack of a better term).
35779  In this case several MCU specific expression folding is done to reduce
35780  register pressure.
35781 \newline
35782
35783 \newline
35784 The second part is more MCU independent and deals with
35785  allocating registers to the remaining live ranges.
35786  A lot of MCU specific code does creep into this phase because of the limited
35787  number of index registers available in the 8051.
35788 \end_layout
35789
35790 \begin_layout Itemize
35791 The Code generation phase is (unhappily), entirely MCU dependent and very
35792  little (if any at all) of this code can be reused for other MCU.
35793  However the scheme for allocating a homogenized assembler operand for each
35794  iCode operand may be reused.
35795 \end_layout
35796
35797 \begin_layout Itemize
35798 As mentioned in the optimization section the peep-hole optimizer is rule
35799  based system, which can reprogrammed for other MCUs.
35800 \end_layout
35801
35802 \begin_layout Standard
35803 More information is available in a wiki
35804 \begin_inset LatexCommand \index{wiki}
35805
35806 \end_inset
35807
35808  (preliminary link 
35809 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35810
35811 \end_inset
35812
35813 ) and in the thread 
35814 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35815
35816 \end_inset
35817
35818  .
35819 \end_layout
35820
35821 \begin_layout Chapter
35822 Compiler internals
35823 \begin_inset LatexCommand \index{Compiler internals}
35824
35825 \end_inset
35826
35827
35828 \end_layout
35829
35830 \begin_layout Section
35831 The anatomy of the compiler
35832 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35833
35834 \end_inset
35835
35836
35837 \end_layout
35838
35839 \begin_layout Standard
35840
35841 \shape italic
35842 This is an excerpt from an article published in Circuit Cellar Magazine
35843  in 
35844 \series bold
35845 August 2000
35846 \series default
35847 .
35848  It's a little outdated (the compiler is much more efficient now and user/develo
35849 per friendly), but pretty well exposes the guts of it all.
35850 \shape default
35851
35852 \newline
35853
35854 \newline
35855 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35856  It is fairly easy to retarget for other 8-bit MCU.
35857  Here we take a look at some of the internals of the compiler.
35858  
35859 \end_layout
35860
35861 \begin_layout Paragraph*
35862 Parsing
35863 \begin_inset LatexCommand \index{Parsing}
35864
35865 \end_inset
35866
35867  
35868 \end_layout
35869
35870 \begin_layout Standard
35871 Parsing the input source file and creating an AST (Annotated Syntax Tree
35872 \begin_inset LatexCommand \index{Annotated syntax tree}
35873
35874 \end_inset
35875
35876 ).
35877  This phase also involves propagating types (annotating each node of the
35878  parse tree with type information) and semantic analysis.
35879  There are some MCU specific parsing rules.
35880  For example the storage classes, the extended storage classes are MCU specific
35881  while there may be a xdata storage class for 8051 there is no such storage
35882  class for z80 or Atmel AVR.
35883  SDCC allows MCU specific storage class extensions, i.e.
35884  xdata will be treated as a storage class specifier when parsing 8051 C
35885  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35886  C code.
35887 \end_layout
35888
35889 \begin_layout Paragraph*
35890 Generating iCode
35891 \begin_inset LatexCommand \index{iCode}
35892
35893 \end_inset
35894
35895
35896 \end_layout
35897
35898 \begin_layout Standard
35899 Intermediate code generation.
35900  In this phase the AST is broken down into three-operand form (iCode).
35901  These three operand forms are represented as doubly linked lists.
35902  ICode is the term given to the intermediate form generated by the compiler.
35903  ICode example section shows some examples of iCode generated for some simple
35904  C source functions.
35905 \end_layout
35906
35907 \begin_layout Paragraph*
35908 Optimizations
35909 \begin_inset LatexCommand \index{Optimizations}
35910
35911 \end_inset
35912
35913 .
35914 \end_layout
35915
35916 \begin_layout Standard
35917 Bulk of the target independent optimizations is performed in this phase.
35918  The optimizations include constant propagation, common sub-expression eliminati
35919 on, loop invariant code movement, strength reduction of loop induction variables
35920  and dead-code elimination.
35921 \end_layout
35922
35923 \begin_layout Paragraph*
35924 Live range analysis
35925 \begin_inset LatexCommand \index{Live range analysis}
35926
35927 \end_inset
35928
35929
35930 \end_layout
35931
35932 \begin_layout Standard
35933 During intermediate code generation phase, the compiler assumes the target
35934  machine has infinite number of registers and generates a lot of temporary
35935  variables.
35936  The live range computation determines the lifetime of each of these compiler-ge
35937 nerated temporaries.
35938  A picture speaks a thousand words.
35939  ICode example sections show the live range annotations for each of the
35940  operand.
35941  It is important to note here, each iCode is assigned a number in the order
35942  of its execution in the function.
35943  The live ranges are computed in terms of these numbers.
35944  The from number is the number of the iCode which first defines the operand
35945  and the to number signifies the iCode which uses this operand last.
35946 \end_layout
35947
35948 \begin_layout Paragraph*
35949 Register Allocation
35950 \begin_inset LatexCommand \index{Register allocation}
35951
35952 \end_inset
35953
35954
35955 \end_layout
35956
35957 \begin_layout Standard
35958 The register allocation determines the type and number of registers needed
35959  by each operand.
35960  In most MCUs only a few registers can be used for indirect addressing.
35961  In case of 8051 for example the registers R0 & R1 can be used to indirectly
35962  address the internal ram and DPTR to indirectly address the external ram.
35963  The compiler will try to allocate the appropriate register to pointer variables
35964  if it can.
35965  ICode example section shows the operands annotated with the registers assigned
35966  to them.
35967  The compiler will try to keep operands in registers as much as possible;
35968  there are several schemes the compiler uses to do achieve this.
35969  When the compiler runs out of registers the compiler will check to see
35970  if there are any live operands which is not used or defined in the current
35971  basic block being processed, if there are any found then it will push that
35972  operand and use the registers in this block, the operand will then be popped
35973  at the end of the basic block.
35974  
35975 \end_layout
35976
35977 \begin_layout Standard
35978 There are other MCU specific considerations in this phase.
35979  Some MCUs have an accumulator; very short-lived operands could be assigned
35980  to the accumulator instead of a general-purpose register.
35981 \end_layout
35982
35983 \begin_layout Paragraph*
35984 Code generation
35985 \end_layout
35986
35987 \begin_layout Standard
35988 Figure II gives a table of iCode
35989 \begin_inset LatexCommand \index{iCode}
35990
35991 \end_inset
35992
35993  operations supported by the compiler.
35994  The code generation involves translating these operations into corresponding
35995  assembly code for the processor.
35996  This sounds overly simple but that is the essence of code generation.
35997  Some of the iCode operations are generated on a MCU specific manner for
35998  example, the z80 port does not use registers to pass parameters so the
35999  SEND and RECV iCode operations will not be generated, and it also does
36000  not support JUMPTABLES.
36001  
36002 \newline
36003
36004 \end_layout
36005
36006 \begin_layout Standard
36007
36008 \size footnotesize
36009 Figure II 
36010 \begin_inset Tabular
36011 <lyxtabular version="3" rows="39" columns="4">
36012 <features islongtable="true" headBottomDL="true">
36013 <column alignment="block" valignment="top" leftline="true" width="13col%">
36014 <column alignment="left" valignment="top" leftline="true" width="13col%">
36015 <column alignment="block" valignment="top" leftline="true" width="22col%">
36016 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36017 <row topline="true" bottomline="true" endhead="true">
36018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36019 \begin_inset Text
36020
36021 \begin_layout Standard
36022
36023 \series bold
36024 iCode
36025 \series default
36026
36027 \begin_inset LatexCommand \index{iCode}
36028
36029 \end_inset
36030
36031
36032 \end_layout
36033
36034 \end_inset
36035 </cell>
36036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36037 \begin_inset Text
36038
36039 \begin_layout Standard
36040
36041 \series bold
36042 Operands
36043 \end_layout
36044
36045 \end_inset
36046 </cell>
36047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36048 \begin_inset Text
36049
36050 \begin_layout Standard
36051
36052 \series bold
36053 Description
36054 \end_layout
36055
36056 \end_inset
36057 </cell>
36058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36059 \begin_inset Text
36060
36061 \begin_layout Standard
36062
36063 \series bold
36064 C Equivalent
36065 \end_layout
36066
36067 \end_inset
36068 </cell>
36069 </row>
36070 <row topline="true">
36071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36072 \begin_inset Text
36073
36074 \begin_layout Standard
36075
36076 \size footnotesize
36077 '!'
36078 \end_layout
36079
36080 \end_inset
36081 </cell>
36082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36083 \begin_inset Text
36084
36085 \begin_layout Standard
36086
36087 \size footnotesize
36088 IC_LEFT() IC_RESULT()
36089 \end_layout
36090
36091 \end_inset
36092 </cell>
36093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36094 \begin_inset Text
36095
36096 \begin_layout Standard
36097
36098 \size footnotesize
36099 NOT operation 
36100 \end_layout
36101
36102 \end_inset
36103 </cell>
36104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36105 \begin_inset Text
36106
36107 \begin_layout Standard
36108
36109 \size footnotesize
36110 IC_RESULT = ! IC_LEFT;
36111 \end_layout
36112
36113 \end_inset
36114 </cell>
36115 </row>
36116 <row topline="true">
36117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36118 \begin_inset Text
36119
36120 \begin_layout Standard
36121
36122 \size footnotesize
36123 '~'
36124 \end_layout
36125
36126 \end_inset
36127 </cell>
36128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36129 \begin_inset Text
36130
36131 \begin_layout Standard
36132
36133 \size footnotesize
36134 IC_LEFT() IC_RESULT()
36135 \end_layout
36136
36137 \end_inset
36138 </cell>
36139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36140 \begin_inset Text
36141
36142 \begin_layout Standard
36143
36144 \size footnotesize
36145 Bitwise complement of 
36146 \end_layout
36147
36148 \end_inset
36149 </cell>
36150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36151 \begin_inset Text
36152
36153 \begin_layout Standard
36154
36155 \size footnotesize
36156 IC_RESULT = ~IC_LEFT;
36157 \end_layout
36158
36159 \end_inset
36160 </cell>
36161 </row>
36162 <row topline="true">
36163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36164 \begin_inset Text
36165
36166 \begin_layout Standard
36167
36168 \size footnotesize
36169 RRC
36170 \end_layout
36171
36172 \end_inset
36173 </cell>
36174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36175 \begin_inset Text
36176
36177 \begin_layout Standard
36178
36179 \size footnotesize
36180 IC_LEFT() IC_RESULT()
36181 \end_layout
36182
36183 \end_inset
36184 </cell>
36185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36186 \begin_inset Text
36187
36188 \begin_layout Standard
36189
36190 \size footnotesize
36191 Rotate right with carry
36192 \end_layout
36193
36194 \end_inset
36195 </cell>
36196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36197 \begin_inset Text
36198
36199 \begin_layout Standard
36200
36201 \size footnotesize
36202 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36203 \end_layout
36204
36205 \end_inset
36206 </cell>
36207 </row>
36208 <row topline="true">
36209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36210 \begin_inset Text
36211
36212 \begin_layout Standard
36213
36214 \size footnotesize
36215 RLC
36216 \end_layout
36217
36218 \end_inset
36219 </cell>
36220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36221 \begin_inset Text
36222
36223 \begin_layout Standard
36224
36225 \size footnotesize
36226 IC_LEFT() IC_RESULT()
36227 \end_layout
36228
36229 \end_inset
36230 </cell>
36231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36232 \begin_inset Text
36233
36234 \begin_layout Standard
36235
36236 \size footnotesize
36237 Rotate left with carry
36238 \end_layout
36239
36240 \end_inset
36241 </cell>
36242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36243 \begin_inset Text
36244
36245 \begin_layout Standard
36246
36247 \size footnotesize
36248 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36249 \end_layout
36250
36251 \end_inset
36252 </cell>
36253 </row>
36254 <row topline="true">
36255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36256 \begin_inset Text
36257
36258 \begin_layout Standard
36259
36260 \size footnotesize
36261 GETHBIT
36262 \end_layout
36263
36264 \end_inset
36265 </cell>
36266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36267 \begin_inset Text
36268
36269 \begin_layout Standard
36270
36271 \size footnotesize
36272 IC_LEFT() IC_RESULT()
36273 \end_layout
36274
36275 \end_inset
36276 </cell>
36277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36278 \begin_inset Text
36279
36280 \begin_layout Standard
36281
36282 \size footnotesize
36283 Get the highest order bit of IC_LEFT
36284 \end_layout
36285
36286 \end_inset
36287 </cell>
36288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36289 \begin_inset Text
36290
36291 \begin_layout Standard
36292
36293 \size footnotesize
36294 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36295 \end_layout
36296
36297 \end_inset
36298 </cell>
36299 </row>
36300 <row topline="true">
36301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36302 \begin_inset Text
36303
36304 \begin_layout Standard
36305
36306 \size footnotesize
36307 UNARYMINUS
36308 \end_layout
36309
36310 \end_inset
36311 </cell>
36312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36313 \begin_inset Text
36314
36315 \begin_layout Standard
36316
36317 \size footnotesize
36318 IC_LEFT() IC_RESULT()
36319 \end_layout
36320
36321 \end_inset
36322 </cell>
36323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36324 \begin_inset Text
36325
36326 \begin_layout Standard
36327
36328 \size footnotesize
36329 Unary minus
36330 \end_layout
36331
36332 \end_inset
36333 </cell>
36334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36335 \begin_inset Text
36336
36337 \begin_layout Standard
36338
36339 \size footnotesize
36340 IC_RESULT = - IC_LEFT;
36341 \end_layout
36342
36343 \end_inset
36344 </cell>
36345 </row>
36346 <row topline="true">
36347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36348 \begin_inset Text
36349
36350 \begin_layout Standard
36351
36352 \size footnotesize
36353 IPUSH
36354 \end_layout
36355
36356 \end_inset
36357 </cell>
36358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36359 \begin_inset Text
36360
36361 \begin_layout Standard
36362
36363 \size footnotesize
36364 IC_LEFT()
36365 \end_layout
36366
36367 \end_inset
36368 </cell>
36369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36370 \begin_inset Text
36371
36372 \begin_layout Standard
36373
36374 \size footnotesize
36375 Push the operand into stack
36376 \end_layout
36377
36378 \end_inset
36379 </cell>
36380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36381 \begin_inset Text
36382
36383 \begin_layout Standard
36384
36385 \size footnotesize
36386 NONE
36387 \end_layout
36388
36389 \end_inset
36390 </cell>
36391 </row>
36392 <row topline="true">
36393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36394 \begin_inset Text
36395
36396 \begin_layout Standard
36397
36398 \size footnotesize
36399 IPOP
36400 \end_layout
36401
36402 \end_inset
36403 </cell>
36404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36405 \begin_inset Text
36406
36407 \begin_layout Standard
36408
36409 \size footnotesize
36410 IC_LEFT()
36411 \end_layout
36412
36413 \end_inset
36414 </cell>
36415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36416 \begin_inset Text
36417
36418 \begin_layout Standard
36419
36420 \size footnotesize
36421 Pop the operand from the stack 
36422 \end_layout
36423
36424 \end_inset
36425 </cell>
36426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36427 \begin_inset Text
36428
36429 \begin_layout Standard
36430
36431 \size footnotesize
36432 NONE
36433 \end_layout
36434
36435 \end_inset
36436 </cell>
36437 </row>
36438 <row topline="true">
36439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36440 \begin_inset Text
36441
36442 \begin_layout Standard
36443
36444 \size footnotesize
36445 CALL
36446 \end_layout
36447
36448 \end_inset
36449 </cell>
36450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36451 \begin_inset Text
36452
36453 \begin_layout Standard
36454
36455 \size footnotesize
36456 IC_LEFT() IC_RESULT()
36457 \end_layout
36458
36459 \end_inset
36460 </cell>
36461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36462 \begin_inset Text
36463
36464 \begin_layout Standard
36465
36466 \size footnotesize
36467 Call the function represented by IC_LEFT 
36468 \end_layout
36469
36470 \end_inset
36471 </cell>
36472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36473 \begin_inset Text
36474
36475 \begin_layout Standard
36476
36477 \size footnotesize
36478 IC_RESULT = IC_LEFT();
36479 \end_layout
36480
36481 \end_inset
36482 </cell>
36483 </row>
36484 <row topline="true">
36485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36486 \begin_inset Text
36487
36488 \begin_layout Standard
36489
36490 \size footnotesize
36491 PCALL
36492 \end_layout
36493
36494 \end_inset
36495 </cell>
36496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36497 \begin_inset Text
36498
36499 \begin_layout Standard
36500
36501 \size footnotesize
36502 IC_LEFT() IC_RESULT()
36503 \end_layout
36504
36505 \end_inset
36506 </cell>
36507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36508 \begin_inset Text
36509
36510 \begin_layout Standard
36511
36512 \size footnotesize
36513 Call via function pointer
36514 \end_layout
36515
36516 \end_inset
36517 </cell>
36518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36519 \begin_inset Text
36520
36521 \begin_layout Standard
36522
36523 \size footnotesize
36524 IC_RESULT = (*IC_LEFT)();
36525 \end_layout
36526
36527 \end_inset
36528 </cell>
36529 </row>
36530 <row topline="true">
36531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36532 \begin_inset Text
36533
36534 \begin_layout Standard
36535
36536 \size footnotesize
36537 RETURN
36538 \end_layout
36539
36540 \end_inset
36541 </cell>
36542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36543 \begin_inset Text
36544
36545 \begin_layout Standard
36546
36547 \size footnotesize
36548 IC_LEFT()
36549 \end_layout
36550
36551 \end_inset
36552 </cell>
36553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36554 \begin_inset Text
36555
36556 \begin_layout Standard
36557
36558 \size footnotesize
36559 Return the value in operand IC_LEFT 
36560 \end_layout
36561
36562 \end_inset
36563 </cell>
36564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36565 \begin_inset Text
36566
36567 \begin_layout Standard
36568
36569 \size footnotesize
36570 return IC_LEFT;
36571 \end_layout
36572
36573 \end_inset
36574 </cell>
36575 </row>
36576 <row topline="true">
36577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36578 \begin_inset Text
36579
36580 \begin_layout Standard
36581
36582 \size footnotesize
36583 LABEL
36584 \end_layout
36585
36586 \end_inset
36587 </cell>
36588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36589 \begin_inset Text
36590
36591 \begin_layout Standard
36592
36593 \size footnotesize
36594 IC_LABEL() 
36595 \end_layout
36596
36597 \end_inset
36598 </cell>
36599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36600 \begin_inset Text
36601
36602 \begin_layout Standard
36603
36604 \size footnotesize
36605 Label
36606 \end_layout
36607
36608 \end_inset
36609 </cell>
36610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36611 \begin_inset Text
36612
36613 \begin_layout Standard
36614
36615 \size footnotesize
36616 IC_LABEL:
36617 \end_layout
36618
36619 \end_inset
36620 </cell>
36621 </row>
36622 <row topline="true">
36623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36624 \begin_inset Text
36625
36626 \begin_layout Standard
36627
36628 \size footnotesize
36629 GOTO
36630 \end_layout
36631
36632 \end_inset
36633 </cell>
36634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36635 \begin_inset Text
36636
36637 \begin_layout Standard
36638
36639 \size footnotesize
36640 IC_LABEL() 
36641 \end_layout
36642
36643 \end_inset
36644 </cell>
36645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36646 \begin_inset Text
36647
36648 \begin_layout Standard
36649
36650 \size footnotesize
36651 Goto label
36652 \end_layout
36653
36654 \end_inset
36655 </cell>
36656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36657 \begin_inset Text
36658
36659 \begin_layout Standard
36660
36661 \size footnotesize
36662 goto IC_LABEL();
36663 \end_layout
36664
36665 \end_inset
36666 </cell>
36667 </row>
36668 <row topline="true">
36669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36670 \begin_inset Text
36671
36672 \begin_layout Standard
36673
36674 \size footnotesize
36675 '+'
36676 \end_layout
36677
36678 \end_inset
36679 </cell>
36680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36681 \begin_inset Text
36682
36683 \begin_layout Standard
36684
36685 \size footnotesize
36686 IC_LEFT() IC_RIGHT() IC_RESULT()
36687 \end_layout
36688
36689 \end_inset
36690 </cell>
36691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36692 \begin_inset Text
36693
36694 \begin_layout Standard
36695
36696 \size footnotesize
36697 Addition
36698 \end_layout
36699
36700 \end_inset
36701 </cell>
36702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36703 \begin_inset Text
36704
36705 \begin_layout Standard
36706
36707 \size footnotesize
36708 IC_RESULT = IC_LEFT + IC_RIGHT
36709 \end_layout
36710
36711 \end_inset
36712 </cell>
36713 </row>
36714 <row topline="true">
36715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36716 \begin_inset Text
36717
36718 \begin_layout Standard
36719
36720 \size footnotesize
36721 '-'
36722 \end_layout
36723
36724 \end_inset
36725 </cell>
36726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36727 \begin_inset Text
36728
36729 \begin_layout Standard
36730
36731 \size footnotesize
36732 IC_LEFT() IC_RIGHT() IC_RESULT()
36733 \end_layout
36734
36735 \end_inset
36736 </cell>
36737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36738 \begin_inset Text
36739
36740 \begin_layout Standard
36741
36742 \size footnotesize
36743 Subtraction
36744 \end_layout
36745
36746 \end_inset
36747 </cell>
36748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36749 \begin_inset Text
36750
36751 \begin_layout Standard
36752
36753 \size footnotesize
36754 IC_RESULT = IC_LEFT - IC_RIGHT 
36755 \end_layout
36756
36757 \end_inset
36758 </cell>
36759 </row>
36760 <row topline="true">
36761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36762 \begin_inset Text
36763
36764 \begin_layout Standard
36765
36766 \size footnotesize
36767 '*'
36768 \end_layout
36769
36770 \end_inset
36771 </cell>
36772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36773 \begin_inset Text
36774
36775 \begin_layout Standard
36776
36777 \size footnotesize
36778 IC_LEFT() IC_RIGHT() IC_RESULT()
36779 \end_layout
36780
36781 \end_inset
36782 </cell>
36783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36784 \begin_inset Text
36785
36786 \begin_layout Standard
36787
36788 \size footnotesize
36789 Multiplication 
36790 \end_layout
36791
36792 \end_inset
36793 </cell>
36794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36795 \begin_inset Text
36796
36797 \begin_layout Standard
36798
36799 \size footnotesize
36800 IC_RESULT = IC_LEFT * IC_RIGHT;
36801 \end_layout
36802
36803 \end_inset
36804 </cell>
36805 </row>
36806 <row topline="true">
36807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36808 \begin_inset Text
36809
36810 \begin_layout Standard
36811
36812 \size footnotesize
36813 '/'
36814 \end_layout
36815
36816 \end_inset
36817 </cell>
36818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36819 \begin_inset Text
36820
36821 \begin_layout Standard
36822
36823 \size footnotesize
36824 IC_LEFT() IC_RIGHT() IC_RESULT()
36825 \end_layout
36826
36827 \end_inset
36828 </cell>
36829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36830 \begin_inset Text
36831
36832 \begin_layout Standard
36833
36834 \size footnotesize
36835 Division
36836 \end_layout
36837
36838 \end_inset
36839 </cell>
36840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36841 \begin_inset Text
36842
36843 \begin_layout Standard
36844
36845 \size footnotesize
36846 IC_RESULT = IC_LEFT / IC_RIGHT;
36847 \end_layout
36848
36849 \end_inset
36850 </cell>
36851 </row>
36852 <row topline="true">
36853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36854 \begin_inset Text
36855
36856 \begin_layout Standard
36857
36858 \size footnotesize
36859 '%'
36860 \end_layout
36861
36862 \end_inset
36863 </cell>
36864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36865 \begin_inset Text
36866
36867 \begin_layout Standard
36868
36869 \size footnotesize
36870 IC_LEFT() IC_RIGHT() IC_RESULT()
36871 \end_layout
36872
36873 \end_inset
36874 </cell>
36875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36876 \begin_inset Text
36877
36878 \begin_layout Standard
36879
36880 \size footnotesize
36881 Modulus
36882 \end_layout
36883
36884 \end_inset
36885 </cell>
36886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36887 \begin_inset Text
36888
36889 \begin_layout Standard
36890
36891 \size footnotesize
36892 IC_RESULT = IC_LEFT % IC_RIGHT;
36893 \end_layout
36894
36895 \end_inset
36896 </cell>
36897 </row>
36898 <row topline="true">
36899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36900 \begin_inset Text
36901
36902 \begin_layout Standard
36903
36904 \size footnotesize
36905 '<'
36906 \end_layout
36907
36908 \end_inset
36909 </cell>
36910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36911 \begin_inset Text
36912
36913 \begin_layout Standard
36914
36915 \size footnotesize
36916 IC_LEFT() IC_RIGHT() IC_RESULT()
36917 \end_layout
36918
36919 \end_inset
36920 </cell>
36921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36922 \begin_inset Text
36923
36924 \begin_layout Standard
36925
36926 \size footnotesize
36927 Less than
36928 \end_layout
36929
36930 \end_inset
36931 </cell>
36932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36933 \begin_inset Text
36934
36935 \begin_layout Standard
36936
36937 \size footnotesize
36938 IC_RESULT = IC_LEFT < IC_RIGHT;
36939 \end_layout
36940
36941 \end_inset
36942 </cell>
36943 </row>
36944 <row topline="true">
36945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36946 \begin_inset Text
36947
36948 \begin_layout Standard
36949
36950 \size footnotesize
36951 '>'
36952 \end_layout
36953
36954 \end_inset
36955 </cell>
36956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36957 \begin_inset Text
36958
36959 \begin_layout Standard
36960
36961 \size footnotesize
36962 IC_LEFT() IC_RIGHT() IC_RESULT()
36963 \end_layout
36964
36965 \end_inset
36966 </cell>
36967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36968 \begin_inset Text
36969
36970 \begin_layout Standard
36971
36972 \size footnotesize
36973 Greater than 
36974 \end_layout
36975
36976 \end_inset
36977 </cell>
36978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36979 \begin_inset Text
36980
36981 \begin_layout Standard
36982
36983 \size footnotesize
36984 IC_RESULT = IC_LEFT > IC_RIGHT;
36985 \end_layout
36986
36987 \end_inset
36988 </cell>
36989 </row>
36990 <row topline="true">
36991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36992 \begin_inset Text
36993
36994 \begin_layout Standard
36995
36996 \size footnotesize
36997 EQ_OP
36998 \end_layout
36999
37000 \end_inset
37001 </cell>
37002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37003 \begin_inset Text
37004
37005 \begin_layout Standard
37006
37007 \size footnotesize
37008 IC_LEFT() IC_RIGHT() IC_RESULT()
37009 \end_layout
37010
37011 \end_inset
37012 </cell>
37013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37014 \begin_inset Text
37015
37016 \begin_layout Standard
37017
37018 \size footnotesize
37019 Equal to 
37020 \end_layout
37021
37022 \end_inset
37023 </cell>
37024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37025 \begin_inset Text
37026
37027 \begin_layout Standard
37028
37029 \size footnotesize
37030 IC_RESULT = IC_LEFT == IC_RIGHT;
37031 \end_layout
37032
37033 \end_inset
37034 </cell>
37035 </row>
37036 <row topline="true">
37037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37038 \begin_inset Text
37039
37040 \begin_layout Standard
37041
37042 \size footnotesize
37043 AND_OP
37044 \end_layout
37045
37046 \end_inset
37047 </cell>
37048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37049 \begin_inset Text
37050
37051 \begin_layout Standard
37052
37053 \size footnotesize
37054 IC_LEFT() IC_RIGHT() IC_RESULT() 
37055 \end_layout
37056
37057 \end_inset
37058 </cell>
37059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37060 \begin_inset Text
37061
37062 \begin_layout Standard
37063
37064 \size footnotesize
37065 Logical and operation
37066 \end_layout
37067
37068 \end_inset
37069 </cell>
37070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37071 \begin_inset Text
37072
37073 \begin_layout Standard
37074
37075 \size footnotesize
37076 IC_RESULT = IC_LEFT && IC_RIGHT; 
37077 \end_layout
37078
37079 \end_inset
37080 </cell>
37081 </row>
37082 <row topline="true">
37083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37084 \begin_inset Text
37085
37086 \begin_layout Standard
37087
37088 \size footnotesize
37089 OR_OP
37090 \end_layout
37091
37092 \end_inset
37093 </cell>
37094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37095 \begin_inset Text
37096
37097 \begin_layout Standard
37098
37099 \size footnotesize
37100 IC_LEFT() IC_RIGHT() IC_RESULT() 
37101 \end_layout
37102
37103 \end_inset
37104 </cell>
37105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37106 \begin_inset Text
37107
37108 \begin_layout Standard
37109
37110 \size footnotesize
37111 Logical or operation 
37112 \end_layout
37113
37114 \end_inset
37115 </cell>
37116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37117 \begin_inset Text
37118
37119 \begin_layout Standard
37120
37121 \size footnotesize
37122 IC_RESULT = IC_LEFT || IC_RIGHT; 
37123 \end_layout
37124
37125 \end_inset
37126 </cell>
37127 </row>
37128 <row topline="true">
37129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37130 \begin_inset Text
37131
37132 \begin_layout Standard
37133
37134 \size footnotesize
37135 '^'
37136 \end_layout
37137
37138 \end_inset
37139 </cell>
37140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37141 \begin_inset Text
37142
37143 \begin_layout Standard
37144
37145 \size footnotesize
37146 IC_LEFT() IC_RIGHT() IC_RESULT() 
37147 \end_layout
37148
37149 \end_inset
37150 </cell>
37151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37152 \begin_inset Text
37153
37154 \begin_layout Standard
37155
37156 \size footnotesize
37157 Exclusive OR
37158 \end_layout
37159
37160 \end_inset
37161 </cell>
37162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37163 \begin_inset Text
37164
37165 \begin_layout Standard
37166
37167 \size footnotesize
37168 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37169 \end_layout
37170
37171 \end_inset
37172 </cell>
37173 </row>
37174 <row topline="true">
37175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37176 \begin_inset Text
37177
37178 \begin_layout Standard
37179
37180 \size footnotesize
37181 '|'
37182 \end_layout
37183
37184 \end_inset
37185 </cell>
37186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37187 \begin_inset Text
37188
37189 \begin_layout Standard
37190
37191 \size footnotesize
37192 IC_LEFT() IC_RIGHT() IC_RESULT() 
37193 \end_layout
37194
37195 \end_inset
37196 </cell>
37197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37198 \begin_inset Text
37199
37200 \begin_layout Standard
37201
37202 \size footnotesize
37203 Bitwise OR 
37204 \end_layout
37205
37206 \end_inset
37207 </cell>
37208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37209 \begin_inset Text
37210
37211 \begin_layout Standard
37212
37213 \size footnotesize
37214 IC_RESULT = IC_LEFT | IC_RIGHT;
37215 \end_layout
37216
37217 \end_inset
37218 </cell>
37219 </row>
37220 <row topline="true">
37221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37222 \begin_inset Text
37223
37224 \begin_layout Standard
37225
37226 \size footnotesize
37227 BITWISEAND
37228 \end_layout
37229
37230 \end_inset
37231 </cell>
37232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37233 \begin_inset Text
37234
37235 \begin_layout Standard
37236
37237 \size footnotesize
37238 IC_LEFT() IC_RIGHT() IC_RESULT()
37239 \end_layout
37240
37241 \end_inset
37242 </cell>
37243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37244 \begin_inset Text
37245
37246 \begin_layout Standard
37247
37248 \size footnotesize
37249 Bitwise AND 
37250 \end_layout
37251
37252 \end_inset
37253 </cell>
37254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37255 \begin_inset Text
37256
37257 \begin_layout Standard
37258
37259 \size footnotesize
37260 IC_RESULT = IC_LEFT & IC_RIGHT;
37261 \end_layout
37262
37263 \end_inset
37264 </cell>
37265 </row>
37266 <row topline="true">
37267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37268 \begin_inset Text
37269
37270 \begin_layout Standard
37271
37272 \size footnotesize
37273 LEFT_OP
37274 \end_layout
37275
37276 \end_inset
37277 </cell>
37278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37279 \begin_inset Text
37280
37281 \begin_layout Standard
37282
37283 \size footnotesize
37284 IC_LEFT() IC_RIGHT() IC_RESULT()
37285 \end_layout
37286
37287 \end_inset
37288 </cell>
37289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37290 \begin_inset Text
37291
37292 \begin_layout Standard
37293
37294 \size footnotesize
37295 Left shift 
37296 \end_layout
37297
37298 \end_inset
37299 </cell>
37300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37301 \begin_inset Text
37302
37303 \begin_layout Standard
37304
37305 \size footnotesize
37306 IC_RESULT = IC_LEFT << IC_RIGHT 
37307 \end_layout
37308
37309 \end_inset
37310 </cell>
37311 </row>
37312 <row topline="true">
37313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37314 \begin_inset Text
37315
37316 \begin_layout Standard
37317
37318 \size footnotesize
37319 RIGHT_OP
37320 \end_layout
37321
37322 \end_inset
37323 </cell>
37324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37325 \begin_inset Text
37326
37327 \begin_layout Standard
37328
37329 \size footnotesize
37330 IC_LEFT() IC_RIGHT() IC_RESULT()
37331 \end_layout
37332
37333 \end_inset
37334 </cell>
37335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37336 \begin_inset Text
37337
37338 \begin_layout Standard
37339
37340 \size footnotesize
37341 Right shift
37342 \end_layout
37343
37344 \end_inset
37345 </cell>
37346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37347 \begin_inset Text
37348
37349 \begin_layout Standard
37350
37351 \size footnotesize
37352 IC_RESULT = IC_LEFT >> IC_RIGHT 
37353 \end_layout
37354
37355 \end_inset
37356 </cell>
37357 </row>
37358 <row topline="true">
37359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37360 \begin_inset Text
37361
37362 \begin_layout Standard
37363
37364 \size footnotesize
37365 GET_VALUE_
37366 \newline
37367 AT_ ADDRESS
37368 \end_layout
37369
37370 \end_inset
37371 </cell>
37372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37373 \begin_inset Text
37374
37375 \begin_layout Standard
37376
37377 \size footnotesize
37378 IC_LEFT() IC_RESULT()
37379 \end_layout
37380
37381 \end_inset
37382 </cell>
37383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37384 \begin_inset Text
37385
37386 \begin_layout Standard
37387
37388 \size footnotesize
37389 Indirect fetch 
37390 \end_layout
37391
37392 \end_inset
37393 </cell>
37394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37395 \begin_inset Text
37396
37397 \begin_layout Standard
37398
37399 \size footnotesize
37400 IC_RESULT = (*IC_LEFT);
37401 \end_layout
37402
37403 \end_inset
37404 </cell>
37405 </row>
37406 <row topline="true">
37407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37408 \begin_inset Text
37409
37410 \begin_layout Standard
37411
37412 \size footnotesize
37413 POINTER_SET
37414 \end_layout
37415
37416 \end_inset
37417 </cell>
37418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37419 \begin_inset Text
37420
37421 \begin_layout Standard
37422
37423 \size footnotesize
37424 IC_RIGHT() IC_RESULT() 
37425 \end_layout
37426
37427 \end_inset
37428 </cell>
37429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37430 \begin_inset Text
37431
37432 \begin_layout Standard
37433
37434 \size footnotesize
37435 Indirect set
37436 \end_layout
37437
37438 \end_inset
37439 </cell>
37440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37441 \begin_inset Text
37442
37443 \begin_layout Standard
37444
37445 \size footnotesize
37446 (*IC_RESULT) = IC_RIGHT;
37447 \end_layout
37448
37449 \end_inset
37450 </cell>
37451 </row>
37452 <row topline="true">
37453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37454 \begin_inset Text
37455
37456 \begin_layout Standard
37457
37458 \size footnotesize
37459 '='
37460 \end_layout
37461
37462 \end_inset
37463 </cell>
37464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37465 \begin_inset Text
37466
37467 \begin_layout Standard
37468
37469 \size footnotesize
37470 IC_RIGHT() IC_RESULT()
37471 \end_layout
37472
37473 \end_inset
37474 </cell>
37475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37476 \begin_inset Text
37477
37478 \begin_layout Standard
37479
37480 \size footnotesize
37481 Assignment
37482 \end_layout
37483
37484 \end_inset
37485 </cell>
37486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37487 \begin_inset Text
37488
37489 \begin_layout Standard
37490
37491 \size footnotesize
37492 IC_RESULT = IC_RIGHT;
37493 \end_layout
37494
37495 \end_inset
37496 </cell>
37497 </row>
37498 <row topline="true">
37499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37500 \begin_inset Text
37501
37502 \begin_layout Standard
37503
37504 \size footnotesize
37505 IFX
37506 \end_layout
37507
37508 \end_inset
37509 </cell>
37510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37511 \begin_inset Text
37512
37513 \begin_layout Standard
37514
37515 \size footnotesize
37516 IC_COND IC_TRUE IC_LABEL
37517 \end_layout
37518
37519 \end_inset
37520 </cell>
37521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37522 \begin_inset Text
37523
37524 \begin_layout Standard
37525
37526 \size footnotesize
37527 Conditional jump.
37528  If true label is present then jump to true label if condition is true else
37529  jump to false label if condition is false 
37530 \end_layout
37531
37532 \end_inset
37533 </cell>
37534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37535 \begin_inset Text
37536
37537 \begin_layout Standard
37538
37539 \size footnotesize
37540 if (IC_COND) goto IC_TRUE; 
37541 \newline
37542 \InsetSpace ~
37543 \InsetSpace ~
37544 Or 
37545 \newline
37546 If (!IC_COND) goto IC_FALSE;
37547 \end_layout
37548
37549 \end_inset
37550 </cell>
37551 </row>
37552 <row topline="true">
37553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37554 \begin_inset Text
37555
37556 \begin_layout Standard
37557
37558 \size footnotesize
37559 ADDRESS_OF
37560 \end_layout
37561
37562 \end_inset
37563 </cell>
37564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37565 \begin_inset Text
37566
37567 \begin_layout Standard
37568
37569 \size footnotesize
37570 IC_LEFT() IC_RESULT()
37571 \end_layout
37572
37573 \end_inset
37574 </cell>
37575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37576 \begin_inset Text
37577
37578 \begin_layout Standard
37579
37580 \size footnotesize
37581 Address of 
37582 \end_layout
37583
37584 \end_inset
37585 </cell>
37586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37587 \begin_inset Text
37588
37589 \begin_layout Standard
37590
37591 \size footnotesize
37592 IC_RESULT = &IC_LEFT();
37593 \end_layout
37594
37595 \end_inset
37596 </cell>
37597 </row>
37598 <row topline="true">
37599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37600 \begin_inset Text
37601
37602 \begin_layout Standard
37603
37604 \size footnotesize
37605 JUMPTABLE
37606 \end_layout
37607
37608 \end_inset
37609 </cell>
37610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37611 \begin_inset Text
37612
37613 \begin_layout Standard
37614
37615 \size footnotesize
37616 IC_JTCOND IC_JTLABELS
37617 \end_layout
37618
37619 \end_inset
37620 </cell>
37621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37622 \begin_inset Text
37623
37624 \begin_layout Standard
37625
37626 \size footnotesize
37627 Jump to list of labels depending on the value of JTCOND
37628 \end_layout
37629
37630 \end_inset
37631 </cell>
37632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37633 \begin_inset Text
37634
37635 \begin_layout Standard
37636
37637 \size footnotesize
37638 Switch statement
37639 \end_layout
37640
37641 \end_inset
37642 </cell>
37643 </row>
37644 <row topline="true">
37645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37646 \begin_inset Text
37647
37648 \begin_layout Standard
37649
37650 \size footnotesize
37651 CAST
37652 \end_layout
37653
37654 \end_inset
37655 </cell>
37656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37657 \begin_inset Text
37658
37659 \begin_layout Standard
37660
37661 \size footnotesize
37662 IC_RIGHT() IC_LEFT() IC_RESULT()
37663 \end_layout
37664
37665 \end_inset
37666 </cell>
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37668 \begin_inset Text
37669
37670 \begin_layout Standard
37671
37672 \size footnotesize
37673 Cast types 
37674 \end_layout
37675
37676 \end_inset
37677 </cell>
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37679 \begin_inset Text
37680
37681 \begin_layout Standard
37682
37683 \size footnotesize
37684 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37685 \end_layout
37686
37687 \end_inset
37688 </cell>
37689 </row>
37690 <row topline="true">
37691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37692 \begin_inset Text
37693
37694 \begin_layout Standard
37695
37696 \size footnotesize
37697 SEND
37698 \end_layout
37699
37700 \end_inset
37701 </cell>
37702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37703 \begin_inset Text
37704
37705 \begin_layout Standard
37706
37707 \size footnotesize
37708 IC_LEFT()
37709 \end_layout
37710
37711 \end_inset
37712 </cell>
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37714 \begin_inset Text
37715
37716 \begin_layout Standard
37717
37718 \size footnotesize
37719 This is used for passing parameters in registers; 
37720 \newline
37721 move IC_LEFT to the next
37722  available parameter register.
37723 \end_layout
37724
37725 \end_inset
37726 </cell>
37727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37728 \begin_inset Text
37729
37730 \begin_layout Standard
37731
37732 \size footnotesize
37733 None
37734 \end_layout
37735
37736 \end_inset
37737 </cell>
37738 </row>
37739 <row topline="true">
37740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37741 \begin_inset Text
37742
37743 \begin_layout Standard
37744
37745 \size footnotesize
37746 RECV
37747 \end_layout
37748
37749 \end_inset
37750 </cell>
37751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37752 \begin_inset Text
37753
37754 \begin_layout Standard
37755
37756 \size footnotesize
37757 IC_RESULT()
37758 \end_layout
37759
37760 \end_inset
37761 </cell>
37762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37763 \begin_inset Text
37764
37765 \begin_layout Standard
37766
37767 \size footnotesize
37768 This is used for receiving parameters passed in registers;
37769 \newline
37770 Move the values
37771  in the next parameter register to IC_RESULT 
37772 \end_layout
37773
37774 \end_inset
37775 </cell>
37776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37777 \begin_inset Text
37778
37779 \begin_layout Standard
37780
37781 \size footnotesize
37782 None
37783 \end_layout
37784
37785 \end_inset
37786 </cell>
37787 </row>
37788 <row topline="true" bottomline="true">
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37790 \begin_inset Text
37791
37792 \begin_layout Standard
37793
37794 \shape slanted
37795 \size footnotesize
37796 (some more have been added)
37797 \end_layout
37798
37799 \end_inset
37800 </cell>
37801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37802 \begin_inset Text
37803
37804 \begin_layout Standard
37805
37806 \end_layout
37807
37808 \end_inset
37809 </cell>
37810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37811 \begin_inset Text
37812
37813 \begin_layout Standard
37814
37815 \end_layout
37816
37817 \end_inset
37818 </cell>
37819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37820 \begin_inset Text
37821
37822 \begin_layout Standard
37823
37824 \shape slanted
37825 \size footnotesize
37826 see f.e.
37827  
37828 \family typewriter
37829 gen51Code()
37830 \family default
37831  in 
37832 \family typewriter
37833 src/mcs51/gen.c
37834 \end_layout
37835
37836 \end_inset
37837 </cell>
37838 </row>
37839 </lyxtabular>
37840
37841 \end_inset
37842
37843
37844 \end_layout
37845
37846 \begin_layout Standard
37847 \begin_inset Note Note
37848 status collapsed
37849
37850 \begin_layout Standard
37851 In the original article Figure II was announced to be downloadable on 
37852 \shape italic
37853 Circuit Cellar
37854 \shape default
37855 's web site.
37856  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37857 \end_layout
37858
37859 \end_inset
37860
37861
37862 \end_layout
37863
37864 \begin_layout Paragraph*
37865 ICode Example
37866 \begin_inset LatexCommand \index{iCode}
37867
37868 \end_inset
37869
37870
37871 \end_layout
37872
37873 \begin_layout Standard
37874 This section shows some details of iCode.
37875  The example C code does not do anything useful; it is used as an example
37876  to illustrate the intermediate code generated by the compiler.
37877 \end_layout
37878
37879 \begin_layout Verse
37880
37881 \family typewriter
37882 1.\InsetSpace ~
37883 xdata int * p;
37884 \newline
37885 2.\InsetSpace ~
37886 int gint;
37887 \newline
37888 3.\InsetSpace ~
37889 /* This function does nothing useful.
37890  It is used
37891 \newline
37892 4.\InsetSpace ~
37893 \InsetSpace ~
37894 \InsetSpace ~
37895 \InsetSpace ~
37896 for the purpose of explaining iCode */
37897 \newline
37898 5.\InsetSpace ~
37899 short function (data
37900  int *x)
37901 \newline
37902 6.\InsetSpace ~
37903 {
37904 \newline
37905 7.\InsetSpace ~
37906 \InsetSpace ~
37907 \InsetSpace ~
37908 short i=10; \InsetSpace ~
37909 \InsetSpace ~
37910 /* dead initialization eliminated */
37911 \newline
37912 8.\InsetSpace ~
37913 \InsetSpace ~
37914 \InsetSpace ~
37915 short sum=10;
37916  /* dead initialization eliminated */
37917 \newline
37918 9.\InsetSpace ~
37919 \InsetSpace ~
37920 \InsetSpace ~
37921 short mul;
37922 \newline
37923 10.\InsetSpace ~
37924 \InsetSpace ~
37925 int j ;
37926 \newline
37927 11.\InsetSpace ~
37928 \InsetSpace ~
37929 while (*x) *x++
37930  = *p++; 
37931 \newline
37932 12.\InsetSpace ~
37933 \InsetSpace ~
37934 \InsetSpace ~
37935 \InsetSpace ~
37936 sum = 0 ; 
37937 \newline
37938 13.\InsetSpace ~
37939 \InsetSpace ~
37940 mul = 0;
37941 \newline
37942 14.\InsetSpace ~
37943 \InsetSpace ~
37944 /* compiler detects i,j to be induction
37945  variables */
37946 \newline
37947 15.\InsetSpace ~
37948 \InsetSpace ~
37949 for (i = 0, j = 10 ; i < 10 ; i++, j
37950 \family default
37951 -
37952 \begin_inset ERT
37953 status collapsed
37954
37955 \begin_layout Standard
37956
37957
37958 \backslash
37959 /
37960 \end_layout
37961
37962 \end_inset
37963
37964 -
37965 \family typewriter
37966 ) {
37967 \newline
37968 16.\InsetSpace ~
37969 \InsetSpace ~
37970 \InsetSpace ~
37971 \InsetSpace ~
37972 sum += i;
37973 \newline
37974 17.\InsetSpace ~
37975 \InsetSpace ~
37976 \InsetSpace ~
37977 \InsetSpace ~
37978 mul += i * 3; \InsetSpace ~
37979 \InsetSpace ~
37980 /* this multiplication remains */
37981 \newline
37982 18.\InsetSpace ~
37983 \InsetSpace ~
37984 \InsetSpace ~
37985 \InsetSpace ~
37986 gint +=
37987  j * 3;\InsetSpace ~
37988 \InsetSpace ~
37989 /* this multiplication changed to addition */
37990 \newline
37991 19.\InsetSpace ~
37992 \InsetSpace ~
37993 }
37994 \newline
37995 20.\InsetSpace ~
37996 \InsetSpace ~
37997 return sum+mul;
37998 \newline
37999 21.\InsetSpace ~
38000 }
38001 \end_layout
38002
38003 \begin_layout Standard
38004 In addition to the operands each iCode contains information about the filename
38005  and line it corresponds to in the source file.
38006  The first field in the listing should be interpreted as follows:
38007 \newline
38008
38009 \shape italic
38010 \size footnotesize
38011 Filename(linenumber: iCode Execution sequence number : ICode hash table
38012  key : loop depth of the iCode).
38013 \shape default
38014 \size default
38015
38016 \newline
38017 Then follows the human readable form of the ICode operation.
38018  Each operand of this triplet form can be of three basic types a) compiler
38019  generated temporary b) user defined variable c) a constant value.
38020  Note that local variables and parameters are replaced by compiler generated
38021  temporaries.
38022  Live ranges
38023 \begin_inset LatexCommand \index{Live range analysis}
38024
38025 \end_inset
38026
38027  are computed only for temporaries (i.e.
38028  live ranges are not computed for global variables).
38029  Registers
38030 \begin_inset LatexCommand \index{Register allocation}
38031
38032 \end_inset
38033
38034  are allocated for temporaries only.
38035  Operands are formatted in the following manner:
38036 \newline
38037
38038 \shape italic
38039 \size footnotesize
38040 Operand Name [lr live-from : live-to ] { type information } [ registers
38041  allocated ].
38042 \shape default
38043 \size default
38044
38045 \newline
38046 As mentioned earlier the live ranges are computed in terms of the execution
38047  sequence number of the iCodes, for example 
38048 \newline
38049 the iTemp0 is live from (i.e.
38050  first defined in iCode with execution sequence number 3, and is last used
38051  in the iCode with sequence number 5).
38052  For induction variables such as iTemp21 the live range computation extends
38053  the lifetime from the start to the end of the loop.
38054 \newline
38055 The register allocator
38056  used the live range information to allocate registers, the same registers
38057  may be used for different temporaries if their live ranges do not overlap,
38058  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38059  ranges do not overlap.
38060  In addition the allocator also takes into consideration the type and usage
38061  of a temporary, for example itemp6 is a pointer to near space and is used
38062  as to fetch data from (i.e.
38063  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38064  Some short lived temporaries are allocated to special registers which have
38065  meaning to the code generator e.g.
38066  iTemp13 is allocated to a pseudo register CC which tells the back end that
38067  the temporary is used only for a conditional jump the code generation makes
38068  use of this information to optimize a compare and jump ICode.
38069 \newline
38070 There are several
38071  loop optimizations
38072 \begin_inset LatexCommand \index{Loop optimization}
38073
38074 \end_inset
38075
38076  performed by the compiler.
38077  It can detect induction variables iTemp21(i) and iTemp23(j).
38078  Also note the compiler does selective strength reduction
38079 \begin_inset LatexCommand \index{Strength reduction}
38080
38081 \end_inset
38082
38083 , i.e.
38084  the multiplication of an induction variable in line 18 (gint = j * 3) is
38085  changed to addition, a new temporary iTemp17 is allocated and assigned
38086  a initial value, a constant 3 is then added for each iteration of the loop.
38087  The compiler does not change the multiplication
38088 \begin_inset LatexCommand \index{Multiplication}
38089
38090 \end_inset
38091
38092  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38093 \newline
38094
38095 Note the dead code elimination
38096 \begin_inset LatexCommand \index{Dead-code elimination}
38097
38098 \end_inset
38099
38100  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38101  respectively.
38102 \newline
38103
38104 \end_layout
38105
38106 \begin_layout Standard
38107
38108 \size footnotesize
38109 Sample.c (5:1:0:0) _entry($9) :
38110 \end_layout
38111
38112 \begin_layout Standard
38113
38114 \size footnotesize
38115 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38116 \end_layout
38117
38118 \begin_layout Standard
38119
38120 \size footnotesize
38121 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38122 \end_layout
38123
38124 \begin_layout Standard
38125
38126 \size footnotesize
38127 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38128 \end_layout
38129
38130 \begin_layout Standard
38131
38132 \size footnotesize
38133 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38134  * int}[r2]
38135 \end_layout
38136
38137 \begin_layout Standard
38138
38139 \size footnotesize
38140 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38141 \end_layout
38142
38143 \begin_layout Standard
38144
38145 \size footnotesize
38146 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38147  int}[r0]]
38148 \end_layout
38149
38150 \begin_layout Standard
38151
38152 \size footnotesize
38153 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38154 \end_layout
38155
38156 \begin_layout Standard
38157
38158 \size footnotesize
38159 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38160  * int}
38161 \end_layout
38162
38163 \begin_layout Standard
38164
38165 \size footnotesize
38166 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38167  {short}
38168 \end_layout
38169
38170 \begin_layout Standard
38171
38172 \size footnotesize
38173 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38174  * int}[DPTR]]
38175 \end_layout
38176
38177 \begin_layout Standard
38178
38179 \size footnotesize
38180 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38181 }[r2 r3]
38182 \end_layout
38183
38184 \begin_layout Standard
38185
38186 \size footnotesize
38187 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38188  * int}[r0] + 0x2 {short}
38189 \end_layout
38190
38191 \begin_layout Standard
38192
38193 \size footnotesize
38194 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38195 \end_layout
38196
38197 \begin_layout Standard
38198
38199 \size footnotesize
38200 Sample.c(11:17:21:0)_whilebreak_0($3) :
38201 \end_layout
38202
38203 \begin_layout Standard
38204
38205 \size footnotesize
38206 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38207 \end_layout
38208
38209 \begin_layout Standard
38210
38211 \size footnotesize
38212 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38213 \end_layout
38214
38215 \begin_layout Standard
38216
38217 \size footnotesize
38218 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38219 \end_layout
38220
38221 \begin_layout Standard
38222
38223 \size footnotesize
38224 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38225 \end_layout
38226
38227 \begin_layout Standard
38228
38229 \size footnotesize
38230 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38231 \end_layout
38232
38233 \begin_layout Standard
38234
38235 \size footnotesize
38236 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38237 \end_layout
38238
38239 \begin_layout Standard
38240
38241 \size footnotesize
38242 Sample.c(15:24:26:1)_forcond_0($4) :
38243 \end_layout
38244
38245 \begin_layout Standard
38246
38247 \size footnotesize
38248 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38249  < 0xa {short}
38250 \end_layout
38251
38252 \begin_layout Standard
38253
38254 \size footnotesize
38255 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38256 \end_layout
38257
38258 \begin_layout Standard
38259
38260 \size footnotesize
38261 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38262  + ITemp21 [lr21:38]{short}[r4]
38263 \end_layout
38264
38265 \begin_layout Standard
38266
38267 \size footnotesize
38268 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38269  * 0x3 {short}
38270 \end_layout
38271
38272 \begin_layout Standard
38273
38274 \size footnotesize
38275 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38276  + iTemp15 [lr29:30]{short}[r1]
38277 \end_layout
38278
38279 \begin_layout Standard
38280
38281 \size footnotesize
38282 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38283  r0]- 0x3 {short}
38284 \end_layout
38285
38286 \begin_layout Standard
38287
38288 \size footnotesize
38289 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38290 int}[r7 r0]
38291 \end_layout
38292
38293 \begin_layout Standard
38294
38295 \size footnotesize
38296 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38297  + 0x1 {short}
38298 \end_layout
38299
38300 \begin_layout Standard
38301
38302 \size footnotesize
38303 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38304  r6]- 0x1 {short}
38305 \end_layout
38306
38307 \begin_layout Standard
38308
38309 \size footnotesize
38310 Sample.c(19:38:47:1) goto _forcond_0($4)
38311 \end_layout
38312
38313 \begin_layout Standard
38314
38315 \size footnotesize
38316 Sample.c(19:39:48:0)_forbreak_0($7) :
38317 \end_layout
38318
38319 \begin_layout Standard
38320
38321 \size footnotesize
38322 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38323  + ITemp11 [lr19:40]{short}[r3]
38324 \end_layout
38325
38326 \begin_layout Standard
38327
38328 \size footnotesize
38329 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38330 \end_layout
38331
38332 \begin_layout Standard
38333
38334 \size footnotesize
38335 Sample.c(20:42:51:0)_return($8) :
38336 \end_layout
38337
38338 \begin_layout Standard
38339
38340 \size footnotesize
38341 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38342 \size default
38343
38344 \newline
38345
38346 \newline
38347 Finally the code generated for this function:
38348 \newline
38349
38350 \end_layout
38351
38352 \begin_layout Standard
38353
38354 \size footnotesize
38355 .area DSEG (DATA)
38356 \end_layout
38357
38358 \begin_layout Standard
38359
38360 \size footnotesize
38361 _p::
38362 \end_layout
38363
38364 \begin_layout Standard
38365
38366 \size footnotesize
38367 \InsetSpace ~
38368 \InsetSpace ~
38369 .ds 2
38370 \end_layout
38371
38372 \begin_layout Standard
38373
38374 \size footnotesize
38375 _gint::
38376 \end_layout
38377
38378 \begin_layout Standard
38379
38380 \size footnotesize
38381 \InsetSpace ~
38382 \InsetSpace ~
38383 .ds 2
38384 \end_layout
38385
38386 \begin_layout Standard
38387
38388 \size footnotesize
38389 ; sample.c 5
38390 \end_layout
38391
38392 \begin_layout Standard
38393
38394 \size footnotesize
38395 ; ----------------------------------------------
38396 \end_layout
38397
38398 \begin_layout Standard
38399
38400 \size footnotesize
38401 ; function function
38402 \end_layout
38403
38404 \begin_layout Standard
38405
38406 \size footnotesize
38407 ; ----------------------------------------------
38408 \end_layout
38409
38410 \begin_layout Standard
38411
38412 \size footnotesize
38413 _function:
38414 \end_layout
38415
38416 \begin_layout Standard
38417
38418 \size footnotesize
38419 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38420 \end_layout
38421
38422 \begin_layout Standard
38423
38424 \size footnotesize
38425 \InsetSpace ~
38426 \InsetSpace ~
38427 mov r2,dpl
38428 \end_layout
38429
38430 \begin_layout Standard
38431
38432 \size footnotesize
38433 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38434 \end_layout
38435
38436 \begin_layout Standard
38437
38438 \size footnotesize
38439 \InsetSpace ~
38440 \InsetSpace ~
38441 mov ar0,r2
38442 \end_layout
38443
38444 \begin_layout Standard
38445
38446 \size footnotesize
38447 ;_whilecontinue_0($1) :
38448 \end_layout
38449
38450 \begin_layout Standard
38451
38452 \size footnotesize
38453 00101$:
38454 \end_layout
38455
38456 \begin_layout Standard
38457
38458 \size footnotesize
38459 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38460 \end_layout
38461
38462 \begin_layout Standard
38463
38464 \size footnotesize
38465 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38466 \end_layout
38467
38468 \begin_layout Standard
38469
38470 \size footnotesize
38471 \InsetSpace ~
38472 \InsetSpace ~
38473 mov ar2,@r0
38474 \end_layout
38475
38476 \begin_layout Standard
38477
38478 \size footnotesize
38479 \InsetSpace ~
38480 \InsetSpace ~
38481 inc r0
38482 \end_layout
38483
38484 \begin_layout Standard
38485
38486 \size footnotesize
38487 \InsetSpace ~
38488 \InsetSpace ~
38489 mov ar3,@r0
38490 \end_layout
38491
38492 \begin_layout Standard
38493
38494 \size footnotesize
38495 \InsetSpace ~
38496 \InsetSpace ~
38497 dec r0
38498 \end_layout
38499
38500 \begin_layout Standard
38501
38502 \size footnotesize
38503 \InsetSpace ~
38504 \InsetSpace ~
38505 mov a,r2
38506 \end_layout
38507
38508 \begin_layout Standard
38509
38510 \size footnotesize
38511 \InsetSpace ~
38512 \InsetSpace ~
38513 orl a,r3
38514 \end_layout
38515
38516 \begin_layout Standard
38517
38518 \size footnotesize
38519 \InsetSpace ~
38520 \InsetSpace ~
38521 jz 00103$
38522 \end_layout
38523
38524 \begin_layout Standard
38525
38526 \size footnotesize
38527 00114$:
38528 \end_layout
38529
38530 \begin_layout Standard
38531
38532 \size footnotesize
38533 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38534 \end_layout
38535
38536 \begin_layout Standard
38537
38538 \size footnotesize
38539 \InsetSpace ~
38540 \InsetSpace ~
38541 mov dpl,_p
38542 \end_layout
38543
38544 \begin_layout Standard
38545
38546 \size footnotesize
38547 \InsetSpace ~
38548 \InsetSpace ~
38549 mov dph,(_p + 1)
38550 \end_layout
38551
38552 \begin_layout Standard
38553
38554 \size footnotesize
38555 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38556 \end_layout
38557
38558 \begin_layout Standard
38559
38560 \size footnotesize
38561 \InsetSpace ~
38562 \InsetSpace ~
38563 mov a,#0x02
38564 \end_layout
38565
38566 \begin_layout Standard
38567
38568 \size footnotesize
38569 \InsetSpace ~
38570 \InsetSpace ~
38571 add a,_p
38572 \end_layout
38573
38574 \begin_layout Standard
38575
38576 \size footnotesize
38577 \InsetSpace ~
38578 \InsetSpace ~
38579 mov _p,a
38580 \end_layout
38581
38582 \begin_layout Standard
38583
38584 \size footnotesize
38585 \InsetSpace ~
38586 \InsetSpace ~
38587 clr a
38588 \end_layout
38589
38590 \begin_layout Standard
38591
38592 \size footnotesize
38593 \InsetSpace ~
38594 \InsetSpace ~
38595 addc a,(_p + 1)
38596 \end_layout
38597
38598 \begin_layout Standard
38599
38600 \size footnotesize
38601 \InsetSpace ~
38602 \InsetSpace ~
38603 mov (_p + 1),a
38604 \end_layout
38605
38606 \begin_layout Standard
38607
38608 \size footnotesize
38609 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38610 \end_layout
38611
38612 \begin_layout Standard
38613
38614 \size footnotesize
38615 \InsetSpace ~
38616 \InsetSpace ~
38617 movx a,@dptr
38618 \end_layout
38619
38620 \begin_layout Standard
38621
38622 \size footnotesize
38623 \InsetSpace ~
38624 \InsetSpace ~
38625 mov r2,a
38626 \end_layout
38627
38628 \begin_layout Standard
38629
38630 \size footnotesize
38631 \InsetSpace ~
38632 \InsetSpace ~
38633 inc dptr
38634 \end_layout
38635
38636 \begin_layout Standard
38637
38638 \size footnotesize
38639 \InsetSpace ~
38640 \InsetSpace ~
38641 movx a,@dptr
38642 \end_layout
38643
38644 \begin_layout Standard
38645
38646 \size footnotesize
38647 \InsetSpace ~
38648 \InsetSpace ~
38649 mov r3,a
38650 \end_layout
38651
38652 \begin_layout Standard
38653
38654 \size footnotesize
38655 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38656 \end_layout
38657
38658 \begin_layout Standard
38659
38660 \size footnotesize
38661 \InsetSpace ~
38662 \InsetSpace ~
38663 mov @r0,ar2
38664 \end_layout
38665
38666 \begin_layout Standard
38667
38668 \size footnotesize
38669 \InsetSpace ~
38670 \InsetSpace ~
38671 inc r0
38672 \end_layout
38673
38674 \begin_layout Standard
38675
38676 \size footnotesize
38677 \InsetSpace ~
38678 \InsetSpace ~
38679 mov @r0,ar3
38680 \end_layout
38681
38682 \begin_layout Standard
38683
38684 \size footnotesize
38685 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38686 \end_layout
38687
38688 \begin_layout Standard
38689
38690 \size footnotesize
38691 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38692 \end_layout
38693
38694 \begin_layout Standard
38695
38696 \size footnotesize
38697 ; 0x2 {short}
38698 \end_layout
38699
38700 \begin_layout Standard
38701
38702 \size footnotesize
38703 \InsetSpace ~
38704 \InsetSpace ~
38705 inc r0
38706 \end_layout
38707
38708 \begin_layout Standard
38709
38710 \size footnotesize
38711 ; goto _whilecontinue_0($1)
38712 \end_layout
38713
38714 \begin_layout Standard
38715
38716 \size footnotesize
38717 \InsetSpace ~
38718 \InsetSpace ~
38719 sjmp 00101$
38720 \end_layout
38721
38722 \begin_layout Standard
38723
38724 \size footnotesize
38725 ; _whilebreak_0($3) :
38726 \end_layout
38727
38728 \begin_layout Standard
38729
38730 \size footnotesize
38731 00103$:
38732 \end_layout
38733
38734 \begin_layout Standard
38735
38736 \size footnotesize
38737 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38738 \end_layout
38739
38740 \begin_layout Standard
38741
38742 \size footnotesize
38743 \InsetSpace ~
38744 \InsetSpace ~
38745 mov r2,#0x00
38746 \end_layout
38747
38748 \begin_layout Standard
38749
38750 \size footnotesize
38751 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38752 \end_layout
38753
38754 \begin_layout Standard
38755
38756 \size footnotesize
38757 \InsetSpace ~
38758 \InsetSpace ~
38759 mov r3,#0x00
38760 \end_layout
38761
38762 \begin_layout Standard
38763
38764 \size footnotesize
38765 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38766 \end_layout
38767
38768 \begin_layout Standard
38769
38770 \size footnotesize
38771 \InsetSpace ~
38772 \InsetSpace ~
38773 mov r4,#0x00
38774 \end_layout
38775
38776 \begin_layout Standard
38777
38778 \size footnotesize
38779 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38780 \end_layout
38781
38782 \begin_layout Standard
38783
38784 \size footnotesize
38785 \InsetSpace ~
38786 \InsetSpace ~
38787 mov r5,#0x0A
38788 \end_layout
38789
38790 \begin_layout Standard
38791
38792 \size footnotesize
38793 \InsetSpace ~
38794 \InsetSpace ~
38795 mov r6,#0x00
38796 \end_layout
38797
38798 \begin_layout Standard
38799
38800 \size footnotesize
38801 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38802 \end_layout
38803
38804 \begin_layout Standard
38805
38806 \size footnotesize
38807 \InsetSpace ~
38808 \InsetSpace ~
38809 mov r7,#0x1E
38810 \end_layout
38811
38812 \begin_layout Standard
38813
38814 \size footnotesize
38815 \InsetSpace ~
38816 \InsetSpace ~
38817 mov r0,#0x00
38818 \end_layout
38819
38820 \begin_layout Standard
38821
38822 \size footnotesize
38823 ; _forcond_0($4) :
38824 \end_layout
38825
38826 \begin_layout Standard
38827
38828 \size footnotesize
38829 00104$:
38830 \end_layout
38831
38832 \begin_layout Standard
38833
38834 \size footnotesize
38835 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38836 \end_layout
38837
38838 \begin_layout Standard
38839
38840 \size footnotesize
38841 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38842 \end_layout
38843
38844 \begin_layout Standard
38845
38846 \size footnotesize
38847 \InsetSpace ~
38848 \InsetSpace ~
38849 clr c
38850 \end_layout
38851
38852 \begin_layout Standard
38853
38854 \size footnotesize
38855 \InsetSpace ~
38856 \InsetSpace ~
38857 mov a,r4
38858 \end_layout
38859
38860 \begin_layout Standard
38861
38862 \size footnotesize
38863 \InsetSpace ~
38864 \InsetSpace ~
38865 xrl a,#0x80
38866 \end_layout
38867
38868 \begin_layout Standard
38869
38870 \size footnotesize
38871 \InsetSpace ~
38872 \InsetSpace ~
38873 subb a,#0x8a
38874 \end_layout
38875
38876 \begin_layout Standard
38877
38878 \size footnotesize
38879 \InsetSpace ~
38880 \InsetSpace ~
38881 jnc 00107$
38882 \end_layout
38883
38884 \begin_layout Standard
38885
38886 \size footnotesize
38887 00115$:
38888 \end_layout
38889
38890 \begin_layout Standard
38891
38892 \size footnotesize
38893 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38894 \end_layout
38895
38896 \begin_layout Standard
38897
38898 \size footnotesize
38899 ; iTemp21 [lr21:38]{short}[r4]
38900 \end_layout
38901
38902 \begin_layout Standard
38903
38904 \size footnotesize
38905 \InsetSpace ~
38906 \InsetSpace ~
38907 mov a,r4
38908 \end_layout
38909
38910 \begin_layout Standard
38911
38912 \size footnotesize
38913 \InsetSpace ~
38914 \InsetSpace ~
38915 add a,r2
38916 \end_layout
38917
38918 \begin_layout Standard
38919
38920 \size footnotesize
38921 \InsetSpace ~
38922 \InsetSpace ~
38923 mov r2,a
38924 \end_layout
38925
38926 \begin_layout Standard
38927
38928 \size footnotesize
38929 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38930 \end_layout
38931
38932 \begin_layout Standard
38933
38934 \size footnotesize
38935 \InsetSpace ~
38936 \InsetSpace ~
38937 mov b,#0x03
38938 \end_layout
38939
38940 \begin_layout Standard
38941
38942 \size footnotesize
38943 \InsetSpace ~
38944 \InsetSpace ~
38945 mov a,r4
38946 \end_layout
38947
38948 \begin_layout Standard
38949
38950 \size footnotesize
38951 \InsetSpace ~
38952 \InsetSpace ~
38953 mul ab
38954 \end_layout
38955
38956 \begin_layout Standard
38957
38958 \size footnotesize
38959 \InsetSpace ~
38960 \InsetSpace ~
38961 mov r1,a
38962 \end_layout
38963
38964 \begin_layout Standard
38965
38966 \size footnotesize
38967 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
38968 \end_layout
38969
38970 \begin_layout Standard
38971
38972 \size footnotesize
38973 ; iTemp15 [lr29:30]{short}[r1]
38974 \end_layout
38975
38976 \begin_layout Standard
38977
38978 \size footnotesize
38979 \InsetSpace ~
38980 \InsetSpace ~
38981 add a,r3
38982 \end_layout
38983
38984 \begin_layout Standard
38985
38986 \size footnotesize
38987 \InsetSpace ~
38988 \InsetSpace ~
38989 mov r3,a
38990 \end_layout
38991
38992 \begin_layout Standard
38993
38994 \size footnotesize
38995 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38996 \end_layout
38997
38998 \begin_layout Standard
38999
39000 \size footnotesize
39001 \InsetSpace ~
39002 \InsetSpace ~
39003 mov a,r7
39004 \end_layout
39005
39006 \begin_layout Standard
39007
39008 \size footnotesize
39009 \InsetSpace ~
39010 \InsetSpace ~
39011 add a,#0xfd
39012 \end_layout
39013
39014 \begin_layout Standard
39015
39016 \size footnotesize
39017 \InsetSpace ~
39018 \InsetSpace ~
39019 mov r7,a
39020 \end_layout
39021
39022 \begin_layout Standard
39023
39024 \size footnotesize
39025 \InsetSpace ~
39026 \InsetSpace ~
39027 mov a,r0
39028 \end_layout
39029
39030 \begin_layout Standard
39031
39032 \size footnotesize
39033 \InsetSpace ~
39034 \InsetSpace ~
39035 addc a,#0xff
39036 \end_layout
39037
39038 \begin_layout Standard
39039
39040 \size footnotesize
39041 \InsetSpace ~
39042 \InsetSpace ~
39043 mov r0,a
39044 \end_layout
39045
39046 \begin_layout Standard
39047
39048 \size footnotesize
39049 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39050 \end_layout
39051
39052 \begin_layout Standard
39053
39054 \size footnotesize
39055 \InsetSpace ~
39056 \InsetSpace ~
39057 mov a,r7
39058 \end_layout
39059
39060 \begin_layout Standard
39061
39062 \size footnotesize
39063 \InsetSpace ~
39064 \InsetSpace ~
39065 add a,_gint
39066 \end_layout
39067
39068 \begin_layout Standard
39069
39070 \size footnotesize
39071 \InsetSpace ~
39072 \InsetSpace ~
39073 mov _gint,a
39074 \end_layout
39075
39076 \begin_layout Standard
39077
39078 \size footnotesize
39079 \InsetSpace ~
39080 \InsetSpace ~
39081 mov a,r0
39082 \end_layout
39083
39084 \begin_layout Standard
39085
39086 \size footnotesize
39087 \InsetSpace ~
39088 \InsetSpace ~
39089 addc a,(_gint + 1)
39090 \end_layout
39091
39092 \begin_layout Standard
39093
39094 \size footnotesize
39095 \InsetSpace ~
39096 \InsetSpace ~
39097 mov (_gint + 1),a
39098 \end_layout
39099
39100 \begin_layout Standard
39101
39102 \size footnotesize
39103 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39104 \end_layout
39105
39106 \begin_layout Standard
39107
39108 \size footnotesize
39109 \InsetSpace ~
39110 \InsetSpace ~
39111 inc r4
39112 \end_layout
39113
39114 \begin_layout Standard
39115
39116 \size footnotesize
39117 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39118 \end_layout
39119
39120 \begin_layout Standard
39121
39122 \size footnotesize
39123 \InsetSpace ~
39124 \InsetSpace ~
39125 dec r5
39126 \end_layout
39127
39128 \begin_layout Standard
39129
39130 \size footnotesize
39131 \InsetSpace ~
39132 \InsetSpace ~
39133 cjne r5,#0xff,00104$
39134 \end_layout
39135
39136 \begin_layout Standard
39137
39138 \size footnotesize
39139 \InsetSpace ~
39140 \InsetSpace ~
39141 dec r6
39142 \end_layout
39143
39144 \begin_layout Standard
39145
39146 \size footnotesize
39147 ; goto _forcond_0($4)
39148 \end_layout
39149
39150 \begin_layout Standard
39151
39152 \size footnotesize
39153 \InsetSpace ~
39154 \InsetSpace ~
39155 sjmp 00104$
39156 \end_layout
39157
39158 \begin_layout Standard
39159
39160 \size footnotesize
39161 ; _forbreak_0($7) :
39162 \end_layout
39163
39164 \begin_layout Standard
39165
39166 \size footnotesize
39167 00107$:
39168 \end_layout
39169
39170 \begin_layout Standard
39171
39172 \size footnotesize
39173 ; ret iTemp24 [lr40:41]{short}
39174 \end_layout
39175
39176 \begin_layout Standard
39177
39178 \size footnotesize
39179 \InsetSpace ~
39180 \InsetSpace ~
39181 mov a,r3
39182 \end_layout
39183
39184 \begin_layout Standard
39185
39186 \size footnotesize
39187 \InsetSpace ~
39188 \InsetSpace ~
39189 add a,r2
39190 \end_layout
39191
39192 \begin_layout Standard
39193
39194 \size footnotesize
39195 \InsetSpace ~
39196 \InsetSpace ~
39197 mov dpl,a
39198 \end_layout
39199
39200 \begin_layout Standard
39201
39202 \size footnotesize
39203 ; _return($8) :
39204 \end_layout
39205
39206 \begin_layout Standard
39207
39208 \size footnotesize
39209 00108$:
39210 \end_layout
39211
39212 \begin_layout Standard
39213
39214 \size footnotesize
39215 \InsetSpace ~
39216 \InsetSpace ~
39217 ret
39218 \newline
39219
39220 \end_layout
39221
39222 \begin_layout Section
39223 A few words about basic block successors, predecessors and dominators
39224 \end_layout
39225
39226 \begin_layout Standard
39227 Successors are basic blocks
39228 \begin_inset LatexCommand \index{Basic blocks}
39229
39230 \end_inset
39231
39232  that might execute after this basic block.
39233 \newline
39234 Predecessors are basic blocks
39235  that might execute before reaching this basic block.
39236 \newline
39237 Dominators are basic
39238  blocks that WILL execute before reaching this basic block.
39239 \newline
39240
39241 \end_layout
39242
39243 \begin_layout Standard
39244 [basic block 1]
39245 \end_layout
39246
39247 \begin_layout Standard
39248 if (something)
39249 \end_layout
39250
39251 \begin_layout Standard
39252 \InsetSpace ~
39253 \InsetSpace ~
39254 \InsetSpace ~
39255 \InsetSpace ~
39256 [basic block 2]
39257 \end_layout
39258
39259 \begin_layout Standard
39260 else
39261 \end_layout
39262
39263 \begin_layout Standard
39264 \InsetSpace ~
39265 \InsetSpace ~
39266 \InsetSpace ~
39267 \InsetSpace ~
39268 [basic block 3]
39269 \end_layout
39270
39271 \begin_layout Standard
39272 [basic block 4]
39273 \newline
39274
39275 \end_layout
39276
39277 \begin_layout Standard
39278 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39279 \end_layout
39280
39281 \begin_layout Standard
39282 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39283 \end_layout
39284
39285 \begin_layout Standard
39286 c) domVect of [BB4] = BB1 ...
39287  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39288  was executed.
39289 \end_layout
39290
39291 \begin_layout Chapter
39292 Acknowledgments
39293 \end_layout
39294
39295 \begin_layout Standard
39296 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39297
39298 \end_inset
39299
39300
39301 \newline
39302
39303 \newline
39304
39305 \emph on
39306 Thanks to all the other volunteer developers who have helped with coding,
39307  testing, web-page creation, distribution sets, etc.
39308  You know who you are :-)
39309 \emph default
39310
39311 \newline
39312
39313 \newline
39314
39315 \emph on
39316 Also thanks to Sourceforge 
39317 \begin_inset LatexCommand \url{http://www.sf.net}
39318
39319 \end_inset
39320
39321  which has hosted the project since 1999 and donates significant download
39322  bandwidth and probably more than 
39323 \begin_inset ERT
39324 status collapsed
39325
39326 \begin_layout Standard
39327
39328 $10^{13}$
39329 \end_layout
39330
39331 \end_inset
39332
39333 CPU cycles per day.
39334 \newline
39335  
39336 \begin_inset Note Note
39337 status open
39338
39339 \begin_layout Standard
39340 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39341  minutes for (configure+make+regression test), and there is (i386, amd64,
39342  alpha, ppc64, (mingw32), sparc, macosx).
39343  
39344 \end_layout
39345
39346 \end_inset
39347
39348
39349 \end_layout
39350
39351 \begin_layout Standard
39352 This document was initially written by Sandeep Dutta
39353 \end_layout
39354
39355 \begin_layout Standard
39356 All product names mentioned herein may be trademarks
39357 \begin_inset LatexCommand \index{Trademarks}
39358
39359 \end_inset
39360
39361  of their respective companies.
39362  
39363 \end_layout
39364
39365 \begin_layout Section*
39366 Alphabetical index
39367 \end_layout
39368
39369 \begin_layout Standard
39370 To avoid confusion, the installation and building options for SDCC itself
39371  (chapter 2) are not part of the index.
39372 \end_layout
39373
39374 \begin_layout Standard
39375 \begin_inset LatexCommand \printindex{}
39376
39377 \end_inset
39378
39379
39380 \end_layout
39381
39382 \end_body
39383 \end_document