Intel mcs-48 Microscope & Magnifier User Manual


 
INTRODUCTION
1.2 Programming a Microcomputer
1.2.1 Machine Language Programming
A microprocessor
is
instructed what to do by
programming it with a series of instructions
stored in Program Memory. The processor
fetches these instructions one at a time and
performs the operation indicated. These
instructions must
be
stored
in
a form that the
processor can understand. This format
is
referred to
as
Machine Language. For most
microprocessors this instruction
is
a group
of a binary bits
(1's
and
O's)
called a word
(also
called a byte if the word
is
a-bits). Some
instructions require more than one location
in Program Memory. To execute a multi-byte
instruction, the processor must execute
multiple fetches of program memory before
performing the instruction. Because mUlti-
byte instructions take more Program Mem-
ory and take longer to execute than single
byte instructions their
use
is
usually kept to a
minimum.
A processor may be programmed by
writing a sequence
of
instructions in the
binary code (ones and zeros) which the
machine can interpret directly. This
is
machine language programming and it
is
very useful where the program
to
be written
is
small and the application requires that
the designer have
an
intimate knowledge
of
the microprocessor. Machine language pro-
gramming
allows the user, because
of
his
detailed knowledge,
to
use many program-
ming
"tricks"
to
produce the most compact
and efficient code possible.
The following
is
an
example
of
a machine
language program: This program reads 5
sequential 8-bit words
in
from
an
I/O port
and stores them
sequentially in data
memory. The program starts by initializing
two
registers, one which determines where
the data is
to
be stored and another which
counts the number
of
words
to
be stored.
When finished the processor continues on
to
the next instructions.
Step
Number
0
1
2
3
4
5
6
7
8
9
10
Machine
Code
1011
1000
00100000
1011
1010
00000101
00001001
10100000
Explanation
Load
decimal
32
in
register
RO
Load
decimal 5
in
register
R2
Load
Port 1
to
accu-
mulator
Transfer contents of
accumulator
to
reg-
ister addressed
by
register 0
0001
1000
Increment
RO
by
1
11101010 Decrement register 2
0000 0100
by
1,
if result
is
zero
continue
to
step
9,
if
not
go
to
step
4
As you can see,
writing
machine instruc-
tions in ones and zeros can
be
very
laborious and subject
to
error. It is almost
always more efficient
to
represent each
a-bits of machine language code in a
shorthand format
called Hexadecimal.
The term hexadecimal results from the
character set used in hexadecimal notation.
Hexadecimal is merely
an
extension of the
normal decimal numbers by the addition of
the first six letters
of
the alphabet. This
gives a total
of
16
different characters. Each
hexadecimal
"digit"
can represent
16
values or the equivalent
of
four
binary bits;
therefore, each a-bit machine language
word can
be
represented by 2 hexadecimal
(hex for short) digits. The correspondence
among the decimal, binary, and hex
number systems is given below:
1-10