of 50
8/13/2019 AL 31
1/50
Assembly Language Programming
2
8051 Microcontroller
8/13/2019 AL 31
2/50
CourseOutline
3
Week Topic
1 Introduction
28051Microcontroller
Architecture
3 Assembly Language
4 Assembly Language Contd.
5, 6
Timers and Counters
Serial Port
Interrupt7 Design and Interface Examples
88086 / 8088 Microprocessor
Introduction and Architecture
9 Midterm Exam
10 Hardware and Design
11 Programming in Assembly
12 PIC 18 F Microcontroller Introduction, Architecture, I/O Pins
13 Programming
14 Timers
15, 16 Peripherals of PIC 18F Microcontrollers
17 Revision
8/13/2019 AL 31
3/50
AssemblyLanguage
Introduction Instruction Set
Software - Keil
AssemblerDirectives
4
8/13/2019 AL 31
4/50
Programming Languages
Assembly is aLowLevelLanguage High Level
Middle Level
Low Level
5
Assembly
C++
C
FORTRAN
Pascal
COBOL
BASIC
8/13/2019 AL 31
5/50
Assembly LanguageLow Level Language
English-like abbreviations Represent basic operations of computer
Translated to machine language Assemblers convert to machine language
High speed conversion
Easier for human interpretation as comparedlanguage
to Machine
Still tedious and difficultMany instructions for simple tasks
These problems led to High Level languages
6
8/13/2019 AL 31
6/50
GeneralFormatofAssemblyProgram
7
8/13/2019 AL 31
7/50
Assembly Language General Format of
Assembly Program
mnemonics operand , [operands]
Sourcedestination,
[label]: mnemonics operand , [operands]Sourcedestination,
Brackets shows that the component is optional
8
8/13/2019 AL 31
8/50
Assembly Language
General Format ofAssembly Program[label]: mnemonics operand , [operands]
Sourcedestination,
Labels: are used toname
represent addressof a line witha
Labels must end with a colon
Operand: on which the operation is performed
9
8/13/2019 AL 31
9/50
Assembly Language General Format of
Assembly Program
[label]: mnemonics operand , [operands]
Sourcedestination,
Mnemonics: InstructionExample:
or command
mov A,#67h mov is mnemonic A and #67h are operands
10
8/13/2019 AL 31
10/50
Assembly Language
Comments Comment begins with a semicolon (;) Assemblerignores the comments
Example:;Thisisacomment
11
8/13/2019 AL 31
11/50
Instruction Set
8051 Instructions have 8 bit Opcode28 Combinations = = 256 255 are 139
92 24
implemented1
23
Byte
ByteByte
instructions
instructionsinstructions
1 Machine Could take
instruction
cycle = 12 clock cycles1, 2 or 4 Machine Cyclesto execute an
12
8/13/2019 AL 31
12/50
InstructionSetSummary
13
8/13/2019 AL 31
13/50
InstructionSet
14
8/13/2019 AL 31
14/50
8/13/2019 AL 31
15/50
Keil for Assembly Programming of 8051
16
Keil Vision
8/13/2019 AL 31
16/50
UsingKeilforAssemblyProgramming
17
8/13/2019 AL 31
17/50
NewProject
18
8/13/2019 AL 31
18/50
SelectDevice
19
8/13/2019 AL 31
19/50
NewFile(forcode)
20
8/13/2019 AL 31
20/50
8/13/2019 AL 31
21/50
AddCodetoProject
22
8/13/2019 AL 31
22/50
Debug Mode
Write Code Save (Ctrl + S)
Build Target File
Debug Mode
(F7)
Ctrl+F5
23
8/13/2019 AL 31
23/50
DebugMode
24
8/13/2019 AL 31
24/50
DebugMode
Registers
Accumulator
PSW
25
8/13/2019 AL 31
25/50
Disassembly(onlyindebugmode)
26
8/13/2019 AL 31
26/50
Disassembly(onlyindebugmode)
27
8/13/2019 AL 31
27/50
Disassembly(onlyindebugmode)
28
8/13/2019 AL 31
28/50
8/13/2019 AL 31
29/50
8/13/2019 AL 31
30/50
Assembler Directives Change state of assembler
Define Symbols, add informationto the object file etc
Must not be confused withInstructions.Theydonotproduceexecutablecode
31
8/13/2019 AL 31
31/50
Assembler Directives
Address ControlSymbol Definition
1.
2.
3.
4.
MemoryOthers
Initialization
32
8/13/2019 AL 31
32/50
Assembler DirectivesAddress Control
ORG, USINGSymbol Definition
Generic Symbols: EQU,
1.
2.SET
Address Symbols: BIT,SFR Symbols: sfr, sbit
Memory Initialization
DBIT, DB, DW
OthersEND
DATA,XDATA
3.
4.
33
8/13/2019 AL 31
33/50
8/13/2019 AL 31
34/50
Address ControlORG Changes location counter of currently active segment
Sets new origin for subsequent statements
Format
ORG expression
where expression must be an absolute address without any forward references
Only absolute addresses and symbols in current segment can be used
When ORG statement is encountered, the assembles calculatesvalue of the expression and changes location counter of current
segment
Examples
ORG 100HORG RESTART
35
8/13/2019 AL 31
35/50
Address ControlUSING
4 Register Banks USING specifies Format
whichRegister Bank isactive
USING expression
where
expressionvalue fromis the register bank number0 and 3 and itmust be a
36
8/13/2019 AL 31
36/50
Symbol Definition Symbols and labels can
from the following list:becomposed of31characters
A -Z, a - z,0 - 9, _ and ?
A9
symbolcanstartwithanyoftheseexceptthedigits0-
37
8/13/2019 AL 31
37/50
Symbol DefinitionEQU and SET Used to create symbols
and addresses Similar to Define in C
that represent registers, numbers
Assign a numeric value / register symbol to the specificsymbol nameDifference between EQU and SET
Symbols defined with EQU may not haven been
previously defined by EQU and can not be redefined
The SET directive allows later redefinition of symbols
38
8/13/2019 AL 31
38/50
Symbol DefinitionEQU and SET FormatsofSET/ EQU statements are:
symbol EQU expressionsymbol EQU register
symbol
symbol
SET expression
SET register
39
8/13/2019 AL 31
39/50
Symbol DefinitionEQU and SET symbol is the name of symbol to define
expression specified will be substituted for eachoccurrence of the symbol used in program. expressionnumeric expression which has no forward references
is
register is one of the 8 registers (in the active bank)
40
8/13/2019 AL 31
40/50
Symbol DefinitionExamples
LIMIT EQU 1200 VALUE EQU LIMIT-200
SERIAL EQU SBUF
VALUE SET 100
COUNTERSET R1COUNTERCOUNTER*VALUE
TEMP TEMP
SETSET
41
8/13/2019 AL 31
41/50
8/13/2019 AL 31
42/50
Symbol Definition - Address Symbols
The BIT, DATA, and XDATA directives assignvalue to the specified symbol
an address
Symbols defined with the BIT, DATAandXDATAdirectivescannotbechangedorredefined
43
8/13/2019 AL 31
43/50
Symbol Definition - Address SymbolsFormat: BIT, DATA, XDATA
symbol BIT bit_address ; defines a BITsymbol
symbol DATAdata_address ; defines a DATA symbol
symbolXDATAxdata_address ; defines XDATA symbol
44
8/13/2019 AL 31
44/50
Symbol Definition - Address SymbolsFormat: BIT, DATA, XDATA
Symbol: name of symbol to be defined
Bit_address: is the address of a bit in internalmemory in the area 20h to 2Fh data
Data_address: data memory address
xdata_address is an xdata memory address65535
inrange0 to
45
8/13/2019 AL 31
45/50
Symbol Definition SFRSymbolssfr, sbitsfr
sfr symbol = address
sbit
sbit symbol = bit-address
Sfr_symbol is the name of symbol to bedefined address is an SFR address with which the symbol
associated bit-address is address of an SFR Bit
is to be
46
8/13/2019 AL 31
46/50
8/13/2019 AL 31
47/50
Memory Initialization
Memory initialization directivesareusedtoinitializecodeor constant space in byteunits
DBIT Used
DB
Used
DW
todefinea bit
todefinebyte 8 bit
UsedtodefineWord 16 bits
48
8/13/2019 AL 31
48/50
8/13/2019 AL 31
49/50
Assembler Directives - OthersEND
Signals the end of assembly module Any text that appears after END is ignored
END directive is required in every assemblymoduleIfmissing,awarningmessageisgenerated byassembler
50
8/13/2019 AL 31
50/50
Number RepresentationD (or nothing) Decimal
H for Hex
Q for Octal
B for Binary