UM004001-COR1103380 C-CompilerUser’s Manual
ASCII Character SetB–6 UM004001-COR1103p 112 70 Lowercase Pq 113 71 Lowercase Qr 114 72 Lowercase Rs 115 73 Lowercase St 116 74 Lowercase Tu 117 75 L
UM004001-COR1103 C–1380 C-COMPILER USER’S MANUALAPPENDIX C PROBLEM/SUGGESTION REPORT FORMIf you experience any problems while using this product, or i
UM004001-COR1103 Glossary-1380 C-COMPILER USER’S MANUALGLOSSARYAABS Absolute ValueAddress Space Physical or logical area of the target system’s Memory
GlossaryGlossary-2 UM004001-COR1103Bit A digit of a binary system. It has only two possible values: 0 or 1.BPS Bits Per Second. Number of binary digi
UM004001-COR1103 Glossary-3GlossaryControl Section A continuous logical area containing code or user data. Each control section has a name. The linke
GlossaryGlossary-4 UM004001-COR1103IM Immediate Data Addressing Mode.IMASK Interrupt Mask Register.IMR Interrupt Mask Register.INC Increment.INCW Incr
UM004001-COR1103 Glossary-5GlossaryJP Jump.JR Jump Range.Library A File Created by a Librarian. This file contains a collection of object modules that
GlossaryGlossary-6 UM004001-COR1103OPC Operation Code.Op Code Operation Code.OTP One-Time Programmable.PCON Port configuration register.PER Peripheral
UM004001-COR1103 Glossary-7GlossaryPublic/Global Symbol A programming variable that is available to more than one program file.PUSH Store a Value In t
UM004001-COR1103 xiFigure Page380 C-COMPILER USER’S MANUALLIST OF FIGURESFIGURE 1-1 DEVELOPMENT FLOW . . . . . . . . . . . . . . . . . . . . . . . .
GlossaryGlossary-8 UM004001-COR1103SMR Stop Mode Recovery.SN Serial Number.SOIC Small Outline IC.SP Stack Pointer.SPH Stack Pointer High.SPI Serial Pe
UM004001-COR1103 Glossary-9GlossarySWI Software Interrupt.Symbol Definition Symbol defined when the symbol name is associ- ated with a certain amount
GlossaryGlossary-10 UM004001-COR1103USART Universal Synchronous/Asynchronous Receiver/Transmitter. Can handle synchronous as well as asynchronous tra
UM004001-COR1103 Glossary-11GlossaryZASM ZiLOG Assembler. ZiLOG’s program development environment for DOS.ZDS ZiLOG Developer Studio. ZiLOG’s program
UM004001-COR1103 Index-1380 C-COMPILER USER’S MANUALINDEXA–DASCII Character Set . . . . . . . . . . . .B-1Assembly FileGeneration . . . . . . . . . .
IndexIndex-2 UM004001-COR1103strpbrk function . . . . . . . . . . . . 4-19strrchr function. . . . . . . . . . . . . 4-20strspn function . . . . . . .
UM004001-COR1103 1–1380 C-COMPILER USER’S MANUALCHAPTER 1 INTRODUCTIONINTRODUCTIONThe 380 C-Compiler conforms to the ANSI’s definition of a “freestand
Introduction Introduction1–2 UM004001-COR1103FIGURE 1-1. DEVELOPMENT FLOWZDS ENVIRONMENTZiLOG Developer Studio is an integrated development environme
UM004001-COR1103 1–3Introduction Minimum Requirements• Build and link a project file• Compile, assemble and link files• Prepare code for ROM release (
Installing the 380 C-compiler Introduction1–4 UM004001-COR1103INSTALLING THE 380 C-COMPILERTo install the 380 C-Compiler, insert the 380 C-Compiler CD
INSTALLING ZDSPerform the following steps to install ZDS: 1. Insert the ZiLOG Developer Studio CD-ROM into the host CD ROM drive. The Emulator Softwa
Sample Session Introduction1–6 UM004001-COR1103SAMPLE SESSIONThe 380 C-Compiler is a modular component that is part of the ZDS development environ-men
UM004001-COR1103 1–7Introduction Sample Session9. Click Save. The file name appears in the Project Name field in the New Project dialog box.10.Select
ii UM004001-COR1103©2003 by ZiLOG, Inc. All rights reserved. No part of this document may be copied or reproduced in any form or by any means without
Sample Session Introduction1–8 UM004001-COR11032. Select Set default include path to compiler settings in the Settings window. Selecting this option s
UM004001-COR1103 1–9Introduction Sample Session5. Type the following code in the edit window:#include <stdlib.h>int randnum;int main(){ srand
Sample Session Introduction1–10 UM004001-COR11037. Hold the Control key and select the following files:– libc.lib (standard C library) – lhf.lib (libr
UM004001-COR1103 1–11Introduction Sample Session16.Type the following code in the edit window:#include <stdlib.h>int randnum;int main(){ sran
Sample Session Introduction1–12 UM004001-COR1103• Warnings• Optimization levels• Preprocessor symbol definitions• Code generation configurationPerform
UM004001-COR1103 1–13Introduction Sample Session• The Generate debug information option generates symbolic debug information in the output object modu
Sample Session Introduction1–14 UM004001-COR1103Configuring WarningsThe C-Compiler Optimizations page allows the user to control the informational and
UM004001-COR1103 1–15Introduction Sample SessionConfiguring Optimization LevelsThe C-Compiler Optimizations page allows the user to select an optimiza
Sample Session Introduction1–16 UM004001-COR1103• The Level 2 optimization option performs:– constant propagation– copy propagation– dead code elimina
UM004001-COR1103 1–17Introduction Sample SessionDefining Preprocessor SymbolsThe C-Compiler Preprocessor page allows you to define preprocessor defini
UM004001-COR1103 iii380 C-COMPILER USER’S MANUAL PREFACEABOUT THIS MANUALWe recommend that you read and understand everything in this manual before s
Sample Session Introduction1–18 UM004001-COR1103• The Additional Include Directories field is used to enter additional search paths the C-compiler sho
UM004001-COR1103 1–19Introduction Compiling and DownloadingCOMPILING AND DOWNLOADINGThe following section shows how to compile a C file using ZDS and
Compiling and Downloading Introduction1–20 UM004001-COR1103DOWNLOADING A COMPILED FILEPerform the following steps to load the a HEX file.NOTE: A term
UM004001-COR1103 1–21Introduction Technical SupportDownload a HEX filePerform the following steps to download a HEX file into the EEPROM memory on top
UM004001-COR1103 2–1380 C-COMPILER USER’S MANUALCHAPTER 2 C-COMPILER OVERVIEWOVERVIEWThe 380 C compiler is an optimizing compiler that translates stan
Language Extensions C-Compiler Overview2–2 UM004001-COR1103– Support for interrupt functions– Intrinsic functions are provided for in-line assembly.•
UM004001-COR1103 2–3C-Compiler Overview pointers POINTERSA pointer to a qualified memory type can not be converted to a different qualified memory typ
I/O ADDRESS SPACES C-Compiler Overview2–4 UM004001-COR1103ACCCESING I/O ADDRESS SPACEThe Z380 instruction set does not allow indirect acess of the int
UM004001-COR1103 2–5C-Compiler Overview INTERRUPT FUNCTIONSINTERRUPT FUNCTIONSInterrupt functions are declared by preceding their definition with #pra
INTERRUPT FUNCTIONS C-Compiler Overview2–6 UM004001-COR1103USING THE DOS COMMAND LINEThe z380 C compiler can be invoked from the DOS command line.COMM
UM004001-COR1103 2–7C-Compiler Overview INTERRUPT FUNCTIONSCOMMAND LINE SWITCHESThe following command-line switches are recognized.TABLE 2-2. COMMAND
INTERRUPT FUNCTIONS C-Compiler Overview2–8 UM004001-COR1103NOTE: Other switches are for ZiLOG use only in this version.COMMAND LINE EXAMPLESCompiling
UM004001-COR1103 2–9C-Compiler Overview Optimization LevelsOPTIMIZATION LEVELSThe Z380 C-compiler allows the user to manually specify the level of opt
Optimization Levels C-Compiler Overview2–10 UM004001-COR1103Level 1 OptimizationsThe following is a description of the optimizations that are performe
UM004001-COR1103 2–11C-Compiler Overview Understanding errorsJump to Jump OptimizationTargets in the control statement are replaced by the ultimate ta
Included Files C-Compiler Overview2–12 UM004001-COR1103INCLUDED FILESA path to included files must be defined before the C-Compiler can recognize incl
UM004001-COR1103 2–13C-Compiler Overview Section NamesSECTION NAMESThe compiler places code and data into separate sections in the object file. Every
Incorporating Assembly with C C-Compiler Overview2–14 UM004001-COR1103INCORPORATING ASSEMBLY WITH CThe Z380- C-Compiler allows the user to incorporate
UM004001-COR1103 2–15C-Compiler Overview Incorporating C with assemblycall.ib _imul; (hl)=productadd sp,4; clean the stackret; return result in (hl)Re
UM004001-COR1103 vChapter Title and Subsections Page380 C-COMPILER USER’S MANUALTABLE OF CONTENTSChapter 1 IntroductionINTRODUCTION . . . . . . . .
UM004001-COR1103 3–1380 C-COMPILER USER’S MANUALCHAPTER 3 LINKING FILESINTRODUCTIONThe purpose of the Zilog cross linker is to read relocatable object
Introduction Linking Files3–2 UM004001-COR1103• Reads in Relocatable object modules and library files in Common Object File Format (COFF) or ZiLOG Obj
UM004001-COR1103 3–3Linking Files Using the Linker with the C-compilerOutputting OMF FilesDepending upon the options specified by the user, the linker
Invoking the Linker Linking Files3–4 UM004001-COR1103RUN TIME INITIALIZATION FILEThe C run-time initialization file is an assembly program that initia
UM004001-COR1103 3–5Linking Files Invoking the LinkerNOTE: The user needs to include the C-run time initialization file that is appropriate for the
Linker symbols Linking Files3–6 UM004001-COR1103• linker-command-file is the command file to be linked by the linker. Sample command files are provide
UM004001-COR1103 3–7Linking Files Linker Command File LINKER COMMAND FILEThe linker command file is text file that contains the linker command and opt
Linker Command File Linking Files3–8 UM004001-COR1103make a copy of an initialized RAM data section in a ROM address space, so that the RAM may be ini
UM004001-COR1103 3–9Linking Files Linker Command File The “Expression Formats” section, which follows, explains different types of expressions that ca
vi UM004001-COR1103Chapter Title and Subsections Page POINTERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Linker Command Line Linking Files3–10 UM004001-COR1103Linker Command RANGEThis command sets the lower and upper limits of a control section or an addr
UM004001-COR1103 3–11Linking Files Linker Command LineCOMMAND LINE SPECIFICATIONSThe following rules govern the command line specification:• ZLD exami
Linker Command Line Linking Files3–12 UM004001-COR1103LINKER COMMAND LINE OPTIONSLinker options are specified by prefixing an option word with a minus
UM004001-COR1103 3–13Linking Files Using the LibrarianSymbol File In Zilog Symbol Format A symbol file in the Zilog symbol format is generated when th
COMMAND LINE OPTIONSCommand line options are specified by prefixing an option letter with a minus (-). The com-mand line options are summarized in Ta
UM004001-COR1103 4–1380 C-COMPILER USER’S MANUALCHAPTER 4 RUN TIME ENVIRONMENTFUNCTION CALLSThe C-compiler imposes a strict set of rules on function c
Function Calls Run Time Environment4–2 UM004001-COR1103FIGURE 4-1. FRAME LAYOUT RESPONSIBILITIES OF A CALLED FUNCTIONA called function must perform t
UM004001-COR1103 4–3Run Time Environment Using the Run-Time LibrarySPECIAL CASES FOR A CALLED FUNCTIONThe following exceptions apply to special cases
Using the Run-Time Library Run Time Environment4–4 UM004001-COR1103INSTALLED FILESThe following header files are installed in the C-Compiler installat
UM004001-COR1103 4–5Run Time Environment Library FunctionsLIBRARY FUNCTIONSRun-time library routines are provided for the following:• Buffer Manipulat
UM004001-COR1103 viiChapter Title and Subsections PageLINKER COMMAND LINE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Library Functions Run Time Environment4–6 UM004001-COR1103 atof, atoi, atol FUNCTIONS Header file statement: #include <stdlib.h>Syntax: double
UM004001-COR1103 4–7Run Time Environment Library Functionsdiv FUNCTIONHeader file statement: #include <stdlib.h>Syntax: div_t div( int num, int
Library Functions Run Time Environment4–8 UM004001-COR1103int isspace( int c );int isupper( int c );int isxdigit( int c );Each function in the is fami
UM004001-COR1103 4–9Run Time Environment Library FunctionsFunction Test Conditionisalnum Alphanumeric (‘A’-‘Z’, ‘a’-‘z’, or ‘0’-‘9’)isalpha Letter (‘A
Library Functions Run Time Environment4–10 UM004001-COR1103memchr FUNCTIONHeader file statement: #include <string.h>Syntax: void *memchr( const
UM004001-COR1103 4–11Run Time Environment Library Functionsmemcpy FUNCTIONHeader file statement: #include <string.h>Syntax: void *memcpy (void *
Library Functions Run Time Environment4–12 UM004001-COR1103memset FUNCTIONHeader file statement: #include <string.h>Syntax: void *memset (void
UM004001-COR1103 4–13Run Time Environment Library Functions srand FUNCTIONHeader file statement: #include <stdlib.h>Syntax: void srand( unsigne
Library Functions Run Time Environment4–14 UM004001-COR1103strchr FUNCTIONHeader file statement: #include <string.h> Syntax: char *strchr (const
UM004001-COR1103 4–15Run Time Environment Library Functionsstrcmp FUNCTIONHeader file statement: #include <string.h> Syntax: int strcmp (const
viii UM004001-COR1103Chapter Title and Subsections Pagestrrchr FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Library Functions Run Time Environment4–16 UM004001-COR1103strcpy FUNCTIONHeader file statement: #include <string.h> Syntax: char *strcpy (char
UM004001-COR1103 4–17Run Time Environment Library Functionsstrlen FUNCTIONHeader file statement: #include <string.h> Syntax: size_t strlen (cons
Library Functions Run Time Environment4–18 UM004001-COR1103strncmp FUNCTIONHeader file statement: #include <string.h> Syntax: int strncmp (const
UM004001-COR1103 4–19Run Time Environment Library Functionsstrncpy FUNCTIONHeader file statement: #include <string.h> Syntax: char *strncpy (cha
Library Functions Run Time Environment4–20 UM004001-COR1103strrchr FUNCTIONHeader file statement: #include <string.h> Syntax: char *strrchr (con
UM004001-COR1103 4–21Run Time Environment Library Functionsstrstr FUNCTIONHeader file statement: #include <string.h> Syntax: char *strstr( cons
Library Functions Run Time Environment4–22 UM004001-COR1103Return ValueThe first time strtok is called, it returns a pointer to the first token in str
UM004001-COR1103 4–23Run Time Environment Library Functions[whitespace] [{ + | -}] [0 [{ x | X }]] [digits]If base is between 2 and 36, then it is use
Library Functions Run Time Environment4–24 UM004001-COR1103tolower, toupper FUNCTIONSHeader file statement: #include <ctype.h>Syntax: int tolowe
UM004001-COR1103 4–25Run Time Environment Library Functions va_arg, va_end, va_start FUNCTIONS Header file statement: #include <stdarg.h> Syntax
UM004001-COR1103 ixTable Page380 C-COMPILER USER’S MANUALLIST OF TABLESTABLE 2-1 I/O MACHINE INSTRUCTIONS . . . . . . . . . . . . . . . . . . . . . .
Library Functions Run Time Environment4–26 UM004001-COR1103• The va_arg macro does the following:– Retrieves a value of type from the location given b
UM004001-COR1103 A–1380 C-COMPILER USER’S MANUALAPPENDIX A INITIALIZATION AND LINK FILES;-------------------------------------------------------------
Initialization File Initialization and Link FilesA–2 UM004001-COR1103ld.ib hl,.BSS_LENGTH; Check for non-zero lengthld bc,hl ; *ld de,hl ; *swap de ;
UM004001-COR1103 A–3Initialization and Link Files Link file__exit:jr $ ; ?;***********************************************************************.de
UM004001-COR1103 B–1380 C-COMPILER USER’S MANUALAPPENDIX B ASCII CHARACTER SETTABLE B-1. ASCII CHARACTER SET Graphic Decimal Hexadecimal Comments0 0
ASCII Character SetB–2 UM004001-COR110316 10 Data Link Escape17 11 Device Control 118 12 Device Control 219 13 Device Control 320 14 Device Control 4
UM004001-COR1103 B–3ASCII Character Set ( 40 28 Opening (Left) Parenthesis) 41 29 Closing (Right) Parenthesis* 42 2A Asterisk+ 43 2B Plus, 44 2C Comm
ASCII Character SetB–4 UM004001-COR1103@ 64 40 Commercial AtA 65 41 Uppercase AB 66 42 Uppercase BC 67 43 Uppercase CD 68 44 Uppercase DE 69 45 Up
UM004001-COR1103 B–5ASCII Character Set X 88 58 Uppercase XY 89 59 Uppercase YZ 90 5A Uppercase Z[ 91 5B Opening (Left) Bracket\ 92 5C Reverse Sl
Comments to this Manuals