Professional Documents
Culture Documents
Assembly 1 PDF
Assembly 1 PDF
Assembly 1 PDF
Dr Mohsin Tiwana
Week 3 – 8051 Microcontroller
3
Course Outline
S/no. Topic
1 Introduction
8051Microcontroller
2
Architecture and Hardware
3 Assembly Language
4 Assembly Language Contd.
5 Timers and Counters
6 Serial Port
7 Interrupt
8 Design and Interface Examples
Arduino Microcontroller
9
PIC 18 F Microcontroller
10
Introduction, Architecture, I/O Pins
11 Programming in C
12 Timers / Counters
13 Using Internal ADC of PIC
14 Peripherals of PIC 18F Microcontrollers
15 RTOS/ FPGA
4
Week 3 – Assembly Language
Introduction
Instruction Set
Software - Keil
Assembler Directives
5
Programming Languages
Assembly is a Low Level Language
FORTRAN
High Level Pascal
COBOL
BASIC
C++
Middle Level C
6
Assembly Language
Low Level Language
English-like abbreviations
Represent basic operations of computer
7
General Format of Assembly Program
8
Assembly Language
General Format of Assembly Program
9
Assembly Language
General Format of Assembly Program
10
Assembly Language
General Format of Assembly Program
11
Assembly Language
Comments
Example:
; This is a comment
12
Instruction Set
8051 Instructions have 8 bit Opcode
Combinations = 28 = 256
255 are implemented
139 1 Byte instructions
92 2 Byte instructions
24 3 Byte instructions (139+92+24=255 instructions)
13
Instruction Set Summary
14
Instruction Set
15
Instruction Definition
mov a, #data
Bytes 2
Cycles 1
Encoding 0111 0100 dddd dddd
Operation (A) #data
Example
mov a, #3
7403
0111 0100 0000 0011
16
Keil µVision
18
New Project
19
Select Device
20
New File (for code)
21
Save File as filename.a51
22
Add Code to Project
23
Debug Mode
Write Code
Save (Ctrl + S)
Build Target File (F7)
Debug Mode
Ctrl + F5
25
Debug Mode
Registers
Accumulator
PSW
26
Disassembly (only in debug mode)
27
Disassembly (only in debug mode)
28
Disassembly (only in debug mode)
29
Assembly Programming for 8051
30
A51 Assembler
Assembler: Converts Assembly code to machine language
code
Second Pass
Forward references are resolved by using symbol table
31
Assembler Directives
Change state of assembler
32
Assembler Directives
1. Address Control
2. Symbol Definition
3. Memory Initialization
4. Others
33
Assembler Directives
1. Address Control
ORG, USING
2. Symbol Definition
Generic Symbols: EQU, SET
Address Symbols: BIT, DATA, XDATA
SFR Symbols: sfr, sbit
3. Memory Initialization
DBIT, DB, DW
4. Others
END
34
Address Control
35
Address Control
ORG
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 calculates
value of the expression and changes location counter of current
segment
Examples
ORG 100H
ORG RESTART
36
Address Control
USING
4 Register Banks
USING specifies which Register Bank is active
Format
USING expression
where
expression is the register bank number and it must be a
value from 0 and 3
37
Symbol Definition
Symbols and labels can be composed of 31 characters
from the following list:
A -Z, a - z, 0 - 9, _ and ?
38
Symbol Definition
EQU and SET
Used to create symbols that represent registers, numbers
and addresses
Similar to Define in C
Assign a numeric value / register symbol to the specific
symbol name
Difference 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
39
Symbol Definition
EQU and SET
Formats of SET / EQU statements are:
40
Symbol Definition
EQU and SET
symbol is the name of symbol to define
41
Symbol Definition
Examples
42
Symbol Definition
EQU and SET
Symbols defined with EQU and SET directive may used
anywhere in operands, expressions, or addresses etc.
43
Symbol Definition - Address Symbols
44
Symbol Definition - Address Symbols
Format: BIT, DATA, XDATA
45
Symbol Definition - Address Symbols
Format: BIT, DATA, XDATA
46
Symbol Definition – SFR Symbols
sfr, sbit
sfr
sfr symbol = address
sbit
sbit symbol = bit-address
47
Symbol Definition – SFR Symbols
sfr, sbit
Examples
48
Memory Initialization
DBIT
Used to define a bit
DB
Used to define byte – 8 bit
DW
Used to define Word – 16 bits
49
Memory Initialization - DB
DB
The DB directive initializes code memory with byte (8-bit)
values
Format
label: DB expression, expression
where
label is the symbol that is given the address of the initialized
memory
expression is a byte value. Each expression may be a value or a
symbol etc
Example
ORG 100h
REQ: DB 1,2,3,4,’A’
50
Assembler Directives - Others
END
51
Number Representation
D (or nothing) Decimal
H for Hex
Q for Octal
B for Binary
52