* doc/sdccman.lyx: documented numeric ranges, WEBDOC #1442369
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \pdfoptionpdfminorversion=3
6 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   pdfkeywords={8032 8051 ansi c compiler CPU DS390
11                embedded GPL HC08 manual mcs51 microcontroller PIC Z80},
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single 
27 \papersize letterpaper
28 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Comment
49
50 Please note: double dashed longoptions (e.g.
51  --version) are written this way: -
52 \begin_inset ERT
53 status Collapsed
54
55 \layout Standard
56
57 \backslash 
58 /
59 \end_inset 
60
61 -
62 \layout Comment
63
64 Two resp.
65  three consecutive dashes simply result in a long resp.
66  extra long dash.
67 \layout Comment
68
69 Architecture specific stuff (like memory models, code examples) should maybe
70  later go
71 \layout Comment
72
73 into seperate sections/chapters/appendices (it is hard to document PIC or
74  Z80 in 
75 \layout Comment
76
77 a 8051 centered document) - for now simply add.
78 \layout Title
79
80 SDCC Compiler User Guide
81 \layout Date
82
83
84 \size normal 
85 SDCC 2.5.6
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by Subversion
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargetted for other microprocessors, support for Microchip
146  PIC, Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargettable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
218 \begin_inset Text
219
220 \layout Standard
221
222 type
223 \end_inset 
224 </cell>
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
226 \begin_inset Text
227
228 \layout Standard
229
230 width
231 \end_inset 
232 </cell>
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
234 \begin_inset Text
235
236 \layout Standard
237
238 default
239 \end_inset 
240 </cell>
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
242 \begin_inset Text
243
244 \layout Standard
245
246 signed range
247 \end_inset 
248 </cell>
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
250 \begin_inset Text
251
252 \layout Standard
253
254 unsigned range
255 \end_inset 
256 </cell>
257 </row>
258 <row topline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 bool
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 1 bit
273 \end_inset 
274 </cell>
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
276 \begin_inset Text
277
278 \layout Standard
279
280 unsigned
281 \end_inset 
282 </cell>
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_inset Text
285
286 \layout Standard
287
288 -
289 \end_inset 
290 </cell>
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_inset Text
293
294 \layout Standard
295
296 0, 1
297 \end_inset 
298 </cell>
299 </row>
300 <row topline="true">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 char
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 8 bits, 1 byte
315 \end_inset 
316 </cell>
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_inset Text
319
320 \layout Standard
321
322 signed
323 \end_inset 
324 </cell>
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \layout Standard
329
330 -128, +127
331 \end_inset 
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
334 \begin_inset Text
335
336 \layout Standard
337
338 0, +255
339 \end_inset 
340 </cell>
341 </row>
342 <row topline="true">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 short
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 16 bits, 2 bytes
357 \end_inset 
358 </cell>
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
360 \begin_inset Text
361
362 \layout Standard
363
364 signed
365 \end_inset 
366 </cell>
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_inset Text
369
370 \layout Standard
371
372 -32.768, +32.767
373 \end_inset 
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
376 \begin_inset Text
377
378 \layout Standard
379
380 0, +65.535
381 \end_inset 
382 </cell>
383 </row>
384 <row topline="true">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 int
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 16 bits, 2 bytes
399 \end_inset 
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
402 \begin_inset Text
403
404 \layout Standard
405
406 signed
407 \end_inset 
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \layout Standard
413
414 -32.768, +32.767
415 \end_inset 
416 </cell>
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
418 \begin_inset Text
419
420 \layout Standard
421
422 0, +65.535
423 \end_inset 
424 </cell>
425 </row>
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 long
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 32 bits, 4 bytes
441 \end_inset 
442 </cell>
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_inset Text
445
446 \layout Standard
447
448 signed
449 \end_inset 
450 </cell>
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_inset Text
453
454 \layout Standard
455
456 -2.147.483.648, +2.147.483.647
457 \end_inset 
458 </cell>
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
460 \begin_inset Text
461
462 \layout Standard
463
464 0, +4.294.967.296
465 \end_inset 
466 </cell>
467 </row>
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 float
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 4 bytes IEEE
483 \end_inset 
484 </cell>
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \layout Standard
489
490 signed
491 \end_inset 
492 </cell>
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
494 \begin_inset Text
495
496 \layout Standard
497
498 \end_inset 
499 </cell>
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
501 \begin_inset Text
502
503 \layout Standard
504
505 \end_inset 
506 </cell>
507 </row>
508 <row topline="true" bottomline="true">
509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_inset Text
511
512 \layout Standard
513
514 pointer
515 \end_inset 
516 </cell>
517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
518 \begin_inset Text
519
520 \layout Standard
521
522 1, 2, 3 or 4 bytes
523 \end_inset 
524 </cell>
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_inset Text
527
528 \layout Standard
529
530 generic
531 \end_inset 
532 </cell>
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \layout Standard
537
538 \end_inset 
539 </cell>
540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
541 \begin_inset Text
542
543 \layout Standard
544
545 \end_inset 
546 </cell>
547 </row>
548 </lyxtabular>
549
550 \end_inset 
551
552
553 \newline 
554 The compiler also allows 
555 \emph on 
556 inline assembler code
557 \emph default 
558  to be embedded anywhere in a function.
559  In addition, routines developed in assembly can also be called.
560 \newline 
561
562 \newline 
563 SDCC also provides an option (-
564 \begin_inset ERT
565 status Collapsed
566
567 \layout Standard
568
569 \backslash 
570 /
571 \end_inset 
572
573 -cyclomatic) to report the relative complexity of a function.
574  These functions can then be further optimized, or hand coded in assembly
575  if needed.
576  
577 \newline 
578
579 \newline 
580 SDCC also comes with a companion source level debugger SDCDB, the debugger
581  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
582  SDCDB and ucSim are currently not available on Win32 platforms.
583  
584 \newline 
585
586 \newline 
587 The latest version can be downloaded from 
588 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
589
590 \end_inset 
591
592 .
593
594 \series bold 
595  
596 \series default 
597 \emph on 
598 Please note: the compiler will probably always be some steps ahead of this
599  documentation
600 \series bold 
601 \emph default 
602
603 \begin_inset LatexCommand \index{Status of documentation}
604
605 \end_inset 
606
607
608 \begin_inset Foot
609 collapsed false
610
611 \layout Standard
612
613 Obviously this has pros and cons
614 \end_inset 
615
616 .
617 \layout Section
618
619 Open Source
620 \layout Standard
621
622 All packages used in this compiler system are 
623 \emph on 
624 open source
625 \emph default 
626  and 
627 \emph on 
628 freeware
629 \emph default 
630 ; source code for all the sub-packages (pre-processor, assemblers, linkers
631  etc) is distributed with the package.
632  This documentation is maintained using a freeware word processor (LyX).
633 \newline 
634 This program is free software; you can redistribute it and/or modify it
635  under the terms of the GNU General Public License
636 \begin_inset LatexCommand \index{GNU General Public License, GPL}
637
638 \end_inset 
639
640  as published by the Free Software Foundation; either version 2, or (at
641  your option) any later version.
642  This program is distributed in the hope that it will be useful, but WITHOUT
643  ANY WARRANTY; without even the implied warranty
644 \begin_inset LatexCommand \index{warranty}
645
646 \end_inset 
647
648  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
649  See the GNU General Public License for more details.
650  You should have received a copy of the GNU General Public License along
651  with this program; if not, write to the Free Software Foundation, 59 Temple
652  Place - Suite 330, Boston, MA 02111-1307, USA.
653  In other words, you are welcome to use, share and improve this program.
654  You are forbidden to forbid anyone else to use, share and improve what
655  you give them.
656  Help stamp out software-hoarding! 
657 \layout Section
658
659 Typographic conventions
660 \begin_inset LatexCommand \index{Typographic conventions}
661
662 \end_inset 
663
664
665 \layout Standard
666
667 Throughout this manual, we will use the following convention.
668  Commands you have to type in are printed in 
669 \family sans 
670 \series bold 
671 "sans serif"
672 \series default 
673 .
674
675 \family default 
676  Code samples are printed in 
677 \family typewriter 
678 typewriter font.
679
680 \family default 
681  Interesting items and new terms are printed in 
682 \emph on 
683 italic.
684 \layout Section
685
686 Compatibility with previous versions
687 \begin_inset LatexCommand \index{Compatibility with previous versions}
688
689 \end_inset 
690
691
692 \layout Standard
693
694 This version has numerous bug fixes compared with the previous version.
695  But we also introduced some incompatibilities with older versions.
696  Not just for the fun of it, but to make the compiler more stable, efficient
697  and ANSI compliant
698 \begin_inset LatexCommand \index{ANSI-compliance}
699
700 \end_inset 
701
702  (see section 
703 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
704
705 \end_inset 
706
707  for ANSI-Compliance).
708  
709 \newline 
710
711 \layout Itemize
712
713 short is now equivalent to int (16 bits), it used to be equivalent to char
714  (8 bits) which is not ANSI compliant.
715 \layout Itemize
716
717 the default directory for gcc-builds where include, library and documentation
718  files are stored is now in /usr/local/share.
719 \layout Itemize
720
721 char type parameters to vararg functions are casted to int unless explicitly
722  casted, e.g.: 
723 \newline 
724
725 \family typewriter 
726 \SpecialChar ~
727 \SpecialChar ~
728 char a=3;
729 \newline 
730 \SpecialChar ~
731 \SpecialChar ~
732 printf ("%d %c
733 \backslash 
734 n", a, (char)a);
735 \family default 
736
737 \newline 
738  will push a as an int and as a char resp.
739 \layout Itemize
740
741 option -
742 \begin_inset ERT
743 status Collapsed
744
745 \layout Standard
746
747 \backslash 
748 /
749 \end_inset 
750
751 -regextend has been removed.
752 \layout Itemize
753
754 option -
755 \begin_inset ERT
756 status Collapsed
757
758 \layout Standard
759
760 \backslash 
761 /
762 \end_inset 
763
764 -noregparms has been removed.
765 \layout Itemize
766
767 option -
768 \begin_inset ERT
769 status Collapsed
770
771 \layout Standard
772
773 \backslash 
774 /
775 \end_inset 
776
777 -stack-after-data has been removed.
778 \layout Itemize
779
780 bit
781 \begin_inset LatexCommand \index{bit}
782
783 \end_inset 
784
785  and sbit
786 \begin_inset LatexCommand \index{sbit}
787
788 \end_inset 
789
790
791 \begin_inset LatexCommand \index{\_\_sbit}
792
793 \end_inset 
794
795  types now consistently behave like the C99 _Bool type with respect to type
796  conversion
797 \begin_inset LatexCommand \index{type conversion}
798
799 \end_inset 
800
801
802 \begin_inset LatexCommand \index{type promotion}
803
804 \end_inset 
805
806 .
807  The most common incompatibility resulting from this change is related to
808  bit toggling
809 \begin_inset LatexCommand \index{Bit toggling}
810
811 \end_inset 
812
813  idioms, e.g.:
814 \newline 
815
816 \family typewriter 
817 \SpecialChar ~
818 \SpecialChar ~
819 bit b;
820 \newline 
821 \SpecialChar ~
822 \SpecialChar ~
823 b = ~b; /* equivalent to b=1 instead of toggling b */
824 \newline 
825 \SpecialChar ~
826 \SpecialChar ~
827 b = !b; /* toggles b */
828 \newline 
829
830 \family default 
831 In previous versions, both forms would have toggled the bit.
832 \layout Standard
833
834
835 \emph on 
836 <pending: more incompatibilities?>
837 \layout Section
838
839 System Requirements
840 \layout Standard
841
842 What do you need before you start installation of SDCC? A computer, and
843  a desire to compute.
844  The preferred method of installation is to compile SDCC from source using
845  GNU gcc and make.
846  For Windows some pre-compiled binary distributions are available for your
847  convenience.
848  You should have some experience with command line tools and compiler use.
849 \layout Section
850
851 Other Resources
852 \layout Standard
853
854 The SDCC home page at 
855 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
856
857 \end_inset 
858
859  is a great place to find distribution sets.
860  You can also find links to the user mailing lists that offer help or discuss
861  SDCC with other SDCC users.
862  Web links to other SDCC related sites can also be found here.
863  This document can be found in the DOC directory of the source package as
864  a text or HTML file.
865  A pdf version of this document is available at 
866 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
867
868 \end_inset 
869
870 .
871  Some of the other tools (simulator and assembler) included with SDCC contain
872  their own documentation and can be found in the source distribution.
873  If you want the latest unreleased software, the complete source package
874  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
875 /trunk/sdcc.
876 \layout Section
877
878 Wishes for the future
879 \layout Standard
880
881 There are (and always will be) some things that could be done.
882  Here are some I can think of:
883 \newline 
884
885 \layout Standard
886
887
888 \family typewriter 
889 char KernelFunction3(char p) at 0x340;
890 \newline 
891
892 \layout Standard
893
894
895 \family typewriter 
896 better code banking
897 \begin_inset LatexCommand \index{code banking (limited support)}
898
899 \end_inset 
900
901  support for mcs51
902 \newline 
903
904 \newline 
905
906 \family default 
907 If you can think of some more, please see the section 
908 \begin_inset LatexCommand \ref{sub:Requesting-Features}
909
910 \end_inset 
911
912  about filing feature requests
913 \begin_inset LatexCommand \index{Requesting features}
914
915 \end_inset 
916
917
918 \begin_inset LatexCommand \index{Feature request}
919
920 \end_inset 
921
922 .
923 \newline 
924
925 \layout Chapter
926
927 Installing SDCC
928 \begin_inset LatexCommand \index{Installation}
929
930 \end_inset 
931
932
933 \layout Standard
934
935 For most users it is sufficient to skip to either section 
936 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
937
938 \end_inset 
939
940  or section 
941 \begin_inset LatexCommand \ref{sub:Windows-Install}
942
943 \end_inset 
944
945 .
946  More detailled instructions follow below.
947 \layout Section
948
949 Configure Options
950 \begin_inset LatexCommand \index{Options SDCC configuration}
951
952 \end_inset 
953
954
955 \layout Standard
956
957 The install paths, search paths and other options are defined when running
958  'configure'.
959  The defaults can be overridden by:
960 \layout List
961 \labelwidthstring 00.00.0000
962
963 -
964 \begin_inset ERT
965 status Collapsed
966
967 \layout Standard
968
969 \backslash 
970 /
971 \end_inset 
972
973 -prefix see table below
974 \layout List
975 \labelwidthstring 00.00.0000
976
977 -
978 \begin_inset ERT
979 status Collapsed
980
981 \layout Standard
982
983 \backslash 
984 /
985 \end_inset 
986
987 -exec_prefix see table below
988 \layout List
989 \labelwidthstring 00.00.0000
990
991 -
992 \begin_inset ERT
993 status Collapsed
994
995 \layout Standard
996
997 \backslash 
998 /
999 \end_inset 
1000
1001 -bindir see table below
1002 \layout List
1003 \labelwidthstring 00.00.0000
1004
1005 -
1006 \begin_inset ERT
1007 status Collapsed
1008
1009 \layout Standard
1010
1011 \backslash 
1012 /
1013 \end_inset 
1014
1015 -datadir see table below
1016 \layout List
1017 \labelwidthstring 00.00.0000
1018
1019 docdir environment variable, see table below
1020 \layout List
1021 \labelwidthstring 00.00.0000
1022
1023 include_dir_suffix environment variable, see table below
1024 \layout List
1025 \labelwidthstring 00.00.0000
1026
1027 lib_dir_suffix environment variable, see table below
1028 \layout List
1029 \labelwidthstring 00.00.0000
1030
1031 sdccconf_h_dir_separator environment variable, either / or 
1032 \backslash 
1033
1034 \backslash 
1035  makes sense here.
1036  This character will only be used in sdccconf.h; don't forget it's a C-header,
1037  therefore a double-backslash is needed there.
1038 \layout List
1039 \labelwidthstring 00.00.0000
1040
1041 -
1042 \begin_inset ERT
1043 status Collapsed
1044
1045 \layout Standard
1046
1047 \backslash 
1048 /
1049 \end_inset 
1050
1051 -disable-mcs51-port Excludes the Intel mcs51 port
1052 \layout List
1053 \labelwidthstring 00.00.0000
1054
1055 -
1056 \begin_inset ERT
1057 status Collapsed
1058
1059 \layout Standard
1060
1061 \backslash 
1062 /
1063 \end_inset 
1064
1065 -disable-gbz80-port Excludes the Gameboy gbz80 port
1066 \layout List
1067 \labelwidthstring 00.00.0000
1068
1069 -
1070 \begin_inset ERT
1071 status Collapsed
1072
1073 \layout Standard
1074
1075 \backslash 
1076 /
1077 \end_inset 
1078
1079 -disable-z80-port Excludes the z80 port
1080 \layout List
1081 \labelwidthstring 00.00.0000
1082
1083 -
1084 \begin_inset ERT
1085 status Collapsed
1086
1087 \layout Standard
1088
1089 \backslash 
1090 /
1091 \end_inset 
1092
1093 -disable-avr-port Excludes the AVR port
1094 \layout List
1095 \labelwidthstring 00.00.0000
1096
1097 -
1098 \begin_inset ERT
1099 status Collapsed
1100
1101 \layout Standard
1102
1103 \backslash 
1104 /
1105 \end_inset 
1106
1107 -disable-ds390-port Excludes the DS390 port
1108 \layout List
1109 \labelwidthstring 00.00.0000
1110
1111 -
1112 \begin_inset ERT
1113 status Collapsed
1114
1115 \layout Standard
1116
1117 \backslash 
1118 /
1119 \end_inset 
1120
1121 -disable-hc08-port Excludes the HC08 port
1122 \layout List
1123 \labelwidthstring 00.00.0000
1124
1125 -
1126 \begin_inset ERT
1127 status Collapsed
1128
1129 \layout Standard
1130
1131 \backslash 
1132 /
1133 \end_inset 
1134
1135 -disable-pic-port Excludes the PIC port
1136 \layout List
1137 \labelwidthstring 00.00.0000
1138
1139 -
1140 \begin_inset ERT
1141 status Collapsed
1142
1143 \layout Standard
1144
1145 \backslash 
1146 /
1147 \end_inset 
1148
1149 -disable-xa51-port Excludes the XA51 port
1150 \layout List
1151 \labelwidthstring 00.00.0000
1152
1153 -
1154 \begin_inset ERT
1155 status Collapsed
1156
1157 \layout Standard
1158
1159 \backslash 
1160 /
1161 \end_inset 
1162
1163 -disable-ucsim Disables configuring and building of ucsim
1164 \layout List
1165 \labelwidthstring 00.00.0000
1166
1167 -
1168 \begin_inset ERT
1169 status Collapsed
1170
1171 \layout Standard
1172
1173 \backslash 
1174 /
1175 \end_inset 
1176
1177 -disable-device-lib Disables automatically building device libraries
1178 \layout List
1179 \labelwidthstring 00.00.0000
1180
1181 -
1182 \begin_inset ERT
1183 status Collapsed
1184
1185 \layout Standard
1186
1187 \backslash 
1188 /
1189 \end_inset 
1190
1191 -disable-packihx Disables building packihx
1192 \layout List
1193 \labelwidthstring 00.00.0000
1194
1195 -
1196 \begin_inset ERT
1197 status Collapsed
1198
1199 \layout Standard
1200
1201 \backslash 
1202 /
1203 \end_inset 
1204
1205 -enable-doc Build pdf, html and txt files from the lyx sources
1206 \layout List
1207 \labelwidthstring 00.00.0000
1208
1209 -
1210 \begin_inset ERT
1211 status Collapsed
1212
1213 \layout Standard
1214
1215 \backslash 
1216 /
1217 \end_inset 
1218
1219 -enable-libgc Use the Bohem memory allocator.
1220  Lower runtime footprint.
1221 \layout Standard
1222
1223 Furthermore the environment variables CC, CFLAGS, ...
1224  the tools and their arguments can be influenced.
1225  Please see `configure -
1226 \begin_inset ERT
1227 status Collapsed
1228
1229 \layout Standard
1230
1231 \backslash 
1232 /
1233 \end_inset 
1234
1235 -help` and the man/info pages of `configure` for details.
1236 \newline 
1237
1238 \newline 
1239 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1240  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1241 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1242  At the moment it's not possible to change the default settings (it was
1243  simply never required).
1244 \newline 
1245
1246 \newline 
1247 These configure options are compiled into the binaries, and can only be
1248  changed by rerunning 'configure' and recompiling SDCC.
1249  The configure options are written in 
1250 \emph on 
1251 italics
1252 \emph default 
1253  to distinguish them from run time environment variables (see section search
1254  paths).
1255 \newline 
1256
1257 \newline 
1258 The settings for 
1259 \begin_inset Quotes sld
1260 \end_inset 
1261
1262 Win32 builds
1263 \begin_inset Quotes srd
1264 \end_inset 
1265
1266  are used by the SDCC team to build the official Win32 binaries.
1267  The SDCC team uses Mingw32 to build the official Windows binaries, because
1268  it's
1269 \layout Enumerate
1270
1271 open source, 
1272 \layout Enumerate
1273
1274 a gcc compiler and last but not least
1275 \layout Enumerate
1276
1277 the binaries can be built by cross compiling on Sourceforge's compile farm.
1278 \layout Standard
1279
1280 See the examples, how to pass the Win32 settings to 'configure'.
1281  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1282  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1283  for Win32.
1284 \newline 
1285
1286 \newline 
1287 These defaults are:
1288 \newline 
1289
1290 \layout Standard
1291 \align center 
1292
1293 \begin_inset  Tabular
1294 <lyxtabular version="3" rows="8" columns="3">
1295 <features>
1296 <column alignment="block" valignment="top" leftline="true" width="0in">
1297 <column alignment="block" valignment="top" leftline="true" width="0in">
1298 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1299 <row topline="true" bottomline="true">
1300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1301 \begin_inset Text
1302
1303 \layout Standard
1304
1305 Variable
1306 \end_inset 
1307 </cell>
1308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1309 \begin_inset Text
1310
1311 \layout Standard
1312
1313 default
1314 \end_inset 
1315 </cell>
1316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1317 \begin_inset Text
1318
1319 \layout Standard
1320
1321 Win32 builds
1322 \end_inset 
1323 </cell>
1324 </row>
1325 <row topline="true">
1326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1327 \begin_inset Text
1328
1329 \layout Standard
1330
1331
1332 \emph on 
1333 PREFIX
1334 \end_inset 
1335 </cell>
1336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1337 \begin_inset Text
1338
1339 \layout Standard
1340
1341 /usr/local
1342 \end_inset 
1343 </cell>
1344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1345 \begin_inset Text
1346
1347 \layout Standard
1348
1349
1350 \backslash 
1351 sdcc
1352 \end_inset 
1353 </cell>
1354 </row>
1355 <row topline="true">
1356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1357 \begin_inset Text
1358
1359 \layout Standard
1360
1361
1362 \emph on 
1363 EXEC_PREFIX
1364 \end_inset 
1365 </cell>
1366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1367 \begin_inset Text
1368
1369 \layout Standard
1370
1371
1372 \emph on 
1373 $PREFIX
1374 \end_inset 
1375 </cell>
1376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1377 \begin_inset Text
1378
1379 \layout Standard
1380
1381
1382 \emph on 
1383 $PREFIX
1384 \end_inset 
1385 </cell>
1386 </row>
1387 <row topline="true">
1388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1389 \begin_inset Text
1390
1391 \layout Standard
1392
1393
1394 \emph on 
1395 BINDIR
1396 \end_inset 
1397 </cell>
1398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1399 \begin_inset Text
1400
1401 \layout Standard
1402
1403
1404 \emph on 
1405 $EXECPREFIX
1406 \emph default 
1407 /bin
1408 \end_inset 
1409 </cell>
1410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1411 \begin_inset Text
1412
1413 \layout Standard
1414
1415
1416 \emph on 
1417 $EXECPREFIX
1418 \emph default 
1419
1420 \backslash 
1421 bin
1422 \end_inset 
1423 </cell>
1424 </row>
1425 <row topline="true">
1426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1427 \begin_inset Text
1428
1429 \layout Standard
1430
1431
1432 \emph on 
1433 DATADIR
1434 \end_inset 
1435 </cell>
1436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1437 \begin_inset Text
1438
1439 \layout Standard
1440
1441
1442 \emph on 
1443 $PREFIX
1444 \emph default 
1445 /share
1446 \end_inset 
1447 </cell>
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452
1453
1454 \emph on 
1455 $PREFIX
1456 \end_inset 
1457 </cell>
1458 </row>
1459 <row topline="true">
1460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1461 \begin_inset Text
1462
1463 \layout Standard
1464
1465
1466 \emph on 
1467 DOCDIR
1468 \end_inset 
1469 </cell>
1470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1471 \begin_inset Text
1472
1473 \layout Standard
1474
1475
1476 \emph on 
1477 $DATADIR
1478 \emph default 
1479 /sdcc/doc
1480 \end_inset 
1481 </cell>
1482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1483 \begin_inset Text
1484
1485 \layout Standard
1486
1487
1488 \emph on 
1489 $DATADIR
1490 \emph default 
1491
1492 \backslash 
1493 doc
1494 \end_inset 
1495 </cell>
1496 </row>
1497 <row topline="true">
1498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1499 \begin_inset Text
1500
1501 \layout Standard
1502
1503
1504 \emph on 
1505 INCLUDE_DIR_SUFFIX
1506 \end_inset 
1507 </cell>
1508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1509 \begin_inset Text
1510
1511 \layout Standard
1512
1513 sdcc/include
1514 \end_inset 
1515 </cell>
1516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1517 \begin_inset Text
1518
1519 \layout Standard
1520
1521 include
1522 \end_inset 
1523 </cell>
1524 </row>
1525 <row topline="true" bottomline="true">
1526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1527 \begin_inset Text
1528
1529 \layout Standard
1530
1531
1532 \emph on 
1533 LIB_DIR_SUFFIX
1534 \end_inset 
1535 </cell>
1536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1537 \begin_inset Text
1538
1539 \layout Standard
1540
1541 sdcc/lib
1542 \end_inset 
1543 </cell>
1544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1545 \begin_inset Text
1546
1547 \layout Standard
1548
1549 lib
1550 \end_inset 
1551 </cell>
1552 </row>
1553 </lyxtabular>
1554
1555 \end_inset 
1556
1557
1558 \newline 
1559
1560 \layout Standard
1561 \noindent 
1562 'configure' also computes relative paths.
1563  This is needed for full relocatability of a binary package and to complete
1564  search paths (see section search paths below):
1565 \newline 
1566  
1567 \layout Standard
1568 \align center 
1569
1570 \begin_inset  Tabular
1571 <lyxtabular version="3" rows="4" columns="3">
1572 <features>
1573 <column alignment="block" valignment="top" leftline="true" width="0in">
1574 <column alignment="block" valignment="top" leftline="true" width="0in">
1575 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1576 <row topline="true" bottomline="true">
1577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1578 \begin_inset Text
1579
1580 \layout Standard
1581
1582 Variable (computed)
1583 \end_inset 
1584 </cell>
1585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1586 \begin_inset Text
1587
1588 \layout Standard
1589
1590 default
1591 \end_inset 
1592 </cell>
1593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1594 \begin_inset Text
1595
1596 \layout Standard
1597
1598 Win32 builds
1599 \end_inset 
1600 </cell>
1601 </row>
1602 <row topline="true" bottomline="true">
1603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1604 \begin_inset Text
1605
1606 \layout Standard
1607
1608
1609 \emph on 
1610 BIN2DATA_DIR
1611 \end_inset 
1612 </cell>
1613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1614 \begin_inset Text
1615
1616 \layout Standard
1617
1618 ../share
1619 \end_inset 
1620 </cell>
1621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1622 \begin_inset Text
1623
1624 \layout Standard
1625
1626 ..
1627 \end_inset 
1628 </cell>
1629 </row>
1630 <row bottomline="true">
1631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1632 \begin_inset Text
1633
1634 \layout Standard
1635
1636
1637 \emph on 
1638 PREFIX2BIN_DIR
1639 \end_inset 
1640 </cell>
1641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 \begin_inset Text
1643
1644 \layout Standard
1645
1646 bin
1647 \end_inset 
1648 </cell>
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1650 \begin_inset Text
1651
1652 \layout Standard
1653
1654 bin
1655 \end_inset 
1656 </cell>
1657 </row>
1658 <row bottomline="true">
1659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1660 \begin_inset Text
1661
1662 \layout Standard
1663
1664
1665 \emph on 
1666 PREFIX2DATA_DIR
1667 \end_inset 
1668 </cell>
1669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1670 \begin_inset Text
1671
1672 \layout Standard
1673
1674 share/sdcc
1675 \end_inset 
1676 </cell>
1677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1678 \begin_inset Text
1679
1680 \layout Standard
1681
1682 \end_inset 
1683 </cell>
1684 </row>
1685 </lyxtabular>
1686
1687 \end_inset 
1688
1689
1690 \newline 
1691
1692 \layout Standard
1693 \noindent 
1694 Examples:
1695 \layout LyX-Code
1696
1697 ./configure
1698 \newline 
1699 ./configure -
1700 \begin_inset ERT
1701 status Collapsed
1702
1703 \layout Standard
1704
1705 \backslash 
1706 /
1707 \end_inset 
1708
1709 -prefix=
1710 \begin_inset Quotes srd
1711 \end_inset 
1712
1713 /usr/bin
1714 \begin_inset Quotes srd
1715 \end_inset 
1716
1717  -
1718 \begin_inset ERT
1719 status Collapsed
1720
1721 \layout Standard
1722
1723 \backslash 
1724 /
1725 \end_inset 
1726
1727 -datadir=
1728 \begin_inset Quotes srd
1729 \end_inset 
1730
1731 /usr/share
1732 \begin_inset Quotes srd
1733 \end_inset 
1734
1735
1736 \newline 
1737 ./configure -
1738 \begin_inset ERT
1739 status Collapsed
1740
1741 \layout Standard
1742
1743 \backslash 
1744 /
1745 \end_inset 
1746
1747 -disable-avr-port -
1748 \begin_inset ERT
1749 status Collapsed
1750
1751 \layout Standard
1752
1753 \backslash 
1754 /
1755 \end_inset 
1756
1757 -disable-xa51-port
1758 \layout Standard
1759
1760 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1761 32'):
1762 \layout LyX-Code
1763
1764 ./configure 
1765 \backslash 
1766
1767 \newline 
1768 CC=
1769 \begin_inset Quotes srd
1770 \end_inset 
1771
1772 i586-mingw32msvc-gcc
1773 \begin_inset Quotes srd
1774 \end_inset 
1775
1776  CXX=
1777 \begin_inset Quotes srd
1778 \end_inset 
1779
1780 i586-mingw32msvc-g++
1781 \begin_inset Quotes srd
1782 \end_inset 
1783
1784  
1785 \backslash 
1786  
1787 \newline 
1788 RANLIB=
1789 \begin_inset Quotes srd
1790 \end_inset 
1791
1792 i586-mingw32msvc-ranlib
1793 \begin_inset Quotes srd
1794 \end_inset 
1795
1796  
1797 \backslash 
1798
1799 \newline 
1800 STRIP=
1801 \begin_inset Quotes srd
1802 \end_inset 
1803
1804 i586-mingw32msvc-strip
1805 \begin_inset Quotes srd
1806 \end_inset 
1807
1808  
1809 \backslash 
1810
1811 \newline 
1812 -
1813 \begin_inset ERT
1814 status Collapsed
1815
1816 \layout Standard
1817
1818 \backslash 
1819 /
1820 \end_inset 
1821
1822 -prefix=
1823 \begin_inset Quotes srd
1824 \end_inset 
1825
1826 /sdcc
1827 \begin_inset Quotes srd
1828 \end_inset 
1829
1830  
1831 \backslash 
1832
1833 \newline 
1834 -
1835 \begin_inset ERT
1836 status Collapsed
1837
1838 \layout Standard
1839
1840 \backslash 
1841 /
1842 \end_inset 
1843
1844 -datadir=
1845 \begin_inset Quotes srd
1846 \end_inset 
1847
1848 /sdcc
1849 \begin_inset Quotes srd
1850 \end_inset 
1851
1852  
1853 \backslash 
1854
1855 \newline 
1856 docdir=
1857 \begin_inset Quotes srd
1858 \end_inset 
1859
1860 /sdcc/doc
1861 \begin_inset Quotes srd
1862 \end_inset 
1863
1864  
1865 \backslash 
1866
1867 \newline 
1868 include_dir_suffix=
1869 \begin_inset Quotes srd
1870 \end_inset 
1871
1872 include
1873 \begin_inset Quotes srd
1874 \end_inset 
1875
1876  
1877 \backslash 
1878
1879 \newline 
1880 lib_dir_suffix=
1881 \begin_inset Quotes srd
1882 \end_inset 
1883
1884 lib
1885 \begin_inset Quotes srd
1886 \end_inset 
1887
1888  
1889 \backslash 
1890
1891 \newline 
1892 sdccconf_h_dir_separator=
1893 \begin_inset Quotes srd
1894 \end_inset 
1895
1896
1897 \backslash 
1898
1899 \backslash 
1900
1901 \backslash 
1902
1903 \backslash 
1904
1905 \begin_inset Quotes srd
1906 \end_inset 
1907
1908  
1909 \backslash 
1910
1911 \newline 
1912 -
1913 \begin_inset ERT
1914 status Collapsed
1915
1916 \layout Standard
1917
1918 \backslash 
1919 /
1920 \end_inset 
1921
1922 -disable-device-lib
1923 \backslash 
1924
1925 \newline 
1926 -
1927 \begin_inset ERT
1928 status Collapsed
1929
1930 \layout Standard
1931
1932 \backslash 
1933 /
1934 \end_inset 
1935
1936 -disable-ucsim
1937 \backslash 
1938
1939 \newline 
1940 -
1941 \begin_inset ERT
1942 status Collapsed
1943
1944 \layout Standard
1945
1946 \backslash 
1947 /
1948 \end_inset 
1949
1950 -host=i586-mingw32msvc -
1951 \begin_inset ERT
1952 status Collapsed
1953
1954 \layout Standard
1955
1956 \backslash 
1957 /
1958 \end_inset 
1959
1960 -build=unknown-unknown-linux-gnu
1961 \layout Standard
1962
1963 To 
1964 \begin_inset Quotes sld
1965 \end_inset 
1966
1967 cross
1968 \begin_inset Quotes srd
1969 \end_inset 
1970
1971 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1972 ):
1973 \layout LyX-Code
1974
1975 ./configure -C 
1976 \backslash 
1977
1978 \newline 
1979 CFLAGS=
1980 \begin_inset Quotes srd
1981 \end_inset 
1982
1983 -mno-cygwin -O2
1984 \begin_inset Quotes srd
1985 \end_inset 
1986
1987  
1988 \backslash 
1989
1990 \newline 
1991 LDFLAGS=
1992 \begin_inset Quotes srd
1993 \end_inset 
1994
1995 -mno-cygwin
1996 \begin_inset Quotes srd
1997 \end_inset 
1998
1999  
2000 \backslash 
2001
2002 \newline 
2003 -
2004 \begin_inset ERT
2005 status Collapsed
2006
2007 \layout Standard
2008
2009 \backslash 
2010 /
2011 \end_inset 
2012
2013 -prefix=
2014 \begin_inset Quotes srd
2015 \end_inset 
2016
2017 /sdcc
2018 \begin_inset Quotes srd
2019 \end_inset 
2020
2021  
2022 \backslash 
2023
2024 \newline 
2025 -
2026 \begin_inset ERT
2027 status Collapsed
2028
2029 \layout Standard
2030
2031 \backslash 
2032 /
2033 \end_inset 
2034
2035 -datadir=
2036 \begin_inset Quotes srd
2037 \end_inset 
2038
2039 /sdcc
2040 \begin_inset Quotes srd
2041 \end_inset 
2042
2043  
2044 \backslash 
2045
2046 \newline 
2047 docdir=
2048 \begin_inset Quotes srd
2049 \end_inset 
2050
2051 /sdcc/doc
2052 \begin_inset Quotes srd
2053 \end_inset 
2054
2055  
2056 \backslash 
2057  
2058 \newline 
2059 include_dir_suffix=
2060 \begin_inset Quotes srd
2061 \end_inset 
2062
2063 include
2064 \begin_inset Quotes srd
2065 \end_inset 
2066
2067  
2068 \backslash 
2069
2070 \newline 
2071 lib_dir_suffix=
2072 \begin_inset Quotes srd
2073 \end_inset 
2074
2075 lib
2076 \begin_inset Quotes srd
2077 \end_inset 
2078
2079  
2080 \backslash 
2081
2082 \newline 
2083 sdccconf_h_dir_separator=
2084 \begin_inset Quotes srd
2085 \end_inset 
2086
2087
2088 \backslash 
2089
2090 \backslash 
2091
2092 \backslash 
2093
2094 \backslash 
2095
2096 \begin_inset Quotes srd
2097 \end_inset 
2098
2099  
2100 \backslash 
2101
2102 \newline 
2103 -
2104 \begin_inset ERT
2105 status Collapsed
2106
2107 \layout Standard
2108
2109 \backslash 
2110 /
2111 \end_inset 
2112
2113 -disable-ucsim
2114 \layout Standard
2115
2116 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2117  The option '-
2118 \begin_inset ERT
2119 status Collapsed
2120
2121 \layout Standard
2122
2123 \backslash 
2124 /
2125 \end_inset 
2126
2127 -C' turns on caching, which gives a little bit extra speed.
2128  However if options are changed, it can be necessary to delete the config.cache
2129  file.
2130 \layout Section
2131
2132 Install paths
2133 \begin_inset LatexCommand \label{sub:Install-paths}
2134
2135 \end_inset 
2136
2137
2138 \begin_inset LatexCommand \index{Install paths}
2139
2140 \end_inset 
2141
2142
2143 \layout Standard
2144 \added_space_top medskip \align center 
2145
2146 \begin_inset  Tabular
2147 <lyxtabular version="3" rows="5" columns="4">
2148 <features>
2149 <column alignment="center" valignment="top" leftline="true" width="0">
2150 <column alignment="center" valignment="top" leftline="true" width="0">
2151 <column alignment="center" valignment="top" leftline="true" width="0">
2152 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
2153 <row topline="true" bottomline="true">
2154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2155 \begin_inset Text
2156
2157 \layout Standard
2158
2159
2160 \series bold 
2161 Description
2162 \end_inset 
2163 </cell>
2164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2165 \begin_inset Text
2166
2167 \layout Standard
2168
2169
2170 \series bold 
2171 Path
2172 \end_inset 
2173 </cell>
2174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2175 \begin_inset Text
2176
2177 \layout Standard
2178
2179
2180 \series bold 
2181 Default
2182 \end_inset 
2183 </cell>
2184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2185 \begin_inset Text
2186
2187 \layout Standard
2188
2189
2190 \series bold 
2191 Win32 builds
2192 \end_inset 
2193 </cell>
2194 </row>
2195 <row topline="true">
2196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2197 \begin_inset Text
2198
2199 \layout Standard
2200
2201 Binary files*
2202 \end_inset 
2203 </cell>
2204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2205 \begin_inset Text
2206
2207 \layout Standard
2208
2209
2210 \emph on 
2211 $EXEC_PREFIX
2212 \end_inset 
2213 </cell>
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2215 \begin_inset Text
2216
2217 \layout Standard
2218
2219 /usr/local/bin
2220 \end_inset 
2221 </cell>
2222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2223 \begin_inset Text
2224
2225 \layout Standard
2226
2227
2228 \backslash 
2229 sdcc
2230 \backslash 
2231 bin
2232 \end_inset 
2233 </cell>
2234 </row>
2235 <row topline="true">
2236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2237 \begin_inset Text
2238
2239 \layout Standard
2240
2241 Include files
2242 \end_inset 
2243 </cell>
2244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2245 \begin_inset Text
2246
2247 \layout Standard
2248
2249
2250 \emph on 
2251 $DATADIR/ $INCLUDE_DIR_SUFFIX
2252 \end_inset 
2253 </cell>
2254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2255 \begin_inset Text
2256
2257 \layout Standard
2258
2259 /usr/local/share/sdcc/include
2260 \end_inset 
2261 </cell>
2262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2263 \begin_inset Text
2264
2265 \layout Standard
2266
2267
2268 \backslash 
2269 sdcc
2270 \backslash 
2271 include
2272 \end_inset 
2273 </cell>
2274 </row>
2275 <row topline="true">
2276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2277 \begin_inset Text
2278
2279 \layout Standard
2280
2281 Library file**
2282 \end_inset 
2283 </cell>
2284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2285 \begin_inset Text
2286
2287 \layout Standard
2288
2289
2290 \emph on 
2291 $DATADIR/$LIB_DIR_SUFFIX
2292 \end_inset 
2293 </cell>
2294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2295 \begin_inset Text
2296
2297 \layout Standard
2298
2299 /usr/local/share/sdcc/lib
2300 \end_inset 
2301 </cell>
2302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2303 \begin_inset Text
2304
2305 \layout Standard
2306
2307
2308 \backslash 
2309 sdcc
2310 \backslash 
2311 lib
2312 \end_inset 
2313 </cell>
2314 </row>
2315 <row topline="true" bottomline="true">
2316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2317 \begin_inset Text
2318
2319 \layout Standard
2320
2321 Documentation
2322 \end_inset 
2323 </cell>
2324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2325 \begin_inset Text
2326
2327 \layout Standard
2328
2329
2330 \emph on 
2331 $DOCDIR
2332 \end_inset 
2333 </cell>
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2335 \begin_inset Text
2336
2337 \layout Standard
2338
2339 /usr/local/share/sdcc/doc
2340 \end_inset 
2341 </cell>
2342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2343 \begin_inset Text
2344
2345 \layout Standard
2346
2347
2348 \backslash 
2349 sdcc
2350 \backslash 
2351 doc
2352 \end_inset 
2353 </cell>
2354 </row>
2355 </lyxtabular>
2356
2357 \end_inset 
2358
2359
2360 \layout Verse
2361
2362
2363 \size footnotesize 
2364 *compiler, preprocessor, assembler, and linker
2365 \newline 
2366 **the 
2367 \shape italic 
2368 model
2369 \shape default 
2370  is auto-appended by the compiler, e.g.
2371  small, large, z80, ds390 etc
2372 \layout Standard
2373 \noindent 
2374 The install paths can still be changed during `make install` with e.g.:
2375 \layout LyX-Code
2376
2377 make install prefix=$(HOME)/local/sdcc
2378 \layout Standard
2379
2380 Of course this doesn't change the search paths compiled into the binaries.
2381 \newline 
2382
2383 \newline 
2384 Moreover the install path can be changed by defining DESTDIR
2385 \begin_inset LatexCommand \index{DESTDIR}
2386
2387 \end_inset 
2388
2389 :
2390 \layout LyX-Code
2391
2392 make install DESTDIR=$(HOME)/sdcc.rpm/
2393 \layout Standard
2394
2395 Please note that DESTDIR must have a trailing slash!
2396 \layout Section
2397
2398 Search Paths
2399 \begin_inset LatexCommand \label{sub:Search-Paths}
2400
2401 \end_inset 
2402
2403
2404 \begin_inset LatexCommand \index{Search path}
2405
2406 \end_inset 
2407
2408
2409 \layout Standard
2410
2411 Some search paths or parts of them are determined by configure variables
2412  (in 
2413 \emph on 
2414 italics
2415 \emph default 
2416 , see section above).
2417  Further search paths are determined by environment variables during runtime.
2418  
2419 \newline 
2420 The paths searched when running the compiler are as follows (the first catch
2421  wins):
2422 \newline 
2423
2424 \newline 
2425 1.
2426  Binary files (preprocessor, assembler and linker)
2427 \newline 
2428
2429 \layout Standard
2430 \align center 
2431
2432 \begin_inset  Tabular
2433 <lyxtabular version="3" rows="4" columns="3">
2434 <features>
2435 <column alignment="block" valignment="top" leftline="true" width="0in">
2436 <column alignment="block" valignment="top" leftline="true" width="0in">
2437 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2438 <row topline="true" bottomline="true">
2439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2440 \begin_inset Text
2441
2442 \layout Standard
2443
2444 Search path
2445 \end_inset 
2446 </cell>
2447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2448 \begin_inset Text
2449
2450 \layout Standard
2451
2452 default
2453 \end_inset 
2454 </cell>
2455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2456 \begin_inset Text
2457
2458 \layout Standard
2459
2460 Win32 builds
2461 \end_inset 
2462 </cell>
2463 </row>
2464 <row topline="true">
2465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2466 \begin_inset Text
2467
2468 \layout Standard
2469
2470 $SDCC_HOME/
2471 \emph on 
2472 $PPREFIX2BIN_DIR
2473 \end_inset 
2474 </cell>
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2476 \begin_inset Text
2477
2478 \layout Standard
2479
2480 $SDCC_HOME/bin
2481 \end_inset 
2482 </cell>
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2484 \begin_inset Text
2485
2486 \layout Standard
2487
2488 $SDCC_HOME
2489 \backslash 
2490 bin
2491 \end_inset 
2492 </cell>
2493 </row>
2494 <row topline="true">
2495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2496 \begin_inset Text
2497
2498 \layout Standard
2499
2500 Path of argv[0] (if available)
2501 \end_inset 
2502 </cell>
2503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2504 \begin_inset Text
2505
2506 \layout Standard
2507
2508 Path of argv[0]
2509 \end_inset 
2510 </cell>
2511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2512 \begin_inset Text
2513
2514 \layout Standard
2515
2516 Path of argv[0]
2517 \end_inset 
2518 </cell>
2519 </row>
2520 <row topline="true" bottomline="true">
2521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2522 \begin_inset Text
2523
2524 \layout Standard
2525
2526 $PATH
2527 \end_inset 
2528 </cell>
2529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2530 \begin_inset Text
2531
2532 \layout Standard
2533
2534 $PATH
2535 \end_inset 
2536 </cell>
2537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2538 \begin_inset Text
2539
2540 \layout Standard
2541
2542 $PATH
2543 \end_inset 
2544 </cell>
2545 </row>
2546 </lyxtabular>
2547
2548 \end_inset 
2549
2550  
2551 \newline 
2552
2553 \layout Standard
2554 \noindent 
2555 2.
2556  Include files
2557 \newline 
2558
2559 \layout Standard
2560 \align center 
2561
2562 \begin_inset  Tabular
2563 <lyxtabular version="3" rows="6" columns="3">
2564 <features>
2565 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2566 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2567 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2568 <row topline="true" bottomline="true">
2569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2570 \begin_inset Text
2571
2572 \layout Standard
2573
2574 Search path
2575 \end_inset 
2576 </cell>
2577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2578 \begin_inset Text
2579
2580 \layout Standard
2581
2582 default
2583 \end_inset 
2584 </cell>
2585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2586 \begin_inset Text
2587
2588 \layout Standard
2589
2590 Win32 builds
2591 \end_inset 
2592 </cell>
2593 </row>
2594 <row topline="true">
2595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2596 \begin_inset Text
2597
2598 \layout Standard
2599
2600 -
2601 \begin_inset ERT
2602 status Collapsed
2603
2604 \layout Standard
2605
2606 \backslash 
2607 /
2608 \end_inset 
2609
2610 -I dir
2611 \end_inset 
2612 </cell>
2613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2614 \begin_inset Text
2615
2616 \layout Standard
2617
2618 -
2619 \begin_inset ERT
2620 status Collapsed
2621
2622 \layout Standard
2623
2624 \backslash 
2625 /
2626 \end_inset 
2627
2628 -I dir
2629 \end_inset 
2630 </cell>
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2632 \begin_inset Text
2633
2634 \layout Standard
2635
2636 -
2637 \begin_inset ERT
2638 status Collapsed
2639
2640 \layout Standard
2641
2642 \backslash 
2643 /
2644 \end_inset 
2645
2646 -I dir
2647 \end_inset 
2648 </cell>
2649 </row>
2650 <row topline="true">
2651 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2652 \begin_inset Text
2653
2654 \layout Standard
2655
2656 $SDCC_INCLUDE
2657 \end_inset 
2658 </cell>
2659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2660 \begin_inset Text
2661
2662 \layout Standard
2663
2664 $SDCC_INCLUDE
2665 \end_inset 
2666 </cell>
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2668 \begin_inset Text
2669
2670 \layout Standard
2671
2672 $SDCC_INCLUDE
2673 \end_inset 
2674 </cell>
2675 </row>
2676 <row topline="true">
2677 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2678 \begin_inset Text
2679
2680 \layout Standard
2681
2682 $SDCC_HOME/
2683 \newline 
2684
2685 \emph on 
2686 $PREFIX2DATA_DIR/
2687 \newline 
2688 $INCLUDE_DIR_SUFFIX
2689 \end_inset 
2690 </cell>
2691 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2692 \begin_inset Text
2693
2694 \layout Standard
2695
2696 $SDCC_ HOME/
2697 \newline 
2698 share/sdcc/
2699 \newline 
2700 include
2701 \end_inset 
2702 </cell>
2703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2704 \begin_inset Text
2705
2706 \layout Standard
2707
2708 $SDCC_HOME
2709 \backslash 
2710 include
2711 \end_inset 
2712 </cell>
2713 </row>
2714 <row topline="true">
2715 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2716 \begin_inset Text
2717
2718 \layout Standard
2719
2720 path(argv[0])/
2721 \newline 
2722
2723 \emph on 
2724 $BIN2DATADIR/
2725 \emph default 
2726
2727 \newline 
2728
2729 \emph on 
2730 $INCLUDE_DIR_SUFFIX
2731 \end_inset 
2732 </cell>
2733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2734 \begin_inset Text
2735
2736 \layout Standard
2737
2738 path(argv[0])/
2739 \newline 
2740 ../sdcc/include
2741 \newline 
2742 \SpecialChar ~
2743 \SpecialChar ~
2744 \SpecialChar ~
2745 \SpecialChar ~
2746 \SpecialChar ~
2747 \SpecialChar ~
2748 \SpecialChar ~
2749 \SpecialChar ~
2750 \SpecialChar ~
2751 \SpecialChar ~
2752 \SpecialChar ~
2753 \SpecialChar ~
2754 \SpecialChar ~
2755 \SpecialChar ~
2756 \SpecialChar ~
2757 \SpecialChar ~
2758 \SpecialChar ~
2759 \SpecialChar ~
2760 \SpecialChar ~
2761 \SpecialChar ~
2762 \SpecialChar ~
2763 \SpecialChar ~
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 \SpecialChar ~
2767 \SpecialChar ~
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 \SpecialChar ~
2773 \SpecialChar ~
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 \SpecialChar ~
2779 \SpecialChar ~
2780
2781 \end_inset 
2782 </cell>
2783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2784 \begin_inset Text
2785
2786 \layout Standard
2787
2788 path(argv[0])
2789 \backslash 
2790 ..
2791 \backslash 
2792 include
2793 \end_inset 
2794 </cell>
2795 </row>
2796 <row topline="true" bottomline="true">
2797 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2798 \begin_inset Text
2799
2800 \layout Standard
2801
2802
2803 \emph on 
2804 $DATADIR/
2805 \emph default 
2806
2807 \newline 
2808
2809 \emph on 
2810 $INCLUDE_DIR_SUFFIX
2811 \end_inset 
2812 </cell>
2813 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2814 \begin_inset Text
2815
2816 \layout Standard
2817
2818 /usr/local/share/sdcc/
2819 \newline 
2820 include
2821 \end_inset 
2822 </cell>
2823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2824 \begin_inset Text
2825
2826 \layout Standard
2827
2828 (not on Win32)
2829 \end_inset 
2830 </cell>
2831 </row>
2832 </lyxtabular>
2833
2834 \end_inset 
2835
2836  
2837 \newline 
2838
2839 \layout Standard
2840 \noindent 
2841 The option -
2842 \begin_inset ERT
2843 status Collapsed
2844
2845 \layout Standard
2846
2847 \backslash 
2848 /
2849 \end_inset 
2850
2851 -nostdinc disables the last two search paths.
2852 \newline 
2853
2854 \newline 
2855 3.
2856  Library files 
2857 \newline 
2858
2859 \layout Standard
2860
2861 With the exception of 
2862 \begin_inset Quotes sld
2863 \end_inset 
2864
2865 -
2866 \begin_inset ERT
2867 status Collapsed
2868
2869 \layout Standard
2870
2871 \backslash 
2872 /
2873 \end_inset 
2874
2875 -L dir
2876 \begin_inset Quotes srd
2877 \end_inset 
2878
2879  the 
2880 \shape italic 
2881 model
2882 \shape default 
2883  is auto-appended by the compiler (e.g.
2884  small, large, z80, ds390 etc.).
2885  
2886 \newline 
2887
2888 \layout Standard
2889 \align center 
2890
2891 \begin_inset  Tabular
2892 <lyxtabular version="3" rows="6" columns="3">
2893 <features>
2894 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2895 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2896 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2897 <row topline="true" bottomline="true">
2898 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2899 \begin_inset Text
2900
2901 \layout Standard
2902
2903 Search path
2904 \end_inset 
2905 </cell>
2906 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2907 \begin_inset Text
2908
2909 \layout Standard
2910
2911 default
2912 \end_inset 
2913 </cell>
2914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2915 \begin_inset Text
2916
2917 \layout Standard
2918
2919 Win32 builds
2920 \end_inset 
2921 </cell>
2922 </row>
2923 <row topline="true">
2924 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2925 \begin_inset Text
2926
2927 \layout Standard
2928
2929 -
2930 \begin_inset ERT
2931 status Collapsed
2932
2933 \layout Standard
2934
2935 \backslash 
2936 /
2937 \end_inset 
2938
2939 -L dir
2940 \end_inset 
2941 </cell>
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \layout Standard
2946
2947 -
2948 \begin_inset ERT
2949 status Collapsed
2950
2951 \layout Standard
2952
2953 \backslash 
2954 /
2955 \end_inset 
2956
2957 -L dir
2958 \end_inset 
2959 </cell>
2960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2961 \begin_inset Text
2962
2963 \layout Standard
2964
2965 -
2966 \begin_inset ERT
2967 status Collapsed
2968
2969 \layout Standard
2970
2971 \backslash 
2972 /
2973 \end_inset 
2974
2975 -L dir
2976 \end_inset 
2977 </cell>
2978 </row>
2979 <row topline="true">
2980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2981 \begin_inset Text
2982
2983 \layout Standard
2984
2985 $SDCC_LIB/
2986 \newline 
2987
2988 \emph on 
2989 <model>
2990 \end_inset 
2991 </cell>
2992 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2993 \begin_inset Text
2994
2995 \layout Standard
2996
2997 $SDCC_LIB/
2998 \newline 
2999
3000 \emph on 
3001 <model>
3002 \end_inset 
3003 </cell>
3004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3005 \begin_inset Text
3006
3007 \layout Standard
3008
3009 $SDCC_LIB
3010 \backslash 
3011
3012 \newline 
3013
3014 \emph on 
3015 <model>
3016 \end_inset 
3017 </cell>
3018 </row>
3019 <row topline="true">
3020 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3021 \begin_inset Text
3022
3023 \layout Standard
3024
3025 $SDCC_HOME/
3026 \newline 
3027
3028 \emph on 
3029 $PREFIX2DATA_DIR/
3030 \newline 
3031 $LIB_DIR_SUFFIX/<model>
3032 \end_inset 
3033 </cell>
3034 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3035 \begin_inset Text
3036
3037 \layout Standard
3038
3039 $SDCC_HOME/
3040 \newline 
3041 share/sdcc/
3042 \newline 
3043 lib/
3044 \emph on 
3045 <model>
3046 \end_inset 
3047 </cell>
3048 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3049 \begin_inset Text
3050
3051 \layout Standard
3052
3053 $SDCC_HOME
3054 \backslash 
3055 lib
3056 \backslash 
3057
3058 \emph on 
3059
3060 \newline 
3061 <model>
3062 \end_inset 
3063 </cell>
3064 </row>
3065 <row topline="true">
3066 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3067 \begin_inset Text
3068
3069 \layout Standard
3070
3071 path(argv[0])/
3072 \newline 
3073
3074 \emph on 
3075 $BIN2DATADIR/
3076 \emph default 
3077
3078 \newline 
3079
3080 \emph on 
3081 $LIB_DIR_SUFFIX/<model>
3082 \end_inset 
3083 </cell>
3084 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3085 \begin_inset Text
3086
3087 \layout Standard
3088
3089 path(argv[0])/
3090 \newline 
3091 ../sdcc/lib/
3092 \emph on 
3093 <model>
3094 \newline 
3095 \SpecialChar ~
3096 \SpecialChar ~
3097 \SpecialChar ~
3098 \SpecialChar ~
3099 \SpecialChar ~
3100 \SpecialChar ~
3101 \SpecialChar ~
3102 \SpecialChar ~
3103 \SpecialChar ~
3104 \SpecialChar ~
3105 \SpecialChar ~
3106 \SpecialChar ~
3107 \SpecialChar ~
3108 \SpecialChar ~
3109 \SpecialChar ~
3110 \SpecialChar ~
3111 \SpecialChar ~
3112 \SpecialChar ~
3113 \SpecialChar ~
3114 \SpecialChar ~
3115 \SpecialChar ~
3116 \SpecialChar ~
3117 \SpecialChar ~
3118 \SpecialChar ~
3119 \SpecialChar ~
3120 \SpecialChar ~
3121 \SpecialChar ~
3122 \SpecialChar ~
3123 \SpecialChar ~
3124 \SpecialChar ~
3125 \SpecialChar ~
3126 \SpecialChar ~
3127 \SpecialChar ~
3128 \SpecialChar ~
3129 \SpecialChar ~
3130 \SpecialChar ~
3131 \SpecialChar ~
3132 \SpecialChar ~
3133 \SpecialChar ~
3134
3135 \end_inset 
3136 </cell>
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3138 \begin_inset Text
3139
3140 \layout Standard
3141
3142 path(argv[0])
3143 \backslash 
3144
3145 \newline 
3146 ..
3147 \backslash 
3148 lib
3149 \backslash 
3150
3151 \emph on 
3152 <model>
3153 \newline 
3154 \SpecialChar ~
3155 \SpecialChar ~
3156 \SpecialChar ~
3157 \SpecialChar ~
3158 \SpecialChar ~
3159 \SpecialChar ~
3160 \SpecialChar ~
3161 \SpecialChar ~
3162 \SpecialChar ~
3163 \SpecialChar ~
3164 \SpecialChar ~
3165 \SpecialChar ~
3166 \SpecialChar ~
3167 \SpecialChar ~
3168 \SpecialChar ~
3169 \SpecialChar ~
3170 \SpecialChar ~
3171 \SpecialChar ~
3172 \SpecialChar ~
3173 \SpecialChar ~
3174 \SpecialChar ~
3175 \SpecialChar ~
3176 \SpecialChar ~
3177 \SpecialChar ~
3178 \SpecialChar ~
3179 \SpecialChar ~
3180 \SpecialChar ~
3181 \SpecialChar ~
3182 \SpecialChar ~
3183 \SpecialChar ~
3184 \SpecialChar ~
3185 \SpecialChar ~
3186 \SpecialChar ~
3187 \SpecialChar ~
3188 \SpecialChar ~
3189
3190 \end_inset 
3191 </cell>
3192 </row>
3193 <row topline="true" bottomline="true">
3194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3195 \begin_inset Text
3196
3197 \layout Standard
3198
3199
3200 \emph on 
3201 $DATADIR/
3202 \newline 
3203 $LIB_DIR_SUFFIX/<model>
3204 \end_inset 
3205 </cell>
3206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3207 \begin_inset Text
3208
3209 \layout Standard
3210
3211 /usr/local/share/sdcc/
3212 \newline 
3213 lib/
3214 \emph on 
3215 <model>
3216 \end_inset 
3217 </cell>
3218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3219 \begin_inset Text
3220
3221 \layout Standard
3222
3223 (not on Win32)
3224 \end_inset 
3225 </cell>
3226 </row>
3227 </lyxtabular>
3228
3229 \end_inset 
3230
3231
3232 \newline 
3233
3234 \layout Comment
3235
3236 Don't delete any of the stray spaces in the table above without checking
3237  the HTML output (last line)!
3238 \layout Standard
3239
3240 \SpecialChar ~
3241
3242 \newline 
3243 The option -
3244 \begin_inset ERT
3245 status Collapsed
3246
3247 \layout Standard
3248
3249 \backslash 
3250 /
3251 \end_inset 
3252
3253 -nostdlib disables the last two search paths.
3254 \layout Section
3255
3256 Building SDCC
3257 \begin_inset LatexCommand \index{Building SDCC}
3258
3259 \end_inset 
3260
3261
3262 \layout Subsection
3263
3264 Building SDCC on Linux
3265 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3266
3267 \end_inset 
3268
3269
3270 \layout Enumerate
3271
3272
3273 \series medium 
3274 Download the source package
3275 \series default 
3276  either from the SDCC Subversion repository or from the nightly snapshots
3277 \series medium 
3278 , it will be named something like sdcc
3279 \series default 
3280 .src
3281 \series medium 
3282 .t
3283 \series default 
3284 ar.
3285 \series medium 
3286 gz
3287 \series default 
3288  
3289 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3290
3291 \end_inset 
3292
3293 .
3294 \layout Enumerate
3295
3296
3297 \series medium 
3298 Bring up a command line terminal, such as xterm.
3299 \layout Enumerate
3300
3301
3302 \series medium 
3303 Unpack the file using a command like: 
3304 \family sans 
3305 \series bold 
3306 "tar -xvzf sdcc.src.tar.gz
3307 \family default 
3308 \series default 
3309 "
3310 \series medium 
3311 , this will create a sub-directory called sdcc with all of the sources.
3312 \layout Enumerate
3313
3314 Change directory into the main SDCC directory, for example type: 
3315 \family sans 
3316 \series bold 
3317 "cd sdcc
3318 \series default 
3319 ".
3320 \layout Enumerate
3321
3322
3323 \series medium 
3324 Type 
3325 \family sans 
3326 \series bold 
3327 "./configure
3328 \family default 
3329 \series default 
3330 ".
3331  This configures the package for compilation on your system.
3332 \layout Enumerate
3333
3334
3335 \series medium 
3336 Type 
3337 \family sans 
3338 \series bold 
3339 "make
3340 \family default 
3341 \series default 
3342 "
3343 \series medium 
3344 .
3345
3346 \series default 
3347  All of the source packages will compile, this can take a while.
3348 \layout Enumerate
3349
3350
3351 \series medium 
3352 Type 
3353 \family sans 
3354 \series bold 
3355 "make install"
3356 \family default 
3357 \series default 
3358  as root
3359 \series medium 
3360 .
3361
3362 \series default 
3363  This copies the binary executables, the include files, the libraries and
3364  the documentation to the install directories.
3365  Proceed with section 
3366 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3367
3368 \end_inset 
3369
3370 .
3371 \layout Subsection
3372
3373 Building SDCC on OSX 2.x
3374 \layout Standard
3375
3376 Follow the instruction for Linux.
3377 \newline 
3378
3379 \newline 
3380 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3381 )) fails to compile SDCC.
3382  Fortunately there's also gcc 2.9.x installed, which works fine.
3383  This compiler can be selected by running 'configure' with:
3384 \layout LyX-Code
3385
3386 ./configure CC=gcc2 CXX=g++2
3387 \layout Subsection
3388
3389 Cross compiling SDCC on Linux for Windows
3390 \layout Standard
3391
3392 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3393  See section 'Configure Options'.
3394 \layout Subsection
3395
3396 Building SDCC on Windows 
3397 \layout Standard
3398
3399 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
3400  built on Windows.
3401  They use Unix-sockets, which are not available on Win32.
3402 \layout Subsection
3403
3404 Building SDCC using Cygwin and Mingw32
3405 \layout Standard
3406
3407 For building and installing a Cygwin executable follow the instructions
3408  for Linux.
3409 \newline 
3410
3411 \newline 
3412 On Cygwin a 
3413 \begin_inset Quotes sld
3414 \end_inset 
3415
3416 native
3417 \begin_inset Quotes srd
3418 \end_inset 
3419
3420  Win32-binary can be built, which will not need the Cygwin-DLL.
3421  For the necessary 'configure' options see section 'configure options' or
3422  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3423 \newline 
3424
3425 \newline 
3426 In order to install Cygwin on Windows download setup.exe from 
3427 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3428
3429 \end_inset 
3430
3431 .
3432  Run it, set the 
3433 \begin_inset Quotes sld
3434 \end_inset 
3435
3436 default text file type
3437 \begin_inset Quotes srd
3438 \end_inset 
3439
3440  to 
3441 \begin_inset Quotes sld
3442 \end_inset 
3443
3444 unix
3445 \begin_inset Quotes srd
3446 \end_inset 
3447
3448  and download/install at least the following packages.
3449  Some packages are selected by default, others will be automatically selected
3450  because of dependencies with the manually selected packages.
3451  Never deselect these packages!
3452 \layout Itemize
3453
3454 flex
3455 \layout Itemize
3456
3457 bison
3458 \layout Itemize
3459
3460 gcc ; version 3.x is fine, no need to use the old 2.9x
3461 \layout Itemize
3462
3463 binutils ; selected with gcc
3464 \layout Itemize
3465
3466 make
3467 \layout Itemize
3468
3469 rxvt ; a nice console, which makes life much easier under windoze (see below)
3470 \layout Itemize
3471
3472 man ; not really needed for building SDCC, but you'll miss it sooner or
3473  later
3474 \layout Itemize
3475
3476 less ; not really needed for building SDCC, but you'll miss it sooner or
3477  later
3478 \layout Itemize
3479
3480 svn ; only if you use Subversion access
3481 \layout Standard
3482
3483 If you want to develop something you'll need:
3484 \layout Itemize
3485
3486 python ; for the regression tests
3487 \layout Itemize
3488
3489 gdb ; the gnu debugger, together with the nice GUI 
3490 \begin_inset Quotes sld
3491 \end_inset 
3492
3493 insight
3494 \begin_inset Quotes srd
3495 \end_inset 
3496
3497
3498 \layout Itemize
3499
3500 openssh ; to access the CF or commit changes
3501 \layout Itemize
3502
3503 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3504  use autoconf-stable!
3505 \layout Standard
3506
3507 rxvt is a nice console with history.
3508  Replace in your cygwin.bat the line
3509 \layout LyX-Code
3510
3511 bash -
3512 \begin_inset ERT
3513 status Collapsed
3514
3515 \layout Standard
3516
3517 \backslash 
3518 /
3519 \end_inset 
3520
3521 -login -i 
3522 \layout Standard
3523
3524 with (one line):
3525 \layout LyX-Code
3526
3527 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3528 \layout LyX-Code
3529
3530      -bg black -fg white -geometry 100x65 -e bash -
3531 \begin_inset ERT
3532 status Collapsed
3533
3534 \layout Standard
3535
3536 \backslash 
3537 /
3538 \end_inset 
3539
3540 -login
3541 \layout Standard
3542
3543 Text selected with the mouse is automatically copied to the clipboard, pasting
3544  works with shift-insert.
3545 \newline 
3546
3547 \newline 
3548 The other good tip is to make sure you have no //c/-style paths anywhere,
3549  use /cygdrive/c/ instead.
3550  Using // invokes a network lookup which is very slow.
3551  If you think 
3552 \begin_inset Quotes sld
3553 \end_inset 
3554
3555 cygdrive
3556 \begin_inset Quotes srd
3557 \end_inset 
3558
3559  is too long, you can change it with e.g.
3560 \layout LyX-Code
3561
3562 mount -s -u -c /mnt
3563 \layout Standard
3564
3565 SDCC sources use the unix line ending LF.
3566  Life is much easier, if you store the source tree on a drive which is mounted
3567  in binary mode.
3568  And use an editor which can handle LF-only line endings.
3569  Make sure not to commit files with windows line endings.
3570  The tabulator spacing
3571 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3572
3573 \end_inset 
3574
3575  used in the project is 8.
3576  Although a tabulator spacing of 8 is a sensible choice for programmers
3577  (it's a power of 2 and allows to display 8/16 bit signed variables without
3578  loosing columns) the plan is to move towards using only spaces in the source.
3579 \layout Subsection
3580
3581 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3582 \layout Standard
3583
3584
3585 \series medium 
3586 Download the source package
3587 \series default 
3588  either from the SDCC Subversion repository or from the 
3589 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3590
3591 \end_inset 
3592
3593
3594 \series medium 
3595 , it will be named something like sdcc
3596 \series default 
3597 .src
3598 \series medium 
3599 .tgz.
3600
3601 \series default 
3602  SDCC is distributed with all the projects, workspaces, and files you need
3603  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3604  doesn't build under MSVC).
3605  The workspace name is 'sdcc.dsw'.
3606  Please note that as it is now, all the executables are created in a folder
3607  called sdcc
3608 \backslash 
3609 bin_vc.
3610  Once built you need to copy the executables from sdcc
3611 \backslash 
3612 bin_vc to sdcc
3613 \backslash 
3614 bin before running SDCC.
3615  
3616 \newline 
3617
3618 \newline 
3619 WARNING: Visual studio is very picky with line terminations; it expects
3620  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3621  When using the Subversion repository it's easiest to configure the svn
3622  client to convert automatically for you.
3623  If however you are getting a message such as "This makefile was not generated
3624  by Developer Studio etc.
3625  etc.
3626 \begin_inset Quotes srd
3627 \end_inset 
3628
3629  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3630  need to convert the Unix style line endings to DOS style line endings.
3631  To do so you can use the 
3632 \begin_inset Quotes sld
3633 \end_inset 
3634
3635 unix2dos
3636 \begin_inset Quotes srd
3637 \end_inset 
3638
3639  utility freely available on the internet.
3640  Doug Hawkins reported in the sdcc-user list that this works:
3641 \newline 
3642
3643 \newline 
3644 C:
3645 \backslash 
3646 Programming
3647 \backslash 
3648 SDCC> unix2dos sdcc.dsw
3649 \newline 
3650 C:
3651 \backslash 
3652 Programming
3653 \backslash 
3654 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3655 \newline 
3656
3657 \newline 
3658 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3659  flex.exe, and gawk.exe.
3660  One good place to get them is 
3661 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3662
3663 \end_inset 
3664
3665
3666 \newline 
3667
3668 \newline 
3669 Download the file UnxUtils
3670 \begin_inset LatexCommand \index{UnxUtils}
3671
3672 \end_inset 
3673
3674 .zip.
3675  Now you have to install the utilities and setup MSVC so it can locate the
3676  required programs.
3677  Here there are two alternatives (choose one!):
3678 \layout Enumerate
3679
3680 The easy way:
3681 \newline 
3682
3683 \newline 
3684 a) Extract UnxUtils.zip to your C:
3685 \backslash 
3686  hard disk PRESERVING the original paths, otherwise bison won't work.
3687  (If you are using WinZip make certain that 'Use folder names' is selected)
3688 \newline 
3689
3690 \newline 
3691 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3692  in 'Show directories for:' select 'Executable files', and in the directories
3693  window add a new path: 'C:
3694 \backslash 
3695 user
3696 \backslash 
3697 local
3698 \backslash 
3699 wbin', click ok.
3700 \newline 
3701
3702 \newline 
3703 (As a side effect, you get a bunch of Unix utilities that could be useful,
3704  such as diff and patch.)
3705 \layout Enumerate
3706
3707 A more compact way:
3708 \newline 
3709
3710 \newline 
3711 This one avoids extracting a bunch of files you may not use, but requires
3712  some extra work:
3713 \newline 
3714
3715 \newline 
3716 a) Create a directory were to put the tools needed, or use a directory already
3717  present.
3718  Say for example 'C:
3719 \backslash 
3720 util'.
3721 \newline 
3722
3723 \newline 
3724 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3725  to such directory WITHOUT preserving the original paths.
3726  (If you are using WinZip make certain that 'Use folder names' is not selected)
3727 \newline 
3728
3729 \newline 
3730 c) Rename bison.exe to '_bison.exe'.
3731 \newline 
3732
3733 \newline 
3734 d) Create a batch file 'bison.bat' in 'C:
3735 \backslash 
3736 util
3737 \backslash 
3738 ' and add these lines: 
3739 \newline 
3740 \SpecialChar ~
3741 \SpecialChar ~
3742 set BISON_SIMPLE=C:
3743 \backslash 
3744 util
3745 \backslash 
3746 bison.simple 
3747 \newline 
3748 \SpecialChar ~
3749 \SpecialChar ~
3750 set BISON_HAIRY=C:
3751 \backslash 
3752 util
3753 \backslash 
3754 bison.hairy
3755 \newline 
3756 \SpecialChar ~
3757 \SpecialChar ~
3758 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3759 \newline 
3760
3761 \newline 
3762 Steps 'c' and 'd' are needed because bison requires by default that the
3763  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3764  '/usr/local/share/' I think.
3765  So it is necessary to tell bison where those files are located if they
3766  are not in such directory.
3767  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3768 \newline 
3769
3770 \newline 
3771 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3772  in 'Show directories for:' select 'Executable files', and in the directories
3773  window add a new path: 'c:
3774 \backslash 
3775 util', click ok.
3776  Note that you can use any other path instead of 'c:
3777 \backslash 
3778 util', even the path where the Visual C++ tools are, probably: 'C:
3779 \backslash 
3780 Program Files
3781 \backslash 
3782 Microsoft Visual Studio
3783 \backslash 
3784 Common
3785 \backslash 
3786 Tools'.
3787  So you don't have to execute step 'e' :)
3788 \layout Standard
3789
3790 That is it.
3791  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3792  the executables from sdcc
3793 \backslash 
3794 bin_vc to sdcc
3795 \backslash 
3796 bin, and you can compile using SDCC.
3797 \layout Subsection
3798
3799 Building SDCC Using Borland
3800 \layout Enumerate
3801
3802 From the sdcc directory, run the command "make -f Makefile.bcc".
3803  This should regenerate all the .exe files in the bin directory except for
3804  sdcdb.exe (which currently doesn't build under Borland C++).
3805 \layout Enumerate
3806
3807 If you modify any source files and need to rebuild, be aware that the dependenci
3808 es may not be correctly calculated.
3809  The safest option is to delete all .obj files and run the build again.
3810  From a Cygwin BASH prompt, this can easily be done with the command (be
3811  sure you are in the sdcc directory):
3812 \newline 
3813
3814 \newline 
3815
3816 \family sans 
3817 \series bold 
3818 find .
3819  
3820 \backslash 
3821 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3822 \backslash 
3823 ) -print -exec rm {} 
3824 \backslash 
3825 ;
3826 \family default 
3827 \series default 
3828
3829 \newline 
3830
3831 \newline 
3832 or on Windows NT/2000/XP from the command prompt with the command:
3833 \newline 
3834
3835 \family sans 
3836 \series bold 
3837
3838 \newline 
3839 del /s *.obj *.lib *.rul
3840 \family default 
3841 \series default 
3842  from the sdcc directory.
3843 \layout Subsection
3844
3845 Windows Install Using a ZIP Package
3846 \layout Enumerate
3847
3848 Download the binary zip package from 
3849 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3850
3851 \end_inset 
3852
3853  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3854  This should unpack to a group of sub-directories.
3855  An example directory structure after unpacking the mingw32 package is:
3856  c:
3857 \backslash 
3858 sdcc
3859 \backslash 
3860 bin for the executables, c:
3861 \backslash 
3862 sdcc
3863 \backslash 
3864 include and c:
3865 \backslash 
3866 sdcc
3867 \backslash 
3868 lib for the include and libraries.
3869 \layout Enumerate
3870
3871 Adjust your environment variable PATH to include the location of the bin
3872  directory or start sdcc using the full path.
3873 \layout Subsection
3874
3875 Windows Install Using the Setup Program
3876 \begin_inset LatexCommand \label{sub:Windows-Install}
3877
3878 \end_inset 
3879
3880
3881 \layout Standard
3882
3883 Download the setup program 
3884 \emph on 
3885 sdcc-x.y.z-setup.exe
3886 \emph default 
3887  for an official release from 
3888 \newline 
3889
3890 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3891
3892 \end_inset 
3893
3894  or a setup program for one of the snapshots 
3895 \emph on 
3896 sdcc_yyyymmdd_setup.exe
3897 \emph default 
3898  from 
3899 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3900
3901 \end_inset 
3902
3903  and execute it.
3904  A windows typical installer will guide you through the installation process.
3905 \layout Subsection
3906
3907 VPATH
3908 \begin_inset LatexCommand \index{VPATH}
3909
3910 \end_inset 
3911
3912  feature
3913 \layout Standard
3914
3915 SDCC supports the VPATH feature provided by configure and make.
3916  It allows to separate the source and build trees.
3917  Here's an example:
3918 \layout Standard
3919
3920
3921 \family typewriter 
3922 cd ~\SpecialChar ~
3923 \SpecialChar ~
3924 \SpecialChar ~
3925 \SpecialChar ~
3926 \SpecialChar ~
3927 \SpecialChar ~
3928 \SpecialChar ~
3929 \SpecialChar ~
3930 \SpecialChar ~
3931 \SpecialChar ~
3932 \SpecialChar ~
3933 \SpecialChar ~
3934 \SpecialChar ~
3935 \SpecialChar ~
3936 \SpecialChar ~
3937 \SpecialChar ~
3938 \SpecialChar ~
3939 \SpecialChar ~
3940 \SpecialChar ~
3941 \SpecialChar ~
3942 \SpecialChar ~
3943 # cd $HOME
3944 \layout Standard
3945
3946
3947 \family typewriter 
3948 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3949 # extract source to directory sdcc
3950 \layout Standard
3951
3952
3953 \family typewriter 
3954 mkdir sdcc.build\SpecialChar ~
3955 \SpecialChar ~
3956 \SpecialChar ~
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 \SpecialChar ~
3960 \SpecialChar ~
3961 \SpecialChar ~
3962 \SpecialChar ~
3963 # put output in sdcc.build
3964 \layout Standard
3965
3966
3967 \family typewriter 
3968 cd sdcc.build
3969 \layout Standard
3970
3971
3972 \family typewriter 
3973 ../sdcc/configure\SpecialChar ~
3974 \SpecialChar ~
3975 \SpecialChar ~
3976 \SpecialChar ~
3977 \SpecialChar ~
3978 \SpecialChar ~
3979 \SpecialChar ~
3980 \SpecialChar ~
3981 # configure is doing all the magic!
3982 \layout Standard
3983
3984
3985 \family typewriter 
3986 make
3987 \layout Standard
3988 \noindent 
3989 That's it! 
3990 \series bold 
3991 configure
3992 \series default 
3993  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
3994  It automagically computes the variables srcdir, top_srcdir and top_buildir
3995  for each directory.
3996  After running 
3997 \series bold 
3998 make
3999 \series default 
4000  the generated files will be in ~/sdcc.build, while the source files stay
4001  in ~/sdcc.
4002 \newline 
4003 This is not only usefull for building different binaries, e.g.
4004  when cross compiling.
4005  It also gives you a much better overview in the source tree when all the
4006  generated files are not scattered between the source files.
4007  And the best thing is: if you want to change a file you can leave the original
4008  file untouched in the source directory.
4009  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4010  Makefile.dep` and `make`.
4011  
4012 \series bold 
4013 make
4014 \series default 
4015  will do the rest for you!
4016 \layout Section
4017
4018 Building the Documentation
4019 \layout Standard
4020
4021 Add -
4022 \begin_inset ERT
4023 status Collapsed
4024
4025 \layout Standard
4026
4027 \backslash 
4028 /
4029 \end_inset 
4030
4031 -enable-doc to the configure arguments to build the documentation together
4032  with all the other stuff.
4033  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4034  dvips and makeindex) to get the job done.
4035  Another possibility is to change to the doc directory and to type 
4036 \family sans 
4037 \series bold 
4038
4039 \begin_inset Quotes srd
4040 \end_inset 
4041
4042 make
4043 \begin_inset Quotes srd
4044 \end_inset 
4045
4046
4047 \family default 
4048 \series default 
4049  there.
4050  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4051 x).
4052  Using LyX 
4053 \begin_inset LatexCommand \url{http://www.lyx.org}
4054
4055 \end_inset 
4056
4057  as editor is straightforward.
4058  Prebuilt documentation in html and pdf format is available from 
4059 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4060
4061 \end_inset 
4062
4063 .
4064 \layout Section
4065
4066 Reading the Documentation
4067 \layout Standard
4068
4069 Currently reading the document in pdf format is recommended, as for unknown
4070  reason the hyperlinks are working there whereas in the html version they
4071  are not
4072 \begin_inset Foot
4073 collapsed false
4074
4075 \layout Standard
4076
4077 If you should know why please drop us a note
4078 \end_inset 
4079
4080 .
4081  
4082 \newline 
4083 You'll find the pdf version
4084 \begin_inset LatexCommand \index{PDF version of this document}
4085
4086 \end_inset 
4087
4088  at 
4089 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4090
4091 \end_inset 
4092
4093 .
4094  
4095 \newline 
4096 A html version
4097 \begin_inset LatexCommand \index{HTML version of this document}
4098
4099 \end_inset 
4100
4101  should be online at 
4102 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4103
4104 \end_inset 
4105
4106 .
4107 \newline 
4108 This documentation is in some aspects different from a commercial documentation:
4109  
4110 \layout Itemize
4111
4112 It tries to document SDCC for several processor architectures in one document
4113  (commercially these probably would be separate documents/products).
4114  This document
4115 \begin_inset LatexCommand \index{Status of documentation}
4116
4117 \end_inset 
4118
4119  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4120 on about f.e.
4121  Z80, PIC14, PIC16 and HC08.
4122 \layout Itemize
4123
4124 There are many references pointing away from this documentation.
4125  Don't let this distract you.
4126  If there f.e.
4127  was a reference like 
4128 \begin_inset LatexCommand \url{http://www.opencores.org}
4129
4130 \end_inset 
4131
4132  together with a statement 
4133 \begin_inset Quotes sld
4134 \end_inset 
4135
4136 some processors which are targetted by SDCC can be implemented in a 
4137 \emph on 
4138 f
4139 \emph default 
4140 ield 
4141 \emph on 
4142 p
4143 \emph default 
4144 rogrammable 
4145 \emph on 
4146 g
4147 \emph default 
4148 ate 
4149 \emph on 
4150 a
4151 \emph default 
4152 rray
4153 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4154
4155 \end_inset 
4156
4157
4158 \begin_inset Quotes srd
4159 \end_inset 
4160
4161  or 
4162 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4163
4164 \end_inset 
4165
4166
4167 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4168
4169 \end_inset 
4170
4171  
4172 \begin_inset Quotes sld
4173 \end_inset 
4174
4175 have you ever heard of an open source compiler that compiles a subset of
4176  C for an FPGA?
4177 \begin_inset Quotes srd
4178 \end_inset 
4179
4180  we expect you to have a quick look there and come back.
4181  If you read this you are on the right track.
4182 \layout Itemize
4183
4184 Some sections attribute more space to problems, restrictions and warnings
4185  than to the solution.
4186 \layout Itemize
4187
4188 The installation section and the section about the debugger is intimidating.
4189 \layout Itemize
4190
4191 There are still lots of typos and there are more different writing styles
4192  than pictures.
4193 \layout Section
4194
4195 Testing the SDCC Compiler
4196 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4197
4198 \end_inset 
4199
4200
4201 \layout Standard
4202
4203 The first thing you should do after installing your SDCC compiler is to
4204  see if it runs.
4205  Type 
4206 \family sans 
4207 \series bold 
4208 "sdcc -
4209 \begin_inset ERT
4210 status Collapsed
4211
4212 \layout Standard
4213
4214 \backslash 
4215 /
4216 \end_inset 
4217
4218 -version"
4219 \begin_inset LatexCommand \index{version}
4220
4221 \end_inset 
4222
4223
4224 \family default 
4225 \series default 
4226  at the prompt, and the program should run and tell you the version.
4227  If it doesn't run, or gives a message about not finding sdcc program, then
4228  you need to check over your installation.
4229  Make sure that the sdcc bin directory is in your executable search path
4230  defined by the PATH environment setting (
4231 \series medium 
4232 see 
4233 \series default 
4234 section 
4235 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4236
4237 \end_inset 
4238
4239 \SpecialChar ~
4240
4241 \series medium 
4242 Install trouble-shooting for suggestions
4243 \series default 
4244 ).
4245  Make sure that the sdcc program is in the bin folder, if not perhaps something
4246  did not install correctly.
4247 \newline 
4248
4249 \newline 
4250
4251 \series medium 
4252 SDCC 
4253 \series default 
4254 is commonly installed as described in section 
4255 \begin_inset Quotes sld
4256 \end_inset 
4257
4258 Install and search paths
4259 \begin_inset Quotes srd
4260 \end_inset 
4261
4262 .
4263 \newline 
4264
4265 \newline 
4266
4267 \series medium 
4268 Make sure the compiler works on a very simple example.
4269  Type in the following test.c program using your favorite 
4270 \series default 
4271 ASCII 
4272 \series medium 
4273 editor:
4274 \layout Verse
4275
4276
4277 \family typewriter 
4278 char test;
4279 \newline 
4280
4281 \newline 
4282 void main(void) {
4283 \newline 
4284 \SpecialChar ~
4285 \SpecialChar ~
4286 \SpecialChar ~
4287 \SpecialChar ~
4288 test=0;
4289 \newline 
4290 }
4291 \layout Standard
4292
4293
4294 \series medium 
4295 Compile this using the following command: 
4296 \family sans 
4297 \series bold 
4298 "sdcc -c test.c".
4299
4300 \family default 
4301 \series default 
4302  
4303 \series medium 
4304 If all goes well, the compiler will generate a test.asm and test.rel file.
4305  Congratulations, you've just compiled your first program with SDCC.
4306  We used the -c option to tell SDCC not to link the generated code, just
4307  to keep things simple for this step.
4308 \series default 
4309
4310 \newline 
4311
4312 \newline 
4313
4314 \series medium 
4315 The next step is to try it with the linker.
4316  Type in 
4317 \family sans 
4318 \series bold 
4319 "sdcc test.c
4320 \family default 
4321 \series default 
4322 "
4323 \series medium 
4324 .
4325  If all goes well the compiler will link with the libraries and produce
4326  a test.ihx output file.
4327  If this step fails
4328 \series default 
4329  
4330 \series medium 
4331 (no test.ihx, and the linker generates warnings), then the problem is most
4332  likely that 
4333 \series default 
4334 SDCC
4335 \series medium 
4336  cannot find the 
4337 \series default 
4338 /
4339 \series medium 
4340 usr/local/share/sdcc/lib directory
4341 \series default 
4342  
4343 \series medium 
4344 (see 
4345 \series default 
4346 section 
4347 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4348
4349 \end_inset 
4350
4351 \SpecialChar ~
4352
4353 \series medium 
4354 Install trouble-shooting for suggestions).
4355 \series default 
4356
4357 \newline 
4358
4359 \newline 
4360
4361 \series medium 
4362 The final test is to ensure 
4363 \series default 
4364 SDCC
4365 \series medium 
4366  can use the 
4367 \series default 
4368 standard
4369 \series medium 
4370  header files and libraries.
4371  Edit test.c and change it to the following:
4372 \layout Verse
4373
4374
4375 \family typewriter 
4376 #include <string.h>
4377 \newline 
4378
4379 \newline 
4380 char str1[10];
4381 \newline 
4382
4383 \newline 
4384 void main(void) {
4385 \newline 
4386 \SpecialChar ~
4387 \SpecialChar ~
4388 strcpy(str1, "testing");
4389 \newline 
4390 }
4391 \layout Standard
4392
4393
4394 \series medium 
4395 Compile this by typing 
4396 \family sans 
4397 \series bold 
4398 "sdcc test.c"
4399 \family default 
4400 \series medium 
4401 .
4402  This should generate a test.ihx output file, and it should give no warnings
4403  such as not finding the string.h file.
4404  If it cannot find the string.h file, then the problem is that 
4405 \series default 
4406 SDCC
4407 \series medium 
4408  cannot find the /usr/local/share/sdcc/include directory
4409 \series default 
4410  
4411 \series medium 
4412 (see the 
4413 \series default 
4414 section 
4415 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4416
4417 \end_inset 
4418
4419 \SpecialChar ~
4420
4421 \series medium 
4422 Install trouble-shooting section for suggestions).
4423
4424 \series default 
4425  Use option 
4426 \series bold 
4427 -
4428 \begin_inset ERT
4429 status Collapsed
4430
4431 \layout Standard
4432
4433 \backslash 
4434 /
4435 \end_inset 
4436
4437 -print-search-dirs
4438 \series default 
4439
4440 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4441
4442 \end_inset 
4443
4444  to find exactly where SDCC is looking for the include and lib files.
4445 \layout Section
4446
4447 Install Trouble-shooting
4448 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4449
4450 \end_inset 
4451
4452
4453 \begin_inset LatexCommand \index{Install trouble-shooting}
4454
4455 \end_inset 
4456
4457
4458 \layout Subsection
4459
4460 If SDCC does not build correctly
4461 \layout Standard
4462
4463 A thing to try is starting from scratch by unpacking the .tgz source package
4464  again in an empty directory.
4465  Configure it like:
4466 \newline 
4467
4468 \newline 
4469
4470 \family sans 
4471 \series bold 
4472 ./configure 2>&1 | tee configure.log
4473 \family default 
4474 \series default 
4475
4476 \newline 
4477
4478 \newline 
4479 and build it like:
4480 \newline 
4481
4482 \newline 
4483
4484 \family sans 
4485 \series bold 
4486 make 2>&1 | tee make.log
4487 \family default 
4488 \series default 
4489
4490 \newline 
4491
4492 \newline 
4493 If anything goes wrong, you can review the log files to locate the problem.
4494  Or a relevant part of this can be attached to an email that could be helpful
4495  when requesting help from the mailing list.
4496 \layout Subsection
4497
4498 What the 
4499 \begin_inset Quotes sld
4500 \end_inset 
4501
4502 ./configure
4503 \begin_inset Quotes srd
4504 \end_inset 
4505
4506  does
4507 \layout Standard
4508
4509 The 
4510 \begin_inset Quotes sld
4511 \end_inset 
4512
4513 ./configure
4514 \begin_inset Quotes srd
4515 \end_inset 
4516
4517  command is a script that analyzes your system and performs some configuration
4518  to ensure the source package compiles on your system.
4519  It will take a few minutes to run, and will compile a few tests to determine
4520  what compiler features are installed.
4521 \layout Subsection
4522
4523 What the 
4524 \begin_inset Quotes sld
4525 \end_inset 
4526
4527 make
4528 \begin_inset Quotes srd
4529 \end_inset 
4530
4531  does
4532 \layout Standard
4533
4534 This runs the GNU make tool, which automatically compiles all the source
4535  packages into the final installed binary executables.
4536 \layout Subsection
4537
4538 What the 
4539 \begin_inset Quotes sld
4540 \end_inset 
4541
4542 make install
4543 \begin_inset Quotes erd
4544 \end_inset 
4545
4546  command does.
4547 \layout Standard
4548
4549 This will install the compiler, other executables libraries and include
4550  files into the appropriate directories.
4551  See sections 
4552 \begin_inset LatexCommand \ref{sub:Install-paths}
4553
4554 \end_inset 
4555
4556 ,\SpecialChar ~
4557
4558 \begin_inset LatexCommand \ref{sub:Search-Paths}
4559
4560 \end_inset 
4561
4562 \SpecialChar ~
4563 about install and search paths.
4564 \newline 
4565 On most systems you will need super-user privileges to do this.
4566 \layout Section
4567
4568 Components of SDCC
4569 \layout Standard
4570
4571 SDCC is not just a compiler, but a collection of tools by various developers.
4572  These include linkers, assemblers, simulators and other components.
4573  Here is a summary of some of the components.
4574  Note that the included simulator and assembler have separate documentation
4575  which you can find in the source package in their respective directories.
4576  As SDCC grows to include support for other processors, other packages from
4577  various developers are included and may have their own sets of documentation.
4578 \newline 
4579
4580 \newline 
4581 You might want to look at the files which are installed in <installdir>.
4582  At the time of this writing, we find the following programs for gcc-builds:
4583 \newline 
4584  
4585 \newline 
4586 In <installdir>/bin:
4587 \layout Itemize
4588
4589 sdcc - The compiler.
4590 \layout Itemize
4591
4592 sdcpp - The C preprocessor.
4593 \layout Itemize
4594
4595 asx8051 - The assembler for 8051 type processors.
4596 \layout Itemize
4597
4598 as-z80
4599 \series bold 
4600
4601 \series default 
4602 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4603 \layout Itemize
4604
4605 aslink -The linker for 8051 type processors.
4606 \layout Itemize
4607
4608 link-z80
4609 \series bold 
4610
4611 \series default 
4612 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4613 \layout Itemize
4614
4615 s51 - The ucSim 8051 simulator.
4616  Not available on Win32 platforms.
4617 \layout Itemize
4618
4619 sdcdb - The source debugger.
4620  Not available on Win32 platforms.
4621 \layout Itemize
4622
4623 packihx - A tool to pack (compress) Intel hex files.
4624 \layout Standard
4625
4626 In <installdir>/share/sdcc/include
4627 \layout Itemize
4628
4629 the include files
4630 \layout Standard
4631
4632 In <installdir>/share/sdcc/lib
4633 \layout Itemize
4634
4635 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4636  relocatables.
4637 \layout Standard
4638
4639 In <installdir>/share/sdcc/doc
4640 \layout Itemize
4641
4642 the documentation
4643 \layout Standard
4644
4645 As development for other processors proceeds, this list will expand to include
4646  executables to support processors like AVR, PIC, etc.
4647 \layout Subsection
4648
4649 sdcc - The Compiler
4650 \layout Standard
4651
4652 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4653  the assembler and linkage editor.
4654 \layout Subsection
4655
4656 sdcpp - The C-Preprocessor
4657 \layout Standard
4658
4659 The preprocessor
4660 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4661
4662 \end_inset 
4663
4664  is a modified version of the GNU preprocessor.
4665  The C preprocessor is used to pull in #include sources, process #ifdef
4666  statements, #defines and so on.
4667 \layout Subsection
4668
4669 as
4670 \emph on 
4671 xxxx
4672 \emph default 
4673 , aslink, link-
4674 \emph on 
4675 xxx
4676 \emph default 
4677  - The Assemblers and Linkage Editors
4678 \layout Standard
4679
4680 This is retargettable assembler & linkage editor, it was developed by Alan
4681  Baldwin.
4682  John Hartman created the version for 8051, and I (Sandeep) have made some
4683  enhancements and bug fixes for it to work properly with SDCC.
4684 \layout Subsection
4685
4686 s51 - The Simulator
4687 \layout Standard
4688
4689 S51
4690 \begin_inset LatexCommand \index{s51}
4691
4692 \end_inset 
4693
4694  is a freeware, opensource simulator developed by Daniel Drotos.
4695  The simulator is built as part of the build process.
4696  For more information visit Daniel's web site at: 
4697 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4698
4699 \end_inset 
4700
4701 .
4702  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4703  XA51 family.
4704  S51 is currently not available on Win32 platfors.
4705 \layout Subsection
4706
4707 sdcdb - Source Level Debugger
4708 \layout Standard
4709
4710 Sdcdb
4711 \begin_inset LatexCommand \index{sdcdb (debugger)}
4712
4713 \end_inset 
4714
4715  is the companion source level debugger.
4716  More about sdcdb in section 
4717 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4718
4719 \end_inset 
4720
4721 .
4722  The current version of the debugger uses Daniel's Simulator S51
4723 \begin_inset LatexCommand \index{s51}
4724
4725 \end_inset 
4726
4727 , but can be easily changed to use other simulators.
4728  Sdcdb is currently not available on Win32 platfors.
4729 \layout Chapter
4730
4731 Using SDCC
4732 \layout Section
4733
4734 Compiling
4735 \layout Subsection
4736
4737 Single Source File Projects
4738 \layout Standard
4739
4740 For single source file 8051 projects the process is very simple.
4741  Compile your programs with the following command 
4742 \family sans 
4743 \series bold 
4744 "sdcc sourcefile.c".
4745
4746 \family default 
4747 \series default 
4748  This will compile, assemble and link your source file.
4749  Output files are as follows:
4750 \layout Itemize
4751
4752 sourcefile.asm
4753 \begin_inset LatexCommand \index{<file>.asm}
4754
4755 \end_inset 
4756
4757  - Assembler source
4758 \begin_inset LatexCommand \index{Assembler source}
4759
4760 \end_inset 
4761
4762  file created by the compiler
4763 \layout Itemize
4764
4765 sourcefile.lst
4766 \begin_inset LatexCommand \index{<file>.lst}
4767
4768 \end_inset 
4769
4770  - Assembler listing
4771 \begin_inset LatexCommand \index{Assembler listing}
4772
4773 \end_inset 
4774
4775  file created by the Assembler
4776 \layout Itemize
4777
4778 sourcefile.rst
4779 \begin_inset LatexCommand \index{<file>.rst}
4780
4781 \end_inset 
4782
4783  - Assembler listing
4784 \begin_inset LatexCommand \index{Assembler listing}
4785
4786 \end_inset 
4787
4788  file updated with linkedit information, created by linkage editor
4789 \layout Itemize
4790
4791 sourcefile.sym
4792 \begin_inset LatexCommand \index{<file>.sym}
4793
4794 \end_inset 
4795
4796  - symbol listing
4797 \begin_inset LatexCommand \index{Symbol listing}
4798
4799 \end_inset 
4800
4801  for the sourcefile, created by the assembler
4802 \layout Itemize
4803
4804 sourcefile.rel
4805 \begin_inset LatexCommand \index{<file>.rel}
4806
4807 \end_inset 
4808
4809  or sourcefile.o
4810 \begin_inset LatexCommand \index{<file>.o}
4811
4812 \end_inset 
4813
4814  - Object file
4815 \begin_inset LatexCommand \index{Object file}
4816
4817 \end_inset 
4818
4819  created by the assembler, input to Linkage editor
4820 \layout Itemize
4821
4822 sourcefile.map
4823 \begin_inset LatexCommand \index{<file>.map}
4824
4825 \end_inset 
4826
4827  - The memory map
4828 \begin_inset LatexCommand \index{Memory map}
4829
4830 \end_inset 
4831
4832  for the load module, created by the Linker
4833 \layout Itemize
4834
4835 sourcefile.mem
4836 \begin_inset LatexCommand \index{<file>.mem}
4837
4838 \end_inset 
4839
4840  - A file with a summary of the memory usage
4841 \layout Itemize
4842
4843 sourcefile.ihx
4844 \begin_inset LatexCommand \index{<file>.ihx}
4845
4846 \end_inset 
4847
4848  - The load module in Intel hex format
4849 \begin_inset LatexCommand \index{Intel hex format}
4850
4851 \end_inset 
4852
4853  (you can select the Motorola S19 format
4854 \begin_inset LatexCommand \index{Motorola S19 format}
4855
4856 \end_inset 
4857
4858  with -
4859 \begin_inset ERT
4860 status Collapsed
4861
4862 \layout Standard
4863
4864 \backslash 
4865 /
4866 \end_inset 
4867
4868 -out-fmt-s19
4869 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4870
4871 \end_inset 
4872
4873 .
4874  If you need another format you might want to use 
4875 \family sans 
4876 \shape italic 
4877 objdump
4878 \family default 
4879 \shape default 
4880
4881 \begin_inset LatexCommand \index{objdump (tool)}
4882
4883 \end_inset 
4884
4885  or
4886 \family sans 
4887 \shape italic 
4888  srecord
4889 \family default 
4890 \shape default 
4891
4892 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4893
4894 \end_inset 
4895
4896 ).
4897  Both formats are documented in the documentation of srecord
4898 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4899
4900 \end_inset 
4901
4902
4903 \layout Itemize
4904
4905 sourcefile.adb
4906 \begin_inset LatexCommand \index{<file>.adb}
4907
4908 \end_inset 
4909
4910  - An intermediate file containing debug information needed to create the
4911  .cdb file (with -
4912 \begin_inset ERT
4913 status Open
4914
4915 \layout Standard
4916
4917 \backslash 
4918 /
4919 \end_inset 
4920
4921 -debug
4922 \begin_inset LatexCommand \index{-\/-debug}
4923
4924 \end_inset 
4925
4926
4927 \layout Itemize
4928
4929 sourcefile.cdb
4930 \begin_inset LatexCommand \index{<file>.cdb}
4931
4932 \end_inset 
4933
4934  - An optional file (with -
4935 \begin_inset ERT
4936 status Collapsed
4937
4938 \layout Standard
4939
4940 \backslash 
4941 /
4942 \end_inset 
4943
4944 -debug) containing debug information.
4945  The format is documented in cdbfileformat.pdf
4946 \layout Itemize
4947
4948 sourcefile.
4949  - (no extension)
4950 \begin_inset LatexCommand \index{<file> (no extension)}
4951
4952 \end_inset 
4953
4954  An optional AOMF or AOMF51
4955 \begin_inset LatexCommand \index{AOMF, AOMF51}
4956
4957 \end_inset 
4958
4959  file containing debug information (generated with option -
4960 \begin_inset ERT
4961 status Collapsed
4962
4963 \layout Standard
4964
4965 \backslash 
4966 /
4967 \end_inset 
4968
4969 -debug).
4970  The (Intel)
4971 \emph on 
4972  a
4973 \emph default 
4974 bsolute 
4975 \emph on 
4976 o
4977 \emph default 
4978 bject 
4979 \emph on 
4980 m
4981 \emph default 
4982 odule 
4983 \emph on 
4984 f
4985 \emph default 
4986 ormat is commonly used by third party tools (debuggers
4987 \begin_inset LatexCommand \index{Debugger}
4988
4989 \end_inset 
4990
4991 , simulators, emulators)
4992 \layout Itemize
4993
4994 sourcefile.dump*
4995 \begin_inset LatexCommand \index{<file>.dump*}
4996
4997 \end_inset 
4998
4999  - Dump file to debug the compiler it self (generated with option -
5000 \begin_inset ERT
5001 status Collapsed
5002
5003 \layout Standard
5004
5005 \backslash 
5006 /
5007 \end_inset 
5008
5009 -dumpall) (see section 
5010 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5011
5012 \end_inset 
5013
5014 \SpecialChar ~
5015  and section 
5016 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5017
5018 \end_inset 
5019
5020 \SpecialChar ~
5021
5022 \begin_inset Quotes sld
5023 \end_inset 
5024
5025 Anatomy of the compiler
5026 \begin_inset Quotes srd
5027 \end_inset 
5028
5029 ).
5030 \layout Subsection
5031
5032 Projects with Multiple Source Files
5033 \layout Standard
5034
5035 SDCC can compile only ONE file at a time.
5036  Let us for example assume that you have a project containing the following
5037  files:
5038 \newline 
5039
5040 \newline 
5041 foo1.c (contains some functions)
5042 \newline 
5043 foo2.c (contains some more functions)
5044 \newline 
5045 foomain.c (contains more functions and the function main)
5046 \newline 
5047
5048 \size footnotesize 
5049
5050 \newline 
5051
5052 \size default 
5053 The first two files will need to be compiled separately with the commands:
5054 \size footnotesize 
5055  
5056 \size default 
5057
5058 \newline 
5059
5060 \newline 
5061
5062 \family sans 
5063 \series bold 
5064 sdcc\SpecialChar ~
5065 -c\SpecialChar ~
5066 foo1.c
5067 \family default 
5068 \series default 
5069 \size footnotesize 
5070
5071 \newline 
5072
5073 \family sans 
5074 \series bold 
5075 \size default 
5076 sdcc\SpecialChar ~
5077 -c\SpecialChar ~
5078 foo2.c
5079 \family default 
5080 \series default 
5081
5082 \newline 
5083
5084 \newline 
5085 Then compile the source file containing the 
5086 \emph on 
5087 main()
5088 \emph default 
5089  function and link
5090 \begin_inset LatexCommand \index{Linker}
5091
5092 \end_inset 
5093
5094  the files together with the following command: 
5095 \newline 
5096
5097 \newline 
5098
5099 \family sans 
5100 \series bold 
5101 sdcc\SpecialChar ~
5102 foomain.c\SpecialChar ~
5103 foo1.rel\SpecialChar ~
5104 foo2.rel
5105 \family default 
5106 \series default 
5107
5108 \begin_inset LatexCommand \index{<file>.rel}
5109
5110 \end_inset 
5111
5112
5113 \newline 
5114
5115 \newline 
5116 Alternatively, 
5117 \emph on 
5118 foomain.c 
5119 \emph default 
5120 can be separately compiled as well: 
5121 \family sans 
5122 \series bold 
5123
5124 \newline 
5125
5126 \newline 
5127 sdcc\SpecialChar ~
5128 -c\SpecialChar ~
5129 foomain.c
5130 \newline 
5131 sdcc foomain.rel foo1.rel foo2.rel
5132 \newline 
5133
5134 \newline 
5135
5136 \family default 
5137 \series default 
5138 The file containing the 
5139 \emph on 
5140 main()
5141 \emph default 
5142  function
5143 \emph on 
5144  
5145 \emph default 
5146 \noun on 
5147 must
5148 \noun default 
5149  be the 
5150 \noun on 
5151 first
5152 \noun default 
5153  file specified in the command line, since the linkage editor processes
5154  file in the order they are presented to it.
5155  The linker is invoked from SDCC using a script file with extension .lnk
5156 \begin_inset LatexCommand \index{<file>.lnk}
5157
5158 \end_inset 
5159
5160 .
5161  You can view this file to troubleshoot linking problems such as those arising
5162  from missing libraries.
5163 \layout Subsection
5164
5165 Projects with Additional Libraries
5166 \begin_inset LatexCommand \index{Libraries}
5167
5168 \end_inset 
5169
5170
5171 \layout Standard
5172
5173 Some reusable routines may be compiled into a library, see the documentation
5174  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5175  for how to create a 
5176 \emph on 
5177 .lib
5178 \begin_inset LatexCommand \index{<file>.lib}
5179
5180 \end_inset 
5181
5182
5183 \emph default 
5184  library file.
5185  Libraries created in this manner can be included in the command line.
5186  Make sure you include the -L <library-path> option to tell the linker where
5187  to look for these files if they are not in the current directory.
5188  Here is an example, assuming you have the source file 
5189 \emph on 
5190 foomain.c
5191 \emph default 
5192  and a library
5193 \emph on 
5194  foolib.lib
5195 \emph default 
5196  in the directory 
5197 \emph on 
5198 mylib
5199 \emph default 
5200  (if that is not the same as your current project):
5201 \newline 
5202
5203 \newline 
5204
5205 \family sans 
5206 \series bold 
5207 sdcc foomain.c foolib.lib -L mylib
5208 \newline 
5209
5210 \newline 
5211
5212 \family default 
5213 \series default 
5214 Note here that
5215 \emph on 
5216  mylib
5217 \emph default 
5218  must be an absolute path name.
5219 \newline 
5220
5221 \newline 
5222 The most efficient way to use libraries is to keep separate modules in separate
5223  source files.
5224  The lib file now should name all the modules.rel
5225 \begin_inset LatexCommand \index{<file>.rel}
5226
5227 \end_inset 
5228
5229  files.
5230  For an example see the standard library file 
5231 \emph on 
5232 libsdcc.lib
5233 \emph default 
5234  in the directory <installdir>/share/lib/small.
5235 \layout Subsection
5236
5237 Using sdcclib to Create and Manage Libraries
5238 \begin_inset LatexCommand \index{sdcclib}
5239
5240 \end_inset 
5241
5242
5243 \layout Standard
5244
5245 Alternatively, instead of having a .rel file for each entry on the library
5246  file as described in the preceding section, sdcclib can be used to embed
5247  all the modules belonging to such library in the library file itself.
5248  This results in a larger library file, but it greatly reduces the number
5249  of disk files accessed by the linker.
5250   Additionally, the packed library file contains an index of all include
5251  modules and symbols that significantly speeds up the linking process.
5252  To display a list of options supported by sdcclib type:
5253 \newline 
5254
5255 \layout Standard
5256
5257
5258 \family sans 
5259 \series bold 
5260 sdcclib -?
5261 \begin_inset LatexCommand \index{sdcclib}
5262
5263 \end_inset 
5264
5265
5266 \newline 
5267
5268 \newline 
5269
5270 \family default 
5271 \series default 
5272 To create a new library file, start by compiling all the required modules.
5273  For example:
5274 \newline 
5275
5276 \layout Standard
5277
5278
5279 \family sans 
5280 \series bold 
5281 sdcc -c _divsint.c
5282 \layout Standard
5283
5284
5285 \family sans 
5286 \series bold 
5287 sdcc -c _divuint.c
5288 \layout Standard
5289
5290
5291 \family sans 
5292 \series bold 
5293 sdcc -c _modsint.c
5294 \layout Standard
5295
5296
5297 \family sans 
5298 \series bold 
5299 sdcc -c _moduint.c
5300 \layout Standard
5301
5302
5303 \family sans 
5304 \series bold 
5305 sdcc -c _mulint.c
5306 \newline 
5307
5308 \layout Standard
5309
5310 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5311  and _mulint.rel.
5312  The next step is to add the .rel files to the library file:
5313 \newline 
5314
5315 \layout Standard
5316
5317
5318 \family sans 
5319 \series bold 
5320 sdcclib libint.lib _divsint.rel
5321 \family default 
5322
5323 \begin_inset LatexCommand \index{sdcclib}
5324
5325 \end_inset 
5326
5327
5328 \layout Standard
5329
5330
5331 \family sans 
5332 \series bold 
5333 sdcclib libint.lib _divuint.rel
5334 \layout Standard
5335
5336
5337 \family sans 
5338 \series bold 
5339 sdcclib libint.lib _modsint.rel
5340 \layout Standard
5341
5342
5343 \family sans 
5344 \series bold 
5345 sdcclib libint.lib _moduint.rel
5346 \layout Standard
5347
5348
5349 \family sans 
5350 \series bold 
5351 sdcclib libint.lib _mulint.rel
5352 \series default 
5353
5354 \newline 
5355
5356 \layout Standard
5357
5358 If the file already exists in the library, it will be replaced.
5359  To see what modules and symbols are included in the library, options -s
5360  and -m are available.
5361  For example:
5362 \newline 
5363
5364 \newline 
5365
5366 \family sans 
5367 \series bold 
5368 sdcclib -s libint.lib
5369 \family default 
5370
5371 \begin_inset LatexCommand \index{sdcclib}
5372
5373 \end_inset 
5374
5375
5376 \newline 
5377
5378 \family typewriter 
5379 \series default 
5380 _divsint.rel:
5381 \layout Standard
5382
5383
5384 \family typewriter 
5385 __divsint_a_1_1
5386 \layout Standard
5387
5388
5389 \family typewriter 
5390 __divsint_PARM_2
5391 \layout Standard
5392
5393
5394 \family typewriter 
5395 __divsint
5396 \newline 
5397 _divuint.rel:
5398 \layout Standard
5399
5400
5401 \family typewriter 
5402 __divuint_a_1_1
5403 \layout Standard
5404
5405
5406 \family typewriter 
5407 __divuint_PARM_2
5408 \layout Standard
5409
5410
5411 \family typewriter 
5412 __divuint_reste_1_1
5413 \layout Standard
5414
5415
5416 \family typewriter 
5417 __divuint_count_1_1
5418 \layout Standard
5419
5420
5421 \family typewriter 
5422 __divuint
5423 \newline 
5424 _modsint.rel:
5425 \layout Standard
5426
5427
5428 \family typewriter 
5429 __modsint_a_1_1
5430 \layout Standard
5431
5432
5433 \family typewriter 
5434 __modsint_PARM_2
5435 \layout Standard
5436
5437
5438 \family typewriter 
5439 __modsint
5440 \newline 
5441 _moduint.rel:
5442 \layout Standard
5443
5444
5445 \family typewriter 
5446 __moduint_a_1_1
5447 \layout Standard
5448
5449
5450 \family typewriter 
5451 __moduint_PARM_2
5452 \layout Standard
5453
5454
5455 \family typewriter 
5456 __moduint_count_1_1
5457 \layout Standard
5458
5459
5460 \family typewriter 
5461 __moduint
5462 \newline 
5463 _mulint.rel:
5464 \layout Standard
5465
5466
5467 \family typewriter 
5468 __mulint_PARM_2
5469 \layout Standard
5470
5471
5472 \family typewriter 
5473 __mulint
5474 \family default 
5475 \series bold 
5476
5477 \newline 
5478
5479 \layout Standard
5480
5481 If the source files are compiled using -
5482 \begin_inset ERT
5483 status Open
5484
5485 \layout Standard
5486
5487 \backslash 
5488 /
5489 \end_inset 
5490
5491 -debug
5492 \begin_inset LatexCommand \index{-\/-debug}
5493
5494 \end_inset 
5495
5496 , the corresponding debug information file .adb will be include in the library
5497  file as well.
5498  The library files created with sdcclib are plain text files, so they can
5499  be viewed with a text editor.
5500  It is not recomended to modify a library file created with sdcclib using
5501  a text editor, as there are file indexes numbers located accross the file
5502  used by the linker to quickly locate the required module to link.
5503  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5504  it can be safely deleted, since all the information required for linking
5505  is embedded in the library file itself.
5506  Library files created using sdcclib are used as described in the preceding
5507  sections.
5508 \layout Section
5509
5510 Command Line Options
5511 \begin_inset LatexCommand \index{Command Line Options}
5512
5513 \end_inset 
5514
5515
5516 \layout Subsection
5517
5518 Processor Selection Options
5519 \begin_inset LatexCommand \index{Options processor selection}
5520
5521 \end_inset 
5522
5523
5524 \begin_inset LatexCommand \index{Processor selection options}
5525
5526 \end_inset 
5527
5528
5529 \layout List
5530 \labelwidthstring 00.00.0000
5531
5532
5533 \series bold 
5534 -mmcs51
5535 \begin_inset LatexCommand \index{-mmcs51}
5536
5537 \end_inset 
5538
5539
5540 \series default 
5541  Generate code for the Intel MCS51
5542 \begin_inset LatexCommand \index{MCS51}
5543
5544 \end_inset 
5545
5546  family of processors.
5547  This is the default processor target.
5548 \layout List
5549 \labelwidthstring 00.00.0000
5550
5551
5552 \series bold 
5553 -mds390
5554 \begin_inset LatexCommand \index{-mds390}
5555
5556 \end_inset 
5557
5558
5559 \series default 
5560  Generate code for the Dallas DS80C390
5561 \begin_inset LatexCommand \index{DS80C390}
5562
5563 \end_inset 
5564
5565  processor.
5566 \layout List
5567 \labelwidthstring 00.00.0000
5568
5569
5570 \series bold 
5571 -mds400
5572 \begin_inset LatexCommand \index{-mds400}
5573
5574 \end_inset 
5575
5576
5577 \series default 
5578  Generate code for the Dallas DS80C400
5579 \begin_inset LatexCommand \index{DS80C400}
5580
5581 \end_inset 
5582
5583  processor.
5584 \layout List
5585 \labelwidthstring 00.00.0000
5586
5587
5588 \series bold 
5589 -mhc08
5590 \begin_inset LatexCommand \index{-mhc08}
5591
5592 \end_inset 
5593
5594
5595 \series default 
5596  Generate code for the Freescale/Motorola HC08
5597 \begin_inset LatexCommand \index{HC08}
5598
5599 \end_inset 
5600
5601  family of processors.
5602 \layout List
5603 \labelwidthstring 00.00.0000
5604
5605
5606 \series bold 
5607 -mz80
5608 \begin_inset LatexCommand \index{-mz80}
5609
5610 \end_inset 
5611
5612
5613 \series default 
5614  Generate code for the Zilog Z80
5615 \begin_inset LatexCommand \index{Z80}
5616
5617 \end_inset 
5618
5619  family of processors.
5620 \layout List
5621 \labelwidthstring 00.00.0000
5622
5623
5624 \series bold 
5625 -mgbz80
5626 \begin_inset LatexCommand \index{-mgbz80}
5627
5628 \end_inset 
5629
5630
5631 \series default 
5632  Generate code for the GameBoy Z80
5633 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5634
5635 \end_inset 
5636
5637  processor (Not actively maintained).
5638 \layout List
5639 \labelwidthstring 00.00.0000
5640
5641
5642 \series bold 
5643 -mavr
5644 \begin_inset LatexCommand \index{-mavr}
5645
5646 \end_inset 
5647
5648
5649 \series default 
5650  Generate code for the Atmel AVR
5651 \begin_inset LatexCommand \index{AVR}
5652
5653 \end_inset 
5654
5655  processor (In development, not complete).
5656  AVR users should probably have a look at winavr 
5657 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5658
5659 \end_inset 
5660
5661  or 
5662 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5663
5664 \end_inset 
5665
5666 .
5667 \layout Comment
5668
5669 I think it is fair to direct users there for now.
5670  Open source is also about avoiding unnecessary work .
5671  But I didn't find the 'official' link.
5672 \layout List
5673 \labelwidthstring 00.00.0000
5674
5675
5676 \series bold 
5677 -mpic14
5678 \begin_inset LatexCommand \index{-mpic14}
5679
5680 \end_inset 
5681
5682
5683 \series default 
5684  Generate code for the Microchip PIC 14
5685 \begin_inset LatexCommand \index{PIC14}
5686
5687 \end_inset 
5688
5689 -bit processors (p16f84 and variants.
5690  In development, not complete).
5691 \layout Comment
5692
5693 p16f627 p16f628 p16f84 p16f873 p16f877?
5694 \layout List
5695 \labelwidthstring 00.00.0000
5696
5697
5698 \series bold 
5699 -mpic16
5700 \begin_inset LatexCommand \index{-mpic16}
5701
5702 \end_inset 
5703
5704
5705 \series default 
5706  Generate code for the Microchip PIC 16
5707 \begin_inset LatexCommand \index{PIC16}
5708
5709 \end_inset 
5710
5711 -bit processors (p18f452 and variants.
5712  In development, not complete).
5713 \layout List
5714 \labelwidthstring 00.00.0000
5715
5716
5717 \series bold 
5718 -mtlcs900h
5719 \series default 
5720  Generate code for the Toshiba TLCS-900H
5721 \begin_inset LatexCommand \index{TLCS-900H}
5722
5723 \end_inset 
5724
5725  processor (Not maintained, not complete).
5726 \layout List
5727 \labelwidthstring 00.00.0000
5728
5729
5730 \series bold 
5731 -mxa51
5732 \begin_inset LatexCommand \index{-mxa51}
5733
5734 \end_inset 
5735
5736
5737 \series default 
5738  Generate code for the Phillips XA51
5739 \begin_inset LatexCommand \index{XA51}
5740
5741 \end_inset 
5742
5743  processor (Not maintained, not complete).
5744 \layout Subsection
5745
5746 Preprocessor Options
5747 \begin_inset LatexCommand \index{Options preprocessor}
5748
5749 \end_inset 
5750
5751
5752 \begin_inset LatexCommand \index{Preprocessor options}
5753
5754 \end_inset 
5755
5756
5757 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5758
5759 \end_inset 
5760
5761
5762 \layout List
5763 \labelwidthstring 00.00.0000
5764
5765
5766 \series bold 
5767 -I<path>
5768 \begin_inset LatexCommand \index{-I<path>}
5769
5770 \end_inset 
5771
5772
5773 \series default 
5774  The additional location where the pre processor will look for <..h> or 
5775 \begin_inset Quotes eld
5776 \end_inset 
5777
5778 ..h
5779 \begin_inset Quotes erd
5780 \end_inset 
5781
5782  files.
5783 \layout List
5784 \labelwidthstring 00.00.0000
5785
5786
5787 \series bold 
5788 -D<macro[=value]>
5789 \begin_inset LatexCommand \index{-D<macro[=value]>}
5790
5791 \end_inset 
5792
5793
5794 \series default 
5795  Command line definition of macros.
5796  Passed to the preprocessor.
5797 \layout List
5798 \labelwidthstring 00.00.0000
5799
5800
5801 \series bold 
5802 -M
5803 \begin_inset LatexCommand \index{-M}
5804
5805 \end_inset 
5806
5807
5808 \series default 
5809  Tell the preprocessor to output a rule suitable for make describing the
5810  dependencies of each object file.
5811  For each source file, the preprocessor outputs one make-rule whose target
5812  is the object file name for that source file and whose dependencies are
5813  all the files `#include'd in it.
5814  This rule may be a single line or may be continued with `
5815 \backslash 
5816 '-newline if it is long.
5817  The list of rules is printed on standard output instead of the preprocessed
5818  C program.
5819  `-M' implies `-E
5820 \begin_inset LatexCommand \index{-E}
5821
5822 \end_inset 
5823
5824 '.
5825 \layout List
5826 \labelwidthstring 00.00.0000
5827
5828
5829 \series bold 
5830 -C
5831 \begin_inset LatexCommand \index{-C}
5832
5833 \end_inset 
5834
5835
5836 \series default 
5837  Tell the preprocessor not to discard comments.
5838  Used with the `-E' option.
5839 \layout List
5840 \labelwidthstring 00.00.0000
5841
5842
5843 \series bold 
5844 -MM
5845 \begin_inset LatexCommand \index{-MM}
5846
5847 \end_inset 
5848
5849
5850 \size large 
5851 \bar under 
5852  
5853 \series default 
5854 \size default 
5855 \bar default 
5856 Like `-M' but the output mentions only the user header files included with
5857  `#include 
5858 \begin_inset Quotes eld
5859 \end_inset 
5860
5861 file"'.
5862  System header files included with `#include <file>' are omitted.
5863 \layout List
5864 \labelwidthstring 00.00.0000
5865
5866
5867 \series bold 
5868 -Aquestion(answer)
5869 \begin_inset LatexCommand \index{-Aquestion(answer)}
5870
5871 \end_inset 
5872
5873
5874 \series default 
5875  Assert the answer answer for question, in case it is tested with a preprocessor
5876  conditional such as `#if #question(answer)'.
5877  `-A-' disables the standard assertions that normally describe the target
5878  machine.
5879 \layout List
5880 \labelwidthstring 00.00.0000
5881
5882
5883 \series bold 
5884 -Umacro
5885 \begin_inset LatexCommand \index{-Umacro}
5886
5887 \end_inset 
5888
5889
5890 \series default 
5891  Undefine macro macro.
5892  `-U' options are evaluated after all `-D' options, but before any `-include'
5893  and `-imacros' options.
5894 \layout List
5895 \labelwidthstring 00.00.0000
5896
5897
5898 \series bold 
5899 -dM
5900 \begin_inset LatexCommand \index{-dM}
5901
5902 \end_inset 
5903
5904
5905 \series default 
5906  Tell the preprocessor to output only a list of the macro definitions that
5907  are in effect at the end of preprocessing.
5908  Used with the `-E' option.
5909 \layout List
5910 \labelwidthstring 00.00.0000
5911
5912
5913 \series bold 
5914 -dD
5915 \begin_inset LatexCommand \index{-dD}
5916
5917 \end_inset 
5918
5919
5920 \series default 
5921  Tell the preprocessor to pass all macro definitions into the output, in
5922  their proper sequence in the rest of the output.
5923 \layout List
5924 \labelwidthstring 00.00.0000
5925
5926
5927 \series bold 
5928 -dN
5929 \begin_inset LatexCommand \index{-dN}
5930
5931 \end_inset 
5932
5933
5934 \size large 
5935 \bar under 
5936  
5937 \series default 
5938 \size default 
5939 \bar default 
5940 Like `-dD' except that the macro arguments and contents are omitted.
5941  Only `#define name' is included in the output.
5942 \layout List
5943 \labelwidthstring 00.00.0000
5944
5945
5946 \series bold 
5947 -Wp\SpecialChar ~
5948 preprocessorOption[,preprocessorOption]
5949 \series default 
5950
5951 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5952
5953 \end_inset 
5954
5955 ...
5956  Pass the preprocessorOption to the preprocessor 
5957 \family typewriter 
5958 sdcpp
5959 \family default 
5960
5961 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5962
5963 \end_inset 
5964
5965 .
5966  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5967  Collection (gcc), if you need more dedicated options please refer to the
5968  documentation at 
5969 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5970
5971 \end_inset 
5972
5973 .
5974 \layout Subsection
5975
5976 Linker Options
5977 \begin_inset LatexCommand \index{Options linker}
5978
5979 \end_inset 
5980
5981
5982 \begin_inset LatexCommand \index{Linker options}
5983
5984 \end_inset 
5985
5986
5987 \layout List
5988 \labelwidthstring 00.00.0000
5989
5990
5991 \series bold 
5992 -L\SpecialChar ~
5993 -
5994 \series default 
5995
5996 \begin_inset ERT
5997 status Collapsed
5998
5999 \layout Standard
6000
6001 \backslash 
6002 /
6003 \end_inset 
6004
6005
6006 \series bold 
6007 -lib-path
6008 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6009
6010 \end_inset 
6011
6012
6013 \begin_inset LatexCommand \index{-L -\/-lib-path}
6014
6015 \end_inset 
6016
6017
6018 \series default 
6019 \SpecialChar ~
6020 <absolute path to additional libraries> This option is passed to the linkage
6021  editor's additional libraries
6022 \begin_inset LatexCommand \index{Libraries}
6023
6024 \end_inset 
6025
6026  search path.
6027  The path name must be absolute.
6028  Additional library files may be specified in the command line.
6029  See section Compiling programs for more details.
6030 \layout List
6031 \labelwidthstring 00.00.0000
6032
6033
6034 \series bold 
6035 -
6036 \begin_inset ERT
6037 status Collapsed
6038
6039 \layout Standard
6040
6041 \backslash 
6042 /
6043 \end_inset 
6044
6045 -xram-loc
6046 \series default 
6047
6048 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6049
6050 \end_inset 
6051
6052 \SpecialChar ~
6053 <Value> The start location of the external ram
6054 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6055
6056 \end_inset 
6057
6058 , default value is 0.
6059  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6060 \begin_inset ERT
6061 status Collapsed
6062
6063 \layout Standard
6064
6065 \backslash 
6066 /
6067 \end_inset 
6068
6069 -xram-loc 0x8000 or -
6070 \begin_inset ERT
6071 status Collapsed
6072
6073 \layout Standard
6074
6075 \backslash 
6076 /
6077 \end_inset 
6078
6079 -xram-loc 32768.
6080 \layout List
6081 \labelwidthstring 00.00.0000
6082
6083
6084 \series bold 
6085 -
6086 \begin_inset ERT
6087 status Collapsed
6088
6089 \layout Standard
6090
6091 \backslash 
6092 /
6093 \end_inset 
6094
6095 -code-loc
6096 \series default 
6097
6098 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6099
6100 \end_inset 
6101
6102 \SpecialChar ~
6103 <Value> The start location of the code
6104 \begin_inset LatexCommand \index{code}
6105
6106 \end_inset 
6107
6108  segment, default value 0.
6109  Note when this option is used the interrupt vector table is also relocated
6110  to the given address.
6111  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6112 \begin_inset ERT
6113 status Collapsed
6114
6115 \layout Standard
6116
6117 \backslash 
6118 /
6119 \end_inset 
6120
6121 -code-loc 0x8000 or -
6122 \begin_inset ERT
6123 status Collapsed
6124
6125 \layout Standard
6126
6127 \backslash 
6128 /
6129 \end_inset 
6130
6131 -code-loc 32768.
6132 \layout List
6133 \labelwidthstring 00.00.0000
6134
6135
6136 \series bold 
6137 -
6138 \begin_inset ERT
6139 status Collapsed
6140
6141 \layout Standard
6142
6143 \backslash 
6144 /
6145 \end_inset 
6146
6147 -stack-loc
6148 \series default 
6149
6150 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6151
6152 \end_inset 
6153
6154 \SpecialChar ~
6155 <Value> By default the stack
6156 \begin_inset LatexCommand \index{stack}
6157
6158 \end_inset 
6159
6160  is placed after the data segment.
6161  Using this option the stack can be placed anywhere in the internal memory
6162  space of the 8051.
6163  The value entered can be in Hexadecimal or Decimal format, e.g.
6164  -
6165 \begin_inset ERT
6166 status Collapsed
6167
6168 \layout Standard
6169
6170 \backslash 
6171 /
6172 \end_inset 
6173
6174 -stack-loc 0x20 or -
6175 \begin_inset ERT
6176 status Collapsed
6177
6178 \layout Standard
6179
6180 \backslash 
6181 /
6182 \end_inset 
6183
6184 -stack-loc 32.
6185  Since the sp register is incremented before a push or call, the initial
6186  sp will be set to one byte prior the provided value.
6187  The provided value should not overlap any other memory areas such as used
6188  register banks or the data segment and with enough space for the current
6189  application.
6190  The 
6191 \series bold 
6192 -
6193 \begin_inset ERT
6194 status Collapsed
6195
6196 \layout Standard
6197
6198 \backslash 
6199 /
6200 \end_inset 
6201
6202 -pack-iram
6203 \series default 
6204 \SpecialChar ~
6205
6206 \begin_inset LatexCommand \index{-\/-pack-iram}
6207
6208 \end_inset 
6209
6210  option (which is now a default setting) will override this setting, so
6211  you should also specify the 
6212 \series bold 
6213 -
6214 \begin_inset ERT
6215 status Collapsed
6216
6217 \layout Standard
6218
6219 \backslash 
6220 /
6221 \end_inset 
6222
6223 -no-pack-iram
6224 \series default 
6225 \SpecialChar ~
6226
6227 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6228
6229 \end_inset 
6230
6231  option if you need to manually place the stack.
6232 \layout List
6233 \labelwidthstring 00.00.0000
6234
6235
6236 \series bold 
6237 -
6238 \begin_inset ERT
6239 status Collapsed
6240
6241 \layout Standard
6242
6243 \backslash 
6244 /
6245 \end_inset 
6246
6247 -xstack-loc
6248 \series default 
6249
6250 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6251
6252 \end_inset 
6253
6254 \SpecialChar ~
6255 <Value> By default the external stack
6256 \begin_inset LatexCommand \index{xstack}
6257
6258 \end_inset 
6259
6260  is placed after the pdata segment.
6261  Using this option the xstack can be placed anywhere in the external memory
6262  space of the 8051.
6263  The value entered can be in Hexadecimal or Decimal format, e.g.
6264  -
6265 \begin_inset ERT
6266 status Collapsed
6267
6268 \layout Standard
6269
6270 \backslash 
6271 /
6272 \end_inset 
6273
6274 -xstack-loc 0x8000 or -
6275 \begin_inset ERT
6276 status Collapsed
6277
6278 \layout Standard
6279
6280 \backslash 
6281 /
6282 \end_inset 
6283
6284 -stack-loc 32768.
6285  The provided value should not overlap any other memory areas such as the
6286  pdata or xdata segment and with enough space for the current application.
6287 \layout List
6288 \labelwidthstring 00.00.0000
6289
6290
6291 \series bold 
6292 -
6293 \begin_inset ERT
6294 status Collapsed
6295
6296 \layout Standard
6297
6298 \backslash 
6299 /
6300 \end_inset 
6301
6302 -data-loc
6303 \series default 
6304
6305 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6306
6307 \end_inset 
6308
6309 \SpecialChar ~
6310 <Value> The start location of the internal ram data
6311 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6312
6313 \end_inset 
6314
6315  segment.
6316  The value entered can be in Hexadecimal or Decimal format, eg.
6317  -
6318 \begin_inset ERT
6319 status Collapsed
6320
6321 \layout Standard
6322
6323 \backslash 
6324 /
6325 \end_inset 
6326
6327 -data-loc 0x20 or -
6328 \begin_inset ERT
6329 status Collapsed
6330
6331 \layout Standard
6332
6333 \backslash 
6334 /
6335 \end_inset 
6336
6337 -data-loc 32.
6338  (By default, the start location of the internal ram data segment  is set
6339  as low as possible in memory, taking into account the used register banks
6340  and the bit segment at address 0x20.
6341  For example if register banks 0 and 1 are used without bit variables, the
6342  data segment will be set, if -
6343 \begin_inset ERT
6344 status Collapsed
6345
6346 \layout Standard
6347
6348 \backslash 
6349 /
6350 \end_inset 
6351
6352 -data-loc is not used, to location 0x10.)
6353 \layout List
6354 \labelwidthstring 00.00.0000
6355
6356
6357 \series bold 
6358 -
6359 \begin_inset ERT
6360 status Collapsed
6361
6362 \layout Standard
6363
6364 \backslash 
6365 /
6366 \end_inset 
6367
6368 -idata-loc
6369 \series default 
6370
6371 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6372
6373 \end_inset 
6374
6375 \SpecialChar ~
6376 <Value> The start location of the indirectly addressable internal ram
6377 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6378
6379 \end_inset 
6380
6381  of the 8051, default value is 0x80.
6382  The value entered can be in Hexadecimal or Decimal format, eg.
6383  -
6384 \begin_inset ERT
6385 status Collapsed
6386
6387 \layout Standard
6388
6389 \backslash 
6390 /
6391 \end_inset 
6392
6393 -idata-loc 0x88 or -
6394 \begin_inset ERT
6395 status Collapsed
6396
6397 \layout Standard
6398
6399 \backslash 
6400 /
6401 \end_inset 
6402
6403 -idata-loc 136.
6404 \layout List
6405 \labelwidthstring 00.00.0000
6406
6407
6408 \series bold 
6409 -
6410 \begin_inset ERT
6411 status Collapsed
6412
6413 \layout Standard
6414
6415 \backslash 
6416 /
6417 \end_inset 
6418
6419 -bit-loc
6420 \series default 
6421 \SpecialChar ~
6422 <Value> The start location of the bit
6423 \begin_inset LatexCommand \index{bit}
6424
6425 \end_inset 
6426
6427  addressable internal ram of the 8051.
6428  This is 
6429 \emph on 
6430 not
6431 \emph default 
6432  implemented yet.
6433  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6434 -bBSEG=<Value>.
6435 \layout List
6436 \labelwidthstring 00.00.0000
6437
6438
6439 \series bold 
6440 -
6441 \begin_inset ERT
6442 status Collapsed
6443
6444 \layout Standard
6445
6446 \backslash 
6447 /
6448 \end_inset 
6449
6450 -out-fmt-ihx
6451 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6452
6453 \end_inset 
6454
6455
6456 \bar under 
6457  
6458 \series default 
6459 \bar default 
6460 The linker output (final object code) is in Intel Hex format.
6461 \begin_inset LatexCommand \index{Intel hex format}
6462
6463 \end_inset 
6464
6465  This is the default option.
6466  The format itself is documented in the documentation of srecord
6467 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6468
6469 \end_inset 
6470
6471 .
6472 \layout List
6473 \labelwidthstring 00.00.0000
6474
6475
6476 \series bold 
6477 -
6478 \begin_inset ERT
6479 status Collapsed
6480
6481 \layout Standard
6482
6483 \backslash 
6484 /
6485 \end_inset 
6486
6487 -out-fmt-s19
6488 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6489
6490 \end_inset 
6491
6492
6493 \bar under 
6494  
6495 \series default 
6496 \bar default 
6497 The linker output (final object code) is in Motorola S19 format
6498 \begin_inset LatexCommand \index{Motorola S19 format}
6499
6500 \end_inset 
6501
6502 .
6503  The format itself is documented in the documentation of srecord.
6504 \layout List
6505 \labelwidthstring 00.00.0000
6506
6507
6508 \series bold 
6509 -
6510 \begin_inset ERT
6511 status Collapsed
6512
6513 \layout Standard
6514
6515 \backslash 
6516 /
6517 \end_inset 
6518
6519 -out-fmt-elf
6520 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6521
6522 \end_inset 
6523
6524
6525 \bar under 
6526  
6527 \series default 
6528 \bar default 
6529 The linker output (final object code) is in ELF format
6530 \begin_inset LatexCommand \index{ELF format}
6531
6532 \end_inset 
6533
6534 .
6535  (Currently only supported for the HC08 processors)
6536 \layout List
6537 \labelwidthstring 00.00.0000
6538
6539
6540 \series bold 
6541 -Wl\SpecialChar ~
6542 linkOption[,linkOption]
6543 \series default 
6544
6545 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6546
6547 \end_inset 
6548
6549 ...
6550  Pass the linkOption to the linker.
6551  See file sdcc/as/doc/asxhtm.html for more on linker options.
6552 \layout Subsection
6553
6554 MCS51 Options
6555 \begin_inset LatexCommand \index{Options MCS51}
6556
6557 \end_inset 
6558
6559
6560 \begin_inset LatexCommand \index{MCS51 options}
6561
6562 \end_inset 
6563
6564
6565 \layout List
6566 \labelwidthstring 00.00.0000
6567
6568
6569 \series bold 
6570 -
6571 \begin_inset ERT
6572 status Collapsed
6573
6574 \layout Standard
6575
6576 \backslash 
6577 /
6578 \end_inset 
6579
6580 -model-small
6581 \begin_inset LatexCommand \index{-\/-model-small}
6582
6583 \end_inset 
6584
6585
6586 \series default 
6587 \size large 
6588 \emph on 
6589  
6590 \size default 
6591 \emph default 
6592 Generate code for Small Model programs, see section Memory Models for more
6593  details.
6594  This is the default model.
6595 \layout List
6596 \labelwidthstring 00.00.0000
6597
6598
6599 \series bold 
6600 -
6601 \begin_inset ERT
6602 status Collapsed
6603
6604 \layout Standard
6605
6606 \backslash 
6607 /
6608 \end_inset 
6609
6610 -model-medium
6611 \begin_inset LatexCommand \index{-\/-model-medium}
6612
6613 \end_inset 
6614
6615
6616 \series default 
6617  Generate code for Medium model programs, see section Memory Models for
6618  more details.
6619  If this option is used all source files in the project have to be compiled
6620  with this option.
6621  It must also be used when invoking the linker.
6622 \layout List
6623 \labelwidthstring 00.00.0000
6624
6625
6626 \series bold 
6627 -
6628 \begin_inset ERT
6629 status Collapsed
6630
6631 \layout Standard
6632
6633 \backslash 
6634 /
6635 \end_inset 
6636
6637 -model-large
6638 \begin_inset LatexCommand \index{-\/-model-large}
6639
6640 \end_inset 
6641
6642
6643 \series default 
6644  Generate code for Large model programs, see section Memory Models for more
6645  details.
6646  If this option is used all source files in the project have to be compiled
6647  with this option.
6648  It must also be used when invoking the linker.
6649 \layout List
6650 \labelwidthstring 00.00.0000
6651
6652
6653 \series bold 
6654 -
6655 \begin_inset ERT
6656 status Collapsed
6657
6658 \layout Standard
6659
6660 \backslash 
6661 /
6662 \end_inset 
6663
6664 -xstack
6665 \begin_inset LatexCommand \index{-\/-xstack}
6666
6667 \end_inset 
6668
6669
6670 \series default 
6671  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
6672  variables and passing parameters.
6673  See section 
6674 \begin_inset LatexCommand \ref{sub:External-Stack}
6675
6676 \end_inset 
6677
6678 \SpecialChar ~
6679  External Stack for more details.
6680 \layout List
6681 \labelwidthstring 00.00.0000
6682
6683
6684 \series bold 
6685 -
6686 \begin_inset ERT
6687 status Collapsed
6688
6689 \layout Standard
6690
6691 \backslash 
6692 /
6693 \end_inset 
6694
6695 -iram-size
6696 \series default 
6697 \SpecialChar ~
6698 <Value>
6699 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6700
6701 \end_inset 
6702
6703  Causes the linker to check if the internal ram usage is within limits of
6704  the given value.
6705 \layout List
6706 \labelwidthstring 00.00.0000
6707
6708
6709 \series bold 
6710 -
6711 \begin_inset ERT
6712 status Collapsed
6713
6714 \layout Standard
6715
6716 \backslash 
6717 /
6718 \end_inset 
6719
6720 -xram-size
6721 \series default 
6722 \SpecialChar ~
6723 <Value>
6724 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6725
6726 \end_inset 
6727
6728  Causes the linker to check if the external ram usage is within limits of
6729  the given value.
6730 \layout List
6731 \labelwidthstring 00.00.0000
6732
6733
6734 \series bold 
6735 -
6736 \begin_inset ERT
6737 status Collapsed
6738
6739 \layout Standard
6740
6741 \backslash 
6742 /
6743 \end_inset 
6744
6745 -code-size
6746 \series default 
6747 \SpecialChar ~
6748 <Value>
6749 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6750
6751 \end_inset 
6752
6753  Causes the linker to check if the code memory usage is within limits of
6754  the given value.
6755 \layout List
6756 \labelwidthstring 00.00.0000
6757
6758
6759 \series bold 
6760 -
6761 \begin_inset ERT
6762 status Collapsed
6763
6764 \layout Standard
6765
6766 \backslash 
6767 /
6768 \end_inset 
6769
6770 -stack-size
6771 \series default 
6772 \SpecialChar ~
6773 <Value>
6774 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6775
6776 \end_inset 
6777
6778  Causes the linker to check if there is at minimum <Value> bytes for stack.
6779 \layout List
6780 \labelwidthstring 00.00.0000
6781
6782
6783 \series bold 
6784 -
6785 \begin_inset ERT
6786 status Collapsed
6787
6788 \layout Standard
6789
6790 \backslash 
6791 /
6792 \end_inset 
6793
6794 -pack-iram
6795 \series default 
6796 \SpecialChar ~
6797
6798 \begin_inset LatexCommand \index{-\/-pack-iram}
6799
6800 \end_inset 
6801
6802  Causes the linker to use unused register banks for data variables and pack
6803  data, idata and stack together.
6804  This is the default now.
6805 \layout List
6806 \labelwidthstring 00.00.0000
6807
6808
6809 \series bold 
6810 -
6811 \begin_inset ERT
6812 status Collapsed
6813
6814 \layout Standard
6815
6816 \backslash 
6817 /
6818 \end_inset 
6819
6820 -no-pack-iram
6821 \series default 
6822 \SpecialChar ~
6823
6824 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6825
6826 \end_inset 
6827
6828  Causes the linker to use old style for allocating memory areas.
6829 \layout Subsection
6830
6831 DS390 / DS400 Options
6832 \begin_inset LatexCommand \index{Options DS390}
6833
6834 \end_inset 
6835
6836
6837 \begin_inset LatexCommand \index{DS390 options}
6838
6839 \end_inset 
6840
6841
6842 \layout List
6843 \labelwidthstring 00.00.0000
6844
6845
6846 \series bold 
6847 -
6848 \begin_inset ERT
6849 status Collapsed
6850
6851 \layout Standard
6852
6853 \backslash 
6854 /
6855 \end_inset 
6856
6857 -model-flat24
6858 \series default 
6859
6860 \begin_inset LatexCommand \index{-\/-model-flat24}
6861
6862 \end_inset 
6863
6864
6865 \size large 
6866 \emph on 
6867  
6868 \size default 
6869 \emph default 
6870 Generate 24-bit flat mode code.
6871  This is the one and only that the ds390 code generator supports right now
6872  and is default when using 
6873 \emph on 
6874 -mds390
6875 \emph default 
6876 .
6877  See section Memory Models for more details.
6878 \layout List
6879 \labelwidthstring 00.00.0000
6880
6881
6882 \series bold 
6883 -
6884 \begin_inset ERT
6885 status Collapsed
6886
6887 \layout Standard
6888
6889 \backslash 
6890 /
6891 \end_inset 
6892
6893 -protect-sp-update
6894 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6895
6896 \end_inset 
6897
6898
6899 \series default 
6900  disable interrupts during ESP:SP updates.
6901 \layout List
6902 \labelwidthstring 00.00.0000
6903
6904
6905 \series bold 
6906 -
6907 \begin_inset ERT
6908 status Collapsed
6909
6910 \layout Standard
6911
6912 \backslash 
6913 /
6914 \end_inset 
6915
6916 -stack-10bit
6917 \series default 
6918
6919 \begin_inset LatexCommand \index{-\/-stack-10bit}
6920
6921 \end_inset 
6922
6923  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6924  This is the one and only that the ds390 code generator supports right now
6925  and is default when using 
6926 \emph on 
6927 -mds390
6928 \emph default 
6929 .
6930  In this mode, the stack is located in the lower 1K of the internal RAM,
6931  which is mapped to 0x400000.
6932  Note that the support is incomplete, since it still uses a single byte
6933  as the stack pointer.
6934  This means that only the lower 256 bytes of the potential 1K stack space
6935  will actually be used.
6936  However, this does allow you to reclaim the precious 256 bytes of low RAM
6937  for use for the DATA and IDATA segments.
6938  The compiler will not generate any code to put the processor into 10 bit
6939  stack mode.
6940  It is important to ensure that the processor is in this mode before calling
6941  any re-entrant functions compiled with this option.
6942  In principle, this should work with the 
6943 \emph on 
6944 -
6945 \begin_inset ERT
6946 status Collapsed
6947
6948 \layout Standard
6949
6950 \backslash 
6951 /
6952 \end_inset 
6953
6954 -stack-auto
6955 \begin_inset LatexCommand \index{-\/-stack-auto}
6956
6957 \end_inset 
6958
6959
6960 \emph default 
6961  option, but that has not been tested.
6962  It is incompatible with the 
6963 \emph on 
6964 -
6965 \begin_inset ERT
6966 status Collapsed
6967
6968 \layout Standard
6969
6970 \backslash 
6971 /
6972 \end_inset 
6973
6974 -xstack
6975 \begin_inset LatexCommand \index{-\/-xstack}
6976
6977 \end_inset 
6978
6979
6980 \emph default 
6981  option.
6982  It also only makes sense if the processor is in 24 bit contiguous addressing
6983  mode (see the 
6984 \emph on 
6985 -
6986 \begin_inset ERT
6987 status Collapsed
6988
6989 \layout Standard
6990
6991 \backslash 
6992 /
6993 \end_inset 
6994
6995 -model-flat24 option
6996 \emph default 
6997 ).
6998 \layout List
6999 \labelwidthstring 00.00.0000
7000
7001
7002 \series bold 
7003 -
7004 \begin_inset ERT
7005 status Collapsed
7006
7007 \layout Standard
7008
7009 \backslash 
7010 /
7011 \end_inset 
7012
7013 -stack-probe
7014 \begin_inset LatexCommand \index{-\/-stack-probe}
7015
7016 \end_inset 
7017
7018
7019 \series default 
7020  insert call to function __stack_probe at each function prologue.
7021 \layout List
7022 \labelwidthstring 00.00.0000
7023
7024
7025 \series bold 
7026 -
7027 \begin_inset ERT
7028 status Collapsed
7029
7030 \layout Standard
7031
7032 \backslash 
7033 /
7034 \end_inset 
7035
7036 -tini-libid
7037 \begin_inset LatexCommand \index{-\/-tini-libid}
7038
7039 \end_inset 
7040
7041
7042 \series default 
7043  <nnnn> LibraryID used in -mTININative.
7044  
7045 \layout List
7046 \labelwidthstring 00.00.0000
7047
7048
7049 \series bold 
7050 -
7051 \begin_inset ERT
7052 status Collapsed
7053
7054 \layout Standard
7055
7056 \backslash 
7057 /
7058 \end_inset 
7059
7060 -use-accelerator
7061 \begin_inset LatexCommand \index{-\/-use-accelerator}
7062
7063 \end_inset 
7064
7065
7066 \series default 
7067  generate code for DS390 Arithmetic Accelerator.
7068  
7069 \layout Subsection
7070
7071 Z80 Options
7072 \begin_inset LatexCommand \index{Options Z80}
7073
7074 \end_inset 
7075
7076
7077 \begin_inset LatexCommand \index{Z80 options}
7078
7079 \end_inset 
7080
7081
7082 \layout List
7083 \labelwidthstring 00.00.0000
7084
7085
7086 \series bold 
7087 -
7088 \begin_inset ERT
7089 status Collapsed
7090
7091 \layout Standard
7092
7093 \backslash 
7094 /
7095 \end_inset 
7096
7097 -callee-saves-bc
7098 \series default 
7099
7100 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
7101
7102 \end_inset 
7103
7104
7105 \size large 
7106 \emph on 
7107  
7108 \size default 
7109 \emph default 
7110 Force a called function to always save BC.
7111 \layout List
7112 \labelwidthstring 00.00.0000
7113
7114
7115 \series bold 
7116 -
7117 \begin_inset ERT
7118 status Collapsed
7119
7120 \layout Standard
7121
7122 \backslash 
7123 /
7124 \end_inset 
7125
7126 -no-std-crt0
7127 \series default 
7128
7129 \begin_inset LatexCommand \index{-\/-no-std-crt0}
7130
7131 \end_inset 
7132
7133  When linking, skip the standard crt0.o object file.
7134  You must provide your own crt0.o for your system when linking.
7135  
7136 \layout Subsection
7137
7138 Optimization Options
7139 \begin_inset LatexCommand \index{Options optimization}
7140
7141 \end_inset 
7142
7143
7144 \begin_inset LatexCommand \index{Optimization options}
7145
7146 \end_inset 
7147
7148
7149 \layout List
7150 \labelwidthstring 00.00.0000
7151
7152
7153 \series bold 
7154 -
7155 \begin_inset ERT
7156 status Collapsed
7157
7158 \layout Standard
7159
7160 \backslash 
7161 /
7162 \end_inset 
7163
7164 -nogcse
7165 \begin_inset LatexCommand \index{-\/-nogcse}
7166
7167 \end_inset 
7168
7169
7170 \series default 
7171  Will not do global subexpression elimination, this option may be used when
7172  the compiler creates undesirably large stack/data spaces to store compiler
7173  temporaries (
7174 \emph on 
7175 s
7176 \emph default 
7177 pill 
7178 \emph on 
7179 loc
7180 \emph default 
7181 ations, sloc
7182 \begin_inset LatexCommand \index{sloc (spill location)}
7183
7184 \end_inset 
7185
7186 ).
7187  A warning message will be generated when this happens and the compiler
7188  will indicate the number of extra bytes it allocated.
7189  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7190 nogcse
7191 \begin_inset LatexCommand \index{\#pragma nogcse}
7192
7193 \end_inset 
7194
7195  can be used to turn off global subexpression elimination
7196 \begin_inset LatexCommand \index{Subexpression elimination}
7197
7198 \end_inset 
7199
7200  for a given function only.
7201 \layout List
7202 \labelwidthstring 00.00.0000
7203
7204
7205 \series bold 
7206 -
7207 \begin_inset ERT
7208 status Collapsed
7209
7210 \layout Standard
7211
7212 \backslash 
7213 /
7214 \end_inset 
7215
7216 -noinvariant
7217 \begin_inset LatexCommand \index{-\/-noinvariant}
7218
7219 \end_inset 
7220
7221
7222 \series default 
7223  Will not do loop invariant optimizations, this may be turned off for reasons
7224  explained for the previous option.
7225  For more details of loop optimizations performed see Loop Invariants in
7226  section 
7227 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7228
7229 \end_inset 
7230
7231 .
7232  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7233 noinvariant
7234 \begin_inset LatexCommand \index{\#pragma noinvariant}
7235
7236 \end_inset 
7237
7238  can be used to turn off invariant optimizations for a given function only.
7239 \layout List
7240 \labelwidthstring 00.00.0000
7241
7242
7243 \series bold 
7244 -
7245 \begin_inset ERT
7246 status Collapsed
7247
7248 \layout Standard
7249
7250 \backslash 
7251 /
7252 \end_inset 
7253
7254 -noinduction
7255 \begin_inset LatexCommand \index{-\/-noinduction}
7256
7257 \end_inset 
7258
7259
7260 \series default 
7261  Will not do loop induction optimizations, see section strength reduction
7262  for more details.
7263  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7264 noinduction
7265 \begin_inset LatexCommand \index{\#pragma noinduction}
7266
7267 \end_inset 
7268
7269  can be used to turn off induction optimizations for a given function only.
7270 \layout List
7271 \labelwidthstring 00.00.0000
7272
7273
7274 \series bold 
7275 -
7276 \begin_inset ERT
7277 status Collapsed
7278
7279 \layout Standard
7280
7281 \backslash 
7282 /
7283 \end_inset 
7284
7285 -nojtbound
7286 \begin_inset LatexCommand \index{-\/-nojtbound}
7287
7288 \end_inset 
7289
7290
7291 \size large 
7292 \bar under 
7293  
7294 \series default 
7295 \size default 
7296 \bar default 
7297  Will not generate boundary condition check when switch statements
7298 \begin_inset LatexCommand \index{switch statement}
7299
7300 \end_inset 
7301
7302  are implemented using jump-tables.
7303  See section 
7304 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7305
7306 \end_inset 
7307
7308 \SpecialChar ~
7309 Switch Statements for more details.
7310  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7311 nojtbound
7312 \begin_inset LatexCommand \index{\#pragma nojtbound}
7313
7314 \end_inset 
7315
7316  can be used to turn off boundary checking for jump tables for a given function
7317  only.
7318 \layout List
7319 \labelwidthstring 00.00.0000
7320
7321
7322 \series bold 
7323 -
7324 \begin_inset ERT
7325 status Collapsed
7326
7327 \layout Standard
7328
7329 \backslash 
7330 /
7331 \end_inset 
7332
7333 -noloopreverse
7334 \begin_inset LatexCommand \index{-\/-noloopreverse}
7335
7336 \end_inset 
7337
7338
7339 \series default 
7340 \size large 
7341  
7342 \size default 
7343 Will not do loop reversal 
7344 \begin_inset LatexCommand \index{Loop reversing}
7345
7346 \end_inset 
7347
7348 optimization.
7349 \layout List
7350 \labelwidthstring 00.00.0000
7351
7352 -
7353 \begin_inset ERT
7354 status Collapsed
7355
7356 \layout Standard
7357
7358 \backslash 
7359 /
7360 \end_inset 
7361
7362 -
7363 \series bold 
7364 nolabelopt
7365 \series default 
7366  
7367 \begin_inset LatexCommand \index{-\/-nolabelopt }
7368
7369 \end_inset 
7370
7371 Will not optimize labels (makes the dumpfiles more readable).
7372 \layout List
7373 \labelwidthstring 00.00.0000
7374
7375
7376 \series bold 
7377 -
7378 \begin_inset ERT
7379 status Collapsed
7380
7381 \layout Standard
7382
7383 \backslash 
7384 /
7385 \end_inset 
7386
7387 -no-xinit-opt
7388 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7389
7390 \end_inset 
7391
7392
7393 \series default 
7394  Will not memcpy initialized data from code space into xdata space.
7395  This saves a few bytes in code space if you don't have initialized data
7396 \begin_inset LatexCommand \index{Variable initialization}
7397
7398 \end_inset 
7399
7400 .
7401 \layout List
7402 \labelwidthstring 00.00.0000
7403
7404
7405 \series bold 
7406 -
7407 \begin_inset ERT
7408 status Collapsed
7409
7410 \layout Standard
7411
7412 \backslash 
7413 /
7414 \end_inset 
7415
7416 -nooverlay
7417 \begin_inset LatexCommand \index{-\/-nooverlay}
7418
7419 \end_inset 
7420
7421
7422 \series default 
7423   The compiler will not overlay parameters and local variables of any function,
7424  see section Parameters and local variables for more details.
7425 \layout List
7426 \labelwidthstring 00.00.0000
7427
7428
7429 \series bold 
7430 -
7431 \begin_inset ERT
7432 status Collapsed
7433
7434 \layout Standard
7435
7436 \backslash 
7437 /
7438 \end_inset 
7439
7440 -no-peep
7441 \begin_inset LatexCommand \index{-\/-no-peep}
7442
7443 \end_inset 
7444
7445
7446 \series default 
7447  Disable peep-hole optimization with built-in rules.
7448 \layout List
7449 \labelwidthstring 00.00.0000
7450
7451
7452 \series bold 
7453 -
7454 \begin_inset ERT
7455 status Collapsed
7456
7457 \layout Standard
7458
7459 \backslash 
7460 /
7461 \end_inset 
7462
7463 -peep-file
7464 \series default 
7465
7466 \begin_inset LatexCommand \index{-\/-peep-file}
7467
7468 \end_inset 
7469
7470 \SpecialChar ~
7471 <filename> This option can be used to use additional rules to be used by
7472  the peep hole optimizer.
7473  See section 
7474 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7475
7476 \end_inset 
7477
7478 \SpecialChar ~
7479 Peep Hole optimizations for details on how to write these rules.
7480 \layout List
7481 \labelwidthstring 00.00.0000
7482
7483
7484 \series bold 
7485 -
7486 \begin_inset ERT
7487 status Collapsed
7488
7489 \layout Standard
7490
7491 \backslash 
7492 /
7493 \end_inset 
7494
7495 -peep-asm
7496 \begin_inset LatexCommand \index{-\/-peep-asm}
7497
7498 \end_inset 
7499
7500
7501 \series default 
7502  Pass the inline assembler code through the peep hole optimizer.
7503  This can cause unexpected changes to inline assembler code, please go through
7504  the peephole optimizer
7505 \begin_inset LatexCommand \index{Peephole optimizer}
7506
7507 \end_inset 
7508
7509  rules defined in the source file tree '<target>/peeph.def' before using
7510  this option.
7511 \layout List
7512 \labelwidthstring 00.00.0000
7513
7514
7515 \series bold 
7516 -
7517 \begin_inset ERT
7518 status Collapsed
7519
7520 \layout Standard
7521
7522 \backslash 
7523 /
7524 \end_inset 
7525
7526 -opt-code-speed
7527 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7528
7529 \end_inset 
7530
7531
7532 \series default 
7533  The compiler will optimize code generation towards fast code, possibly
7534  at the expense of code size.
7535 \layout List
7536 \labelwidthstring 00.00.0000
7537
7538
7539 \series bold 
7540 -
7541 \begin_inset ERT
7542 status Collapsed
7543
7544 \layout Standard
7545
7546 \backslash 
7547 /
7548 \end_inset 
7549
7550 -opt-code-size
7551 \begin_inset LatexCommand \index{-\/-opt-code-size}
7552
7553 \end_inset 
7554
7555
7556 \series default 
7557  The compiler will optimize code generation towards compact code, possibly
7558  at the expense of code speed.
7559 \layout Subsection
7560
7561 Other Options
7562 \begin_inset LatexCommand \index{Options other}
7563
7564 \end_inset 
7565
7566
7567 \layout List
7568 \labelwidthstring 00.00.0000
7569
7570
7571 \series bold 
7572 -c\SpecialChar ~
7573 -
7574 \begin_inset ERT
7575 status Collapsed
7576
7577 \layout Standard
7578
7579 \backslash 
7580 /
7581 \end_inset 
7582
7583 -compile-only
7584 \begin_inset LatexCommand \index{-\/-compile-only}
7585
7586 \end_inset 
7587
7588
7589 \begin_inset LatexCommand \index{-c -\/-compile-only}
7590
7591 \end_inset 
7592
7593
7594 \series default 
7595  will compile and assemble the source, but will not call the linkage editor.
7596 \layout List
7597 \labelwidthstring 00.00.0000
7598
7599
7600 \series bold 
7601 -
7602 \series default 
7603
7604 \begin_inset ERT
7605 status Collapsed
7606
7607 \layout Standard
7608
7609 \backslash 
7610 /
7611 \end_inset 
7612
7613
7614 \series bold 
7615 -c1mode
7616 \begin_inset LatexCommand \index{-\/-c1mode}
7617
7618 \end_inset 
7619
7620
7621 \series default 
7622  reads the preprocessed source from standard input and compiles it.
7623  The file name for the assembler output must be specified using the -o option.
7624 \layout List
7625 \labelwidthstring 00.00.0000
7626
7627
7628 \series bold 
7629 -E
7630 \begin_inset LatexCommand \index{-E}
7631
7632 \end_inset 
7633
7634
7635 \series default 
7636  Run only the C preprocessor.
7637  Preprocess all the C source files specified and output the results to standard
7638  output.
7639 \layout List
7640 \labelwidthstring 00.00.0000
7641
7642
7643 \series bold 
7644 -o\SpecialChar ~
7645 <path/file>
7646 \begin_inset LatexCommand \index{-o <path/file>}
7647
7648 \end_inset 
7649
7650  
7651 \series default 
7652 The output path resp.
7653  file where everything will be placed.
7654  If the parameter is a path, it must have a trailing slash (or backslash
7655  for the Windows binaries) to be recognized as a path.
7656  
7657 \layout List
7658 \labelwidthstring 00.00.0000
7659
7660
7661 \series bold 
7662 -
7663 \begin_inset ERT
7664 status Collapsed
7665
7666 \layout Standard
7667
7668 \backslash 
7669 /
7670 \end_inset 
7671
7672 -stack-auto
7673 \begin_inset LatexCommand \index{-\/-stack-auto}
7674
7675 \end_inset 
7676
7677
7678 \series default 
7679 \size large 
7680 \emph on 
7681  
7682 \size default 
7683 \emph default 
7684 All functions in the source file will be compiled as 
7685 \emph on 
7686 reentrant
7687 \emph default 
7688
7689 \begin_inset LatexCommand \index{reentrant}
7690
7691 \end_inset 
7692
7693 , i.e.
7694  the parameters and local variables will be allocated on the stack
7695 \begin_inset LatexCommand \index{stack}
7696
7697 \end_inset 
7698
7699 .
7700  See section 
7701 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7702
7703 \end_inset 
7704
7705  Parameters and Local Variables for more details.
7706  If this option is used all source files in the project should be compiled
7707  with this option.
7708  It automatically implies --int-long-reent and --float-reent.
7709  
7710 \layout List
7711 \labelwidthstring 00.00.0000
7712
7713
7714 \series bold 
7715 -
7716 \begin_inset ERT
7717 status Collapsed
7718
7719 \layout Standard
7720
7721 \backslash 
7722 /
7723 \end_inset 
7724
7725 -callee-saves
7726 \begin_inset LatexCommand \index{-\/-callee-saves}
7727
7728 \end_inset 
7729
7730  function1[,function2][,function3]....
7731
7732 \series default 
7733  The compiler by default uses a caller saves convention for register saving
7734  across function calls, however this can cause unnecessary register pushing
7735  & popping when calling small functions from larger functions.
7736  This option can be used to switch the register saving convention for the
7737  function names specified.
7738  The compiler will not save registers when calling these functions, no extra
7739  code will be generated at the entry & exit (function prologue
7740 \series bold 
7741
7742 \begin_inset LatexCommand \index{function prologue}
7743
7744 \end_inset 
7745
7746
7747 \series default 
7748  & epilogue
7749 \series bold 
7750
7751 \begin_inset LatexCommand \index{function epilogue}
7752
7753 \end_inset 
7754
7755
7756 \series default 
7757 ) for these functions to save & restore the registers used by these functions,
7758  this can SUBSTANTIALLY reduce code & improve run time performance of the
7759  generated code.
7760  In the future the compiler (with inter procedural analysis) will be able
7761  to determine the appropriate scheme to use for each function call.
7762  DO NOT use this option for built-in functions such as _mulint..., if this
7763  option is used for a library function the appropriate library function
7764  needs to be recompiled with the same option.
7765  If the project consists of multiple source files then all the source file
7766  should be compiled with the same -
7767 \begin_inset ERT
7768 status Collapsed
7769
7770 \layout Standard
7771
7772 \backslash 
7773 /
7774 \end_inset 
7775
7776 -callee-saves option string.
7777  Also see #pragma\SpecialChar ~
7778 callee_saves
7779 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7780
7781 \end_inset 
7782
7783 .
7784 \layout List
7785 \labelwidthstring 00.00.0000
7786
7787
7788 \series bold 
7789 -
7790 \begin_inset ERT
7791 status Collapsed
7792
7793 \layout Standard
7794
7795 \backslash 
7796 /
7797 \end_inset 
7798
7799 -debug
7800 \begin_inset LatexCommand \index{-\/-debug}
7801
7802 \end_inset 
7803
7804
7805 \bar under 
7806  
7807 \series default 
7808 \bar default 
7809 When this option is used the compiler will generate debug information.
7810  The debug information collected in a file with .cdb extension can be used
7811  with the SDCDB.
7812  For more information see documentation for SDCDB.
7813  Another file with no extension contains debug information in AOMF or AOMF51
7814 \begin_inset LatexCommand \index{AOMF, AOMF51}
7815
7816 \end_inset 
7817
7818  format which is commonly used by third party tools.
7819 \layout List
7820 \labelwidthstring 00.00.0000
7821
7822
7823 \series bold 
7824 -S
7825 \begin_inset LatexCommand \index{-S}
7826
7827 \end_inset 
7828
7829
7830 \size large 
7831 \bar under 
7832  
7833 \series default 
7834 \size default 
7835 \bar default 
7836 Stop after the stage of compilation proper; do not assemble.
7837  The output is an assembler code file for the input file specified.
7838 \layout List
7839 \labelwidthstring 00.00.0000
7840
7841
7842 \series bold 
7843 -
7844 \begin_inset ERT
7845 status Collapsed
7846
7847 \layout Standard
7848
7849 \backslash 
7850 /
7851 \end_inset 
7852
7853 -int-long-reent
7854 \begin_inset LatexCommand \index{-\/-int-long-reent}
7855
7856 \end_inset 
7857
7858
7859 \series default 
7860  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7861  Note by default these libraries are compiled as non-reentrant.
7862  See section Installation for more details.
7863 \layout List
7864 \labelwidthstring 00.00.0000
7865
7866
7867 \series bold 
7868 -
7869 \begin_inset ERT
7870 status Collapsed
7871
7872 \layout Standard
7873
7874 \backslash 
7875 /
7876 \end_inset 
7877
7878 -cyclomatic
7879 \begin_inset LatexCommand \index{-\/-cyclomatic}
7880
7881 \end_inset 
7882
7883
7884 \bar under 
7885  
7886 \series default 
7887 \bar default 
7888 This option will cause the compiler to generate an information message for
7889  each function in the source file.
7890  The message contains some 
7891 \emph on 
7892 important
7893 \emph default 
7894  information about the function.
7895  The number of edges and nodes the compiler detected in the control flow
7896  graph of the function, and most importantly the 
7897 \emph on 
7898 cyclomatic complexity
7899 \begin_inset LatexCommand \index{Cyclomatic complexity}
7900
7901 \end_inset 
7902
7903
7904 \emph default 
7905  see section on Cyclomatic Complexity for more details.
7906 \layout List
7907 \labelwidthstring 00.00.0000
7908
7909
7910 \series bold 
7911 -
7912 \begin_inset ERT
7913 status Collapsed
7914
7915 \layout Standard
7916
7917 \backslash 
7918 /
7919 \end_inset 
7920
7921 -float-reent
7922 \begin_inset LatexCommand \index{-\/-float-reent}
7923
7924 \end_inset 
7925
7926
7927 \series default 
7928  Floating point library is compiled as reentrant
7929 \begin_inset LatexCommand \index{reentrant}
7930
7931 \end_inset 
7932
7933 .
7934  See section Installation for more details.
7935 \layout List
7936 \labelwidthstring 00.00.0000
7937
7938
7939 \series bold 
7940 -
7941 \begin_inset ERT
7942 status Collapsed
7943
7944 \layout Standard
7945
7946 \backslash 
7947 /
7948 \end_inset 
7949
7950 -main-return
7951 \begin_inset LatexCommand \index{-\/-main-return}
7952
7953 \end_inset 
7954
7955
7956 \series default 
7957  This option can be used if the code generated is called by a monitor program
7958  or if the main routine includes an endless loop.
7959  This option might result in slightly smaller code and save two bytes of
7960  stack space.
7961  The return from the 'main'
7962 \begin_inset LatexCommand \index{main return}
7963
7964 \end_inset 
7965
7966  function will return to the function calling main.
7967  The default setting is to lock up i.e.
7968  generate a '
7969 \family typewriter 
7970 sjmp .
7971 \family default 
7972 '.
7973 \layout List
7974 \labelwidthstring 00.00.0000
7975
7976
7977 \series bold 
7978 -
7979 \begin_inset ERT
7980 status Collapsed
7981
7982 \layout Standard
7983
7984 \backslash 
7985 /
7986 \end_inset 
7987
7988 -nostdinc
7989 \begin_inset LatexCommand \index{-\/-nostdinc}
7990
7991 \end_inset 
7992
7993
7994 \series default 
7995  This will prevent the compiler from passing on the default include path
7996  to the preprocessor.
7997 \layout List
7998 \labelwidthstring 00.00.0000
7999
8000
8001 \series bold 
8002 -
8003 \begin_inset ERT
8004 status Collapsed
8005
8006 \layout Standard
8007
8008 \backslash 
8009 /
8010 \end_inset 
8011
8012 -nostdlib
8013 \begin_inset LatexCommand \index{-\/-nostdlib}
8014
8015 \end_inset 
8016
8017
8018 \series default 
8019  This will prevent the compiler from passing on the default library
8020 \begin_inset LatexCommand \index{Libraries}
8021
8022 \end_inset 
8023
8024  path to the linker.
8025 \layout List
8026 \labelwidthstring 00.00.0000
8027
8028
8029 \series bold 
8030 -
8031 \begin_inset ERT
8032 status Collapsed
8033
8034 \layout Standard
8035
8036 \backslash 
8037 /
8038 \end_inset 
8039
8040 -verbose
8041 \begin_inset LatexCommand \index{-\/-verbose}
8042
8043 \end_inset 
8044
8045
8046 \series default 
8047  Shows the various actions the compiler is performing.
8048 \layout List
8049 \labelwidthstring 00.00.0000
8050
8051
8052 \series bold 
8053 -V
8054 \begin_inset LatexCommand \index{-V}
8055
8056 \end_inset 
8057
8058
8059 \series default 
8060  Shows the actual commands the compiler is executing.
8061 \layout List
8062 \labelwidthstring 00.00.0000
8063
8064
8065 \series bold 
8066 -
8067 \begin_inset ERT
8068 status Collapsed
8069
8070 \layout Standard
8071
8072 \backslash 
8073 /
8074 \end_inset 
8075
8076 -no-c-code-in-asm
8077 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8078
8079 \end_inset 
8080
8081
8082 \series default 
8083  Hides your ugly and inefficient c-code from the asm file, so you can always
8084  blame the compiler :)
8085 \layout List
8086 \labelwidthstring 00.00.0000
8087
8088
8089 \series bold 
8090 -
8091 \begin_inset ERT
8092 status Collapsed
8093
8094 \layout Standard
8095
8096 \backslash 
8097 /
8098 \end_inset 
8099
8100 -no-peep-comments
8101 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8102
8103 \end_inset 
8104
8105
8106 \series default 
8107  Will not include peep-hole comments in the generated files.
8108 \layout List
8109 \labelwidthstring 00.00.0000
8110
8111
8112 \series bold 
8113 -
8114 \begin_inset ERT
8115 status Collapsed
8116
8117 \layout Standard
8118
8119 \backslash 
8120 /
8121 \end_inset 
8122
8123 -i-code-in-asm
8124 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8125
8126 \end_inset 
8127
8128
8129 \series default 
8130  Include i-codes in the asm file.
8131  Sounds like noise but is most helpful for debugging the compiler itself.
8132 \layout List
8133 \labelwidthstring 00.00.0000
8134
8135
8136 \series bold 
8137 -
8138 \begin_inset ERT
8139 status Collapsed
8140
8141 \layout Standard
8142
8143 \backslash 
8144 /
8145 \end_inset 
8146
8147 -less-pedantic
8148 \begin_inset LatexCommand \index{-\/-less-pedantic}
8149
8150 \end_inset 
8151
8152
8153 \series default 
8154  Disable some of the more pedantic warnings
8155 \begin_inset LatexCommand \index{Warnings}
8156
8157 \end_inset 
8158
8159  (jwk burps: please be more specific here, please!).
8160 \layout List
8161 \labelwidthstring 00.00.0000
8162
8163
8164 \series bold 
8165 -
8166 \begin_inset ERT
8167 status Collapsed
8168
8169 \layout Standard
8170
8171 \backslash 
8172 /
8173 \end_inset 
8174
8175 -disable-warning\SpecialChar ~
8176 <nnnn>
8177 \begin_inset LatexCommand \index{-\/-disable-warning}
8178
8179 \end_inset 
8180
8181
8182 \series default 
8183  Disable specific warning with number <nnnn>.
8184 \layout List
8185 \labelwidthstring 00.00.0000
8186
8187
8188 \series bold 
8189 -
8190 \begin_inset ERT
8191 status Collapsed
8192
8193 \layout Standard
8194
8195 \backslash 
8196 /
8197 \end_inset 
8198
8199 -print-search-dirs
8200 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8201
8202 \end_inset 
8203
8204
8205 \series default 
8206  Display the directories in the compiler's search path
8207 \layout List
8208 \labelwidthstring 00.00.0000
8209
8210
8211 \series bold 
8212 -
8213 \begin_inset ERT
8214 status Collapsed
8215
8216 \layout Standard
8217
8218 \backslash 
8219 /
8220 \end_inset 
8221
8222 -vc
8223 \begin_inset LatexCommand \index{-\/-vc}
8224
8225 \end_inset 
8226
8227
8228 \series default 
8229  Display errors and warnings using MSVC style, so you can use SDCC with
8230  visual studio.
8231 \layout List
8232 \labelwidthstring 00.00.0000
8233
8234
8235 \series bold 
8236 -
8237 \begin_inset ERT
8238 status Collapsed
8239
8240 \layout Standard
8241
8242 \backslash 
8243 /
8244 \end_inset 
8245
8246 -use-stdout
8247 \begin_inset LatexCommand \index{-\/-use-stdout}
8248
8249 \end_inset 
8250
8251
8252 \series default 
8253  Send errors and warnings to stdout instead of stderr.
8254 \layout List
8255 \labelwidthstring 00.00.0000
8256
8257
8258 \series bold 
8259 -Wa\SpecialChar ~
8260 asmOption[,asmOption]
8261 \series default 
8262
8263 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8264
8265 \end_inset 
8266
8267 ...
8268  Pass the asmOption to the assembler
8269 \begin_inset LatexCommand \index{Options assembler}
8270
8271 \end_inset 
8272
8273
8274 \begin_inset LatexCommand \index{Assembler options}
8275
8276 \end_inset 
8277
8278 .
8279  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8280 \layout List
8281 \labelwidthstring 00.00.0000
8282
8283
8284 \series bold 
8285 -
8286 \begin_inset ERT
8287 status Collapsed
8288
8289 \layout Standard
8290
8291 \backslash 
8292 /
8293 \end_inset 
8294
8295 -std-sdcc89
8296 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8297
8298 \end_inset 
8299
8300
8301 \series default 
8302  Generally follow the C89 standard, but allow SDCC features that conflict
8303  with the standard (default).
8304 \layout List
8305 \labelwidthstring 00.00.0000
8306
8307
8308 \series bold 
8309 -
8310 \begin_inset ERT
8311 status Collapsed
8312
8313 \layout Standard
8314
8315 \backslash 
8316 /
8317 \end_inset 
8318
8319 -std-c89
8320 \begin_inset LatexCommand \index{-\/-std-c89}
8321
8322 \end_inset 
8323
8324
8325 \series default 
8326  Follow the C89 standard and disable SDCC features that conflict with the
8327  standard.
8328 \layout List
8329 \labelwidthstring 00.00.0000
8330
8331
8332 \series bold 
8333 -
8334 \begin_inset ERT
8335 status Collapsed
8336
8337 \layout Standard
8338
8339 \backslash 
8340 /
8341 \end_inset 
8342
8343 -std-sdcc99
8344 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8345
8346 \end_inset 
8347
8348
8349 \series default 
8350  Generally follow the C99 standard, but allow SDCC features that conflict
8351  with the standard (incomplete support).
8352 \layout List
8353 \labelwidthstring 00.00.0000
8354
8355
8356 \series bold 
8357 -
8358 \begin_inset ERT
8359 status Collapsed
8360
8361 \layout Standard
8362
8363 \backslash 
8364 /
8365 \end_inset 
8366
8367 -std-c99
8368 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8369
8370 \end_inset 
8371
8372
8373 \series default 
8374  Follow the C99 standard and disable SDCC features that conflict with the
8375  standard (incomplete support).
8376 \layout List
8377 \labelwidthstring 00.00.0000
8378
8379
8380 \series bold 
8381 -
8382 \begin_inset ERT
8383 status Collapsed
8384
8385 \layout Standard
8386
8387 \backslash 
8388 /
8389 \end_inset 
8390
8391 -codeseg
8392 \series default 
8393
8394 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8395
8396 \end_inset 
8397
8398 \SpecialChar ~
8399 <Name> The name to be used for the code
8400 \begin_inset LatexCommand \index{code}
8401
8402 \end_inset 
8403
8404  segment, default CSEG.
8405  This is useful if you need to tell the compiler to put the code in a special
8406  segment so you can later on tell the linker to put this segment in a special
8407  place in memory.
8408  Can be used for instance when using bank switching to put the code in a
8409  bank.
8410 \layout List
8411 \labelwidthstring 00.00.0000
8412
8413
8414 \series bold 
8415 -
8416 \begin_inset ERT
8417 status Collapsed
8418
8419 \layout Standard
8420
8421 \backslash 
8422 /
8423 \end_inset 
8424
8425 -constseg
8426 \series default 
8427
8428 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8429
8430 \end_inset 
8431
8432 \SpecialChar ~
8433 <Name> The name to be used for the const
8434 \begin_inset LatexCommand \index{code}
8435
8436 \end_inset 
8437
8438  segment, default CONST.
8439  This is useful if you need to tell the compiler to put the const data in
8440  a special segment so you can later on tell the linker to put this segment
8441  in a special place in memory.
8442  Can be used for instance when using bank switching to put the const data
8443  in a bank.
8444 \layout List
8445 \labelwidthstring 00.00.0000
8446
8447
8448 \series bold 
8449 more-pedantic
8450 \series default 
8451  Actually this is 
8452 \series bold 
8453 \emph on 
8454 not
8455 \series default 
8456 \emph default 
8457  a SDCC compiler option but if you want 
8458 \emph on 
8459 more
8460 \emph default 
8461  warnings you can use a separate tool dedicated to syntax checking like
8462  splint
8463 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8464
8465 \end_inset 
8466
8467
8468 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8469
8470 \end_inset 
8471
8472  
8473 \begin_inset LatexCommand \url{http://www.splint.org}
8474
8475 \end_inset 
8476
8477 .
8478  To make your source files parseable by splint you will have to include
8479  
8480 \family sans 
8481 lint.h
8482 \family default 
8483
8484 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8485
8486 \end_inset 
8487
8488  in your source file and add brackets around extended keywords (like 
8489 \family sans 
8490
8491 \begin_inset Quotes sld
8492 \end_inset 
8493
8494 __at\SpecialChar ~
8495
8496 \series bold 
8497 (
8498 \series default 
8499 0xab
8500 \series bold 
8501 )
8502 \series default 
8503
8504 \begin_inset Quotes srd
8505 \end_inset 
8506
8507
8508 \family default 
8509  and 
8510 \family sans 
8511
8512 \begin_inset Quotes sld
8513 \end_inset 
8514
8515 __interrupt\SpecialChar ~
8516 (2)
8517 \begin_inset Quotes srd
8518 \end_inset 
8519
8520
8521 \family default 
8522 ).
8523  
8524 \newline 
8525 Splint has an excellent on line manual at 
8526 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8527
8528 \end_inset 
8529
8530  and it's capabilities go beyond pure syntax checking.
8531  You'll need to tell splint the location of SDCC's include files so a typical
8532  command line could look like this: 
8533 \newline 
8534
8535 \family sans 
8536 splint\SpecialChar ~
8537 -I\SpecialChar ~
8538 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8539 \SpecialChar ~
8540 myprogram.c
8541 \layout Subsection
8542
8543 Intermediate Dump Options
8544 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8545
8546 \end_inset 
8547
8548
8549 \begin_inset LatexCommand \index{Options intermediate dump}
8550
8551 \end_inset 
8552
8553
8554 \begin_inset LatexCommand \index{Intermediate dump options}
8555
8556 \end_inset 
8557
8558
8559 \layout Standard
8560
8561 The following options are provided for the purpose of retargetting and debugging
8562  the compiler.
8563  They provide a means to dump the intermediate code (iCode
8564 \begin_inset LatexCommand \index{iCode}
8565
8566 \end_inset 
8567
8568 ) generated by the compiler in human readable form at various stages of
8569  the compilation process.
8570  More on iCodes see chapter 
8571 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8572
8573 \end_inset 
8574
8575  
8576 \begin_inset Quotes srd
8577 \end_inset 
8578
8579 The anatomy of the compiler
8580 \begin_inset Quotes srd
8581 \end_inset 
8582
8583 .
8584 \layout List
8585 \labelwidthstring 00.00.0000
8586
8587
8588 \series bold 
8589 -
8590 \begin_inset ERT
8591 status Collapsed
8592
8593 \layout Standard
8594
8595 \backslash 
8596 /
8597 \end_inset 
8598
8599 -dumpraw
8600 \begin_inset LatexCommand \index{-\/-dumpraw}
8601
8602 \end_inset 
8603
8604
8605 \series default 
8606  This option will cause the compiler to dump the intermediate code into
8607  a file of named 
8608 \emph on 
8609 <source filename>.dumpraw
8610 \emph default 
8611  just after the intermediate code has been generated for a function, i.e.
8612  before any optimizations are done.
8613  The basic blocks
8614 \begin_inset LatexCommand \index{Basic blocks}
8615
8616 \end_inset 
8617
8618  at this stage ordered in the depth first number, so they may not be in
8619  sequence of execution.
8620 \layout List
8621 \labelwidthstring 00.00.0000
8622
8623
8624 \series bold 
8625 -
8626 \begin_inset ERT
8627 status Collapsed
8628
8629 \layout Standard
8630
8631 \backslash 
8632 /
8633 \end_inset 
8634
8635 -dumpgcse
8636 \begin_inset LatexCommand \index{-\/-dumpgcse}
8637
8638 \end_inset 
8639
8640
8641 \series default 
8642  Will create a dump of iCode's, after global subexpression elimination
8643 \begin_inset LatexCommand \index{Global subexpression elimination}
8644
8645 \end_inset 
8646
8647 , into a file named 
8648 \emph on 
8649 <source filename>.dumpgcse.
8650 \layout List
8651 \labelwidthstring 00.00.0000
8652
8653
8654 \series bold 
8655 -
8656 \begin_inset ERT
8657 status Collapsed
8658
8659 \layout Standard
8660
8661 \backslash 
8662 /
8663 \end_inset 
8664
8665 -dumpdeadcode
8666 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8667
8668 \end_inset 
8669
8670
8671 \series default 
8672  Will create a dump of iCode's, after deadcode elimination
8673 \begin_inset LatexCommand \index{Dead-code elimination}
8674
8675 \end_inset 
8676
8677 , into a file named 
8678 \emph on 
8679 <source filename>.dumpdeadcode.
8680 \layout List
8681 \labelwidthstring 00.00.0000
8682
8683
8684 \series bold 
8685 -
8686 \begin_inset ERT
8687 status Collapsed
8688
8689 \layout Standard
8690
8691 \backslash 
8692 /
8693 \end_inset 
8694
8695 -dumploop
8696 \begin_inset LatexCommand \index{-\/-dumploop}
8697
8698 \end_inset 
8699
8700
8701 \series default 
8702 \size large 
8703  
8704 \size default 
8705 Will create a dump of iCode's, after loop optimizations
8706 \begin_inset LatexCommand \index{Loop optimization}
8707
8708 \end_inset 
8709
8710 , into a file named 
8711 \emph on 
8712 <source filename>.dumploop.
8713 \layout List
8714 \labelwidthstring 00.00.0000
8715
8716
8717 \series bold 
8718 -
8719 \begin_inset ERT
8720 status Collapsed
8721
8722 \layout Standard
8723
8724 \backslash 
8725 /
8726 \end_inset 
8727
8728 -dumprange
8729 \begin_inset LatexCommand \index{-\/-dumprange}
8730
8731 \end_inset 
8732
8733
8734 \series default 
8735 \size large 
8736  
8737 \size default 
8738 Will create a dump of iCode's, after live range analysis
8739 \begin_inset LatexCommand \index{Live range analysis}
8740
8741 \end_inset 
8742
8743 , into a file named 
8744 \emph on 
8745 <source filename>.dumprange.
8746 \layout List
8747 \labelwidthstring 00.00.0000
8748
8749
8750 \series bold 
8751 -
8752 \begin_inset ERT
8753 status Collapsed
8754
8755 \layout Standard
8756
8757 \backslash 
8758 /
8759 \end_inset 
8760
8761 -dumlrange
8762 \begin_inset LatexCommand \index{-\/-dumlrange}
8763
8764 \end_inset 
8765
8766
8767 \series default 
8768  Will dump the life ranges
8769 \begin_inset LatexCommand \index{Live range analysis}
8770
8771 \end_inset 
8772
8773  for all symbols.
8774 \layout List
8775 \labelwidthstring 00.00.0000
8776
8777
8778 \series bold 
8779 -
8780 \begin_inset ERT
8781 status Collapsed
8782
8783 \layout Standard
8784
8785 \backslash 
8786 /
8787 \end_inset 
8788
8789 -dumpregassign
8790 \begin_inset LatexCommand \index{-\/-dumpregassign}
8791
8792 \end_inset 
8793
8794
8795 \bar under 
8796  
8797 \series default 
8798 \bar default 
8799 Will create a dump of iCode's, after register assignment
8800 \begin_inset LatexCommand \index{Register assignment}
8801
8802 \end_inset 
8803
8804 , into a file named 
8805 \emph on 
8806 <source filename>.dumprassgn.
8807 \layout List
8808 \labelwidthstring 00.00.0000
8809
8810
8811 \series bold 
8812 -
8813 \begin_inset ERT
8814 status Collapsed
8815
8816 \layout Standard
8817
8818 \backslash 
8819 /
8820 \end_inset 
8821
8822 -dumplrange
8823 \begin_inset LatexCommand \index{-\/-dumplrange}
8824
8825 \end_inset 
8826
8827
8828 \series default 
8829  Will create a dump of the live ranges of iTemp's
8830 \layout List
8831 \labelwidthstring 00.00.0000
8832
8833
8834 \series bold 
8835 -
8836 \begin_inset ERT
8837 status Collapsed
8838
8839 \layout Standard
8840
8841 \backslash 
8842 /
8843 \end_inset 
8844
8845 -dumpall
8846 \begin_inset LatexCommand \index{-\/-dumpall}
8847
8848 \end_inset 
8849
8850
8851 \size large 
8852 \bar under 
8853  
8854 \series default 
8855 \size default 
8856 \bar default 
8857 Will cause all the above mentioned dumps to be created.
8858 \layout Subsection
8859
8860 Redirecting output on Windows Shells
8861 \layout Standard
8862
8863 By default SDCC writes it's error messages to 
8864 \begin_inset Quotes sld
8865 \end_inset 
8866
8867 standard error
8868 \begin_inset Quotes srd
8869 \end_inset 
8870
8871 .
8872  To force all messages to 
8873 \begin_inset Quotes sld
8874 \end_inset 
8875
8876 standard output
8877 \begin_inset Quotes srd
8878 \end_inset 
8879
8880  use 
8881 \series bold 
8882 -
8883 \series default 
8884 \emph on 
8885
8886 \begin_inset ERT
8887 status Collapsed
8888
8889 \layout Standard
8890
8891 \backslash 
8892 /
8893 \end_inset 
8894
8895
8896 \series bold 
8897 \emph default 
8898 -
8899 \series default 
8900 use-stdout
8901 \begin_inset LatexCommand \index{-\/-use-stdout}
8902
8903 \end_inset 
8904
8905 .
8906  Additionally, if you happen to have visual studio installed in your windows
8907  machine, you can use it to compile your sources using a custom build and
8908  the SDCC -
8909 \emph on 
8910
8911 \begin_inset ERT
8912 status Collapsed
8913
8914 \layout Standard
8915
8916 \backslash 
8917 /
8918 \end_inset 
8919
8920
8921 \emph default 
8922 -vc
8923 \begin_inset LatexCommand \index{-\/-vc}
8924
8925 \end_inset 
8926
8927  option.
8928  Something like this should work:
8929 \newline 
8930
8931 \newline 
8932
8933 \series bold 
8934 c:
8935 \backslash 
8936 sdcc
8937 \backslash 
8938 bin
8939 \backslash 
8940 sdcc.exe -
8941 \series default 
8942 \emph on 
8943
8944 \begin_inset ERT
8945 status Collapsed
8946
8947 \layout Standard
8948
8949 \backslash 
8950 /
8951 \end_inset 
8952
8953
8954 \series bold 
8955 \emph default 
8956 -vc -
8957 \series default 
8958 \emph on 
8959
8960 \begin_inset ERT
8961 status Collapsed
8962
8963 \layout Standard
8964
8965 \backslash 
8966 /
8967 \end_inset 
8968
8969
8970 \series bold 
8971 \emph default 
8972 -model-large -c $(InputPath)
8973 \layout Section
8974
8975 Environment variables
8976 \begin_inset LatexCommand \index{Environment variables}
8977
8978 \end_inset 
8979
8980
8981 \layout Standard
8982
8983 SDCC recognizes the following environment variables:
8984 \layout List
8985 \labelwidthstring 00.00.0000
8986
8987
8988 \series bold 
8989 SDCC_LEAVE_SIGNALS
8990 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
8991
8992 \end_inset 
8993
8994
8995 \series default 
8996  SDCC installs a signal handler
8997 \begin_inset LatexCommand \index{signal handler}
8998
8999 \end_inset 
9000
9001  to be able to delete temporary files after an user break (^C) or an exception.
9002  If this environment variable is set, SDCC won't install the signal handler
9003  in order to be able to debug SDCC.
9004 \layout List
9005 \labelwidthstring 00.00.0000
9006
9007
9008 \series bold 
9009 TMP,\SpecialChar ~
9010 TEMP,\SpecialChar ~
9011 TMPDIR
9012 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9013
9014 \end_inset 
9015
9016
9017 \series default 
9018  Path, where temporary files will be created.
9019  The order of the variables is the search order.
9020  In a standard *nix environment these variables are not set, and there's
9021  no need to set them.
9022  On Windows it's recommended to set one of them.
9023 \layout List
9024 \labelwidthstring 00.00.0000
9025
9026
9027 \series bold 
9028 SDCC_HOME
9029 \begin_inset LatexCommand \index{SDCC\_HOME}
9030
9031 \end_inset 
9032
9033
9034 \series default 
9035  Path, see section 
9036 \begin_inset LatexCommand \ref{sub:Install-paths}
9037
9038 \end_inset 
9039
9040 \SpecialChar ~
9041
9042 \begin_inset Quotes sld
9043 \end_inset 
9044
9045  Install Paths
9046 \begin_inset Quotes srd
9047 \end_inset 
9048
9049 .
9050 \layout List
9051 \labelwidthstring 00.00.0000
9052
9053
9054 \series bold 
9055 SDCC_INCLUDE
9056 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9057
9058 \end_inset 
9059
9060
9061 \series default 
9062  Path, see section 
9063 \begin_inset LatexCommand \ref{sub:Search-Paths}
9064
9065 \end_inset 
9066
9067 \SpecialChar ~
9068
9069 \begin_inset Quotes sld
9070 \end_inset 
9071
9072 Search Paths
9073 \begin_inset Quotes srd
9074 \end_inset 
9075
9076 .
9077 \layout List
9078 \labelwidthstring 00.00.0000
9079
9080
9081 \series bold 
9082 SDCC_LIB
9083 \begin_inset LatexCommand \index{SDCC\_LIB}
9084
9085 \end_inset 
9086
9087
9088 \series default 
9089  Path, see section 
9090 \begin_inset LatexCommand \ref{sub:Search-Paths}
9091
9092 \end_inset 
9093
9094 \SpecialChar ~
9095
9096 \begin_inset Quotes sld
9097 \end_inset 
9098
9099 Search Paths
9100 \begin_inset Quotes srd
9101 \end_inset 
9102
9103 ..
9104 \layout Standard
9105
9106 There are some more environment variables recognized by SDCC, but these
9107  are solely used for debugging purposes.
9108  They can change or disappear very quickly, and will never be documented.
9109 \layout Section
9110
9111 Storage Class Language Extensions
9112 \layout Subsection
9113
9114 MCS51/DS390 Storage Class
9115 \begin_inset LatexCommand \index{Storage class}
9116
9117 \end_inset 
9118
9119  Language Extensions
9120 \layout Standard
9121
9122 In addition to the ANSI storage classes SDCC allows the following MCS51
9123  specific storage classes:
9124 \layout Subsubsection
9125
9126 data
9127 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9128
9129 \end_inset 
9130
9131
9132 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9133
9134 \end_inset 
9135
9136  / near
9137 \begin_inset LatexCommand \index{near (storage class)}
9138
9139 \end_inset 
9140
9141
9142 \begin_inset LatexCommand \index{\_\_near (storage class)}
9143
9144 \end_inset 
9145
9146
9147 \layout Standard
9148
9149 This is the 
9150 \series bold 
9151 default
9152 \series default 
9153  storage class for the Small Memory model (
9154 \emph on 
9155 data
9156 \emph default 
9157  and 
9158 \emph on 
9159 near
9160 \emph default 
9161  can be used synonymously).
9162  Variables declared with this storage class will be allocated in the directly
9163  addressable portion of the internal RAM of a 8051, e.g.:
9164 \layout Verse
9165
9166
9167 \family typewriter 
9168 data unsigned char test_data;
9169 \layout Standard
9170
9171 Writing 0x01 to this variable generates the assembly code:
9172 \layout Verse
9173
9174
9175 \family typewriter 
9176 75*00 01\SpecialChar ~
9177 \SpecialChar ~
9178 \SpecialChar ~
9179 mov\SpecialChar ~
9180 \SpecialChar ~
9181 _test_data,#0x01 
9182 \layout Subsubsection
9183
9184 xdata
9185 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9186
9187 \end_inset 
9188
9189
9190 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9191
9192 \end_inset 
9193
9194  / far
9195 \begin_inset LatexCommand \index{far (storage class)}
9196
9197 \end_inset 
9198
9199
9200 \begin_inset LatexCommand \index{\_\_far (storage class)}
9201
9202 \end_inset 
9203
9204
9205 \layout Standard
9206
9207 Variables declared with this storage class will be placed in the external
9208  RAM.
9209  This is the 
9210 \series bold 
9211 default
9212 \series default 
9213  storage class for the Large Memory model, e.g.:
9214 \layout Verse
9215
9216
9217 \family typewriter 
9218 xdata unsigned char test_xdata;
9219 \layout Standard
9220
9221 Writing 0x01 to this variable generates the assembly code:
9222 \layout Verse
9223
9224
9225 \family typewriter 
9226 90s00r00\SpecialChar ~
9227 \SpecialChar ~
9228 \SpecialChar ~
9229 mov\SpecialChar ~
9230 \SpecialChar ~
9231 dptr,#_test_xdata 
9232 \newline 
9233 74\SpecialChar ~
9234 01\SpecialChar ~
9235 \SpecialChar ~
9236 \SpecialChar ~
9237 \SpecialChar ~
9238 \SpecialChar ~
9239 \SpecialChar ~
9240 mov\SpecialChar ~
9241 \SpecialChar ~
9242 a,#0x01 
9243 \newline 
9244 F0\SpecialChar ~
9245 \SpecialChar ~
9246 \SpecialChar ~
9247 \SpecialChar ~
9248 \SpecialChar ~
9249 \SpecialChar ~
9250 \SpecialChar ~
9251 \SpecialChar ~
9252 \SpecialChar ~
9253 movx\SpecialChar ~
9254 @dptr,a 
9255 \layout Subsubsection
9256
9257 idata
9258 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9259
9260 \end_inset 
9261
9262
9263 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9264
9265 \end_inset 
9266
9267
9268 \layout Standard
9269
9270 Variables declared with this storage class will be allocated into the indirectly
9271  addressable portion of the internal ram of a 8051, e.g.:
9272 \layout Verse
9273
9274
9275 \family typewriter 
9276 idata unsigned char test_idata;
9277 \layout Standard
9278
9279 Writing 0x01 to this variable generates the assembly code:
9280 \layout Verse
9281
9282
9283 \family typewriter 
9284 78r00\SpecialChar ~
9285 \SpecialChar ~
9286 \SpecialChar ~
9287 \SpecialChar ~
9288 \SpecialChar ~
9289 \SpecialChar ~
9290 \SpecialChar ~
9291 mov\SpecialChar ~
9292 \SpecialChar ~
9293 r0,#_test_idata
9294 \newline 
9295 76\SpecialChar ~
9296 01\SpecialChar ~
9297 \SpecialChar ~
9298 \SpecialChar ~
9299 \SpecialChar ~
9300 \SpecialChar ~
9301 \SpecialChar ~
9302 \SpecialChar ~
9303 mov\SpecialChar ~
9304 \SpecialChar ~
9305 @r0,#0x01
9306 \layout Standard
9307
9308 Please note, the first 128 byte of idata physically access the same RAM
9309  as the data memory.
9310  The original 8051 had 128 byte idata memory, nowadays most devices have
9311  256 byte idata memory.
9312  The stack
9313 \begin_inset LatexCommand \index{stack}
9314
9315 \end_inset 
9316
9317  is located in idata memory.
9318 \layout Subsubsection
9319
9320 pdata
9321 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9322
9323 \end_inset 
9324
9325
9326 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9327
9328 \end_inset 
9329
9330
9331 \layout Standard
9332
9333 Paged xdata access is just as straightforward as using the other addressing
9334  modes of a 8051.
9335  It is typically located at the start of xdata and has a maximum size of
9336  256 bytes.
9337  The following example writes 0x01 to the pdata variable.
9338  Please note, pdata access physically accesses xdata memory.
9339  The high byte of the address is determined by port P2 
9340 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9341
9342 \end_inset 
9343
9344 (or in case of some 8051 variants by a separate Special Function Register,
9345  see section 
9346 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9347
9348 \end_inset 
9349
9350 ).
9351  This is the 
9352 \series bold 
9353 default
9354 \series default 
9355  storage class for the Medium Memory model, e.g.:
9356 \layout Verse
9357
9358
9359 \family typewriter 
9360 pdata unsigned char test_pdata;
9361 \layout Standard
9362
9363 Writing 0x01 to this variable generates the assembly code:
9364 \layout Verse
9365
9366
9367 \family typewriter 
9368 78r00\SpecialChar ~
9369 \SpecialChar ~
9370 \SpecialChar ~
9371 \SpecialChar ~
9372 \SpecialChar ~
9373 \SpecialChar ~
9374 mov r0,#_test_pdata
9375 \newline 
9376 74 01\SpecialChar ~
9377 \SpecialChar ~
9378 \SpecialChar ~
9379 \SpecialChar ~
9380 \SpecialChar ~
9381 \SpecialChar ~
9382 mov a,#0x01 
9383 \newline 
9384 F2\SpecialChar ~
9385 \SpecialChar ~
9386 \SpecialChar ~
9387 \SpecialChar ~
9388 \SpecialChar ~
9389 \SpecialChar ~
9390 \SpecialChar ~
9391 \SpecialChar ~
9392 \SpecialChar ~
9393 movx @r0,a
9394 \layout Standard
9395
9396 If the -
9397 \begin_inset ERT
9398 status Collapsed
9399
9400 \layout Standard
9401
9402 \backslash 
9403 /
9404 \end_inset 
9405
9406 -xstack
9407 \begin_inset LatexCommand \index{-\/-xstack}
9408
9409 \end_inset 
9410
9411  option is used the pdata memory area is followed by the xstack memory area
9412  and the sum of their sizes is limited to 256 bytes.
9413 \layout Subsubsection
9414
9415 code
9416 \begin_inset LatexCommand \index{code}
9417
9418 \end_inset 
9419
9420
9421 \begin_inset LatexCommand \index{\_\_code}
9422
9423 \end_inset 
9424
9425
9426 \layout Standard
9427
9428 'Variables' declared with this storage class will be placed in the code
9429  memory:
9430 \layout Verse
9431
9432
9433 \family typewriter 
9434 code unsigned char test_code;
9435 \layout Standard
9436
9437 Read access to this variable generates the assembly code:
9438 \layout Verse
9439
9440
9441 \family typewriter 
9442 90s00r6F\SpecialChar ~
9443 \SpecialChar ~
9444 \SpecialChar ~
9445 mov dptr,#_test_code
9446 \newline 
9447 E4\SpecialChar ~
9448 \SpecialChar ~
9449 \SpecialChar ~
9450 \SpecialChar ~
9451 \SpecialChar ~
9452 \SpecialChar ~
9453 \SpecialChar ~
9454 \SpecialChar ~
9455 \SpecialChar ~
9456 clr a
9457 \newline 
9458 93\SpecialChar ~
9459 \SpecialChar ~
9460 \SpecialChar ~
9461 \SpecialChar ~
9462 \SpecialChar ~
9463 \SpecialChar ~
9464 \SpecialChar ~
9465 \SpecialChar ~
9466 \SpecialChar ~
9467 movc a,@a+dptr 
9468 \layout Standard
9469
9470
9471 \family typewriter 
9472 char
9473 \family default 
9474  indexed arrays of characters in code memory can be accessed efficiently:
9475 \layout Verse
9476
9477
9478 \family typewriter 
9479 code char test_array[] = {'c','h','e','a','p'}; 
9480 \layout Standard
9481
9482 Read access to this array using an 8-bit unsigned index generates the assembly
9483  code:
9484 \layout Verse
9485
9486
9487 \family typewriter 
9488 E5*00\SpecialChar ~
9489 \SpecialChar ~
9490 \SpecialChar ~
9491 \SpecialChar ~
9492 \SpecialChar ~
9493 \SpecialChar ~
9494 mov a,_index 
9495 \layout Verse
9496
9497
9498 \family typewriter 
9499 90s00r41\SpecialChar ~
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 mov dptr,#_test_array
9503 \layout Verse
9504
9505
9506 \family typewriter 
9507 93\SpecialChar ~
9508 \SpecialChar ~
9509 \SpecialChar ~
9510 \SpecialChar ~
9511 \SpecialChar ~
9512 \SpecialChar ~
9513 \SpecialChar ~
9514 \SpecialChar ~
9515 \SpecialChar ~
9516 movc a,@a+dptr 
9517 \layout Subsubsection
9518
9519 bit
9520 \begin_inset LatexCommand \index{bit}
9521
9522 \end_inset 
9523
9524
9525 \begin_inset LatexCommand \index{\_\_bit}
9526
9527 \end_inset 
9528
9529
9530 \layout Standard
9531
9532 This is a data-type and a storage class specifier.
9533  When a variable is declared as a bit, it is allocated into the bit addressable
9534  memory of 8051, e.g.:
9535 \layout Verse
9536
9537
9538 \family typewriter 
9539 bit test_bit;
9540 \layout Standard
9541
9542 Writing 1 to this variable generates the assembly code:
9543 \layout Verse
9544
9545
9546 \family typewriter 
9547 D2*00\SpecialChar ~
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 \SpecialChar ~
9553 \SpecialChar ~
9554 setb\SpecialChar ~
9555 _test_bit
9556 \layout Standard
9557
9558 The bit addressable memory consists of 128 bits which are located from 0x20
9559  to 0x2f in data memory.
9560  
9561 \newline 
9562 Apart from this 8051 specific storage class most architectures support ANSI-C
9563  bitfields
9564 \begin_inset LatexCommand \index{bitfields}
9565
9566 \end_inset 
9567
9568
9569 \begin_inset Foot
9570 collapsed false
9571
9572 \layout Standard
9573
9574 Not really meant as examples, but nevertheless showing what bitfields are
9575  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9576 \end_inset 
9577
9578 .
9579  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9580  signed modifier are implemented as unsigned.
9581 \layout Subsubsection
9582
9583 sfr
9584 \begin_inset LatexCommand \index{sfr}
9585
9586 \end_inset 
9587
9588
9589 \begin_inset LatexCommand \index{\_\_sfr}
9590
9591 \end_inset 
9592
9593  / sfr16
9594 \begin_inset LatexCommand \index{sfr16}
9595
9596 \end_inset 
9597
9598
9599 \begin_inset LatexCommand \index{\_\_sfr16}
9600
9601 \end_inset 
9602
9603  / sfr32
9604 \begin_inset LatexCommand \index{sfr32}
9605
9606 \end_inset 
9607
9608
9609 \begin_inset LatexCommand \index{\_\_sfr32}
9610
9611 \end_inset 
9612
9613  / sbit
9614 \begin_inset LatexCommand \index{\_\_sbit}
9615
9616 \end_inset 
9617
9618
9619 \layout Standard
9620
9621 Like the bit keyword, 
9622 \emph on 
9623 sfr / sfr16 / sfr32 / sbit 
9624 \emph default 
9625 signify both a data-type and storage class, they are used to describe the
9626  
9627 \emph on 
9628 s
9629 \emph default 
9630 pecial 
9631 \emph on 
9632 f
9633 \emph default 
9634 unction 
9635 \emph on 
9636 r
9637 \emph default 
9638 egisters and 
9639 \emph on 
9640 s
9641 \emph default 
9642 pecial 
9643 \emph on 
9644 bit
9645 \emph default 
9646  variables of a 8051, eg:
9647 \layout Verse
9648
9649
9650 \family typewriter 
9651 sfr at
9652 \begin_inset LatexCommand \index{at}
9653
9654 \end_inset 
9655
9656
9657 \begin_inset LatexCommand \index{\_\_at}
9658
9659 \end_inset 
9660
9661  0x80 P0;\SpecialChar ~
9662  /* special function register P0 at location 0x80 */
9663 \newline 
9664 /* 16 bit special function register combination for timer 0 */
9665 \newline 
9666 /* with the high byte at location 0x8C and the low byte at location 0x8A
9667  */
9668 \newline 
9669 sfr16 at
9670 \begin_inset LatexCommand \index{at}
9671
9672 \end_inset 
9673
9674
9675 \begin_inset LatexCommand \index{\_\_at}
9676
9677 \end_inset 
9678
9679  0x8C8A TMR0;
9680 \newline 
9681 sbit at 0xd7 CY; /* CY (Carry Flag
9682 \begin_inset LatexCommand \index{Flags}
9683
9684 \end_inset 
9685
9686
9687 \begin_inset LatexCommand \index{Carry flag}
9688
9689 \end_inset 
9690
9691 ) */
9692 \layout Standard
9693
9694 Special function registers which are located on an address dividable by
9695  8 are bit-addressable, an
9696 \emph on 
9697  sbit
9698 \emph default 
9699  addresses a specific bit within these sfr.
9700 \newline 
9701 16 Bit and 32 bit special function register combinations which require a
9702  certain access order are better not declared using 
9703 \emph on 
9704 sfr16
9705 \emph default 
9706  or 
9707 \emph on 
9708 sfr32.
9709
9710 \emph default 
9711  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9712  this is not guaranteed.
9713 \layout Subsubsection
9714
9715 Pointers
9716 \begin_inset LatexCommand \index{Pointer}
9717
9718 \end_inset 
9719
9720  to MCS51/DS390 specific memory spaces
9721 \layout Standard
9722
9723 SDCC allows (via language extensions) pointers to explicitly point to any
9724  of the memory spaces
9725 \begin_inset LatexCommand \index{Memory model}
9726
9727 \end_inset 
9728
9729  of the 8051.
9730  In addition to the explicit pointers, the compiler uses (by default) generic
9731  pointers which can be used to point to any of the memory spaces.
9732 \newline 
9733
9734 \newline 
9735 Pointer declaration examples:
9736 \layout Verse
9737
9738
9739 \family typewriter 
9740 /* pointer physically in internal ram pointing to object in external ram
9741  */ 
9742 \newline 
9743 xdata unsigned char * data p;
9744 \newline 
9745
9746 \newline 
9747 /* pointer physically in external ram pointing to object in internal ram
9748  */ 
9749 \newline 
9750 data unsigned char * xdata p;
9751 \newline 
9752
9753 \newline 
9754 /* pointer physically in code rom pointing to data in xdata space */ 
9755 \newline 
9756 xdata unsigned char * code p;
9757 \newline 
9758
9759 \newline 
9760 /* pointer physically in code space pointing to data in code space */ 
9761 \newline 
9762 code unsigned char * code p;
9763 \newline 
9764
9765 \newline 
9766 /* the following is a generic pointer physically located in xdata space
9767  */
9768 \newline 
9769 char * xdata p;
9770 \newline 
9771
9772 \newline 
9773 /* the following is a function pointer physically located in data space
9774  */
9775 \newline 
9776 char (* data fp)(void);
9777 \layout Standard
9778
9779 Well you get the idea.
9780  
9781 \newline 
9782
9783 \newline 
9784 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
9785 \emph on 
9786 generic
9787 \emph default 
9788  pointers.
9789  
9790 \size small 
9791
9792 \newline 
9793
9794 \newline 
9795
9796 \size default 
9797 The highest order byte of the 
9798 \emph on 
9799 generic
9800 \emph default 
9801  pointers contains the data space information.
9802  Assembler support routines are called whenever data is stored or retrieved
9803  using 
9804 \emph on 
9805 generic
9806 \emph default 
9807  pointers.
9808  These are useful for developing reusable library
9809 \begin_inset LatexCommand \index{Libraries}
9810
9811 \end_inset 
9812
9813  routines.
9814  Explicitly specifying the pointer type will generate the most efficient
9815  code.
9816 \layout Subsubsection
9817
9818 Notes on MCS51 memory
9819 \begin_inset LatexCommand \index{MCS51 memory}
9820
9821 \end_inset 
9822
9823  layout
9824 \layout Standard
9825
9826 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
9827  RAM memory which is structured as follows:
9828 \newline 
9829
9830 \newline 
9831 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
9832  
9833 \newline 
9834 - Bytes 20-2F - 16 bytes to hold 128 bit
9835 \begin_inset LatexCommand \index{bit}
9836
9837 \end_inset 
9838
9839  variables and, 
9840 \newline 
9841 - Bytes 30-7F - 80 bytes for general purpose use.
9842 \newline 
9843
9844 \layout Standard
9845
9846 Additionally some members of the MCS51 family may have up to 128 bytes of
9847  additional, indirectly addressable, internal RAM memory (
9848 \emph on 
9849 idata
9850 \emph default 
9851
9852 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9853
9854 \end_inset 
9855
9856
9857 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9858
9859 \end_inset 
9860
9861 ).
9862  Furthermore, some chips may have some built in external memory (
9863 \emph on 
9864 xdata
9865 \emph default 
9866
9867 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9868
9869 \end_inset 
9870
9871
9872 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9873
9874 \end_inset 
9875
9876 ) which should not be confused with the internal, directly addressable RAM
9877  memory (
9878 \emph on 
9879 data
9880 \emph default 
9881
9882 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9883
9884 \end_inset 
9885
9886
9887 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9888
9889 \end_inset 
9890
9891 ).
9892  Sometimes this built in 
9893 \emph on 
9894 xdata
9895 \emph default 
9896  memory has to be activated before using it (you can probably find this
9897  information on the datasheet of the microcontroller your are using, see
9898  also section 
9899 \begin_inset LatexCommand \ref{sub:Startup-Code}
9900
9901 \end_inset 
9902
9903 \SpecialChar ~
9904 Startup-Code).
9905 \layout Standard
9906
9907 Normally SDCC will only use the first bank
9908 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9909
9910 \end_inset 
9911
9912  of registers (register bank 0), but it is possible to specify that other
9913  banks of registers (keyword 
9914 \emph on 
9915 using
9916 \emph default 
9917  
9918 \emph on 
9919
9920 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9921
9922 \end_inset 
9923
9924
9925 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
9926
9927 \end_inset 
9928
9929
9930 \emph default 
9931 ) should be used in interrupt
9932 \begin_inset LatexCommand \index{interrupt}
9933
9934 \end_inset 
9935
9936
9937 \begin_inset LatexCommand \index{\_\_interrupt}
9938
9939 \end_inset 
9940
9941  routines.
9942  By default, the compiler will place the stack after the last byte of allocated
9943  memory for variables.
9944  For example, if the first 2 banks of registers are used, and only four
9945  bytes are used for 
9946 \emph on 
9947 data
9948 \emph default 
9949  variables, it will position the base of the internal stack at address 20
9950  (0x14).
9951  This implies that as the stack
9952 \begin_inset LatexCommand \index{stack}
9953
9954 \end_inset 
9955
9956  grows, it will use up the remaining register banks, and the 16 bytes used
9957  by the 128 bit variables, and 80 bytes for general purpose use.
9958  If any bit variables are used, the data variables will be placed in unused
9959  register banks and after the byte holding the last bit variable.
9960  For example, if register banks 0 and 1 are used, and there are 9 bit variables
9961  (two bytes used), 
9962 \emph on 
9963 data
9964 \emph default 
9965  variables will be placed starting from address 0x10 to 0x20 and continue
9966  at address 0x22.
9967  You can also use -
9968 \begin_inset ERT
9969 status Collapsed
9970
9971 \layout Standard
9972
9973 \backslash 
9974 /
9975 \end_inset 
9976
9977 -data-loc
9978 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
9979
9980 \end_inset 
9981
9982  to specify the start address of the 
9983 \emph on 
9984 data
9985 \emph default 
9986  and -
9987 \begin_inset ERT
9988 status Collapsed
9989
9990 \layout Standard
9991
9992 \backslash 
9993 /
9994 \end_inset 
9995
9996 -iram-size
9997 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
9998
9999 \end_inset 
10000
10001  to specify the size of the total internal RAM (
10002 \emph on 
10003 data
10004 \emph default 
10005 +
10006 \emph on 
10007 idata
10008 \emph default 
10009 ).
10010  
10011 \layout Standard
10012
10013 By default the 8051 linker will place the stack after the last byte of (i)data
10014  variables.
10015  Option -
10016 \begin_inset ERT
10017 status Collapsed
10018
10019 \layout Standard
10020
10021 \backslash 
10022 /
10023 \end_inset 
10024
10025 -stack-loc
10026 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10027
10028 \end_inset 
10029
10030  allows you to specify the start of the stack, i.e.
10031  you could start it after any data in the general purpose area.
10032  If your microcontroller has additional indirectly addressable internal
10033  RAM (
10034 \emph on 
10035 idata
10036 \emph default 
10037 ) you can place the stack on it.
10038  You may also need to use -
10039 \begin_inset ERT
10040 status Collapsed
10041
10042 \layout Standard
10043
10044 \backslash 
10045 /
10046 \end_inset 
10047
10048 -xdata-loc
10049 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10050
10051 \end_inset 
10052
10053  to set the start address of the external RAM (
10054 \emph on 
10055 xdata
10056 \emph default 
10057 ) and -
10058 \begin_inset ERT
10059 status Collapsed
10060
10061 \layout Standard
10062
10063 \backslash 
10064 /
10065 \end_inset 
10066
10067 -xram-size
10068 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10069
10070 \end_inset 
10071
10072  to specify its size.
10073  Same goes for the code memory, using -
10074 \begin_inset ERT
10075 status Collapsed
10076
10077 \layout Standard
10078
10079 \backslash 
10080 /
10081 \end_inset 
10082
10083 -code-loc
10084 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10085
10086 \end_inset 
10087
10088  and -
10089 \begin_inset ERT
10090 status Collapsed
10091
10092 \layout Standard
10093
10094 \backslash 
10095 /
10096 \end_inset 
10097
10098 -code-size
10099 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10100
10101 \end_inset 
10102
10103 .
10104  If in doubt, don't specify any options and see if the resulting memory
10105  layout is appropriate, then you can adjust it.
10106 \layout Standard
10107
10108 The linker generates two files with memory allocation information.
10109  The first, with extension .map
10110 \begin_inset LatexCommand \index{<file>.map}
10111
10112 \end_inset 
10113
10114  shows all the variables and segments.
10115  The second with extension .mem
10116 \begin_inset LatexCommand \index{<file>.mem}
10117
10118 \end_inset 
10119
10120  shows the final memory layout.
10121  The linker will complain either if memory segments overlap, there is not
10122  enough memory, or there is not enough space for stack.
10123  If you get any linking warnings and/or errors related to stack or segments
10124  allocation, take a look at either the .map or .mem files to find out what
10125  the problem is.
10126  The .mem file may even suggest a solution to the problem.
10127 \layout Subsection
10128
10129 Z80/Z180 Storage Class
10130 \begin_inset LatexCommand \index{Storage class}
10131
10132 \end_inset 
10133
10134  Language Extensions
10135 \layout Subsubsection
10136
10137 sfr
10138 \begin_inset LatexCommand \index{sfr}
10139
10140 \end_inset 
10141
10142
10143 \begin_inset LatexCommand \index{\_\_sfr}
10144
10145 \end_inset 
10146
10147  (in/out to 8-bit addresses)
10148 \layout Standard
10149
10150 The Z80
10151 \begin_inset LatexCommand \index{Z80}
10152
10153 \end_inset 
10154
10155  family has separate address spaces for memory and 
10156 \emph on 
10157 i
10158 \emph default 
10159 nput/
10160 \emph on 
10161 o
10162 \emph default 
10163 utput memory.
10164  I/O memory
10165 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10166
10167 \end_inset 
10168
10169  is accessed with special instructions, e.g.:
10170 \layout Verse
10171
10172
10173 \family typewriter 
10174 sfr at 0x78 IoPort;\SpecialChar ~
10175 \SpecialChar ~
10176 /* define a var in I/O space at 78h called IoPort */
10177  
10178 \layout Standard
10179
10180 Writing 0x01 to this variable generates the assembly code:
10181 \layout Verse
10182
10183
10184 \family typewriter 
10185 3E 01\SpecialChar ~
10186 \SpecialChar ~
10187 \SpecialChar ~
10188 \SpecialChar ~
10189 \SpecialChar ~
10190 \SpecialChar ~
10191 ld a,#0x01
10192 \newline 
10193 D3 78\SpecialChar ~
10194 \SpecialChar ~
10195 \SpecialChar ~
10196 \SpecialChar ~
10197 \SpecialChar ~
10198 \SpecialChar ~
10199 out (_IoPort),a 
10200 \layout Subsubsection
10201
10202 banked sfr
10203 \begin_inset LatexCommand \index{sfr}
10204
10205 \end_inset 
10206
10207
10208 \begin_inset LatexCommand \index{\_\_sfr}
10209
10210 \end_inset 
10211
10212  (in/out to 16-bit addresses)
10213 \layout Standard
10214
10215 The keyword 
10216 \emph on 
10217 banked
10218 \emph default 
10219  is used to support 16 bit addresses in I/O memory e.g.:
10220 \layout Verse
10221
10222
10223 \family typewriter 
10224 sfr banked at
10225 \begin_inset LatexCommand \index{at}
10226
10227 \end_inset 
10228
10229
10230 \begin_inset LatexCommand \index{\_\_at}
10231
10232 \end_inset 
10233
10234  0x123 IoPort; 
10235 \layout Standard
10236
10237 Writing 0x01 to this variable generates the assembly code:
10238 \layout Verse
10239
10240
10241 \family typewriter 
10242 01 23 01\SpecialChar ~
10243 \SpecialChar ~
10244 \SpecialChar ~
10245 ld bc,#_IoPort
10246 \newline 
10247 3E 01\SpecialChar ~
10248 \SpecialChar ~
10249 \SpecialChar ~
10250 \SpecialChar ~
10251 \SpecialChar ~
10252 \SpecialChar ~
10253 ld a,#0x01 
10254 \newline 
10255 ED 79\SpecialChar ~
10256 \SpecialChar ~
10257 \SpecialChar ~
10258 \SpecialChar ~
10259 \SpecialChar ~
10260 \SpecialChar ~
10261 out (c),a 
10262 \layout Subsubsection
10263
10264 sfr
10265 \begin_inset LatexCommand \index{sfr}
10266
10267 \end_inset 
10268
10269
10270 \begin_inset LatexCommand \index{\_\_sfr}
10271
10272 \end_inset 
10273
10274  (in0/out0 to 8 bit addresses on Z180
10275 \begin_inset LatexCommand \index{Z180}
10276
10277 \end_inset 
10278
10279 /HD64180
10280 \begin_inset LatexCommand \index{HD64180}
10281
10282 \end_inset 
10283
10284 )
10285 \layout Standard
10286
10287 The compiler option -
10288 \begin_inset ERT
10289 status Collapsed
10290
10291 \layout Standard
10292
10293 \backslash 
10294 /
10295 \end_inset 
10296
10297 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
10298 portmode
10299 \begin_inset LatexCommand \index{\#pragma portmode}
10300
10301 \end_inset 
10302
10303 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10304 ns 
10305 \family typewriter 
10306 in0/out0
10307 \family default 
10308  instead of 
10309 \family typewriter 
10310 in/out
10311 \family default 
10312 .
10313  If you include the file z180.h this will be set automatically.
10314 \layout Subsection
10315
10316 HC08 Storage Class
10317 \begin_inset LatexCommand \index{Storage class}
10318
10319 \end_inset 
10320
10321  Language Extensions
10322 \layout Subsubsection
10323
10324 data
10325 \begin_inset LatexCommand \index{data (hc08 storage class)}
10326
10327 \end_inset 
10328
10329
10330 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10331
10332 \end_inset 
10333
10334  
10335 \layout Standard
10336
10337 The data storage class declares a variable that resides in the first 256
10338  bytes of memory (the direct page).
10339  The HC08 is most efficient at accessing variables (especially pointers)
10340  stored here.
10341 \layout Subsubsection
10342
10343 xdata
10344 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10345
10346 \end_inset 
10347
10348
10349 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10350
10351 \end_inset 
10352
10353  
10354 \layout Standard
10355
10356 The xdata storage class declares a variable that can reside anywhere in
10357  memory.
10358  This is the default if no storage class is specified.
10359  
10360 \layout Section
10361
10362 Absolute Addressing
10363 \begin_inset LatexCommand \index{Absolute addressing}
10364
10365 \end_inset 
10366
10367
10368 \layout Standard
10369
10370 Data items can be assigned an absolute address with the 
10371 \emph on 
10372 at
10373 \begin_inset LatexCommand \index{at}
10374
10375 \end_inset 
10376
10377
10378 \begin_inset LatexCommand \index{\_\_at}
10379
10380 \end_inset 
10381
10382  <address>
10383 \emph default 
10384  keyword, in addition to a storage class, e.g.:
10385 \layout Verse
10386
10387
10388 \family typewriter 
10389 xdata
10390 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10391
10392 \end_inset 
10393
10394
10395 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10396
10397 \end_inset 
10398
10399  at
10400 \begin_inset LatexCommand \index{at}
10401
10402 \end_inset 
10403
10404
10405 \begin_inset LatexCommand \index{\_\_at}
10406
10407 \end_inset 
10408
10409  0x7ffe unsigned int chksum;
10410 \layout Standard
10411
10412 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10413  of the external ram.
10414  The compiler does 
10415 \emph on 
10416 not
10417 \emph default 
10418  reserve any space for variables declared in this way (they are implemented
10419  with an equate in the assembler).
10420  Thus it is left to the programmer to make sure there are no overlaps with
10421  other variables that are declared without the absolute address.
10422  The assembler listing file (.lst
10423 \begin_inset LatexCommand \index{<file>.lst}
10424
10425 \end_inset 
10426
10427 ) and the linker output files (.rst
10428 \begin_inset LatexCommand \index{<file>.rst}
10429
10430 \end_inset 
10431
10432 ) and (.map
10433 \begin_inset LatexCommand \index{<file>.map}
10434
10435 \end_inset 
10436
10437 ) are good places to look for such overlaps.
10438  Variables with an absolute address are 
10439 \emph on 
10440 not
10441 \emph default 
10442  initialized
10443 \begin_inset LatexCommand \index{Variable initialization}
10444
10445 \end_inset 
10446
10447 .
10448 \layout Standard
10449
10450 In case of memory mapped I/O devices the keyword 
10451 \emph on 
10452 volatile
10453 \emph default 
10454  has to be used to tell the compiler that accesses might not be removed:
10455 \layout Verse
10456
10457
10458 \family typewriter 
10459 volatile
10460 \begin_inset LatexCommand \index{volatile}
10461
10462 \end_inset 
10463
10464  xdata
10465 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10466
10467 \end_inset 
10468
10469  at
10470 \begin_inset LatexCommand \index{at}
10471
10472 \end_inset 
10473
10474  0x8000 unsigned char PORTA_8255;
10475 \layout Standard
10476
10477 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10478 r) array
10479 \family typewriter 
10480 \size footnotesize 
10481
10482 \begin_inset LatexCommand \index{Aligned array}
10483
10484 \end_inset 
10485
10486
10487 \family default 
10488 \size default 
10489  starts at a block (256 byte) boundary
10490 \begin_inset LatexCommand \index{block boundary}
10491
10492 \end_inset 
10493
10494  (section 
10495 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10496
10497 \end_inset 
10498
10499  has an example).
10500 \newline 
10501 Absolute addresses can be specified for variables in all storage classes,
10502  e.g.:
10503 \layout Verse
10504
10505
10506 \family typewriter 
10507 bit
10508 \begin_inset LatexCommand \index{bit}
10509
10510 \end_inset 
10511
10512  at
10513 \begin_inset LatexCommand \index{at}
10514
10515 \end_inset 
10516
10517  0x02 bvar;
10518 \layout Standard
10519
10520 The above example will allocate the variable at offset 0x02 in the bit-addressab
10521 le space.
10522  There is no real advantage to assigning absolute addresses to variables
10523  in this manner, unless you want strict control over all the variables allocated.
10524  One possible use would be to write hardware portable code.
10525  For example, if you have a routine that uses one or more of the microcontroller
10526  I/O pins, and such pins are different for two different hardwares, you
10527  can declare the I/O pins in your routine using:
10528 \layout Verse
10529
10530
10531 \family typewriter 
10532 extern volatile
10533 \begin_inset LatexCommand \index{volatile}
10534
10535 \end_inset 
10536
10537  bit MOSI;\SpecialChar ~
10538 \SpecialChar ~
10539 \SpecialChar ~
10540 \SpecialChar ~
10541 /* master out, slave in */
10542 \newline 
10543 extern volatile bit MISO;\SpecialChar ~
10544 \SpecialChar ~
10545 \SpecialChar ~
10546 \SpecialChar ~
10547 /* master in, slave out */
10548 \newline 
10549 extern volatile bit MCLK;\SpecialChar ~
10550 \SpecialChar ~
10551 \SpecialChar ~
10552 \SpecialChar ~
10553 /* master clock */
10554 \newline 
10555
10556 \newline 
10557 /* Input and Output of a byte on a 3-wire serial bus.
10558 \newline 
10559 \SpecialChar ~
10560 \SpecialChar ~
10561 \SpecialChar ~
10562 If needed adapt polarity of clock, polarity of data and bit order
10563 \newline 
10564 \SpecialChar ~
10565 */
10566 \newline 
10567 unsigned char spi_io(unsigned char out_byte) 
10568 \newline 
10569
10570 \newline 
10571 \SpecialChar ~
10572 \SpecialChar ~
10573 \SpecialChar ~
10574 \SpecialChar ~
10575 unsigned char i=8;
10576 \newline 
10577 \SpecialChar ~
10578 \SpecialChar ~
10579 \SpecialChar ~
10580 \SpecialChar ~
10581 do { 
10582 \newline 
10583 \SpecialChar ~
10584 \SpecialChar ~
10585 \SpecialChar ~
10586 \SpecialChar ~
10587 \SpecialChar ~
10588 \SpecialChar ~
10589 \SpecialChar ~
10590 \SpecialChar ~
10591 MOSI = out_byte & 0x80; 
10592 \newline 
10593 \SpecialChar ~
10594 \SpecialChar ~
10595 \SpecialChar ~
10596 \SpecialChar ~
10597 \SpecialChar ~
10598 \SpecialChar ~
10599 \SpecialChar ~
10600 \SpecialChar ~
10601 out_byte <<= 1;
10602 \newline 
10603 \SpecialChar ~
10604 \SpecialChar ~
10605 \SpecialChar ~
10606 \SpecialChar ~
10607 \SpecialChar ~
10608 \SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 MCLK = 1; 
10612 \newline 
10613 \SpecialChar ~
10614 \SpecialChar ~
10615 \SpecialChar ~
10616 \SpecialChar ~
10617 \SpecialChar ~
10618 \SpecialChar ~
10619 \SpecialChar ~
10620 \SpecialChar ~
10621 /* _asm nop _endasm; */\SpecialChar ~
10622 \SpecialChar ~
10623 \SpecialChar ~
10624 \SpecialChar ~
10625 \SpecialChar ~
10626 \SpecialChar ~
10627 \SpecialChar ~
10628 \SpecialChar ~
10629 /* for slow peripherals */
10630 \newline 
10631 \SpecialChar ~
10632 \SpecialChar ~
10633 \SpecialChar ~
10634 \SpecialChar ~
10635 \SpecialChar ~
10636 \SpecialChar ~
10637 \SpecialChar ~
10638 \SpecialChar ~
10639 if(MISO) 
10640 \newline 
10641 \SpecialChar ~
10642 \SpecialChar ~
10643 \SpecialChar ~
10644 \SpecialChar ~
10645 \SpecialChar ~
10646 \SpecialChar ~
10647 \SpecialChar ~
10648 \SpecialChar ~
10649 \SpecialChar ~
10650 \SpecialChar ~
10651 \SpecialChar ~
10652 \SpecialChar ~
10653 out_byte += 1; 
10654 \newline 
10655 \SpecialChar ~
10656 \SpecialChar ~
10657 \SpecialChar ~
10658 \SpecialChar ~
10659 \SpecialChar ~
10660 \SpecialChar ~
10661 \SpecialChar ~
10662 \SpecialChar ~
10663 MCLK = 0; 
10664 \newline 
10665 \SpecialChar ~
10666 \SpecialChar ~
10667 \SpecialChar ~
10668 \SpecialChar ~
10669 } while(--i);
10670 \newline 
10671 \SpecialChar ~
10672 \SpecialChar ~
10673 \SpecialChar ~
10674 \SpecialChar ~
10675 return out_byte; 
10676 \newline 
10677 }
10678 \layout Standard
10679
10680 Then, someplace in the code for the first hardware you would use
10681 \layout Verse
10682
10683
10684 \family typewriter 
10685 bit at
10686 \begin_inset LatexCommand \index{at}
10687
10688 \end_inset 
10689
10690
10691 \begin_inset LatexCommand \index{\_\_at}
10692
10693 \end_inset 
10694
10695  0x80 MOSI;\SpecialChar ~
10696 \SpecialChar ~
10697 \SpecialChar ~
10698 \SpecialChar ~
10699 /* I/O port 0, bit 0 */
10700 \newline 
10701 bit at 0x81 MISO;\SpecialChar ~
10702 \SpecialChar ~
10703 \SpecialChar ~
10704 \SpecialChar ~
10705 /* I/O port 0, bit 1 */
10706 \newline 
10707 bit at 0x82 MCLK;\SpecialChar ~
10708 \SpecialChar ~
10709 \SpecialChar ~
10710 \SpecialChar ~
10711 /* I/O port 0, bit 2 */
10712 \layout Standard
10713
10714 Similarly, for the second hardware you would use
10715 \layout Verse
10716
10717
10718 \family typewriter 
10719 bit at 0x83 MOSI;\SpecialChar ~
10720 \SpecialChar ~
10721 \SpecialChar ~
10722 \SpecialChar ~
10723 /* I/O port 0, bit 3 */
10724 \newline 
10725 bit at 0x91 MISO;\SpecialChar ~
10726 \SpecialChar ~
10727 \SpecialChar ~
10728 \SpecialChar ~
10729 /* I/O port 1, bit 1 */
10730 \newline 
10731 bit
10732 \begin_inset LatexCommand \index{bit}
10733
10734 \end_inset 
10735
10736  at 0x92 MCLK;\SpecialChar ~
10737 \SpecialChar ~
10738 \SpecialChar ~
10739 \SpecialChar ~
10740 /* I/O port 1, bit 2 */
10741 \layout Standard
10742
10743 and you can use the same hardware dependent routine without changes, as
10744  for example in a library.
10745  This is somehow similar to sbit, but only one absolute address has to be
10746  specified in the whole project.
10747 \layout Section
10748
10749 Parameters
10750 \begin_inset LatexCommand \index{Parameters}
10751
10752 \end_inset 
10753
10754
10755 \begin_inset LatexCommand \index{function parameter}
10756
10757 \end_inset 
10758
10759  & Local Variables
10760 \begin_inset LatexCommand \index{local variables}
10761
10762 \end_inset 
10763
10764
10765 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
10766
10767 \end_inset 
10768
10769
10770 \layout Standard
10771
10772 Automatic (local) variables and parameters to functions can either be placed
10773  on the stack or in data-space.
10774  The default action of the compiler is to place these variables in the internal
10775  RAM (for small model) or external RAM (for large model).
10776  This in fact makes them similar to 
10777 \emph on 
10778 static
10779 \begin_inset LatexCommand \index{static}
10780
10781 \end_inset 
10782
10783
10784 \emph default 
10785  so by default functions are non-reentrant
10786 \begin_inset LatexCommand \index{reentrant}
10787
10788 \end_inset 
10789
10790 .
10791  
10792 \newline 
10793
10794 \newline 
10795 They can be placed on the stack
10796 \begin_inset LatexCommand \index{stack}
10797
10798 \end_inset 
10799
10800  by using the
10801 \emph on 
10802  -
10803 \begin_inset ERT
10804 status Collapsed
10805
10806 \layout Standard
10807
10808 \backslash 
10809 /
10810 \end_inset 
10811
10812 -stack-auto
10813 \begin_inset LatexCommand \index{-\/-stack-auto}
10814
10815 \end_inset 
10816
10817
10818 \emph default 
10819  option, by using 
10820 \emph on 
10821 #pragma\SpecialChar ~
10822 stackauto
10823 \emph default 
10824
10825 \begin_inset LatexCommand \index{\#pragma stackauto}
10826
10827 \end_inset 
10828
10829  or by using the 
10830 \emph on 
10831 reentrant
10832 \begin_inset LatexCommand \index{reentrant}
10833
10834 \end_inset 
10835
10836
10837 \emph default 
10838  keyword in the function declaration, e.g.:
10839 \layout Verse
10840
10841
10842 \family typewriter 
10843 unsigned char foo(char i) reentrant 
10844 \newline 
10845
10846 \newline 
10847 \SpecialChar ~
10848 \SpecialChar ~
10849 \SpecialChar ~
10850 \SpecialChar ~
10851 ...
10852  
10853 \newline 
10854 }
10855 \layout Standard
10856
10857 Since stack space on 8051 is limited, the 
10858 \emph on 
10859 reentrant 
10860 \emph default 
10861 keyword or the
10862 \emph on 
10863  -
10864 \begin_inset ERT
10865 status Collapsed
10866
10867 \layout Standard
10868
10869 \backslash 
10870 /
10871 \end_inset 
10872
10873 -stack-auto
10874 \emph default 
10875  option should be used sparingly.
10876  Note that the reentrant keyword just means that the parameters & local
10877  variables will be allocated to the stack, it 
10878 \emph on 
10879 does not
10880 \emph default 
10881  mean that the function is register bank
10882 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10883
10884 \end_inset 
10885
10886  independent.
10887 \newline 
10888
10889 \newline 
10890 Local variables
10891 \begin_inset LatexCommand \index{local variables}
10892
10893 \end_inset 
10894
10895  can be assigned storage classes and absolute
10896 \begin_inset LatexCommand \index{Absolute addressing}
10897
10898 \end_inset 
10899
10900  addresses, e.g.: 
10901 \layout Verse
10902
10903
10904 \family typewriter 
10905 unsigned char foo() 
10906 \newline 
10907 {
10908 \newline 
10909 \SpecialChar ~
10910 \SpecialChar ~
10911 \SpecialChar ~
10912 \SpecialChar ~
10913 xdata unsigned char i;
10914 \newline 
10915 \SpecialChar ~
10916 \SpecialChar ~
10917 \SpecialChar ~
10918 \SpecialChar ~
10919 bit bvar;
10920 \newline 
10921 \SpecialChar ~
10922 \SpecialChar ~
10923 \SpecialChar ~
10924 \SpecialChar ~
10925 data at
10926 \begin_inset LatexCommand \index{at}
10927
10928 \end_inset 
10929
10930  0x31 unsigned char j;
10931 \newline 
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 \SpecialChar ~
10935 \SpecialChar ~
10936 ...
10937  
10938 \newline 
10939 }
10940 \layout Standard
10941
10942 In the above example the variable 
10943 \emph on 
10944 i
10945 \emph default 
10946  will be allocated in the external ram, 
10947 \emph on 
10948 bvar
10949 \emph default 
10950  in bit addressable space and
10951 \emph on 
10952  j
10953 \emph default 
10954  in internal ram.
10955  When compiled with 
10956 \emph on 
10957 -
10958 \begin_inset ERT
10959 status Collapsed
10960
10961 \layout Standard
10962
10963 \backslash 
10964 /
10965 \end_inset 
10966
10967 -stack-auto
10968 \emph default 
10969  or when a function is declared as 
10970 \emph on 
10971 reentrant
10972 \emph default 
10973  this should only be done for static variables.
10974 \layout Standard
10975
10976 Parameters
10977 \begin_inset LatexCommand \index{function parameter}
10978
10979 \end_inset 
10980
10981  however are not allowed any storage class
10982 \begin_inset LatexCommand \index{Storage class}
10983
10984 \end_inset 
10985
10986 , (storage classes for parameters will be ignored), their allocation is
10987  governed by the memory model in use, and the reentrancy options.
10988 \layout Standard
10989
10990 It is however allowed to use bit parameters in reentrant functions and also
10991  non-static local bit variables are supported.
10992  Efficient use is limited to 8 semi-bitregisters in bit space.
10993  They are pushed and popped to stack as a single byte just like the normal
10994  registers.
10995 \layout Section
10996
10997 Overlaying
10998 \begin_inset LatexCommand \label{sub:Overlaying}
10999
11000 \end_inset 
11001
11002
11003 \begin_inset LatexCommand \index{Overlaying}
11004
11005 \end_inset 
11006
11007
11008 \layout Standard
11009
11010 For non-reentrant
11011 \begin_inset LatexCommand \index{reentrant}
11012
11013 \end_inset 
11014
11015  functions SDCC will try to reduce internal ram space usage by overlaying
11016  parameters and local variables of a function (if possible).
11017  Parameters and local variables
11018 \begin_inset LatexCommand \index{local variables}
11019
11020 \end_inset 
11021
11022  of a function will be allocated to an overlayable segment if the function
11023  has 
11024 \emph on 
11025 no other function calls and the function is non-reentrant and the memory
11026  model
11027 \begin_inset LatexCommand \index{Memory model}
11028
11029 \end_inset 
11030
11031  is small.
11032
11033 \emph default 
11034  If an explicit storage class
11035 \begin_inset LatexCommand \index{Storage class}
11036
11037 \end_inset 
11038
11039  is specified for a local variable, it will NOT be overlayed.
11040 \layout Standard
11041
11042 Note that the compiler (not the linkage editor) makes the decision for overlayin
11043 g the data items.
11044  Functions that are called from an interrupt service routine should be preceded
11045  by a #pragma\SpecialChar ~
11046 nooverlay
11047 \begin_inset LatexCommand \index{\#pragma nooverlay}
11048
11049 \end_inset 
11050
11051  if they are not reentrant.
11052 \layout Standard
11053
11054 Also note that the compiler does not do any processing of inline assembler
11055  code, so the compiler might incorrectly assign local variables and parameters
11056  of a function into the overlay segment if the inline assembler code calls
11057  other c-functions that might use the overlay.
11058  In that case the #pragma\SpecialChar ~
11059 nooverlay should be used.
11060 \layout Standard
11061
11062 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11063 tion
11064 \begin_inset LatexCommand \index{Multiplication}
11065
11066 \end_inset 
11067
11068  or division
11069 \begin_inset LatexCommand \index{Division}
11070
11071 \end_inset 
11072
11073  will NOT be overlayed since these are implemented using external functions,
11074  e.g.:
11075 \layout Verse
11076
11077
11078 \family typewriter 
11079 #pragma save 
11080 \newline 
11081 #pragma nooverlay
11082 \begin_inset LatexCommand \index{\#pragma nooverlay}
11083
11084 \end_inset 
11085
11086  
11087 \newline 
11088 void set_error(unsigned char errcd) 
11089 \newline 
11090 {
11091 \newline 
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 \SpecialChar ~
11095 \SpecialChar ~
11096 P3 = errcd;
11097 \newline 
11098
11099 \newline 
11100 #pragma restore 
11101 \newline 
11102
11103 \newline 
11104 void some_isr () interrupt
11105 \begin_inset LatexCommand \index{interrupt}
11106
11107 \end_inset 
11108
11109  2
11110 \newline 
11111 {
11112 \newline 
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 ...
11118 \newline 
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 set_error(10);
11124 \newline 
11125 \SpecialChar ~
11126 \SpecialChar ~
11127 \SpecialChar ~
11128 \SpecialChar ~
11129 ...
11130  
11131 \newline 
11132 }
11133 \layout Standard
11134
11135 In the above example the parameter 
11136 \emph on 
11137 errcd
11138 \emph default 
11139  for the function 
11140 \emph on 
11141 set_error
11142 \emph default 
11143  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11144 nooverlay was
11145  not present, this could cause unpredictable runtime behavior when called
11146  from an interrupt service routine.
11147  The #pragma\SpecialChar ~
11148 nooverlay ensures that the parameters and local variables for
11149  the function are NOT overlayed.
11150 \layout Section
11151
11152 Interrupt Service Routines
11153 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11154
11155 \end_inset 
11156
11157
11158 \layout Subsection
11159
11160 General Information
11161 \layout Standard
11162
11163 SDCC allows 
11164 \emph on 
11165 i
11166 \emph default 
11167 nterrupt 
11168 \emph on 
11169 s
11170 \emph default 
11171 ervice 
11172 \emph on 
11173 r
11174 \emph default 
11175 outines to be coded in C, with some extended keywords.
11176 \layout Verse
11177
11178
11179 \family typewriter 
11180 void timer_isr (void) interrupt 1 using 1 
11181 \newline 
11182
11183 \newline 
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 \SpecialChar ~
11187 \SpecialChar ~
11188 ...
11189  
11190 \newline 
11191 }
11192 \layout Standard
11193
11194 The optional number following the 
11195 \emph on 
11196 interrupt
11197 \begin_inset LatexCommand \index{interrupt}
11198
11199 \end_inset 
11200
11201
11202 \begin_inset LatexCommand \index{\_\_interrupt}
11203
11204 \end_inset 
11205
11206
11207 \emph default 
11208  keyword is the interrupt number this routine will service.
11209  When present, the compiler will insert a call to this routine in the interrupt
11210  vector table for the interrupt number specified.
11211  If you have multiple source files in your project, interrupt service routines
11212  can be present in any of them, but a prototype of the isr MUST be present
11213  or included in the file that contains the function 
11214 \emph on 
11215 main
11216 \emph default 
11217 .
11218  The optional 
11219 \emph on 
11220 using
11221 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11222
11223 \end_inset 
11224
11225
11226 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11227
11228 \end_inset 
11229
11230
11231 \emph default 
11232  keyword can be used to tell the compiler to use the specified register
11233  bank (8051 specific) when generating code for this function.
11234  
11235 \newline 
11236
11237 \layout Standard
11238
11239 Interrupt service routines open the door for some very interesting bugs:
11240 \newline 
11241 If an interrupt service routine changes variables which are accessed by
11242  other functions these variables have to be declared 
11243 \emph on 
11244 volatile
11245 \emph default 
11246
11247 \begin_inset LatexCommand \index{volatile}
11248
11249 \end_inset 
11250
11251 .
11252  
11253 \layout Standard
11254
11255 If the access to these variables is not 
11256 \emph on 
11257 atomic
11258 \begin_inset LatexCommand \index{atomic}
11259
11260 \end_inset 
11261
11262
11263 \emph default 
11264  (i.e.
11265  the processor needs more than one instruction for the access and could
11266  be interrupted while accessing the variable) the interrupt must be disabled
11267  during the access to avoid inconsistent data.
11268  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
11269  and should be protected by disabling interrupts.
11270  You're not automatically on the safe side if you use 8 bit variables though.
11271  We need an example here: f.e.
11272  on the 8051 the harmless looking 
11273 \begin_inset Quotes srd
11274 \end_inset 
11275
11276
11277 \family typewriter 
11278 flags\SpecialChar ~
11279 |=\SpecialChar ~
11280 0x80;
11281 \family default 
11282
11283 \begin_inset Quotes sld
11284 \end_inset 
11285
11286  is not atomic if 
11287 \family typewriter 
11288 flags
11289 \family default 
11290  resides in xdata.
11291  Setting 
11292 \begin_inset Quotes srd
11293 \end_inset 
11294
11295
11296 \family typewriter 
11297 flags\SpecialChar ~
11298 |=\SpecialChar ~
11299 0x40;
11300 \family default 
11301
11302 \begin_inset Quotes sld
11303 \end_inset 
11304
11305  from within an interrupt routine might get lost if the interrupt occurs
11306  at the wrong time.
11307  
11308 \begin_inset Quotes sld
11309 \end_inset 
11310
11311
11312 \family typewriter 
11313 counter\SpecialChar ~
11314 +=\SpecialChar ~
11315 8;
11316 \family default 
11317
11318 \begin_inset Quotes srd
11319 \end_inset 
11320
11321  is not atomic on the 8051 even if 
11322 \family typewriter 
11323 counter
11324 \family default 
11325  is located in data memory.
11326  Bugs like these are hard to reproduce and can cause a lot of trouble.
11327  
11328 \layout Standard
11329
11330 The return address and the registers used in the interrupt service routine
11331  are saved on the stack
11332 \begin_inset LatexCommand \index{stack}
11333
11334 \end_inset 
11335
11336  so there must be sufficient stack space.
11337  If there isn't variables or registers (or even the return address itself)
11338  will be corrupted.
11339  This 
11340 \emph on 
11341 stack overflow
11342 \emph default 
11343
11344 \begin_inset LatexCommand \index{stack overflow}
11345
11346 \end_inset 
11347
11348  is most likely to happen if the interrupt occurs during the 
11349 \begin_inset Quotes sld
11350 \end_inset 
11351
11352 deepest
11353 \begin_inset Quotes srd
11354 \end_inset 
11355
11356  subroutine when the stack is already in use for f.e.
11357  many return addresses.
11358 \layout Standard
11359
11360 A special note here, int (16 bit) and long (32 bit) integer division
11361 \begin_inset LatexCommand \index{Division}
11362
11363 \end_inset 
11364
11365 , multiplication
11366 \begin_inset LatexCommand \index{Multiplication}
11367
11368 \end_inset 
11369
11370  & modulus
11371 \begin_inset LatexCommand \index{Modulus}
11372
11373 \end_inset 
11374
11375  and floating-point
11376 \begin_inset LatexCommand \index{Floating point support}
11377
11378 \end_inset 
11379
11380  operations are implemented using external support routines developed in
11381  ANSI-C.
11382  If an interrupt service routine needs to do any of these operations then
11383  the support routines (as mentioned in a following section) will have to
11384  be recompiled using the
11385 \emph on 
11386  -
11387 \begin_inset ERT
11388 status Collapsed
11389
11390 \layout Standard
11391
11392 \backslash 
11393 /
11394 \end_inset 
11395
11396 -stack-auto
11397 \begin_inset LatexCommand \index{-\/-stack-auto}
11398
11399 \end_inset 
11400
11401
11402 \emph default 
11403  option and the source file will need to be compiled using the 
11404 \emph on 
11405 -
11406 \begin_inset ERT
11407 status Collapsed
11408
11409 \layout Standard
11410
11411 \backslash 
11412 /
11413 \end_inset 
11414
11415 -int-long-reent
11416 \emph default 
11417
11418 \begin_inset LatexCommand \index{-\/-int-long-reent}
11419
11420 \end_inset 
11421
11422  compiler option.
11423 \layout Standard
11424
11425 Calling other functions from an interrupt service routine is not recommended,
11426  avoid it if possible.
11427  Note that when some function is called from an interrupt service routine
11428  it should be preceded by a #pragma\SpecialChar ~
11429 nooverlay
11430 \begin_inset LatexCommand \index{\#pragma nooverlay}
11431
11432 \end_inset 
11433
11434  if it is not reentrant.
11435  Furthermore nonreentrant functions should not be called from the main program
11436  while the interrupt service routine might be active.
11437  They also must not be called from low priority interrupt service routines
11438  while a high priority interrupt service routine might be active.
11439  You could use semaphores or make the function
11440 \emph on 
11441  critical
11442 \emph default 
11443  if all parameters are passed in registers.
11444 \newline 
11445
11446 \newline 
11447 Also see section 
11448 \begin_inset LatexCommand \ref{sub:Overlaying}
11449
11450 \end_inset 
11451
11452 \SpecialChar ~
11453 about Overlaying and section 
11454 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11455
11456 \end_inset 
11457
11458 \SpecialChar ~
11459 about Functions using private register banks.
11460 \layout Subsection
11461
11462 MCS51/DS390 Interrupt Service Routines
11463 \layout Standard
11464
11465 Interrupt numbers and the corresponding address & descriptions for the Standard
11466  8051/8052 are listed below.
11467  SDCC will automatically adjust the interrupt vector table to the maximum
11468  interrupt number specified.
11469 \newline 
11470
11471 \layout Standard
11472 \align center 
11473
11474 \begin_inset  Tabular
11475 <lyxtabular version="3" rows="7" columns="3">
11476 <features>
11477 <column alignment="center" valignment="top" leftline="true" width="0in">
11478 <column alignment="center" valignment="top" leftline="true" width="0in">
11479 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
11480 <row topline="true" bottomline="true">
11481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11482 \begin_inset Text
11483
11484 \layout Standard
11485
11486 Interrupt #
11487 \end_inset 
11488 </cell>
11489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11490 \begin_inset Text
11491
11492 \layout Standard
11493
11494 Description
11495 \end_inset 
11496 </cell>
11497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11498 \begin_inset Text
11499
11500 \layout Standard
11501
11502 Vector Address
11503 \end_inset 
11504 </cell>
11505 </row>
11506 <row topline="true">
11507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11508 \begin_inset Text
11509
11510 \layout Standard
11511
11512 0
11513 \end_inset 
11514 </cell>
11515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11516 \begin_inset Text
11517
11518 \layout Standard
11519
11520 External 0
11521 \end_inset 
11522 </cell>
11523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11524 \begin_inset Text
11525
11526 \layout Standard
11527
11528 0x0003
11529 \end_inset 
11530 </cell>
11531 </row>
11532 <row topline="true">
11533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11534 \begin_inset Text
11535
11536 \layout Standard
11537
11538 1
11539 \end_inset 
11540 </cell>
11541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11542 \begin_inset Text
11543
11544 \layout Standard
11545
11546 Timer 0
11547 \end_inset 
11548 </cell>
11549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11550 \begin_inset Text
11551
11552 \layout Standard
11553
11554 0x000B
11555 \end_inset 
11556 </cell>
11557 </row>
11558 <row topline="true">
11559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11560 \begin_inset Text
11561
11562 \layout Standard
11563
11564 2
11565 \end_inset 
11566 </cell>
11567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11568 \begin_inset Text
11569
11570 \layout Standard
11571
11572 External 1
11573 \end_inset 
11574 </cell>
11575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11576 \begin_inset Text
11577
11578 \layout Standard
11579
11580 0x0013
11581 \end_inset 
11582 </cell>
11583 </row>
11584 <row topline="true">
11585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11586 \begin_inset Text
11587
11588 \layout Standard
11589
11590 3
11591 \end_inset 
11592 </cell>
11593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11594 \begin_inset Text
11595
11596 \layout Standard
11597
11598 Timer 1
11599 \end_inset 
11600 </cell>
11601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11602 \begin_inset Text
11603
11604 \layout Standard
11605
11606 0x001B
11607 \end_inset 
11608 </cell>
11609 </row>
11610 <row topline="true">
11611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11612 \begin_inset Text
11613
11614 \layout Standard
11615
11616 4
11617 \end_inset 
11618 </cell>
11619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11620 \begin_inset Text
11621
11622 \layout Standard
11623
11624 Serial
11625 \end_inset 
11626 </cell>
11627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11628 \begin_inset Text
11629
11630 \layout Standard
11631
11632 0x0023
11633 \end_inset 
11634 </cell>
11635 </row>
11636 <row topline="true" bottomline="true">
11637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11638 \begin_inset Text
11639
11640 \layout Standard
11641
11642 5
11643 \end_inset 
11644 </cell>
11645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11646 \begin_inset Text
11647
11648 \layout Standard
11649
11650 Timer 2 (8052)
11651 \end_inset 
11652 </cell>
11653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11654 \begin_inset Text
11655
11656 \layout Standard
11657
11658 0x002B
11659 \end_inset 
11660 </cell>
11661 </row>
11662 </lyxtabular>
11663
11664 \end_inset 
11665
11666
11667 \newline 
11668
11669 \layout Standard
11670
11671 If the interrupt service routine is defined without 
11672 \emph on 
11673 using
11674 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11675
11676 \end_inset 
11677
11678
11679 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11680
11681 \end_inset 
11682
11683
11684 \emph default 
11685  a register bank or with register bank 0 (
11686 \emph on 
11687 using
11688 \emph default 
11689  0), the compiler will save the registers used by itself on the stack upon
11690  entry and restore them at exit, however if such an interrupt service routine
11691  calls another function then the entire register bank will be saved on the
11692  stack.
11693  This scheme may be advantageous for small interrupt service routines which
11694  have low register usage.
11695 \layout Standard
11696
11697 If the interrupt service routine is defined to be using a specific register
11698  bank then only 
11699 \emph on 
11700 a, b, dptr
11701 \emph default 
11702  & psw are saved and restored, if such an interrupt service routine calls
11703  another function (using another register bank) then the entire register
11704  bank of the called function will be saved on the stack.
11705  This scheme is recommended for larger interrupt service routines.
11706 \layout Subsection
11707
11708 HC08 Interrupt Service Routines
11709 \layout Standard
11710
11711 Since the number of interrupts available is chip specific and the interrupt
11712  vector table always ends at the last byte of memory, the interrupt numbers
11713  corresponds to the interrupt vectors in reverse order of address.
11714  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
11715  2 will use the interrupt vector at 0xfffa, and so on.
11716  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
11717  this way; instead see section 
11718 \begin_inset LatexCommand \ref{sub:Startup-Code}
11719
11720 \end_inset 
11721
11722  for details on customizing startup.
11723 \layout Subsection
11724
11725 Z80 Interrupt Service Routines
11726 \layout Standard
11727
11728 The Z80 uses several different methods for determining the correct interrupt
11729  vector depending on the hardware implementation.
11730  Therefore, SDCC ignores the optional interrupt number and does not attempt
11731  to generate an interrupt vector table.
11732 \layout Standard
11733
11734 By default, SDCC generates code for a maskable interrupt, which uses a RETI
11735  instruction to return from the interrupt.
11736  To write an interrupt handler for the non-maskable interrupt, which needs
11737  a RETN instruction instead, add the 
11738 \emph on 
11739 critical
11740 \emph default 
11741  keyword:
11742 \layout Verse
11743
11744
11745 \family typewriter 
11746 void nmi_isr (void) critical interrupt
11747 \newline 
11748
11749 \newline 
11750 \SpecialChar ~
11751 \SpecialChar ~
11752 \SpecialChar ~
11753 \SpecialChar ~
11754 ...
11755  
11756 \newline 
11757 }
11758 \layout Standard
11759
11760 However if you need to create a non-interruptable interrupt service routine
11761  you would also require the 
11762 \emph on 
11763 critical
11764 \emph default 
11765  keyword.
11766  To distinguish between this and an nmi_isr you must provide an interrupt
11767  number.
11768 \layout Section
11769
11770 Enabling and Disabling Interrupts
11771 \layout Subsection
11772
11773 Critical Functions and Critical Statements
11774 \layout Standard
11775
11776 A special keyword may be associated with a block or a function declaring
11777  it as 
11778 \emph on 
11779 critical
11780 \emph default 
11781 .
11782  SDCC will generate code to disable all interrupts
11783 \begin_inset LatexCommand \index{interrupt}
11784
11785 \end_inset 
11786
11787  upon entry to a critical function and restore the interrupt enable to the
11788  previous state before returning.
11789  Nesting critical functions will need one additional byte on the stack
11790 \begin_inset LatexCommand \index{stack}
11791
11792 \end_inset 
11793
11794  for each call.
11795 \layout Verse
11796
11797
11798 \family typewriter 
11799 int foo () critical
11800 \begin_inset LatexCommand \index{critical}
11801
11802 \end_inset 
11803
11804
11805 \begin_inset LatexCommand \index{\_\_critical}
11806
11807 \end_inset 
11808
11809  
11810 \newline 
11811
11812 \newline 
11813 \SpecialChar ~
11814 \SpecialChar ~
11815 \SpecialChar ~
11816 \SpecialChar ~
11817 ...
11818  
11819 \newline 
11820 \SpecialChar ~
11821 \SpecialChar ~
11822 \SpecialChar ~
11823 \SpecialChar ~
11824 ...
11825  
11826 \newline 
11827 }
11828 \layout Standard
11829
11830 The critical attribute maybe used with other attributes like 
11831 \emph on 
11832 reentrant.
11833 \emph default 
11834
11835 \newline 
11836 The keyword 
11837 \emph on 
11838 critical
11839 \emph default 
11840  may also be used to disable interrupts more locally:
11841 \layout Verse
11842
11843
11844 \family typewriter 
11845 critical{ i++; }
11846 \layout Standard
11847
11848 More than one statement could have been included in the block.
11849 \layout Subsection
11850
11851 Enabling and Disabling Interrupts directly
11852 \layout Standard
11853
11854 Interrupts
11855 \begin_inset LatexCommand \index{interrupt}
11856
11857 \end_inset 
11858
11859  can also be disabled and enabled directly (8051):
11860 \layout Verse
11861
11862
11863 \family typewriter 
11864 EA = 0;\SpecialChar ~
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 \SpecialChar ~
11868 \SpecialChar ~
11869 \SpecialChar ~
11870 \SpecialChar ~
11871 \SpecialChar ~
11872 \SpecialChar ~
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 \SpecialChar ~
11876 or:\SpecialChar ~
11877 \SpecialChar ~
11878 \SpecialChar ~
11879 \SpecialChar ~
11880 \SpecialChar ~
11881 \SpecialChar ~
11882 \SpecialChar ~
11883 \SpecialChar ~
11884 \SpecialChar ~
11885 \SpecialChar ~
11886 \SpecialChar ~
11887 EA_SAVE = EA;
11888 \layout Verse
11889
11890
11891 \family typewriter 
11892 ...\SpecialChar ~
11893 \SpecialChar ~
11894 \SpecialChar ~
11895 \SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 \SpecialChar ~
11899 \SpecialChar ~
11900 \SpecialChar ~
11901 \SpecialChar ~
11902 \SpecialChar ~
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 \SpecialChar ~
11908 \SpecialChar ~
11909 \SpecialChar ~
11910 \SpecialChar ~
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 \SpecialChar ~
11914 \SpecialChar ~
11915 \SpecialChar ~
11916 \SpecialChar ~
11917 \SpecialChar ~
11918 \SpecialChar ~
11919 \SpecialChar ~
11920 \SpecialChar ~
11921 \SpecialChar ~
11922 EA = 0;
11923 \layout Verse
11924
11925
11926 \family typewriter 
11927 EA = 1;\SpecialChar ~
11928 \SpecialChar ~
11929 \SpecialChar ~
11930 \SpecialChar ~
11931 \SpecialChar ~
11932 \SpecialChar ~
11933 \SpecialChar ~
11934 \SpecialChar ~
11935 \SpecialChar ~
11936 \SpecialChar ~
11937 \SpecialChar ~
11938 \SpecialChar ~
11939 \SpecialChar ~
11940 \SpecialChar ~
11941 \SpecialChar ~
11942 \SpecialChar ~
11943 \SpecialChar ~
11944 \SpecialChar ~
11945 \SpecialChar ~
11946 \SpecialChar ~
11947 \SpecialChar ~
11948 \SpecialChar ~
11949 \SpecialChar ~
11950 \SpecialChar ~
11951 \SpecialChar ~
11952 \SpecialChar ~
11953 ...
11954 \layout Verse
11955
11956
11957 \family typewriter 
11958 \SpecialChar ~
11959 \SpecialChar ~
11960 \SpecialChar ~
11961 \SpecialChar ~
11962 \SpecialChar ~
11963 \SpecialChar ~
11964 \SpecialChar ~
11965 \SpecialChar ~
11966 \SpecialChar ~
11967 \SpecialChar ~
11968 \SpecialChar ~
11969 \SpecialChar ~
11970 \SpecialChar ~
11971 \SpecialChar ~
11972 \SpecialChar ~
11973 \SpecialChar ~
11974 \SpecialChar ~
11975 \SpecialChar ~
11976 \SpecialChar ~
11977 \SpecialChar ~
11978 \SpecialChar ~
11979 \SpecialChar ~
11980 \SpecialChar ~
11981 \SpecialChar ~
11982 \SpecialChar ~
11983 \SpecialChar ~
11984 \SpecialChar ~
11985 \SpecialChar ~
11986 \SpecialChar ~
11987 \SpecialChar ~
11988 \SpecialChar ~
11989 \SpecialChar ~
11990 \SpecialChar ~
11991 EA = EA_SAVE;
11992 \layout Standard
11993
11994 On other architectures which have seperate opcodes for enabling and disabling
11995  interrupts you might want to make use of defines with inline assembly
11996 \begin_inset LatexCommand \index{Assembler routines}
11997
11998 \end_inset 
11999
12000  (HC08):
12001 \layout Verse
12002
12003
12004 \family typewriter 
12005 #define CLI _asm
12006 \begin_inset LatexCommand \index{\_asm}
12007
12008 \end_inset 
12009
12010 \SpecialChar ~
12011 \SpecialChar ~
12012 cli\SpecialChar ~
12013 \SpecialChar ~
12014 _endasm
12015 \begin_inset LatexCommand \index{\_endasm}
12016
12017 \end_inset 
12018
12019
12020 \layout Verse
12021
12022
12023 \family typewriter 
12024 #define SEI _asm\SpecialChar ~
12025 \SpecialChar ~
12026 sei\SpecialChar ~
12027 \SpecialChar ~
12028 _endasm; 
12029 \layout Verse
12030
12031
12032 \family typewriter 
12033 ...
12034 \layout Standard
12035
12036 Note: it is sometimes sufficient to disable only a specific interrupt source
12037  like f.e.
12038  a timer or serial interrupt by manipulating an 
12039 \emph on 
12040 interrupt mask
12041 \begin_inset LatexCommand \index{interrupt mask}
12042
12043 \end_inset 
12044
12045
12046 \emph default 
12047  register.
12048  
12049 \layout Standard
12050
12051 Usually the time during which interrupts are disabled should be kept as
12052  short as possible.
12053  This minimizes both 
12054 \emph on 
12055 interrupt latency
12056 \emph default 
12057
12058 \begin_inset LatexCommand \index{interrupt latency}
12059
12060 \end_inset 
12061
12062  (the time between the occurrence of the interrupt and the execution of
12063  the first code in the interrupt routine) and 
12064 \emph on 
12065 interrupt jitter
12066 \emph default 
12067
12068 \begin_inset LatexCommand \index{interrupt jitter}
12069
12070 \end_inset 
12071
12072  (the difference between the shortest and the longest interrupt latency).
12073  These really are something different, f.e.
12074  a serial interrupt has to be served before its buffer overruns so it cares
12075  for the maximum interrupt latency, whereas it does not care about jitter.
12076  On a loudspeaker driven via a digital to analog converter which is fed
12077  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12078  a much smaller jitter will be very audible.
12079 \layout Standard
12080
12081 You can reenable interrupts within an interrupt routine and on some architecture
12082 s you can make use of two (or more) levels of 
12083 \emph on 
12084 interrupt priorities
12085 \emph default 
12086
12087 \begin_inset LatexCommand \index{interrupt priority}
12088
12089 \end_inset 
12090
12091 .
12092  On some architectures which don't support interrupt priorities these can
12093  be implemented by manipulating the interrupt mask and reenabling interrupts
12094  within the interrupt routine.
12095  Check there is sufficient space on the stack
12096 \begin_inset LatexCommand \index{stack}
12097
12098 \end_inset 
12099
12100  and don't add complexity unless you have to.
12101  
12102 \layout Subsection
12103
12104 Semaphore
12105 \begin_inset LatexCommand \index{semaphore}
12106
12107 \end_inset 
12108
12109  locking (mcs51/ds390)
12110 \layout Standard
12111
12112 Some architectures (mcs51/ds390) have an atomic
12113 \begin_inset LatexCommand \index{atomic}
12114
12115 \end_inset 
12116
12117  bit test and
12118 \emph on 
12119  
12120 \emph default 
12121 clear
12122 \emph on 
12123  
12124 \emph default 
12125 instruction.
12126  These type of instructions are typically used in preemptive multitasking
12127  systems, where a routine f.e.
12128  claims the use of a data structure ('acquires a lock
12129 \begin_inset LatexCommand \index{lock}
12130
12131 \end_inset 
12132
12133  on it'), makes some modifications and then releases the lock when the data
12134  structure is consistent again.
12135  The instruction may also be used if interrupt and non-interrupt code have
12136  to compete for a resource.
12137  With the atomic bit test and clear instruction interrupts
12138 \begin_inset LatexCommand \index{interrupt}
12139
12140 \end_inset 
12141
12142  don't have to be disabled for the locking operation.
12143  
12144 \layout Standard
12145
12146 SDCC generates this instruction if the source follows this pattern:
12147 \layout Verse
12148
12149
12150 \family typewriter 
12151 volatile
12152 \begin_inset LatexCommand \index{volatile}
12153
12154 \end_inset 
12155
12156  bit resource_is_free; 
12157 \newline 
12158
12159 \newline 
12160 if (resource_is_free) 
12161 \newline 
12162 \SpecialChar ~
12163 \SpecialChar ~
12164
12165 \newline 
12166 \SpecialChar ~
12167 \SpecialChar ~
12168 \SpecialChar ~
12169 \SpecialChar ~
12170 resource_is_free=0; 
12171 \newline 
12172 \SpecialChar ~
12173 \SpecialChar ~
12174 \SpecialChar ~
12175 \SpecialChar ~
12176 ...
12177  
12178 \newline 
12179 \SpecialChar ~
12180 \SpecialChar ~
12181 \SpecialChar ~
12182 \SpecialChar ~
12183 resource_is_free=1;
12184 \newline 
12185 \SpecialChar ~
12186 \SpecialChar ~
12187
12188 \layout Standard
12189
12190 Note, mcs51 and ds390 support only an atomic
12191 \begin_inset LatexCommand \index{atomic}
12192
12193 \end_inset 
12194
12195  bit test and 
12196 \emph on 
12197 clear
12198 \emph default 
12199  instruction (as opposed to atomic bit test and 
12200 \emph on 
12201 set).
12202 \layout Section
12203
12204 Functions using private register banks
12205 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12206
12207 \end_inset 
12208
12209  (mcs51/ds390)
12210 \layout Standard
12211
12212 Some architectures have support for quickly changing register sets.
12213  SDCC supports this feature with the 
12214 \emph on 
12215 using
12216 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12217
12218 \end_inset 
12219
12220
12221 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12222
12223 \end_inset 
12224
12225
12226 \emph default 
12227  attribute (which tells the compiler to use a register bank
12228 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12229
12230 \end_inset 
12231
12232  other than the default bank zero).
12233  It should only be applied to 
12234 \emph on 
12235 interrupt
12236 \begin_inset LatexCommand \index{interrupt}
12237
12238 \end_inset 
12239
12240
12241 \emph default 
12242  functions (see footnote below).
12243  This will in most circumstances make the generated ISR code more efficient
12244  since it will not have to save registers on the stack.
12245 \layout Standard
12246
12247 The 
12248 \emph on 
12249 using
12250 \emph default 
12251  attribute will have no effect on the generated code for a 
12252 \emph on 
12253 non-interrupt
12254 \emph default 
12255  function (but may occasionally be useful anyway
12256 \begin_inset Foot
12257 collapsed false
12258
12259 \layout Standard
12260
12261 possible exception: if a function is called ONLY from 'interrupt' functions
12262  using a particular bank, it can be declared with the same 'using' attribute
12263  as the calling 'interrupt' functions.
12264  For instance, if you have several ISRs using bank one, and all of them
12265  call memcpy(), it might make sense to create a specialized version of memcpy()
12266  'using 1', since this would prevent the ISR from having to save bank zero
12267  to the stack on entry and switch to bank zero before calling the function
12268 \end_inset 
12269
12270 ).
12271 \newline 
12272
12273 \emph on 
12274 (pending: I don't think this has been done yet)
12275 \layout Standard
12276
12277 An 
12278 \emph on 
12279 interrupt
12280 \emph default 
12281  function using a non-zero bank will assume that it can trash that register
12282  bank, and will not save it.
12283  Since high-priority interrupts
12284 \begin_inset LatexCommand \index{interrupts}
12285
12286 \end_inset 
12287
12288
12289 \begin_inset LatexCommand \index{interrupt priority}
12290
12291 \end_inset 
12292
12293  can interrupt low-priority ones on the 8051 and friends, this means that
12294  if a high-priority ISR 
12295 \emph on 
12296 using
12297 \emph default 
12298  a particular bank occurs while processing a low-priority ISR 
12299 \emph on 
12300 using
12301 \emph default 
12302  the same bank, terrible and bad things can happen.
12303  To prevent this, no single register bank should be 
12304 \emph on 
12305 used
12306 \emph default 
12307  by both a high priority and a low priority ISR.
12308  This is probably most easily done by having all high priority ISRs use
12309  one bank and all low priority ISRs use another.
12310  If you have an ISR which can change priority at runtime, you're on your
12311  own: I suggest using the default bank zero and taking the small performance
12312  hit.
12313 \layout Standard
12314
12315 It is most efficient if your ISR calls no other functions.
12316  If your ISR must call other functions, it is most efficient if those functions
12317  use the same bank as the ISR (see note 1 below); the next best is if the
12318  called functions use bank zero.
12319  It is very inefficient to call a function using a different, non-zero bank
12320  from an ISR.
12321  
12322 \layout Section
12323
12324 Startup Code
12325 \begin_inset LatexCommand \label{sub:Startup-Code}
12326
12327 \end_inset 
12328
12329
12330 \begin_inset LatexCommand \index{Startup code}
12331
12332 \end_inset 
12333
12334
12335 \layout Subsection
12336
12337 MCS51/DS390 Startup Code
12338 \layout Standard
12339
12340 The compiler inserts a call to the C routine 
12341 \emph on 
12342 _sdcc_external_startup()
12343 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12344
12345 \end_inset 
12346
12347
12348 \series bold 
12349 \emph default 
12350  
12351 \series default 
12352 at the start of the CODE area.
12353  This routine is in the runtime library
12354 \begin_inset LatexCommand \index{Runtime library}
12355
12356 \end_inset 
12357
12358 .
12359  By default this routine returns 0, if this routine returns a non-zero value,
12360  the static & global variable initialization will be skipped and the function
12361  main will be invoked.
12362  Otherwise static & global variables will be initialized before the function
12363  main is invoked.
12364  You could add a 
12365 \emph on 
12366 _sdcc_external_startup()
12367 \emph default 
12368  routine to your program to override the default if you need to setup hardware
12369  or perform some other critical operation prior to static & global variable
12370  initialization
12371 \begin_inset LatexCommand \index{Variable initialization}
12372
12373 \end_inset 
12374
12375 .
12376  On some mcs51 variants xdata
12377 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12378
12379 \end_inset 
12380
12381  memory has to be explicitly enabled before it can be accessed or if the
12382  watchdog needs to be disabled, this is the place to do it.
12383  The startup code clears all internal data memory, 256 bytes by default,
12384  but from 0 to n-1 if 
12385 \emph on 
12386 -
12387 \begin_inset ERT
12388 status Collapsed
12389
12390 \layout Standard
12391
12392 \backslash 
12393 /
12394 \end_inset 
12395
12396 -iram-size
12397 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12398
12399 \end_inset 
12400
12401 n
12402 \emph default 
12403  is used.
12404  (recommended for Chipcon CC1010).
12405 \layout Standard
12406
12407 See also the compiler option 
12408 \emph on 
12409 -
12410 \begin_inset ERT
12411 status Collapsed
12412
12413 \layout Standard
12414
12415 \backslash 
12416 /
12417 \end_inset 
12418
12419 -no-xinit
12420 \emph default 
12421 -
12422 \emph on 
12423 opt
12424 \emph default 
12425
12426 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
12427
12428 \end_inset 
12429
12430  and section 
12431 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12432
12433 \end_inset 
12434
12435 \SpecialChar ~
12436 about MCS51-variants.
12437 \layout Subsection
12438
12439 HC08 Startup Code
12440 \layout Standard
12441
12442 The HC08 startup code follows the same scheme as the MCS51 startup code.
12443 \layout Subsection
12444
12445 Z80 Startup Code
12446 \layout Standard
12447
12448 On the Z80 the startup code is inserted by linking with crt0.o which is generated
12449  from sdcc/device/lib/z80/crt0.s.
12450  If you need a different startup code you can use the compiler option 
12451 \emph on 
12452 -
12453 \series bold 
12454 \emph default 
12455
12456 \begin_inset ERT
12457 status Collapsed
12458
12459 \layout Standard
12460
12461 \backslash 
12462 /
12463 \end_inset 
12464
12465
12466 \series default 
12467 \emph on 
12468 -no-std-crt0
12469 \emph default 
12470
12471 \begin_inset LatexCommand \index{-\/-no-std-crt0}
12472
12473 \end_inset 
12474
12475  and provide your own crt0.o.
12476  
12477 \layout Section
12478
12479 Inline Assembler Code
12480 \begin_inset LatexCommand \index{Assembler routines}
12481
12482 \end_inset 
12483
12484
12485 \layout Subsection
12486
12487 A Step by Step Introduction
12488 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
12489
12490 \end_inset 
12491
12492
12493 \layout Standard
12494
12495 Starting from a small snippet of c-code this example shows for the MCS51
12496  how to use inline assembly, access variables, a function parameter and
12497  an array in xdata memory.
12498  The example uses an MCS51 here but is easily adapted for other architectures.
12499  This is a buffer routine which should be optimized:
12500 \layout Verse
12501
12502
12503 \family typewriter 
12504 \size footnotesize 
12505 unsigned char far
12506 \begin_inset LatexCommand \index{far (storage class)}
12507
12508 \end_inset 
12509
12510
12511 \begin_inset LatexCommand \index{\_\_far (storage class)}
12512
12513 \end_inset 
12514
12515  at
12516 \begin_inset LatexCommand \index{at}
12517
12518 \end_inset 
12519
12520
12521 \begin_inset LatexCommand \index{\_\_at}
12522
12523 \end_inset 
12524
12525  0x7f00 buf[0x100];
12526 \begin_inset LatexCommand \index{Aligned array}
12527
12528 \end_inset 
12529
12530
12531 \newline 
12532 unsigned char head,tail;
12533 \newline 
12534
12535 \newline 
12536 void to_buffer( unsigned char c ) 
12537 \newline 
12538 {
12539 \newline 
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 if( head != tail-1 ) 
12545 \newline 
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 buf[ head++ ] = c;\SpecialChar ~
12555 \SpecialChar ~
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 /* access to a 256 byte aligned array */
12559 \newline 
12560
12561 \layout Standard
12562
12563 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
12564  then a corresponding buffer.asm file is generated.
12565  We define a new function 
12566 \family typewriter 
12567 to_buffer_asm()
12568 \family default 
12569  in file buffer.c in which we cut and paste the generated code, removing
12570  unwanted comments and some ':'.
12571  Then add 
12572 \begin_inset Quotes sld
12573 \end_inset 
12574
12575 _asm
12576 \begin_inset Quotes srd
12577 \end_inset 
12578
12579  and 
12580 \begin_inset Quotes sld
12581 \end_inset 
12582
12583 _endasm;
12584 \begin_inset Quotes srd
12585 \end_inset 
12586
12587  to the beginning and the end of the function body:
12588 \layout Verse
12589
12590
12591 \family typewriter 
12592 \size footnotesize 
12593 /* With a cut and paste from the .asm file, we have something to start with.
12594 \newline 
12595 \SpecialChar ~
12596 \SpecialChar ~
12597 \SpecialChar ~
12598 The function is not yet OK! (registers aren't saved) */ 
12599 \newline 
12600 void to_buffer_asm( unsigned char c ) 
12601 \newline 
12602
12603 \newline 
12604 \SpecialChar ~
12605 \SpecialChar ~
12606 \SpecialChar ~
12607 \SpecialChar ~
12608 _asm
12609 \begin_inset LatexCommand \index{\_asm}
12610
12611 \end_inset 
12612
12613
12614 \begin_inset LatexCommand \index{\_\_asm}
12615
12616 \end_inset 
12617
12618
12619 \newline 
12620 \SpecialChar ~
12621 \SpecialChar ~
12622 \SpecialChar ~
12623 \SpecialChar ~
12624 mov\SpecialChar ~
12625 \SpecialChar ~
12626 r2,dpl 
12627 \newline 
12628 ;buffer.c if( head != tail-1 ) 
12629 \newline 
12630 \SpecialChar ~
12631 \SpecialChar ~
12632 \SpecialChar ~
12633 \SpecialChar ~
12634 mov\SpecialChar ~
12635 \SpecialChar ~
12636 a,_tail 
12637 \newline 
12638 \SpecialChar ~
12639 \SpecialChar ~
12640 \SpecialChar ~
12641 \SpecialChar ~
12642 dec\SpecialChar ~
12643 \SpecialChar ~
12644
12645 \newline 
12646 \SpecialChar ~
12647 \SpecialChar ~
12648 \SpecialChar ~
12649 \SpecialChar ~
12650 mov\SpecialChar ~
12651 \SpecialChar ~
12652 r3,a 
12653 \newline 
12654 \SpecialChar ~
12655 \SpecialChar ~
12656 \SpecialChar ~
12657 \SpecialChar ~
12658 mov\SpecialChar ~
12659 \SpecialChar ~
12660 a,_head 
12661 \newline 
12662 \SpecialChar ~
12663 \SpecialChar ~
12664 \SpecialChar ~
12665 \SpecialChar ~
12666 cjne a,ar3,00106$ 
12667 \newline 
12668 \SpecialChar ~
12669 \SpecialChar ~
12670 \SpecialChar ~
12671 \SpecialChar ~
12672 ret
12673 \newline 
12674 00106$: 
12675 \newline 
12676 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
12677 \begin_inset LatexCommand \index{Aligned array}
12678
12679 \end_inset 
12680
12681
12682 \newline 
12683 \SpecialChar ~
12684 \SpecialChar ~
12685 \SpecialChar ~
12686 \SpecialChar ~
12687 mov\SpecialChar ~
12688 \SpecialChar ~
12689 r3,_head 
12690 \newline 
12691 \SpecialChar ~
12692 \SpecialChar ~
12693 \SpecialChar ~
12694 \SpecialChar ~
12695 inc\SpecialChar ~
12696 \SpecialChar ~
12697 _head 
12698 \newline 
12699 \SpecialChar ~
12700 \SpecialChar ~
12701 \SpecialChar ~
12702 \SpecialChar ~
12703 mov\SpecialChar ~
12704 \SpecialChar ~
12705 dpl,r3 
12706 \newline 
12707 \SpecialChar ~
12708 \SpecialChar ~
12709 \SpecialChar ~
12710 \SpecialChar ~
12711 mov\SpecialChar ~
12712 \SpecialChar ~
12713 dph,#(_buf >> 8) 
12714 \newline 
12715 \SpecialChar ~
12716 \SpecialChar ~
12717 \SpecialChar ~
12718 \SpecialChar ~
12719 mov\SpecialChar ~
12720 \SpecialChar ~
12721 a,r2 
12722 \newline 
12723 \SpecialChar ~
12724 \SpecialChar ~
12725 \SpecialChar ~
12726 \SpecialChar ~
12727 movx @dptr,a 
12728 \newline 
12729 00103$: 
12730 \newline 
12731 \SpecialChar ~
12732 \SpecialChar ~
12733 \SpecialChar ~
12734 \SpecialChar ~
12735 ret
12736 \newline 
12737 \SpecialChar ~
12738 \SpecialChar ~
12739 \SpecialChar ~
12740 \SpecialChar ~
12741 _endasm
12742 \begin_inset LatexCommand \index{\_endasm}
12743
12744 \end_inset 
12745
12746
12747 \begin_inset LatexCommand \index{\_\_endasm}
12748
12749 \end_inset 
12750
12751 ;
12752 \newline 
12753
12754 \layout Standard
12755
12756 The new file buffer.c should compile with only one warning about the unreferenced
12757  function argument 'c'.
12758  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
12759  (1) and finally have:
12760 \layout Verse
12761
12762
12763 \family typewriter 
12764 \size footnotesize 
12765 unsigned char far at 0x7f00 buf[0x100];
12766 \newline 
12767 unsigned char head,tail;
12768 \newline 
12769 #define USE_ASSEMBLY (1)
12770 \newline 
12771
12772 \newline 
12773 #if !USE_ASSEMBLY
12774 \newline 
12775
12776 \newline 
12777 void to_buffer( unsigned char c )
12778 \newline 
12779 {
12780 \newline 
12781 \SpecialChar ~
12782 \SpecialChar ~
12783 \SpecialChar ~
12784 \SpecialChar ~
12785 if( head != tail-1 )
12786 \newline 
12787 \SpecialChar ~
12788 \SpecialChar ~
12789 \SpecialChar ~
12790 \SpecialChar ~
12791 \SpecialChar ~
12792 \SpecialChar ~
12793 \SpecialChar ~
12794 \SpecialChar ~
12795 buf[ head++ ] = c;
12796 \newline 
12797 }
12798 \newline 
12799
12800 \newline 
12801 #else
12802 \newline 
12803
12804 \newline 
12805 void to_buffer( unsigned char c )
12806 \newline 
12807 {
12808 \newline 
12809 \SpecialChar ~
12810 \SpecialChar ~
12811 \SpecialChar ~
12812 \SpecialChar ~
12813 c; // to avoid warning: unreferenced function argument
12814 \newline 
12815 \SpecialChar ~
12816 \SpecialChar ~
12817 \SpecialChar ~
12818 \SpecialChar ~
12819 _asm
12820 \begin_inset LatexCommand \index{\_asm}
12821
12822 \end_inset 
12823
12824
12825 \begin_inset LatexCommand \index{\_\_asm}
12826
12827 \end_inset 
12828
12829
12830 \newline 
12831 \SpecialChar ~
12832 \SpecialChar ~
12833 \SpecialChar ~
12834 \SpecialChar ~
12835 \SpecialChar ~
12836 \SpecialChar ~
12837 \SpecialChar ~
12838 \SpecialChar ~
12839 ; save used registers here.
12840  
12841 \newline 
12842 \SpecialChar ~
12843 \SpecialChar ~
12844 \SpecialChar ~
12845 \SpecialChar ~
12846 \SpecialChar ~
12847 \SpecialChar ~
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 ; If we were still using r2,r3 we would have to push them here.
12851  
12852 \newline 
12853 ; if( head != tail-1 )
12854 \newline 
12855 \SpecialChar ~
12856 \SpecialChar ~
12857 \SpecialChar ~
12858 \SpecialChar ~
12859 \SpecialChar ~
12860 \SpecialChar ~
12861 \SpecialChar ~
12862 \SpecialChar ~
12863 mov\SpecialChar ~
12864  a,_tail
12865 \newline 
12866 \SpecialChar ~
12867 \SpecialChar ~
12868 \SpecialChar ~
12869 \SpecialChar ~
12870 \SpecialChar ~
12871 \SpecialChar ~
12872 \SpecialChar ~
12873 \SpecialChar ~
12874 dec\SpecialChar ~
12875  a
12876 \newline 
12877 \SpecialChar ~
12878 \SpecialChar ~
12879 \SpecialChar ~
12880 \SpecialChar ~
12881 \SpecialChar ~
12882 \SpecialChar ~
12883 \SpecialChar ~
12884 \SpecialChar ~
12885 xrl\SpecialChar ~
12886  a,_head
12887 \newline 
12888 \SpecialChar ~
12889 \SpecialChar ~
12890 \SpecialChar ~
12891 \SpecialChar ~
12892 \SpecialChar ~
12893 \SpecialChar ~
12894 \SpecialChar ~
12895 \SpecialChar ~
12896 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
12897 \newline 
12898 \SpecialChar ~
12899 \SpecialChar ~
12900 \SpecialChar ~
12901 \SpecialChar ~
12902 \SpecialChar ~
12903 \SpecialChar ~
12904 \SpecialChar ~
12905 \SpecialChar ~
12906 jz\SpecialChar ~
12907 \SpecialChar ~
12908  t_b_end$
12909 \newline 
12910 \SpecialChar ~
12911 \SpecialChar ~
12912 \SpecialChar ~
12913 \SpecialChar ~
12914 \SpecialChar ~
12915 \SpecialChar ~
12916 \SpecialChar ~
12917 \SpecialChar ~
12918 ;
12919 \newline 
12920 ; buf[ head++ ] = c;
12921 \newline 
12922 \SpecialChar ~
12923 \SpecialChar ~
12924 \SpecialChar ~
12925 \SpecialChar ~
12926 \SpecialChar ~
12927 \SpecialChar ~
12928 \SpecialChar ~
12929 \SpecialChar ~
12930 mov\SpecialChar ~
12931  a,dpl \SpecialChar ~
12932 \SpecialChar ~
12933 \SpecialChar ~
12934 \SpecialChar ~
12935 \SpecialChar ~
12936 \SpecialChar ~
12937 \SpecialChar ~
12938 ; dpl holds lower byte of function argument
12939 \newline 
12940 \SpecialChar ~
12941 \SpecialChar ~
12942 \SpecialChar ~
12943 \SpecialChar ~
12944 \SpecialChar ~
12945 \SpecialChar ~
12946 \SpecialChar ~
12947 \SpecialChar ~
12948 mov\SpecialChar ~
12949  dpl,_head \SpecialChar ~
12950 \SpecialChar ~
12951 \SpecialChar ~
12952 ; buf is 0x100 byte aligned so head can be used directly
12953 \newline 
12954 \SpecialChar ~
12955 \SpecialChar ~
12956 \SpecialChar ~
12957 \SpecialChar ~
12958 \SpecialChar ~
12959 \SpecialChar ~
12960 \SpecialChar ~
12961 \SpecialChar ~
12962 mov\SpecialChar ~
12963  dph,#(_buf>>8)
12964 \newline 
12965 \SpecialChar ~
12966 \SpecialChar ~
12967 \SpecialChar ~
12968 \SpecialChar ~
12969 \SpecialChar ~
12970 \SpecialChar ~
12971 \SpecialChar ~
12972 \SpecialChar ~
12973 movx @dptr,a
12974 \newline 
12975 \SpecialChar ~
12976 \SpecialChar ~
12977 \SpecialChar ~
12978 \SpecialChar ~
12979 \SpecialChar ~
12980 \SpecialChar ~
12981 \SpecialChar ~
12982 \SpecialChar ~
12983 inc \SpecialChar ~
12984 _head
12985 \newline 
12986 \SpecialChar ~
12987 \SpecialChar ~
12988 \SpecialChar ~
12989 \SpecialChar ~
12990 \SpecialChar ~
12991 \SpecialChar ~
12992 \SpecialChar ~
12993 \SpecialChar ~
12994 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
12995 \newline 
12996 t_b_end$:
12997 \newline 
12998 \SpecialChar ~
12999 \SpecialChar ~
13000 \SpecialChar ~
13001 \SpecialChar ~
13002 \SpecialChar ~
13003 \SpecialChar ~
13004 \SpecialChar ~
13005 \SpecialChar ~
13006 ; restore used registers here 
13007 \newline 
13008 \SpecialChar ~
13009 \SpecialChar ~
13010 \SpecialChar ~
13011 \SpecialChar ~
13012 _endasm
13013 \begin_inset LatexCommand \index{\_endasm}
13014
13015 \end_inset 
13016
13017
13018 \begin_inset LatexCommand \index{\_\_endasm}
13019
13020 \end_inset 
13021
13022 ;
13023 \newline 
13024 }
13025 \newline 
13026 #endif
13027 \layout Standard
13028
13029 The inline assembler code can contain any valid code understood by the assembler
13030 , this includes any assembler directives and comment lines
13031 \begin_inset Foot
13032 collapsed false
13033
13034 \layout Standard
13035
13036 The assembler does not like some characters like ':' or ''' in comments.
13037  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13038 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13039
13040 \end_inset 
13041
13042
13043 \begin_inset LatexCommand \index{Assembler documentation}
13044
13045 \end_inset 
13046
13047
13048 \end_inset 
13049
13050 .
13051  The compiler does not do any validation of the code within the 
13052 \family typewriter 
13053 _asm
13054 \begin_inset LatexCommand \index{\_asm}
13055
13056 \end_inset 
13057
13058
13059 \begin_inset LatexCommand \index{\_\_asm}
13060
13061 \end_inset 
13062
13063  ...
13064  _endasm
13065 \size footnotesize 
13066
13067 \begin_inset LatexCommand \index{\_endasm}
13068
13069 \end_inset 
13070
13071
13072 \begin_inset LatexCommand \index{\_\_endasm}
13073
13074 \end_inset 
13075
13076
13077 \size default 
13078 ;
13079 \family default 
13080  keyword pair.
13081  Specifically it will not know which registers are used and thus register
13082  pushing/popping
13083 \begin_inset LatexCommand \index{push/pop}
13084
13085 \end_inset 
13086
13087  has to be done manually.
13088  
13089 \layout Standard
13090
13091 It is recommended that each assembly instruction (including labels) be placed
13092  in a separate line (as the example shows).
13093  When the -
13094 \begin_inset ERT
13095 status Collapsed
13096
13097 \layout Standard
13098
13099 \backslash 
13100 /
13101 \end_inset 
13102
13103 -
13104 \emph on 
13105 peep-asm
13106 \begin_inset LatexCommand \index{-\/-peep-asm}
13107
13108 \end_inset 
13109
13110
13111 \emph default 
13112  command line option is used, the inline assembler code will be passed through
13113  the peephole optimizer
13114 \begin_inset LatexCommand \index{Peephole optimizer}
13115
13116 \end_inset 
13117
13118 .
13119  There are only a few (if any) cases where this option makes sense, it might
13120  cause some unexpected changes in the inline assembler code.
13121  Please go through the peephole optimizer rules defined in file 
13122 \emph on 
13123 SDCCpeeph.def
13124 \emph default 
13125  before using this option.
13126 \layout Subsection
13127
13128 Naked Functions
13129 \begin_inset LatexCommand \label{sub:Naked-Functions}
13130
13131 \end_inset 
13132
13133
13134 \begin_inset LatexCommand \index{Naked functions}
13135
13136 \end_inset 
13137
13138
13139 \layout Standard
13140
13141 A special keyword may be associated with a function declaring it as 
13142 \emph on 
13143 _naked
13144 \begin_inset LatexCommand \index{\_naked}
13145
13146 \end_inset 
13147
13148
13149 \begin_inset LatexCommand \index{\_\_naked}
13150
13151 \end_inset 
13152
13153 .
13154  
13155 \emph default 
13156 The 
13157 \emph on 
13158 _naked
13159 \emph default 
13160  function modifier attribute prevents the compiler from generating prologue
13161 \begin_inset LatexCommand \index{function prologue}
13162
13163 \end_inset 
13164
13165  and epilogue
13166 \begin_inset LatexCommand \index{function epilogue}
13167
13168 \end_inset 
13169
13170  code for that function.
13171  This means that the user is entirely responsible for such things as saving
13172  any registers that may need to be preserved, selecting the proper register
13173  bank, generating the 
13174 \emph on 
13175 return
13176 \emph default 
13177  instruction at the end, etc.
13178  Practically, this means that the contents of the function must be written
13179  in inline assembler.
13180  This is particularly useful for interrupt functions, which can have a large
13181  (and often unnecessary) prologue/epilogue.
13182  For example, compare the code generated by these two functions:
13183 \layout Verse
13184
13185
13186 \family typewriter 
13187 volatile
13188 \begin_inset LatexCommand \index{volatile}
13189
13190 \end_inset 
13191
13192  data unsigned char counter;
13193 \newline 
13194
13195 \newline 
13196 void simpleInterrupt(void) interrupt
13197 \begin_inset LatexCommand \index{interrupt}
13198
13199 \end_inset 
13200
13201
13202 \begin_inset LatexCommand \index{\_\_interrupt}
13203
13204 \end_inset 
13205
13206  1
13207 \newline 
13208 {
13209 \newline 
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 \SpecialChar ~
13213 \SpecialChar ~
13214 counter++;
13215 \newline 
13216 }
13217 \newline 
13218
13219 \newline 
13220 void nakedInterrupt(void) interrupt 2 _naked
13221 \newline 
13222 {
13223 \newline 
13224 \SpecialChar ~
13225 \SpecialChar ~
13226 \SpecialChar ~
13227 \SpecialChar ~
13228 _asm
13229 \begin_inset LatexCommand \index{\_asm}
13230
13231 \end_inset 
13232
13233
13234 \begin_inset LatexCommand \index{\_\_asm}
13235
13236 \end_inset 
13237
13238
13239 \newline 
13240 \SpecialChar ~
13241 \SpecialChar ~
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 \SpecialChar ~
13246 inc\SpecialChar ~
13247 \SpecialChar ~
13248 \SpecialChar ~
13249 \SpecialChar ~
13250 \SpecialChar ~
13251 _counter ; does not change flags, no need to save psw
13252 \newline 
13253 \SpecialChar ~
13254 \SpecialChar ~
13255 \SpecialChar ~
13256 \SpecialChar ~
13257 \SpecialChar ~
13258 \SpecialChar ~
13259 reti\SpecialChar ~
13260 \SpecialChar ~
13261 \SpecialChar ~
13262 \SpecialChar ~
13263 ; MUST explicitly include ret or reti in _naked function.
13264 \newline 
13265 \SpecialChar ~
13266 \SpecialChar ~
13267 \SpecialChar ~
13268 \SpecialChar ~
13269 _endasm
13270 \begin_inset LatexCommand \index{\_endasm}
13271
13272 \end_inset 
13273
13274
13275 \begin_inset LatexCommand \index{\_\_endasm}
13276
13277 \end_inset 
13278
13279 ;
13280 \newline 
13281 }
13282 \layout Standard
13283
13284 For an 8051 target, the generated simpleInterrupt looks like:
13285 \layout Verse
13286
13287
13288 \family typewriter 
13289 _simpleInterrupt:
13290 \newline 
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 \SpecialChar ~
13295 push\SpecialChar ~
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 \SpecialChar ~
13299 acc
13300 \newline 
13301 \SpecialChar ~
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 push\SpecialChar ~
13306 \SpecialChar ~
13307 \SpecialChar ~
13308 \SpecialChar ~
13309 b
13310 \newline 
13311 \SpecialChar ~
13312 \SpecialChar ~
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 push\SpecialChar ~
13316 \SpecialChar ~
13317 \SpecialChar ~
13318 \SpecialChar ~
13319 dpl
13320 \newline 
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 \SpecialChar ~
13324 \SpecialChar ~
13325 push\SpecialChar ~
13326 \SpecialChar ~
13327 \SpecialChar ~
13328 \SpecialChar ~
13329 dph
13330 \newline 
13331 \SpecialChar ~
13332 \SpecialChar ~
13333 \SpecialChar ~
13334 \SpecialChar ~
13335 push\SpecialChar ~
13336 \SpecialChar ~
13337 \SpecialChar ~
13338 \SpecialChar ~
13339 psw
13340 \newline 
13341 \SpecialChar ~
13342 \SpecialChar ~
13343 \SpecialChar ~
13344 \SpecialChar ~
13345 mov\SpecialChar ~
13346 \SpecialChar ~
13347 \SpecialChar ~
13348 \SpecialChar ~
13349 \SpecialChar ~
13350 psw,#0x00
13351 \newline 
13352 \SpecialChar ~
13353 \SpecialChar ~
13354 \SpecialChar ~
13355 \SpecialChar ~
13356 inc\SpecialChar ~
13357 \SpecialChar ~
13358 \SpecialChar ~
13359 \SpecialChar ~
13360 \SpecialChar ~
13361 _counter
13362 \newline 
13363 \SpecialChar ~
13364 \SpecialChar ~
13365 \SpecialChar ~
13366 \SpecialChar ~
13367 pop\SpecialChar ~
13368 \SpecialChar ~
13369 \SpecialChar ~
13370 \SpecialChar ~
13371 \SpecialChar ~
13372 psw
13373 \newline 
13374 \SpecialChar ~
13375 \SpecialChar ~
13376 \SpecialChar ~
13377 \SpecialChar ~
13378 pop\SpecialChar ~
13379 \SpecialChar ~
13380 \SpecialChar ~
13381 \SpecialChar ~
13382 \SpecialChar ~
13383 dph
13384 \newline 
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 pop\SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 \SpecialChar ~
13393 \SpecialChar ~
13394 dpl
13395 \newline 
13396 \SpecialChar ~
13397 \SpecialChar ~
13398 \SpecialChar ~
13399 \SpecialChar ~
13400 pop\SpecialChar ~
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 b
13406 \newline 
13407 \SpecialChar ~
13408 \SpecialChar ~
13409 \SpecialChar ~
13410 \SpecialChar ~
13411 pop\SpecialChar ~
13412 \SpecialChar ~
13413 \SpecialChar ~
13414 \SpecialChar ~
13415 \SpecialChar ~
13416 acc
13417 \newline 
13418 \SpecialChar ~
13419 \SpecialChar ~
13420 \SpecialChar ~
13421 \SpecialChar ~
13422 reti
13423 \layout Standard
13424
13425 whereas nakedInterrupt looks like:
13426 \layout Verse
13427
13428
13429 \family typewriter 
13430 _nakedInterrupt:
13431 \newline 
13432 \SpecialChar ~
13433 \SpecialChar ~
13434 \SpecialChar ~
13435 \SpecialChar ~
13436 inc\SpecialChar ~
13437 \SpecialChar ~
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 _counter ; does not change flags, no need to save psw
13441 \newline 
13442 \SpecialChar ~
13443 \SpecialChar ~
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 reti\SpecialChar ~
13447 \SpecialChar ~
13448 \SpecialChar ~
13449 \SpecialChar ~
13450 \SpecialChar ~
13451 \SpecialChar ~
13452 \SpecialChar ~
13453 \SpecialChar ~
13454 \SpecialChar ~
13455 \SpecialChar ~
13456 \SpecialChar ~
13457 \SpecialChar ~
13458 ; MUST explicitly include ret or reti in _naked function
13459 \layout Standard
13460
13461 The related directive #pragma exclude
13462 \begin_inset LatexCommand \index{\#pragma exclude}
13463
13464 \end_inset 
13465
13466  allows a more fine grained control over pushing & popping
13467 \begin_inset LatexCommand \index{push/pop}
13468
13469 \end_inset 
13470
13471  the registers.
13472 \layout Standard
13473
13474 While there is nothing preventing you from writing C code inside a 
13475 \family typewriter 
13476 _naked
13477 \family default 
13478  function, there are many ways to shoot yourself in the foot doing this,
13479  and it is recommended that you stick to inline assembler.
13480 \layout Subsection
13481
13482 Use of Labels within Inline Assembler
13483 \layout Standard
13484
13485 SDCC allows the use of in-line assembler with a few restrictions regarding
13486  labels.
13487  In older versions of the compiler all labels defined within inline assembler
13488  code 
13489 \emph on 
13490 had to be
13491 \emph default 
13492  of the form 
13493 \emph on 
13494 nnnnn$
13495 \emph default 
13496  where nnnn is a number less than 100 (which implies a limit of utmost 100
13497  inline assembler labels 
13498 \emph on 
13499 per function
13500 \emph default 
13501 \noun on 
13502 )
13503 \noun default 
13504 .
13505  
13506 \layout Verse
13507
13508
13509 \family typewriter 
13510 _asm
13511 \begin_inset LatexCommand \index{\_asm}
13512
13513 \end_inset 
13514
13515
13516 \begin_inset LatexCommand \index{\_\_asm}
13517
13518 \end_inset 
13519
13520  
13521 \newline 
13522 \SpecialChar ~
13523 \SpecialChar ~
13524 \SpecialChar ~
13525 \SpecialChar ~
13526 mov\SpecialChar ~
13527 \SpecialChar ~
13528 \SpecialChar ~
13529 \SpecialChar ~
13530 \SpecialChar ~
13531 b,#10 
13532 \newline 
13533 00001$: 
13534 \newline 
13535 \SpecialChar ~
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 \SpecialChar ~
13539 djnz\SpecialChar ~
13540 \SpecialChar ~
13541 \SpecialChar ~
13542 \SpecialChar ~
13543 b,00001$ 
13544 \newline 
13545 _endasm
13546 \begin_inset LatexCommand \index{\_endasm}
13547
13548 \end_inset 
13549
13550
13551 \begin_inset LatexCommand \index{\_\_endasm}
13552
13553 \end_inset 
13554
13555  ;
13556 \layout Standard
13557
13558 Inline assembler code cannot reference any C-Labels, however it can reference
13559  labels
13560 \begin_inset LatexCommand \index{Labels}
13561
13562 \end_inset 
13563
13564  defined by the inline assembler, e.g.:
13565 \layout Verse
13566
13567
13568 \family typewriter 
13569 foo() { 
13570 \newline 
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 \SpecialChar ~
13575 /* some c code */ 
13576 \newline 
13577 \SpecialChar ~
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 _asm 
13582 \newline 
13583 \SpecialChar ~
13584 \SpecialChar ~
13585 \SpecialChar ~
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 ; some assembler code 
13590 \newline 
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 \SpecialChar ~
13595 \SpecialChar ~
13596 \SpecialChar ~
13597 ljmp $0003 
13598 \newline 
13599 \SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 _endasm; 
13604 \newline 
13605 \SpecialChar ~
13606 \SpecialChar ~
13607 \SpecialChar ~
13608 \SpecialChar ~
13609 /* some more c code */ 
13610 \newline 
13611 clabel:\SpecialChar ~
13612 \SpecialChar ~
13613 /* inline assembler cannot reference this label */ 
13614 \newline 
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 \SpecialChar ~
13619 _asm
13620 \newline 
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 \SpecialChar ~
13625 $0003: ;label (can be referenced by inline assembler only) 
13626 \newline 
13627 \SpecialChar ~
13628 \SpecialChar ~
13629 \SpecialChar ~
13630 \SpecialChar ~
13631 _endasm
13632 \begin_inset LatexCommand \index{\_endasm}
13633
13634 \end_inset 
13635
13636
13637 \begin_inset LatexCommand \index{\_\_endasm}
13638
13639 \end_inset 
13640
13641  ; 
13642 \newline 
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 \SpecialChar ~
13647 /* some more c code */
13648 \newline 
13649 }
13650 \layout Standard
13651
13652 In other words inline assembly code can access labels defined in inline
13653  assembly within the scope of the function.
13654  The same goes the other way, i.e.
13655  labels defines in inline assembly can not be accessed by C statements.
13656 \layout Section
13657
13658 Interfacing with Assembler Code
13659 \begin_inset LatexCommand \index{Assembler routines}
13660
13661 \end_inset 
13662
13663
13664 \layout Subsection
13665
13666 Global Registers used for Parameter Passing
13667 \begin_inset LatexCommand \index{Parameter passing}
13668
13669 \end_inset 
13670
13671
13672 \layout Standard
13673
13674 The compiler always uses the global registers 
13675 \emph on 
13676 DPL, DPH
13677 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13678
13679 \end_inset 
13680
13681
13682 \begin_inset LatexCommand \index{DPTR}
13683
13684 \end_inset 
13685
13686 , B
13687 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
13688
13689 \end_inset 
13690
13691  
13692 \emph default 
13693 and
13694 \emph on 
13695  ACC
13696 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
13697
13698 \end_inset 
13699
13700
13701 \emph default 
13702  to pass the first parameter to a routine.
13703  The second parameter onwards is either allocated on the stack (for reentrant
13704  routines or if -
13705 \begin_inset ERT
13706 status Collapsed
13707
13708 \layout Standard
13709
13710 \backslash 
13711 /
13712 \end_inset 
13713
13714 -stack-auto is used) or in data / xdata memory (depending on the memory
13715  model).
13716  
13717 \layout Subsection
13718
13719 Assembler Routine (non-reentrant)
13720 \layout Standard
13721
13722 In the following example
13723 \begin_inset LatexCommand \index{reentrant}
13724
13725 \end_inset 
13726
13727
13728 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
13729
13730 \end_inset 
13731
13732  the function c_func calls an assembler routine asm_func, which takes two
13733  parameters
13734 \begin_inset LatexCommand \index{function parameter}
13735
13736 \end_inset 
13737
13738 .
13739 \layout Verse
13740
13741
13742 \family typewriter 
13743 extern int asm_func(unsigned char, unsigned char);
13744 \newline 
13745
13746 \newline 
13747 int c_func (unsigned char i, unsigned char j)
13748 \newline 
13749 {
13750 \newline 
13751 \SpecialChar ~
13752 \SpecialChar ~
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 return asm_func(i,j);
13756 \newline 
13757 }
13758 \newline 
13759
13760 \newline 
13761 int main()
13762 \newline 
13763 {
13764 \newline 
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 \SpecialChar ~
13768 \SpecialChar ~
13769 return c_func(10,9);
13770 \newline 
13771 }
13772 \layout Standard
13773
13774 The corresponding assembler function is:
13775 \layout Verse
13776
13777
13778 \family typewriter 
13779 .globl _asm_func_PARM_2 
13780 \newline 
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 \SpecialChar ~
13786 \SpecialChar ~
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 .globl _asm_func 
13790 \newline 
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 .area OSEG 
13800 \newline 
13801 _asm_func_PARM_2:
13802 \newline 
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 \SpecialChar ~
13808 \SpecialChar ~
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 .ds    1 
13812 \newline 
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 \SpecialChar ~
13820 \SpecialChar ~
13821 .area CSEG 
13822 \newline 
13823 _asm_func: 
13824 \newline 
13825 \SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 \SpecialChar ~
13829 \SpecialChar ~
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 mov\SpecialChar ~
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 \SpecialChar ~
13837 a,dpl 
13838 \newline 
13839 \SpecialChar ~
13840 \SpecialChar ~
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 \SpecialChar ~
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 add\SpecialChar ~
13848 \SpecialChar ~
13849 \SpecialChar ~
13850 \SpecialChar ~
13851 a,_asm_func_PARM_2 
13852 \newline 
13853 \SpecialChar ~
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 \SpecialChar ~
13859 \SpecialChar ~
13860 \SpecialChar ~
13861 mov\SpecialChar ~
13862 \SpecialChar ~
13863 \SpecialChar ~
13864 \SpecialChar ~
13865 dpl,a 
13866 \newline 
13867 \SpecialChar ~
13868 \SpecialChar ~
13869 \SpecialChar ~
13870 \SpecialChar ~
13871 \SpecialChar ~
13872 \SpecialChar ~
13873 \SpecialChar ~
13874 \SpecialChar ~
13875 mov\SpecialChar ~
13876 \SpecialChar ~
13877 \SpecialChar ~
13878 \SpecialChar ~
13879 dph
13880 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13881
13882 \end_inset 
13883
13884 ,#0x00 
13885 \newline 
13886 \SpecialChar ~
13887 \SpecialChar ~
13888 \SpecialChar ~
13889 \SpecialChar ~
13890 \SpecialChar ~
13891 \SpecialChar ~
13892 \SpecialChar ~
13893 \SpecialChar ~
13894 ret
13895 \layout Standard
13896
13897 Note here that the return values
13898 \begin_inset LatexCommand \index{return value}
13899
13900 \end_inset 
13901
13902  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
13903  two byte values.
13904  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
13905 b' & 'acc' for four byte values.
13906 \layout Standard
13907
13908 The parameter naming convention is _<function_name>_PARM_<n>, where n is
13909  the parameter number starting from 1, and counting from the left.
13910  The first parameter is passed in 
13911 \begin_inset Quotes eld
13912 \end_inset 
13913
13914 dpl
13915 \begin_inset Quotes erd
13916 \end_inset 
13917
13918  for a one byte parameter, 
13919 \begin_inset Quotes eld
13920 \end_inset 
13921
13922 dptr
13923 \begin_inset Quotes erd
13924 \end_inset 
13925
13926  for two bytes, 
13927 \begin_inset Quotes eld
13928 \end_inset 
13929
13930 b,dptr
13931 \begin_inset Quotes erd
13932 \end_inset 
13933
13934  for three bytes and 
13935 \begin_inset Quotes eld
13936 \end_inset 
13937
13938 acc,b,dptr
13939 \begin_inset Quotes erd
13940 \end_inset 
13941
13942  for a four bytes parameter.
13943  The variable name for the second parameter will be _<function_name>_PARM_2.
13944 \newline 
13945
13946 \newline 
13947 Assemble the assembler routine with the following command:
13948 \newline 
13949
13950 \newline 
13951
13952 \family sans 
13953 \series bold 
13954 asx8051 -losg asmfunc.asm
13955 \newline 
13956
13957 \newline 
13958
13959 \family default 
13960 \series default 
13961 Then compile and link the assembler routine to the C source file with the
13962  following command:
13963 \newline 
13964
13965 \newline 
13966
13967 \family sans 
13968 \series bold 
13969 sdcc cfunc.c asmfunc.rel
13970 \layout Subsection
13971
13972 Assembler Routine (reentrant)
13973 \layout Standard
13974
13975 In this case
13976 \begin_inset LatexCommand \index{reentrant}
13977
13978 \end_inset 
13979
13980
13981 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
13982
13983 \end_inset 
13984
13985  the second parameter
13986 \begin_inset LatexCommand \index{function parameter}
13987
13988 \end_inset 
13989
13990  onwards will be passed on the stack, the parameters are pushed from right
13991  to left i.e.
13992  after the call the leftmost parameter will be on the top of the stack.
13993  Here is an example:
13994 \layout Verse
13995
13996
13997 \family typewriter 
13998 extern int asm_func(unsigned char, unsigned char);
13999 \newline 
14000
14001 \newline 
14002 int c_func (unsigned char i, unsigned char j) reentrant 
14003 \newline 
14004
14005 \newline 
14006 \SpecialChar ~
14007 \SpecialChar ~
14008 \SpecialChar ~
14009 \SpecialChar ~
14010 return asm_func(i,j); 
14011 \newline 
14012
14013 \newline 
14014
14015 \newline 
14016 int main() 
14017 \newline 
14018
14019 \newline 
14020 \SpecialChar ~
14021 \SpecialChar ~
14022 \SpecialChar ~
14023 \SpecialChar ~
14024 return c_func(10,9); 
14025 \newline 
14026 }
14027 \layout Standard
14028
14029 The corresponding assembler routine is:
14030 \layout Verse
14031
14032
14033 \family typewriter 
14034 .globl _asm_func 
14035 \newline 
14036 _asm_func: 
14037 \newline 
14038 \SpecialChar ~
14039 \SpecialChar ~
14040 \SpecialChar ~
14041 \SpecialChar ~
14042 push  _bp 
14043 \newline 
14044 \SpecialChar ~
14045 \SpecialChar ~
14046 \SpecialChar ~
14047 \SpecialChar ~
14048 mov _bp,sp 
14049 \newline 
14050 \SpecialChar ~
14051 \SpecialChar ~
14052 \SpecialChar ~
14053 \SpecialChar ~
14054 mov r2,dpl
14055 \newline 
14056 \SpecialChar ~
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 mov a,_bp 
14061 \newline 
14062 \SpecialChar ~
14063 \SpecialChar ~
14064 \SpecialChar ~
14065 \SpecialChar ~
14066 add a,#0xfd 
14067 \newline 
14068 \SpecialChar ~
14069 \SpecialChar ~
14070 \SpecialChar ~
14071 \SpecialChar ~
14072 mov r0,a 
14073 \newline 
14074 \SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 add  a,#0xfc ;?
14079 \newline 
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 \SpecialChar ~
14084 mov  r1,a 
14085 \newline 
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 \SpecialChar ~
14089 \SpecialChar ~
14090 mov  a,@r0 
14091 \newline 
14092 \SpecialChar ~
14093 \SpecialChar ~
14094 \SpecialChar ~
14095 \SpecialChar ~
14096 add  a,r2 ;?
14097 \newline 
14098 \SpecialChar ~
14099 \SpecialChar ~
14100 \SpecialChar ~
14101 \SpecialChar ~
14102 mov  dpl,a 
14103 \newline 
14104 \SpecialChar ~
14105 \SpecialChar ~
14106 \SpecialChar ~
14107 \SpecialChar ~
14108 mov  dph,#0x00 
14109 \newline 
14110 \SpecialChar ~
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 mov  sp,_bp 
14115 \newline 
14116 \SpecialChar ~
14117 \SpecialChar ~
14118 \SpecialChar ~
14119 \SpecialChar ~
14120 pop  _bp 
14121 \newline 
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 \SpecialChar ~
14126 ret
14127 \layout Standard
14128
14129 The compiling and linking procedure remains the same, however note the extra
14130  entry & exit linkage required for the assembler code, _bp is the stack
14131  frame pointer and is used to compute the offset into the stack for parameters
14132  and local variables.
14133 \layout Section
14134
14135 int (16 bit)
14136 \begin_inset LatexCommand \index{int (16 bit)}
14137
14138 \end_inset 
14139
14140  and long (32 bit)
14141 \begin_inset LatexCommand \index{long (32 bit)}
14142
14143 \end_inset 
14144
14145  Support
14146 \layout Standard
14147
14148 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14149  multiplication and modulus operations are implemented by support routines.
14150  These support routines are all developed in ANSI-C to facilitate porting
14151  to other MCUs, although some model specific assembler optimizations are
14152  used.
14153  The following files contain the described routines, all of them can be
14154  found in <installdir>/share/sdcc/lib.
14155 \newline 
14156
14157 \layout Standard
14158 \align center 
14159
14160 \begin_inset  Tabular
14161 <lyxtabular version="3" rows="11" columns="2">
14162 <features>
14163 <column alignment="center" valignment="top" leftline="true" width="0">
14164 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14165 <row topline="true" bottomline="true">
14166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14167 \begin_inset Text
14168
14169 \layout Standard
14170
14171
14172 \series bold 
14173 Function
14174 \end_inset 
14175 </cell>
14176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14177 \begin_inset Text
14178
14179 \layout Standard
14180
14181
14182 \series bold 
14183 Description
14184 \end_inset 
14185 </cell>
14186 </row>
14187 <row topline="true">
14188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14189 \begin_inset Text
14190
14191 \layout Standard
14192
14193 _mulint.c 
14194 \end_inset 
14195 </cell>
14196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14197 \begin_inset Text
14198
14199 \layout Standard
14200
14201 16 bit multiplication
14202 \end_inset 
14203 </cell>
14204 </row>
14205 <row topline="true">
14206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14207 \begin_inset Text
14208
14209 \layout Standard
14210
14211 _divsint.c 
14212 \end_inset 
14213 </cell>
14214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14215 \begin_inset Text
14216
14217 \layout Standard
14218
14219  signed 16 bit division (calls _divuint)
14220 \end_inset 
14221 </cell>
14222 </row>
14223 <row topline="true">
14224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14225 \begin_inset Text
14226
14227 \layout Standard
14228
14229 _divuint.c 
14230 \end_inset 
14231 </cell>
14232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14233 \begin_inset Text
14234
14235 \layout Standard
14236
14237  unsigned 16 bit division
14238 \end_inset 
14239 </cell>
14240 </row>
14241 <row topline="true">
14242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14243 \begin_inset Text
14244
14245 \layout Standard
14246
14247 _modsint.c
14248 \end_inset 
14249 </cell>
14250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14251 \begin_inset Text
14252
14253 \layout Standard
14254
14255 signed 16 bit modulus (calls _moduint)
14256 \end_inset 
14257 </cell>
14258 </row>
14259 <row topline="true">
14260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14261 \begin_inset Text
14262
14263 \layout Standard
14264
14265 _moduint.c
14266 \end_inset 
14267 </cell>
14268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14269 \begin_inset Text
14270
14271 \layout Standard
14272
14273 unsigned 16 bit modulus
14274 \end_inset 
14275 </cell>
14276 </row>
14277 <row topline="true">
14278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14279 \begin_inset Text
14280
14281 \layout Standard
14282
14283 _mullong.c
14284 \end_inset 
14285 </cell>
14286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14287 \begin_inset Text
14288
14289 \layout Standard
14290
14291 32 bit multiplication
14292 \end_inset 
14293 </cell>
14294 </row>
14295 <row topline="true">
14296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14297 \begin_inset Text
14298
14299 \layout Standard
14300
14301 _divslong.c 
14302 \end_inset 
14303 </cell>
14304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14305 \begin_inset Text
14306
14307 \layout Standard
14308
14309  signed 32 division (calls _divulong)
14310 \end_inset 
14311 </cell>
14312 </row>
14313 <row topline="true">
14314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14315 \begin_inset Text
14316
14317 \layout Standard
14318
14319 _divulong.c 
14320 \end_inset 
14321 </cell>
14322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14323 \begin_inset Text
14324
14325 \layout Standard
14326
14327 unsigned 32 division
14328 \end_inset 
14329 </cell>
14330 </row>
14331 <row topline="true">
14332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14333 \begin_inset Text
14334
14335 \layout Standard
14336
14337 _modslong.c
14338 \end_inset 
14339 </cell>
14340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14341 \begin_inset Text
14342
14343 \layout Standard
14344
14345  signed 32 bit modulus (calls _modulong)
14346 \end_inset 
14347 </cell>
14348 </row>
14349 <row topline="true" bottomline="true">
14350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14351 \begin_inset Text
14352
14353 \layout Standard
14354
14355 _modulong.c
14356 \end_inset 
14357 </cell>
14358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14359 \begin_inset Text
14360
14361 \layout Standard
14362
14363 unsigned 32 bit modulus
14364 \end_inset 
14365 </cell>
14366 </row>
14367 </lyxtabular>
14368
14369 \end_inset 
14370
14371
14372 \newline 
14373
14374 \layout Standard
14375
14376 Since they are compiled as 
14377 \emph on 
14378 non-reentrant
14379 \emph default 
14380
14381 \begin_inset LatexCommand \index{reentrant}
14382
14383 \end_inset 
14384
14385 , interrupt
14386 \begin_inset LatexCommand \index{interrupt}
14387
14388 \end_inset 
14389
14390  service routines should not do any of the above operations.
14391  If this is unavoidable then the above routines will need to be compiled
14392  with the 
14393 \emph on 
14394 -
14395 \begin_inset ERT
14396 status Collapsed
14397
14398 \layout Standard
14399
14400 \backslash 
14401 /
14402 \end_inset 
14403
14404 -stack-auto
14405 \begin_inset LatexCommand \index{-\/-stack-auto}
14406
14407 \end_inset 
14408
14409
14410 \emph default 
14411  option, after which the source program will have to be compiled with 
14412 \emph on 
14413 -
14414 \begin_inset ERT
14415 status Collapsed
14416
14417 \layout Standard
14418
14419 \backslash 
14420 /
14421 \end_inset 
14422
14423 -int-long-reent
14424 \begin_inset LatexCommand \index{-\/-int-long-reent}
14425
14426 \end_inset 
14427
14428
14429 \emph default 
14430  option.
14431  Notice that you don't have to call these routines directly.
14432  The compiler will use them automatically every time an integer operation
14433  is required.
14434 \layout Section
14435
14436 Floating Point Support
14437 \begin_inset LatexCommand \index{Floating point support}
14438
14439 \end_inset 
14440
14441
14442 \layout Standard
14443
14444 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
14445  floating point support routines are derived from gcc's floatlib.c and consist
14446  of the following routines:
14447 \newline 
14448
14449 \layout Standard
14450 \align center 
14451
14452 \size footnotesize 
14453
14454 \begin_inset  Tabular
14455 <lyxtabular version="3" rows="17" columns="2">
14456 <features>
14457 <column alignment="center" valignment="top" leftline="true" width="0">
14458 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14459 <row topline="true" bottomline="true">
14460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14461 \begin_inset Text
14462
14463 \layout Standard
14464
14465
14466 \family roman 
14467 \series medium 
14468 \shape up 
14469 \size normal 
14470 \emph off 
14471 \bar no 
14472 \noun off 
14473 \color none
14474 Function 
14475 \end_inset 
14476 </cell>
14477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14478 \begin_inset Text
14479
14480 \layout Standard
14481
14482 Description
14483 \end_inset 
14484 </cell>
14485 </row>
14486 <row topline="true">
14487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14488 \begin_inset Text
14489
14490 \layout Standard
14491
14492
14493 \family roman 
14494 \series medium 
14495 \shape up 
14496 \size normal 
14497 \emph off 
14498 \bar no 
14499 \noun off 
14500 \color none
14501 _fsadd.c
14502 \end_inset 
14503 </cell>
14504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14505 \begin_inset Text
14506
14507 \layout Standard
14508
14509
14510 \family roman 
14511 \series medium 
14512 \shape up 
14513 \size normal 
14514 \emph off 
14515 \bar no 
14516 \noun off 
14517 \color none
14518 add floating point numbers
14519 \end_inset 
14520 </cell>
14521 </row>
14522 <row topline="true">
14523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14524 \begin_inset Text
14525
14526 \layout Standard
14527
14528
14529 \family roman 
14530 \series medium 
14531 \shape up 
14532 \size normal 
14533 \emph off 
14534 \bar no 
14535 \noun off 
14536 \color none
14537 _fssub.c 
14538 \end_inset 
14539 </cell>
14540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14541 \begin_inset Text
14542
14543 \layout Standard
14544
14545
14546 \family roman 
14547 \series medium 
14548 \shape up 
14549 \size normal 
14550 \emph off 
14551 \bar no 
14552 \noun off 
14553 \color none
14554 subtract floating point numbers 
14555 \end_inset 
14556 </cell>
14557 </row>
14558 <row topline="true">
14559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14560 \begin_inset Text
14561
14562 \layout Standard
14563
14564
14565 \family roman 
14566 \series medium 
14567 \shape up 
14568 \size normal 
14569 \emph off 
14570 \bar no 
14571 \noun off 
14572 \color none
14573 _fsdiv.c 
14574 \end_inset 
14575 </cell>
14576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14577 \begin_inset Text
14578
14579 \layout Standard
14580
14581
14582 \family roman 
14583 \series medium 
14584 \shape up 
14585 \size normal 
14586 \emph off 
14587 \bar no 
14588 \noun off 
14589 \color none
14590 divide floating point numbers 
14591 \end_inset 
14592 </cell>
14593 </row>
14594 <row topline="true">
14595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14596 \begin_inset Text
14597
14598 \layout Standard
14599
14600
14601 \family roman 
14602 \series medium 
14603 \shape up 
14604 \size normal 
14605 \emph off 
14606 \bar no 
14607 \noun off 
14608 \color none
14609 _fsmul.c 
14610 \end_inset 
14611 </cell>
14612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14613 \begin_inset Text
14614
14615 \layout Standard
14616
14617
14618 \family roman 
14619 \series medium 
14620 \shape up 
14621 \size normal 
14622 \emph off 
14623 \bar no 
14624 \noun off 
14625 \color none
14626 multiply floating point numbers 
14627 \end_inset 
14628 </cell>
14629 </row>
14630 <row topline="true">
14631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14632 \begin_inset Text
14633
14634 \layout Standard
14635
14636
14637 \family roman 
14638 \series medium 
14639 \shape up 
14640 \size normal 
14641 \emph off 
14642 \bar no 
14643 \noun off 
14644 \color none
14645 _fs2uchar.c
14646 \end_inset 
14647 </cell>
14648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14649 \begin_inset Text
14650
14651 \layout Standard
14652
14653
14654 \family roman 
14655 \series medium 
14656 \shape up 
14657 \size normal 
14658 \emph off 
14659 \bar no 
14660 \noun off 
14661 \color none
14662 convert floating point to unsigned char
14663 \end_inset 
14664 </cell>
14665 </row>
14666 <row topline="true">
14667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14668 \begin_inset Text
14669
14670 \layout Standard
14671
14672
14673 \family roman 
14674 \series medium 
14675 \shape up 
14676 \size normal 
14677 \emph off 
14678 \bar no 
14679 \noun off 
14680 \color none
14681 _fs2char.c
14682 \end_inset 
14683 </cell>
14684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14685 \begin_inset Text
14686
14687 \layout Standard
14688
14689
14690 \family roman 
14691 \series medium 
14692 \shape up 
14693 \size normal 
14694 \emph off 
14695 \bar no 
14696 \noun off 
14697 \color none
14698 convert floating point to signed char
14699 \end_inset 
14700 </cell>
14701 </row>
14702 <row topline="true">
14703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14704 \begin_inset Text
14705
14706 \layout Standard
14707
14708
14709 \family roman 
14710 \series medium 
14711 \shape up 
14712 \size normal 
14713 \emph off 
14714 \bar no 
14715 \noun off 
14716 \color none
14717 _fs2uint.c
14718 \end_inset 
14719 </cell>
14720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14721 \begin_inset Text
14722
14723 \layout Standard
14724
14725
14726 \family roman 
14727 \series medium 
14728 \shape up 
14729 \size normal 
14730 \emph off 
14731 \bar no 
14732 \noun off 
14733 \color none
14734 convert floating point to unsigned int
14735 \end_inset 
14736 </cell>
14737 </row>
14738 <row topline="true">
14739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14740 \begin_inset Text
14741
14742 \layout Standard
14743
14744
14745 \family roman 
14746 \series medium 
14747 \shape up 
14748 \size normal 
14749 \emph off 
14750 \bar no 
14751 \noun off 
14752 \color none
14753 _fs2int.c
14754 \end_inset 
14755 </cell>
14756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14757 \begin_inset Text
14758
14759 \layout Standard
14760
14761
14762 \family roman 
14763 \series medium 
14764 \shape up 
14765 \size normal 
14766 \emph off 
14767 \bar no 
14768 \noun off 
14769 \color none
14770 convert floating point to signed int
14771 \end_inset 
14772 </cell>
14773 </row>
14774 <row topline="true">
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14776 \begin_inset Text
14777
14778 \layout Standard
14779
14780
14781 \family roman 
14782 \series medium 
14783 \shape up 
14784 \size normal 
14785 \emph off 
14786 \bar no 
14787 \noun off 
14788 \color none
14789 _fs2ulong.
14790 \family default 
14791 \series default 
14792 \shape default 
14793 \size default 
14794 \emph default 
14795 \bar default 
14796 \noun default 
14797 \color default
14798 c
14799 \end_inset 
14800 </cell>
14801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14802 \begin_inset Text
14803
14804 \layout Standard
14805
14806
14807 \family roman 
14808 \series medium 
14809 \shape up 
14810 \size normal 
14811 \emph off 
14812 \bar no 
14813 \noun off 
14814 \color none
14815 convert floating point to unsigned long
14816 \end_inset 
14817 </cell>
14818 </row>
14819 <row topline="true">
14820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14821 \begin_inset Text
14822
14823 \layout Standard
14824
14825
14826 \family roman 
14827 \series medium 
14828 \shape up 
14829 \size normal 
14830 \emph off 
14831 \bar no 
14832 \noun off 
14833 \color none
14834 _fs2long.c
14835 \end_inset 
14836 </cell>
14837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14838 \begin_inset Text
14839
14840 \layout Standard
14841
14842
14843 \family roman 
14844 \series medium 
14845 \shape up 
14846 \size normal 
14847 \emph off 
14848 \bar no 
14849 \noun off 
14850 \color none
14851 convert floating point to signed long
14852 \end_inset 
14853 </cell>
14854 </row>
14855 <row topline="true">
14856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14857 \begin_inset Text
14858
14859 \layout Standard
14860
14861
14862 \family roman 
14863 \series medium 
14864 \shape up 
14865 \size normal 
14866 \emph off 
14867 \bar no 
14868 \noun off 
14869 \color none
14870 _uchar2fs.c
14871 \end_inset 
14872 </cell>
14873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14874 \begin_inset Text
14875
14876 \layout Standard
14877
14878
14879 \family roman 
14880 \series medium 
14881 \shape up 
14882 \size normal 
14883 \emph off 
14884 \bar no 
14885 \noun off 
14886 \color none
14887 convert unsigned char to floating point
14888 \end_inset 
14889 </cell>
14890 </row>
14891 <row topline="true">
14892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14893 \begin_inset Text
14894
14895 \layout Standard
14896
14897
14898 \family roman 
14899 \series medium 
14900 \shape up 
14901 \size normal 
14902 \emph off 
14903 \bar no 
14904 \noun off 
14905 \color none
14906 _char2fs.c
14907 \end_inset 
14908 </cell>
14909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14910 \begin_inset Text
14911
14912 \layout Standard
14913
14914
14915 \family roman 
14916 \series medium 
14917 \shape up 
14918 \size normal 
14919 \emph off 
14920 \bar no 
14921 \noun off 
14922 \color none
14923 convert char to floating point number
14924 \end_inset 
14925 </cell>
14926 </row>
14927 <row topline="true">
14928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14929 \begin_inset Text
14930
14931 \layout Standard
14932
14933
14934 \family roman 
14935 \series medium 
14936 \shape up 
14937 \size normal 
14938 \emph off 
14939 \bar no 
14940 \noun off 
14941 \color none
14942 _uint2fs.c
14943 \end_inset 
14944 </cell>
14945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14946 \begin_inset Text
14947
14948 \layout Standard
14949
14950
14951 \family roman 
14952 \series medium 
14953 \shape up 
14954 \size normal 
14955 \emph off 
14956 \bar no 
14957 \noun off 
14958 \color none
14959 convert unsigned int to floating point
14960 \end_inset 
14961 </cell>
14962 </row>
14963 <row topline="true">
14964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14965 \begin_inset Text
14966
14967 \layout Standard
14968
14969
14970 \family roman 
14971 \series medium 
14972 \shape up 
14973 \size normal 
14974 \emph off 
14975 \bar no 
14976 \noun off 
14977 \color none
14978 _int2fs.c
14979 \end_inset 
14980 </cell>
14981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14982 \begin_inset Text
14983
14984 \layout Standard
14985
14986
14987 \family roman 
14988 \series medium 
14989 \shape up 
14990 \size normal 
14991 \emph off 
14992 \bar no 
14993 \noun off 
14994 \color none
14995 convert int to floating point numbers
14996 \end_inset 
14997 </cell>
14998 </row>
14999 <row topline="true">
15000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15001 \begin_inset Text
15002
15003 \layout Standard
15004
15005
15006 \family roman 
15007 \series medium 
15008 \shape up 
15009 \size normal 
15010 \emph off 
15011 \bar no 
15012 \noun off 
15013 \color none
15014 _ulong2fs.c
15015 \end_inset 
15016 </cell>
15017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15018 \begin_inset Text
15019
15020 \layout Standard
15021
15022
15023 \family roman 
15024 \series medium 
15025 \shape up 
15026 \size normal 
15027 \emph off 
15028 \bar no 
15029 \noun off 
15030 \color none
15031 convert unsigned long to floating point number
15032 \end_inset 
15033 </cell>
15034 </row>
15035 <row topline="true" bottomline="true">
15036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15037 \begin_inset Text
15038
15039 \layout Standard
15040
15041
15042 \family roman 
15043 \series medium 
15044 \shape up 
15045 \size normal 
15046 \emph off 
15047 \bar no 
15048 \noun off 
15049 \color none
15050 _long2fs.c
15051 \end_inset 
15052 </cell>
15053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15054 \begin_inset Text
15055
15056 \layout Standard
15057
15058
15059 \family roman 
15060 \series medium 
15061 \shape up 
15062 \size normal 
15063 \emph off 
15064 \bar no 
15065 \noun off 
15066 \color none
15067 convert long to floating point number
15068 \end_inset 
15069 </cell>
15070 </row>
15071 </lyxtabular>
15072
15073 \end_inset 
15074
15075
15076 \newline 
15077
15078 \layout Standard
15079
15080 These support routines are developed in ANSI-C so there is room for space
15081  and speed improvement
15082 \begin_inset Foot
15083 collapsed false
15084
15085 \layout Standard
15086
15087 The floating point routines for the mcs51 are implemented in assembler
15088 \end_inset 
15089
15090 .
15091  Note if all these routines are used simultaneously the data space might
15092  overflow.
15093  For serious floating point usage the large model might be needed.
15094  Also notice that you don't have to call this routines directly.
15095  The compiler will use them automatically every time a floating point operation
15096  is required.
15097 \layout Section
15098
15099 Library Routines
15100 \begin_inset LatexCommand \index{Libraries}
15101
15102 \end_inset 
15103
15104
15105 \layout Standard
15106
15107
15108 \emph on 
15109 <pending: this is messy and incomplete - a little more information is in
15110  sdcc/doc/libdoc.txt
15111 \emph default 
15112  >
15113 \layout Subsection
15114
15115 Compiler support routines (_gptrget, _mulint etc.)
15116 \layout Subsection
15117
15118 Stdclib functions (puts, printf, strcat etc.)
15119 \layout Subsubsection
15120
15121 <stdio.h>
15122 \layout Standard
15123
15124
15125 \begin_inset LatexCommand \index{<stdio.h>}
15126
15127 \end_inset 
15128
15129 As usual on embedded systems you have to provide your own 
15130 \family typewriter 
15131 getchar()
15132 \begin_inset LatexCommand \index{getchar()}
15133
15134 \end_inset 
15135
15136  
15137 \family default 
15138 and 
15139 \family typewriter 
15140 putchar()
15141 \begin_inset LatexCommand \index{putchar()}
15142
15143 \end_inset 
15144
15145
15146 \family default 
15147  routines.
15148  SDCC does not know whether the system connects to a serial line with or
15149  without handshake, LCD, keyboard or other device.
15150  You'll find examples for serial routines f.e.
15151  in sdcc/device/lib.
15152 \layout Standard
15153
15154 The default
15155 \family typewriter 
15156  printf()
15157 \begin_inset LatexCommand \index{printf()}
15158
15159 \end_inset 
15160
15161
15162 \family default 
15163 implementation in
15164 \family typewriter 
15165  printf_large.c
15166 \family default 
15167  does not support float (except on ds390).
15168  To enable this recompile it with the option 
15169 \emph on 
15170 -
15171 \begin_inset ERT
15172 status Collapsed
15173
15174 \layout Standard
15175
15176 \backslash 
15177 /
15178 \end_inset 
15179
15180 DUSE_FLOATS=1
15181 \begin_inset LatexCommand \index{USE\_FLOATS}
15182
15183 \end_inset 
15184
15185
15186 \emph default 
15187  on the command line.
15188  Use
15189 \emph on 
15190 -
15191 \begin_inset ERT
15192 status Collapsed
15193
15194 \layout Standard
15195
15196 \backslash 
15197 /
15198 \end_inset 
15199
15200 -model-large
15201 \begin_inset LatexCommand \index{-\/-model-large}
15202
15203 \end_inset 
15204
15205
15206 \emph default 
15207  for the mcs51 port, since this uses a lot of memory.
15208 \layout Standard
15209
15210 If you're short on memory you might want to use 
15211 \family typewriter 
15212 printf_small()
15213 \begin_inset LatexCommand \index{printf\_small()}
15214
15215 \end_inset 
15216
15217
15218 \family default 
15219  
15220 \emph on 
15221 instead
15222 \emph default 
15223  of
15224 \family typewriter 
15225  printf().
15226
15227 \family default 
15228  For the mcs51 there additionally are assembly versions 
15229 \family typewriter 
15230 printf_tiny()
15231 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
15232
15233 \end_inset 
15234
15235
15236 \family default 
15237  and 
15238 \family typewriter 
15239 printf_fast()
15240 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
15241
15242 \end_inset 
15243
15244  
15245 \family default 
15246 and
15247 \family typewriter 
15248  printf_fast_f()
15249 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
15250
15251 \end_inset 
15252
15253
15254 \family default 
15255  which should fit the requirements of many embedded systems (printf_fast()
15256  can be customized by unsetting #defines to 
15257 \emph on 
15258 not
15259 \emph default 
15260  support long variables and field widths).
15261 \layout Subsection
15262
15263 Math functions (sin, pow, sqrt etc.)
15264 \layout Subsection
15265
15266 Other libraries
15267 \layout Standard
15268
15269 Libraries
15270 \begin_inset LatexCommand \index{Libraries}
15271
15272 \end_inset 
15273
15274  included in SDCC should have a license at least as liberal as the GNU Lesser
15275  General Public License
15276 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15277
15278 \end_inset 
15279
15280  
15281 \emph on 
15282 LGPL
15283 \emph default 
15284 .
15285 \layout Comment
15286
15287 license statements for the libraries are missing.
15288  sdcc/device/lib/ser_ir.c
15289 \layout Comment
15290
15291 or _decdptr f.e.
15292  come with a GPL (as opposed to LGPL) License - this will not be liberal
15293  enough for many embedded programmers.
15294 \layout Standard
15295
15296 If you have ported some library or want to share experience about some code
15297  which f.e.
15298  falls into any of these categories Busses (I
15299 \begin_inset Formula $^{\textrm{2}}$
15300 \end_inset 
15301
15302 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
15303  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
15304  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
15305 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
15306
15307 \end_inset 
15308
15309 \SpecialChar ~
15310 would certainly like to hear about it.
15311  Programmers coding for embedded systems are not especially famous for being
15312  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
15313 e these references are very valuable.
15314  Let's help to create a climate where information is shared.
15315 \layout Section
15316
15317 Memory Models
15318 \layout Subsection
15319
15320 MCS51 Memory Models
15321 \begin_inset LatexCommand \index{Memory model}
15322
15323 \end_inset 
15324
15325
15326 \begin_inset LatexCommand \index{MCS51 memory model}
15327
15328 \end_inset 
15329
15330
15331 \layout Subsubsection
15332
15333 Small, Medium and Large
15334 \layout Standard
15335
15336 SDCC allows three memory models for MCS51 code, 
15337 \shape slanted 
15338 small, medium
15339 \shape default 
15340  and 
15341 \shape slanted 
15342 large
15343 \shape default 
15344 .
15345  Modules compiled with different memory models should 
15346 \emph on 
15347 never
15348 \emph default 
15349  be combined together or the results would be unpredictable.
15350  The library routines supplied with the compiler are compiled as small,
15351  medium and large.
15352  The compiled library modules are contained in separate directories as small,
15353  medium and large so that you can link to the appropriate set.
15354 \layout Standard
15355
15356 When the medium or large model is used all variables declared without a
15357  storage class will be allocated into the external ram, this includes all
15358  parameters and local variables (for non-reentrant
15359 \begin_inset LatexCommand \index{reentrant}
15360
15361 \end_inset 
15362
15363  functions).
15364  When the small model is used variables without storage class are allocated
15365  in the internal ram.
15366 \layout Standard
15367
15368 Judicious usage of the processor specific storage classes
15369 \begin_inset LatexCommand \index{Storage class}
15370
15371 \end_inset 
15372
15373  and the 'reentrant' function type will yield much more efficient code,
15374  than using the large model.
15375  Several optimizations are disabled when the program is compiled using the
15376  large model, it is therefore recommended that the small model be used unless
15377  absolutely required.
15378 \layout Subsubsection
15379
15380 External Stack
15381 \begin_inset LatexCommand \label{sub:External-Stack}
15382
15383 \end_inset 
15384
15385
15386 \begin_inset LatexCommand \index{stack}
15387
15388 \end_inset 
15389
15390
15391 \begin_inset LatexCommand \index{External stack (mcs51)}
15392
15393 \end_inset 
15394
15395
15396 \layout Standard
15397
15398 The external stack (-
15399 \begin_inset ERT
15400 status Collapsed
15401
15402 \layout Standard
15403
15404 \backslash 
15405 /
15406 \end_inset 
15407
15408 -xstack option
15409 \begin_inset LatexCommand \index{-\/-xstack}
15410
15411 \end_inset 
15412
15413 ) is located in pdata
15414 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
15415
15416 \end_inset 
15417
15418  memory (usually at the start of the external ram segment) and uses all
15419  unused space in pdata (max.
15420  256 bytes).
15421  When -
15422 \begin_inset ERT
15423 status Collapsed
15424
15425 \layout Standard
15426
15427 \backslash 
15428 /
15429 \end_inset 
15430
15431 -xstack option is used to compile the program, the parameters and local
15432  variables
15433 \begin_inset LatexCommand \index{local variables}
15434
15435 \end_inset 
15436
15437  of all reentrant functions are allocated in this area.
15438  This option is provided for programs with large stack space requirements.
15439  When used with the -
15440 \begin_inset ERT
15441 status Collapsed
15442
15443 \layout Standard
15444
15445 \backslash 
15446 /
15447 \end_inset 
15448
15449 -stack-auto
15450 \begin_inset LatexCommand \index{-\/-stack-auto}
15451
15452 \end_inset 
15453
15454  option, all parameters and local variables are allocated on the external
15455  stack (note: support libraries will need to be recompiled with the same
15456  options.
15457  There is a predefined target in the library makefile).
15458 \layout Standard
15459
15460 The compiler outputs the higher order address byte of the external ram segment
15461  into port P2
15462 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
15463
15464 \end_inset 
15465
15466  (see also section 
15467 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15468
15469 \end_inset 
15470
15471 ), therefore when using the External Stack option, this port 
15472 \emph on 
15473 may not
15474 \emph default 
15475  be used by the application program.
15476 \layout Subsection
15477
15478 DS390 Memory Model
15479 \begin_inset LatexCommand \index{Memory model}
15480
15481 \end_inset 
15482
15483
15484 \begin_inset LatexCommand \index{DS390 memory model}
15485
15486 \end_inset 
15487
15488
15489 \layout Standard
15490
15491 The only model supported is Flat 24
15492 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
15493
15494 \end_inset 
15495
15496 .
15497  This generates code for the 24 bit contiguous addressing mode of the Dallas
15498  DS80C390 part.
15499  In this mode, up to four meg of external RAM or code space can be directly
15500  addressed.
15501  See the data sheets at www.dalsemi.com for further information on this part.
15502 \newline 
15503
15504 \newline 
15505 Note that the compiler does not generate any code to place the processor
15506  into 24 bitmode (although 
15507 \emph on 
15508 tinibios
15509 \emph default 
15510  in the ds390 libraries will do that for you).
15511  If you don't use 
15512 \emph on 
15513 tinibios
15514 \emph default 
15515
15516 \begin_inset LatexCommand \index{Tinibios (DS390)}
15517
15518 \end_inset 
15519
15520 , the boot loader or similar code must ensure that the processor is in 24
15521  bit contiguous addressing mode before calling the SDCC startup code.
15522 \newline 
15523
15524 \newline 
15525 Like the 
15526 \emph on 
15527 -
15528 \begin_inset ERT
15529 status Collapsed
15530
15531 \layout Standard
15532
15533 \backslash 
15534 /
15535 \end_inset 
15536
15537 -model-large
15538 \emph default 
15539  option, variables will by default be placed into the XDATA segment.
15540  
15541 \newline 
15542
15543 \newline 
15544 Segments may be placed anywhere in the 4 meg address space using the usual
15545  -
15546 \begin_inset ERT
15547 status Collapsed
15548
15549 \layout Standard
15550
15551 \backslash 
15552 /
15553 \end_inset 
15554
15555 -*-loc options.
15556  Note that if any segments are located above 64K, the -r flag must be passed
15557  to the linker to generate the proper segment relocations, and the Intel
15558  HEX output format must be used.
15559  The -r flag can be passed to the linker by using the option 
15560 \emph on 
15561 -Wl-r
15562 \emph default 
15563  on the SDCC command line.
15564  However, currently the linker can not handle code segments > 64k.
15565 \layout Section
15566
15567 Pragmas
15568 \begin_inset LatexCommand \index{Pragmas}
15569
15570 \end_inset 
15571
15572
15573 \layout Standard
15574
15575 SDCC supports the following #pragma directives:
15576 \layout Itemize
15577
15578 save
15579 \begin_inset LatexCommand \index{\#pragma save}
15580
15581 \end_inset 
15582
15583  - this will save all current options to the save/restore stack.
15584  See #pragma\SpecialChar ~
15585 restore.
15586 \layout Itemize
15587
15588 restore
15589 \begin_inset LatexCommand \index{\#pragma restore}
15590
15591 \end_inset 
15592
15593  - will restore saved options from the last save.
15594  saves & restores can be nested.
15595  SDCC uses a save/restore stack: save pushes current options to the stack,
15596  restore pulls current options from the stack.
15597  See #pragma\SpecialChar ~
15598 save.
15599 \newline 
15600
15601 \layout Itemize
15602
15603 callee_saves
15604 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15605
15606 \end_inset 
15607
15608
15609 \begin_inset LatexCommand \index{function prologue}
15610
15611 \end_inset 
15612
15613  function1[,function2[,function3...]] - The compiler by default uses a caller
15614  saves convention for register saving across function calls, however this
15615  can cause unnecessary register pushing & popping
15616 \begin_inset LatexCommand \index{push/pop}
15617
15618 \end_inset 
15619
15620  when calling small functions from larger functions.
15621  This option can be used to switch off the register saving convention for
15622  the function names specified.
15623  The compiler will not save registers when calling these functions, extra
15624  code need to be manually inserted at the entry & exit for these functions
15625  to save & restore the registers used by these functions, this can SUBSTANTIALLY
15626  reduce code & improve run time performance of the generated code.
15627  In the future the compiler (with inter procedural analysis) may be able
15628  to determine the appropriate scheme to use for each function call.
15629  If -
15630 \begin_inset ERT
15631 status Collapsed
15632
15633 \layout Standard
15634
15635 \backslash 
15636 /
15637 \end_inset 
15638
15639 -callee-saves command line option is used, the function names specified
15640  in #pragma\SpecialChar ~
15641 callee_saves
15642 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15643
15644 \end_inset 
15645
15646  is appended to the list of functions specified in the command line.
15647 \layout Itemize
15648
15649 exclude
15650 \begin_inset LatexCommand \index{\#pragma exclude}
15651
15652 \end_inset 
15653
15654  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
15655  of pairs of push/pop
15656 \begin_inset LatexCommand \index{push/pop}
15657
15658 \end_inset 
15659
15660  instructions in 
15661 \emph on 
15662 I
15663 \emph default 
15664 nterrupt
15665 \begin_inset LatexCommand \index{interrupt}
15666
15667 \end_inset 
15668
15669  
15670 \emph on 
15671 S
15672 \emph default 
15673 ervice 
15674 \emph on 
15675 R
15676 \emph default 
15677 outines.
15678  The directive should be placed immediately before the ISR function definition
15679  and it affects ALL ISR functions following it.
15680  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
15681 exclude\SpecialChar ~
15682 none
15683 \begin_inset LatexCommand \index{\#pragma exclude}
15684
15685 \end_inset 
15686
15687 .
15688  See also the related keyword _naked
15689 \begin_inset LatexCommand \index{\_naked}
15690
15691 \end_inset 
15692
15693
15694 \begin_inset LatexCommand \index{\_\_naked}
15695
15696 \end_inset 
15697
15698 .
15699 \layout Itemize
15700
15701 less_pedantic
15702 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
15703
15704 \end_inset 
15705
15706  - the compiler will not warn you anymore for obvious mistakes, you'r on
15707  your own now ;-(
15708 \layout Itemize
15709
15710 disable_warning <nnnn>
15711 \begin_inset LatexCommand \index{\#pragma disable\_warning}
15712
15713 \end_inset 
15714
15715  - the compiler will not warn you anymore about warning number <nnnn>.
15716 \layout Itemize
15717
15718 nogcse
15719 \begin_inset LatexCommand \index{\#pragma nogcse}
15720
15721 \end_inset 
15722
15723  - will stop global common subexpression elimination.
15724 \layout Itemize
15725
15726 noinduction
15727 \begin_inset LatexCommand \index{\#pragma noinduction}
15728
15729 \end_inset 
15730
15731  - will stop loop induction optimizations.
15732 \layout Itemize
15733
15734 noinvariant
15735 \begin_inset LatexCommand \index{\#pragma noinvariant}
15736
15737 \end_inset 
15738
15739  - will not do loop invariant optimizations.
15740  For more details see Loop Invariants in section
15741 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
15742
15743 \end_inset 
15744
15745 .
15746 \layout Itemize
15747
15748 noiv
15749 \begin_inset LatexCommand \index{\#pragma noiv}
15750
15751 \end_inset 
15752
15753  - Do not generate interrupt
15754 \begin_inset LatexCommand \index{interrupt}
15755
15756 \end_inset 
15757
15758  vector table entries for all ISR functions defined after the pragma.
15759  This is useful in cases where the interrupt vector table must be defined
15760  manually, or when there is a secondary, manually defined interrupt vector
15761  table (e.g.
15762  for the autovector feature of the Cypress EZ-USB FX2).
15763  More elegantly this can be achieved by obmitting the optional interrupt
15764  number after the interrupt keyword, see section 
15765 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
15766
15767 \end_inset 
15768
15769 \SpecialChar ~
15770 about interrupts.
15771 \layout Itemize
15772
15773 nojtbound
15774 \begin_inset LatexCommand \index{\#pragma nojtbound}
15775
15776 \end_inset 
15777
15778  - will not generate code for boundary value checking, when switch statements
15779  are turned into jump-tables (dangerous).
15780  For more details see section 
15781 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
15782
15783 \end_inset 
15784
15785 .
15786 \layout Itemize
15787
15788 noloopreverse
15789 \begin_inset LatexCommand \index{\#pragma noloopreverse}
15790
15791 \end_inset 
15792
15793  - Will not do loop reversal optimization
15794 \layout Itemize
15795
15796 nooverlay
15797 \begin_inset LatexCommand \index{\#pragma nooverlay}
15798
15799 \end_inset 
15800
15801  - the compiler will not overlay the parameters and local variables of a
15802  function.
15803 \layout Itemize
15804
15805 stackauto
15806 \begin_inset LatexCommand \index{\#pragma stackauto}
15807
15808 \end_inset 
15809
15810 - See option -
15811 \begin_inset ERT
15812 status Collapsed
15813
15814 \layout Standard
15815
15816 \backslash 
15817 /
15818 \end_inset 
15819
15820 -stack-auto
15821 \begin_inset LatexCommand \index{-\/-stack-auto}
15822
15823 \end_inset 
15824
15825  and section 
15826 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
15827
15828 \end_inset 
15829
15830  Parameters and Local Variables.
15831 \layout Itemize
15832
15833 opt_code_speed 
15834 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
15835
15836 \end_inset 
15837
15838 - The compiler will optimize code generation towards fast code, possibly
15839  at the expense of code size.
15840 \layout Itemize
15841
15842 opt_code_size 
15843 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
15844
15845 \end_inset 
15846
15847 - The compiler will optimize code generation towards compact code, possibly
15848  at the expense of code speed.
15849 \layout Itemize
15850
15851 opt_code_balanced 
15852 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
15853
15854 \end_inset 
15855
15856 - The compiler will attempt to generate code that is both compact and fast,
15857  as long as meeting one goal is not a detriment to the other (this is the
15858  default).
15859  
15860 \layout Itemize
15861
15862 std_sdcc89 
15863 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
15864
15865 \end_inset 
15866
15867 - Generally follow the C89 standard, but allow SDCC features that conflict
15868  with the standard (default).
15869 \layout Itemize
15870
15871 std_c89 
15872 \begin_inset LatexCommand \index{\#pragma std\_c89}
15873
15874 \end_inset 
15875
15876 - Follow the C89 standard and disable SDCC features that conflict with the
15877  standard.
15878 \layout Itemize
15879
15880 std_sdcc99 
15881 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
15882
15883 \end_inset 
15884
15885 - Generally follow the C99 standard, but allow SDCC features that conflict
15886  with the standard (incomplete support).
15887 \layout Itemize
15888
15889 std_c99 
15890 \begin_inset LatexCommand \index{\#pragma std\_c99}
15891
15892 \end_inset 
15893
15894 - Follow the C99 standard and disable SDCC features that conflict with the
15895  standard (incomplete support).
15896 \layout Itemize
15897
15898 codeseg <name>
15899 \begin_inset LatexCommand \index{\#pragma codeseg}
15900
15901 \end_inset 
15902
15903 - Use this name (max.
15904  8 characters) for the code segment.
15905 \layout Itemize
15906
15907 constseg <name>
15908 \begin_inset LatexCommand \index{\#pragma constseg}
15909
15910 \end_inset 
15911
15912 - Use this name (max.
15913  8 characters) for the const segment.
15914 \layout Standard
15915
15916 SDCPP supports the following #pragma directives:
15917 \layout Itemize
15918
15919 preproc_asm
15920 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
15921
15922 \end_inset 
15923
15924  (+ | -) - switch _asm _endasm block preprocessing on / off.
15925  Default is on.
15926 \layout Standard
15927
15928 The pragma's are intended to be used to turn-on or off certain optimizations
15929  which might cause the compiler to generate extra stack / data space to
15930  store compiler generated temporary variables.
15931  This usually happens in large functions.
15932  Pragma directives should be used as shown in the following example, they
15933  are used to control options & optimizations for a given function; pragmas
15934  should be placed before and/or after a function, placing pragma's inside
15935  a function body could have unpredictable results.
15936 \layout Verse
15937
15938
15939 \family typewriter 
15940 #pragma save
15941 \begin_inset LatexCommand \index{\#pragma save}
15942
15943 \end_inset 
15944
15945  \SpecialChar ~
15946 \SpecialChar ~
15947 \SpecialChar ~
15948 \SpecialChar ~
15949 \SpecialChar ~
15950 \SpecialChar ~
15951 \SpecialChar ~
15952 /* save the current settings */ 
15953 \newline 
15954 #pragma nogcse
15955 \begin_inset LatexCommand \index{\#pragma nogcse}
15956
15957 \end_inset 
15958
15959  \SpecialChar ~
15960 \SpecialChar ~
15961 \SpecialChar ~
15962 \SpecialChar ~
15963 \SpecialChar ~
15964 /* turnoff global subexpression elimination */ 
15965 \newline 
15966 #pragma noinduction
15967 \begin_inset LatexCommand \index{\#pragma noinduction}
15968
15969 \end_inset 
15970
15971  /* turn off induction optimizations */ 
15972 \newline 
15973 int foo () 
15974 \newline 
15975
15976 \newline 
15977 \SpecialChar ~
15978  \SpecialChar ~
15979  ...
15980  
15981 \newline 
15982 \SpecialChar ~
15983  \SpecialChar ~
15984  /* large code */ 
15985 \newline 
15986 \SpecialChar ~
15987  \SpecialChar ~
15988  ...
15989  
15990 \newline 
15991
15992 \newline 
15993 #pragma restore
15994 \begin_inset LatexCommand \index{\#pragma restore}
15995
15996 \end_inset 
15997
15998  /* turn the optimizations back on */
15999 \layout Standard
16000
16001 The compiler will generate a warning message when extra space is allocated.
16002  It is strongly recommended that the save and restore pragma's be used when
16003  changing options for a function.
16004 \layout Section
16005
16006 Defines Created by the Compiler
16007 \layout Standard
16008
16009 The compiler creates the following #defines
16010 \begin_inset LatexCommand \index{\#defines}
16011
16012 \end_inset 
16013
16014
16015 \begin_inset LatexCommand \index{Defines created by the compiler}
16016
16017 \end_inset 
16018
16019 :
16020 \newline 
16021
16022 \layout Standard
16023
16024
16025 \begin_inset  Tabular
16026 <lyxtabular version="3" rows="11" columns="2">
16027 <features>
16028 <column alignment="center" valignment="top" leftline="true" width="0">
16029 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16030 <row topline="true" bottomline="true">
16031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16032 \begin_inset Text
16033
16034 \layout Standard
16035
16036
16037 \series bold 
16038 #define
16039 \end_inset 
16040 </cell>
16041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16042 \begin_inset Text
16043
16044 \layout Standard
16045
16046
16047 \series bold 
16048 Description
16049 \end_inset 
16050 </cell>
16051 </row>
16052 <row topline="true">
16053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16054 \begin_inset Text
16055
16056 \layout Standard
16057
16058 SDCC
16059 \begin_inset LatexCommand \index{SDCC}
16060
16061 \end_inset 
16062
16063  
16064 \end_inset 
16065 </cell>
16066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16067 \begin_inset Text
16068
16069 \layout Standard
16070
16071 this Symbol is always defined.
16072  Since version 2.5.6 it's this version number as an int (ex.
16073  256)
16074 \end_inset 
16075 </cell>
16076 </row>
16077 <row topline="true">
16078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16079 \begin_inset Text
16080
16081 \layout Standard
16082
16083 SDCC_mcs51
16084 \begin_inset LatexCommand \index{SDCC\_mcs51}
16085
16086 \end_inset 
16087
16088  or SDCC_ds390
16089 \begin_inset LatexCommand \index{SDCC\_ds390}
16090
16091 \end_inset 
16092
16093  or SDCC_z80
16094 \begin_inset LatexCommand \index{SDCC\_z80}
16095
16096 \end_inset 
16097
16098 , etc
16099 \end_inset 
16100 </cell>
16101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16102 \begin_inset Text
16103
16104 \layout Standard
16105
16106 depending on the model used (e.g.: -mds390
16107 \end_inset 
16108 </cell>
16109 </row>
16110 <row topline="true">
16111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16112 \begin_inset Text
16113
16114 \layout Standard
16115
16116 __mcs51
16117 \begin_inset LatexCommand \index{\_\_mcs51}
16118
16119 \end_inset 
16120
16121 , __ds390
16122 \begin_inset LatexCommand \index{\_\_ds390}
16123
16124 \end_inset 
16125
16126 , __hc08
16127 \begin_inset LatexCommand \index{\_\_hc08}
16128
16129 \end_inset 
16130
16131 , __z80
16132 \begin_inset LatexCommand \index{\_\_z80}
16133
16134 \end_inset 
16135
16136 , etc
16137 \end_inset 
16138 </cell>
16139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16140 \begin_inset Text
16141
16142 \layout Standard
16143
16144 depending on the model used (e.g.
16145  -mz80)
16146 \end_inset 
16147 </cell>
16148 </row>
16149 <row topline="true">
16150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16151 \begin_inset Text
16152
16153 \layout Standard
16154
16155 SDCC_STACK_AUTO
16156 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
16157
16158 \end_inset 
16159
16160
16161 \end_inset 
16162 </cell>
16163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16164 \begin_inset Text
16165
16166 \layout Standard
16167
16168 when 
16169 \emph on 
16170 -
16171 \begin_inset ERT
16172 status Collapsed
16173
16174 \layout Standard
16175
16176 \backslash 
16177 /
16178 \end_inset 
16179
16180 -stack-auto
16181 \emph default 
16182  option is used
16183 \end_inset 
16184 </cell>
16185 </row>
16186 <row topline="true">
16187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16188 \begin_inset Text
16189
16190 \layout Standard
16191
16192 SDCC_MODEL_SMALL
16193 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
16194
16195 \end_inset 
16196
16197
16198 \end_inset 
16199 </cell>
16200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16201 \begin_inset Text
16202
16203 \layout Standard
16204
16205 when 
16206 \emph on 
16207 -
16208 \begin_inset ERT
16209 status Collapsed
16210
16211 \layout Standard
16212
16213 \backslash 
16214 /
16215 \end_inset 
16216
16217 -model-small
16218 \emph default 
16219  is used
16220 \end_inset 
16221 </cell>
16222 </row>
16223 <row topline="true">
16224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16225 \begin_inset Text
16226
16227 \layout Standard
16228
16229 SDCC_MODEL_MEDIUM
16230 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
16231
16232 \end_inset 
16233
16234
16235 \end_inset 
16236 </cell>
16237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16238 \begin_inset Text
16239
16240 \layout Standard
16241
16242 when 
16243 \emph on 
16244 -
16245 \begin_inset ERT
16246 status Collapsed
16247
16248 \layout Standard
16249
16250 \backslash 
16251 /
16252 \end_inset 
16253
16254 -model-medium
16255 \emph default 
16256  is used
16257 \end_inset 
16258 </cell>
16259 </row>
16260 <row topline="true">
16261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16262 \begin_inset Text
16263
16264 \layout Standard
16265
16266 SDCC_MODEL_LARGE
16267 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
16268
16269 \end_inset 
16270
16271
16272 \end_inset 
16273 </cell>
16274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16275 \begin_inset Text
16276
16277 \layout Standard
16278
16279 when 
16280 \emph on 
16281 -
16282 \begin_inset ERT
16283 status Collapsed
16284
16285 \layout Standard
16286
16287 \backslash 
16288 /
16289 \end_inset 
16290
16291 -model-large
16292 \emph default 
16293  is used
16294 \end_inset 
16295 </cell>
16296 </row>
16297 <row topline="true">
16298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16299 \begin_inset Text
16300
16301 \layout Standard
16302
16303 SDCC_USE_XSTACK
16304 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
16305
16306 \end_inset 
16307
16308
16309 \end_inset 
16310 </cell>
16311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16312 \begin_inset Text
16313
16314 \layout Standard
16315
16316 when 
16317 \emph on 
16318 -
16319 \begin_inset ERT
16320 status Collapsed
16321
16322 \layout Standard
16323
16324 \backslash 
16325 /
16326 \end_inset 
16327
16328 -xstack
16329 \emph default 
16330  option is used
16331 \end_inset 
16332 </cell>
16333 </row>
16334 <row topline="true">
16335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16336 \begin_inset Text
16337
16338 \layout Standard
16339
16340 SDCC_STACK_TENBIT
16341 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
16342
16343 \end_inset 
16344
16345  
16346 \end_inset 
16347 </cell>
16348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16349 \begin_inset Text
16350
16351 \layout Standard
16352
16353 when 
16354 \emph on 
16355 -mds390
16356 \emph default 
16357  is used
16358 \end_inset 
16359 </cell>
16360 </row>
16361 <row topline="true" bottomline="true">
16362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16363 \begin_inset Text
16364
16365 \layout Standard
16366
16367 SDCC_MODEL_FLAT24
16368 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
16369
16370 \end_inset 
16371
16372
16373 \end_inset 
16374 </cell>
16375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16376 \begin_inset Text
16377
16378 \layout Standard
16379
16380 when 
16381 \emph on 
16382 -mds390
16383 \emph default 
16384  is used
16385 \end_inset 
16386 </cell>
16387 </row>
16388 </lyxtabular>
16389
16390 \end_inset 
16391
16392
16393 \layout Chapter
16394
16395 Notes on supported Processors
16396 \layout Section
16397
16398 MCS51 variants
16399 \begin_inset LatexCommand \label{sub:MCS51-variants}
16400
16401 \end_inset 
16402
16403
16404 \begin_inset LatexCommand \index{MCS51 variants}
16405
16406 \end_inset 
16407
16408
16409 \layout Standard
16410
16411 MCS51 processors are available from many vendors and come in many different
16412  flavours.
16413  While they might differ considerably in respect to Special Function Registers
16414  the core MCS51 is usually not modified or is kept compatible.
16415  
16416 \layout Subsection
16417
16418 pdata access by SFR 
16419 \layout Standard
16420
16421 With the upcome of devices with internal xdata and flash memory devices
16422  using port P2
16423 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16424
16425 \end_inset 
16426
16427  as dedicated I/O port is becoming more popular.
16428  Switching the high byte for pdata
16429 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16430
16431 \end_inset 
16432
16433  access which was formerly done by port P2 is then achieved by a Special
16434  Function Register
16435 \begin_inset LatexCommand \index{sfr}
16436
16437 \end_inset 
16438
16439 .
16440  In well-established MCS51 tradition the address of this 
16441 \emph on 
16442 sfr
16443 \emph default 
16444  is where the chip designers decided to put it.
16445  Needless to say that they didn't agree on a common name either.
16446  So that the startup code can correctly initialize xdata variables, you
16447  should define an sfr with the name _XPAGE
16448 \family typewriter 
16449
16450 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
16451
16452 \end_inset 
16453
16454
16455 \family default 
16456  at the appropriate location if the default, port P2, is not used for this.
16457  Some examples are:
16458 \layout Verse
16459
16460
16461 \family typewriter 
16462 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
16463 \layout Verse
16464
16465
16466 \family typewriter 
16467 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
16468 \layout Verse
16469
16470
16471 \family typewriter 
16472 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
16473 \layout Standard
16474
16475 For more exotic implementations further customizations may be needed.
16476  See section 
16477 \begin_inset LatexCommand \ref{sub:Startup-Code}
16478
16479 \end_inset 
16480
16481  for other possibilities.
16482 \layout Subsection
16483
16484 Other Features available by SFR
16485 \layout Standard
16486
16487 Some MCS51 variants offer features like Double DPTR
16488 \begin_inset LatexCommand \index{DPTR}
16489
16490 \end_inset 
16491
16492 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
16493  These are currently not used for the MCS51 port.
16494  If you absolutely need them you can fall back to inline assembly or submit
16495  a patch to SDCC.
16496 \layout Section
16497
16498 DS400 port
16499 \layout Standard
16500
16501 The DS80C400 microcontroller has a rich set of peripherals.
16502  In its built-in ROM library it includes functions to access some of the
16503  features, among them is a TCP stack with IP4 and IP6 support.
16504  Library headers (currently in beta status) and other files are provided
16505  at 
16506 \size footnotesize 
16507
16508 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
16509
16510 \end_inset 
16511
16512 .
16513  
16514 \layout Section
16515
16516 The Z80 and gbz80 port
16517 \layout Standard
16518
16519 SDCC can target both the Zilog 
16520 \begin_inset LatexCommand \index{Z80}
16521
16522 \end_inset 
16523
16524  and the Nintendo Gameboy's Z80-like gbz80
16525 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
16526
16527 \end_inset 
16528
16529 .
16530  The Z80 port is passed through the same 
16531 \emph on 
16532 regressions tests
16533 \begin_inset LatexCommand \index{Regression test}
16534
16535 \end_inset 
16536
16537
16538 \emph default 
16539  as the MCS51 and DS390 ports, so floating point support, support for long
16540  variables and bitfield support is fine.
16541  See mailing lists and forums about interrupt routines.
16542 \layout Standard
16543
16544 As always, the code is the authoritative reference - see z80/ralloc.c and
16545  z80/gen.c.
16546  The stack
16547 \begin_inset LatexCommand \index{stack}
16548
16549 \end_inset 
16550
16551  frame is similar to that generated by the IAR Z80 compiler.
16552  IX is used as the base pointer, HL and IY are used as a temporary registers,
16553  and BC and DE are available for holding variables.
16554  Return values
16555 \begin_inset LatexCommand \index{return value}
16556
16557 \end_inset 
16558
16559  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
16560  bytes).
16561  The gbz80 port use the same set of registers for the return values, but
16562  in a different order of significance: E (one byte), DE (two bytes), or
16563  HLDE (four bytes).
16564 \layout Section
16565
16566 The HC08 port
16567 \layout Standard
16568
16569 The port to the Motorola HC08
16570 \begin_inset LatexCommand \index{HC08}
16571
16572 \end_inset 
16573
16574  family has been added in October 2003, and is still undergoing some basic
16575  development.
16576  The code generator is complete, but the register allocation is still quite
16577  unoptimized.
16578  Some of the SDCC's standard C library functions have embedded non-HC08
16579  inline assembly and so are not yet usable.
16580 \newline 
16581
16582 \newline 
16583
16584 \layout Section
16585
16586 The PIC14 port
16587 \layout Standard
16588
16589 The 14bit PIC
16590 \begin_inset LatexCommand \index{PIC14}
16591
16592 \end_inset 
16593
16594  port still requires a major effort from the development community.
16595  However it can work for very simple code.
16596 \layout Subsection
16597
16598 C code and 14bit PIC code page
16599 \begin_inset LatexCommand \index{code page (pic14)}
16600
16601 \end_inset 
16602
16603  and RAM banks
16604 \begin_inset LatexCommand \index{RAM bank (pic14)}
16605
16606 \end_inset 
16607
16608
16609 \layout Standard
16610
16611 The linker organizes allocation for the code page and RAM banks.
16612  It does not have intimate knowledge of the code flow.
16613  It will put all the code section of a single asm file into a single code
16614  page.
16615  In order to make use of multiple code pages, separate asm files must be
16616  used.
16617  The compiler treats all functions of a single C file as being in the same
16618  code page unless it is non static.
16619  The compiler treats all local variables of a single C file as being in
16620  the same RAM bank unless it is an extern.
16621 \newline 
16622
16623 \newline 
16624 To get the best follow these guide lines:
16625 \layout Enumerate
16626
16627 make local functions static, as non static functions require code page selection
16628  overhead.
16629 \layout Enumerate
16630
16631 Make local variables static as extern variables require RAM bank selection
16632  overhead.
16633 \layout Enumerate
16634
16635 For devices that have multiple code pages it is more efficient to use the
16636  same number of files as pages, i.e.
16637  for the 16F877 use 4 separate files and i.e.
16638  for the 16F874 use 2 separate files.
16639  This way the linker can put the code for each file into different code
16640  pages and the compiler can allocate reusable variables more efficiently
16641  and there's less page selection overhead.
16642  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
16643  instruction set) use 'unsigned char' whereever possible instead of 'int'.
16644 \layout Subsection
16645
16646 Creating a device include file 
16647 \layout Standard
16648
16649 For generating a device include file use the support perl script inc2h.pl
16650  kept in directory support/script.
16651 \layout Subsection
16652
16653 Interrupt code
16654 \layout Standard
16655
16656 For the interrupt function, use the keyword 'interrupt'
16657 \begin_inset LatexCommand \index{interrupt}
16658
16659 \end_inset 
16660
16661  with level number of 0 (PIC14 only has 1 interrupt so this number is only
16662  there to avoid a syntax error - it ought to be fixed).
16663  E.g.:
16664 \layout Verse
16665
16666
16667 \family typewriter 
16668 void Intr(void) interrupt 0
16669 \newline 
16670 {
16671 \newline 
16672 \SpecialChar ~
16673 \SpecialChar ~
16674 T0IF = 0; /* Clear timer interrupt */
16675 \newline 
16676 }
16677 \layout Subsection
16678
16679 Linking and assembling
16680 \layout Standard
16681
16682 For assembling you can use either GPUTILS'
16683 \begin_inset LatexCommand \index{gputils (pic tools)}
16684
16685 \end_inset 
16686
16687  gpasm.exe or MPLAB's mpasmwin.exe.
16688  GPUTILS is available from 
16689 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
16690
16691 \end_inset 
16692
16693 .
16694  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
16695  If you use MPLAB and an interrupt function then the linker script file
16696  vectors section will need to be enlarged to link with mplink.
16697 \newline 
16698
16699 \newline 
16700 Here is a 
16701 \family typewriter 
16702 Makefile
16703 \family default 
16704  using GPUTILS:
16705 \layout Verse
16706
16707
16708 \family typewriter 
16709 .c.o:
16710 \newline 
16711 \SpecialChar ~
16712 \SpecialChar ~
16713 \SpecialChar ~
16714 \SpecialChar ~
16715 \SpecialChar ~
16716 \SpecialChar ~
16717 \SpecialChar ~
16718 \SpecialChar ~
16719 sdcc -S -V -mpic14 -p16F877 $< 
16720 \newline 
16721 \SpecialChar ~
16722 \SpecialChar ~
16723 \SpecialChar ~
16724 \SpecialChar ~
16725 \SpecialChar ~
16726 \SpecialChar ~
16727 \SpecialChar ~
16728 \SpecialChar ~
16729 gpasm -c $*.asm
16730 \newline 
16731
16732 \newline 
16733 $(PRJ).hex: $(OBJS) 
16734 \newline 
16735 \SpecialChar ~
16736 \SpecialChar ~
16737 \SpecialChar ~
16738 \SpecialChar ~
16739 \SpecialChar ~
16740 \SpecialChar ~
16741 \SpecialChar ~
16742 \SpecialChar ~
16743 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
16744 \layout Standard
16745
16746 Here is a 
16747 \family typewriter 
16748 Makefile
16749 \family default 
16750  using MPLAB:
16751 \layout Verse
16752
16753
16754 \family typewriter 
16755 .c.o: 
16756 \newline 
16757 \SpecialChar ~
16758 \SpecialChar ~
16759 \SpecialChar ~
16760 \SpecialChar ~
16761 \SpecialChar ~
16762 \SpecialChar ~
16763 \SpecialChar ~
16764 \SpecialChar ~
16765 sdcc -S -V -mpic14 -p16F877 $< 
16766 \newline 
16767 \SpecialChar ~
16768 \SpecialChar ~
16769 \SpecialChar ~
16770 \SpecialChar ~
16771 \SpecialChar ~
16772 \SpecialChar ~
16773 \SpecialChar ~
16774 \SpecialChar ~
16775 mpasmwin /q /o $*.asm
16776 \newline 
16777
16778 \newline 
16779 $(PRJ).hex: $(OBJS) 
16780 \newline 
16781 \SpecialChar ~
16782 \SpecialChar ~
16783 \SpecialChar ~
16784 \SpecialChar ~
16785 \SpecialChar ~
16786 \SpecialChar ~
16787 \SpecialChar ~
16788 \SpecialChar ~
16789 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
16790 \layout Standard
16791
16792 Please note that indentations within a
16793 \family typewriter 
16794  Makefile
16795 \family default 
16796  have to be done with a tabulator character.
16797 \layout Subsection
16798
16799 Command-line options
16800 \layout Standard
16801
16802 Besides the switches common to all SDCC backends, the PIC14 port accepts
16803  the following options (for an updated list see sdcc -
16804 \begin_inset ERT
16805 status Collapsed
16806
16807 \layout Standard
16808
16809 \backslash 
16810 /
16811 \end_inset 
16812
16813 -help):
16814 \layout List
16815 \labelwidthstring 00.00.0000
16816
16817 -
16818 \begin_inset ERT
16819 status Collapsed
16820
16821 \layout Standard
16822
16823 \backslash 
16824 /
16825 \end_inset 
16826
16827 -debug-extra emit debug info in assembly output
16828 \layout List
16829 \labelwidthstring 00.00.0000
16830
16831 -
16832 \begin_inset ERT
16833 status Collapsed
16834
16835 \layout Standard
16836
16837 \backslash 
16838 /
16839 \end_inset 
16840
16841 -no-pcode-opt disable (slightly faulty) optimization on pCode
16842 \layout Subsection
16843
16844 The library
16845 \layout Subsubsection
16846
16847 error: missing definition for symbol 
16848 \begin_inset Quotes sld
16849 \end_inset 
16850
16851 __gptrget1
16852 \begin_inset Quotes srd
16853 \end_inset 
16854
16855
16856 \layout Standard
16857
16858 The PIC14 port uses library routines to provide more complex operations
16859  like multiplication, division/modulus and (generic) pointer dereferencing.
16860  In order to add these routines to your project, you must link with PIC14's
16861  
16862 \family typewriter 
16863 libsdcc.lib
16864 \family default 
16865 .
16866  For single source file projects this is done automatically, more complex
16867  projects must add 
16868 \family typewriter 
16869 libsdcc.lib
16870 \family default 
16871  to the linker's arguments.
16872  Make sure you also add an include path for the library (using the -I switch
16873  to the linker)!
16874 \layout Subsubsection
16875
16876 Processor mismatch in file 
16877 \begin_inset Quotes sld
16878 \end_inset 
16879
16880 XXX
16881 \begin_inset Quotes srd
16882 \end_inset 
16883
16884 .
16885 \layout Standard
16886
16887 This warning can usually be ignored due to the very good compatibility amongst
16888  14 bit PIC devices.
16889 \layout Standard
16890
16891 You might also consider recompiling the library for your specific device
16892  by changing the ARCH=p16f877 (default target) entry in 
16893 \family typewriter 
16894 device/lib/pic/Makefile.in
16895 \family default 
16896  and 
16897 \family typewriter 
16898 device/lib/pic/Makefile
16899 \family default 
16900  to reflect your device.
16901  This might even improve performance for smaller devices as unneccesary
16902  BANKSELs migth be removed.
16903 \layout Subsection
16904
16905 Known bugs
16906 \layout Subsubsection
16907
16908 initialized data
16909 \layout Standard
16910
16911 Currently, data can only be initialized if it resides in the source file
16912  together with 
16913 \emph on 
16914 main()
16915 \emph default 
16916 .
16917  Data in other source files will silently 
16918 \series bold 
16919 not
16920 \series default 
16921  be initialized.
16922 \layout Section
16923
16924 The PIC16
16925 \begin_inset LatexCommand \index{PIC16}
16926
16927 \end_inset 
16928
16929  port
16930 \layout Standard
16931
16932 The PIC16
16933 \begin_inset LatexCommand \index{PIC16}
16934
16935 \end_inset 
16936
16937  port is the portion of SDCC that is responsible to produce code for the
16938  Microchip
16939 \begin_inset LatexCommand \index{Microchip}
16940
16941 \end_inset 
16942
16943 (TM) microcontrollers with 16 bit core.
16944  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
16945  Currently supported devices are:
16946 \layout Standard
16947 \align center 
16948
16949 \begin_inset  Tabular
16950 <lyxtabular version="3" rows="4" columns="6">
16951 <features>
16952 <column alignment="center" valignment="top" leftline="true" width="0">
16953 <column alignment="center" valignment="top" leftline="true" width="0">
16954 <column alignment="center" valignment="top" leftline="true" width="0">
16955 <column alignment="center" valignment="top" leftline="true" width="0">
16956 <column alignment="center" valignment="top" leftline="true" width="0">
16957 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16958 <row topline="true">
16959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16960 \begin_inset Text
16961
16962 \layout Standard
16963
16964 18F242
16965 \end_inset 
16966 </cell>
16967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16968 \begin_inset Text
16969
16970 \layout Standard
16971
16972 18F248
16973 \end_inset 
16974 </cell>
16975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16976 \begin_inset Text
16977
16978 \layout Standard
16979
16980 18F252
16981 \end_inset 
16982 </cell>
16983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16984 \begin_inset Text
16985
16986 \layout Standard
16987
16988 18F258
16989 \end_inset 
16990 </cell>
16991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16992 \begin_inset Text
16993
16994 \layout Standard
16995
16996 18F442
16997 \end_inset 
16998 </cell>
16999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17000 \begin_inset Text
17001
17002 \layout Standard
17003
17004 18F448
17005 \end_inset 
17006 </cell>
17007 </row>
17008 <row topline="true">
17009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17010 \begin_inset Text
17011
17012 \layout Standard
17013
17014 18F452
17015 \end_inset 
17016 </cell>
17017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17018 \begin_inset Text
17019
17020 \layout Standard
17021
17022 18F458
17023 \end_inset 
17024 </cell>
17025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17026 \begin_inset Text
17027
17028 \layout Standard
17029
17030 18F1220
17031 \end_inset 
17032 </cell>
17033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17034 \begin_inset Text
17035
17036 \layout Standard
17037
17038 18F2220
17039 \end_inset 
17040 </cell>
17041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17042 \begin_inset Text
17043
17044 \layout Standard
17045
17046 18F2550
17047 \end_inset 
17048 </cell>
17049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17050 \begin_inset Text
17051
17052 \layout Standard
17053
17054 18F4331
17055 \end_inset 
17056 </cell>
17057 </row>
17058 <row topline="true">
17059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17060 \begin_inset Text
17061
17062 \layout Standard
17063
17064 18F4455
17065 \end_inset 
17066 </cell>
17067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17068 \begin_inset Text
17069
17070 \layout Standard
17071
17072 18F6520
17073 \end_inset 
17074 </cell>
17075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17076 \begin_inset Text
17077
17078 \layout Standard
17079
17080 18F6620
17081 \end_inset 
17082 </cell>
17083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17084 \begin_inset Text
17085
17086 \layout Standard
17087
17088 18F6680
17089 \end_inset 
17090 </cell>
17091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17092 \begin_inset Text
17093
17094 \layout Standard
17095
17096 18F6720
17097 \end_inset 
17098 </cell>
17099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17100 \begin_inset Text
17101
17102 \layout Standard
17103
17104 18F8520
17105 \end_inset 
17106 </cell>
17107 </row>
17108 <row topline="true" bottomline="true">
17109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17110 \begin_inset Text
17111
17112 \layout Standard
17113
17114 18F8620
17115 \end_inset 
17116 </cell>
17117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17118 \begin_inset Text
17119
17120 \layout Standard
17121
17122 18F8680
17123 \end_inset 
17124 </cell>
17125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17126 \begin_inset Text
17127
17128 \layout Standard
17129
17130 18F8720
17131 \end_inset 
17132 </cell>
17133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17134 \begin_inset Text
17135
17136 \layout Standard
17137
17138 \end_inset 
17139 </cell>
17140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17141 \begin_inset Text
17142
17143 \layout Standard
17144
17145 \end_inset 
17146 </cell>
17147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17148 \begin_inset Text
17149
17150 \layout Standard
17151
17152 \end_inset 
17153 </cell>
17154 </row>
17155 </lyxtabular>
17156
17157 \end_inset 
17158
17159
17160 \layout Subsection
17161
17162 Global Options
17163 \layout Standard
17164
17165 PIC16 port supports the standard command line arguments as supposed, with
17166  the exception of certain cases that will be mentioned in the following
17167  list:
17168 \layout List
17169 \labelwidthstring 00.00.0000
17170
17171 -
17172 \begin_inset ERT
17173 status Collapsed
17174
17175 \layout Standard
17176
17177 \backslash 
17178 /
17179 \end_inset 
17180
17181 -callee-saves See -
17182 \begin_inset ERT
17183 status Collapsed
17184
17185 \layout Standard
17186
17187 \backslash 
17188 /
17189 \end_inset 
17190
17191 -all-callee-saves
17192 \layout List
17193 \labelwidthstring 00.00.0000
17194
17195 -
17196 \begin_inset ERT
17197 status Collapsed
17198
17199 \layout Standard
17200
17201 \backslash 
17202 /
17203 \end_inset 
17204
17205 -all-callee-saves All function arguments are passed on stack by default.
17206  
17207 \emph on 
17208 There is no need to specify this in the command line.
17209 \layout List
17210 \labelwidthstring 00.00.0000
17211
17212 -
17213 \begin_inset ERT
17214 status Collapsed
17215
17216 \layout Standard
17217
17218 \backslash 
17219 /
17220 \end_inset 
17221
17222 -fommit-frame-pointer Frame pointer will be omitted when the function uses
17223  no local variables.
17224 \layout Subsection
17225
17226 Port Specific Options
17227 \begin_inset LatexCommand \index{Options PIC16}
17228
17229 \end_inset 
17230
17231
17232 \layout Standard
17233
17234 The port specific options appear after the global options in the sdcc --help
17235  output.
17236 \layout Subsubsection
17237
17238 General Options
17239 \layout Standard
17240
17241 General options enable certain port features and optimizations.
17242 \layout List
17243 \labelwidthstring 00.00.0000
17244
17245 -
17246 \begin_inset ERT
17247 status Collapsed
17248
17249 \layout Standard
17250
17251 \backslash 
17252 /
17253 \end_inset 
17254
17255 -stack-model=[model] Used in conjuction with the command above.
17256  Defines the stack model to be used, valid stack models are : 
17257 \begin_deeper 
17258 \layout List
17259 \labelwidthstring 00.00.0000
17260
17261
17262 \emph on 
17263 small
17264 \emph default 
17265  Selects small stack model.
17266  8 bit stack and frame pointers.
17267  Supports 256 bytes stack size.
17268 \layout List
17269 \labelwidthstring 00.00.0000
17270
17271
17272 \emph on 
17273 large
17274 \emph default 
17275  Selects large stack model.
17276  16 bit stack and frame pointers.
17277  Supports 65536 bytes stack size.
17278 \end_deeper 
17279 \layout List
17280 \labelwidthstring 00.00.0000
17281
17282 -
17283 \begin_inset ERT
17284 status Collapsed
17285
17286 \layout Standard
17287
17288 \backslash 
17289 /
17290 \end_inset 
17291
17292 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
17293  unitialized data variables with [kword].
17294  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
17295 \layout List
17296 \labelwidthstring 00.00.0000
17297
17298 -
17299 \begin_inset ERT
17300 status Collapsed
17301
17302 \layout Standard
17303
17304 \backslash 
17305 /
17306 \end_inset 
17307
17308 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
17309  Useful for bootloaders.
17310 \layout List
17311 \labelwidthstring 00.00.0000
17312
17313 -
17314 \begin_inset ERT
17315 status Collapsed
17316
17317 \layout Standard
17318
17319 \backslash 
17320 /
17321 \end_inset 
17322
17323 -asm= sets the full path and name of an external assembler to call.
17324 \layout List
17325 \labelwidthstring 00.00.0000
17326
17327 -
17328 \begin_inset ERT
17329 status Collapsed
17330
17331 \layout Standard
17332
17333 \backslash 
17334 /
17335 \end_inset 
17336
17337 -link= sets the full path and name of an external linker to call.
17338 \layout List
17339 \labelwidthstring 00.00.0000
17340
17341 -
17342 \begin_inset ERT
17343 status Collapsed
17344
17345 \layout Standard
17346
17347 \backslash 
17348 /
17349 \end_inset 
17350
17351 -mplab-comp MPLAB compatibility option.
17352  Currently only suppresses special gpasm directives.
17353 \layout Subsubsection
17354
17355 Optimization Options
17356 \layout List
17357 \labelwidthstring 00.00.0000
17358
17359 -
17360 \begin_inset ERT
17361 status Collapsed
17362
17363 \layout Standard
17364
17365 \backslash 
17366 /
17367 \end_inset 
17368
17369 -optimize-goto Try to use (conditional) BRA instead of GOTO
17370 \layout List
17371 \labelwidthstring 00.00.0000
17372
17373 -
17374 \begin_inset ERT
17375 status Collapsed
17376
17377 \layout Standard
17378
17379 \backslash 
17380 /
17381 \end_inset 
17382
17383 -optimize-cmp Try to optimize some compares.
17384 \layout List
17385 \labelwidthstring 00.00.0000
17386
17387 -
17388 \begin_inset ERT
17389 status Collapsed
17390
17391 \layout Standard
17392
17393 \backslash 
17394 /
17395 \end_inset 
17396
17397 -optimize-df Analyze the dataflow of the generated code and improve it.
17398 \layout List
17399 \labelwidthstring 00.00.0000
17400
17401 -
17402 \begin_inset ERT
17403 status Collapsed
17404
17405 \layout Standard
17406
17407 \backslash 
17408 /
17409 \end_inset 
17410
17411 -obanksel=nn Set optimization level for inserting BANKSELs.
17412 \newline 
17413
17414 \begin_deeper 
17415 \layout List
17416 \labelwidthstring 00.00.0000
17417
17418 0 no optimization
17419 \layout List
17420 \labelwidthstring 00.00.0000
17421
17422 1 checks previous used register and if it is the same then does not emit
17423  BANKSEL, accounts only for labels.
17424 \layout List
17425 \labelwidthstring 00.00.0000
17426
17427 2 tries to check the location of (even different) symbols and removes BANKSELs
17428  if they are in the same bank.
17429  
17430 \newline 
17431
17432 \emph on 
17433 Important: There might be problems if the linker script has data sections
17434  across bank borders!
17435 \end_deeper 
17436 \layout Subsubsection
17437
17438 Linking Options
17439 \layout List
17440 \labelwidthstring 00.00.0000
17441
17442 -
17443 \begin_inset ERT
17444 status Collapsed
17445
17446 \layout Standard
17447
17448 \backslash 
17449 /
17450 \end_inset 
17451
17452 -nodefaultlibs do not link default libraries when linking
17453 \layout List
17454 \labelwidthstring 00.00.0000
17455
17456 -
17457 \begin_inset ERT
17458 status Collapsed
17459
17460 \layout Standard
17461
17462 \backslash 
17463 /
17464 \end_inset 
17465
17466 -no-crt Don't link the default run-time modules
17467 \layout List
17468 \labelwidthstring 00.00.0000
17469
17470 -
17471 \begin_inset ERT
17472 status Collapsed
17473
17474 \layout Standard
17475
17476 \backslash 
17477 /
17478 \end_inset 
17479
17480 -use-crt= Use a custom run-time module instead of the defaults.
17481 \layout Subsubsection
17482
17483 Debugging Options
17484 \layout Standard
17485
17486 Debugging options enable extra debugging information in the output files.
17487 \layout List
17488 \labelwidthstring 00.00.0000
17489
17490 -
17491 \begin_inset ERT
17492 status Collapsed
17493
17494 \layout Standard
17495
17496 \backslash 
17497 /
17498 \end_inset 
17499
17500 -debug-xtra Similar to -
17501 \begin_inset ERT
17502 status Collapsed
17503
17504 \layout Standard
17505
17506 \backslash 
17507 /
17508 \end_inset 
17509
17510 -debug
17511 \begin_inset LatexCommand \index{-\/-debug}
17512
17513 \end_inset 
17514
17515 , but dumps more information.
17516 \layout List
17517 \labelwidthstring 00.00.0000
17518
17519 -
17520 \begin_inset ERT
17521 status Collapsed
17522
17523 \layout Standard
17524
17525 \backslash 
17526 /
17527 \end_inset 
17528
17529 -debug-ralloc Force register allocator to dump <source>.d file with debugging
17530  information.
17531  <source> is the name of the file compiled.
17532 \layout List
17533 \labelwidthstring 00.00.0000
17534
17535 -
17536 \begin_inset ERT
17537 status Collapsed
17538
17539 \layout Standard
17540
17541 \backslash 
17542 /
17543 \end_inset 
17544
17545 -pcode-verbose Enable pcode debugging information in translation.
17546 \layout List
17547 \labelwidthstring 00.00.0000
17548
17549 -
17550 \begin_inset ERT
17551 status Collapsed
17552
17553 \layout Standard
17554
17555 \backslash 
17556 /
17557 \end_inset 
17558
17559 -denable-peeps Force the usage of peepholes.
17560  Use with care.
17561 \layout List
17562 \labelwidthstring 00.00.0000
17563
17564 -
17565 \begin_inset ERT
17566 status Collapsed
17567
17568 \layout Standard
17569
17570 \backslash 
17571 /
17572 \end_inset 
17573
17574 -gstack Trace push/pops for stack pointer overflow
17575 \layout List
17576 \labelwidthstring 00.00.0000
17577
17578 -
17579 \begin_inset ERT
17580 status Collapsed
17581
17582 \layout Standard
17583
17584 \backslash 
17585 /
17586 \end_inset 
17587
17588 -call-tree dump call tree in .calltree file
17589 \layout Subsection
17590
17591 Enviromental Variables
17592 \layout Standard
17593
17594 There is a number of enviromental variables that can be used when running
17595  SDCC to enable certain optimizations or force a specific program behaviour.
17596  these variables are primarily for debugging purposes so they can be enabled/dis
17597 abled at will.
17598 \layout Standard
17599
17600 Currently there is only two such variables available:
17601 \layout List
17602 \labelwidthstring 00.00.0000
17603
17604 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
17605  bitfields is optimized by directly loading FSR0 with the address of the
17606  bitfield structure.
17607  Normally SDCC will cast the bitfield structure to a bitfield pointer and
17608  then load FSR0.
17609  This step saves data ram and code space for functions that perform heavy
17610  use of bitfields.
17611  (ie.
17612  80 bytes of code space are saved when compiling malloc.c with this option).
17613  
17614 \layout List
17615 \labelwidthstring 00.00.0000
17616
17617 NO_REG_OPT do not perform pCode registers optimization.
17618  This should be used for debugging purposes.
17619  In some where bugs in the pcode optimizer are found, users can benefit
17620  from temporarily disabling the optimizer until the bug is fixed.
17621 \layout Subsection
17622
17623 Preprocessor Macros
17624 \layout Standard
17625
17626 PIC16 port defines the following preprocessor macros while translating a
17627  source.
17628 \layout Standard
17629 \align center 
17630
17631 \begin_inset  Tabular
17632 <lyxtabular version="3" rows="6" columns="2">
17633 <features>
17634 <column alignment="center" valignment="top" leftline="true" width="0">
17635 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17636 <row topline="true" bottomline="true">
17637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17638 \begin_inset Text
17639
17640 \layout Standard
17641
17642 Macro
17643 \end_inset 
17644 </cell>
17645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17646 \begin_inset Text
17647
17648 \layout Standard
17649
17650 Description
17651 \end_inset 
17652 </cell>
17653 </row>
17654 <row topline="true">
17655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17656 \begin_inset Text
17657
17658 \layout Standard
17659
17660 SDCC_pic16
17661 \end_inset 
17662 </cell>
17663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17664 \begin_inset Text
17665
17666 \layout Standard
17667
17668 Port identification
17669 \end_inset 
17670 </cell>
17671 </row>
17672 <row topline="true">
17673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17674 \begin_inset Text
17675
17676 \layout Standard
17677
17678 _
17679 \begin_inset ERT
17680 status Collapsed
17681
17682 \layout Standard
17683
17684 \backslash 
17685 /
17686 \end_inset 
17687
17688 _pic16
17689 \end_inset 
17690 </cell>
17691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17692 \begin_inset Text
17693
17694 \layout Standard
17695
17696 Port identification (same as above)
17697 \end_inset 
17698 </cell>
17699 </row>
17700 <row topline="true">
17701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17702 \begin_inset Text
17703
17704 \layout Standard
17705
17706 pic18fxxxx
17707 \end_inset 
17708 </cell>
17709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17710 \begin_inset Text
17711
17712 \layout Standard
17713
17714 MCU Identification.
17715  
17716 \emph on 
17717 xxxx
17718 \emph default 
17719  is the microcontrol identification number, i.e.
17720  452, 6620, etc
17721 \end_inset 
17722 </cell>
17723 </row>
17724 <row topline="true">
17725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17726 \begin_inset Text
17727
17728 \layout Standard
17729
17730 _
17731 \begin_inset ERT
17732 status Collapsed
17733
17734 \layout Standard
17735
17736 \backslash 
17737 /
17738 \end_inset 
17739
17740 _18Fxxxx
17741 \end_inset 
17742 </cell>
17743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17744 \begin_inset Text
17745
17746 \layout Standard
17747
17748 MCU Identification (same as above)
17749 \end_inset 
17750 </cell>
17751 </row>
17752 <row topline="true" bottomline="true">
17753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17754 \begin_inset Text
17755
17756 \layout Standard
17757
17758 STACK_MODEL_nnn
17759 \end_inset 
17760 </cell>
17761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17762 \begin_inset Text
17763
17764 \layout Standard
17765
17766 nnn = SMALL or LARGE respectively according to the stack model used
17767 \end_inset 
17768 </cell>
17769 </row>
17770 </lyxtabular>
17771
17772 \end_inset 
17773
17774
17775 \layout Standard
17776
17777 In addition the following macros are defined when calling assembler:
17778 \layout Standard
17779 \align center 
17780
17781 \begin_inset  Tabular
17782 <lyxtabular version="3" rows="4" columns="2">
17783 <features>
17784 <column alignment="center" valignment="top" leftline="true" width="0">
17785 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17786 <row topline="true" bottomline="true">
17787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17788 \begin_inset Text
17789
17790 \layout Standard
17791
17792 Macro
17793 \end_inset 
17794 </cell>
17795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17796 \begin_inset Text
17797
17798 \layout Standard
17799
17800 Description
17801 \end_inset 
17802 </cell>
17803 </row>
17804 <row topline="true">
17805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17806 \begin_inset Text
17807
17808 \layout Standard
17809
17810 __18Fxxxx
17811 \end_inset 
17812 </cell>
17813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17814 \begin_inset Text
17815
17816 \layout Standard
17817
17818 MCU Identification.
17819  
17820 \emph on 
17821 xxxx
17822 \emph default 
17823  is the microcontrol identification number, i.e.
17824  452, 6620, etc
17825 \end_inset 
17826 </cell>
17827 </row>
17828 <row topline="true">
17829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17830 \begin_inset Text
17831
17832 \layout Standard
17833
17834 SDCC_MODEL_nnn
17835 \end_inset 
17836 </cell>
17837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17838 \begin_inset Text
17839
17840 \layout Standard
17841
17842 nnn = SMALL or LARGE respectively according to the memory model used for
17843  SDCC
17844 \end_inset 
17845 </cell>
17846 </row>
17847 <row topline="true" bottomline="true">
17848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17849 \begin_inset Text
17850
17851 \layout Standard
17852
17853 STACK_MODEL_nnn
17854 \end_inset 
17855 </cell>
17856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17857 \begin_inset Text
17858
17859 \layout Standard
17860
17861 nnn = SMALL or LARGE respectively according to the stack model used
17862 \end_inset 
17863 </cell>
17864 </row>
17865 </lyxtabular>
17866
17867 \end_inset 
17868
17869
17870 \layout Subsection
17871
17872 Directories
17873 \layout Standard
17874
17875 PIC16
17876 \begin_inset LatexCommand \index{PIC16}
17877
17878 \end_inset 
17879
17880  port uses the following directories for searching header files and libraries.
17881 \layout Standard
17882 \align center 
17883
17884 \begin_inset  Tabular
17885 <lyxtabular version="3" rows="3" columns="4">
17886 <features>
17887 <column alignment="center" valignment="top" leftline="true" width="0">
17888 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17889 <column alignment="center" valignment="top" width="0">
17890 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17891 <row topline="true" bottomline="true">
17892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17893 \begin_inset Text
17894
17895 \layout Standard
17896
17897 Directory
17898 \end_inset 
17899 </cell>
17900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17901 \begin_inset Text
17902
17903 \layout Standard
17904
17905 Description
17906 \end_inset 
17907 </cell>
17908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17909 \begin_inset Text
17910
17911 \layout Standard
17912
17913 Target
17914 \end_inset 
17915 </cell>
17916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17917 \begin_inset Text
17918
17919 \layout Standard
17920
17921 Command prefix
17922 \end_inset 
17923 </cell>
17924 </row>
17925 <row topline="true">
17926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17927 \begin_inset Text
17928
17929 \layout Standard
17930
17931 PREFIX/sdcc/include/pic16
17932 \end_inset 
17933 </cell>
17934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17935 \begin_inset Text
17936
17937 \layout Standard
17938
17939 PIC16 specific headers
17940 \end_inset 
17941 </cell>
17942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17943 \begin_inset Text
17944
17945 \layout Standard
17946
17947 Compiler
17948 \end_inset 
17949 </cell>
17950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17951 \begin_inset Text
17952
17953 \layout Standard
17954
17955 -I
17956 \end_inset 
17957 </cell>
17958 </row>
17959 <row topline="true" bottomline="true">
17960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17961 \begin_inset Text
17962
17963 \layout Standard
17964
17965 PREFIX/sdcc/lib/pic16
17966 \end_inset 
17967 </cell>
17968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17969 \begin_inset Text
17970
17971 \layout Standard
17972
17973 PIC16 specific libraries
17974 \end_inset 
17975 </cell>
17976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17977 \begin_inset Text
17978
17979 \layout Standard
17980
17981 Linker
17982 \end_inset 
17983 </cell>
17984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17985 \begin_inset Text
17986
17987 \layout Standard
17988
17989 -L
17990 \end_inset 
17991 </cell>
17992 </row>
17993 </lyxtabular>
17994
17995 \end_inset 
17996
17997
17998 \layout Subsection
17999
18000 Pragmas
18001 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
18002
18003 \end_inset 
18004
18005
18006 \layout Standard
18007
18008 PIC16 port currently supports the following pragmas:
18009 \layout List
18010 \labelwidthstring 00.00.0000
18011
18012 stack pragma stack forces the code generator to initialize the stack & frame
18013  pointers at a specific address.
18014  This is an adhoc solution for cases where no STACK directive is available
18015  in the linker script or gplink is not instructed to create a stack section.
18016 \newline 
18017 The stack pragma should be used only once in a project.
18018  Multiple pragmas may result in indeterminate behaviour of the program.
18019 \begin_inset Foot
18020 collapsed false
18021
18022 \layout Standard
18023
18024 The old format (ie.
18025  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
18026  cross page boundaries (or even exceed the available data RAM) and crash
18027  the program.
18028  Make sure that stack does not cross page boundaries when using the SMALL
18029  stack model.
18030 \end_inset 
18031
18032
18033 \newline 
18034 The format is as follows:
18035 \layout LyX-Code
18036
18037 #pragma stack bottom_address [stack_size]
18038 \layout Standard
18039
18040
18041 \emph on 
18042 bottom_address
18043 \emph default 
18044  is the lower bound of the stack section.
18045  The stack pointer initially will point at address (bottom_address+stack_size-1).
18046 \layout LyX-Code
18047
18048 Example:
18049 \layout LyX-Code
18050
18051 \layout LyX-Code
18052
18053 /* initializes stack of 100 bytes at RAM address 0x200 */
18054 \layout LyX-Code
18055
18056 #pragma stack 0x200 100
18057 \layout Standard
18058
18059 If the stack_size field is omitted then a stack is created with the default
18060  size of 64.
18061  This size might be enough for most programs, but its not enough for operations
18062  with deep function nesting or excessive stack usage.
18063 \layout List
18064 \labelwidthstring 00.00.0000
18065
18066 wparam 
18067 \emph on 
18068 This pragma is deprecated.
18069  Its use will cause a warning message to be issued.
18070 \emph default 
18071
18072 \newline 
18073
18074 \layout List
18075 \labelwidthstring 00.00.0000
18076
18077 code place a function symbol at static FLASH address
18078 \layout LyX-Code
18079
18080 Example:
18081 \layout LyX-Code
18082
18083 \layout LyX-Code
18084
18085 /* place function test_func at 0x4000 */
18086 \layout LyX-Code
18087
18088 #pragma code test_func 0x4000
18089 \layout LyX-Code
18090
18091 \layout List
18092 \labelwidthstring 00.00.0000
18093
18094 library instructs the linker to use a library module.
18095 \newline 
18096 Usage:
18097 \layout LyX-Code
18098
18099 #pragma library module_name
18100 \layout Standard
18101
18102
18103 \emph on 
18104 module_name
18105 \emph default 
18106  can be any library or object file (including its path).
18107  Note that there are four reserved keywords which have special meaning.
18108  These are:
18109 \layout Standard
18110 \align center 
18111
18112 \begin_inset  Tabular
18113 <lyxtabular version="3" rows="6" columns="3">
18114 <features>
18115 <column alignment="center" valignment="top" leftline="true" width="0">
18116 <column alignment="block" valignment="top" leftline="true" width="20page%">
18117 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18118 <row topline="true" bottomline="true">
18119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18120 \begin_inset Text
18121
18122 \layout Standard
18123
18124 Keyword
18125 \end_inset 
18126 </cell>
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18128 \begin_inset Text
18129
18130 \layout Standard
18131
18132 Description
18133 \end_inset 
18134 </cell>
18135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18136 \begin_inset Text
18137
18138 \layout Standard
18139
18140 Module to link
18141 \end_inset 
18142 </cell>
18143 </row>
18144 <row topline="true">
18145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18146 \begin_inset Text
18147
18148 \layout Standard
18149
18150
18151 \series bold 
18152 ignore
18153 \end_inset 
18154 </cell>
18155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18156 \begin_inset Text
18157
18158 \layout Standard
18159
18160 ignore all library pragmas
18161 \end_inset 
18162 </cell>
18163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18164 \begin_inset Text
18165
18166 \layout Standard
18167
18168
18169 \emph on 
18170 (none)
18171 \end_inset 
18172 </cell>
18173 </row>
18174 <row topline="true">
18175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18176 \begin_inset Text
18177
18178 \layout Standard
18179
18180
18181 \series bold 
18182 c
18183 \end_inset 
18184 </cell>
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18186 \begin_inset Text
18187
18188 \layout Standard
18189
18190 link the C library
18191 \end_inset 
18192 </cell>
18193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18194 \begin_inset Text
18195
18196 \layout Standard
18197
18198
18199 \emph on 
18200 libc18f
18201 \emph default 
18202 .lib
18203 \end_inset 
18204 </cell>
18205 </row>
18206 <row topline="true">
18207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18208 \begin_inset Text
18209
18210 \layout Standard
18211
18212
18213 \series bold 
18214 math
18215 \end_inset 
18216 </cell>
18217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18218 \begin_inset Text
18219
18220 \layout Standard
18221
18222 link the Math libarary
18223 \end_inset 
18224 </cell>
18225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18226 \begin_inset Text
18227
18228 \layout Standard
18229
18230
18231 \emph on 
18232 libm18f
18233 \emph default 
18234 .lib
18235 \end_inset 
18236 </cell>
18237 </row>
18238 <row topline="true">
18239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18240 \begin_inset Text
18241
18242 \layout Standard
18243
18244
18245 \series bold 
18246 io
18247 \end_inset 
18248 </cell>
18249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18250 \begin_inset Text
18251
18252 \layout Standard
18253
18254 link the I/O library
18255 \end_inset 
18256 </cell>
18257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18258 \begin_inset Text
18259
18260 \layout Standard
18261
18262
18263 \emph on 
18264 libio18f*
18265 \emph default 
18266 .lib
18267 \end_inset 
18268 </cell>
18269 </row>
18270 <row topline="true" bottomline="true">
18271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18272 \begin_inset Text
18273
18274 \layout Standard
18275
18276
18277 \series bold 
18278 debug
18279 \end_inset 
18280 </cell>
18281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18282 \begin_inset Text
18283
18284 \layout Standard
18285
18286 link the debug library
18287 \end_inset 
18288 </cell>
18289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18290 \begin_inset Text
18291
18292 \layout Standard
18293
18294
18295 \emph on 
18296 libdebug
18297 \emph default 
18298 .lib
18299 \end_inset 
18300 </cell>
18301 </row>
18302 </lyxtabular>
18303
18304 \end_inset 
18305
18306
18307 \newline 
18308 * is the device number, i.e.
18309  452 for PIC18F452 MCU.
18310 \layout Standard
18311
18312 This feature allows for linking with specific libraries withoug having to
18313  explicit name them in the command line.
18314  Note that the 
18315 \noun on 
18316 ignore
18317 \noun default 
18318  keyword will reject all modules specified by the library pragma.
18319 \layout List
18320 \labelwidthstring 00.00.0000
18321
18322 udata pragma udata instructs the compiler to emit code so that linker will
18323  place a variable at a specific memory bank
18324 \layout LyX-Code
18325
18326 Example:
18327 \layout LyX-Code
18328
18329 \layout LyX-Code
18330
18331 /* places variable foo at bank2 */
18332 \layout LyX-Code
18333
18334 #pragma udata bank2 foo
18335 \layout LyX-Code
18336
18337 char foo;
18338 \layout Standard
18339
18340 In order for this pragma to work extra SECTION directives should be added
18341  in the .lkr script.
18342  In the following example a sample .lkr file is shown:
18343 \layout LyX-Code
18344
18345 \layout LyX-Code
18346
18347 // Sample linker script for the PIC18F452 processor
18348 \layout LyX-Code
18349
18350 LIBPATH .
18351 \layout LyX-Code
18352
18353 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
18354 \layout LyX-Code
18355
18356 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
18357 \layout LyX-Code
18358
18359 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
18360 \layout LyX-Code
18361
18362 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
18363 \layout LyX-Code
18364
18365 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
18366 \layout LyX-Code
18367
18368 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
18369 \layout LyX-Code
18370
18371 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
18372 \layout LyX-Code
18373
18374 \layout LyX-Code
18375
18376 DATABANK   NAME=gpr0       START=0x80           END=0xFF
18377 \layout LyX-Code
18378
18379 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
18380 \layout LyX-Code
18381
18382 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
18383 \layout LyX-Code
18384
18385 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
18386 \layout LyX-Code
18387
18388 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
18389 \layout LyX-Code
18390
18391 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
18392 \layout LyX-Code
18393
18394 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
18395 \layout LyX-Code
18396
18397 \layout LyX-Code
18398
18399 SECTION    NAME=CONFIG     ROM=config
18400 \layout LyX-Code
18401
18402 \layout LyX-Code
18403
18404 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
18405 \layout LyX-Code
18406
18407 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
18408 \layout LyX-Code
18409
18410 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
18411 \layout LyX-Code
18412
18413 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
18414 \layout LyX-Code
18415
18416 SECTION    NAME=bank4      RAM=gpr4
18417 \layout LyX-Code
18418
18419 SECTION    NAME=bank5      RAM=gpr5
18420 \layout Standard
18421
18422 The linker will recognise the section name set in the pragma statement and
18423  will position the variable at the memory bank set with the RAM field at
18424  the SECTION line in the linker script file.
18425 \layout Subsection
18426
18427 Header Files
18428 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
18429
18430 \end_inset 
18431
18432
18433 \layout Standard
18434
18435 There is one main header file that can be included to the source files using
18436  the pic16 port.
18437  That file is the 
18438 \series bold 
18439 pic18fregs.h
18440 \series default 
18441 .
18442  This header file contains the definitions for the processor special registers,
18443  so it is necessary if the source accesses them.
18444  It can be included by adding the following line in the beginning of the
18445  file:
18446 \layout LyX-Code
18447
18448 #include <pic18fregs.h>
18449 \layout Standard
18450
18451 The specific microcontroller is selected within the pic18fregs.h automatically,
18452  so the same source can be used with a variety of devices.
18453 \layout Subsection
18454
18455 Libraries
18456 \layout Standard
18457
18458 The libraries that PIC16
18459 \begin_inset LatexCommand \index{PIC16}
18460
18461 \end_inset 
18462
18463  port depends on are the microcontroller device libraries which contain
18464  the symbol definitions for the microcontroller special function registers.
18465  These libraries have the format pic18fxxxx.lib, where 
18466 \emph on 
18467 xxxx
18468 \emph default 
18469  is the microcontroller identification number.
18470  The specific library is selected automatically by the compiler at link
18471  stage according to the selected device.
18472 \layout Standard
18473
18474 Libraries are created with gplib which is part of the gputils package 
18475 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
18476
18477 \end_inset 
18478
18479 .
18480 \layout Subsubsection*
18481
18482 Building the libraries
18483 \layout Standard
18484
18485 Before using SDCC/pic16 there are some libraries that need to be compiled.
18486  This process is not done automatically by SDCC since not all users use
18487  SDCC for pic16 projects.
18488  So each user should compile the libraries separately.
18489 \layout Standard
18490
18491 The steps to compile the pic16 libraries under Linux are:
18492 \layout LyX-Code
18493
18494 cd device/lib/pic16
18495 \layout LyX-Code
18496
18497 ./configure
18498 \layout LyX-Code
18499
18500 make
18501 \layout LyX-Code
18502
18503 cd ..
18504 \layout LyX-Code
18505
18506 make model-pic16
18507 \layout LyX-Code
18508
18509 su -c 'make install'     # install the libraries, you need the root password
18510 \layout Standard
18511
18512 If you need to install the headers too, do:
18513 \layout LyX-Code
18514
18515 cd device/include
18516 \layout LyX-Code
18517
18518 su -c 'make install'     # install the headers, you need the root password
18519 \layout Standard
18520
18521 There exist a special target to build the I/O libraries.
18522  This target is not automatically build because it will build the I/O library
18523  for 
18524 \emph on 
18525 every
18526 \emph default 
18527  supported device.
18528  This way building will take quite a lot of time.
18529  Users are advised to edit the 
18530 \series bold 
18531 device/lib/pic16/pics.build
18532 \series default 
18533  file and then execute:
18534 \layout LyX-Code
18535
18536 make lib-io
18537 \layout Subsection
18538
18539 Memory Models
18540 \layout Standard
18541
18542 The following memory models are supported by the PIC16 port:
18543 \layout Itemize
18544
18545 small model
18546 \layout Itemize
18547
18548 large model
18549 \layout Standard
18550
18551 Memory model affects the default size of pointers within the source.
18552  The sizes are shown in the next table:
18553 \layout Standard
18554 \align center 
18555
18556 \begin_inset  Tabular
18557 <lyxtabular version="3" rows="3" columns="3">
18558 <features>
18559 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18560 <column alignment="center" valignment="top" leftline="true" width="0">
18561 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18562 <row topline="true" bottomline="true">
18563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18564 \begin_inset Text
18565
18566 \layout Standard
18567
18568 Pointer sizes according to memory model
18569 \end_inset 
18570 </cell>
18571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18572 \begin_inset Text
18573
18574 \layout Standard
18575
18576 small model
18577 \end_inset 
18578 </cell>
18579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18580 \begin_inset Text
18581
18582 \layout Standard
18583
18584 large model
18585 \end_inset 
18586 </cell>
18587 </row>
18588 <row topline="true" bottomline="true">
18589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18590 \begin_inset Text
18591
18592 \layout Standard
18593
18594 code pointers
18595 \end_inset 
18596 </cell>
18597 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18598 \begin_inset Text
18599
18600 \layout Standard
18601
18602 16-bits
18603 \end_inset 
18604 </cell>
18605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18606 \begin_inset Text
18607
18608 \layout Standard
18609
18610 24-bits
18611 \end_inset 
18612 </cell>
18613 </row>
18614 <row topline="true" bottomline="true">
18615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18616 \begin_inset Text
18617
18618 \layout Standard
18619
18620 data pointers
18621 \end_inset 
18622 </cell>
18623 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
18624 \begin_inset Text
18625
18626 \layout Standard
18627
18628 16-bits
18629 \end_inset 
18630 </cell>
18631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18632 \begin_inset Text
18633
18634 \layout Standard
18635
18636 16-bits
18637 \end_inset 
18638 </cell>
18639 </row>
18640 </lyxtabular>
18641
18642 \end_inset 
18643
18644
18645 \layout Standard
18646
18647 It is advisable that all sources within a project are compiled with the
18648  same memory model.
18649  If one wants to override the default memory model, this can be done by
18650  declaring a pointer as 
18651 \series bold 
18652 far
18653 \series default 
18654  or 
18655 \series bold 
18656 near
18657 \series default 
18658 .
18659  Far selects large memory model's pointers, while near selects small memory
18660  model's pointers.
18661 \layout Standard
18662
18663 The standard device libraries (see 
18664 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
18665
18666 \end_inset 
18667
18668 ) contain no reference to pointers, so they can be used with both memory
18669  models.
18670 \layout Subsection
18671
18672 Stack
18673 \layout Standard
18674
18675 The stack implementation for the PIC16 port uses two indirect registers,
18676  FSR1 and FSR2.
18677 \layout List
18678 \labelwidthstring 00.00.0000
18679
18680 FSR1 is assigned as stack pointer
18681 \layout List
18682 \labelwidthstring 00.00.0000
18683
18684 FSR2 is assigned as frame pointer
18685 \layout Standard
18686
18687 The following stack models are supported by the PIC16 port
18688 \layout Itemize
18689
18690
18691 \noun on 
18692 small
18693 \noun default 
18694  model
18695 \layout Itemize
18696
18697
18698 \noun on 
18699 large
18700 \noun default 
18701  model
18702 \layout Standard
18703
18704
18705 \noun on 
18706 Small
18707 \noun default 
18708  model means that only the FSRxL byte is used to access stack and frame,
18709  while 
18710 \emph on 
18711 \noun on 
18712 large
18713 \emph default 
18714 \noun default 
18715  uses both FSRxL and FSRxH registers.
18716  The following table shows the stack/frame pointers sizes according to stack
18717  model and the maximum space they can address:
18718 \layout Standard
18719 \align center 
18720
18721 \begin_inset  Tabular
18722 <lyxtabular version="3" rows="3" columns="3">
18723 <features>
18724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18725 <column alignment="center" valignment="top" leftline="true" width="0">
18726 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18727 <row topline="true" bottomline="true">
18728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18729 \begin_inset Text
18730
18731 \layout Standard
18732
18733 Stack & Frame pointer sizes according to stack model
18734 \end_inset 
18735 </cell>
18736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18737 \begin_inset Text
18738
18739 \layout Standard
18740
18741 small
18742 \end_inset 
18743 </cell>
18744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18745 \begin_inset Text
18746
18747 \layout Standard
18748
18749 large
18750 \end_inset 
18751 </cell>
18752 </row>
18753 <row topline="true">
18754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18755 \begin_inset Text
18756
18757 \layout Standard
18758
18759 Stack pointer FSR1
18760 \end_inset 
18761 </cell>
18762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18763 \begin_inset Text
18764
18765 \layout Standard
18766
18767 8-bits
18768 \end_inset 
18769 </cell>
18770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18771 \begin_inset Text
18772
18773 \layout Standard
18774
18775 16-bits
18776 \end_inset 
18777 </cell>
18778 </row>
18779 <row topline="true" bottomline="true">
18780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18781 \begin_inset Text
18782
18783 \layout Standard
18784
18785 Frame pointer FSR2
18786 \end_inset 
18787 </cell>
18788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18789 \begin_inset Text
18790
18791 \layout Standard
18792
18793 8-bits
18794 \end_inset 
18795 </cell>
18796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18797 \begin_inset Text
18798
18799 \layout Standard
18800
18801 16-bits
18802 \end_inset 
18803 </cell>
18804 </row>
18805 </lyxtabular>
18806
18807 \end_inset 
18808
18809
18810 \layout Standard
18811
18812
18813 \noun on 
18814 Large 
18815 \noun default 
18816 stack model is currently not working properly throughout the code generator.
18817  So its use is not advised.
18818  Also there are some other points that need special care:
18819 \newline 
18820
18821 \layout Enumerate
18822
18823 Do not create stack sections with size more than one physical bank (that
18824  is 256 bytes)
18825 \layout Enumerate
18826
18827 Stack sections should no cross physical bank limits (i.e.
18828  #pragma stack 0x50 0x100)
18829 \layout Standard
18830
18831 These limitations are caused by the fact that only FSRxL is modified when
18832  using SMALL stack model, so no more than 256 bytes of stack can be used.
18833  This problem will disappear after LARGE model is fully implemented.
18834 \layout Subsection
18835
18836 Functions
18837 \layout Standard
18838
18839 In addition to the standard SDCC function keywords, PIC16 port makes available
18840  two more:
18841 \layout List
18842 \labelwidthstring 00.00.0000
18843
18844 wparam Use the WREG to pass one byte of the first function argument.
18845  This improves speed but you may not use this for functions with arguments
18846  that are called via function pointers, otherwise the first byte of the
18847  first parameter will get lost.
18848  Usage:
18849 \layout LyX-Code
18850
18851 void func_wparam(int a) wparam
18852 \layout LyX-Code
18853
18854 {
18855 \layout LyX-Code
18856
18857     /* WREG hold the lower part of a */
18858 \layout LyX-Code
18859
18860     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
18861  */
18862 \layout LyX-Code
18863
18864 ...
18865 \layout LyX-Code
18866
18867 }
18868 \layout Standard
18869
18870 This keyword replaces the deprecated wparam pragma.
18871 \layout List
18872 \labelwidthstring 00.00.0000
18873
18874 shadowregs When entering/exiting an ISR, it is possible to take advantage
18875  of the PIC18F hardware shadow registers which hold the values of WREG,
18876  STATUS and BSR registers.
18877  This can be done by adding the keyword 
18878 \emph on 
18879 shadowregs
18880 \emph default 
18881  before the 
18882 \emph on 
18883 interrupt
18884 \emph default 
18885  keyword in the function's header.
18886 \layout LyX-Code
18887
18888 void isr_shadow(void) shadowregs interrupt 1
18889 \layout LyX-Code
18890
18891 {
18892 \layout LyX-Code
18893
18894 ...
18895 \layout LyX-Code
18896
18897 }
18898 \layout Standard
18899
18900
18901 \emph on 
18902 shadowregs
18903 \emph default 
18904  instructs the code generator not to store/restore WREG, STATUS, BSR when
18905  entering/exiting the ISR.
18906 \layout Subsection
18907
18908 Function return values
18909 \layout Standard
18910
18911 Return values from functions are placed to the appropriate registers following
18912  a modified Microchip policy optimized for SDCC.
18913  The following table shows these registers:
18914 \layout Standard
18915 \align center 
18916
18917 \begin_inset  Tabular
18918 <lyxtabular version="3" rows="6" columns="2">
18919 <features>
18920 <column alignment="center" valignment="top" leftline="true" width="0">
18921 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18922 <row topline="true" bottomline="true">
18923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18924 \begin_inset Text
18925
18926 \layout Standard
18927
18928 size
18929 \end_inset 
18930 </cell>
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18932 \begin_inset Text
18933
18934 \layout Standard
18935
18936 destination register
18937 \end_inset 
18938 </cell>
18939 </row>
18940 <row topline="true">
18941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18942 \begin_inset Text
18943
18944 \layout Standard
18945
18946 8 bits
18947 \end_inset 
18948 </cell>
18949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18950 \begin_inset Text
18951
18952 \layout Standard
18953
18954 WREG
18955 \end_inset 
18956 </cell>
18957 </row>
18958 <row topline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18960 \begin_inset Text
18961
18962 \layout Standard
18963
18964 16 bits
18965 \end_inset 
18966 </cell>
18967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18968 \begin_inset Text
18969
18970 \layout Standard
18971
18972 PRODL:WREG
18973 \end_inset 
18974 </cell>
18975 </row>
18976 <row topline="true">
18977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18978 \begin_inset Text
18979
18980 \layout Standard
18981
18982 24 bits
18983 \end_inset 
18984 </cell>
18985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18986 \begin_inset Text
18987
18988 \layout Standard
18989
18990 PRODH:PRODL:WREG
18991 \end_inset 
18992 </cell>
18993 </row>
18994 <row topline="true">
18995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18996 \begin_inset Text
18997
18998 \layout Standard
18999
19000 32 bits
19001 \end_inset 
19002 </cell>
19003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19004 \begin_inset Text
19005
19006 \layout Standard
19007
19008 FSR0L:PRODH:PRODL:WREG
19009 \end_inset 
19010 </cell>
19011 </row>
19012 <row topline="true" bottomline="true">
19013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19014 \begin_inset Text
19015
19016 \layout Standard
19017
19018 >32 bits
19019 \end_inset 
19020 </cell>
19021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19022 \begin_inset Text
19023
19024 \layout Standard
19025
19026 on stack, FSR0 points to the beginning
19027 \end_inset 
19028 </cell>
19029 </row>
19030 </lyxtabular>
19031
19032 \end_inset 
19033
19034
19035 \layout Subsection
19036
19037 Interrupts
19038 \layout Standard
19039
19040 An interrupt servive routine (ISR) is declared using the 
19041 \emph on 
19042 interrupt
19043 \emph default 
19044  keyword.
19045 \layout LyX-Code
19046
19047 void isr(void) interrupt 
19048 \emph on 
19049 n
19050 \layout LyX-Code
19051
19052 {
19053 \layout LyX-Code
19054
19055 ...
19056 \layout LyX-Code
19057
19058 }
19059 \layout Standard
19060
19061
19062 \emph on 
19063 n
19064 \emph default 
19065  is the interrupt number, which for PIC18F devices can be:
19066 \layout Standard
19067 \align center 
19068
19069 \begin_inset  Tabular
19070 <lyxtabular version="3" rows="4" columns="3">
19071 <features>
19072 <column alignment="center" valignment="top" leftline="true" width="0">
19073 <column alignment="center" valignment="top" leftline="true" width="0">
19074 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19075 <row topline="true" bottomline="true">
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19077 \begin_inset Text
19078
19079 \layout Standard
19080
19081
19082 \emph on 
19083 n
19084 \end_inset 
19085 </cell>
19086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19087 \begin_inset Text
19088
19089 \layout Standard
19090
19091 Interrupt Vector
19092 \end_inset 
19093 </cell>
19094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19095 \begin_inset Text
19096
19097 \layout Standard
19098
19099 Interrupt Vector Address
19100 \end_inset 
19101 </cell>
19102 </row>
19103 <row topline="true">
19104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19105 \begin_inset Text
19106
19107 \layout Standard
19108
19109 0
19110 \end_inset 
19111 </cell>
19112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19113 \begin_inset Text
19114
19115 \layout Standard
19116
19117 RESET vector
19118 \end_inset 
19119 </cell>
19120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19121 \begin_inset Text
19122
19123 \layout Standard
19124
19125 0x000000
19126 \end_inset 
19127 </cell>
19128 </row>
19129 <row topline="true">
19130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19131 \begin_inset Text
19132
19133 \layout Standard
19134
19135
19136 \family roman 
19137 \series medium 
19138 \shape up 
19139 \size normal 
19140 \emph off 
19141 \bar no 
19142 \noun off 
19143 \color none
19144 1
19145 \end_inset 
19146 </cell>
19147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19148 \begin_inset Text
19149
19150 \layout Standard
19151
19152
19153 \family roman 
19154 \series medium 
19155 \shape up 
19156 \size normal 
19157 \emph off 
19158 \bar no 
19159 \noun off 
19160 \color none
19161 HIGH priority interrupts
19162 \end_inset 
19163 </cell>
19164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19165 \begin_inset Text
19166
19167 \layout Standard
19168
19169 0x000008
19170 \end_inset 
19171 </cell>
19172 </row>
19173 <row topline="true" bottomline="true">
19174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19175 \begin_inset Text
19176
19177 \layout Standard
19178
19179 2
19180 \end_inset 
19181 </cell>
19182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19183 \begin_inset Text
19184
19185 \layout Standard
19186
19187 LOW priority interrupts
19188 \end_inset 
19189 </cell>
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19191 \begin_inset Text
19192
19193 \layout Standard
19194
19195 0x000018
19196 \end_inset 
19197 </cell>
19198 </row>
19199 </lyxtabular>
19200
19201 \end_inset 
19202
19203
19204 \layout Standard
19205
19206 When generating assembly code for ISR the code generator places a 
19207 \noun on 
19208 goto 
19209 \noun default 
19210 instruction at the 
19211 \emph on 
19212 Interrupt Vector Address
19213 \emph default 
19214  which points at the genetated ISR.
19215  This single GOTO instruction is part of an automatically generated 
19216 \emph on 
19217 interrupt entry point
19218 \emph default 
19219  function.
19220  The actuall ISR code is placed as normally would in the code space.
19221  Upon interrupt request, the GOTO instruction is executed which jumps to
19222  the ISR code.
19223  When declaring interrupt functions as _naked this GOTO instruction is 
19224 \series bold 
19225 not
19226 \series default 
19227  generated.
19228  The whole interrupt functions is therefore placed at the Interrupt Vector
19229  Address of the specific interrupt.
19230  This is not a problem for the LOW priority interrupts, but it is a problem
19231  for the RESET and the HIGH priority interrupts because code may be written
19232  at the next interrupt´s vector address and cause undeterminate program
19233  behaviour if that interrupt is raised.
19234 \begin_inset Foot
19235 collapsed false
19236
19237 \layout Standard
19238
19239 This is not a problem when
19240 \layout Enumerate
19241
19242 this is a HIGH interrupt ISR and LOW interrupts are 
19243 \emph on 
19244 disabled
19245 \emph default 
19246  or not used.
19247 \layout Enumerate
19248
19249 when the ISR is small enough not to reach the next interrupt´s vector address.
19250 \end_inset 
19251
19252
19253 \layout Standard
19254
19255
19256 \emph on 
19257 n
19258 \emph default 
19259  is possible to be omitted.
19260  This way a function is generated similar to an ISR, but it is not assigned
19261  to any interrupt.
19262 \layout Standard
19263
19264 When entering an interrupt, currently the PIC16
19265 \begin_inset LatexCommand \index{PIC16}
19266
19267 \end_inset 
19268
19269  port automatically saves the following registers:
19270 \layout Itemize
19271
19272 WREG
19273 \layout Itemize
19274
19275 STATUS
19276 \layout Itemize
19277
19278 BSR
19279 \layout Itemize
19280
19281 PROD (PRODL and PRODH)
19282 \layout Itemize
19283
19284 FSR0 (FSR0L and FSR0H)
19285 \layout Standard
19286
19287 These registers are restored upon return from the interrupt routine.
19288 \begin_inset Foot
19289 collapsed false
19290
19291 \layout Standard
19292
19293 NOTE that when the _naked attribute is specified for an interrupt routine,
19294  then NO registers are stored or restored.
19295 \end_inset 
19296
19297
19298 \layout Subsection
19299
19300 Generic Pointers
19301 \layout Standard
19302
19303 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
19304  There are 3 types of generic pointers currently implemented data, code
19305  and eeprom pointers.
19306  They are differentiated by the value of the 7th and 6th bits of the upper
19307  byte:
19308 \layout Standard
19309 \align center 
19310
19311 \begin_inset  Tabular
19312 <lyxtabular version="3" rows="5" columns="5">
19313 <features>
19314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19315 <column alignment="center" valignment="top" width="0">
19316 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19317 <column alignment="center" valignment="top" width="0">
19318 <column alignment="left" valignment="top" rightline="true" width="0">
19319 <row topline="true" bottomline="true">
19320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19321 \begin_inset Text
19322
19323 \layout Standard
19324
19325 pointer type
19326 \end_inset 
19327 </cell>
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \layout Standard
19332
19333 7th bit
19334 \end_inset 
19335 </cell>
19336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19337 \begin_inset Text
19338
19339 \layout Standard
19340
19341 6th bit
19342 \end_inset 
19343 </cell>
19344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19345 \begin_inset Text
19346
19347 \layout Standard
19348
19349 rest of the pointer
19350 \end_inset 
19351 </cell>
19352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19353 \begin_inset Text
19354
19355 \layout Standard
19356
19357 descrption
19358 \end_inset 
19359 </cell>
19360 </row>
19361 <row topline="true" bottomline="true">
19362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19363 \begin_inset Text
19364
19365 \layout Standard
19366
19367 data 
19368 \end_inset 
19369 </cell>
19370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19371 \begin_inset Text
19372
19373 \layout Standard
19374
19375 1
19376 \end_inset 
19377 </cell>
19378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19379 \begin_inset Text
19380
19381 \layout Standard
19382
19383 0
19384 \end_inset 
19385 </cell>
19386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19387 \begin_inset Text
19388
19389 \layout Standard
19390
19391
19392 \family typewriter 
19393 \shape slanted 
19394 \emph on 
19395 uuuuuu uuuuxxxx xxxxxxxx
19396 \end_inset 
19397 </cell>
19398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19399 \begin_inset Text
19400
19401 \layout Standard
19402
19403 a 12-bit data pointer in data RAM memory
19404 \end_inset 
19405 </cell>
19406 </row>
19407 <row bottomline="true">
19408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19409 \begin_inset Text
19410
19411 \layout Standard
19412
19413 code
19414 \end_inset 
19415 </cell>
19416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19417 \begin_inset Text
19418
19419 \layout Standard
19420
19421 0
19422 \end_inset 
19423 </cell>
19424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19425 \begin_inset Text
19426
19427 \layout Standard
19428
19429 0
19430 \end_inset 
19431 </cell>
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19433 \begin_inset Text
19434
19435 \layout Standard
19436
19437
19438 \family typewriter 
19439 \shape slanted 
19440 \emph on 
19441 uxxxxx xxxxxxxx xxxxxxxx
19442 \end_inset 
19443 </cell>
19444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19445 \begin_inset Text
19446
19447 \layout Standard
19448
19449 a 21-bit code pointer in FLASH memory
19450 \end_inset 
19451 </cell>
19452 </row>
19453 <row bottomline="true">
19454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19455 \begin_inset Text
19456
19457 \layout Standard
19458
19459 eeprom
19460 \end_inset 
19461 </cell>
19462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19463 \begin_inset Text
19464
19465 \layout Standard
19466
19467 0
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 \layout Standard
19474
19475 1
19476 \end_inset 
19477 </cell>
19478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19479 \begin_inset Text
19480
19481 \layout Standard
19482
19483
19484 \family typewriter 
19485 \shape slanted 
19486 \emph on 
19487 uuuuuu uuuuuuxx xxxxxxxx
19488 \end_inset 
19489 </cell>
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19491 \begin_inset Text
19492
19493 \layout Standard
19494
19495 a 10-bit eeprom pointer in EEPROM memory
19496 \end_inset 
19497 </cell>
19498 </row>
19499 <row bottomline="true">
19500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19501 \begin_inset Text
19502
19503 \layout Standard
19504
19505 (unimplemented)
19506 \end_inset 
19507 </cell>
19508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19509 \begin_inset Text
19510
19511 \layout Standard
19512
19513 1
19514 \end_inset 
19515 </cell>
19516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19517 \begin_inset Text
19518
19519 \layout Standard
19520
19521 1
19522 \end_inset 
19523 </cell>
19524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19525 \begin_inset Text
19526
19527 \layout Standard
19528
19529
19530 \family typewriter 
19531 \shape slanted 
19532 \emph on 
19533 xxxxxx xxxxxxxx xxxxxxxx
19534 \end_inset 
19535 </cell>
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_inset Text
19538
19539 \layout Standard
19540
19541 unimplemented pointer type
19542 \end_inset 
19543 </cell>
19544 </row>
19545 </lyxtabular>
19546
19547 \end_inset 
19548
19549
19550 \layout Standard
19551
19552 Generic pointer are read and written with a set of library functions which
19553  read/write 1, 2, 3, 4 bytes.
19554 \layout Subsection
19555
19556 PIC16 C Libraries
19557 \layout Subsubsection
19558
19559 Standard I/O Streams
19560 \layout Standard
19561
19562 In the 
19563 \emph on 
19564 stdio.h
19565 \emph default 
19566  the type FILE is defined as:
19567 \layout LyX-Code
19568
19569 typedef char * FILE;
19570 \layout Standard
19571
19572 This type is the stream type implemented I/O in the PIC18F devices.
19573  Also the standard input and output streams are declared in stdio.h:
19574 \layout LyX-Code
19575
19576 extern FILE * stdin;
19577 \layout LyX-Code
19578
19579 extern FILE * stdout;
19580 \layout Standard
19581
19582 The FILE type is actually a generic pointer which defines one more type
19583  of generic pointers, the 
19584 \emph on 
19585 stream 
19586 \emph default 
19587 pointer.
19588  This new type has the format:
19589 \layout Standard
19590 \align center 
19591
19592 \begin_inset  Tabular
19593 <lyxtabular version="3" rows="2" columns="7">
19594 <features>
19595 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19596 <column alignment="center" valignment="top" width="0">
19597 <column alignment="center" valignment="top" leftline="true" width="0">
19598 <column alignment="center" valignment="top" leftline="true" width="0">
19599 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19600 <column alignment="center" valignment="top" width="0">
19601 <column alignment="left" valignment="top" rightline="true" width="0">
19602 <row topline="true" bottomline="true">
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19604 \begin_inset Text
19605
19606 \layout Standard
19607
19608 pointer type
19609 \end_inset 
19610 </cell>
19611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19612 \begin_inset Text
19613
19614 \layout Standard
19615
19616 <7:6>
19617 \end_inset 
19618 </cell>
19619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19620 \begin_inset Text
19621
19622 \layout Standard
19623
19624 <5>
19625 \end_inset 
19626 </cell>
19627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19628 \begin_inset Text
19629
19630 \layout Standard
19631
19632 <4>
19633 \end_inset 
19634 </cell>
19635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19636 \begin_inset Text
19637
19638 \layout Standard
19639
19640 <3:0>
19641 \end_inset 
19642 </cell>
19643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19644 \begin_inset Text
19645
19646 \layout Standard
19647
19648 rest of the pointer
19649 \end_inset 
19650 </cell>
19651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19652 \begin_inset Text
19653
19654 \layout Standard
19655
19656 descrption
19657 \end_inset 
19658 </cell>
19659 </row>
19660 <row topline="true" bottomline="true">
19661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19662 \begin_inset Text
19663
19664 \layout Standard
19665
19666 stream
19667 \end_inset 
19668 </cell>
19669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19670 \begin_inset Text
19671
19672 \layout Standard
19673
19674 00
19675 \end_inset 
19676 </cell>
19677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19678 \begin_inset Text
19679
19680 \layout Standard
19681
19682 1
19683 \end_inset 
19684 </cell>
19685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19686 \begin_inset Text
19687
19688 \layout Standard
19689
19690 0
19691 \end_inset 
19692 </cell>
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19694 \begin_inset Text
19695
19696 \layout Standard
19697
19698 nnnn
19699 \end_inset 
19700 </cell>
19701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19702 \begin_inset Text
19703
19704 \layout Standard
19705
19706
19707 \family typewriter 
19708 \shape slanted 
19709 \emph on 
19710 uuuuuuuu uuuuuuuu
19711 \end_inset 
19712 </cell>
19713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19714 \begin_inset Text
19715
19716 \layout Standard
19717
19718 upper byte high nubble is 0x2n, the rest are zeroes
19719 \end_inset 
19720 </cell>
19721 </row>
19722 </lyxtabular>
19723
19724 \end_inset 
19725
19726
19727 \layout Standard
19728
19729 Currently implemented there are 3 types of streams defined:
19730 \layout Standard
19731 \align center 
19732
19733 \begin_inset  Tabular
19734 <lyxtabular version="3" rows="4" columns="4">
19735 <features>
19736 <column alignment="center" valignment="top" leftline="true" width="0">
19737 <column alignment="center" valignment="top" leftline="true" width="0">
19738 <column alignment="center" valignment="top" leftline="true" width="0">
19739 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19740 <row topline="true" bottomline="true">
19741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19742 \begin_inset Text
19743
19744 \layout Standard
19745
19746 stream type
19747 \end_inset 
19748 </cell>
19749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19750 \begin_inset Text
19751
19752 \layout Standard
19753
19754 value
19755 \end_inset 
19756 </cell>
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19758 \begin_inset Text
19759
19760 \layout Standard
19761
19762 module
19763 \end_inset 
19764 </cell>
19765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19766 \begin_inset Text
19767
19768 \layout Standard
19769
19770 description
19771 \end_inset 
19772 </cell>
19773 </row>
19774 <row topline="true">
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19776 \begin_inset Text
19777
19778 \layout Standard
19779
19780 STREAM_USART
19781 \end_inset 
19782 </cell>
19783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19784 \begin_inset Text
19785
19786 \layout Standard
19787
19788
19789 \family typewriter 
19790 0x200000UL
19791 \end_inset 
19792 </cell>
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19794 \begin_inset Text
19795
19796 \layout Standard
19797
19798 USART
19799 \end_inset 
19800 </cell>
19801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19802 \begin_inset Text
19803
19804 \layout Standard
19805
19806 Writes/Reads characters via the USART peripheral
19807 \end_inset 
19808 </cell>
19809 </row>
19810 <row topline="true">
19811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19812 \begin_inset Text
19813
19814 \layout Standard
19815
19816 STREAM_MSSP
19817 \end_inset 
19818 </cell>
19819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19820 \begin_inset Text
19821
19822 \layout Standard
19823
19824
19825 \family typewriter 
19826 0x210000UL
19827 \end_inset 
19828 </cell>
19829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19830 \begin_inset Text
19831
19832 \layout Standard
19833
19834 MSSP
19835 \end_inset 
19836 </cell>
19837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19838 \begin_inset Text
19839
19840 \layout Standard
19841
19842 Writes/Reads characters via the MSSP peripheral
19843 \end_inset 
19844 </cell>
19845 </row>
19846 <row topline="true" bottomline="true">
19847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19848 \begin_inset Text
19849
19850 \layout Standard
19851
19852 STREAM_USER
19853 \end_inset 
19854 </cell>
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19856 \begin_inset Text
19857
19858 \layout Standard
19859
19860
19861 \family typewriter 
19862 0x2f0000UL
19863 \end_inset 
19864 </cell>
19865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19866 \begin_inset Text
19867
19868 \layout Standard
19869
19870 (none)
19871 \end_inset 
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \layout Standard
19877
19878 Writes/Reads characters via used defined functions
19879 \end_inset 
19880 </cell>
19881 </row>
19882 </lyxtabular>
19883
19884 \end_inset 
19885
19886
19887 \layout Standard
19888
19889 The stream identifiers are declared as macros in the stdio.h header.
19890 \layout Standard
19891
19892 In the libc library there exist the functions that are used to write to
19893  each of the above streams.
19894  These are
19895 \layout List
19896 \labelwidthstring 00.00.0000
19897
19898 _
19899 \begin_inset ERT
19900 status Collapsed
19901
19902 \layout Standard
19903
19904 \backslash 
19905 /
19906 \end_inset 
19907
19908 _stream_usart_putchar writes a character at the USART stream
19909 \layout List
19910 \labelwidthstring 00.00.0000
19911
19912 _
19913 \begin_inset ERT
19914 status Collapsed
19915
19916 \layout Standard
19917
19918 \backslash 
19919 /
19920 \end_inset 
19921
19922 _stream_mssp_putchar writes a character at the MSSP stream
19923 \layout List
19924 \labelwidthstring 00.00.0000
19925
19926 putchar dummy function.
19927  This writes a character to a user specified manner.
19928 \layout Standard
19929
19930 In order to increase performance 
19931 \emph on 
19932 putchar 
19933 \emph default 
19934 is declared in stdio.h as having its parameter in WREG (it has the wparam
19935  keyword).
19936  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
19937  in a user-friendly way.
19938  
19939 \emph on 
19940 arg
19941 \emph default 
19942  is the name of the variable that holds the character to print.
19943  An example follows:
19944 \layout LyX-Code
19945
19946 #include <pic18fregs.h>
19947 \newline 
19948 #include <stdio.h>
19949 \newline 
19950
19951 \newline 
19952 PUTCHAR( c )
19953 \layout LyX-Code
19954
19955 {
19956 \layout LyX-Code
19957
19958     PORTA = c;    /* dump character c to PORTA */
19959 \layout LyX-Code
19960
19961
19962 \newline 
19963
19964 \newline 
19965 void main(void)
19966 \layout LyX-Code
19967
19968 {
19969 \layout LyX-Code
19970
19971     stdout = STREAM_USER;    /* this is not necessery, since stdout points
19972 \layout LyX-Code
19973
19974                               * by default to STREAM_USER */
19975 \layout LyX-Code
19976
19977     printf (¨This is a printf test
19978 \backslash 
19979 n¨);
19980 \layout LyX-Code
19981
19982 }
19983 \layout LyX-Code
19984
19985 \layout Subsubsection
19986
19987 Printing functions
19988 \layout Standard
19989
19990 PIC16 contains an implementation of the printf-family of functions.
19991  There exist the following functions:
19992 \layout LyX-Code
19993
19994 extern unsigned int sprintf(char *buf, char *fmt, ...);
19995 \layout LyX-Code
19996
19997 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
19998 \layout LyX-Code
19999
20000 \layout LyX-Code
20001
20002 extern unsigned int printf(char *fmt, ...);
20003 \layout LyX-Code
20004
20005 extern unsigned int vprintf(char *fmt, va_lista ap);
20006 \layout LyX-Code
20007
20008 \layout LyX-Code
20009
20010 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
20011 \layout LyX-Code
20012
20013 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
20014 \layout Standard
20015
20016 For sprintf and vsprintf 
20017 \emph on 
20018 buf 
20019 \emph default 
20020 should normally be a data pointer where the resulting string will be placed.
20021  No range checking is done so the user should allocate the necessery buffer.
20022  For fprintf and vfprintf 
20023 \emph on 
20024 fp
20025 \emph default 
20026  should be a stream pointer (i.e.
20027  stdout, STREAM_MSSP, etc...).
20028 \layout Subsubsection
20029
20030 Signals
20031 \layout Standard
20032
20033 The PIC18F family of microcontrollers supports a number of interrupt sources.
20034  A list of these interrupts is shown in the following table:
20035 \layout Standard
20036 \align center 
20037
20038 \begin_inset  Tabular
20039 <lyxtabular version="3" rows="11" columns="4">
20040 <features>
20041 <column alignment="left" valignment="top" leftline="true" width="0">
20042 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20043 <column alignment="left" valignment="top" leftline="true" width="0">
20044 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20045 <row topline="true" bottomline="true">
20046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20047 \begin_inset Text
20048
20049 \layout Standard
20050
20051 signal name
20052 \end_inset 
20053 </cell>
20054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20055 \begin_inset Text
20056
20057 \layout Standard
20058
20059 description
20060 \end_inset 
20061 </cell>
20062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20063 \begin_inset Text
20064
20065 \layout Standard
20066
20067 signal name
20068 \end_inset 
20069 </cell>
20070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20071 \begin_inset Text
20072
20073 \layout Standard
20074
20075 descritpion
20076 \end_inset 
20077 </cell>
20078 </row>
20079 <row topline="true">
20080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20081 \begin_inset Text
20082
20083 \layout Standard
20084
20085 SIG_RB
20086 \end_inset 
20087 </cell>
20088 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20089 \begin_inset Text
20090
20091 \layout Standard
20092
20093 PORTB change interrupt
20094 \end_inset 
20095 </cell>
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20097 \begin_inset Text
20098
20099 \layout Standard
20100
20101 SIG_EE
20102 \end_inset 
20103 </cell>
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20105 \begin_inset Text
20106
20107 \layout Standard
20108
20109 EEPROM/FLASH write complete interrupt
20110 \end_inset 
20111 </cell>
20112 </row>
20113 <row topline="true">
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20115 \begin_inset Text
20116
20117 \layout Standard
20118
20119 SIG_INT0
20120 \end_inset 
20121 </cell>
20122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20123 \begin_inset Text
20124
20125 \layout Standard
20126
20127 INT0 external interrupt
20128 \end_inset 
20129 </cell>
20130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20131 \begin_inset Text
20132
20133 \layout Standard
20134
20135 SIG_BCOL
20136 \end_inset 
20137 </cell>
20138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20139 \begin_inset Text
20140
20141 \layout Standard
20142
20143 Bus collision interrupt
20144 \end_inset 
20145 </cell>
20146 </row>
20147 <row topline="true">
20148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20149 \begin_inset Text
20150
20151 \layout Standard
20152
20153 SIG_INT1
20154 \end_inset 
20155 </cell>
20156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20157 \begin_inset Text
20158
20159 \layout Standard
20160
20161 INT1 external interrupt
20162 \end_inset 
20163 </cell>
20164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20165 \begin_inset Text
20166
20167 \layout Standard
20168
20169 SIG_LVD
20170 \end_inset 
20171 </cell>
20172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20173 \begin_inset Text
20174
20175 \layout Standard
20176
20177 Low voltage detect interrupt
20178 \end_inset 
20179 </cell>
20180 </row>
20181 <row topline="true">
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20183 \begin_inset Text
20184
20185 \layout Standard
20186
20187 SIG_INT2
20188 \end_inset 
20189 </cell>
20190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20191 \begin_inset Text
20192
20193 \layout Standard
20194
20195 INT2 external interrupt
20196 \end_inset 
20197 </cell>
20198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20199 \begin_inset Text
20200
20201 \layout Standard
20202
20203 SIG_PSP
20204 \end_inset 
20205 </cell>
20206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20207 \begin_inset Text
20208
20209 \layout Standard
20210
20211 Parallel slave port interrupt
20212 \end_inset 
20213 </cell>
20214 </row>
20215 <row topline="true">
20216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20217 \begin_inset Text
20218
20219 \layout Standard
20220
20221 SIG_CCP1
20222 \end_inset 
20223 </cell>
20224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20225 \begin_inset Text
20226
20227 \layout Standard
20228
20229 CCP1 module interrupt
20230 \end_inset 
20231 </cell>
20232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20233 \begin_inset Text
20234
20235 \layout Standard
20236
20237 SIG_AD
20238 \end_inset 
20239 </cell>
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20241 \begin_inset Text
20242
20243 \layout Standard
20244
20245 AD convertion complete interrupt
20246 \end_inset 
20247 </cell>
20248 </row>
20249 <row topline="true">
20250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20251 \begin_inset Text
20252
20253 \layout Standard
20254
20255 SIG_CCP2
20256 \end_inset 
20257 </cell>
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20259 \begin_inset Text
20260
20261 \layout Standard
20262
20263 CCP2 module interrupt
20264 \end_inset 
20265 </cell>
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20267 \begin_inset Text
20268
20269 \layout Standard
20270
20271 SIG_RC
20272 \end_inset 
20273 </cell>
20274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20275 \begin_inset Text
20276
20277 \layout Standard
20278
20279 USART receive interrupt
20280 \end_inset 
20281 </cell>
20282 </row>
20283 <row topline="true">
20284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20285 \begin_inset Text
20286
20287 \layout Standard
20288
20289 SIG_TMR0
20290 \end_inset 
20291 </cell>
20292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20293 \begin_inset Text
20294
20295 \layout Standard
20296
20297 TMR0 overflow interrupt
20298 \end_inset 
20299 </cell>
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \layout Standard
20304
20305 SIG_TX
20306 \end_inset 
20307 </cell>
20308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20309 \begin_inset Text
20310
20311 \layout Standard
20312
20313 USART transmit interrupt
20314 \end_inset 
20315 </cell>
20316 </row>
20317 <row topline="true">
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \layout Standard
20322
20323 SIG_TMR1
20324 \end_inset 
20325 </cell>
20326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20327 \begin_inset Text
20328
20329 \layout Standard
20330
20331 TMR1 overflow interrupt
20332 \end_inset 
20333 </cell>
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20335 \begin_inset Text
20336
20337 \layout Standard
20338
20339 SIG_MSSP
20340 \end_inset 
20341 </cell>
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20343 \begin_inset Text
20344
20345 \layout Standard
20346
20347 SSP receive/transmit interrupt
20348 \end_inset 
20349 </cell>
20350 </row>
20351 <row topline="true">
20352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20353 \begin_inset Text
20354
20355 \layout Standard
20356
20357 SIG_TMR2
20358 \end_inset 
20359 </cell>
20360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20361 \begin_inset Text
20362
20363 \layout Standard
20364
20365 TMR2 matches PR2 interrupt
20366 \end_inset 
20367 </cell>
20368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20369 \begin_inset Text
20370
20371 \layout Standard
20372
20373 \end_inset 
20374 </cell>
20375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20376 \begin_inset Text
20377
20378 \layout Standard
20379
20380 \end_inset 
20381 </cell>
20382 </row>
20383 <row topline="true" bottomline="true">
20384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20385 \begin_inset Text
20386
20387 \layout Standard
20388
20389 SIG_TMR3
20390 \end_inset 
20391 </cell>
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20393 \begin_inset Text
20394
20395 \layout Standard
20396
20397 TMR3 overflow interrupt
20398 \end_inset 
20399 </cell>
20400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20401 \begin_inset Text
20402
20403 \layout Standard
20404
20405 \end_inset 
20406 </cell>
20407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20408 \begin_inset Text
20409
20410 \layout Standard
20411
20412 \end_inset 
20413 </cell>
20414 </row>
20415 </lyxtabular>
20416
20417 \end_inset 
20418
20419
20420 \layout Standard
20421
20422 The prototypes for these names are defined in the header file 
20423 \emph on 
20424 signal.h
20425 \emph default 
20426  .
20427 \layout Standard
20428
20429 In order to simplify signal handling, a number of macros is provided:
20430 \layout List
20431 \labelwidthstring 00.00.0000
20432
20433 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
20434  high priority interrupts.
20435  
20436 \emph on 
20437 name
20438 \emph default 
20439  is the function name to use.
20440 \layout List
20441 \labelwidthstring 00.00.0000
20442
20443 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
20444  low priority interrupt.
20445  
20446 \emph on 
20447 name
20448 \emph default 
20449  is the function name to use.
20450 \layout List
20451 \labelwidthstring 00.00.0000
20452
20453 DEF_HANDLER(sig,handler) define a handler for signal 
20454 \emph on 
20455 sig.
20456 \layout List
20457 \labelwidthstring 00.00.0000
20458
20459 END_DEF end the declaration of the dispatch table.
20460 \layout Standard
20461
20462 Additionally there are two more macros to simplify the declaration of the
20463  signal handler:
20464 \layout List
20465 \labelwidthstring 00.00.0000
20466
20467
20468 \series medium 
20469 SIGHANDLER(handler) 
20470 \series default 
20471 this declares the function prototype for the 
20472 \emph on 
20473 handler
20474 \emph default 
20475  function.
20476 \layout List
20477 \labelwidthstring 00.00.0000
20478
20479 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
20480 \layout Standard
20481
20482 An example of using the macros above is shown below:
20483 \layout LyX-Code
20484
20485 #include <pic18fregs.h>
20486 \layout LyX-Code
20487
20488 #include <signal.h>
20489 \newline 
20490
20491 \newline 
20492 DEF_INTHIGH(high_int)
20493 \layout LyX-Code
20494
20495 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
20496 \layout LyX-Code
20497
20498 DEF_HANDLER(SIG_BCOL, _bcol_handler)
20499 \layout LyX-Code
20500
20501 END_DEF
20502 \newline 
20503
20504 \newline 
20505 SIGHANDLER(_tmr0_handler)
20506 \layout LyX-Code
20507
20508 {
20509 \layout LyX-Code
20510
20511   /* action to be taken when timer 0 overflows */
20512 \layout LyX-Code
20513
20514 }
20515 \newline 
20516
20517 \newline 
20518 SIGHANDLERNAKED(_bcol_handler)
20519 \layout LyX-Code
20520
20521 {
20522 \layout LyX-Code
20523
20524   _asm
20525 \layout LyX-Code
20526
20527     /* action to be taken when bus collision occurs */
20528 \layout LyX-Code
20529
20530     retfie
20531 \layout LyX-Code
20532
20533  _endasm;
20534 \layout LyX-Code
20535
20536 }
20537 \layout Standard
20538
20539
20540 \series bold 
20541 NOTES:
20542 \series default 
20543  Special care should be taken when using the above scheme:
20544 \layout Itemize
20545
20546 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
20547 \layout Itemize
20548
20549 when declaring SIGHANDLERNAKED handler never forget to use 
20550 \emph on 
20551 retfie
20552 \emph default 
20553  for proper returning.
20554 \layout Subsection
20555
20556 PIC16 Port -- Tips
20557 \layout Standard
20558
20559 Here you can find some general tips for compiling programs with SDCC/pic16.
20560 \layout Subsubsection
20561
20562 Stack size
20563 \layout Standard
20564
20565 The default stack size (that is 64 bytes) probably is enough for many programs.
20566  One must take care that when there are many levels of function nesting,
20567  or there is excessive usage of stack, its size should be extended.
20568  An example of such a case is the printf/sprintf family of functions.
20569  If you encounter problems like not being able to print integers, then you
20570  need to set the stack size around the maximum (256 for small stack model).
20571  The following diagram shows what happens when calling printf to print an
20572  integer:
20573 \layout LyX-Code
20574
20575 printf () --> ltoa () --> ultoa () --> divschar ()
20576 \layout Standard
20577
20578 It is should be understood that stack is easily consumed when calling complicate
20579 d functions.
20580  Using command line arguments like -
20581 \begin_inset ERT
20582 status Collapsed
20583
20584 \layout Standard
20585
20586 \backslash 
20587 /
20588 \end_inset 
20589
20590 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
20591  stack frames.
20592  Other ways to reduce stack usage may exist.
20593 \layout Chapter
20594
20595 Debugging with SDCDB
20596 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
20597
20598 \end_inset 
20599
20600
20601 \begin_inset LatexCommand \index{sdcdb (debugger)}
20602
20603 \end_inset 
20604
20605  
20606 \layout Standard
20607
20608 SDCC is distributed with a source level debugger
20609 \begin_inset LatexCommand \index{Debugger}
20610
20611 \end_inset 
20612
20613 .
20614  The debugger uses a command line interface, the command repertoire of the
20615  debugger has been kept as close to gdb
20616 \begin_inset LatexCommand \index{gdb}
20617
20618 \end_inset 
20619
20620  (the GNU debugger) as possible.
20621  The configuration and build process is part of the standard compiler installati
20622 on, which also builds and installs the debugger in the target directory
20623  specified during configuration.
20624  The debugger allows you debug BOTH at the C source and at the ASM source
20625  level.
20626  Sdcdb is currently not available on Win32 platforms.
20627 \layout Section
20628
20629 Compiling for Debugging
20630 \layout Standard
20631
20632 The -
20633 \begin_inset ERT
20634 status Collapsed
20635
20636 \layout Standard
20637
20638 \backslash 
20639 /
20640 \end_inset 
20641
20642 -debug
20643 \begin_inset LatexCommand \index{-\/-debug}
20644
20645 \end_inset 
20646
20647  option must be specified for all files for which debug information is to
20648  be generated.
20649  The complier generates a .adb file for each of these files.
20650  The linker creates the .cdb
20651 \begin_inset LatexCommand \index{<file>.cdb}
20652
20653 \end_inset 
20654
20655  file from the .adb
20656 \begin_inset LatexCommand \index{<file>.adb}
20657
20658 \end_inset 
20659
20660  files and the address information.
20661  This .cdb is used by the debugger.
20662 \layout Section
20663
20664 How the Debugger Works
20665 \layout Standard
20666
20667 When the -
20668 \begin_inset ERT
20669 status Collapsed
20670
20671 \layout Standard
20672
20673 \backslash 
20674 /
20675 \end_inset 
20676
20677 -debug option is specified the compiler generates extra symbol information
20678  some of which are put into the assembler source and some are put into the
20679  .adb file.
20680   Then the linker creates the .cdb file from the individual .adb files with
20681  the address information for the symbols.
20682  The debugger reads the symbolic information generated by the compiler &
20683  the address information generated by the linker.
20684  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
20685  execution is controlled by the debugger.
20686  When a command is issued for the debugger, it translates it into appropriate
20687  commands for the simulator.
20688 \layout Section
20689
20690 Starting the Debugger
20691 \layout Standard
20692
20693 The debugger can be started using the following command line.
20694  (Assume the file you are debugging has the file name foo).
20695 \newline 
20696
20697 \newline 
20698
20699 \family sans 
20700 \series bold 
20701 sdcdb foo
20702 \newline 
20703
20704 \family default 
20705 \series default 
20706
20707 \newline 
20708 The debugger will look for the following files.
20709 \layout Itemize
20710
20711 foo.c - the source file.
20712 \layout Itemize
20713
20714 foo.cdb - the debugger symbol information file.
20715 \layout Itemize
20716
20717 foo.ihx - the Intel hex format
20718 \begin_inset LatexCommand \index{Intel hex format}
20719
20720 \end_inset 
20721
20722  object file.
20723 \layout Section
20724
20725 Command Line Options
20726 \layout Itemize
20727
20728 -
20729 \begin_inset ERT
20730 status Collapsed
20731
20732 \layout Standard
20733
20734 \backslash 
20735 /
20736 \end_inset 
20737
20738 -directory=<source file directory> this option can used to specify the directory
20739  search list.
20740  The debugger will look into the directory list specified for source, cdb
20741  & ihx files.
20742  The items in the directory list must be separated by ':', e.g.
20743  if the source files can be in the directories /home/src1 and /home/src2,
20744  the -
20745 \begin_inset ERT
20746 status Collapsed
20747
20748 \layout Standard
20749
20750 \backslash 
20751 /
20752 \end_inset 
20753
20754 -directory option should be -
20755 \begin_inset ERT
20756 status Collapsed
20757
20758 \layout Standard
20759
20760 \backslash 
20761 /
20762 \end_inset 
20763
20764 -directory=/home/src1:/home/src2.
20765  Note there can be no spaces in the option.
20766  
20767 \layout Itemize
20768
20769 -cd <directory> - change to the <directory>.
20770 \layout Itemize
20771
20772 -fullname - used by GUI front ends.
20773 \layout Itemize
20774
20775 -cpu <cpu-type> - this argument is passed to the simulator please see the
20776  simulator docs for details.
20777 \layout Itemize
20778
20779 -X <Clock frequency > this options is passed to the simulator please see
20780  the simulator docs for details.
20781 \layout Itemize
20782
20783 -s <serial port file> passed to simulator see the simulator docs for details.
20784 \layout Itemize
20785
20786 -S <serial in,out> passed to simulator see the simulator docs for details.
20787 \layout Itemize
20788
20789 -k <port number> passed to simulator see the simulator docs for details.
20790 \layout Section
20791
20792 Debugger Commands
20793 \layout Standard
20794
20795 As mentioned earlier the command interface for the debugger has been deliberatel
20796 y kept as close the GNU debugger gdb, as possible.
20797  This will help the integration with existing graphical user interfaces
20798  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
20799  If you use a graphical user interface for the debugger you can skip this
20800  section.
20801 \layout Subsubsection*
20802
20803 break [line | file:line | function | file:function]
20804 \layout Standard
20805
20806 Set breakpoint at specified line or function:
20807 \newline 
20808
20809 \newline 
20810
20811 \family sans 
20812 \series bold 
20813 sdcdb>break 100 
20814 \newline 
20815 sdcdb>break foo.c:100
20816 \newline 
20817 sdcdb>break funcfoo
20818 \newline 
20819 sdcdb>break foo.c:funcfoo
20820 \layout Subsubsection*
20821
20822 clear [line | file:line | function | file:function ]
20823 \layout Standard
20824
20825 Clear breakpoint at specified line or function:
20826 \newline 
20827
20828 \newline 
20829
20830 \family sans 
20831 \series bold 
20832 sdcdb>clear 100
20833 \newline 
20834 sdcdb>clear foo.c:100
20835 \newline 
20836 sdcdb>clear funcfoo
20837 \newline 
20838 sdcdb>clear foo.c:funcfoo
20839 \layout Subsubsection*
20840
20841 continue
20842 \layout Standard
20843
20844 Continue program being debugged, after breakpoint.
20845 \layout Subsubsection*
20846
20847 finish
20848 \layout Standard
20849
20850 Execute till the end of the current function.
20851 \layout Subsubsection*
20852
20853 delete [n]
20854 \layout Standard
20855
20856 Delete breakpoint number 'n'.
20857  If used without any option clear ALL user defined break points.
20858 \layout Subsubsection*
20859
20860 info [break | stack | frame | registers ]
20861 \layout Itemize
20862
20863 info break - list all breakpoints
20864 \layout Itemize
20865
20866 info stack - show the function call stack.
20867 \layout Itemize
20868
20869 info frame - show information about the current execution frame.
20870 \layout Itemize
20871
20872 info registers - show content of all registers.
20873 \layout Subsubsection*
20874
20875 step
20876 \layout Standard
20877
20878 Step program until it reaches a different source line.
20879  Note: pressing <return> repeats the last command.
20880 \layout Subsubsection*
20881
20882 next
20883 \layout Standard
20884
20885 Step program, proceeding through subroutine calls.
20886 \layout Subsubsection*
20887
20888 run
20889 \layout Standard
20890
20891 Start debugged program.
20892 \layout Subsubsection*
20893
20894 ptype variable 
20895 \layout Standard
20896
20897 Print type information of the variable.
20898 \layout Subsubsection*
20899
20900 print variable
20901 \layout Standard
20902
20903 print value of variable.
20904 \layout Subsubsection*
20905
20906 file filename
20907 \layout Standard
20908
20909 load the given file name.
20910  Note this is an alternate method of loading file for debugging.
20911 \layout Subsubsection*
20912
20913 frame
20914 \layout Standard
20915
20916 print information about current frame.
20917 \layout Subsubsection*
20918
20919 set srcmode
20920 \layout Standard
20921
20922 Toggle between C source & assembly source.
20923 \layout Subsubsection*
20924
20925 ! simulator command
20926 \layout Standard
20927
20928 Send the string following '!' to the simulator, the simulator response is
20929  displayed.
20930  Note the debugger does not interpret the command being sent to the simulator,
20931  so if a command like 'go' is sent the debugger can loose its execution
20932  context and may display incorrect values.
20933 \layout Subsubsection*
20934
20935 quit
20936 \layout Standard
20937
20938 "Watch me now.
20939  Iam going Down.
20940  My name is Bobby Brown"
20941 \layout Section
20942
20943 Interfacing with DDD
20944 \layout Comment
20945
20946 The screenshot was converted from png to eps with: 
20947 \begin_inset Quotes sld
20948 \end_inset 
20949
20950 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
20951 \begin_inset Quotes srd
20952 \end_inset 
20953
20954  which produces a pretty compact eps file which is free from compression
20955  artifacts.
20956 \layout Comment
20957
20958 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
20959  as this broke the build system on Sourceforge (pdf-file was broken).
20960 \layout Standard
20961
20962 The .eps File 
20963 \size footnotesize 
20964
20965 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.eps}
20966
20967 \end_inset 
20968
20969
20970 \size default 
20971  shows a screenshot of a debugging session with DDD
20972 \begin_inset LatexCommand \index{DDD (debugger)}
20973
20974 \end_inset 
20975
20976  (Unix only) on a simulated 8032.
20977  The debugging session might not run as smoothly as the screenshot suggests.
20978  The debugger allows setting of breakpoints, displaying and changing variables,
20979  single stepping through C and assembler code.
20980  
20981 \newline 
20982 The source was compiled with 
20983 \family sans 
20984 \series bold 
20985
20986 \newline 
20987
20988 \newline 
20989 sdcc -
20990 \family default 
20991 \series default 
20992
20993 \begin_inset ERT
20994 status Collapsed
20995
20996 \layout Standard
20997
20998 \backslash 
20999 /
21000 \end_inset 
21001
21002
21003 \family sans 
21004 \series bold 
21005 -debug ddd_example.c
21006 \family default 
21007 \series default 
21008  
21009 \family sans 
21010 \series bold 
21011
21012 \newline 
21013
21014 \family default 
21015 \series default 
21016
21017 \newline 
21018 and DDD was invoked with 
21019 \family sans 
21020 \series bold 
21021
21022 \newline 
21023
21024 \newline 
21025 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
21026 \layout Section
21027
21028 Interfacing with XEmacs
21029 \begin_inset LatexCommand \index{XEmacs}
21030
21031 \end_inset 
21032
21033
21034 \begin_inset LatexCommand \index{Emacs}
21035
21036 \end_inset 
21037
21038
21039 \layout Standard
21040
21041 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
21042  sdcdb.el and sdcdbsrc.el.
21043  These two files can be found in the $(prefix)/bin directory after the installat
21044 ion is complete.
21045  These files need to be loaded into XEmacs for the interface to work.
21046  This can be done at XEmacs startup time by inserting the following into
21047  your '.xemacs' file (which can be found in your HOME directory): 
21048 \newline 
21049
21050 \newline 
21051
21052 \family typewriter 
21053 (load-file sdcdbsrc.el) 
21054 \family default 
21055
21056 \newline 
21057
21058 \newline 
21059 .xemacs is a lisp file so the () around the command is REQUIRED.
21060  The files can also be loaded dynamically while XEmacs is running, set the
21061  environment variable 'EMACSLOADPATH' to the installation bin directory
21062  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
21063  To start the interface enter the following command: 
21064 \newline 
21065
21066 \newline 
21067
21068 \family sans 
21069 \series bold 
21070 ESC-x sdcdbsrc
21071 \family default 
21072 \series default 
21073
21074 \newline 
21075
21076 \newline 
21077 You will prompted to enter the file name to be debugged.
21078  
21079 \newline 
21080
21081 \newline 
21082 The command line options that are passed to the simulator directly are bound
21083  to default values in the file sdcdbsrc.el.
21084  The variables are listed below, these values maybe changed as required.
21085 \layout Itemize
21086
21087 sdcdbsrc-cpu-type '51
21088 \layout Itemize
21089
21090 sdcdbsrc-frequency '11059200
21091 \layout Itemize
21092
21093 sdcdbsrc-serial nil
21094 \layout Standard
21095
21096 The following is a list of key mapping for the debugger interface.
21097 \layout Standard
21098
21099 \SpecialChar ~
21100
21101 \family typewriter 
21102
21103 \newline 
21104 ;;\SpecialChar ~
21105 Current Listing :: 
21106 \newline 
21107 ;;key\SpecialChar ~
21108 \SpecialChar ~
21109 \SpecialChar ~
21110 \SpecialChar ~
21111 \SpecialChar ~
21112 \SpecialChar ~
21113 \SpecialChar ~
21114 \SpecialChar ~
21115 \SpecialChar ~
21116 \SpecialChar ~
21117 \SpecialChar ~
21118 \SpecialChar ~
21119 \SpecialChar ~
21120 \SpecialChar ~
21121 binding\SpecialChar ~
21122 \SpecialChar ~
21123 \SpecialChar ~
21124 \SpecialChar ~
21125 \SpecialChar ~
21126 \SpecialChar ~
21127 \SpecialChar ~
21128 \SpecialChar ~
21129 \SpecialChar ~
21130 \SpecialChar ~
21131 \SpecialChar ~
21132 \SpecialChar ~
21133 \SpecialChar ~
21134 \SpecialChar ~
21135 \SpecialChar ~
21136 \SpecialChar ~
21137 \SpecialChar ~
21138 \SpecialChar ~
21139 \SpecialChar ~
21140 \SpecialChar ~
21141 \SpecialChar ~
21142 \SpecialChar ~
21143 Comment 
21144 \newline 
21145 ;;---\SpecialChar ~
21146 \SpecialChar ~
21147 \SpecialChar ~
21148 \SpecialChar ~
21149 \SpecialChar ~
21150 \SpecialChar ~
21151 \SpecialChar ~
21152 \SpecialChar ~
21153 \SpecialChar ~
21154 \SpecialChar ~
21155 \SpecialChar ~
21156 \SpecialChar ~
21157 \SpecialChar ~
21158 \SpecialChar ~
21159 -------\SpecialChar ~
21160 \SpecialChar ~
21161 \SpecialChar ~
21162 \SpecialChar ~
21163 \SpecialChar ~
21164 \SpecialChar ~
21165 \SpecialChar ~
21166 \SpecialChar ~
21167 \SpecialChar ~
21168 \SpecialChar ~
21169 \SpecialChar ~
21170 \SpecialChar ~
21171 \SpecialChar ~
21172 \SpecialChar ~
21173 \SpecialChar ~
21174 \SpecialChar ~
21175 \SpecialChar ~
21176 \SpecialChar ~
21177 \SpecialChar ~
21178 \SpecialChar ~
21179 \SpecialChar ~
21180 \SpecialChar ~
21181 -------
21182 \newline 
21183 ;; 
21184 \newline 
21185 ;;\SpecialChar ~
21186 n\SpecialChar ~
21187 \SpecialChar ~
21188 \SpecialChar ~
21189 \SpecialChar ~
21190 \SpecialChar ~
21191 \SpecialChar ~
21192 \SpecialChar ~
21193 \SpecialChar ~
21194 \SpecialChar ~
21195 \SpecialChar ~
21196 \SpecialChar ~
21197 \SpecialChar ~
21198 \SpecialChar ~
21199 \SpecialChar ~
21200 \SpecialChar ~
21201 sdcdb-next-from-src\SpecialChar ~
21202 \SpecialChar ~
21203 \SpecialChar ~
21204 \SpecialChar ~
21205 \SpecialChar ~
21206 \SpecialChar ~
21207 \SpecialChar ~
21208 \SpecialChar ~
21209 \SpecialChar ~
21210 \SpecialChar ~
21211 SDCDB next command 
21212 \newline 
21213 ;;\SpecialChar ~
21214 b\SpecialChar ~
21215 \SpecialChar ~
21216 \SpecialChar ~
21217 \SpecialChar ~
21218 \SpecialChar ~
21219 \SpecialChar ~
21220 \SpecialChar ~
21221 \SpecialChar ~
21222 \SpecialChar ~
21223 \SpecialChar ~
21224 \SpecialChar ~
21225 \SpecialChar ~
21226 \SpecialChar ~
21227 \SpecialChar ~
21228 \SpecialChar ~
21229 sdcdb-back-from-src\SpecialChar ~
21230 \SpecialChar ~
21231 \SpecialChar ~
21232 \SpecialChar ~
21233 \SpecialChar ~
21234 \SpecialChar ~
21235 \SpecialChar ~
21236 \SpecialChar ~
21237 \SpecialChar ~
21238 \SpecialChar ~
21239 SDCDB back command 
21240 \newline 
21241 ;;\SpecialChar ~
21242 c\SpecialChar ~
21243 \SpecialChar ~
21244 \SpecialChar ~
21245 \SpecialChar ~
21246 \SpecialChar ~
21247 \SpecialChar ~
21248 \SpecialChar ~
21249 \SpecialChar ~
21250 \SpecialChar ~
21251 \SpecialChar ~
21252 \SpecialChar ~
21253 \SpecialChar ~
21254 \SpecialChar ~
21255 \SpecialChar ~
21256 \SpecialChar ~
21257 sdcdb-cont-from-src\SpecialChar ~
21258 \SpecialChar ~
21259 \SpecialChar ~
21260 \SpecialChar ~
21261 \SpecialChar ~
21262 \SpecialChar ~
21263 \SpecialChar ~
21264 \SpecialChar ~
21265 \SpecialChar ~
21266 \SpecialChar ~
21267 SDCDB continue command
21268 \newline 
21269 ;;\SpecialChar ~
21270 s\SpecialChar ~
21271 \SpecialChar ~
21272 \SpecialChar ~
21273 \SpecialChar ~
21274 \SpecialChar ~
21275 \SpecialChar ~
21276 \SpecialChar ~
21277 \SpecialChar ~
21278 \SpecialChar ~
21279 \SpecialChar ~
21280 \SpecialChar ~
21281 \SpecialChar ~
21282 \SpecialChar ~
21283 \SpecialChar ~
21284 \SpecialChar ~
21285 sdcdb-step-from-src\SpecialChar ~
21286 \SpecialChar ~
21287 \SpecialChar ~
21288 \SpecialChar ~
21289 \SpecialChar ~
21290 \SpecialChar ~
21291 \SpecialChar ~
21292 \SpecialChar ~
21293 \SpecialChar ~
21294 \SpecialChar ~
21295 SDCDB step command 
21296 \newline 
21297 ;;\SpecialChar ~
21298 ?\SpecialChar ~
21299 \SpecialChar ~
21300 \SpecialChar ~
21301 \SpecialChar ~
21302 \SpecialChar ~
21303 \SpecialChar ~
21304 \SpecialChar ~
21305 \SpecialChar ~
21306 \SpecialChar ~
21307 \SpecialChar ~
21308 \SpecialChar ~
21309 \SpecialChar ~
21310 \SpecialChar ~
21311 \SpecialChar ~
21312 \SpecialChar ~
21313 sdcdb-whatis-c-sexp\SpecialChar ~
21314 \SpecialChar ~
21315 \SpecialChar ~
21316 \SpecialChar ~
21317 \SpecialChar ~
21318 \SpecialChar ~
21319 \SpecialChar ~
21320 \SpecialChar ~
21321 \SpecialChar ~
21322 \SpecialChar ~
21323 SDCDB ptypecommand for data at 
21324 \newline 
21325 ;;\SpecialChar ~
21326 \SpecialChar ~
21327 \SpecialChar ~
21328 \SpecialChar ~
21329 \SpecialChar ~
21330 \SpecialChar ~
21331 \SpecialChar ~
21332 \SpecialChar ~
21333 \SpecialChar ~
21334 \SpecialChar ~
21335 \SpecialChar ~
21336 \SpecialChar ~
21337 \SpecialChar ~
21338 \SpecialChar ~
21339 \SpecialChar ~
21340 \SpecialChar ~
21341 \SpecialChar ~
21342 \SpecialChar ~
21343 \SpecialChar ~
21344 \SpecialChar ~
21345 \SpecialChar ~
21346 \SpecialChar ~
21347 \SpecialChar ~
21348 \SpecialChar ~
21349 \SpecialChar ~
21350 \SpecialChar ~
21351 \SpecialChar ~
21352 \SpecialChar ~
21353 \SpecialChar ~
21354 \SpecialChar ~
21355 \SpecialChar ~
21356 \SpecialChar ~
21357 \SpecialChar ~
21358 \SpecialChar ~
21359 \SpecialChar ~
21360 \SpecialChar ~
21361 \SpecialChar ~
21362 \SpecialChar ~
21363 \SpecialChar ~
21364 \SpecialChar ~
21365 \SpecialChar ~
21366 \SpecialChar ~
21367 \SpecialChar ~
21368 \SpecialChar ~
21369 \SpecialChar ~
21370 \SpecialChar ~
21371 \SpecialChar ~
21372 buffer point 
21373 \newline 
21374 ;;\SpecialChar ~
21375 x\SpecialChar ~
21376 \SpecialChar ~
21377 \SpecialChar ~
21378 \SpecialChar ~
21379 \SpecialChar ~
21380 \SpecialChar ~
21381 \SpecialChar ~
21382 \SpecialChar ~
21383 \SpecialChar ~
21384 \SpecialChar ~
21385 \SpecialChar ~
21386 \SpecialChar ~
21387 \SpecialChar ~
21388 \SpecialChar ~
21389 \SpecialChar ~
21390 sdcdbsrc-delete\SpecialChar ~
21391 \SpecialChar ~
21392 \SpecialChar ~
21393 \SpecialChar ~
21394 \SpecialChar ~
21395 \SpecialChar ~
21396 \SpecialChar ~
21397 \SpecialChar ~
21398 \SpecialChar ~
21399 \SpecialChar ~
21400 \SpecialChar ~
21401 \SpecialChar ~
21402 \SpecialChar ~
21403 \SpecialChar ~
21404 SDCDB Delete all breakpoints if no arg 
21405 \newline 
21406 ;;\SpecialChar ~
21407 \SpecialChar ~
21408 \SpecialChar ~
21409 \SpecialChar ~
21410 \SpecialChar ~
21411 \SpecialChar ~
21412 \SpecialChar ~
21413 \SpecialChar ~
21414 \SpecialChar ~
21415 \SpecialChar ~
21416 \SpecialChar ~
21417 \SpecialChar ~
21418 \SpecialChar ~
21419 \SpecialChar ~
21420 \SpecialChar ~
21421 \SpecialChar ~
21422 \SpecialChar ~
21423 \SpecialChar ~
21424 \SpecialChar ~
21425 \SpecialChar ~
21426 \SpecialChar ~
21427 \SpecialChar ~
21428 \SpecialChar ~
21429 \SpecialChar ~
21430 \SpecialChar ~
21431 \SpecialChar ~
21432 \SpecialChar ~
21433 \SpecialChar ~
21434 \SpecialChar ~
21435 \SpecialChar ~
21436 \SpecialChar ~
21437 \SpecialChar ~
21438 \SpecialChar ~
21439 \SpecialChar ~
21440 \SpecialChar ~
21441 \SpecialChar ~
21442 \SpecialChar ~
21443 \SpecialChar ~
21444 \SpecialChar ~
21445 \SpecialChar ~
21446 \SpecialChar ~
21447 \SpecialChar ~
21448 \SpecialChar ~
21449 \SpecialChar ~
21450 \SpecialChar ~
21451 \SpecialChar ~
21452 \SpecialChar ~
21453 given or delete arg (C-u arg x) 
21454 \newline 
21455 ;;\SpecialChar ~
21456 m\SpecialChar ~
21457 \SpecialChar ~
21458 \SpecialChar ~
21459 \SpecialChar ~
21460 \SpecialChar ~
21461 \SpecialChar ~
21462 \SpecialChar ~
21463 \SpecialChar ~
21464 \SpecialChar ~
21465 \SpecialChar ~
21466 \SpecialChar ~
21467 \SpecialChar ~
21468 \SpecialChar ~
21469 \SpecialChar ~
21470 \SpecialChar ~
21471 sdcdbsrc-frame\SpecialChar ~
21472 \SpecialChar ~
21473 \SpecialChar ~
21474 \SpecialChar ~
21475 \SpecialChar ~
21476 \SpecialChar ~
21477 \SpecialChar ~
21478 \SpecialChar ~
21479 \SpecialChar ~
21480 \SpecialChar ~
21481 \SpecialChar ~
21482 \SpecialChar ~
21483 \SpecialChar ~
21484 \SpecialChar ~
21485 \SpecialChar ~
21486 SDCDB Display current frame if no arg, 
21487 \newline 
21488 ;;\SpecialChar ~
21489 \SpecialChar ~
21490 \SpecialChar ~
21491 \SpecialChar ~
21492 \SpecialChar ~
21493 \SpecialChar ~
21494 \SpecialChar ~
21495 \SpecialChar ~
21496 \SpecialChar ~
21497 \SpecialChar ~
21498 \SpecialChar ~
21499 \SpecialChar ~
21500 \SpecialChar ~
21501 \SpecialChar ~
21502 \SpecialChar ~
21503 \SpecialChar ~
21504 \SpecialChar ~
21505 \SpecialChar ~
21506 \SpecialChar ~
21507 \SpecialChar ~
21508 \SpecialChar ~
21509 \SpecialChar ~
21510 \SpecialChar ~
21511 \SpecialChar ~
21512 \SpecialChar ~
21513 \SpecialChar ~
21514 \SpecialChar ~
21515 \SpecialChar ~
21516 \SpecialChar ~
21517 \SpecialChar ~
21518 \SpecialChar ~
21519 \SpecialChar ~
21520 \SpecialChar ~
21521 \SpecialChar ~
21522 \SpecialChar ~
21523 \SpecialChar ~
21524 \SpecialChar ~
21525 \SpecialChar ~
21526 \SpecialChar ~
21527 \SpecialChar ~
21528 \SpecialChar ~
21529 \SpecialChar ~
21530 \SpecialChar ~
21531 \SpecialChar ~
21532 \SpecialChar ~
21533 \SpecialChar ~
21534 \SpecialChar ~
21535 given or display frame arg 
21536 \newline 
21537 ;;\SpecialChar ~
21538 \SpecialChar ~
21539 \SpecialChar ~
21540 \SpecialChar ~
21541 \SpecialChar ~
21542 \SpecialChar ~
21543 \SpecialChar ~
21544 \SpecialChar ~
21545 \SpecialChar ~
21546 \SpecialChar ~
21547 \SpecialChar ~
21548 \SpecialChar ~
21549 \SpecialChar ~
21550 \SpecialChar ~
21551 \SpecialChar ~
21552 \SpecialChar ~
21553 \SpecialChar ~
21554 \SpecialChar ~
21555 \SpecialChar ~
21556 \SpecialChar ~
21557 \SpecialChar ~
21558 \SpecialChar ~
21559 \SpecialChar ~
21560 \SpecialChar ~
21561 \SpecialChar ~
21562 \SpecialChar ~
21563 \SpecialChar ~
21564 \SpecialChar ~
21565 \SpecialChar ~
21566 \SpecialChar ~
21567 \SpecialChar ~
21568 \SpecialChar ~
21569 \SpecialChar ~
21570 \SpecialChar ~
21571 \SpecialChar ~
21572 \SpecialChar ~
21573 \SpecialChar ~
21574 \SpecialChar ~
21575 \SpecialChar ~
21576 \SpecialChar ~
21577 \SpecialChar ~
21578 \SpecialChar ~
21579 \SpecialChar ~
21580 \SpecialChar ~
21581 \SpecialChar ~
21582 \SpecialChar ~
21583 \SpecialChar ~
21584 buffer point 
21585 \newline 
21586 ;;\SpecialChar ~
21587 !\SpecialChar ~
21588 \SpecialChar ~
21589 \SpecialChar ~
21590 \SpecialChar ~
21591 \SpecialChar ~
21592 \SpecialChar ~
21593 \SpecialChar ~
21594 \SpecialChar ~
21595 \SpecialChar ~
21596 \SpecialChar ~
21597 \SpecialChar ~
21598 \SpecialChar ~
21599 \SpecialChar ~
21600 \SpecialChar ~
21601 \SpecialChar ~
21602 sdcdbsrc-goto-sdcdb\SpecialChar ~
21603 \SpecialChar ~
21604 \SpecialChar ~
21605 \SpecialChar ~
21606 \SpecialChar ~
21607 \SpecialChar ~
21608 \SpecialChar ~
21609 \SpecialChar ~
21610 \SpecialChar ~
21611 \SpecialChar ~
21612 Goto the SDCDB output buffer 
21613 \newline 
21614 ;;\SpecialChar ~
21615 p\SpecialChar ~
21616 \SpecialChar ~
21617 \SpecialChar ~
21618 \SpecialChar ~
21619 \SpecialChar ~
21620 \SpecialChar ~
21621 \SpecialChar ~
21622 \SpecialChar ~
21623 \SpecialChar ~
21624 \SpecialChar ~
21625 \SpecialChar ~
21626 \SpecialChar ~
21627 \SpecialChar ~
21628 \SpecialChar ~
21629 \SpecialChar ~
21630 sdcdb-print-c-sexp\SpecialChar ~
21631 \SpecialChar ~
21632 \SpecialChar ~
21633 \SpecialChar ~
21634 \SpecialChar ~
21635 \SpecialChar ~
21636 \SpecialChar ~
21637 \SpecialChar ~
21638 \SpecialChar ~
21639 \SpecialChar ~
21640 \SpecialChar ~
21641 SDCDB print command for data at 
21642 \newline 
21643 ;;\SpecialChar ~
21644 \SpecialChar ~
21645 \SpecialChar ~
21646 \SpecialChar ~
21647 \SpecialChar ~
21648 \SpecialChar ~
21649 \SpecialChar ~
21650 \SpecialChar ~
21651 \SpecialChar ~
21652 \SpecialChar ~
21653 \SpecialChar ~
21654 \SpecialChar ~
21655 \SpecialChar ~
21656 \SpecialChar ~
21657 \SpecialChar ~
21658 \SpecialChar ~
21659 \SpecialChar ~
21660 \SpecialChar ~
21661 \SpecialChar ~
21662 \SpecialChar ~
21663 \SpecialChar ~
21664 \SpecialChar ~
21665 \SpecialChar ~
21666 \SpecialChar ~
21667 \SpecialChar ~
21668 \SpecialChar ~
21669 \SpecialChar ~
21670 \SpecialChar ~
21671 \SpecialChar ~
21672 \SpecialChar ~
21673 \SpecialChar ~
21674 \SpecialChar ~
21675 \SpecialChar ~
21676 \SpecialChar ~
21677 \SpecialChar ~
21678 \SpecialChar ~
21679 \SpecialChar ~
21680 \SpecialChar ~
21681 \SpecialChar ~
21682 \SpecialChar ~
21683 \SpecialChar ~
21684 \SpecialChar ~
21685 \SpecialChar ~
21686 \SpecialChar ~
21687 \SpecialChar ~
21688 \SpecialChar ~
21689 \SpecialChar ~
21690 buffer point 
21691 \newline 
21692 ;;\SpecialChar ~
21693 g\SpecialChar ~
21694 \SpecialChar ~
21695 \SpecialChar ~
21696 \SpecialChar ~
21697 \SpecialChar ~
21698 \SpecialChar ~
21699 \SpecialChar ~
21700 \SpecialChar ~
21701 \SpecialChar ~
21702 \SpecialChar ~
21703 \SpecialChar ~
21704 \SpecialChar ~
21705 \SpecialChar ~
21706 \SpecialChar ~
21707 \SpecialChar ~
21708 sdcdbsrc-goto-sdcdb\SpecialChar ~
21709 \SpecialChar ~
21710 \SpecialChar ~
21711 \SpecialChar ~
21712 \SpecialChar ~
21713 \SpecialChar ~
21714 \SpecialChar ~
21715 \SpecialChar ~
21716 \SpecialChar ~
21717 \SpecialChar ~
21718 Goto the SDCDB output buffer 
21719 \newline 
21720 ;;\SpecialChar ~
21721 t\SpecialChar ~
21722 \SpecialChar ~
21723 \SpecialChar ~
21724 \SpecialChar ~
21725 \SpecialChar ~
21726 \SpecialChar ~
21727 \SpecialChar ~
21728 \SpecialChar ~
21729 \SpecialChar ~
21730 \SpecialChar ~
21731 \SpecialChar ~
21732 \SpecialChar ~
21733 \SpecialChar ~
21734 \SpecialChar ~
21735 \SpecialChar ~
21736 sdcdbsrc-mode\SpecialChar ~
21737 \SpecialChar ~
21738 \SpecialChar ~
21739 \SpecialChar ~
21740 \SpecialChar ~
21741 \SpecialChar ~
21742 \SpecialChar ~
21743 \SpecialChar ~
21744 \SpecialChar ~
21745 \SpecialChar ~
21746 \SpecialChar ~
21747 \SpecialChar ~
21748 \SpecialChar ~
21749 \SpecialChar ~
21750 \SpecialChar ~
21751 \SpecialChar ~
21752 Toggles Sdcdbsrc mode (turns it off) 
21753 \newline 
21754 ;; 
21755 \newline 
21756 ;;\SpecialChar ~
21757 C-c\SpecialChar ~
21758 C-f\SpecialChar ~
21759 \SpecialChar ~
21760 \SpecialChar ~
21761 \SpecialChar ~
21762 \SpecialChar ~
21763 \SpecialChar ~
21764 \SpecialChar ~
21765 \SpecialChar ~
21766 \SpecialChar ~
21767 sdcdb-finish-from-src\SpecialChar ~
21768 \SpecialChar ~
21769 \SpecialChar ~
21770 \SpecialChar ~
21771 \SpecialChar ~
21772 \SpecialChar ~
21773 \SpecialChar ~
21774 \SpecialChar ~
21775 SDCDB finish command 
21776 \newline 
21777 ;; 
21778 \newline 
21779 ;;\SpecialChar ~
21780 C-x\SpecialChar ~
21781 SPC\SpecialChar ~
21782 \SpecialChar ~
21783 \SpecialChar ~
21784 \SpecialChar ~
21785 \SpecialChar ~
21786 \SpecialChar ~
21787 \SpecialChar ~
21788 \SpecialChar ~
21789 \SpecialChar ~
21790 sdcdb-break\SpecialChar ~
21791 \SpecialChar ~
21792 \SpecialChar ~
21793 \SpecialChar ~
21794 \SpecialChar ~
21795 \SpecialChar ~
21796 \SpecialChar ~
21797 \SpecialChar ~
21798 \SpecialChar ~
21799 \SpecialChar ~
21800 \SpecialChar ~
21801 \SpecialChar ~
21802 \SpecialChar ~
21803 \SpecialChar ~
21804 \SpecialChar ~
21805 \SpecialChar ~
21806 \SpecialChar ~
21807 \SpecialChar ~
21808 Set break for line with point 
21809 \newline 
21810 ;;\SpecialChar ~
21811 ESC\SpecialChar ~
21812 t\SpecialChar ~
21813 \SpecialChar ~
21814 \SpecialChar ~
21815 \SpecialChar ~
21816 \SpecialChar ~
21817 \SpecialChar ~
21818 \SpecialChar ~
21819 \SpecialChar ~
21820 \SpecialChar ~
21821 \SpecialChar ~
21822 \SpecialChar ~
21823 sdcdbsrc-mode\SpecialChar ~
21824 \SpecialChar ~
21825 \SpecialChar ~
21826 \SpecialChar ~
21827 \SpecialChar ~
21828 \SpecialChar ~
21829 \SpecialChar ~
21830 \SpecialChar ~
21831 \SpecialChar ~
21832 \SpecialChar ~
21833 \SpecialChar ~
21834 \SpecialChar ~
21835 \SpecialChar ~
21836 \SpecialChar ~
21837 \SpecialChar ~
21838 \SpecialChar ~
21839 Toggle Sdcdbsrc mode 
21840 \newline 
21841 ;;\SpecialChar ~
21842 ESC\SpecialChar ~
21843 m\SpecialChar ~
21844 \SpecialChar ~
21845 \SpecialChar ~
21846 \SpecialChar ~
21847 \SpecialChar ~
21848 \SpecialChar ~
21849 \SpecialChar ~
21850 \SpecialChar ~
21851 \SpecialChar ~
21852 \SpecialChar ~
21853 \SpecialChar ~
21854 sdcdbsrc-srcmode\SpecialChar ~
21855 \SpecialChar ~
21856 \SpecialChar ~
21857 \SpecialChar ~
21858 \SpecialChar ~
21859 \SpecialChar ~
21860 \SpecialChar ~
21861 \SpecialChar ~
21862 \SpecialChar ~
21863 \SpecialChar ~
21864 \SpecialChar ~
21865 \SpecialChar ~
21866 \SpecialChar ~
21867 Toggle list mode 
21868 \newline 
21869 ;; 
21870 \newline 
21871
21872 \layout Chapter
21873 \pagebreak_top 
21874 TIPS
21875 \layout Standard
21876
21877 Here are a few guidelines that will help the compiler generate more efficient
21878  code, some of the tips are specific to this compiler others are generally
21879  good programming practice.
21880 \layout Itemize
21881
21882 Use the smallest data type to represent your data-value.
21883  If it is known in advance that the value is going to be less than 256 then
21884  use an 'unsigned char' instead of a 'short' or 'int'.
21885  Please note, that ANSI C requires both signed and unsigned chars to be
21886  promoted to 'signed int' before doing any operation.
21887  This promotion
21888 \begin_inset LatexCommand \index{type promotion}
21889
21890 \end_inset 
21891
21892  can be omitted, if the result is the same.
21893  The effect of the promotion rules together with the sign-extension is often
21894  surprising:
21895 \begin_deeper 
21896 \layout Verse
21897
21898
21899 \family typewriter 
21900 unsigned char uc = 0xfe;
21901 \newline 
21902 if (uc * uc < 0) /* this is true! */
21903 \newline 
21904 {
21905 \newline 
21906 \SpecialChar ~
21907 \SpecialChar ~
21908 \SpecialChar ~
21909 \SpecialChar ~
21910 ....
21911 \newline 
21912 }
21913 \layout Standard
21914
21915
21916 \family typewriter 
21917 uc * uc
21918 \family default 
21919  is evaluated as 
21920 \family typewriter 
21921 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
21922 \family default 
21923 .
21924  
21925 \newline 
21926 Another one:
21927 \layout Verse
21928
21929
21930 \family typewriter 
21931 (unsigned char) -12 / (signed char) -3 = ...
21932 \layout Standard
21933
21934 No, the result is not 4:
21935 \layout Verse
21936
21937
21938 \family typewriter 
21939 (int) (unsigned char) -12 / (int) (signed char) -3 =
21940 \newline 
21941 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
21942 \newline 
21943 (int) 0x00f4 / (int) 0xfffd =
21944 \newline 
21945 (int) 0x00f4 / (int) 0xfffd =
21946 \newline 
21947 (int) 244 / (int) -3 =
21948 \newline 
21949 (int) -81 = (int) 0xffaf;
21950 \layout Standard
21951
21952 Don't complain, that gcc gives you a different result.
21953  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
21954  Therefore the results are different.
21955 \newline 
21956 From 
21957 \begin_inset Quotes sld
21958 \end_inset 
21959
21960 comp.lang.c FAQ
21961 \begin_inset Quotes srd
21962 \end_inset 
21963
21964 :
21965 \layout Quote
21966
21967 If well-defined overflow characteristics are important and negative values
21968  are not, or if you want to steer clear of sign-extension problems when
21969  manipulating bits or bytes, use one of the corresponding unsigned types.
21970  (Beware when mixing signed and unsigned values in expressions, though.)
21971 \newline 
21972 Although character types (especially unsigned char) can be used as "tiny"
21973  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
21974 ble sign extension and increased code size.
21975 \end_deeper 
21976 \layout Itemize
21977
21978 Use unsigned when it is known in advance that the value is not going to
21979  be negative.
21980  This helps especially if you are doing division or multiplication, bit-shifting
21981  or are using an array index.
21982 \layout Itemize
21983
21984 NEVER jump into a LOOP.
21985 \layout Itemize
21986
21987 Declare the variables to be local
21988 \begin_inset LatexCommand \index{local variables}
21989
21990 \end_inset 
21991
21992  whenever possible, especially loop control variables (induction).
21993 \layout Itemize
21994
21995 Since the compiler does not always do implicit integral promotion, the programme
21996 r should do an explicit cast when integral promotion is required.
21997 \layout Itemize
21998
21999 Reducing the size of division, multiplication & modulus operations can reduce
22000  code size substantially.
22001  Take the following code for example.
22002 \begin_deeper 
22003 \layout Verse
22004
22005
22006 \family typewriter 
22007 foobar(unsigned int p1, unsigned char ch)
22008 \newline 
22009 {
22010 \newline 
22011 \SpecialChar ~
22012 \SpecialChar ~
22013 \SpecialChar ~
22014 \SpecialChar ~
22015 unsigned char ch1 = p1 % ch ;
22016 \newline 
22017 \SpecialChar ~
22018 \SpecialChar ~
22019 \SpecialChar ~
22020 \SpecialChar ~
22021 ....
22022 \newline 
22023 }
22024 \layout Standard
22025
22026 For the modulus operation the variable ch will be promoted to unsigned int
22027  first then the modulus operation will be performed (this will lead to a
22028  call to support routine _moduint()), and the result will be casted to a
22029  char.
22030  If the code is changed to 
22031 \layout Verse
22032
22033
22034 \family typewriter 
22035 foobar(unsigned int p1, unsigned char ch)
22036 \newline 
22037 {
22038 \newline 
22039 \SpecialChar ~
22040 \SpecialChar ~
22041 \SpecialChar ~
22042 \SpecialChar ~
22043 unsigned char ch1 = (unsigned char)p1 % ch ;
22044 \newline 
22045 \SpecialChar ~
22046 \SpecialChar ~
22047 \SpecialChar ~
22048 \SpecialChar ~
22049 ....
22050 \newline 
22051 }
22052 \layout Standard
22053
22054 It would substantially reduce the code generated (future versions of the
22055  compiler will be smart enough to detect such optimization opportunities).
22056 \end_deeper 
22057 \layout Itemize
22058
22059 Have a look at the assembly listing to get a 
22060 \begin_inset Quotes sld
22061 \end_inset 
22062
22063 feeling
22064 \begin_inset Quotes srd
22065 \end_inset 
22066
22067  for the code generation.
22068 \layout Section
22069
22070 Tools
22071 \begin_inset LatexCommand \index{Tools}
22072
22073 \end_inset 
22074
22075  included in the distribution
22076 \layout Standard
22077 \align center 
22078
22079 \begin_inset  Tabular
22080 <lyxtabular version="3" rows="12" columns="3">
22081 <features>
22082 <column alignment="center" valignment="top" leftline="true" width="0pt">
22083 <column alignment="center" valignment="top" leftline="true" width="0pt">
22084 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22085 <row topline="true" bottomline="true">
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22087 \begin_inset Text
22088
22089 \layout Standard
22090
22091 Name
22092 \end_inset 
22093 </cell>
22094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22095 \begin_inset Text
22096
22097 \layout Standard
22098
22099 Purpose
22100 \end_inset 
22101 </cell>
22102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22103 \begin_inset Text
22104
22105 \layout Standard
22106
22107 Directory
22108 \end_inset 
22109 </cell>
22110 </row>
22111 <row topline="true">
22112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22113 \begin_inset Text
22114
22115 \layout Standard
22116
22117 uCsim
22118 \end_inset 
22119 </cell>
22120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22121 \begin_inset Text
22122
22123 \layout Standard
22124
22125 Simulator for various architectures
22126 \end_inset 
22127 </cell>
22128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22129 \begin_inset Text
22130
22131 \layout Standard
22132
22133 sdcc/sim/ucsim
22134 \end_inset 
22135 </cell>
22136 </row>
22137 <row topline="true">
22138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22139 \begin_inset Text
22140
22141 \layout Standard
22142
22143 keil2sdcc.pl
22144 \end_inset 
22145 </cell>
22146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22147 \begin_inset Text
22148
22149 \layout Standard
22150
22151 header file conversion
22152 \end_inset 
22153 </cell>
22154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22155 \begin_inset Text
22156
22157 \layout Standard
22158
22159 sdcc/support/scripts
22160 \end_inset 
22161 </cell>
22162 </row>
22163 <row topline="true">
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22165 \begin_inset Text
22166
22167 \layout Standard
22168
22169 mh2h.c
22170 \end_inset 
22171 </cell>
22172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22173 \begin_inset Text
22174
22175 \layout Standard
22176
22177 header file conversion
22178 \end_inset 
22179 </cell>
22180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22181 \begin_inset Text
22182
22183 \layout Standard
22184
22185 sdcc/support/scripts
22186 \end_inset 
22187 </cell>
22188 </row>
22189 <row topline="true">
22190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22191 \begin_inset Text
22192
22193 \layout Standard
22194
22195 as-gbz80
22196 \end_inset 
22197 </cell>
22198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22199 \begin_inset Text
22200
22201 \layout Standard
22202
22203 Assembler
22204 \end_inset 
22205 </cell>
22206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22207 \begin_inset Text
22208
22209 \layout Standard
22210
22211
22212 \family roman 
22213 \series medium 
22214 \shape up 
22215 \size normal 
22216 \emph off 
22217 \bar no 
22218 \noun off 
22219 \color none
22220 sdcc/bin
22221 \end_inset 
22222 </cell>
22223 </row>
22224 <row topline="true">
22225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22226 \begin_inset Text
22227
22228 \layout Standard
22229
22230 as-z80
22231 \end_inset 
22232 </cell>
22233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22234 \begin_inset Text
22235
22236 \layout Standard
22237
22238 Assembler
22239 \end_inset 
22240 </cell>
22241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22242 \begin_inset Text
22243
22244 \layout Standard
22245
22246
22247 \family roman 
22248 \series medium 
22249 \shape up 
22250 \size normal 
22251 \emph off 
22252 \bar no 
22253 \noun off 
22254 \color none
22255 sdcc/bin
22256 \end_inset 
22257 </cell>
22258 </row>
22259 <row topline="true">
22260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22261 \begin_inset Text
22262
22263 \layout Standard
22264
22265 asx8051
22266 \end_inset 
22267 </cell>
22268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22269 \begin_inset Text
22270
22271 \layout Standard
22272
22273 Assembler
22274 \end_inset 
22275 </cell>
22276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22277 \begin_inset Text
22278
22279 \layout Standard
22280
22281
22282 \family roman 
22283 \series medium 
22284 \shape up 
22285 \size normal 
22286 \emph off 
22287 \bar no 
22288 \noun off 
22289 \color none
22290 sdcc/bin
22291 \end_inset 
22292 </cell>
22293 </row>
22294 <row topline="true">
22295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22296 \begin_inset Text
22297
22298 \layout Standard
22299
22300 sdcdb
22301 \end_inset 
22302 </cell>
22303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22304 \begin_inset Text
22305
22306 \layout Standard
22307
22308 Simulator
22309 \end_inset 
22310 </cell>
22311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22312 \begin_inset Text
22313
22314 \layout Standard
22315
22316
22317 \family roman 
22318 \series medium 
22319 \shape up 
22320 \size normal 
22321 \emph off 
22322 \bar no 
22323 \noun off 
22324 \color none
22325 sdcc/bin
22326 \end_inset 
22327 </cell>
22328 </row>
22329 <row topline="true">
22330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22331 \begin_inset Text
22332
22333 \layout Standard
22334
22335 aslink
22336 \end_inset 
22337 </cell>
22338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22339 \begin_inset Text
22340
22341 \layout Standard
22342
22343 Linker
22344 \end_inset 
22345 </cell>
22346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22347 \begin_inset Text
22348
22349 \layout Standard
22350
22351
22352 \family roman 
22353 \series medium 
22354 \shape up 
22355 \size normal 
22356 \emph off 
22357 \bar no 
22358 \noun off 
22359 \color none
22360 sdcc/bin
22361 \end_inset 
22362 </cell>
22363 </row>
22364 <row topline="true">
22365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22366 \begin_inset Text
22367
22368 \layout Standard
22369
22370 link-z80
22371 \end_inset 
22372 </cell>
22373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22374 \begin_inset Text
22375
22376 \layout Standard
22377
22378 Linker
22379 \end_inset 
22380 </cell>
22381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22382 \begin_inset Text
22383
22384 \layout Standard
22385
22386
22387 \family roman 
22388 \series medium 
22389 \shape up 
22390 \size normal 
22391 \emph off 
22392 \bar no 
22393 \noun off 
22394 \color none
22395 sdcc/bin
22396 \end_inset 
22397 </cell>
22398 </row>
22399 <row topline="true">
22400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22401 \begin_inset Text
22402
22403 \layout Standard
22404
22405 link-gbz80
22406 \end_inset 
22407 </cell>
22408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22409 \begin_inset Text
22410
22411 \layout Standard
22412
22413 Linker
22414 \end_inset 
22415 </cell>
22416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22417 \begin_inset Text
22418
22419 \layout Standard
22420
22421
22422 \family roman 
22423 \series medium 
22424 \shape up 
22425 \size normal 
22426 \emph off 
22427 \bar no 
22428 \noun off 
22429 \color none
22430 sdcc/bin
22431 \end_inset 
22432 </cell>
22433 </row>
22434 <row topline="true" bottomline="true">
22435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22436 \begin_inset Text
22437
22438 \layout Standard
22439
22440 packihx
22441 \end_inset 
22442 </cell>
22443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22444 \begin_inset Text
22445
22446 \layout Standard
22447
22448 ihx packer
22449 \end_inset 
22450 </cell>
22451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22452 \begin_inset Text
22453
22454 \layout Standard
22455
22456
22457 \family roman 
22458 \series medium 
22459 \shape up 
22460 \size normal 
22461 \emph off 
22462 \bar no 
22463 \noun off 
22464 \color none
22465 sdcc/bin
22466 \end_inset 
22467 </cell>
22468 </row>
22469 </lyxtabular>
22470
22471 \end_inset 
22472
22473
22474 \newline 
22475
22476 \layout Section
22477
22478 Documentation
22479 \begin_inset LatexCommand \index{Documentation}
22480
22481 \end_inset 
22482
22483  included in the distribution
22484 \layout Standard
22485 \align center 
22486
22487 \begin_inset  Tabular
22488 <lyxtabular version="3" rows="10" columns="2">
22489 <features>
22490 <column alignment="left" valignment="top" leftline="true" width="0">
22491 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22492 <row topline="true" bottomline="true">
22493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22494 \begin_inset Text
22495
22496 \layout Standard
22497
22498 Subject / Title
22499 \end_inset 
22500 </cell>
22501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22502 \begin_inset Text
22503
22504 \layout Standard
22505
22506 Where to get / filename
22507 \end_inset 
22508 </cell>
22509 </row>
22510 <row topline="true">
22511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22512 \begin_inset Text
22513
22514 \layout Standard
22515
22516 SDCC Compiler User Guide
22517 \end_inset 
22518 </cell>
22519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22520 \begin_inset Text
22521
22522 \layout Standard
22523
22524 You're reading it right now
22525 \end_inset 
22526 </cell>
22527 </row>
22528 <row topline="true">
22529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22530 \begin_inset Text
22531
22532 \layout Standard
22533
22534 Changelog of SDCC
22535 \end_inset 
22536 </cell>
22537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22538 \begin_inset Text
22539
22540 \layout Standard
22541
22542 sdcc/Changelog
22543 \end_inset 
22544 </cell>
22545 </row>
22546 <row topline="true">
22547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22548 \begin_inset Text
22549
22550 \layout Standard
22551
22552 ASXXXX
22553 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
22554
22555 \end_inset 
22556
22557
22558 \begin_inset LatexCommand \index{Assembler documentation}
22559
22560 \end_inset 
22561
22562  Assemblers and ASLINK
22563 \begin_inset LatexCommand \index{aslink}
22564
22565 \end_inset 
22566
22567
22568 \begin_inset LatexCommand \index{Linker documentation}
22569
22570 \end_inset 
22571
22572  Relocating Linker
22573 \end_inset 
22574 </cell>
22575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22576 \begin_inset Text
22577
22578 \layout Standard
22579
22580 sdcc/as/doc/asxhtm.html
22581 \end_inset 
22582 </cell>
22583 </row>
22584 <row topline="true">
22585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22586 \begin_inset Text
22587
22588 \layout Standard
22589
22590 SDCC regression test
22591 \begin_inset LatexCommand \index{Regression test}
22592
22593 \end_inset 
22594
22595
22596 \end_inset 
22597 </cell>
22598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22599 \begin_inset Text
22600
22601 \layout Standard
22602
22603 sdcc/doc/test_suite_spec.pdf
22604 \end_inset 
22605 </cell>
22606 </row>
22607 <row topline="true">
22608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22609 \begin_inset Text
22610
22611 \layout Standard
22612
22613 Various notes
22614 \end_inset 
22615 </cell>
22616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22617 \begin_inset Text
22618
22619 \layout Standard
22620
22621 sdcc/doc/*
22622 \end_inset 
22623 </cell>
22624 </row>
22625 <row topline="true">
22626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22627 \begin_inset Text
22628
22629 \layout Standard
22630
22631 Notes on debugging with sdcdb
22632 \begin_inset LatexCommand \index{sdcdb (debugger)}
22633
22634 \end_inset 
22635
22636
22637 \end_inset 
22638 </cell>
22639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22640 \begin_inset Text
22641
22642 \layout Standard
22643
22644 sdcc/debugger/README
22645 \end_inset 
22646 </cell>
22647 </row>
22648 <row topline="true">
22649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22650 \begin_inset Text
22651
22652 \layout Standard
22653
22654 Software simulator for microcontrollers
22655 \end_inset 
22656 </cell>
22657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22658 \begin_inset Text
22659
22660 \layout Standard
22661
22662
22663 \family roman 
22664 \series medium 
22665 \shape up 
22666 \size normal 
22667 \emph off 
22668 \bar no 
22669 \noun off 
22670 \color none
22671 sdcc/sim/ucsim/doc
22672 \family default 
22673 \series default 
22674 \shape default 
22675 \size default 
22676 \emph default 
22677 \bar default 
22678 \noun default 
22679 \color default
22680 /index.html
22681 \end_inset 
22682 </cell>
22683 </row>
22684 <row topline="true">
22685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22686 \begin_inset Text
22687
22688 \layout Standard
22689
22690 Temporary notes on the pic16
22691 \begin_inset LatexCommand \index{PIC16}
22692
22693 \end_inset 
22694
22695  port
22696 \end_inset 
22697 </cell>
22698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22699 \begin_inset Text
22700
22701 \layout Standard
22702
22703 sdcc/src/pic16/NOTES
22704 \end_inset 
22705 </cell>
22706 </row>
22707 <row topline="true" bottomline="true">
22708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22709 \begin_inset Text
22710
22711 \layout Standard
22712
22713 SDCC internal documentation (debugging file format)
22714 \end_inset 
22715 </cell>
22716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22717 \begin_inset Text
22718
22719 \layout Standard
22720
22721 sdcc/doc/
22722 \family roman 
22723 \series medium 
22724 \shape up 
22725 \size normal 
22726 \emph off 
22727 \bar no 
22728 \noun off 
22729 \color none
22730 cdbfileformat.pd
22731 \family default 
22732 \series default 
22733 \shape default 
22734 \size default 
22735 \emph default 
22736 \bar default 
22737 \noun default 
22738 \color default
22739 f
22740 \end_inset 
22741 </cell>
22742 </row>
22743 </lyxtabular>
22744
22745 \end_inset 
22746
22747
22748 \newline 
22749
22750 \layout Section
22751
22752 Related open source tools
22753 \begin_inset LatexCommand \index{Related tools}
22754
22755 \end_inset 
22756
22757
22758 \layout Standard
22759 \align center 
22760
22761 \begin_inset  Tabular
22762 <lyxtabular version="3" rows="11" columns="3">
22763 <features>
22764 <column alignment="center" valignment="top" leftline="true" width="0pt">
22765 <column alignment="block" valignment="top" leftline="true" width="30line%">
22766 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22767 <row topline="true" bottomline="true">
22768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22769 \begin_inset Text
22770
22771 \layout Standard
22772
22773 Name
22774 \end_inset 
22775 </cell>
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22777 \begin_inset Text
22778
22779 \layout Standard
22780
22781 Purpose
22782 \end_inset 
22783 </cell>
22784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22785 \begin_inset Text
22786
22787 \layout Standard
22788
22789 Where to get
22790 \end_inset 
22791 </cell>
22792 </row>
22793 <row topline="true">
22794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22795 \begin_inset Text
22796
22797 \layout Standard
22798
22799 gpsim
22800 \begin_inset LatexCommand \index{gpsim (pic simulator)}
22801
22802 \end_inset 
22803
22804
22805 \end_inset 
22806 </cell>
22807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22808 \begin_inset Text
22809
22810 \layout Standard
22811
22812 PIC simulator
22813 \end_inset 
22814 </cell>
22815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22816 \begin_inset Text
22817
22818 \layout Standard
22819
22820
22821 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
22822
22823 \end_inset 
22824
22825
22826 \end_inset 
22827 </cell>
22828 </row>
22829 <row topline="true">
22830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22831 \begin_inset Text
22832
22833 \layout Standard
22834
22835 gputils
22836 \begin_inset LatexCommand \index{gputils (pic tools)}
22837
22838 \end_inset 
22839
22840
22841 \end_inset 
22842 </cell>
22843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22844 \begin_inset Text
22845
22846 \layout Standard
22847
22848 GNU PIC utilities
22849 \end_inset 
22850 </cell>
22851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22852 \begin_inset Text
22853
22854 \layout Standard
22855
22856
22857 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22858
22859 \end_inset 
22860
22861
22862 \end_inset 
22863 </cell>
22864 </row>
22865 <row topline="true">
22866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22867 \begin_inset Text
22868
22869 \layout Standard
22870
22871 flP5
22872 \end_inset 
22873 </cell>
22874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22875 \begin_inset Text
22876
22877 \layout Standard
22878
22879 PIC programmer
22880 \end_inset 
22881 </cell>
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22883 \begin_inset Text
22884
22885 \layout Standard
22886
22887
22888 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
22889
22890 \end_inset 
22891
22892
22893 \end_inset 
22894 </cell>
22895 </row>
22896 <row topline="true">
22897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22898 \begin_inset Text
22899
22900 \layout Standard
22901
22902 indent
22903 \begin_inset LatexCommand \index{indent (source formatting tool)}
22904
22905 \end_inset 
22906
22907
22908 \end_inset 
22909 </cell>
22910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22911 \begin_inset Text
22912
22913 \layout Standard
22914
22915 Formats C source - Master of the white spaces
22916 \end_inset 
22917 </cell>
22918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22919 \begin_inset Text
22920
22921 \layout Standard
22922
22923
22924 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
22925
22926 \end_inset 
22927
22928
22929 \end_inset 
22930 </cell>
22931 </row>
22932 <row topline="true">
22933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22934 \begin_inset Text
22935
22936 \layout Standard
22937
22938 srecord
22939 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
22940
22941 \end_inset 
22942
22943
22944 \end_inset 
22945 </cell>
22946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22947 \begin_inset Text
22948
22949 \layout Standard
22950
22951 Object file conversion, checksumming, ...
22952 \end_inset 
22953 </cell>
22954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22955 \begin_inset Text
22956
22957 \layout Standard
22958
22959
22960 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
22961
22962 \end_inset 
22963
22964
22965 \end_inset 
22966 </cell>
22967 </row>
22968 <row topline="true">
22969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22970 \begin_inset Text
22971
22972 \layout Standard
22973
22974 objdump
22975 \begin_inset LatexCommand \index{objdump (tool)}
22976
22977 \end_inset 
22978
22979
22980 \end_inset 
22981 </cell>
22982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22983 \begin_inset Text
22984
22985 \layout Standard
22986
22987 Object file conversion, ...
22988 \end_inset 
22989 </cell>
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22991 \begin_inset Text
22992
22993 \layout Standard
22994
22995 Part of binutils (should be there anyway)
22996 \end_inset 
22997 </cell>
22998 </row>
22999 <row topline="true">
23000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23001 \begin_inset Text
23002
23003 \layout Standard
23004
23005 doxygen
23006 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
23007
23008 \end_inset 
23009
23010
23011 \end_inset 
23012 </cell>
23013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23014 \begin_inset Text
23015
23016 \layout Standard
23017
23018 Source code documentation system
23019 \end_inset 
23020 </cell>
23021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23022 \begin_inset Text
23023
23024 \layout Standard
23025
23026
23027 \begin_inset LatexCommand \url{http://www.doxygen.org}
23028
23029 \end_inset 
23030
23031
23032 \end_inset 
23033 </cell>
23034 </row>
23035 <row topline="true">
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23037 \begin_inset Text
23038
23039 \layout Standard
23040
23041 kdevelop
23042 \end_inset 
23043 </cell>
23044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23045 \begin_inset Text
23046
23047 \layout Standard
23048
23049 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
23050 \end_inset 
23051 </cell>
23052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23053 \begin_inset Text
23054
23055 \layout Standard
23056
23057
23058 \begin_inset LatexCommand \url{http://www.kdevelop.org}
23059
23060 \end_inset 
23061
23062
23063 \end_inset 
23064 </cell>
23065 </row>
23066 <row topline="true">
23067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23068 \begin_inset Text
23069
23070 \layout Standard
23071
23072 splint
23073 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23074
23075 \end_inset 
23076
23077
23078 \end_inset 
23079 </cell>
23080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23081 \begin_inset Text
23082
23083 \layout Standard
23084
23085 Statically checks c sources (see 
23086 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23087
23088 \end_inset 
23089
23090 )
23091 \end_inset 
23092 </cell>
23093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23094 \begin_inset Text
23095
23096 \layout Standard
23097
23098
23099 \begin_inset LatexCommand \url{http://www.splint.org}
23100
23101 \end_inset 
23102
23103
23104 \end_inset 
23105 </cell>
23106 </row>
23107 <row topline="true" bottomline="true">
23108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23109 \begin_inset Text
23110
23111 \layout Standard
23112
23113 ddd
23114 \begin_inset LatexCommand \index{ddd (debugger)}
23115
23116 \end_inset 
23117
23118
23119 \end_inset 
23120 </cell>
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23122 \begin_inset Text
23123
23124 \layout Standard
23125
23126 Debugger, serves nicely as GUI to sdcdb
23127 \begin_inset LatexCommand \index{sdcdb (debugger)}
23128
23129 \end_inset 
23130
23131  (Unix only)
23132 \end_inset 
23133 </cell>
23134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23135 \begin_inset Text
23136
23137 \layout Standard
23138
23139
23140 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
23141
23142 \end_inset 
23143
23144
23145 \end_inset 
23146 </cell>
23147 </row>
23148 </lyxtabular>
23149
23150 \end_inset 
23151
23152
23153 \newline 
23154
23155 \layout Section
23156
23157 Related documentation / recommended reading
23158 \layout Standard
23159 \align center 
23160
23161 \begin_inset  Tabular
23162 <lyxtabular version="3" rows="6" columns="3">
23163 <features>
23164 <column alignment="center" valignment="top" leftline="true" width="0pt">
23165 <column alignment="block" valignment="top" leftline="true" width="30line%">
23166 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
23167 <row topline="true" bottomline="true">
23168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23169 \begin_inset Text
23170
23171 \layout Standard
23172
23173 Name
23174 \end_inset 
23175 </cell>
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \layout Standard
23180
23181 Subject / Title
23182 \end_inset 
23183 </cell>
23184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23185 \begin_inset Text
23186
23187 \layout Standard
23188
23189 Where to get
23190 \end_inset 
23191 </cell>
23192 </row>
23193 <row topline="true">
23194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23195 \begin_inset Text
23196
23197 \layout Standard
23198
23199
23200 \family roman 
23201 \series medium 
23202 \shape up 
23203 \size normal 
23204 \emph off 
23205 \bar no 
23206 \noun off 
23207 \color none
23208 c-refcard.pdf
23209 \end_inset 
23210 </cell>
23211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23212 \begin_inset Text
23213
23214 \layout Standard
23215
23216 C Reference Card
23217 \begin_inset LatexCommand \index{C Reference card}
23218
23219 \end_inset 
23220
23221 , 2 pages
23222 \end_inset 
23223 </cell>
23224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23225 \begin_inset Text
23226
23227 \layout Standard
23228
23229
23230 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
23231
23232 \end_inset 
23233
23234
23235 \end_inset 
23236 </cell>
23237 </row>
23238 <row topline="true">
23239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23240 \begin_inset Text
23241
23242 \layout Standard
23243
23244 c-faq
23245 \end_inset 
23246 </cell>
23247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23248 \begin_inset Text
23249
23250 \layout Standard
23251
23252 C-FAQ-list
23253 \end_inset 
23254 </cell>
23255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23256 \begin_inset Text
23257
23258 \layout Standard
23259
23260
23261 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
23262
23263 \end_inset 
23264
23265
23266 \end_inset 
23267 </cell>
23268 </row>
23269 <row topline="true">
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23271 \begin_inset Text
23272
23273 \layout Standard
23274
23275 \end_inset 
23276 </cell>
23277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23278 \begin_inset Text
23279
23280 \layout Standard
23281
23282 Latest datasheet of the target CPU
23283 \end_inset 
23284 </cell>
23285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23286 \begin_inset Text
23287
23288 \layout Standard
23289
23290 vendor
23291 \end_inset 
23292 </cell>
23293 </row>
23294 <row topline="true">
23295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23296 \begin_inset Text
23297
23298 \layout Standard
23299
23300 \end_inset 
23301 </cell>
23302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23303 \begin_inset Text
23304
23305 \layout Standard
23306
23307 Revision history of datasheet
23308 \end_inset 
23309 </cell>
23310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23311 \begin_inset Text
23312
23313 \layout Standard
23314
23315 vendor
23316 \end_inset 
23317 </cell>
23318 </row>
23319 <row topline="true" bottomline="true">
23320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23321 \begin_inset Text
23322
23323 \layout Standard
23324
23325 S.
23326  S.
23327  Muchnick
23328 \end_inset 
23329 </cell>
23330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23331 \begin_inset Text
23332
23333 \layout Standard
23334
23335 Advanced Compiler Design and Implementation
23336 \end_inset 
23337 </cell>
23338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23339 \begin_inset Text
23340
23341 \layout Standard
23342
23343 bookstore (very dedicated, probably read other books first)
23344 \end_inset 
23345 </cell>
23346 </row>
23347 </lyxtabular>
23348
23349 \end_inset 
23350
23351
23352 \newline 
23353
23354 \layout Section
23355
23356 Some Questions
23357 \layout Standard
23358
23359 Some questions answered, some pointers given - it might be time to in turn
23360  ask 
23361 \emph on 
23362 you
23363 \emph default 
23364  some questions: 
23365 \layout Itemize
23366
23367 can you solve your project with the selected microcontroller? Would you
23368  find out early or rather late that your target is too small/slow/whatever?
23369  Can you switch to a slightly better device if it doesn't fit?
23370 \layout Itemize
23371
23372 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
23373  and/or another programming language be more adequate? Would an operating
23374  system on the target device help?
23375 \layout Itemize
23376
23377 if you solved the problem, will the marketing department be happy?
23378 \layout Itemize
23379
23380 if the marketing department is happy, will customers be happy?
23381 \layout Itemize
23382
23383 if you're the project manager, marketing department and maybe even the customer
23384  in one person, have you tried to see the project from the outside?
23385 \layout Itemize
23386
23387 is the project done if you think it is done? Or is just that other interface/pro
23388 tocol/feature/configuration/option missing? How about website, manual(s),
23389  internationali(z|s)ation, packaging, labels, 2nd source for components,
23390  electromagnetic compatability/interference, documentation for production,
23391  production test software, update mechanism, patent issues?
23392 \layout Itemize
23393
23394 is your project adequately positioned in that magic triangle: fame, fortune,
23395  fun?
23396 \layout Standard
23397
23398 Maybe not all answers to these questions are known and some answers may
23399  even be 
23400 \emph on 
23401 no
23402 \emph default 
23403 , nevertheless knowing these questions may help you to avoid burnout
23404 \begin_inset Foot
23405 collapsed false
23406
23407 \layout Standard
23408
23409 burnout is bad for electronic devices, programmers and motorcycle tyres
23410 \end_inset 
23411
23412 .
23413  Chances are you didn't want to hear some of them...
23414 \layout Chapter
23415
23416 Support
23417 \begin_inset LatexCommand \index{Support}
23418
23419 \end_inset 
23420
23421
23422 \layout Standard
23423
23424 SDCC has grown to be a large project.
23425  The compiler alone (without the preprocessor, assembler and linker) is
23426  well over 100,000 lines of code (blank stripped).
23427  The open source nature of this project is a key to its continued growth
23428  and support.
23429  You gain the benefit and support of many active software developers and
23430  end users.
23431  Is SDCC perfect? No, that's why we need your help.
23432  The developers take pride in fixing reported bugs.
23433  You can help by reporting the bugs and helping other SDCC users.
23434  There are lots of ways to contribute, and we encourage you to take part
23435  in making SDCC a great software package.
23436  
23437 \layout Standard
23438
23439 The SDCC project is hosted on the SDCC sourceforge site at 
23440 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
23441
23442 \end_inset 
23443
23444 .
23445  You'll find the complete set of mailing lists
23446 \begin_inset LatexCommand \index{Mailing list(s)}
23447
23448 \end_inset 
23449
23450 , forums, bug reporting system, patch submission
23451 \begin_inset LatexCommand \index{Patch submission}
23452
23453 \end_inset 
23454
23455  system, download
23456 \begin_inset LatexCommand \index{download}
23457
23458 \end_inset 
23459
23460  area and Subversion code repository
23461 \begin_inset LatexCommand \index{Subversion code repository}
23462
23463 \end_inset 
23464
23465  there.
23466 \layout Section
23467
23468 Reporting Bugs
23469 \begin_inset LatexCommand \index{Bug reporting}
23470
23471 \end_inset 
23472
23473
23474 \begin_inset LatexCommand \index{Reporting bugs}
23475
23476 \end_inset 
23477
23478
23479 \layout Standard
23480
23481 The recommended way of reporting bugs is using the infrastructure of the
23482  sourceforge site.
23483  You can follow the status of bug reports there and have an overview about
23484  the known bugs.
23485 \layout Standard
23486
23487 Bug reports are automatically forwarded to the developer mailing list and
23488  will be fixed ASAP.
23489  When reporting a bug, it is very useful to include a small test program
23490  (the smaller the better) which reproduces the problem.
23491  If you can isolate the problem by looking at the generated assembly code,
23492  this can be very helpful.
23493  Compiling your program with the -
23494 \begin_inset ERT
23495 status Collapsed
23496
23497 \layout Standard
23498
23499 \backslash 
23500 /
23501 \end_inset 
23502
23503 -dumpall
23504 \begin_inset LatexCommand \index{-\/-dumpall}
23505
23506 \end_inset 
23507
23508  option can sometimes be useful in locating optimization problems.
23509  When reporting a bug please maker sure you:
23510 \layout Enumerate
23511
23512 Attach the code you are compiling with SDCC.
23513  
23514 \layout Enumerate
23515
23516 Specify the exact command you use to run SDCC, or attach your Makefile.
23517  
23518 \layout Enumerate
23519
23520 Specify the SDCC version (type "
23521 \family sans 
23522 \series bold 
23523 sdcc -v
23524 \family default 
23525 \series default 
23526 "), your platform, and operating system.
23527  
23528 \layout Enumerate
23529
23530 Provide an exact copy of any error message or incorrect output.
23531  
23532 \layout Enumerate
23533
23534 Put something meaningful in the subject of your message.
23535 \layout Standard
23536
23537 Please attempt to include these 5 important parts, as applicable, in all
23538  requests for support or when reporting any problems or bugs with SDCC.
23539  Though this will make your message lengthy, it will greatly improve your
23540  chance that SDCC users and developers will be able to help you.
23541  Some SDCC developers are frustrated by bug reports without code provided
23542  that they can use to reproduce and ultimately fix the problem, so please
23543  be sure to provide sample code if you are reporting a bug! 
23544 \layout Standard
23545
23546 Please have a short check that you are using a recent version of SDCC and
23547  the bug is not yet known.
23548  This is the link for reporting bugs: 
23549 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
23550
23551 \end_inset 
23552
23553 .
23554 \layout Section
23555
23556 Requesting Features
23557 \begin_inset LatexCommand \label{sub:Requesting-Features}
23558
23559 \end_inset 
23560
23561
23562 \begin_inset LatexCommand \index{Feature request}
23563
23564 \end_inset 
23565
23566
23567 \begin_inset LatexCommand \index{Requesting features}
23568
23569 \end_inset 
23570
23571
23572 \layout Standard
23573
23574 Like bug reports feature requests are forwarded to the developer mailing
23575  list.
23576  This is the link for requesting features: 
23577 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
23578
23579 \end_inset 
23580
23581 .
23582 \layout Section
23583
23584 Submitting patches
23585 \layout Standard
23586
23587 Like bug reports contributed patches are forwarded to the developer mailing
23588  list.
23589  This is the link for submitting patches
23590 \begin_inset LatexCommand \index{Patch submission}
23591
23592 \end_inset 
23593
23594
23595 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
23596
23597 \end_inset 
23598
23599 .
23600 \layout Standard
23601
23602 You need to specify some parameters to the 
23603 \family typewriter 
23604 diff
23605 \family default 
23606  command for the patches to be useful.
23607  If you modified more than one file a patch created f.e.
23608  with 
23609 \family sans 
23610 \series bold 
23611
23612 \begin_inset Quotes sld
23613 \end_inset 
23614
23615 diff -Naur unmodified_directory modified_directory >my_changes.patch
23616 \begin_inset Quotes srd
23617 \end_inset 
23618
23619
23620 \family default 
23621 \series default 
23622  will be fine, otherwise 
23623 \family sans 
23624 \series bold 
23625
23626 \begin_inset Quotes sld
23627 \end_inset 
23628
23629 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
23630 \begin_inset Quotes srd
23631 \end_inset 
23632
23633
23634 \series default 
23635  
23636 \family default 
23637 will do.
23638 \layout Section
23639
23640 Getting Help
23641 \layout Standard
23642
23643 These links should take you directly to the 
23644 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
23645
23646 \end_inset 
23647
23648
23649 \begin_inset Foot
23650 collapsed false
23651
23652 \layout Standard
23653
23654 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
23655  automated messages (mid 2003)
23656 \end_inset 
23657
23658  and the 
23659 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
23660
23661 \end_inset 
23662
23663 , lists
23664 \begin_inset LatexCommand \index{Mailing list(s)}
23665
23666 \end_inset 
23667
23668  and forums are archived and searchable so if you are lucky someone already
23669  had a similar problem.
23670  While mails to the lists themselves are delivered promptly their web front
23671  end on sourceforge sometimes shows a severe time lag (up to several weeks),
23672  if you're seriously using SDCC please consider subscribing to the lists.
23673 \layout Section
23674
23675 ChangeLog
23676 \layout Standard
23677
23678 You can follow the status of the Subversion version
23679 \begin_inset LatexCommand \index{version}
23680
23681 \end_inset 
23682
23683  of SDCC by watching the Changelog
23684 \begin_inset LatexCommand \index{Changelog}
23685
23686 \end_inset 
23687
23688  in the Subversion repository
23689 \newline 
23690
23691 \size footnotesize 
23692
23693 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
23694
23695 \end_inset 
23696
23697 .
23698 \layout Section
23699
23700 Release policy
23701 \begin_inset LatexCommand \index{Release policy}
23702
23703 \end_inset 
23704
23705
23706 \layout Standard
23707
23708 Historically there often were long delays between official releases and
23709  the sourceforge download area tends to get not updated at all.
23710  Excuses in the past might have referred to problems with live range analysis,
23711  but as this was fixed a while ago, the current problem is that another
23712  excuse has to be found.
23713  Kidding aside, we have to get better there! On the other hand there are
23714  daily snapshots available at 
23715 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
23716
23717 \end_inset 
23718
23719 , and you can always build the very last version (hopefully with many bugs
23720  fixed, and features added) from the source code available at 
23721 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
23722
23723 \end_inset 
23724
23725 .
23726 \layout Section
23727
23728 Examples
23729 \begin_inset LatexCommand \index{Examples}
23730
23731 \end_inset 
23732
23733
23734 \layout Standard
23735
23736 You'll find some small examples in the directory 
23737 \emph on 
23738 sdcc/device/examples/.
23739  
23740 \emph default 
23741 More examples and libraries are available at
23742 \emph on 
23743  The SDCC Open Knowledge Resource 
23744 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
23745
23746 \end_inset 
23747
23748  
23749 \emph default 
23750 web site or at 
23751 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
23752
23753 \end_inset 
23754
23755 .
23756 \layout Comment
23757
23758 I did insert a reference to Paul's web site here although it seems rather
23759  dedicated to a specific 8032 board (I think it's okay because it f.e.
23760  shows LCD/Harddisc interface and has a free 8051 monitor.
23761  Independent 8032 board vendors face hard competition of heavily subsidized
23762  development boards anyway).
23763 \layout Comment
23764
23765 Maybe we should include some links to real world applications.
23766  Preferably pointer to pointers (one for each architecture) so this stays
23767  manageable here?
23768 \layout Section
23769
23770 Quality control
23771 \begin_inset LatexCommand \index{Quality control}
23772
23773 \end_inset 
23774
23775
23776 \layout Standard
23777
23778 The compiler is passed through nightly compile and build checks.
23779  The so called 
23780 \shape italic 
23781 regression tests
23782 \shape default 
23783
23784 \begin_inset LatexCommand \index{Regression test}
23785
23786 \end_inset 
23787
23788  check that SDCC itself compiles flawlessly on several platforms and checks
23789  the quality of the code generated by SDCC by running the code through simulator
23790 s.
23791  There is a separate document 
23792 \shape italic 
23793 test_suite.pdf
23794 \begin_inset LatexCommand \index{Test suite}
23795
23796 \end_inset 
23797
23798
23799 \shape default 
23800  about this.
23801 \layout Standard
23802
23803 You'll find the test code in the directory 
23804 \shape italic 
23805 sdcc/support/regression
23806 \shape default 
23807 .
23808  You can run these tests manually by running 
23809 \family sans 
23810 make
23811 \family default 
23812  in this directory (or f.e.
23813  
23814 \family sans 
23815 \series bold 
23816
23817 \begin_inset Quotes sld
23818 \end_inset 
23819
23820 make test-mcs51
23821 \begin_inset Quotes srd
23822 \end_inset 
23823
23824
23825 \family default 
23826 \series default 
23827  if you don't want to run the complete tests).
23828  The test code might also be interesting if you want to look for examples
23829 \begin_inset LatexCommand \index{Examples}
23830
23831 \end_inset 
23832
23833  checking corner cases of SDCC or if you plan to submit patches
23834 \begin_inset LatexCommand \index{Patch submission}
23835
23836 \end_inset 
23837
23838 .
23839 \layout Standard
23840
23841 The pic port uses a different set of regression tests, you'll find them
23842  in the directory 
23843 \shape italic 
23844 sdcc/src/regression
23845 \shape default 
23846 .
23847 \layout Section
23848
23849 Use of SDCC in Education
23850 \layout Standard
23851
23852 In short: 
23853 \emph on 
23854 highly
23855 \emph default 
23856  encouraged
23857 \begin_inset Foot
23858 collapsed false
23859
23860 \layout Standard
23861
23862 the phrase "use in education" might evoke the association "
23863 \emph on 
23864 only
23865 \emph default 
23866  fit for use in education".
23867  This connotation is not intended but nevertheless risked as the licensing
23868  of SDCC makes it difficult to offer educational discounts
23869 \end_inset 
23870
23871 .
23872  If your rationales are to:
23873 \layout Enumerate
23874
23875 give students a chance to understand the 
23876 \emph on 
23877 complete
23878 \emph default 
23879  steps of code generation
23880 \layout Enumerate
23881
23882 have a curriculum that can be extended for years.
23883  Then you could use an fpga board as target and your curriculum will seamlessly
23884  extend from logic synthesis (
23885 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
23886
23887 \end_inset 
23888
23889
23890 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
23891
23892 \end_inset 
23893
23894 ), over assembly programming, to C to FPGA compilers (
23895 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
23896
23897 \end_inset 
23898
23899 ) and to C.
23900 \layout Enumerate
23901
23902 be able to insert excursions about skills like using a revision control
23903  system, submitting/applying patches, using a type-setting (as opposed to
23904  word-processing) engine LyX/LaTeX, using 
23905 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
23906
23907 \end_inset 
23908
23909 , following some 
23910 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
23911
23912 \end_inset 
23913
23914 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
23915  Source Software, CPU simulation, compiler regression tests
23916 \begin_inset LatexCommand \index{Regression test}
23917
23918 \end_inset 
23919
23920 .
23921  
23922 \newline 
23923 And if there should be a shortage of ideas then you can always point students
23924  to the ever-growing feature request list 
23925 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
23926
23927 \end_inset 
23928
23929 .
23930 \layout Enumerate
23931
23932 not tie students to a specific host platform and instead allow them to use
23933  a host platform of 
23934 \emph on 
23935 their
23936 \emph default 
23937  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
23938  eventually 
23939 \begin_inset LatexCommand \url[OLPC]{http://wiki.laptop.org/wiki/One_Laptop_per_Child}
23940
23941 \end_inset 
23942
23943 )
23944 \layout Enumerate
23945
23946 not encourage students to use illegal copies of educational software
23947 \layout Enumerate
23948
23949 be immune to licensing/availability/price changes of the chosen tool chain
23950 \layout Enumerate
23951
23952 be able to change to a new target platform without having to adopt a new
23953  tool chain
23954 \layout Enumerate
23955
23956 have complete control over and insight into the tool chain
23957 \layout Enumerate
23958
23959 make your students aware about the pros and cons of open source software
23960  development
23961 \layout Enumerate
23962
23963 give back to the public as you are probably at least partially publically
23964  funded
23965 \layout Enumerate
23966
23967 give students a chance to publically prove their skills and to possibly
23968  see a world wide impact
23969 \layout Standard
23970
23971 then SDCC is probably among the first choices.
23972  Well, probably SDCC might be the only choice.
23973 \layout Chapter
23974 \pagebreak_top 
23975 SDCC Technical Data
23976 \layout Section
23977
23978 Optimizations
23979 \begin_inset LatexCommand \index{Optimizations}
23980
23981 \end_inset 
23982
23983
23984 \layout Standard
23985
23986 SDCC performs a host of standard optimizations in addition to some MCU specific
23987  optimizations.
23988  
23989 \layout Subsection
23990
23991 Sub-expression Elimination
23992 \begin_inset LatexCommand \index{Subexpression elimination}
23993
23994 \end_inset 
23995
23996
23997 \layout Standard
23998
23999 The compiler does local and 
24000 \emph on 
24001 g
24002 \emph default 
24003 lobal 
24004 \emph on 
24005 c
24006 \emph default 
24007 ommon 
24008 \emph on 
24009 s
24010 \emph default 
24011 ubexpression 
24012 \emph on 
24013 e
24014 \emph default 
24015 limination, e.g.: 
24016 \layout Verse
24017
24018
24019 \family typewriter 
24020 i = x + y + 1; 
24021 \newline 
24022 j = x + y;
24023 \layout Standard
24024
24025 will be translated to
24026 \layout Verse
24027
24028
24029 \family typewriter 
24030 iTemp = x + y; 
24031 \newline 
24032 i = iTemp + 1; 
24033 \newline 
24034 j = iTemp;
24035 \layout Standard
24036
24037 Some subexpressions are not as obvious as the above example, e.g.:
24038 \layout Verse
24039
24040
24041 \family typewriter 
24042 a->b[i].c = 10; 
24043 \newline 
24044 a->b[i].d = 11;
24045 \layout Standard
24046
24047 In this case the address arithmetic a->b[i] will be computed only once;
24048  the equivalent code in C would be.
24049 \layout Verse
24050
24051
24052 \family typewriter 
24053 iTemp = a->b[i]; 
24054 \newline 
24055 iTemp.c = 10; 
24056 \newline 
24057 iTemp.d = 11;
24058 \layout Standard
24059
24060 The compiler will try to keep these temporary variables in registers.
24061 \layout Subsection
24062
24063 Dead-Code Elimination
24064 \begin_inset LatexCommand \index{Dead-code elimination}
24065
24066 \end_inset 
24067
24068
24069 \layout Verse
24070
24071
24072 \family typewriter 
24073 int global;
24074 \newline 
24075
24076 \newline 
24077 void f () { 
24078 \newline 
24079 \SpecialChar ~
24080 \SpecialChar ~
24081 int i; 
24082 \newline 
24083 \SpecialChar ~
24084 \SpecialChar ~
24085 i = 1; \SpecialChar ~
24086 \SpecialChar ~
24087 \SpecialChar ~
24088 \SpecialChar ~
24089 \SpecialChar ~
24090 /* dead store */ 
24091 \newline 
24092 \SpecialChar ~
24093 \SpecialChar ~
24094 global = 1;\SpecialChar ~
24095 /* dead store */ 
24096 \newline 
24097 \SpecialChar ~
24098 \SpecialChar ~
24099 global = 2; 
24100 \newline 
24101 \SpecialChar ~
24102 \SpecialChar ~
24103 return; 
24104 \newline 
24105 \SpecialChar ~
24106 \SpecialChar ~
24107 global = 3;\SpecialChar ~
24108 /* unreachable */ 
24109 \newline 
24110 }
24111 \layout Standard
24112
24113 will be changed to
24114 \layout Verse
24115
24116
24117 \family typewriter 
24118 int global;
24119 \newline 
24120
24121 \newline 
24122 void f () {
24123 \newline 
24124 \SpecialChar ~
24125 \SpecialChar ~
24126 global = 2; 
24127 \newline 
24128 }
24129 \layout Subsection
24130
24131 Copy-Propagation
24132 \begin_inset LatexCommand \index{Copy propagation}
24133
24134 \end_inset 
24135
24136
24137 \layout Verse
24138
24139
24140 \family typewriter 
24141 int f() { 
24142 \newline 
24143 \SpecialChar ~
24144 \SpecialChar ~
24145 int i, j; 
24146 \newline 
24147 \SpecialChar ~
24148 \SpecialChar ~
24149 i = 10; 
24150 \newline 
24151 \SpecialChar ~
24152 \SpecialChar ~
24153 j = i; 
24154 \newline 
24155 \SpecialChar ~
24156 \SpecialChar ~
24157 return j; 
24158 \newline 
24159 }
24160 \layout Standard
24161
24162 will be changed to 
24163 \layout Verse
24164
24165
24166 \family typewriter 
24167 int f() { 
24168 \newline 
24169 \SpecialChar ~
24170 \SpecialChar ~
24171 int i, j; 
24172 \newline 
24173 \SpecialChar ~
24174 \SpecialChar ~
24175 i = 10; 
24176 \newline 
24177 \SpecialChar ~
24178 \SpecialChar ~
24179 j = 10; 
24180 \newline 
24181 \SpecialChar ~
24182 \SpecialChar ~
24183 return 10; 
24184 \newline 
24185 }
24186 \layout Standard
24187
24188 Note: the dead stores created by this copy propagation will be eliminated
24189  by dead-code elimination.
24190 \layout Subsection
24191
24192 Loop Optimizations
24193 \begin_inset LatexCommand \index{Loop optimization}
24194
24195 \end_inset 
24196
24197
24198 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
24199
24200 \end_inset 
24201
24202
24203 \layout Standard
24204
24205 Two types of loop optimizations are done by SDCC 
24206 \emph on 
24207 loop invariant
24208 \emph default 
24209  lifting and
24210 \emph on 
24211  strength reduction
24212 \emph default 
24213  of loop induction variables.
24214  In addition to the strength reduction the optimizer marks the induction
24215  variables and the register allocator tries to keep the induction variables
24216  in registers for the duration of the loop.
24217  Because of this preference of the register allocator
24218 \begin_inset LatexCommand \index{Register allocation}
24219
24220 \end_inset 
24221
24222 , loop induction optimization causes an increase in register pressure, which
24223  may cause unwanted spilling of other temporary variables into the stack
24224 \begin_inset LatexCommand \index{stack}
24225
24226 \end_inset 
24227
24228  / data space.
24229  The compiler will generate a warning message when it is forced to allocate
24230  extra space either on the stack or data space.
24231  If this extra space allocation is undesirable then induction optimization
24232  can be eliminated either for the entire source file (with -
24233 \begin_inset ERT
24234 status Collapsed
24235
24236 \layout Standard
24237
24238 \backslash 
24239 /
24240 \end_inset 
24241
24242 -noinduction option) or for a given function only using #pragma\SpecialChar ~
24243 noinduction
24244 \begin_inset LatexCommand \index{\#pragma noinduction}
24245
24246 \end_inset 
24247
24248 .
24249 \newline 
24250
24251 \newline 
24252 Loop Invariant:
24253 \layout Verse
24254
24255
24256 \family typewriter 
24257 for (i = 0 ; i < 100 ; i ++) 
24258 \newline 
24259 \SpecialChar ~
24260 \SpecialChar ~
24261 \SpecialChar ~
24262 \SpecialChar ~
24263 f += k + l;
24264 \layout Standard
24265
24266 changed to
24267 \layout Verse
24268
24269
24270 \family typewriter 
24271 itemp = k + l; 
24272 \newline 
24273 for (i = 0; i < 100; i++) 
24274 \newline 
24275 \SpecialChar ~
24276 \SpecialChar ~
24277 \SpecialChar ~
24278 \SpecialChar ~
24279 f += itemp;
24280 \layout Standard
24281
24282 As mentioned previously some loop invariants are not as apparent, all static
24283  address computations are also moved out of the loop.
24284 \newline 
24285
24286 \newline 
24287 Strength Reduction
24288 \begin_inset LatexCommand \index{Strength reduction}
24289
24290 \end_inset 
24291
24292 , this optimization substitutes an expression by a cheaper expression:
24293 \layout Verse
24294
24295
24296 \family typewriter 
24297 for (i=0;i < 100; i++)
24298 \newline 
24299 \SpecialChar ~
24300 \SpecialChar ~
24301 \SpecialChar ~
24302 \SpecialChar ~
24303 ar[i*5] = i*3;
24304 \layout Standard
24305
24306 changed to
24307 \layout Verse
24308
24309
24310 \family typewriter 
24311 itemp1 = 0; 
24312 \newline 
24313 itemp2 = 0; 
24314 \newline 
24315 for (i=0;i< 100;i++) { 
24316 \newline 
24317 \SpecialChar ~
24318 \SpecialChar ~
24319 \SpecialChar ~
24320 \SpecialChar ~
24321 ar[itemp1] = itemp2; 
24322 \newline 
24323 \SpecialChar ~
24324 \SpecialChar ~
24325 \SpecialChar ~
24326 \SpecialChar ~
24327 itemp1 += 5; 
24328 \newline 
24329 \SpecialChar ~
24330 \SpecialChar ~
24331 \SpecialChar ~
24332 \SpecialChar ~
24333 itemp2 += 3; 
24334 \newline 
24335 }
24336 \layout Standard
24337
24338 The more expensive multiplication
24339 \begin_inset LatexCommand \index{Multiplication}
24340
24341 \end_inset 
24342
24343  is changed to a less expensive addition.
24344 \layout Subsection
24345
24346 Loop Reversing
24347 \begin_inset LatexCommand \index{Loop reversing}
24348
24349 \end_inset 
24350
24351
24352 \layout Standard
24353
24354 This optimization is done to reduce the overhead of checking loop boundaries
24355  for every iteration.
24356  Some simple loops can be reversed and implemented using a 
24357 \begin_inset Quotes eld
24358 \end_inset 
24359
24360 decrement and jump if not zero
24361 \begin_inset Quotes erd
24362 \end_inset 
24363
24364  instruction.
24365  SDCC checks for the following criterion to determine if a loop is reversible
24366  (note: more sophisticated compilers use data-dependency analysis to make
24367  this determination, SDCC uses a more simple minded analysis).
24368 \layout Itemize
24369
24370 The 'for' loop is of the form 
24371 \newline 
24372
24373 \newline 
24374
24375 \family typewriter 
24376 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
24377  += 1])
24378 \newline 
24379 \SpecialChar ~
24380 \SpecialChar ~
24381 \SpecialChar ~
24382 \SpecialChar ~
24383 <for body>
24384 \layout Itemize
24385
24386 The <for body> does not contain 
24387 \begin_inset Quotes eld
24388 \end_inset 
24389
24390 continue
24391 \begin_inset Quotes erd
24392 \end_inset 
24393
24394  or 'break
24395 \begin_inset Quotes erd
24396 \end_inset 
24397
24398 .
24399 \layout Itemize
24400
24401 All goto's are contained within the loop.
24402 \layout Itemize
24403
24404 No function calls within the loop.
24405 \layout Itemize
24406
24407 The loop control variable <sym> is not assigned any value within the loop
24408 \layout Itemize
24409
24410 The loop control variable does NOT participate in any arithmetic operation
24411  within the loop.
24412 \layout Itemize
24413
24414 There are NO switch statements in the loop.
24415 \layout Subsection
24416
24417 Algebraic Simplifications
24418 \layout Standard
24419
24420 SDCC does numerous algebraic simplifications, the following is a small sub-set
24421  of these optimizations.
24422 \layout Verse
24423
24424
24425 \family typewriter 
24426 i = j + 0;\SpecialChar ~
24427 \SpecialChar ~
24428 \SpecialChar ~
24429 \SpecialChar ~
24430  /* changed to: */\SpecialChar ~
24431 \SpecialChar ~
24432 \SpecialChar ~
24433 \SpecialChar ~
24434  i = j; 
24435 \newline 
24436 i /= 2;\SpecialChar ~
24437 \SpecialChar ~
24438 \SpecialChar ~
24439 \SpecialChar ~
24440 \SpecialChar ~
24441 \SpecialChar ~
24442 \SpecialChar ~
24443  /* changed to: */\SpecialChar ~
24444 \SpecialChar ~
24445 \SpecialChar ~
24446 \SpecialChar ~
24447  i >>= 1; 
24448 \newline 
24449 i = j - j;\SpecialChar ~
24450 \SpecialChar ~
24451 \SpecialChar ~
24452 \SpecialChar ~
24453  /* changed to: */\SpecialChar ~
24454 \SpecialChar ~
24455 \SpecialChar ~
24456 \SpecialChar ~
24457  i = 0; 
24458 \newline 
24459 i = j / 1;\SpecialChar ~
24460 \SpecialChar ~
24461 \SpecialChar ~
24462 \SpecialChar ~
24463  /* changed to: */\SpecialChar ~
24464 \SpecialChar ~
24465 \SpecialChar ~
24466 \SpecialChar ~
24467  i = j;
24468 \layout Standard
24469
24470 Note the subexpressions
24471 \begin_inset LatexCommand \index{Subexpression}
24472
24473 \end_inset 
24474
24475  given above are generally introduced by macro expansions or as a result
24476  of copy/constant propagation.
24477 \layout Subsection
24478
24479 'switch' Statements
24480 \begin_inset LatexCommand \label{sub:'switch'-Statements}
24481
24482 \end_inset 
24483
24484
24485 \begin_inset LatexCommand \index{switch statement}
24486
24487 \end_inset 
24488
24489
24490 \layout Standard
24491
24492 SDCC can optimize switch statements to jump tables
24493 \begin_inset LatexCommand \index{jump tables}
24494
24495 \end_inset 
24496
24497 .
24498  It makes the decision based on an estimate of the generated code size.
24499  SDCC is quite liberal in the requirements for jump table generation: 
24500 \layout Itemize
24501
24502 The labels need not be in order, and the starting number need not be one
24503  or zero, the case labels are in numerical sequence or not too many case
24504  labels are missing.
24505 \begin_deeper 
24506 \layout Verse
24507
24508
24509 \family typewriter 
24510 switch(i) {\SpecialChar ~
24511 \SpecialChar ~
24512 \SpecialChar ~
24513 \SpecialChar ~
24514 \SpecialChar ~
24515 \SpecialChar ~
24516 \SpecialChar ~
24517 \SpecialChar ~
24518 \SpecialChar ~
24519 \SpecialChar ~
24520 \SpecialChar ~
24521 \SpecialChar ~
24522 \SpecialChar ~
24523 \SpecialChar ~
24524 \SpecialChar ~
24525 \SpecialChar ~
24526 \SpecialChar ~
24527 \SpecialChar ~
24528 \SpecialChar ~
24529 \SpecialChar ~
24530 \SpecialChar ~
24531 \SpecialChar ~
24532 \SpecialChar ~
24533 \SpecialChar ~
24534 \SpecialChar ~
24535 \SpecialChar ~
24536 switch (i) { 
24537 \newline 
24538 \SpecialChar ~
24539 \SpecialChar ~
24540 \SpecialChar ~
24541 case 4: ...\SpecialChar ~
24542 \SpecialChar ~
24543 \SpecialChar ~
24544 \SpecialChar ~
24545 \SpecialChar ~
24546 \SpecialChar ~
24547 \SpecialChar ~
24548 \SpecialChar ~
24549 \SpecialChar ~
24550 \SpecialChar ~
24551 \SpecialChar ~
24552 \SpecialChar ~
24553 \SpecialChar ~
24554 \SpecialChar ~
24555 \SpecialChar ~
24556 \SpecialChar ~
24557 \SpecialChar ~
24558 \SpecialChar ~
24559 \SpecialChar ~
24560 \SpecialChar ~
24561 \SpecialChar ~
24562 \SpecialChar ~
24563 \SpecialChar ~
24564 \SpecialChar ~
24565 \SpecialChar ~
24566 \SpecialChar ~
24567 case 0: ...
24568  
24569 \newline 
24570 \SpecialChar ~
24571 \SpecialChar ~
24572 \SpecialChar ~
24573 case 5: ...\SpecialChar ~
24574 \SpecialChar ~
24575 \SpecialChar ~
24576 \SpecialChar ~
24577 \SpecialChar ~
24578 \SpecialChar ~
24579 \SpecialChar ~
24580 \SpecialChar ~
24581 \SpecialChar ~
24582 \SpecialChar ~
24583 \SpecialChar ~
24584 \SpecialChar ~
24585 \SpecialChar ~
24586 \SpecialChar ~
24587 \SpecialChar ~
24588 \SpecialChar ~
24589 \SpecialChar ~
24590 \SpecialChar ~
24591 \SpecialChar ~
24592 \SpecialChar ~
24593 \SpecialChar ~
24594 \SpecialChar ~
24595 \SpecialChar ~
24596 \SpecialChar ~
24597 \SpecialChar ~
24598 \SpecialChar ~
24599 case 1: ...
24600  
24601 \newline 
24602 \SpecialChar ~
24603 \SpecialChar ~
24604 \SpecialChar ~
24605 case 3: ...\SpecialChar ~
24606 \SpecialChar ~
24607 \SpecialChar ~
24608 \SpecialChar ~
24609 \SpecialChar ~
24610 \SpecialChar ~
24611 \SpecialChar ~
24612 \SpecialChar ~
24613 \SpecialChar ~
24614 \SpecialChar ~
24615 \SpecialChar ~
24616 \SpecialChar ~
24617 \SpecialChar ~
24618 \SpecialChar ~
24619 \SpecialChar ~
24620 \SpecialChar ~
24621 \SpecialChar ~
24622 \SpecialChar ~
24623 \SpecialChar ~
24624 \SpecialChar ~
24625 \SpecialChar ~
24626 \SpecialChar ~
24627 \SpecialChar ~
24628 \SpecialChar ~
24629 \SpecialChar ~
24630 \SpecialChar ~
24631
24632 \newline 
24633 \SpecialChar ~
24634 \SpecialChar ~
24635 \SpecialChar ~
24636 case 6: ...\SpecialChar ~
24637 \SpecialChar ~
24638 \SpecialChar ~
24639 \SpecialChar ~
24640 \SpecialChar ~
24641 \SpecialChar ~
24642 \SpecialChar ~
24643 \SpecialChar ~
24644 \SpecialChar ~
24645 \SpecialChar ~
24646 \SpecialChar ~
24647 \SpecialChar ~
24648 \SpecialChar ~
24649 \SpecialChar ~
24650 \SpecialChar ~
24651 \SpecialChar ~
24652 \SpecialChar ~
24653 \SpecialChar ~
24654 \SpecialChar ~
24655 \SpecialChar ~
24656 \SpecialChar ~
24657 \SpecialChar ~
24658 \SpecialChar ~
24659 \SpecialChar ~
24660 \SpecialChar ~
24661 \SpecialChar ~
24662 case 3: ...
24663  
24664 \newline 
24665 \SpecialChar ~
24666 \SpecialChar ~
24667 \SpecialChar ~
24668 case 7: ...\SpecialChar ~
24669 \SpecialChar ~
24670 \SpecialChar ~
24671 \SpecialChar ~
24672 \SpecialChar ~
24673 \SpecialChar ~
24674 \SpecialChar ~
24675 \SpecialChar ~
24676 \SpecialChar ~
24677 \SpecialChar ~
24678 \SpecialChar ~
24679 \SpecialChar ~
24680 \SpecialChar ~
24681 \SpecialChar ~
24682 \SpecialChar ~
24683 \SpecialChar ~
24684 \SpecialChar ~
24685 \SpecialChar ~
24686 \SpecialChar ~
24687 \SpecialChar ~
24688 \SpecialChar ~
24689 \SpecialChar ~
24690 \SpecialChar ~
24691 \SpecialChar ~
24692 \SpecialChar ~
24693 \SpecialChar ~
24694 case 4: ...
24695  
24696 \newline 
24697 \SpecialChar ~
24698 \SpecialChar ~
24699 \SpecialChar ~
24700 case 8: ...\SpecialChar ~
24701 \SpecialChar ~
24702 \SpecialChar ~
24703 \SpecialChar ~
24704 \SpecialChar ~
24705 \SpecialChar ~
24706 \SpecialChar ~
24707 \SpecialChar ~
24708 \SpecialChar ~
24709 \SpecialChar ~
24710 \SpecialChar ~
24711 \SpecialChar ~
24712 \SpecialChar ~
24713 \SpecialChar ~
24714 \SpecialChar ~
24715 \SpecialChar ~
24716 \SpecialChar ~
24717 \SpecialChar ~
24718 \SpecialChar ~
24719 \SpecialChar ~
24720 \SpecialChar ~
24721 \SpecialChar ~
24722 \SpecialChar ~
24723 \SpecialChar ~
24724 \SpecialChar ~
24725 \SpecialChar ~
24726 case 5: ...
24727  
24728 \newline 
24729 \SpecialChar ~
24730 \SpecialChar ~
24731 \SpecialChar ~
24732 case 9: ...\SpecialChar ~
24733 \SpecialChar ~
24734 \SpecialChar ~
24735 \SpecialChar ~
24736 \SpecialChar ~
24737 \SpecialChar ~
24738 \SpecialChar ~
24739 \SpecialChar ~
24740 \SpecialChar ~
24741 \SpecialChar ~
24742 \SpecialChar ~
24743 \SpecialChar ~
24744 \SpecialChar ~
24745 \SpecialChar ~
24746 \SpecialChar ~
24747 \SpecialChar ~
24748 \SpecialChar ~
24749 \SpecialChar ~
24750 \SpecialChar ~
24751 \SpecialChar ~
24752 \SpecialChar ~
24753 \SpecialChar ~
24754 \SpecialChar ~
24755 \SpecialChar ~
24756 \SpecialChar ~
24757 \SpecialChar ~
24758 case 6: ...
24759  
24760 \newline 
24761 \SpecialChar ~
24762 \SpecialChar ~
24763 \SpecialChar ~
24764 case 10: ...\SpecialChar ~
24765 \SpecialChar ~
24766 \SpecialChar ~
24767 \SpecialChar ~
24768 \SpecialChar ~
24769 \SpecialChar ~
24770 \SpecialChar ~
24771 \SpecialChar ~
24772 \SpecialChar ~
24773 \SpecialChar ~
24774 \SpecialChar ~
24775 \SpecialChar ~
24776 \SpecialChar ~
24777 \SpecialChar ~
24778 \SpecialChar ~
24779 \SpecialChar ~
24780 \SpecialChar ~
24781 \SpecialChar ~
24782 \SpecialChar ~
24783 \SpecialChar ~
24784 \SpecialChar ~
24785 \SpecialChar ~
24786 \SpecialChar ~
24787 \SpecialChar ~
24788 \SpecialChar ~
24789 case 7: ...
24790  
24791 \newline 
24792 \SpecialChar ~
24793 \SpecialChar ~
24794 \SpecialChar ~
24795 case 11: ...\SpecialChar ~
24796 \SpecialChar ~
24797 \SpecialChar ~
24798 \SpecialChar ~
24799 \SpecialChar ~
24800 \SpecialChar ~
24801 \SpecialChar ~
24802 \SpecialChar ~
24803 \SpecialChar ~
24804 \SpecialChar ~
24805 \SpecialChar ~
24806 \SpecialChar ~
24807 \SpecialChar ~
24808 \SpecialChar ~
24809 \SpecialChar ~
24810 \SpecialChar ~
24811 \SpecialChar ~
24812 \SpecialChar ~
24813 \SpecialChar ~
24814 \SpecialChar ~
24815 \SpecialChar ~
24816 \SpecialChar ~
24817 \SpecialChar ~
24818 \SpecialChar ~
24819 \SpecialChar ~
24820 case 8: ...
24821  
24822 \newline 
24823 }\SpecialChar ~
24824 \SpecialChar ~
24825 \SpecialChar ~
24826 \SpecialChar ~
24827 \SpecialChar ~
24828 \SpecialChar ~
24829 \SpecialChar ~
24830 \SpecialChar ~
24831 \SpecialChar ~
24832 \SpecialChar ~
24833 \SpecialChar ~
24834 \SpecialChar ~
24835 \SpecialChar ~
24836 \SpecialChar ~
24837 \SpecialChar ~
24838 \SpecialChar ~
24839 \SpecialChar ~
24840 \SpecialChar ~
24841 \SpecialChar ~
24842 \SpecialChar ~
24843 \SpecialChar ~
24844 \SpecialChar ~
24845 \SpecialChar ~
24846 \SpecialChar ~
24847 \SpecialChar ~
24848 \SpecialChar ~
24849 \SpecialChar ~
24850 \SpecialChar ~
24851 \SpecialChar ~
24852 \SpecialChar ~
24853 \SpecialChar ~
24854 \SpecialChar ~
24855 \SpecialChar ~
24856 \SpecialChar ~
24857 \SpecialChar ~
24858 \SpecialChar ~
24859 }
24860 \layout Standard
24861
24862 Both the above switch statements will be implemented using a jump-table.
24863  The example to the right side is slightly more efficient as the check for
24864  the lower boundary of the jump-table is not needed.
24865 \end_deeper 
24866 \layout Itemize
24867
24868 The number of case labels is not larger than supported by the target architectur
24869 e.
24870 \layout Itemize
24871
24872 If the case labels are not in numerical sequence ('gaps' between cases)
24873  SDCC checks whether a jump table with additionally inserted dummy cases
24874  is still attractive.
24875  
24876 \layout Itemize
24877
24878 If the starting number is not zero and a check for the lower boundary of
24879  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
24880  ...
24881  .
24882 \layout Standard
24883
24884 Switch statements which have large gaps in the numeric sequence or those
24885  that have too many case labels can be split into more than one switch statement
24886  for efficient code generation, e.g.:
24887 \layout Verse
24888
24889
24890 \family typewriter 
24891 switch (i) { 
24892 \newline 
24893 \SpecialChar ~
24894 \SpecialChar ~
24895 case 1: ...
24896  
24897 \newline 
24898 \SpecialChar ~
24899 \SpecialChar ~
24900 case 2: ...
24901  
24902 \newline 
24903 \SpecialChar ~
24904 \SpecialChar ~
24905 case 3: ...
24906  
24907 \newline 
24908 \SpecialChar ~
24909 \SpecialChar ~
24910 case 4: ...
24911  
24912 \newline 
24913 \SpecialChar ~
24914 \SpecialChar ~
24915 case 5: ...
24916  
24917 \newline 
24918 \SpecialChar ~
24919 \SpecialChar ~
24920 case 6: ...
24921  
24922 \newline 
24923 \SpecialChar ~
24924 \SpecialChar ~
24925 case 7: ...
24926  
24927 \newline 
24928 \SpecialChar ~
24929 \SpecialChar ~
24930 case 101: ...
24931  
24932 \newline 
24933 \SpecialChar ~
24934 \SpecialChar ~
24935 case 102: ...
24936  
24937 \newline 
24938 \SpecialChar ~
24939 \SpecialChar ~
24940 case 103: ...
24941  
24942 \newline 
24943 \SpecialChar ~
24944 \SpecialChar ~
24945 case 104: ...
24946  
24947 \newline 
24948 \SpecialChar ~
24949 \SpecialChar ~
24950 case 105: ...
24951  
24952 \newline 
24953 \SpecialChar ~
24954 \SpecialChar ~
24955 case 106: ...
24956  
24957 \newline 
24958 \SpecialChar ~
24959 \SpecialChar ~
24960 case 107: ...
24961  
24962 \newline 
24963 }
24964 \layout Standard
24965
24966 If the above switch statement is broken down into two switch statements
24967 \layout Verse
24968
24969
24970 \family typewriter 
24971 switch (i) { 
24972 \newline 
24973 \SpecialChar ~
24974 \SpecialChar ~
24975 case 1: ...
24976  
24977 \newline 
24978 \SpecialChar ~
24979 \SpecialChar ~
24980 case 2: ...
24981  
24982 \newline 
24983 \SpecialChar ~
24984 \SpecialChar ~
24985 case 3: ...
24986  
24987 \newline 
24988 \SpecialChar ~
24989 \SpecialChar ~
24990 case 4: ...
24991  
24992 \newline 
24993 \SpecialChar ~
24994 \SpecialChar ~
24995 case 5: ...
24996  
24997 \newline 
24998 \SpecialChar ~
24999 \SpecialChar ~
25000 case 6: ...
25001  
25002 \newline 
25003 \SpecialChar ~
25004 \SpecialChar ~
25005 case 7: ...
25006  
25007 \newline 
25008 }
25009 \layout Standard
25010
25011 and
25012 \layout Verse
25013
25014
25015 \family typewriter 
25016 switch (i) { 
25017 \newline 
25018 \SpecialChar ~
25019 \SpecialChar ~
25020 case 101: ...
25021  
25022 \newline 
25023 \SpecialChar ~
25024 \SpecialChar ~
25025 case 102: ...
25026  
25027 \newline 
25028 \SpecialChar ~
25029 \SpecialChar ~
25030 case 103: ...
25031  
25032 \newline 
25033 \SpecialChar ~
25034 \SpecialChar ~
25035 case 104: ...
25036  
25037 \newline 
25038 \SpecialChar ~
25039 \SpecialChar ~
25040 case 105: ...
25041  
25042 \newline 
25043 \SpecialChar ~
25044 \SpecialChar ~
25045 case 106: ...
25046  
25047 \newline 
25048 \SpecialChar ~
25049 \SpecialChar ~
25050 case 107: ...
25051  
25052 \newline 
25053 }
25054 \layout Standard
25055
25056 then both the switch statements will be implemented using jump-tables whereas
25057  the unmodified switch statement will not be.
25058 \layout Comment
25059
25060 There might be reasons which SDCC cannot know about to either favour or
25061  not favour jump tables.
25062  If the target system has to be as quick for the last switch case as for
25063  the first (pro jump table), or if the switch argument is known to be zero
25064  in the majority of the cases (contra jump table).
25065 \layout Standard
25066
25067 The pragma nojtbound
25068 \begin_inset LatexCommand \index{\#pragma nojtbound}
25069
25070 \end_inset 
25071
25072  can be used to turn off checking the 
25073 \emph on 
25074 j
25075 \emph default 
25076 ump 
25077 \emph on 
25078 t
25079 \emph default 
25080 able 
25081 \emph on 
25082 bound
25083 \emph default 
25084 aries.
25085  It has no effect if a default label is supplied.
25086  Use of this pragma is dangerous: if the switch
25087 \begin_inset LatexCommand \index{switch statement}
25088
25089 \end_inset 
25090
25091  argument is not matched by a case statement the processor will happily
25092  jump into Nirvana.
25093 \layout Subsection
25094
25095 Bit-shifting Operations
25096 \begin_inset LatexCommand \index{Bit shifting}
25097
25098 \end_inset 
25099
25100 .
25101 \layout Standard
25102
25103 Bit shifting is one of the most frequently used operation in embedded programmin
25104 g.
25105  SDCC tries to implement bit-shift operations in the most efficient way
25106  possible, e.g.:
25107 \layout Verse
25108
25109
25110 \family typewriter 
25111 unsigned char i;
25112 \newline 
25113 ...
25114  
25115 \newline 
25116 i >>= 4; 
25117 \newline 
25118 ...
25119 \layout Standard
25120
25121 generates the following code:
25122 \layout Verse
25123
25124
25125 \family typewriter 
25126 mov\SpecialChar ~
25127  a,_i 
25128 \newline 
25129 swap a 
25130 \newline 
25131 anl\SpecialChar ~
25132  a,#0x0f 
25133 \newline 
25134 mov\SpecialChar ~
25135  _i,a
25136 \layout Standard
25137
25138 In general SDCC will never setup a loop if the shift count is known.
25139  Another example:
25140 \layout Verse
25141
25142
25143 \family typewriter 
25144 unsigned int i; 
25145 \newline 
25146 ...
25147  
25148 \newline 
25149 i >>= 9; 
25150 \newline 
25151 ...
25152 \layout Standard
25153
25154 will generate:
25155 \layout Verse
25156
25157
25158 \family typewriter 
25159 mov\SpecialChar ~
25160 \SpecialChar ~
25161 a,(_i + 1) 
25162 \newline 
25163 mov\SpecialChar ~
25164 \SpecialChar ~
25165 (_i + 1),#0x00 
25166 \newline 
25167 clr\SpecialChar ~
25168 \SpecialChar ~
25169
25170 \newline 
25171 rrc\SpecialChar ~
25172 \SpecialChar ~
25173
25174 \newline 
25175 mov\SpecialChar ~
25176 \SpecialChar ~
25177 _i,a
25178 \layout Subsection
25179
25180 Bit-rotation
25181 \begin_inset LatexCommand \index{Bit rotation}
25182
25183 \end_inset 
25184
25185
25186 \layout Standard
25187
25188 A special case of the bit-shift operation is bit rotation
25189 \begin_inset LatexCommand \index{rotating bits}
25190
25191 \end_inset 
25192
25193 , SDCC recognizes the following expression to be a left bit-rotation:
25194 \layout Verse
25195
25196
25197 \family typewriter 
25198 \series bold 
25199 unsigned
25200 \series default 
25201 \SpecialChar ~
25202 \SpecialChar ~
25203 char i;\SpecialChar ~
25204 \SpecialChar ~
25205 \SpecialChar ~
25206 \SpecialChar ~
25207 \SpecialChar ~
25208 \SpecialChar ~
25209 \SpecialChar ~
25210 \SpecialChar ~
25211 \SpecialChar ~
25212 \SpecialChar ~
25213 \SpecialChar ~
25214 /* unsigned is needed for rotation */ 
25215 \newline 
25216 ...
25217  
25218 \newline 
25219 i = ((i << 1) | (i >> 7)); 
25220 \family default 
25221
25222 \newline 
25223
25224 \family typewriter 
25225 ...
25226 \layout Standard
25227
25228 will generate the following code:
25229 \layout Verse
25230
25231
25232 \family typewriter 
25233 mov\SpecialChar ~
25234 \SpecialChar ~
25235 a,_i 
25236 \newline 
25237 rl\SpecialChar ~
25238 \SpecialChar ~
25239 \SpecialChar ~
25240
25241 \newline 
25242 mov\SpecialChar ~
25243 \SpecialChar ~
25244 _i,a
25245 \layout Standard
25246
25247 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
25248 ns of this case will also be recognized as bit-rotation, i.e.: 
25249 \layout Verse
25250
25251
25252 \family typewriter 
25253 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
25254 \layout Subsection
25255
25256 Nibble and Byte Swapping
25257 \layout Standard
25258
25259 Other special cases of the bit-shift operations are nibble or byte swapping
25260 \begin_inset LatexCommand \index{swapping nibbles/bytes}
25261
25262 \end_inset 
25263
25264 , SDCC recognizes the following expressions:
25265 \layout Verse
25266
25267
25268 \family typewriter 
25269 \series bold 
25270 unsigned
25271 \series default 
25272 \SpecialChar ~
25273 \SpecialChar ~
25274 char i; 
25275 \newline 
25276
25277 \series bold 
25278 unsigned
25279 \series default 
25280 \SpecialChar ~
25281 \SpecialChar ~
25282 int j; 
25283 \newline 
25284 ...
25285  
25286 \newline 
25287 i = ((i << 4) | (i >> 4)); 
25288 \family default 
25289
25290 \newline 
25291
25292 \family typewriter 
25293 j = ((j << 8) | (j >> 8)); 
25294 \layout Standard
25295
25296 and generates a swap instruction for the nibble swapping
25297 \begin_inset LatexCommand \index{Nibble swapping}
25298
25299 \end_inset 
25300
25301  or move instructions for the byte swapping
25302 \begin_inset LatexCommand \index{Byte swapping}
25303
25304 \end_inset 
25305
25306 .
25307  The 
25308 \begin_inset Quotes sld
25309 \end_inset 
25310
25311 j
25312 \begin_inset Quotes srd
25313 \end_inset 
25314
25315  example can be used to convert from little to big-endian or vice versa.
25316  If you want to change the endianness of a 
25317 \emph on 
25318 signed
25319 \emph default 
25320  integer you have to cast to 
25321 \family typewriter 
25322 (unsigned int)
25323 \family default 
25324  first.
25325 \layout Standard
25326
25327 Note that SDCC stores numbers in little-endian
25328 \begin_inset Foot
25329 collapsed false
25330
25331 \layout Standard
25332
25333 Usually 8-bit processors don't care much about endianness.
25334  This is not the case for the standard 8051 which only has an instruction
25335  to increment its 
25336 \emph on 
25337 dptr
25338 \emph default 
25339
25340 \begin_inset LatexCommand \index{DPTR}
25341
25342 \end_inset 
25343
25344 -datapointer
25345 \emph on 
25346  
25347 \emph default 
25348 so little-endian is the more efficient byte order.
25349 \end_inset 
25350
25351
25352 \begin_inset LatexCommand \index{little-endian}
25353
25354 \end_inset 
25355
25356
25357 \begin_inset LatexCommand \index{Endianness}
25358
25359 \end_inset 
25360
25361  format (i.e.
25362  lowest order first).
25363 \layout Subsection
25364
25365 Highest Order Bit
25366 \begin_inset LatexCommand \index{Highest Order Bit}
25367
25368 \end_inset 
25369
25370  / Any Order Bit
25371 \begin_inset LatexCommand \index{Any Order Bit}
25372
25373 \end_inset 
25374
25375
25376 \layout Standard
25377
25378 It is frequently required to obtain the highest order bit of an integral
25379  type (long, int, short or char types).
25380  Also obtaining any other order bit is not uncommon.
25381  SDCC recognizes the following expressions to yield the highest order bit
25382  and generates optimized code for it, e.g.:
25383 \layout Verse
25384
25385
25386 \family typewriter 
25387 unsigned int gint; 
25388 \newline 
25389
25390 \newline 
25391 foo () { 
25392 \newline 
25393 \SpecialChar ~
25394 \SpecialChar ~
25395 unsigned char hob1, aob1; 
25396 \newline 
25397 \SpecialChar ~
25398 \SpecialChar ~
25399 bit hob2, hob3, aob2, aob3; 
25400 \newline 
25401 \SpecialChar ~
25402 \SpecialChar ~
25403 ...
25404  
25405 \newline 
25406 \SpecialChar ~
25407 \SpecialChar ~
25408 hob1 = (gint >> 15) & 1; 
25409 \newline 
25410 \SpecialChar ~
25411 \SpecialChar ~
25412 hob2 = (gint >> 15) & 1; 
25413 \newline 
25414 \SpecialChar ~
25415 \SpecialChar ~
25416 hob3 = gint & 0x8000; 
25417 \newline 
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 aob1 = (gint >> 9) & 1; 
25421 \newline 
25422 \SpecialChar ~
25423 \SpecialChar ~
25424 aob2 = (gint >> 8) & 1; 
25425 \newline 
25426 \SpecialChar ~
25427 \SpecialChar ~
25428 aob3 = gint & 0x0800; 
25429 \newline 
25430 \SpecialChar ~
25431 \SpecialChar ~
25432 ..
25433  
25434 \newline 
25435 }
25436 \layout Standard
25437
25438 will generate the following code:
25439 \layout Verse
25440
25441
25442 \family typewriter 
25443 \SpecialChar ~
25444 \SpecialChar ~
25445 \SpecialChar ~
25446 \SpecialChar ~
25447 \SpecialChar ~
25448 \SpecialChar ~
25449 \SpecialChar ~
25450 \SpecialChar ~
25451 \SpecialChar ~
25452 \SpecialChar ~
25453 \SpecialChar ~
25454 \SpecialChar ~
25455 \SpecialChar ~
25456 \SpecialChar ~
25457 \SpecialChar ~
25458 \SpecialChar ~
25459 \SpecialChar ~
25460 \SpecialChar ~
25461 \SpecialChar ~
25462 \SpecialChar ~
25463 \SpecialChar ~
25464 \SpecialChar ~
25465 \SpecialChar ~
25466 \SpecialChar ~
25467 \SpecialChar ~
25468  61 ;\SpecialChar ~
25469  hob.c 7 
25470 \newline 
25471 000A E5*01\SpecialChar ~
25472 \SpecialChar ~
25473 \SpecialChar ~
25474 \SpecialChar ~
25475 \SpecialChar ~
25476 \SpecialChar ~
25477 \SpecialChar ~
25478 \SpecialChar ~
25479 \SpecialChar ~
25480 \SpecialChar ~
25481 \SpecialChar ~
25482 \SpecialChar ~
25483 \SpecialChar ~
25484 \SpecialChar ~
25485 \SpecialChar ~
25486  62\SpecialChar ~
25487 \SpecialChar ~
25488 \SpecialChar ~
25489 \SpecialChar ~
25490 \SpecialChar ~
25491 \SpecialChar ~
25492 \SpecialChar ~
25493 \SpecialChar ~
25494  mov\SpecialChar ~
25495 \SpecialChar ~
25496  a,(_gint + 1) 
25497 \newline 
25498 000C 23\SpecialChar ~
25499 \SpecialChar ~
25500 \SpecialChar ~
25501 \SpecialChar ~
25502 \SpecialChar ~
25503 \SpecialChar ~
25504 \SpecialChar ~
25505 \SpecialChar ~
25506 \SpecialChar ~
25507 \SpecialChar ~
25508 \SpecialChar ~
25509 \SpecialChar ~
25510 \SpecialChar ~
25511 \SpecialChar ~
25512 \SpecialChar ~
25513 \SpecialChar ~
25514 \SpecialChar ~
25515 \SpecialChar ~
25516  63\SpecialChar ~
25517 \SpecialChar ~
25518 \SpecialChar ~
25519 \SpecialChar ~
25520 \SpecialChar ~
25521 \SpecialChar ~
25522 \SpecialChar ~
25523 \SpecialChar ~
25524  rl\SpecialChar ~
25525 \SpecialChar ~
25526 \SpecialChar ~
25527  a 
25528 \newline 
25529 000D 54 01\SpecialChar ~
25530 \SpecialChar ~
25531 \SpecialChar ~
25532 \SpecialChar ~
25533 \SpecialChar ~
25534 \SpecialChar ~
25535 \SpecialChar ~
25536 \SpecialChar ~
25537 \SpecialChar ~
25538 \SpecialChar ~
25539 \SpecialChar ~
25540 \SpecialChar ~
25541 \SpecialChar ~
25542 \SpecialChar ~
25543 \SpecialChar ~
25544  64\SpecialChar ~
25545 \SpecialChar ~
25546 \SpecialChar ~
25547 \SpecialChar ~
25548 \SpecialChar ~
25549 \SpecialChar ~
25550 \SpecialChar ~
25551 \SpecialChar ~
25552  anl\SpecialChar ~
25553 \SpecialChar ~
25554  a,#0x01 
25555 \newline 
25556 000F F5*02\SpecialChar ~
25557 \SpecialChar ~
25558 \SpecialChar ~
25559 \SpecialChar ~
25560 \SpecialChar ~
25561 \SpecialChar ~
25562 \SpecialChar ~
25563 \SpecialChar ~
25564 \SpecialChar ~
25565 \SpecialChar ~
25566 \SpecialChar ~
25567 \SpecialChar ~
25568 \SpecialChar ~
25569 \SpecialChar ~
25570 \SpecialChar ~
25571  65\SpecialChar ~
25572 \SpecialChar ~
25573 \SpecialChar ~
25574 \SpecialChar ~
25575 \SpecialChar ~
25576 \SpecialChar ~
25577 \SpecialChar ~
25578 \SpecialChar ~
25579  mov\SpecialChar ~
25580 \SpecialChar ~
25581  _foo_hob1_1_1,a 
25582 \newline 
25583 \SpecialChar ~
25584 \SpecialChar ~
25585 \SpecialChar ~
25586 \SpecialChar ~
25587 \SpecialChar ~
25588 \SpecialChar ~
25589 \SpecialChar ~
25590 \SpecialChar ~
25591 \SpecialChar ~
25592 \SpecialChar ~
25593 \SpecialChar ~
25594 \SpecialChar ~
25595 \SpecialChar ~
25596 \SpecialChar ~
25597 \SpecialChar ~
25598 \SpecialChar ~
25599 \SpecialChar ~
25600 \SpecialChar ~
25601 \SpecialChar ~
25602 \SpecialChar ~
25603 \SpecialChar ~
25604 \SpecialChar ~
25605 \SpecialChar ~
25606 \SpecialChar ~
25607 \SpecialChar ~
25608  66 ;\SpecialChar ~
25609  hob.c 8 
25610 \newline 
25611 0011 E5*01\SpecialChar ~
25612 \SpecialChar ~
25613 \SpecialChar ~
25614 \SpecialChar ~
25615 \SpecialChar ~
25616 \SpecialChar ~
25617 \SpecialChar ~
25618 \SpecialChar ~
25619 \SpecialChar ~
25620 \SpecialChar ~
25621 \SpecialChar ~
25622 \SpecialChar ~
25623 \SpecialChar ~
25624 \SpecialChar ~
25625 \SpecialChar ~
25626  67\SpecialChar ~
25627 \SpecialChar ~
25628 \SpecialChar ~
25629 \SpecialChar ~
25630 \SpecialChar ~
25631 \SpecialChar ~
25632 \SpecialChar ~
25633 \SpecialChar ~
25634  mov\SpecialChar ~
25635 \SpecialChar ~
25636  a,(_gint + 1) 
25637 \newline 
25638 0013 33\SpecialChar ~
25639 \SpecialChar ~
25640 \SpecialChar ~
25641 \SpecialChar ~
25642 \SpecialChar ~
25643 \SpecialChar ~
25644 \SpecialChar ~
25645 \SpecialChar ~
25646 \SpecialChar ~
25647 \SpecialChar ~
25648 \SpecialChar ~
25649 \SpecialChar ~
25650 \SpecialChar ~
25651 \SpecialChar ~
25652 \SpecialChar ~
25653 \SpecialChar ~
25654 \SpecialChar ~
25655 \SpecialChar ~
25656  68\SpecialChar ~
25657 \SpecialChar ~
25658 \SpecialChar ~
25659 \SpecialChar ~
25660 \SpecialChar ~
25661 \SpecialChar ~
25662 \SpecialChar ~
25663 \SpecialChar ~
25664  rlc\SpecialChar ~
25665 \SpecialChar ~
25666  a 
25667 \newline 
25668 0014 92*00\SpecialChar ~
25669 \SpecialChar ~
25670 \SpecialChar ~
25671 \SpecialChar ~
25672 \SpecialChar ~
25673 \SpecialChar ~
25674 \SpecialChar ~
25675 \SpecialChar ~
25676 \SpecialChar ~
25677 \SpecialChar ~
25678 \SpecialChar ~
25679 \SpecialChar ~
25680 \SpecialChar ~
25681 \SpecialChar ~
25682 \SpecialChar ~
25683  69\SpecialChar ~
25684 \SpecialChar ~
25685 \SpecialChar ~
25686 \SpecialChar ~
25687 \SpecialChar ~
25688 \SpecialChar ~
25689 \SpecialChar ~
25690 \SpecialChar ~
25691  mov\SpecialChar ~
25692 \SpecialChar ~
25693  _foo_hob2_1_1,c 
25694 \newline 
25695 \SpecialChar ~
25696 \SpecialChar ~
25697 \SpecialChar ~
25698 \SpecialChar ~
25699 \SpecialChar ~
25700 \SpecialChar ~
25701 \SpecialChar ~
25702 \SpecialChar ~
25703 \SpecialChar ~
25704 \SpecialChar ~
25705 \SpecialChar ~
25706 \SpecialChar ~
25707 \SpecialChar ~
25708 \SpecialChar ~
25709 \SpecialChar ~
25710 \SpecialChar ~
25711 \SpecialChar ~
25712 \SpecialChar ~
25713 \SpecialChar ~
25714 \SpecialChar ~
25715 \SpecialChar ~
25716 \SpecialChar ~
25717 \SpecialChar ~
25718 \SpecialChar ~
25719 \SpecialChar ~
25720  66 ;\SpecialChar ~
25721  hob.c 9 
25722 \newline 
25723 0016 E5*01\SpecialChar ~
25724 \SpecialChar ~
25725 \SpecialChar ~
25726 \SpecialChar ~
25727 \SpecialChar ~
25728 \SpecialChar ~
25729 \SpecialChar ~
25730 \SpecialChar ~
25731 \SpecialChar ~
25732 \SpecialChar ~
25733 \SpecialChar ~
25734 \SpecialChar ~
25735 \SpecialChar ~
25736 \SpecialChar ~
25737 \SpecialChar ~
25738  67\SpecialChar ~
25739 \SpecialChar ~
25740 \SpecialChar ~
25741 \SpecialChar ~
25742 \SpecialChar ~
25743 \SpecialChar ~
25744 \SpecialChar ~
25745 \SpecialChar ~
25746  mov\SpecialChar ~
25747 \SpecialChar ~
25748  a,(_gint + 1) 
25749 \newline 
25750 0018 33\SpecialChar ~
25751 \SpecialChar ~
25752 \SpecialChar ~
25753 \SpecialChar ~
25754 \SpecialChar ~
25755 \SpecialChar ~
25756 \SpecialChar ~
25757 \SpecialChar ~
25758 \SpecialChar ~
25759 \SpecialChar ~
25760 \SpecialChar ~
25761 \SpecialChar ~
25762 \SpecialChar ~
25763 \SpecialChar ~
25764 \SpecialChar ~
25765 \SpecialChar ~
25766 \SpecialChar ~
25767 \SpecialChar ~
25768  68\SpecialChar ~
25769 \SpecialChar ~
25770 \SpecialChar ~
25771 \SpecialChar ~
25772 \SpecialChar ~
25773 \SpecialChar ~
25774 \SpecialChar ~
25775 \SpecialChar ~
25776  rlc\SpecialChar ~
25777 \SpecialChar ~
25778  a 
25779 \newline 
25780 0019 92*01\SpecialChar ~
25781 \SpecialChar ~
25782 \SpecialChar ~
25783 \SpecialChar ~
25784 \SpecialChar ~
25785 \SpecialChar ~
25786 \SpecialChar ~
25787 \SpecialChar ~
25788 \SpecialChar ~
25789 \SpecialChar ~
25790 \SpecialChar ~
25791 \SpecialChar ~
25792 \SpecialChar ~
25793 \SpecialChar ~
25794 \SpecialChar ~
25795  69\SpecialChar ~
25796 \SpecialChar ~
25797 \SpecialChar ~
25798 \SpecialChar ~
25799 \SpecialChar ~
25800 \SpecialChar ~
25801 \SpecialChar ~
25802 \SpecialChar ~
25803  mov\SpecialChar ~
25804 \SpecialChar ~
25805  _foo_hob3_1_1,c 
25806 \newline 
25807 \SpecialChar ~
25808 \SpecialChar ~
25809 \SpecialChar ~
25810 \SpecialChar ~
25811 \SpecialChar ~
25812 \SpecialChar ~
25813 \SpecialChar ~
25814 \SpecialChar ~
25815 \SpecialChar ~
25816 \SpecialChar ~
25817 \SpecialChar ~
25818 \SpecialChar ~
25819 \SpecialChar ~
25820 \SpecialChar ~
25821 \SpecialChar ~
25822 \SpecialChar ~
25823 \SpecialChar ~
25824 \SpecialChar ~
25825 \SpecialChar ~
25826 \SpecialChar ~
25827 \SpecialChar ~
25828 \SpecialChar ~
25829 \SpecialChar ~
25830 \SpecialChar ~
25831 \SpecialChar ~
25832  70 ;\SpecialChar ~
25833  hob.c 10 
25834 \newline 
25835 001B E5*01\SpecialChar ~
25836 \SpecialChar ~
25837 \SpecialChar ~
25838 \SpecialChar ~
25839 \SpecialChar ~
25840 \SpecialChar ~
25841 \SpecialChar ~
25842 \SpecialChar ~
25843 \SpecialChar ~
25844 \SpecialChar ~
25845 \SpecialChar ~
25846 \SpecialChar ~
25847 \SpecialChar ~
25848 \SpecialChar ~
25849 \SpecialChar ~
25850  71\SpecialChar ~
25851 \SpecialChar ~
25852 \SpecialChar ~
25853 \SpecialChar ~
25854 \SpecialChar ~
25855 \SpecialChar ~
25856 \SpecialChar ~
25857 \SpecialChar ~
25858  mov\SpecialChar ~
25859 \SpecialChar ~
25860  a,(_gint + 1) 
25861 \newline 
25862 001D 03\SpecialChar ~
25863 \SpecialChar ~
25864 \SpecialChar ~
25865 \SpecialChar ~
25866 \SpecialChar ~
25867 \SpecialChar ~
25868 \SpecialChar ~
25869 \SpecialChar ~
25870 \SpecialChar ~
25871 \SpecialChar ~
25872 \SpecialChar ~
25873 \SpecialChar ~
25874 \SpecialChar ~
25875 \SpecialChar ~
25876 \SpecialChar ~
25877 \SpecialChar ~
25878 \SpecialChar ~
25879 \SpecialChar ~
25880  72\SpecialChar ~
25881 \SpecialChar ~
25882 \SpecialChar ~
25883 \SpecialChar ~
25884 \SpecialChar ~
25885 \SpecialChar ~
25886 \SpecialChar ~
25887 \SpecialChar ~
25888  rr\SpecialChar ~
25889 \SpecialChar ~
25890 \SpecialChar ~
25891  a 
25892 \newline 
25893 001E 54 01\SpecialChar ~
25894 \SpecialChar ~
25895 \SpecialChar ~
25896 \SpecialChar ~
25897 \SpecialChar ~
25898 \SpecialChar ~
25899 \SpecialChar ~
25900 \SpecialChar ~
25901 \SpecialChar ~
25902 \SpecialChar ~
25903 \SpecialChar ~
25904 \SpecialChar ~
25905 \SpecialChar ~
25906 \SpecialChar ~
25907 \SpecialChar ~
25908  73\SpecialChar ~
25909 \SpecialChar ~
25910 \SpecialChar ~
25911 \SpecialChar ~
25912 \SpecialChar ~
25913 \SpecialChar ~
25914 \SpecialChar ~
25915 \SpecialChar ~
25916  anl\SpecialChar ~
25917 \SpecialChar ~
25918  a,#0x01 
25919 \newline 
25920 0020 F5*03\SpecialChar ~
25921 \SpecialChar ~
25922 \SpecialChar ~
25923 \SpecialChar ~
25924 \SpecialChar ~
25925 \SpecialChar ~
25926 \SpecialChar ~
25927 \SpecialChar ~
25928 \SpecialChar ~
25929 \SpecialChar ~
25930 \SpecialChar ~
25931 \SpecialChar ~
25932 \SpecialChar ~
25933 \SpecialChar ~
25934 \SpecialChar ~
25935  74\SpecialChar ~
25936 \SpecialChar ~
25937 \SpecialChar ~
25938 \SpecialChar ~
25939 \SpecialChar ~
25940 \SpecialChar ~
25941 \SpecialChar ~
25942 \SpecialChar ~
25943  mov\SpecialChar ~
25944 \SpecialChar ~
25945  _foo_aob1_1_1,a 
25946 \newline 
25947 \SpecialChar ~
25948 \SpecialChar ~
25949 \SpecialChar ~
25950 \SpecialChar ~
25951 \SpecialChar ~
25952 \SpecialChar ~
25953 \SpecialChar ~
25954 \SpecialChar ~
25955 \SpecialChar ~
25956 \SpecialChar ~
25957 \SpecialChar ~
25958 \SpecialChar ~
25959 \SpecialChar ~
25960 \SpecialChar ~
25961 \SpecialChar ~
25962 \SpecialChar ~
25963 \SpecialChar ~
25964 \SpecialChar ~
25965 \SpecialChar ~
25966 \SpecialChar ~
25967 \SpecialChar ~
25968 \SpecialChar ~
25969 \SpecialChar ~
25970 \SpecialChar ~
25971 \SpecialChar ~
25972  75 ;\SpecialChar ~
25973  hob.c 11 
25974 \newline 
25975 0022 E5*01\SpecialChar ~
25976 \SpecialChar ~
25977 \SpecialChar ~
25978 \SpecialChar ~
25979 \SpecialChar ~
25980 \SpecialChar ~
25981 \SpecialChar ~
25982 \SpecialChar ~
25983 \SpecialChar ~
25984 \SpecialChar ~
25985 \SpecialChar ~
25986 \SpecialChar ~
25987 \SpecialChar ~
25988 \SpecialChar ~
25989 \SpecialChar ~
25990  76\SpecialChar ~
25991 \SpecialChar ~
25992 \SpecialChar ~
25993 \SpecialChar ~
25994 \SpecialChar ~
25995 \SpecialChar ~
25996 \SpecialChar ~
25997 \SpecialChar ~
25998  mov\SpecialChar ~
25999 \SpecialChar ~
26000  a,(_gint + 1) 
26001 \newline 
26002 0024 13\SpecialChar ~
26003 \SpecialChar ~
26004 \SpecialChar ~
26005 \SpecialChar ~
26006 \SpecialChar ~
26007 \SpecialChar ~
26008 \SpecialChar ~
26009 \SpecialChar ~
26010 \SpecialChar ~
26011 \SpecialChar ~
26012 \SpecialChar ~
26013 \SpecialChar ~
26014 \SpecialChar ~
26015 \SpecialChar ~
26016 \SpecialChar ~
26017 \SpecialChar ~
26018 \SpecialChar ~
26019 \SpecialChar ~
26020  77\SpecialChar ~
26021 \SpecialChar ~
26022 \SpecialChar ~
26023 \SpecialChar ~
26024 \SpecialChar ~
26025 \SpecialChar ~
26026 \SpecialChar ~
26027 \SpecialChar ~
26028  rrc\SpecialChar ~
26029 \SpecialChar ~
26030  a 
26031 \newline 
26032 0025 92*02\SpecialChar ~
26033 \SpecialChar ~
26034 \SpecialChar ~
26035 \SpecialChar ~
26036 \SpecialChar ~
26037 \SpecialChar ~
26038 \SpecialChar ~
26039 \SpecialChar ~
26040 \SpecialChar ~
26041 \SpecialChar ~
26042 \SpecialChar ~
26043 \SpecialChar ~
26044 \SpecialChar ~
26045 \SpecialChar ~
26046 \SpecialChar ~
26047  78\SpecialChar ~
26048 \SpecialChar ~
26049 \SpecialChar ~
26050 \SpecialChar ~
26051 \SpecialChar ~
26052 \SpecialChar ~
26053 \SpecialChar ~
26054 \SpecialChar ~
26055  mov\SpecialChar ~
26056 \SpecialChar ~
26057  _foo_aob2_1_1,c 
26058 \newline 
26059 \SpecialChar ~
26060 \SpecialChar ~
26061 \SpecialChar ~
26062 \SpecialChar ~
26063 \SpecialChar ~
26064 \SpecialChar ~
26065 \SpecialChar ~
26066 \SpecialChar ~
26067 \SpecialChar ~
26068 \SpecialChar ~
26069 \SpecialChar ~
26070 \SpecialChar ~
26071 \SpecialChar ~
26072 \SpecialChar ~
26073 \SpecialChar ~
26074 \SpecialChar ~
26075 \SpecialChar ~
26076 \SpecialChar ~
26077 \SpecialChar ~
26078 \SpecialChar ~
26079 \SpecialChar ~
26080 \SpecialChar ~
26081 \SpecialChar ~
26082 \SpecialChar ~
26083 \SpecialChar ~
26084  79 ;\SpecialChar ~
26085  hob.c 12 
26086 \newline 
26087 0027 E5*01\SpecialChar ~
26088 \SpecialChar ~
26089 \SpecialChar ~
26090 \SpecialChar ~
26091 \SpecialChar ~
26092 \SpecialChar ~
26093 \SpecialChar ~
26094 \SpecialChar ~
26095 \SpecialChar ~
26096 \SpecialChar ~
26097 \SpecialChar ~
26098 \SpecialChar ~
26099 \SpecialChar ~
26100 \SpecialChar ~
26101 \SpecialChar ~
26102  80\SpecialChar ~
26103 \SpecialChar ~
26104 \SpecialChar ~
26105 \SpecialChar ~
26106 \SpecialChar ~
26107 \SpecialChar ~
26108 \SpecialChar ~
26109 \SpecialChar ~
26110  mov\SpecialChar ~
26111 \SpecialChar ~
26112  a,(_gint + 1) 
26113 \newline 
26114 0029 A2 E3\SpecialChar ~
26115 \SpecialChar ~
26116 \SpecialChar ~
26117 \SpecialChar ~
26118 \SpecialChar ~
26119 \SpecialChar ~
26120 \SpecialChar ~
26121 \SpecialChar ~
26122 \SpecialChar ~
26123 \SpecialChar ~
26124 \SpecialChar ~
26125 \SpecialChar ~
26126 \SpecialChar ~
26127 \SpecialChar ~
26128 \SpecialChar ~
26129  81\SpecialChar ~
26130 \SpecialChar ~
26131 \SpecialChar ~
26132 \SpecialChar ~
26133 \SpecialChar ~
26134 \SpecialChar ~
26135 \SpecialChar ~
26136 \SpecialChar ~
26137  mov\SpecialChar ~
26138 \SpecialChar ~
26139  c,acc[3] 
26140 \newline 
26141 002B 92*03\SpecialChar ~
26142 \SpecialChar ~
26143 \SpecialChar ~
26144 \SpecialChar ~
26145 \SpecialChar ~
26146 \SpecialChar ~
26147 \SpecialChar ~
26148 \SpecialChar ~
26149 \SpecialChar ~
26150 \SpecialChar ~
26151 \SpecialChar ~
26152 \SpecialChar ~
26153 \SpecialChar ~
26154 \SpecialChar ~
26155 \SpecialChar ~
26156  82\SpecialChar ~
26157 \SpecialChar ~
26158 \SpecialChar ~
26159 \SpecialChar ~
26160 \SpecialChar ~
26161 \SpecialChar ~
26162 \SpecialChar ~
26163 \SpecialChar ~
26164  mov\SpecialChar ~
26165 \SpecialChar ~
26166  _foo_aob3_1_1,c 
26167 \layout Standard
26168
26169 Other variations of these cases however will 
26170 \emph on 
26171 not
26172 \emph default 
26173  be recognized.
26174  They are standard C expressions, so I heartily recommend these be the only
26175  way to get the highest order bit, (it is portable).
26176  Of course it will be recognized even if it is embedded in other expressions,
26177  e.g.:
26178 \layout Verse
26179
26180
26181 \family typewriter 
26182 xyz = gint + ((gint >> 15) & 1);
26183 \layout Standard
26184
26185 will still be recognized.
26186 \layout Subsection
26187
26188 Higher Order Byte
26189 \begin_inset LatexCommand \index{Higher Order Byte}
26190
26191 \end_inset 
26192
26193  / Higher Order Word
26194 \begin_inset LatexCommand \index{Higher Order Word}
26195
26196 \end_inset 
26197
26198
26199 \layout Standard
26200
26201 It is also frequently required to obtain a higher order byte or word of
26202  a larger integral type (long, int or short types).
26203  SDCC recognizes the following expressions to yield the higher order byte
26204  or word and generates optimized code for it, e.g.:
26205 \layout Verse
26206
26207
26208 \family typewriter 
26209 unsigned int gint; 
26210 \newline 
26211 unsigned long int glong; 
26212 \newline 
26213
26214 \newline 
26215 foo () { 
26216 \newline 
26217 \SpecialChar ~
26218 \SpecialChar ~
26219 unsigned char hob1, hob2; 
26220 \newline 
26221 \SpecialChar ~
26222 \SpecialChar ~
26223 unsigned int how1, how2; 
26224 \newline 
26225 \SpecialChar ~
26226 \SpecialChar ~
26227 ...
26228  
26229 \newline 
26230 \SpecialChar ~
26231 \SpecialChar ~
26232 hob1 = (gint >> 8) & 0xFF; 
26233 \newline 
26234 \SpecialChar ~
26235 \SpecialChar ~
26236 hob2 = glong >> 24; 
26237 \newline 
26238 \SpecialChar ~
26239 \SpecialChar ~
26240 how1 = (glong >> 16) & 0xFFFF; 
26241 \newline 
26242 \SpecialChar ~
26243 \SpecialChar ~
26244 how2 = glong >> 8; 
26245 \newline 
26246 \SpecialChar ~
26247 \SpecialChar ~
26248 ..
26249  
26250 \newline 
26251 }
26252 \layout Standard
26253
26254 will generate the following code:
26255 \layout Verse
26256
26257
26258 \family typewriter 
26259 \SpecialChar ~
26260 \SpecialChar ~
26261 \SpecialChar ~
26262 \SpecialChar ~
26263 \SpecialChar ~
26264 \SpecialChar ~
26265 \SpecialChar ~
26266 \SpecialChar ~
26267 \SpecialChar ~
26268 \SpecialChar ~
26269 \SpecialChar ~
26270 \SpecialChar ~
26271 \SpecialChar ~
26272 \SpecialChar ~
26273 \SpecialChar ~
26274 \SpecialChar ~
26275 \SpecialChar ~
26276 \SpecialChar ~
26277 \SpecialChar ~
26278 \SpecialChar ~
26279 \SpecialChar ~
26280 \SpecialChar ~
26281 \SpecialChar ~
26282 \SpecialChar ~
26283 \SpecialChar ~
26284  91 ;\SpecialChar ~
26285  hob.c 15 
26286 \newline 
26287 0037 85*01*06\SpecialChar ~
26288 \SpecialChar ~
26289 \SpecialChar ~
26290 \SpecialChar ~
26291 \SpecialChar ~
26292 \SpecialChar ~
26293 \SpecialChar ~
26294 \SpecialChar ~
26295 \SpecialChar ~
26296 \SpecialChar ~
26297 \SpecialChar ~
26298 \SpecialChar ~
26299  92\SpecialChar ~
26300 \SpecialChar ~
26301 \SpecialChar ~
26302 \SpecialChar ~
26303 \SpecialChar ~
26304 \SpecialChar ~
26305 \SpecialChar ~
26306 \SpecialChar ~
26307  mov\SpecialChar ~
26308 \SpecialChar ~
26309  _foo_hob1_1_1,(_gint + 1) 
26310 \newline 
26311 \SpecialChar ~
26312 \SpecialChar ~
26313 \SpecialChar ~
26314 \SpecialChar ~
26315 \SpecialChar ~
26316 \SpecialChar ~
26317 \SpecialChar ~
26318 \SpecialChar ~
26319 \SpecialChar ~
26320 \SpecialChar ~
26321 \SpecialChar ~
26322 \SpecialChar ~
26323 \SpecialChar ~
26324 \SpecialChar ~
26325 \SpecialChar ~
26326 \SpecialChar ~
26327 \SpecialChar ~
26328 \SpecialChar ~
26329 \SpecialChar ~
26330 \SpecialChar ~
26331 \SpecialChar ~
26332 \SpecialChar ~
26333 \SpecialChar ~
26334 \SpecialChar ~
26335 \SpecialChar ~
26336  93 ;\SpecialChar ~
26337  hob.c 16 
26338 \newline 
26339 003A 85*05*07\SpecialChar ~
26340 \SpecialChar ~
26341 \SpecialChar ~
26342 \SpecialChar ~
26343 \SpecialChar ~
26344 \SpecialChar ~
26345 \SpecialChar ~
26346 \SpecialChar ~
26347 \SpecialChar ~
26348 \SpecialChar ~
26349 \SpecialChar ~
26350 \SpecialChar ~
26351  94\SpecialChar ~
26352 \SpecialChar ~
26353 \SpecialChar ~
26354 \SpecialChar ~
26355 \SpecialChar ~
26356 \SpecialChar ~
26357 \SpecialChar ~
26358 \SpecialChar ~
26359  mov\SpecialChar ~
26360 \SpecialChar ~
26361  _foo_hob2_1_1,(_glong + 3) 
26362 \newline 
26363 \SpecialChar ~
26364 \SpecialChar ~
26365 \SpecialChar ~
26366 \SpecialChar ~
26367 \SpecialChar ~
26368 \SpecialChar ~
26369 \SpecialChar ~
26370 \SpecialChar ~
26371 \SpecialChar ~
26372 \SpecialChar ~
26373 \SpecialChar ~
26374 \SpecialChar ~
26375 \SpecialChar ~
26376 \SpecialChar ~
26377 \SpecialChar ~
26378 \SpecialChar ~
26379 \SpecialChar ~
26380 \SpecialChar ~
26381 \SpecialChar ~
26382 \SpecialChar ~
26383 \SpecialChar ~
26384 \SpecialChar ~
26385 \SpecialChar ~
26386 \SpecialChar ~
26387 \SpecialChar ~
26388  95 ;\SpecialChar ~
26389  hob.c 17 
26390 \newline 
26391 003D 85*04*08\SpecialChar ~
26392 \SpecialChar ~
26393 \SpecialChar ~
26394 \SpecialChar ~
26395 \SpecialChar ~
26396 \SpecialChar ~
26397 \SpecialChar ~
26398 \SpecialChar ~
26399 \SpecialChar ~
26400 \SpecialChar ~
26401 \SpecialChar ~
26402 \SpecialChar ~
26403  96\SpecialChar ~
26404 \SpecialChar ~
26405 \SpecialChar ~
26406 \SpecialChar ~
26407 \SpecialChar ~
26408 \SpecialChar ~
26409 \SpecialChar ~
26410 \SpecialChar ~
26411  mov\SpecialChar ~
26412 \SpecialChar ~
26413  _foo_how1_1_1,(_glong + 2) 
26414 \newline 
26415 0040 85*05*09\SpecialChar ~
26416 \SpecialChar ~
26417 \SpecialChar ~
26418 \SpecialChar ~
26419 \SpecialChar ~
26420 \SpecialChar ~
26421 \SpecialChar ~
26422 \SpecialChar ~
26423 \SpecialChar ~
26424 \SpecialChar ~
26425 \SpecialChar ~
26426 \SpecialChar ~
26427  97\SpecialChar ~
26428 \SpecialChar ~
26429 \SpecialChar ~
26430 \SpecialChar ~
26431 \SpecialChar ~
26432 \SpecialChar ~
26433 \SpecialChar ~
26434 \SpecialChar ~
26435  mov\SpecialChar ~
26436 \SpecialChar ~
26437  (_foo_how1_1_1 + 1),(_glong + 3) 
26438 \newline 
26439 0043 85*03*0A\SpecialChar ~
26440 \SpecialChar ~
26441 \SpecialChar ~
26442 \SpecialChar ~
26443 \SpecialChar ~
26444 \SpecialChar ~
26445 \SpecialChar ~
26446 \SpecialChar ~
26447 \SpecialChar ~
26448 \SpecialChar ~
26449 \SpecialChar ~
26450 \SpecialChar ~
26451  98\SpecialChar ~
26452 \SpecialChar ~
26453 \SpecialChar ~
26454 \SpecialChar ~
26455 \SpecialChar ~
26456 \SpecialChar ~
26457 \SpecialChar ~
26458 \SpecialChar ~
26459  mov\SpecialChar ~
26460 \SpecialChar ~
26461  _foo_how2_1_1,(_glong + 1) 
26462 \newline 
26463 0046 85*04*0B\SpecialChar ~
26464 \SpecialChar ~
26465 \SpecialChar ~
26466 \SpecialChar ~
26467 \SpecialChar ~
26468 \SpecialChar ~
26469 \SpecialChar ~
26470 \SpecialChar ~
26471 \SpecialChar ~
26472 \SpecialChar ~
26473 \SpecialChar ~
26474 \SpecialChar ~
26475  99\SpecialChar ~
26476 \SpecialChar ~
26477 \SpecialChar ~
26478 \SpecialChar ~
26479 \SpecialChar ~
26480 \SpecialChar ~
26481 \SpecialChar ~
26482 \SpecialChar ~
26483  mov\SpecialChar ~
26484 \SpecialChar ~
26485  (_foo_how2_1_1 + 1),(_glong + 2) 
26486 \layout Standard
26487
26488 Again, variations of these cases may 
26489 \emph on 
26490 not
26491 \emph default 
26492  be recognized.
26493  They are standard C expressions, so I heartily recommend these be the only
26494  way to get the higher order byte/word, (it is portable).
26495  Of course it will be recognized even if it is embedded in other expressions,
26496  e.g.:
26497 \layout Verse
26498
26499
26500 \family typewriter 
26501 xyz = gint + ((gint >> 8) & 0xFF);
26502 \layout Standard
26503
26504 will still be recognized.
26505 \layout Subsection
26506
26507 Peephole Optimizer
26508 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
26509
26510 \end_inset 
26511
26512
26513 \begin_inset LatexCommand \index{Peephole optimizer}
26514
26515 \end_inset 
26516
26517
26518 \layout Standard
26519
26520 The compiler uses a rule based, pattern matching and re-writing mechanism
26521  for peep-hole optimization.
26522  It is inspired by 
26523 \emph on 
26524 copt
26525 \emph default 
26526  a peep-hole optimizer by Christopher W.
26527  Fraser (cwfraser\SpecialChar ~
26528 @\SpecialChar ~
26529 microsoft.com).
26530  A default set of rules are compiled into the compiler, additional rules
26531  may be added with the 
26532 \emph on 
26533 -
26534 \begin_inset ERT
26535 status Collapsed
26536
26537 \layout Standard
26538
26539 \backslash 
26540 /
26541 \end_inset 
26542
26543 -peep-file
26544 \begin_inset LatexCommand \index{-\/-peep-file}
26545
26546 \end_inset 
26547
26548  <filename>
26549 \emph default 
26550  option.
26551  The rule language is best illustrated with examples.
26552 \layout Verse
26553
26554
26555 \family typewriter 
26556 replace { 
26557 \newline 
26558 \SpecialChar ~
26559 \SpecialChar ~
26560 mov %1,a 
26561 \newline 
26562 \SpecialChar ~
26563 \SpecialChar ~
26564 mov a,%1
26565 \newline 
26566 } by {
26567 \newline 
26568 \SpecialChar ~
26569 \SpecialChar ~
26570 mov %1,a
26571 \newline 
26572 }
26573 \layout Standard
26574
26575 The above rule will change the following assembly
26576 \begin_inset LatexCommand \index{Assembler routines}
26577
26578 \end_inset 
26579
26580  sequence:
26581 \layout Verse
26582
26583
26584 \family typewriter 
26585 mov r1,a 
26586 \newline 
26587 mov a,r1
26588 \layout Standard
26589
26590 to
26591 \layout Verse
26592
26593
26594 \family typewriter 
26595 mov r1,a
26596 \layout Standard
26597
26598 Note: All occurrences of a 
26599 \emph on 
26600 %n
26601 \emph default 
26602  (pattern variable) must denote the same string.
26603  With the above rule, the assembly sequence:
26604 \layout Verse
26605
26606
26607 \family typewriter 
26608 mov r1,a 
26609 \newline 
26610 mov a,r2
26611 \layout Standard
26612
26613 will remain unmodified.
26614 \newline 
26615
26616 \newline 
26617 Other special case optimizations may be added by the user (via 
26618 \emph on 
26619 -
26620 \begin_inset ERT
26621 status Collapsed
26622
26623 \layout Standard
26624
26625 \backslash 
26626 /
26627 \end_inset 
26628
26629 -peep-file option
26630 \emph default 
26631 ).
26632  E.g.
26633  some variants of the 8051 MCU
26634 \begin_inset LatexCommand \index{MCS51 variants}
26635
26636 \end_inset 
26637
26638  allow only 
26639 \family typewriter 
26640 ajmp
26641 \family default 
26642  and 
26643 \family typewriter 
26644 acall
26645 \family default 
26646 .
26647  The following two rules will change all 
26648 \family typewriter 
26649 ljmp
26650 \family default 
26651  and 
26652 \family typewriter 
26653 lcall
26654 \family default 
26655  to 
26656 \family typewriter 
26657 ajmp
26658 \family default 
26659  and 
26660 \family typewriter 
26661 acall
26662 \layout Verse
26663
26664
26665 \family typewriter 
26666 replace { lcall %1 } by { acall %1 } 
26667 \newline 
26668 replace { ljmp %1 } by { ajmp %1 }
26669 \layout Standard
26670
26671 The 
26672 \emph on 
26673 inline-assembler code
26674 \emph default 
26675  is also passed through the peep hole optimizer, thus the peephole optimizer
26676  can also be used as an assembly level macro expander.
26677  The rules themselves are MCU dependent whereas the rule language infra-structur
26678 e is MCU independent.
26679  Peephole optimization rules for other MCU can be easily programmed using
26680  the rule language.
26681 \newline 
26682
26683 \newline 
26684 The syntax for a rule is as follows:
26685 \layout Verse
26686
26687
26688 \family typewriter 
26689 rule := replace [ restart ] '{' <assembly sequence> '
26690 \backslash 
26691 n' 
26692 \newline 
26693 \SpecialChar ~
26694  \SpecialChar ~
26695  \SpecialChar ~
26696  \SpecialChar ~
26697  \SpecialChar ~
26698  \SpecialChar ~
26699  \SpecialChar ~
26700  \SpecialChar ~
26701  \SpecialChar ~
26702  \SpecialChar ~
26703  \SpecialChar ~
26704  \SpecialChar ~
26705  \SpecialChar ~
26706  \SpecialChar ~
26707  '}' by '{' '
26708 \backslash 
26709 n' 
26710 \newline 
26711 \SpecialChar ~
26712  \SpecialChar ~
26713  \SpecialChar ~
26714  \SpecialChar ~
26715  \SpecialChar ~
26716  \SpecialChar ~
26717  \SpecialChar ~
26718  \SpecialChar ~
26719  \SpecialChar ~
26720  \SpecialChar ~
26721  \SpecialChar ~
26722  \SpecialChar ~
26723  \SpecialChar ~
26724  \SpecialChar ~
26725  \SpecialChar ~
26726  \SpecialChar ~
26727  <assembly sequence> '
26728 \backslash 
26729 n' 
26730 \newline 
26731 \SpecialChar ~
26732  \SpecialChar ~
26733  \SpecialChar ~
26734  \SpecialChar ~
26735  \SpecialChar ~
26736  \SpecialChar ~
26737  \SpecialChar ~
26738  \SpecialChar ~
26739  \SpecialChar ~
26740  \SpecialChar ~
26741  \SpecialChar ~
26742  \SpecialChar ~
26743  \SpecialChar ~
26744  \SpecialChar ~
26745  '}' [if <functionName> ] '
26746 \backslash 
26747 n' 
26748 \layout Standard
26749
26750 <assembly sequence> := assembly instruction (each instruction including
26751  labels must be on a separate line).
26752 \newline 
26753
26754 \newline 
26755 The optimizer will apply to the rules one by one from the top in the sequence
26756  of their appearance, it will terminate when all rules are exhausted.
26757  If the 'restart' option is specified, then the optimizer will start matching
26758  the rules again from the top, this option for a rule is expensive (performance)
26759 , it is intended to be used in situations where a transformation will trigger
26760  the same rule again.
26761  An example of this (not a good one, it has side effects) is the following
26762  rule:
26763 \layout Verse
26764
26765
26766 \family typewriter 
26767 replace restart { 
26768 \newline 
26769 \SpecialChar ~
26770 \SpecialChar ~
26771 pop %1 
26772 \newline 
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 push %1 } by { 
26776 \newline 
26777 \SpecialChar ~
26778 \SpecialChar ~
26779 ; nop 
26780 \newline 
26781 }
26782 \layout Standard
26783
26784 Note that the replace pattern cannot be a blank, but can be a comment line.
26785  Without the 'restart' option only the innermost 'pop' 'push' pair would
26786  be eliminated, i.e.:
26787 \layout Verse
26788
26789
26790 \family typewriter 
26791 pop ar1 
26792 \newline 
26793 pop ar2 
26794 \newline 
26795 push ar2 
26796 \newline 
26797 push ar1
26798 \layout Standard
26799
26800 would result in:
26801 \layout Verse
26802
26803
26804 \family typewriter 
26805 pop ar1 
26806 \newline 
26807 ; nop 
26808 \newline 
26809 push ar1
26810 \layout Standard
26811
26812
26813 \emph on 
26814 with
26815 \emph default 
26816  the restart option the rule will be applied again to the resulting code
26817  and then all the pop-push pairs will be eliminated to yield:
26818 \layout Verse
26819
26820
26821 \family typewriter 
26822 ; nop 
26823 \newline 
26824 ; nop
26825 \layout Standard
26826
26827 A conditional function can be attached to a rule.
26828  Attaching rules are somewhat more involved, let me illustrate this with
26829  an example.
26830 \layout Verse
26831
26832
26833 \family typewriter 
26834 replace { 
26835 \newline 
26836 \SpecialChar ~
26837  \SpecialChar ~
26838  \SpecialChar ~
26839 ljmp %5 
26840 \newline 
26841 %2:
26842 \newline 
26843 } by { 
26844 \newline 
26845 \SpecialChar ~
26846  \SpecialChar ~
26847  \SpecialChar ~
26848 sjmp %5 
26849 \newline 
26850 %2:
26851 \newline 
26852 } if labelInRange
26853 \layout Standard
26854
26855 The optimizer does a look-up of a function name table defined in function
26856  
26857 \emph on 
26858 callFuncByName
26859 \emph default 
26860  in the source file SDCCpeeph.c, with the name 
26861 \emph on 
26862 labelInRange
26863 \emph default 
26864 .
26865  If it finds a corresponding entry the function is called.
26866  Note there can be no parameters specified for these functions, in this
26867  case the use of 
26868 \emph on 
26869 %5
26870 \emph default 
26871  is crucial, since the function 
26872 \emph on 
26873 labelInRange
26874 \emph default 
26875  expects to find the label in that particular variable (the hash table containin
26876 g the variable bindings is passed as a parameter).
26877  If you want to code more such functions, take a close look at the function
26878  labelInRange and the calling mechanism in source file SDCCpeeph.c.
26879  Currently implemented are 
26880 \emph on 
26881 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
26882  24bitMode, portIsDS390, 24bitModeAndPortDS390 
26883 \emph default 
26884 and
26885 \emph on 
26886  notVolatile
26887 \emph default 
26888 .
26889 \layout Standard
26890
26891 I know this whole thing is a little kludgey, but maybe some day we will
26892  have some better means.
26893  If you are looking at this file, you will see the default rules that are
26894  compiled into the compiler, you can add your own rules in the default set
26895  there if you get tired of specifying the -
26896 \begin_inset ERT
26897 status Collapsed
26898
26899 \layout Standard
26900
26901 \backslash 
26902 /
26903 \end_inset 
26904
26905 -peep-file option.
26906 \layout Section
26907
26908 ANSI-Compliance
26909 \begin_inset LatexCommand \index{ANSI-compliance}
26910
26911 \end_inset 
26912
26913
26914 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
26915
26916 \end_inset 
26917
26918
26919 \layout Standard
26920
26921 Deviations from the compliance:
26922 \layout Itemize
26923
26924 functions are not reentrant
26925 \begin_inset LatexCommand \index{reentrant}
26926
26927 \end_inset 
26928
26929  unless explicitly declared as such or the 
26930 \series bold 
26931 -
26932 \begin_inset ERT
26933 status Collapsed
26934
26935 \layout Standard
26936
26937 \backslash 
26938 /
26939 \end_inset 
26940
26941 -stack-auto
26942 \begin_inset LatexCommand \index{-\/-stack-auto}
26943
26944 \end_inset 
26945
26946
26947 \series default 
26948  command line option is specified.
26949 \layout Itemize
26950
26951 structures and unions cannot be assigned values directly, cannot be passed
26952  as function parameters or assigned to each other and cannot be a return
26953  value from a function, e.g.:
26954 \begin_deeper 
26955 \layout Verse
26956
26957
26958 \family typewriter 
26959 struct s { ...
26960  }; 
26961 \newline 
26962 struct s s1, s2; 
26963 \newline 
26964 foo() 
26965 \newline 
26966
26967 \newline 
26968 \SpecialChar ~
26969 \SpecialChar ~
26970 \SpecialChar ~
26971 \SpecialChar ~
26972 ...
26973  
26974 \newline 
26975 \SpecialChar ~
26976 \SpecialChar ~
26977 \SpecialChar ~
26978 \SpecialChar ~
26979 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
26980 \newline 
26981 \SpecialChar ~
26982 \SpecialChar ~
26983 \SpecialChar ~
26984 \SpecialChar ~
26985 ...
26986  
26987 \newline 
26988 }
26989 \newline 
26990 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
26991  */
26992 \newline 
26993
26994 \newline 
26995 \SpecialChar ~
26996 \SpecialChar ~
26997 \SpecialChar ~
26998 \SpecialChar ~
26999 struct s rets; 
27000 \newline 
27001 \SpecialChar ~
27002 \SpecialChar ~
27003 \SpecialChar ~
27004 \SpecialChar ~
27005 ...
27006  
27007 \newline 
27008 \SpecialChar ~
27009 \SpecialChar ~
27010 \SpecialChar ~
27011 \SpecialChar ~
27012 return rets;/* is invalid in SDCC although allowed in ANSI */ 
27013 \newline 
27014 }
27015 \end_deeper 
27016 \layout Itemize
27017
27018 initialization of structure arrays must be fully braced.
27019 \begin_deeper 
27020 \layout Verse
27021
27022
27023 \family typewriter 
27024 struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
27025 \newline 
27026 struct s { char x } a[] = {{1}, {2}}; /* OK */
27027 \end_deeper 
27028 \layout Itemize
27029
27030 'long long
27031 \begin_inset LatexCommand \index{long long (not supported)}
27032
27033 \end_inset 
27034
27035 ' (64 bit integers
27036 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
27037
27038 \end_inset 
27039
27040 ) not supported.
27041 \layout Itemize
27042
27043 'double
27044 \begin_inset LatexCommand \index{double (not supported)}
27045
27046 \end_inset 
27047
27048 ' precision floating point 
27049 \begin_inset LatexCommand \index{Floating point support}
27050
27051 \end_inset 
27052
27053 not supported.
27054 \layout Itemize
27055
27056 Old K&R style
27057 \begin_inset LatexCommand \index{K\&R style}
27058
27059 \end_inset 
27060
27061  function declarations are NOT allowed.
27062 \begin_deeper 
27063 \layout Verse
27064
27065
27066 \family typewriter 
27067 foo(i,j) /* this old style of function declarations */ 
27068 \newline 
27069 int i,j; /* are valid in ANSI but not valid in SDCC */ 
27070 \newline 
27071
27072 \newline 
27073 \SpecialChar ~
27074 \SpecialChar ~
27075 \SpecialChar ~
27076 \SpecialChar ~
27077 ...
27078  
27079 \newline 
27080 }
27081 \end_deeper 
27082 \layout Itemize
27083
27084 Most enhancements in C99 are not supported, f.e.:
27085 \begin_deeper 
27086 \layout Verse
27087
27088
27089 \family typewriter 
27090 \series bold 
27091 inline
27092 \series default 
27093  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
27094  in C99 */
27095 \newline 
27096 for (
27097 \series bold 
27098 int
27099 \series default 
27100  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
27101 \end_deeper 
27102 \layout Itemize
27103
27104 Certain words that are valid identifiers in the standard may be reserved
27105  words in SDCC unless the 
27106 \series bold 
27107 -
27108 \begin_inset ERT
27109 status Collapsed
27110
27111 \layout Standard
27112
27113 \backslash 
27114 /
27115 \end_inset 
27116
27117 -std-c89
27118 \begin_inset LatexCommand \index{-\/-std-c89}
27119
27120 \end_inset 
27121
27122  or -
27123 \begin_inset ERT
27124 status Collapsed
27125
27126 \layout Standard
27127
27128 \backslash 
27129 /
27130 \end_inset 
27131
27132 -std-c99
27133 \begin_inset LatexCommand \index{-\/-std-c99}
27134
27135 \end_inset 
27136
27137
27138 \series default 
27139  command line options are used.
27140  These may include (depending on the selected processor): 'at', 'banked',
27141  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
27142 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
27143  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
27144  '_naked'.
27145  Compliant equivalents of these keywords are always available in a form
27146  that begin with two underscores
27147 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
27148
27149 \end_inset 
27150
27151 , f.e.
27152  '__data' instead of 'data'.
27153 \layout Section
27154
27155 Cyclomatic Complexity
27156 \begin_inset LatexCommand \index{Cyclomatic complexity}
27157
27158 \end_inset 
27159
27160
27161 \layout Standard
27162
27163 Cyclomatic complexity of a function is defined as the number of independent
27164  paths the program can take during execution of the function.
27165  This is an important number since it defines the number test cases you
27166  have to generate to validate the function.
27167  The accepted industry standard for complexity number is 10, if the cyclomatic
27168  complexity reported by SDCC exceeds 10 you should think about simplification
27169  of the function logic.
27170  Note that the complexity level is not related to the number of lines of
27171  code in a function.
27172  Large functions can have low complexity, and small functions can have large
27173  complexity levels.
27174  
27175 \newline 
27176
27177 \newline 
27178 SDCC uses the following formula to compute the complexity:
27179 \newline 
27180
27181 \layout Standard
27182
27183 complexity = (number of edges in control flow graph) - (number of nodes
27184  in control flow graph) + 2;
27185 \newline 
27186
27187 \newline 
27188 Having said that the industry standard is 10, you should be aware that in
27189  some cases it be may unavoidable to have a complexity level of less than
27190  10.
27191  For example if you have switch statement with more than 10 case labels,
27192  each case label adds one to the complexity level.
27193  The complexity level is by no means an absolute measure of the algorithmic
27194  complexity of the function, it does however provide a good starting point
27195  for which functions you might look at for further optimization.
27196 \layout Section
27197
27198 Retargetting for other Processors
27199 \layout Standard
27200
27201 The issues for retargetting the compiler are far too numerous to be covered
27202  by this document.
27203  What follows is a brief description of each of the seven phases of the
27204  compiler and its MCU dependency.
27205 \layout Itemize
27206
27207 Parsing the source and building the annotated parse tree.
27208  This phase is largely MCU independent (except for the language extensions).
27209  Syntax & semantic checks are also done in this phase, along with some initial
27210  optimizations like back patching labels and the pattern matching optimizations
27211  like bit-rotation etc.
27212 \layout Itemize
27213
27214 The second phase involves generating an intermediate code which can be easy
27215  manipulated during the later phases.
27216  This phase is entirely MCU independent.
27217  The intermediate code generation assumes the target machine has unlimited
27218  number of registers, and designates them with the name iTemp.
27219  The compiler can be made to dump a human readable form of the code generated
27220  by using the -
27221 \begin_inset ERT
27222 status Collapsed
27223
27224 \layout Standard
27225
27226 \backslash 
27227 /
27228 \end_inset 
27229
27230 -dumpraw option.
27231 \layout Itemize
27232
27233 This phase does the bulk of the standard optimizations and is also MCU independe
27234 nt.
27235  This phase can be broken down into several sub-phases:
27236 \newline 
27237
27238 \newline 
27239 Break down intermediate code (iCode) into basic blocks.
27240 \newline 
27241 Do control flow & data flow analysis on the basic blocks.
27242 \newline 
27243 Do local common subexpression elimination, then global subexpression elimination
27244 \newline 
27245 Dead code elimination
27246 \newline 
27247 Loop optimizations
27248 \newline 
27249 If loop optimizations caused any changes then do 'global subexpression eliminati
27250 on' and 'dead code elimination' again.
27251 \layout Itemize
27252
27253 This phase determines the live-ranges; by live range I mean those iTemp
27254  variables defined by the compiler that still survive after all the optimization
27255 s.
27256  Live range analysis
27257 \begin_inset LatexCommand \index{Live range analysis}
27258
27259 \end_inset 
27260
27261  is essential for register allocation, since these computation determines
27262  which of these iTemps will be assigned to registers, and for how long.
27263 \layout Itemize
27264
27265 Phase five is register allocation.
27266  There are two parts to this process.
27267 \newline 
27268
27269 \newline 
27270 The first part I call 'register packing' (for lack of a better term).
27271  In this case several MCU specific expression folding is done to reduce
27272  register pressure.
27273 \newline 
27274
27275 \newline 
27276 The second part is more MCU independent and deals with allocating registers
27277  to the remaining live ranges.
27278  A lot of MCU specific code does creep into this phase because of the limited
27279  number of index registers available in the 8051.
27280 \layout Itemize
27281
27282 The Code generation phase is (unhappily), entirely MCU dependent and very
27283  little (if any at all) of this code can be reused for other MCU.
27284  However the scheme for allocating a homogenized assembler operand for each
27285  iCode operand may be reused.
27286 \layout Itemize
27287
27288 As mentioned in the optimization section the peep-hole optimizer is rule
27289  based system, which can reprogrammed for other MCUs.
27290 \layout Chapter
27291
27292 Compiler internals
27293 \begin_inset LatexCommand \index{Compiler internals}
27294
27295 \end_inset 
27296
27297
27298 \layout Section
27299
27300 The anatomy of the compiler
27301 \begin_inset LatexCommand \label{sub:The-anatomy-of}
27302
27303 \end_inset 
27304
27305
27306 \layout Standard
27307
27308
27309 \shape italic 
27310 This is an excerpt from an article published in Circuit Cellar Magazine
27311  in 
27312 \series bold 
27313 August 2000
27314 \series default 
27315 .
27316  It's a little outdated (the compiler is much more efficient now and user/develo
27317 per friendly), but pretty well exposes the guts of it all.
27318 \shape default 
27319
27320 \newline 
27321
27322 \newline 
27323 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
27324  It is fairly easy to retarget for other 8-bit MCU.
27325  Here we take a look at some of the internals of the compiler.
27326  
27327 \layout Paragraph*
27328
27329 Parsing
27330 \begin_inset LatexCommand \index{Parsing}
27331
27332 \end_inset 
27333
27334  
27335 \layout Standard
27336
27337 Parsing the input source file and creating an AST (Annotated Syntax Tree
27338 \begin_inset LatexCommand \index{Annotated syntax tree}
27339
27340 \end_inset 
27341
27342 ).
27343  This phase also involves propagating types (annotating each node of the
27344  parse tree with type information) and semantic analysis.
27345  There are some MCU specific parsing rules.
27346  For example the storage classes, the extended storage classes are MCU specific
27347  while there may be a xdata storage class for 8051 there is no such storage
27348  class for z80 or Atmel AVR.
27349  SDCC allows MCU specific storage class extensions, i.e.
27350  xdata will be treated as a storage class specifier when parsing 8051 C
27351  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
27352  C code.
27353 \layout Paragraph*
27354
27355 Generating iCode
27356 \begin_inset LatexCommand \index{iCode}
27357
27358 \end_inset 
27359
27360
27361 \layout Standard
27362
27363 Intermediate code generation.
27364  In this phase the AST is broken down into three-operand form (iCode).
27365  These three operand forms are represented as doubly linked lists.
27366  ICode is the term given to the intermediate form generated by the compiler.
27367  ICode example section shows some examples of iCode generated for some simple
27368  C source functions.
27369 \layout Paragraph*
27370
27371 Optimizations
27372 \begin_inset LatexCommand \index{Optimizations}
27373
27374 \end_inset 
27375
27376 .
27377 \layout Standard
27378
27379 Bulk of the target independent optimizations is performed in this phase.
27380  The optimizations include constant propagation, common sub-expression eliminati
27381 on, loop invariant code movement, strength reduction of loop induction variables
27382  and dead-code elimination.
27383 \layout Paragraph*
27384
27385 Live range analysis
27386 \begin_inset LatexCommand \index{Live range analysis}
27387
27388 \end_inset 
27389
27390
27391 \layout Standard
27392
27393 During intermediate code generation phase, the compiler assumes the target
27394  machine has infinite number of registers and generates a lot of temporary
27395  variables.
27396  The live range computation determines the lifetime of each of these compiler-ge
27397 nerated temporaries.
27398  A picture speaks a thousand words.
27399  ICode example sections show the live range annotations for each of the
27400  operand.
27401  It is important to note here, each iCode is assigned a number in the order
27402  of its execution in the function.
27403  The live ranges are computed in terms of these numbers.
27404  The from number is the number of the iCode which first defines the operand
27405  and the to number signifies the iCode which uses this operand last.
27406 \layout Paragraph*
27407
27408 Register Allocation
27409 \begin_inset LatexCommand \index{Register allocation}
27410
27411 \end_inset 
27412
27413
27414 \layout Standard
27415
27416 The register allocation determines the type and number of registers needed
27417  by each operand.
27418  In most MCUs only a few registers can be used for indirect addressing.
27419  In case of 8051 for example the registers R0 & R1 can be used to indirectly
27420  address the internal ram and DPTR to indirectly address the external ram.
27421  The compiler will try to allocate the appropriate register to pointer variables
27422  if it can.
27423  ICode example section shows the operands annotated with the registers assigned
27424  to them.
27425  The compiler will try to keep operands in registers as much as possible;
27426  there are several schemes the compiler uses to do achieve this.
27427  When the compiler runs out of registers the compiler will check to see
27428  if there are any live operands which is not used or defined in the current
27429  basic block being processed, if there are any found then it will push that
27430  operand and use the registers in this block, the operand will then be popped
27431  at the end of the basic block.
27432  
27433 \layout Standard
27434
27435 There are other MCU specific considerations in this phase.
27436  Some MCUs have an accumulator; very short-lived operands could be assigned
27437  to the accumulator instead of a general-purpose register.
27438 \layout Paragraph*
27439
27440 Code generation
27441 \layout Standard
27442
27443 Figure II gives a table of iCode operations supported by the compiler.
27444  The code generation involves translating these operations into corresponding
27445  assembly code for the processor.
27446  This sounds overly simple but that is the essence of code generation.
27447  Some of the iCode operations are generated on a MCU specific manner for
27448  example, the z80 port does not use registers to pass parameters so the
27449  SEND and RECV iCode operations will not be generated, and it also does
27450  not support JUMPTABLES.
27451  
27452 \newline 
27453
27454 \series bold 
27455 \shape italic 
27456 \color red
27457 <Where is Figure II?>
27458 \layout Comment
27459
27460 In the original article Figure II was announced to be downloadable on 
27461 \shape italic 
27462 Circuit Cellar
27463 \shape default 
27464 's web site.
27465  Unfortunately it never seemed to have shown up there, so: where is Figure
27466  II?
27467 \layout Paragraph*
27468
27469 ICode Example
27470 \begin_inset LatexCommand \index{iCode}
27471
27472 \end_inset 
27473
27474
27475 \layout Standard
27476
27477 This section shows some details of iCode.
27478  The example C code does not do anything useful; it is used as an example
27479  to illustrate the intermediate code generated by the compiler.
27480 \layout Verse
27481
27482
27483 \family typewriter 
27484 1.\SpecialChar ~
27485 xdata int * p;
27486 \newline 
27487 2.\SpecialChar ~
27488 int gint;
27489 \newline 
27490 3.\SpecialChar ~
27491 /* This function does nothing useful.
27492  It is used
27493 \newline 
27494 4.\SpecialChar ~
27495 \SpecialChar ~
27496 \SpecialChar ~
27497 \SpecialChar ~
27498 for the purpose of explaining iCode */
27499 \newline 
27500 5.\SpecialChar ~
27501 short function (data int *x)
27502 \newline 
27503 6.\SpecialChar ~
27504 {
27505 \newline 
27506 7.\SpecialChar ~
27507 \SpecialChar ~
27508 \SpecialChar ~
27509 short i=10; \SpecialChar ~
27510 \SpecialChar ~
27511 /* dead initialization eliminated */
27512 \newline 
27513 8.\SpecialChar ~
27514 \SpecialChar ~
27515 \SpecialChar ~
27516 short sum=10; /* dead initialization eliminated */
27517 \newline 
27518 9.\SpecialChar ~
27519 \SpecialChar ~
27520 \SpecialChar ~
27521 short mul;
27522 \newline 
27523 10.\SpecialChar ~
27524 \SpecialChar ~
27525 int j ;
27526 \newline 
27527 11.\SpecialChar ~
27528 \SpecialChar ~
27529 while (*x) *x++ = *p++; 
27530 \newline 
27531 12.\SpecialChar ~
27532 \SpecialChar ~
27533 \SpecialChar ~
27534 \SpecialChar ~
27535 sum = 0 ; 
27536 \newline 
27537 13.\SpecialChar ~
27538 \SpecialChar ~
27539 mul = 0;
27540 \newline 
27541 14.\SpecialChar ~
27542 \SpecialChar ~
27543 /* compiler detects i,j to be induction variables */
27544 \newline 
27545 15.\SpecialChar ~
27546 \SpecialChar ~
27547 for (i = 0, j = 10 ; i < 10 ; i++, j
27548 \family default 
27549 -
27550 \begin_inset ERT
27551 status Collapsed
27552
27553 \layout Standard
27554
27555 \backslash 
27556 /
27557 \end_inset 
27558
27559 -
27560 \family typewriter 
27561 ) {
27562 \newline 
27563 16.\SpecialChar ~
27564 \SpecialChar ~
27565 \SpecialChar ~
27566 \SpecialChar ~
27567 sum += i;
27568 \newline 
27569 17.\SpecialChar ~
27570 \SpecialChar ~
27571 \SpecialChar ~
27572 \SpecialChar ~
27573 mul += i * 3; \SpecialChar ~
27574 \SpecialChar ~
27575 /* this multiplication remains */
27576 \newline 
27577 18.\SpecialChar ~
27578 \SpecialChar ~
27579 \SpecialChar ~
27580 \SpecialChar ~
27581 gint += j * 3;\SpecialChar ~
27582 \SpecialChar ~
27583 /* this multiplication changed to addition */
27584 \newline 
27585 19.\SpecialChar ~
27586 \SpecialChar ~
27587 }
27588 \newline 
27589 20.\SpecialChar ~
27590 \SpecialChar ~
27591 return sum+mul;
27592 \newline 
27593 21.\SpecialChar ~
27594 }
27595 \layout Standard
27596
27597 In addition to the operands each iCode contains information about the filename
27598  and line it corresponds to in the source file.
27599  The first field in the listing should be interpreted as follows:
27600 \newline 
27601
27602 \shape italic 
27603 \size footnotesize 
27604 Filename(linenumber: iCode Execution sequence number : ICode hash table
27605  key : loop depth of the iCode).
27606 \shape default 
27607 \size default 
27608
27609 \newline 
27610 Then follows the human readable form of the ICode operation.
27611  Each operand of this triplet form can be of three basic types a) compiler
27612  generated temporary b) user defined variable c) a constant value.
27613  Note that local variables and parameters are replaced by compiler generated
27614  temporaries.
27615  Live ranges
27616 \begin_inset LatexCommand \index{Live range analysis}
27617
27618 \end_inset 
27619
27620  are computed only for temporaries (i.e.
27621  live ranges are not computed for global variables).
27622  Registers
27623 \begin_inset LatexCommand \index{Register allocation}
27624
27625 \end_inset 
27626
27627  are allocated for temporaries only.
27628  Operands are formatted in the following manner:
27629 \newline 
27630
27631 \shape italic 
27632 \size footnotesize 
27633 Operand Name [lr live-from : live-to ] { type information } [ registers
27634  allocated ].
27635 \shape default 
27636 \size default 
27637
27638 \newline 
27639 As mentioned earlier the live ranges are computed in terms of the execution
27640  sequence number of the iCodes, for example 
27641 \newline 
27642 the iTemp0 is live from (i.e.
27643  first defined in iCode with execution sequence number 3, and is last used
27644  in the iCode with sequence number 5).
27645  For induction variables such as iTemp21 the live range computation extends
27646  the lifetime from the start to the end of the loop.
27647 \newline 
27648 The register allocator used the live range information to allocate registers,
27649  the same registers may be used for different temporaries if their live
27650  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
27651  iTemp17 since their live ranges do not overlap.
27652  In addition the allocator also takes into consideration the type and usage
27653  of a temporary, for example itemp6 is a pointer to near space and is used
27654  as to fetch data from (i.e.
27655  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
27656  Some short lived temporaries are allocated to special registers which have
27657  meaning to the code generator e.g.
27658  iTemp13 is allocated to a pseudo register CC which tells the back end that
27659  the temporary is used only for a conditional jump the code generation makes
27660  use of this information to optimize a compare and jump ICode.
27661 \newline 
27662 There are several loop optimizations
27663 \begin_inset LatexCommand \index{Loop optimization}
27664
27665 \end_inset 
27666
27667  performed by the compiler.
27668  It can detect induction variables iTemp21(i) and iTemp23(j).
27669  Also note the compiler does selective strength reduction
27670 \begin_inset LatexCommand \index{Strength reduction}
27671
27672 \end_inset 
27673
27674 , i.e.
27675  the multiplication of an induction variable in line 18 (gint = j * 3) is
27676  changed to addition, a new temporary iTemp17 is allocated and assigned
27677  a initial value, a constant 3 is then added for each iteration of the loop.
27678  The compiler does not change the multiplication
27679 \begin_inset LatexCommand \index{Multiplication}
27680
27681 \end_inset 
27682
27683  in line 17 however since the processor does support an 8 * 8 bit multiplication.
27684 \newline 
27685 Note the dead code elimination
27686 \begin_inset LatexCommand \index{Dead-code elimination}
27687
27688 \end_inset 
27689
27690  optimization eliminated the dead assignments in line 7 & 8 to I and sum
27691  respectively.
27692 \newline 
27693
27694 \layout Standard
27695
27696
27697 \size footnotesize 
27698 Sample.c (5:1:0:0) _entry($9) :
27699 \layout Standard
27700
27701
27702 \size footnotesize 
27703 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
27704 \layout Standard
27705
27706
27707 \size footnotesize 
27708 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
27709 \layout Standard
27710
27711
27712 \size footnotesize 
27713 Sample.c(11:4:53:0) preHeaderLbl0($11) :
27714 \layout Standard
27715
27716
27717 \size footnotesize 
27718 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
27719  * int}[r2]
27720 \layout Standard
27721
27722
27723 \size footnotesize 
27724 Sample.c(11:6:5:1) _whilecontinue_0($1) :
27725 \layout Standard
27726
27727
27728 \size footnotesize 
27729 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
27730  int}[r0]]
27731 \layout Standard
27732
27733
27734 \size footnotesize 
27735 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
27736 \layout Standard
27737
27738
27739 \size footnotesize 
27740 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
27741  * int}
27742 \layout Standard
27743
27744
27745 \size footnotesize 
27746 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
27747  {short}
27748 \layout Standard
27749
27750
27751 \size footnotesize 
27752 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
27753  * int}[DPTR]]
27754 \layout Standard
27755
27756
27757 \size footnotesize 
27758 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
27759 }[r2 r3]
27760 \layout Standard
27761
27762
27763 \size footnotesize 
27764 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
27765  * int}[r0] + 0x2 {short}
27766 \layout Standard
27767
27768
27769 \size footnotesize 
27770 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
27771 \layout Standard
27772
27773
27774 \size footnotesize 
27775 Sample.c(11:17:21:0)_whilebreak_0($3) :
27776 \layout Standard
27777
27778
27779 \size footnotesize 
27780 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
27781 \layout Standard
27782
27783
27784 \size footnotesize 
27785 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
27786 \layout Standard
27787
27788
27789 \size footnotesize 
27790 Sample.c(15:20:54:0)preHeaderLbl1($13) :
27791 \layout Standard
27792
27793
27794 \size footnotesize 
27795 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
27796 \layout Standard
27797
27798
27799 \size footnotesize 
27800 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
27801 \layout Standard
27802
27803
27804 \size footnotesize 
27805 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
27806 \layout Standard
27807
27808
27809 \size footnotesize 
27810 Sample.c(15:24:26:1)_forcond_0($4) :
27811 \layout Standard
27812
27813
27814 \size footnotesize 
27815 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
27816  < 0xa {short}
27817 \layout Standard
27818
27819
27820 \size footnotesize 
27821 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
27822 \layout Standard
27823
27824
27825 \size footnotesize 
27826 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
27827  + ITemp21 [lr21:38]{short}[r4]
27828 \layout Standard
27829
27830
27831 \size footnotesize 
27832 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
27833  * 0x3 {short}
27834 \layout Standard
27835
27836
27837 \size footnotesize 
27838 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
27839  + iTemp15 [lr29:30]{short}[r1]
27840 \layout Standard
27841
27842
27843 \size footnotesize 
27844 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
27845  r0]- 0x3 {short}
27846 \layout Standard
27847
27848
27849 \size footnotesize 
27850 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
27851 int}[r7 r0]
27852 \layout Standard
27853
27854
27855 \size footnotesize 
27856 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
27857  + 0x1 {short}
27858 \layout Standard
27859
27860
27861 \size footnotesize 
27862 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
27863  r6]- 0x1 {short}
27864 \layout Standard
27865
27866
27867 \size footnotesize 
27868 Sample.c(19:38:47:1) goto _forcond_0($4)
27869 \layout Standard
27870
27871
27872 \size footnotesize 
27873 Sample.c(19:39:48:0)_forbreak_0($7) :
27874 \layout Standard
27875
27876
27877 \size footnotesize 
27878 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
27879  + ITemp11 [lr19:40]{short}[r3]
27880 \layout Standard
27881
27882
27883 \size footnotesize 
27884 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
27885 \layout Standard
27886
27887
27888 \size footnotesize 
27889 Sample.c(20:42:51:0)_return($8) :
27890 \layout Standard
27891
27892
27893 \size footnotesize 
27894 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
27895 \size default 
27896
27897 \newline 
27898
27899 \newline 
27900 Finally the code generated for this function:
27901 \newline 
27902
27903 \layout Standard
27904
27905
27906 \size footnotesize 
27907 .area DSEG (DATA)
27908 \layout Standard
27909
27910
27911 \size footnotesize 
27912 _p::
27913 \layout Standard
27914
27915
27916 \size footnotesize 
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 .ds 2
27920 \layout Standard
27921
27922
27923 \size footnotesize 
27924 _gint::
27925 \layout Standard
27926
27927
27928 \size footnotesize 
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 .ds 2
27932 \layout Standard
27933
27934
27935 \size footnotesize 
27936 ; sample.c 5
27937 \layout Standard
27938
27939
27940 \size footnotesize 
27941 ; ----------------------------------------------
27942 \layout Standard
27943
27944
27945 \size footnotesize 
27946 ; function function
27947 \layout Standard
27948
27949
27950 \size footnotesize 
27951 ; ----------------------------------------------
27952 \layout Standard
27953
27954
27955 \size footnotesize 
27956 _function:
27957 \layout Standard
27958
27959
27960 \size footnotesize 
27961 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
27962 \layout Standard
27963
27964
27965 \size footnotesize 
27966 \SpecialChar ~
27967 \SpecialChar ~
27968 mov r2,dpl
27969 \layout Standard
27970
27971
27972 \size footnotesize 
27973 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
27974 \layout Standard
27975
27976
27977 \size footnotesize 
27978 \SpecialChar ~
27979 \SpecialChar ~
27980 mov ar0,r2
27981 \layout Standard
27982
27983
27984 \size footnotesize 
27985 ;_whilecontinue_0($1) :
27986 \layout Standard
27987
27988
27989 \size footnotesize 
27990 00101$:
27991 \layout Standard
27992
27993
27994 \size footnotesize 
27995 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
27996 \layout Standard
27997
27998
27999 \size footnotesize 
28000 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28001 \layout Standard
28002
28003
28004 \size footnotesize 
28005 \SpecialChar ~
28006 \SpecialChar ~
28007 mov ar2,@r0
28008 \layout Standard
28009
28010
28011 \size footnotesize 
28012 \SpecialChar ~
28013 \SpecialChar ~
28014 inc r0
28015 \layout Standard
28016
28017
28018 \size footnotesize 
28019 \SpecialChar ~
28020 \SpecialChar ~
28021 mov ar3,@r0
28022 \layout Standard
28023
28024
28025 \size footnotesize 
28026 \SpecialChar ~
28027 \SpecialChar ~
28028 dec r0
28029 \layout Standard
28030
28031
28032 \size footnotesize 
28033 \SpecialChar ~
28034 \SpecialChar ~
28035 mov a,r2
28036 \layout Standard
28037
28038
28039 \size footnotesize 
28040 \SpecialChar ~
28041 \SpecialChar ~
28042 orl a,r3
28043 \layout Standard
28044
28045
28046 \size footnotesize 
28047 \SpecialChar ~
28048 \SpecialChar ~
28049 jz 00103$
28050 \layout Standard
28051
28052
28053 \size footnotesize 
28054 00114$:
28055 \layout Standard
28056
28057
28058 \size footnotesize 
28059 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
28060 \layout Standard
28061
28062
28063 \size footnotesize 
28064 \SpecialChar ~
28065 \SpecialChar ~
28066 mov dpl,_p
28067 \layout Standard
28068
28069
28070 \size footnotesize 
28071 \SpecialChar ~
28072 \SpecialChar ~
28073 mov dph,(_p + 1)
28074 \layout Standard
28075
28076
28077 \size footnotesize 
28078 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
28079 \layout Standard
28080
28081
28082 \size footnotesize 
28083 \SpecialChar ~
28084 \SpecialChar ~
28085 mov a,#0x02
28086 \layout Standard
28087
28088
28089 \size footnotesize 
28090 \SpecialChar ~
28091 \SpecialChar ~
28092 add a,_p
28093 \layout Standard
28094
28095
28096 \size footnotesize 
28097 \SpecialChar ~
28098 \SpecialChar ~
28099 mov _p,a
28100 \layout Standard
28101
28102
28103 \size footnotesize 
28104 \SpecialChar ~
28105 \SpecialChar ~
28106 clr a
28107 \layout Standard
28108
28109
28110 \size footnotesize 
28111 \SpecialChar ~
28112 \SpecialChar ~
28113 addc a,(_p + 1)
28114 \layout Standard
28115
28116
28117 \size footnotesize 
28118 \SpecialChar ~
28119 \SpecialChar ~
28120 mov (_p + 1),a
28121 \layout Standard
28122
28123
28124 \size footnotesize 
28125 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
28126 \layout Standard
28127
28128
28129 \size footnotesize 
28130 \SpecialChar ~
28131 \SpecialChar ~
28132 movx a,@dptr
28133 \layout Standard
28134
28135
28136 \size footnotesize 
28137 \SpecialChar ~
28138 \SpecialChar ~
28139 mov r2,a
28140 \layout Standard
28141
28142
28143 \size footnotesize 
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 inc dptr
28147 \layout Standard
28148
28149
28150 \size footnotesize 
28151 \SpecialChar ~
28152 \SpecialChar ~
28153 movx a,@dptr
28154 \layout Standard
28155
28156
28157 \size footnotesize 
28158 \SpecialChar ~
28159 \SpecialChar ~
28160 mov r3,a
28161 \layout Standard
28162
28163
28164 \size footnotesize 
28165 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
28166 \layout Standard
28167
28168
28169 \size footnotesize 
28170 \SpecialChar ~
28171 \SpecialChar ~
28172 mov @r0,ar2
28173 \layout Standard
28174
28175
28176 \size footnotesize 
28177 \SpecialChar ~
28178 \SpecialChar ~
28179 inc r0
28180 \layout Standard
28181
28182
28183 \size footnotesize 
28184 \SpecialChar ~
28185 \SpecialChar ~
28186 mov @r0,ar3
28187 \layout Standard
28188
28189
28190 \size footnotesize 
28191 ; iTemp6 [lr5:16]{_near * int}[r0] = 
28192 \layout Standard
28193
28194
28195 \size footnotesize 
28196 ; iTemp6 [lr5:16]{_near * int}[r0] + 
28197 \layout Standard
28198
28199
28200 \size footnotesize 
28201 ; 0x2 {short}
28202 \layout Standard
28203
28204
28205 \size footnotesize 
28206 \SpecialChar ~
28207 \SpecialChar ~
28208 inc r0
28209 \layout Standard
28210
28211
28212 \size footnotesize 
28213 ; goto _whilecontinue_0($1)
28214 \layout Standard
28215
28216
28217 \size footnotesize 
28218 \SpecialChar ~
28219 \SpecialChar ~
28220 sjmp 00101$
28221 \layout Standard
28222
28223
28224 \size footnotesize 
28225 ; _whilebreak_0($3) :
28226 \layout Standard
28227
28228
28229 \size footnotesize 
28230 00103$:
28231 \layout Standard
28232
28233
28234 \size footnotesize 
28235 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
28236 \layout Standard
28237
28238
28239 \size footnotesize 
28240 \SpecialChar ~
28241 \SpecialChar ~
28242 mov r2,#0x00
28243 \layout Standard
28244
28245
28246 \size footnotesize 
28247 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
28248 \layout Standard
28249
28250
28251 \size footnotesize 
28252 \SpecialChar ~
28253 \SpecialChar ~
28254 mov r3,#0x00
28255 \layout Standard
28256
28257
28258 \size footnotesize 
28259 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
28260 \layout Standard
28261
28262
28263 \size footnotesize 
28264 \SpecialChar ~
28265 \SpecialChar ~
28266 mov r4,#0x00
28267 \layout Standard
28268
28269
28270 \size footnotesize 
28271 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
28272 \layout Standard
28273
28274
28275 \size footnotesize 
28276 \SpecialChar ~
28277 \SpecialChar ~
28278 mov r5,#0x0A
28279 \layout Standard
28280
28281
28282 \size footnotesize 
28283 \SpecialChar ~
28284 \SpecialChar ~
28285 mov r6,#0x00
28286 \layout Standard
28287
28288
28289 \size footnotesize 
28290 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
28291 \layout Standard
28292
28293
28294 \size footnotesize 
28295 \SpecialChar ~
28296 \SpecialChar ~
28297 mov r7,#0x1E
28298 \layout Standard
28299
28300
28301 \size footnotesize 
28302 \SpecialChar ~
28303 \SpecialChar ~
28304 mov r0,#0x00
28305 \layout Standard
28306
28307
28308 \size footnotesize 
28309 ; _forcond_0($4) :
28310 \layout Standard
28311
28312
28313 \size footnotesize 
28314 00104$:
28315 \layout Standard
28316
28317
28318 \size footnotesize 
28319 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
28320 \layout Standard
28321
28322
28323 \size footnotesize 
28324 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
28325 \layout Standard
28326
28327
28328 \size footnotesize 
28329 \SpecialChar ~
28330 \SpecialChar ~
28331 clr c
28332 \layout Standard
28333
28334
28335 \size footnotesize 
28336 \SpecialChar ~
28337 \SpecialChar ~
28338 mov a,r4
28339 \layout Standard
28340
28341
28342 \size footnotesize 
28343 \SpecialChar ~
28344 \SpecialChar ~
28345 xrl a,#0x80
28346 \layout Standard
28347
28348
28349 \size footnotesize 
28350 \SpecialChar ~
28351 \SpecialChar ~
28352 subb a,#0x8a
28353 \layout Standard
28354
28355
28356 \size footnotesize 
28357 \SpecialChar ~
28358 \SpecialChar ~
28359 jnc 00107$
28360 \layout Standard
28361
28362
28363 \size footnotesize 
28364 00115$:
28365 \layout Standard
28366
28367
28368 \size footnotesize 
28369 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
28370 \layout Standard
28371
28372
28373 \size footnotesize 
28374 ; iTemp21 [lr21:38]{short}[r4]
28375 \layout Standard
28376
28377
28378 \size footnotesize 
28379 \SpecialChar ~
28380 \SpecialChar ~
28381 mov a,r4
28382 \layout Standard
28383
28384
28385 \size footnotesize 
28386 \SpecialChar ~
28387 \SpecialChar ~
28388 add a,r2
28389 \layout Standard
28390
28391
28392 \size footnotesize 
28393 \SpecialChar ~
28394 \SpecialChar ~
28395 mov r2,a
28396 \layout Standard
28397
28398
28399 \size footnotesize 
28400 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
28401 \layout Standard
28402
28403
28404 \size footnotesize 
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 mov b,#0x03
28408 \layout Standard
28409
28410
28411 \size footnotesize 
28412 \SpecialChar ~
28413 \SpecialChar ~
28414 mov a,r4
28415 \layout Standard
28416
28417
28418 \size footnotesize 
28419 \SpecialChar ~
28420 \SpecialChar ~
28421 mul ab
28422 \layout Standard
28423
28424
28425 \size footnotesize 
28426 \SpecialChar ~
28427 \SpecialChar ~
28428 mov r1,a
28429 \layout Standard
28430
28431
28432 \size footnotesize 
28433 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
28434 \layout Standard
28435
28436
28437 \size footnotesize 
28438 ; iTemp15 [lr29:30]{short}[r1]
28439 \layout Standard
28440
28441
28442 \size footnotesize 
28443 \SpecialChar ~
28444 \SpecialChar ~
28445 add a,r3
28446 \layout Standard
28447
28448
28449 \size footnotesize 
28450 \SpecialChar ~
28451 \SpecialChar ~
28452 mov r3,a
28453 \layout Standard
28454
28455
28456 \size footnotesize 
28457 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
28458 \layout Standard
28459
28460
28461 \size footnotesize 
28462 \SpecialChar ~
28463 \SpecialChar ~
28464 mov a,r7
28465 \layout Standard
28466
28467
28468 \size footnotesize 
28469 \SpecialChar ~
28470 \SpecialChar ~
28471 add a,#0xfd
28472 \layout Standard
28473
28474
28475 \size footnotesize 
28476 \SpecialChar ~
28477 \SpecialChar ~
28478 mov r7,a
28479 \layout Standard
28480
28481
28482 \size footnotesize 
28483 \SpecialChar ~
28484 \SpecialChar ~
28485 mov a,r0
28486 \layout Standard
28487
28488
28489 \size footnotesize 
28490 \SpecialChar ~
28491 \SpecialChar ~
28492 addc a,#0xff
28493 \layout Standard
28494
28495
28496 \size footnotesize 
28497 \SpecialChar ~
28498 \SpecialChar ~
28499 mov r0,a
28500 \layout Standard
28501
28502
28503 \size footnotesize 
28504 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
28505 \layout Standard
28506
28507
28508 \size footnotesize 
28509 \SpecialChar ~
28510 \SpecialChar ~
28511 mov a,r7
28512 \layout Standard
28513
28514
28515 \size footnotesize 
28516 \SpecialChar ~
28517 \SpecialChar ~
28518 add a,_gint
28519 \layout Standard
28520
28521
28522 \size footnotesize 
28523 \SpecialChar ~
28524 \SpecialChar ~
28525 mov _gint,a
28526 \layout Standard
28527
28528
28529 \size footnotesize 
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 mov a,r0
28533 \layout Standard
28534
28535
28536 \size footnotesize 
28537 \SpecialChar ~
28538 \SpecialChar ~
28539 addc a,(_gint + 1)
28540 \layout Standard
28541
28542
28543 \size footnotesize 
28544 \SpecialChar ~
28545 \SpecialChar ~
28546 mov (_gint + 1),a
28547 \layout Standard
28548
28549
28550 \size footnotesize 
28551 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
28552 \layout Standard
28553
28554
28555 \size footnotesize 
28556 \SpecialChar ~
28557 \SpecialChar ~
28558 inc r4
28559 \layout Standard
28560
28561
28562 \size footnotesize 
28563 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
28564 \layout Standard
28565
28566
28567 \size footnotesize 
28568 \SpecialChar ~
28569 \SpecialChar ~
28570 dec r5
28571 \layout Standard
28572
28573
28574 \size footnotesize 
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 cjne r5,#0xff,00104$
28578 \layout Standard
28579
28580
28581 \size footnotesize 
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 dec r6
28585 \layout Standard
28586
28587
28588 \size footnotesize 
28589 ; goto _forcond_0($4)
28590 \layout Standard
28591
28592
28593 \size footnotesize 
28594 \SpecialChar ~
28595 \SpecialChar ~
28596 sjmp 00104$
28597 \layout Standard
28598
28599
28600 \size footnotesize 
28601 ; _forbreak_0($7) :
28602 \layout Standard
28603
28604
28605 \size footnotesize 
28606 00107$:
28607 \layout Standard
28608
28609
28610 \size footnotesize 
28611 ; ret iTemp24 [lr40:41]{short}
28612 \layout Standard
28613
28614
28615 \size footnotesize 
28616 \SpecialChar ~
28617 \SpecialChar ~
28618 mov a,r3
28619 \layout Standard
28620
28621
28622 \size footnotesize 
28623 \SpecialChar ~
28624 \SpecialChar ~
28625 add a,r2
28626 \layout Standard
28627
28628
28629 \size footnotesize 
28630 \SpecialChar ~
28631 \SpecialChar ~
28632 mov dpl,a
28633 \layout Standard
28634
28635
28636 \size footnotesize 
28637 ; _return($8) :
28638 \layout Standard
28639
28640
28641 \size footnotesize 
28642 00108$:
28643 \layout Standard
28644
28645
28646 \size footnotesize 
28647 \SpecialChar ~
28648 \SpecialChar ~
28649 ret
28650 \newline 
28651
28652 \layout Section
28653
28654 A few words about basic block successors, predecessors and dominators
28655 \layout Standard
28656
28657 Successors are basic blocks
28658 \begin_inset LatexCommand \index{Basic blocks}
28659
28660 \end_inset 
28661
28662  that might execute after this basic block.
28663 \newline 
28664 Predecessors are basic blocks that might execute before reaching this basic
28665  block.
28666 \newline 
28667 Dominators are basic blocks that WILL execute before reaching this basic
28668  block.
28669 \newline 
28670
28671 \layout Standard
28672
28673 [basic block 1]
28674 \layout Standard
28675
28676 if (something)
28677 \layout Standard
28678
28679 \SpecialChar ~
28680 \SpecialChar ~
28681 \SpecialChar ~
28682 \SpecialChar ~
28683 [basic block 2]
28684 \layout Standard
28685
28686 else
28687 \layout Standard
28688
28689 \SpecialChar ~
28690 \SpecialChar ~
28691 \SpecialChar ~
28692 \SpecialChar ~
28693 [basic block 3]
28694 \layout Standard
28695
28696 [basic block 4]
28697 \newline 
28698
28699 \layout Standard
28700
28701 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
28702 \layout Standard
28703
28704 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
28705 \layout Standard
28706
28707 c) domVect of [BB4] = BB1 ...
28708  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
28709  was executed.
28710 \layout Chapter
28711
28712 Acknowledgments
28713 \layout Standard
28714
28715
28716 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
28717
28718 \end_inset 
28719
28720
28721 \newline 
28722
28723 \newline 
28724
28725 \emph on 
28726 Thanks to all the other volunteer developers who have helped with coding,
28727  testing, web-page creation, distribution sets, etc.
28728  You know who you are :-)
28729 \emph default 
28730
28731 \newline 
28732
28733 \layout Standard
28734
28735 This document was initially written by Sandeep Dutta
28736 \layout Standard
28737
28738 All product names mentioned herein may be trademarks
28739 \begin_inset LatexCommand \index{Trademarks}
28740
28741 \end_inset 
28742
28743  of their respective companies.
28744  
28745 \layout Section*
28746
28747 Alphabetical index
28748 \layout Standard
28749
28750 To avoid confusion, the installation and building options for SDCC itself
28751  (chapter 2) are not part of the index.
28752 \layout Standard
28753
28754
28755 \begin_inset LatexCommand \printindex{}
28756
28757 \end_inset 
28758
28759
28760 \the_end