compiler reference

Download Compiler Reference

Post on 26-Oct-2014

117 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

8051 IAR C/C++ CompilerReference Guide

for the MCS-51 Microcontroller Family

COPYRIGHT NOTICE Copyright 19912005 IAR Systems. All rights reserved. No part of this document may be reproduced without the prior written consent of IAR Systems. The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license.

DISCLAIMERThe information in this document is subject to change without notice and does not represent a commitment on any part of IAR Systems. While the information contained herein is assumed to be accurate, IAR Systems assumes no responsibility for any errors or omissions. In no event shall IAR Systems, its employees, its contractors, or the authors of this document be liable for special, direct, indirect, or consequential damage, losses, costs, charges, claims, demands, claim for lost profits, fees, or expenses of any nature or kind.

TRADEMARKSIAR Systems, From Idea to Target, IAR Embedded Workbench, visualSTATE, IAR MakeApp and C-SPY are trademarks owned by IAR Systems AB. Microsoft and Windows are registered trademarks of Microsoft Corporation. All other product names are trademarks or registered trademarks of their respective owners.

EDITION NOTICEThird edition: July 2005 Part number: C8051-3 This guide applies to version 7.1x of the 8051 IAR Embedded Workbench IDE.

Brief contentsTables...................................................................................................................... xv ................................................................................................................... xix ......................................................... 1

Preface

Part 1. Using the compilerGetting started Data storage Functions

.................................................................................................... 3

...................................................................................................... 13

............................................................................................................. 31 .................................................................................... 47 ............................................................... 69 ............................................................ 103

Placing code and data

The DLIB runtime environment The CLIB runtime environment Assembler language interface IAR C++

................................................................. 113

.............................................................................................................. 139 ...................................... 151

Efficient coding for embedded applications

Part 2. Compiler reference .................................................... 165Data representation Segment reference Compiler options...................................................................................... 167 ......................................................................................... 177 ........................................................................................... 213 ....................................................................................... 245

Extended keywords The preprocessor Intrinsic functions Library functions

Pragma directives ............................................................................................ 263........................................................................................... 275 ........................................................................................... 285

............................................................................................. 289

iii

Implementation-defined behavior IAR language extensions Diagnostics Index

.......................................................... 297

............................................................................. 311

......................................................................................................... 321

..................................................................................................................... 323

8051 IAR C/C++ Compiler

iv

Reference Guide

ContentsTables...................................................................................................................... xv ................................................................................................................... xix

Preface

Who should read this guide .............................................................. xix How to use this guide ......................................................................... xix What this guide contains ..................................................................... xx Other documentation .......................................................................... xxiFurther reading .................................................................................. xxi

Document conventions ......................................................................xxiiTypographic conventions .................................................................xxii

Part 1. Using the compilerGetting started

......................................................... 1

.................................................................................................... 3

IAR language overview ........................................................................... 3 Supported MCS-51 derivatives ........................................................... 4 Building applicationsan overview .................................................. 4Compiling ............................................................................................. 4 Linking ................................................................................................. 5

Basic settings for project configuration .......................................... 5Cores .................................................................................................... 6 Code model .......................................................................................... 6 Data model ........................................................................................... 7 Calling conventions .............................................................................. 7 Optimization settings ........................................................................... 8 Runtime environment ........................................................................... 9 Combinations and dependencies of the settings ................................ 10

Special support for embedded systems ........................................ 10Extended keywords ............................................................................ 11 Pragma directives ............................................................................... 11 Predefined symbols ............................................................................ 11 Special function types ........................................................................ 11

v

Header files for I/O ............................................................................ 11 Accessing low-level features ............................................................. 12

Data storage

...................................................................................................... 13

Introduction .............................................................................................. 13 Data models .............................................................................................. 14Specifying a data model ..................................................................... 14

Memory types .......................................................................................... 15Using data memory attributes ............................................................ 15 Structures and memory types ............................................................ 18 Pointers and memory types ................................................................ 19 Examples ............................................................................................ 20 Multiple data pointer registers (DPTRs) ........................................... 20

C++ and memory types ...................................................................... 22 Constants and strings ........................................................................... 23 The stack and auto variables ............................................................. 24 Calling conventions ................................................................................ 26 Dynamic memory on the heap ........................................................ 27 Virtual registers ..................................................................................... 28The virtual bit register ....................................................................... 29

Functions

............................................................................................................. 31

Code models ............................................................................................ 31Using function memory attributes ...................................................... 32 Function directives ............................................................................. 33

Special function types .......................................................................... 33Interrupt functions .......................................................................

Recommended

View more >