beautypg.com

Inline assembly – Zilog EZ80F916 User Manual

Page 163

background image

UM014423-0607

Using the ANSI C-Compiler

ZiLOG Developer Studio II

eZ80Acclaim!

®

User Manual

143

Placement of Consecutive Variables
The compiler also provides syntax to place several variables at consecutive addresses. For
example:

char ch1 _At 0xB7E000;
char ch2 _At ...;
char ch3 _At ...;

This places

ch1

at address

0xB7E000

,

ch2

at the next address (

0xB7E001

) after

ch1

, and

ch3

at the next address (

0xB7E002

) after

ch2

. The

_At

...

directive can only be used

after a previous

_At

or

_Align

directive.

Alignment of a Variable
The following syntax can be used to declare a global or static variable aligned at a speci-
fied alignment:

char ch2 _Align 2; // ch2 is aligned at even boundary
char ch4 _Align 4; // ch4 is aligned at a four byte boundary

NOTE: Only aligned variables with the

const

qualifier can be initialized. Non-

const

aligned variables would not be re-initialized correctly upon program reset. The
uninitialized aligned variables are not initialized to zero by the compiler startup
routine.

Inline Assembly

There are two methods of inserting assembly language within C code:

“Inline Assembly Using the Pragma Directive” on page 143

“Inline Assembly Using the asm Statement” on page 143

Inline Assembly Using the Pragma Directive
The first method uses the

#pragma

feature of ANSI C with the following syntax:

#pragma asm

"

<assembly line>

"

#pragma

can be inserted anywhere within the C source file. The contents of

<assembly line> must be legal assembly language syntax. The usual C escape sequences
(such as

\n

,

\t

, and

\r

) are properly translated. Currently, the compiler does not process

the <assembly line>. Except for escape sequences, it is passed through the compiler to the
assembler verbatim.

Inline Assembly Using the asm Statement
The second method of inserting assembly language uses the

asm

statement:

This manual is related to the following products: