Lecture-2 (Microcontroller Based Design)
Lecture-2 (Microcontroller Based Design)
Design
MT 312
Lecture-02
Main Objectives
Introduction to 8051 Assembly
Programming
Registers
Registers
MOV Instruction
Notes
ADD instruction
Assembly Language
Assembly Language
Structure
Steps in Programming
The step of Assembly language program are outlines
as follows:
1) First we use an editor to type a program, many
excellent editors or word processors (e.g., Notepad)
are available that can be used to create and/or edit
the program
For many assemblers source file has the extension asm
or src, depending on which assembler you are using
Steps in Programming
3) Assembler require a third step called linking
The linker program takes one or more object code files
and produce an absolute object file with the extension
abs
This abs file is used by 8051 trainers that have a
monitor program
Steps in Programming
Program Counter
The program counter points to the address of
the next instruction to be executed
As the CPU fetches the opcode from the
program ROM, the program counter is
increasing to point to the next instruction
The program counter is 16 bits wide
This means that it can access program
addresses 0000 to FFFFH, a total of 64K bytes
of code
On Power UP
All 8051 members start at memory address
0000 when theyre powered up
Program Counter has the value of 0000
The first opcode is burned into ROM address
0000H, since this is where the 8051 looks for
the first instruction when it is booted
We achieve this by the ORG directive in the
source program
ROM Contents
4K
16K
32K
Directives
The DB directive is the most widely used data
directive in the assembler
It is used to define the 8-bit data
When DB is used to define data, the numbers can be
in decimal, binary, hex, ASCII formats
4K
16K
32K
Directives
ORG (origin)
The ORG directive is used to indicate the beginning of
the address
The number that comes after ORG can be either in
hex and decimal
If the number is not followed by H, it is decimal and
the assembler will convert it to hex
END
This indicates to the assembler the end of the source
(asm) file
The END directive is the last line of an 8051 program
Mean that in the code anything after the END directive
is ignored by the assembler
Directives
EQU (equate)
This is used to define a constant without occupying a
memory location
The EQU directive does not set aside storage for a
data item but associates a constant value with a data
label
4K
When the label appears in the program, its constant
value will be substituted for the label (like parameter
32K
in Verilog)
Assume that there is a constant used in many
different places in the program, By the use of EQU,
one can change it once and the assembler will change
all of its occurrences