EasyManua.ls Logo

ST ST7 - Declaring Variables

ST ST7
317 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
138/317
6 - STMicroelectronics Programming Tools
The assembler automatically recognizes the addressing mode afterthe syntax of the operand,
as in the following examples:
LD A,#2; immediate
LD A,VALUE; direct short
LD A,VALUE2; direct long
LD A,VALUE,(X); indexed with short displacement
LD A,VALUE2,(X); indexed with long displacement
LD A,(X); indexed
LD A,[VALUE]; indirect short
LD A,[VALUE2]; indirect long
LD A,[VALUE,(X)]; indirect indexed with short displacement
LD A,[VALUE2,(X)]; indirect indexed with long displacement
assuming that the address of VALUE is less than 100h and the address of VALUE2 is above that
address.
The assembler translates each statement in turn, and assigns them to successive locations in
program memory. Provided the address of the first instruction is specified, all the following in-
structions have a defined place in memory.
6.1.3 Declaring variables
A variable, in the programming sense, is a piece of memory allocated to hold a particular data
object. This piece can range in size anywhere from a bit to the whole memory space; the most
common data types are bytes, words (double bytes), double words and arrays of these basic
data types. Whatever its type, a variable is given a symbolic name to be used in a program.
Another feature of a variable is that it may be changed during the execution of the program, in
whichcaseitmustresideinread-writememoryorRAM.
We have already introduced the notion of symbolic data. The term
VALUE given in the exam-
ples above is the symbolic name that the programmer may assign to a data object somewhere
in the addressable space. Since these names can be freely chosen, they can be meaningful
words that help the reader locate and recognize the various data. This is absolutely necessary
since numeric addresses immediately lead to confusion.
The second task the assembler performs is to assign addresses in memory. This is obvious as
far as the program is concerned: the successive instructions are put at consecutive ad-
dresses, and the programmer only needs to supply the start address of the program for the
whole code to be determined. However,when data are involved, things are not so clear. A var-
iable is assigned a place in memory, by giving an address for its first byte. Some variables are
only one byte long; others are one word long, or two bytes; others are more complex data like
double words, structures, arrays, etc. To avoid one variable to overlapping another, it is nec-
essary to space them properly, according to their length. It is very cumbersome to calculate

Table of Contents

Related product manuals