2. Module 3
• Addressing modes: Immediate addressing,
Register addressing, indirect addressing,
relative addressing, absolute addressing ,
indexed addressing
• Instruction set: Assembler directives Data
exchange, Arithmetic instructions, rotate
instruction and data serialization, loop and
jump instruction, call instructions, time delay,
Assembly language programs
3. Addressing Modes
“What is an addressing mode ?“
A simple question always has a simple answer
too. Addressing mode is a way to address an
operand. Operand means the data we are
operating upon (in most cases source data). It
can be a direct address of memory, it can be
register names, it can be any numerical data
etc.
4. • There are 5 different ways to execute this
instruction and hence we say, we have got 5
addressing modes for 8051. They are---
1) Immediate addressing mode
2) Direct addressing mode
3) Register direct addressing mode
4) Register indirect addressing mode
5) Indexed addressing mode
5. 1.Immediate Addressing Mode
• we can write MOV A, #data
• This addressing mode is named as “immediate” because it
transfers an 8-bit data immediately to the accumulator
(destination operand).
• Note: The ‘#’ symbol before 6AH indicates that operand is a
data (8 bit). If ‘#’ is not present then the hexadecimal number
would be taken as address.
6. 2.Direct Addressing Mode
• This is another way of addressing an operand.
Here the address of the data (source data ) is
given as operand.
• MOV A, 04H
• Here 04H is the address of register 4 of register
bank 0. When this instruction is executed, what
ever data is stored in register 04H is moved to
accumulator.
7. 3.Register Direct Addressing Mode
• In this addressing mode we use the register
name directly (as source operand). An
example is shown below.
• MOV A, R4
• in register direct addressing mode, data
is transferred to accumulator from the register
8. 4. Register Indirect Addressing Mode
In this addressing mode, address of the data
(source data to transfer) is given in the register
operand.
• MOV A, @R0
• Here the value inside R0 is considered as an
address, which holds the data to be transferred
to accumulator.
9. 5.Indexed Addressing Mode
MOVC A, @A+DPTR and MOVC A, @A+PC
• where DPTR is data pointer and PC is program counter (both
are 16 bit registers)
MOVC A, @A+DPTR
What’s the first impression you have now?
The source operand is @A+DPTR and we know we will get the
source data (to transfer) from this location.
It is nothing but adding contents of DPTR with present content
of accumulator.
This addition will result a new data which is taken as the
address of source data (to transfer).
The data at this address is then transferred to accumulator
10. • The other example MOVC A, @A+PC works
the same way as above example.
• The only difference is, instead of adding DPTR
with accumulator, here data inside program
counter (PC) is added with accumulator to
obtain the target address.
11. INSTRUCTION CY OV AC
ADD X X X
ADDC X X X
SUBB X X X
MUL 0 X
DIV 0 X
DA X
RRC X
RLC X
SETB C 1
CLR C 0
CPL C X
ANL C,BIT X
ORL C,BIT X
MOV C,BIT X
CJNE X
** NOTE – X CAN BE ‘0’ OR ‘1’
INSTRUCTIONS THAT
AFFECT FLAG BITS
12. MACHINE CYCLE TAKEN UP BY
THE DIFFERENT INSTRUCTIONS
OF 8051 MicroController
INSTRUCTION MACHINE
CYCLE
MOV R3, #VALUE 1
ADD , ADDC , SUBB 1
CLR bit 1
CPL bit 1
SETB bit 1
INC RX, DEC RX 1
NOP 1
INC DPTR 2
DJNZ 2
PUSH 2
POP 2
MOVX, MOVC,
MOV DPTR, #VALUE
2
LJMP 2
SJMP 2
MUL AB 4
DIV AB 4
NOTE :
REFER TEXT BOOK FOR MORE INSTRUCTIONS & THEIR
Machine Cycle
20. SHORT JUMP ( SJMP)
• FORMAT : SJMP 8BitAddress
• FUNCTION : Transfers control unconditionally to
a new address
-- 2 byte instruction
--First byte is opcode, second byte is signed number displacement ,
which is added to PC of the instruction following the SJMP to
target address
--Target address must be with in -128 to +128 bytes of the pc
-- If the most significant bit of relative address byte is 1, then the
short jump instruction is back jump, else it is considered as
forward jump.
21. LONG JUMP ( LJMP)
FORMAT : LJMP 16BitAddress
FUNCTION : Transfers control unconditionally to a new
address
-- It is A 3 byte instruction
-- First byte is opcode, and the next two byte is the target
address
--Target address is any address within 64k byte code
space of 8051 mc
22. ABSOLUTE JUMP (AJMP)
• FORMAT: AJMP Target Address
• FUNCTION: Transfers program execution to
the target address unconditionally
-- THE TARGET ADDRESS FOR THIS MUST BE
WITHIN 2K BYTES PF PROGRAM MEMORY
23.
24.
25. Call instructions
1. ACALL (Absolute call)
2. LCALL (Long call)
• These two instructions allow the programmer to call a
subroutine
• Subroutines are often used to perform tasks that need
to be performed frequently. This makes a program
more structured in addition to saving memory space.
26. 1. ACALL target address
Flags affected: none
Functions: it calls subroutines with a target address
within 2K bytes from the current PC
FORMAT : ACALL 11BITADDRESS
• 2-byte instruction
• target address of ACALL must be within a 2K-byte range.
27. 2. LCALL 16 bit address
Function : transfers control unconditionally to a new address
FORMAT : LCALL 16 bit address
• 3-byte instruction
• first byte is the opcode and the second and third bytes are used
for the address of the target subroutine
• call subroutines located anywhere within the 64K-byte address
space of the 8051
When a subroutine is called, control is transferred to that
subroutine, and the processor saves the PC (program counter) on
the stack and begins to fetch instructions from the new location.
After finishing execution of the subroutine, the instruction RET
(return) transfers control back to the caller. Every subroutine
needs RET as the last instruction.
30. Rotate instructions
MNEMONICS OPERATION EXAMPLE BYTES
RL A Rotate left the
accumulator
RL A 1
RLC A Rotate A left
through carry
RLC A 1
RR A Rotate A right RR A 1
RRC A Rotate A right
through carry
RRC A 1