| |
 |
The 8051
|
|
|
|
| |
|
| |
|
| |
A Basic Instruction Set for a
Basic Microprocessor |
| |
|
| |
Before we start to look at the 8051 instruction
set, it would be better to take a fictitious, basic microprocessor and
examine a limited number of instructions that this microprocessor might
perform. |
| |
|
| |
 |
| |
|
| |
Inside the ALU there is a special
register called the accumulator. In our assembly language, we will
refer to this 8-bit register as A. |
| |
|
| |
To facilitate this we will also invent a basic
assembly language which we will use to demonstrate the instruction set. |
| |
|
| |
| Assembly |
HEX Equivalent |
Operation |
Size of Instruction |
| INC A |
E4 |
(A) <- (A) +
1 |
1 byte |
| DEC A |
E5 |
(A) <- (A) -
1 |
1 byte |
| LD A, data |
3E, data |
(A) <- data |
2 bytes |
| JP, address |
D6, address |
(PC) <-
address |
3 bytes |
|
| |
|
| |
The instruction set consists of four
instructions. The first one increases the contents of A by one.
The second decreases the contents of A by one. The third loads
the data into A and the fourth jumps to address
by storing address in the PC. |
| |
|
| |
We could write a simple program that uses all
four instructions. |
| |
|
| |
LD A, 05H |
| |
INC A |
| |
INC A |
| |
DEC A |
| |
JP, 0000H |
| |
|
| |
Assembling the program above involves taking the
assembly language and changing it into HEX code. |
| |
|
| |
| |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
| 0000 |
3E |
05 |
E4 |
E4 |
E5 |
D6 |
00 |
00 |
|
| |
|
| |
The machine code (ie, the HEX equivalent of our
program) is stored in ROM, starting at address 0000H. Therefore, the
program loads 05H into A, increases A by one twice and then decreases A
by one once. It then jumps back to 0000H (ie, the start of the
program). This program would loop forever. |
| |
|
| |
Try out EdSim51's Execution Cycle Simulation - part 2. |
| |
|
| |
|
| |
Conditional Jump |
| |
One more instruction is now added to
our basic instruction set - a conditional jump, as detailed in the
table below. |
| |
|
| |
| Assembly |
HEX Equivalent |
Operation |
Size of Instruction |
| INC A |
E4 |
(A) <- (A) +
1 |
1 byte |
| DEC A |
E5 |
(A) <- (A) -
1 |
1 byte |
| LD A, data |
3E, data |
(A) <- data |
2 bytes |
| JP, address |
D6, address |
(PC) <-
address |
3 bytes |
| JP Z, address |
D7, address |
if (A) = 0 (PC)
<- address
if (A) != 0 (PC) <- (PC) + 3
|
3 bytes |
|
| |
|
| |
JP Z, address can is described as
follows: if the contents of A are zero, jump to address,
otherwise continue with next instruction.
|
| |
|
| |
Now we write a second program.
|
| |
|
| |
ORG 0130H
|
| |
LD A, 03H |
| |
DEC A |
| |
JP Z, 0130H |
| |
JP 0132H |
| |
|
| |
The machine code equivalent of the above program
is: |
| |
|
| |
| |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
| 0130 |
3E |
03 |
E5 |
D7 |
30 |
01 |
D6 |
32 |
01 |
|
| |
|
| |
Note the program starts at location 0130H. This
was specified by the ORG statement. We stated earlier that the program
counter is loaded with 0000H on power up. However, the system can be
designed so that an address other than 0000H is placed in the PC on
power up. This is illustrated in the second example below. |
| |
|
| |
Try out EdSim51's Execution Cycle Simulation - part 2 (with
conditional jump). |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
Copyright (c) 2005-2006 NyCelt LLC
|