Assembly file – Zilog EZ80F916 User Manual
Page 187

UM014423-0607
Using the ANSI C-Compiler
ZiLOG Developer Studio II
eZ80Acclaim!
®
User Manual
167
LOCATING VARIABLES AT SPECIFIC ADDRESSES: OLDER METHOD
Beginning with release 4.11.0 of ZDS II, the eZ80 Acclaim! C-Compiler now provides an
easy and natural extension to the C language for placing variables at specific locations, as
described in “Placement Directives” on page 142. This is the recommended way to per-
form this task in newly written code. However, for compatibility with code developed
using older versions of the eZ80 Acclaim! C-Compiler, this section describes a technique
that can be used in those versions to accomplish the same thing more laboriously. This
technique uses the macro-processing capabilities of ANSI C to control variable placement.
To access a specific location in memory using this older technique, you can declare a
macro that expands into a pointer reference to the appropriate memory locations as shown
in the following example:
#define b_x *((char *)0x20)
#define b_y *((int *)0x120)
#define b_array ((unsigned char * )0x30)
char c;
int i;
void main(void)
{
b_x = 10;
c = b_x;
b_y = 0x1234;
i = b_y;
c = b_array[c];
}
The various Special Function Registers can be defined and accessed in a similar manner,
although this can now be done more easily using the placement directives described in
“Placement Directives” on page 142.
NOTE: When using this method, check the address ranges on the Project Settings dialog
box (“Project Settings—Address Spaces Page” on page 89) so that your program
does not inadvertently access data in areas already allocated.
Another method of allocating and accessing variables at a specified location requires a lit-
tle assembly programming. The idea is to allocate segments in an assembly module that is
located using the ORG directive. Labels are placed at the appropriate location and are
made public using the XDEF directive. When this module is linked with the rest of your
program, the variable is located at the proper position in memory.
Assembly File
xdef _my_data
define_my_seg,space=ram,org=80h
segment my_seg
_my_data:
ds 20; 20 bytes at 80h