Microcontroller Basics Course
Microcontroller Basics Course
MICROCONTROLLER
Microcontroller
Basics Course
part 1: the TASM assembler
By B. Kainka
44 Elektor Electronics
Personal Download for Fagerlund, Mikko | copyright Elektor 1/2002
783018
MICROCONTROLLER
1/2002 Elektor Electronics Personal Download for Fagerlund, Mikko | copyright Elektor 45
783018
MICROCONTROLLER
we do not fully know but whose behaviour is first line, the numerical value P1 .equ 090H ;Port 1
easy to understand. That’s how it is with 0Fh (= 15), which is identified by the
modern technology — it has become nearly ‘#’ symbol, is loaded into the accu- main mov a,#0Fh
impossible to regard everything at all possi- mulator a. The accumulator is a reg- mov P1,a
ble levels of understanding. ister or memory with a size of eight loop sjmp loop
So, now we know that a microcontroller bits, so it can hold numerical values .end
has its own language, which actually con- between 0 and 255.
sists of nothing but numbers. However, there In the second line, the value in This listing also shows us something
is an obvious problem: the language that a the accumulator is then copied to else: the jump labels and newly
microcontroller can read easily and fluently is address 90h (= 144). At this address defined words are all located at the
not exactly suitable for people. We are not there is a register whose leads are beginning of the line, and all assem-
made to work with numbers, but rather with routed to the exterior of the IC, bler instructions are located some-
words. Consequently, words (which are easier namely to the Port 1 pins. The word what indented. Furthermore, there is
to remember) have been devised to represent ‘sjmp’ (short jump) causes a jump in also a comment, which plays
the individual machine-language instruc- program execution, in this case to absolutely no part in the translation.
tions. The programmer writes these words in the location ‘loop’. The word ‘loop’ A comment starts with a semicolon
a text file, and a special program then trans- has been chosen completely arbi- (;).
lates them into the language of the micro- trarily and simply represents an The specific notation varies some-
controller. This program is called an assem- address, in this case a position in the what from one assembler to the
bler, and the programming language is also series of instructions. The assembler next. Here we are using the share-
called assembler (or assembly language). treats such words, which are called ware assembler TASM (Table-Driven
Assembler is thus a notation that you and I labels, as addresses and replaces Assembler, a program written by
can use to tell a microcontroller what it them with the appropriate numerical Thomas N. Anderson). TASM is very
should do, as in: values. The sjmp instruction can simple and can translate programs
cause a jump of up to 127 bytes for many different types of microcon-
main mov a,#0Fh backwards or 128 bytes forwards. A trollers, as long as it has the appro-
mov 090H,a single byte is thus sufficient to spec- priate instruction table.
loop sjmp loop ify the jump destination. Here the At the end of the program there is
jump is calculated relative to the cur- a loop, in which a jump to the desti-
This is already much more readable. Actually, rent position in the program. nation ‘loop’ takes place, always and
here we only need to know two special The word ‘main’ at the beginning forever. In other programming lan-
words: ‘mov’ and ‘sjmp’. Both of these words of the program is also arbitrarily cho- guages, such a situation would be
are called mnemonics, which means markers sen. The only actual assembler key- called a fatal endless loop, which is
used in place of the actual machine-language words here are thus ‘mov’ and practically equivalent to a crash. In
instructions. The word ‘mov’ (move) means ‘sjmp’. We humans can easily such a loop, the processor is in a
‘move’, ‘shift’ or ‘load’. Following it comes remember such words without the state that it cannot exit under its
first the location where something is to be aid of an electronic brain. own power. In general, it should
loaded and then what is to be loaded. In the However, there is still a problem. always be clear what should be
46 Elektor Electronics
Personal Download for Fagerlund, Mikko | copyright Elektor 1/2002
783018
MICROCONTROLLER
TASM -51 -b flash1.asm When TASM translates a program, you can specify the format in which the results are to be
stored. In the binary format, only the bytes that represent the individual machine-language
flash1.bin
instructions are written. A text editor cannot make any sense of such a file.
The Intel hex format uses text lines containing hexadecimal numbers. In addition to the
to specify our particular example actual code, there is a start address and a checksum for each line. This format can also be
program, the instruction table viewed as text.
TASM51.tab and binary output for-
1/2002 Elektor Electronics Personal Download for Fagerlund, Mikko | copyright Elektor 47
783018
MICROCONTROLLER
48 Elektor Electronics
Personal Download for Fagerlund, Mikko | copyright Elektor 1/2002