0% found this document useful (0 votes)
29 views

Lecture-2 (Microcontroller Based Design)

This document provides an introduction to 8051 assembly programming. It discusses the main registers used in 8051 assembly including the accumulator, data pointer, and program counter. It describes common instructions like MOV and ADD. It outlines the steps to program in assembly, including writing code in an editor, assembling the code, linking, and converting to a hex file. It also discusses directives like ORG, DB, EQU, and END that provide instructions to the assembler.

Uploaded by

KhuleedShaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Lecture-2 (Microcontroller Based Design)

This document provides an introduction to 8051 assembly programming. It discusses the main registers used in 8051 assembly including the accumulator, data pointer, and program counter. It describes common instructions like MOV and ADD. It outlines the steps to program in assembly, including writing code in an editor, assembling the code, linking, and converting to a hex file. It also discusses directives like ORG, DB, EQU, and END that provide instructions to the assembler.

Uploaded by

KhuleedShaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Microcontroller Based

Design
MT 312
Lecture-02

Main Objectives
Introduction to 8051 Assembly
Programming

Registers

Register are used to store information


temporarily, while the information could be
a byte of data to be processed, or
an address pointing to the data to be fetched

The vast majority of 8051 register are 8-bit


registers
There is only one data type, 8 bits (for
assembly programming)
With an 8-bit data type, any data larger than 8
bits must be broken into 8-bit chunks before it
is processed

Registers

There are a large number of registers, but the


ones which are generally used are as follows
A (Accumulator) For all arithmetic and logic
instructions
B, R0, R1, R2, R3, R4, R5, R6, R7
DPTR (data pointer), and PC (program counter)

MOV Instruction

Notes

Value (proceeded with #) can be loaded


directly to registers A, B, or R0 R7
MOV A, #23H
MOV R5, #0F9H (To show F is not a character we add
0)

If values 0 to F moved into an 8-bit register,


the rest of the bits are assumed all zeros
MOV A, #5, the result will be A=05; i.e., A =
00000101 in
binary
Moving a value that is too large into a register
will cause an error
MOV A, #7F2H ; ILLEGAL: 7F2H>8 bits (FFH)

ADD instruction

The ADD instruction tells the CPU to add the


source byte to register A and put the result in
register A
Source operand can be either a register or
immediate data, but the destination must
always be register A
ADD R4, A and ADD R2, #12H are invalid
since A must be the destination of any
arithmetic operation

Assembly Language

Assembly language instruction includes


a mnemonic (abbreviation easy to remember) the
commands to the CPU, telling it what to do with those
items
optionally followed by one or two operands

the data items being manipulated


A given Assembly language program is a series
of statements, or lines
Assembly language instructions tell the CPU
what to do
While Directives (or pseudo-instructions) give
directions to the assembler

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

2) The asm source file containing the program code


created in step 1 is fed to an 8051 assembler
The assembler converts the instructions into machine code
The assembler will produce an object file and a list file
The extension for the object file is obj while the extension for
the list file is lst

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

4) Next the abs file is fed into a program called


OH (object to hex converter) which creates a
file with extension hex that is ready to burn
into ROM
This program comes with all 8051 assemblers
Recent Programs combine all these functions.

Steps in Programming

The List File

The lst (list) file, which is optional, is very useful to the


programmer
It lists all the opcodes and addresses as well as errors
that the assembler detected
The programmer uses the lst file to find the syntax errors
or debug

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

Placing Code in ROM

ROM Contents

ROM Memory Map in 8051


Family
No member of 8051 family can access more
than 64K bytes of opcode (Why?)

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

You might also like