Fract keyword – Zilog EZ80F916 User Manual
Page 164

UM014423-0607
Using the ANSI C-Compiler
ZiLOG Developer Studio II
eZ80Acclaim!
®
User Manual
144
asm(
"
<assembly line>
"
);
The
asm
statement cannot be within an expression and can be used only within the body of
a function.
The <assembly line> can be any string.The compiler does not check the legality of the
string.
As with the
#pragma asm
form, the compiler does not process the <assembly line>
except for translating the standard C escape sequences.
The compiler prefixes the name of every global variable and function name with “_”. Glo-
bal variables and functions can therefore be accessed in inline assembly by prefixing their
name with “_”. The local variables and parameters cannot be accessed in inline assembly.
fract Keyword
The compiler extends the ANSI C language to include support for a new base type called
fract
that supports fixed-point fractional numbers. Declaring a
fract
variable is very
similar to declaring an integer variable, although the values to be associated with the vari-
able are not integers. Both
signed
and
unsigned
fract
s are supported. The following
are examples of legal fractional variable declarations:
int fract sif;
/* signed integer fract */
unsigned short fract usf;
/* unsigned short fract */
char fract ascf[10];
/* array of signed char fracts */
The
char
,
short
, and
int
base types determine the size of the object based upon the
default base type sizes for the target processor. For eZ80Acclaim!, they are 8, 16, and 24
bits wide, respectively. The
long fract
type is not supported.
Fractional Fixed-Point Representations
The compiler uses fractional fixed-point arithmetic for improved efficiency over floating-
point representations. Both
signed
and
unsigned
fractional numbers are supported. A
signed
fractional variable n is always within the following range:
-1 <= n < 1
When representing a signed fractional number, the most significant bit represents the sign,
and the remaining bits represent the two’s complement of the fraction. The binary point is
immediately after the sign bit.
An unsigned fractional variable n is always within the range: 0 <= n < 1. The binary point
is just before the most significant bit.
When determining the value of a fractional number, look at each bit of the fraction as a
negative power of two. For example, consider the following
signed short fract
:
2
-1
2
-2
2
-3
2
-4
2
-5
2
-6
2
-7
2
-8
2
-9
2
-10
2
-11
2
-12
2
-13
2
-14
2
-15
s .b
b
b
B
b
b
b
b
b
b
b
b
b
b
b