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

4-8051 - Assembly Language Programming Basics and 8-Bit Arithmetic Operations-25-07-2024

Assembly Language Programming Basics and 8-bit Arithmetic Operations

Uploaded by

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

4-8051 - Assembly Language Programming Basics and 8-Bit Arithmetic Operations-25-07-2024

Assembly Language Programming Basics and 8-bit Arithmetic Operations

Uploaded by

Hardik Singla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Microprocessors and Microcontrollers

BECE204L

Dr Vishal Gupta
Assistant Professor
School of Electronics Engineering
VIT Vellore, Tamil Nadu, India
8051 Microcontroller:
Addressing Modes
Addressing Modes
❑“What is an addressing mode ?“
Addressing mode is a way to address an operand. Operand means the data we
are operating upon (in most cases source data).
Or
An Addressing Mode is a way to locate a target Data, which is also called as
Operand.
➢ It can be a direct address of memory,
➢ It can be register names,
➢ It can be any numerical data etc.
8051 Addressing Modes
• The CPU can access data in various ways, which are called
addressing modes.

1. Immediate addressing mode.


2. Register direct addressing mode.
3. Direct addressing mode.
4. Register indirect addressing mode.
5. External Direct or indexed addressing mode.
Immediate Addressing Mode
❖ This addressing mode is named as “immediate” because it transfers an 8-bit data
immediately to the accumulator (destination operand).
❖ Data is immediately available in the instruction.
❖ The source operand is a constant.
❖ The immediate data must be preceded by the sign, “#”.
❖ Can load information into any registers, including 16-bit DPTR register.

MOV A, #data DPTR can also be accessed as


two 8-bit registers, the high
byte DPH and low byte DPL.
Immediate Addressing Mode
MOV A, #6AH
❑ The opcode for MOV A, # data is 74H.
The opcode is saved in program
memory at 0202 address.
❑ The data 6AH is saved in program
memory 0203 (any part of the program
memory can be used).
❑ When the opcode 74H is read, the next
step taken would be to transfer whatever
data at the next program memory.
address (here at 0203) to accumulator A.
❑ This instruction is of two bytes and is
executed in one cycle.
❑ After the execution of this instruction,
program counter will add 2 and move to
0204 of program memory.
Register direct Addressing Mode
❑ In this addressing mode we use the register name directly (as source operand)
❑ Data is available in the registers specified in the instruction.
❑ Use registers to hold the data to be manipulated.

❑ The source and destination registers must match in size.


MOV DPTR, A will give an error.
Register direct Addressing Mode
❑ The opcode is stored in program memory
MOV A, R4 ❑ Opcode for MOV A, R4 is EC. address 0202 and when it is executed the
control goes directly to R4 of the
respected register bank.
❑ If RB0 is selected, then the data from
R4 of register bank RB0 will be
moved to accumulator.
❑ 04H is the address of R4 of RB0.
❑ Here 2FH is getting transferred to
accumulator from data memory
location 0C H (dotted line) in Register
4 (R4) of RB1.
❑ The instruction is 1 byte and requires
1 cycle for complete execution.
❑ Register direct addressing mode can
save program memory.
Register direct Addressing Mode
❑ The movement of data between Rn registers is not allowed.
MOV R4, R7 is invalid.
❑ We can get the same result by using this instruction:
MOV R5, 07H, or
MOV 05H, R7.
❑ These two instructions will work when the selected register bank is RB0.
❑ To use another register bank and to get the same effect, we have to add the starting
address of that register bank with the register number.
❑ For an example, if the RB2 is selected, and we want to access R5, then the address will
be (10H + 05H = 15H), so the instruction will look like this
MOV 15H, R7
Here 10H is the starting address of Register Bank 2.
Accessing Memory
❖ Direct Addressing
❖ Register Indirect
❖ Indexed
Direct Addressing Mode
❑ This is another way of addressing an operand. Here the address of the data (source
data) is given as operand.
❑ Address of the data is available in the instruction.

❑ The direct addressing mode is most often used to access RAM locations 30–7FH.

❑ The entire 128 bytes of RAM can be accessed.

❑ Contrast this with immediate addressing mode, there is no “#” sign in the operand.

❑ Ex: MOV A, 4 ; is same as MOV A, R4 ; Register addressing mode (which


means copy R4 into A)
Direct Addressing Mode
MOV A, 04H ❑ This is a 2-byte instruction which requires 1 cycle to complete.
❑ Program counter will increment by 2 and
stand in 0204.
❑ The opcode for instruction MOV A, address
is E5H.
❑ When the instruction at 0202 is executed
(E5H), accumulator is made active and
ready to receive data.
❑ Then program control goes to next address
that is 0203 and look up the address of the
location (04H) where the source data (to be
transferred to accumulator) is located.
❑ At 04H the control finds the data 1F and
transfers it to accumulator and hence the
execution is completed.
SFR Addresses
SFR Addresses
SFR Registers & their Addresses
MOV 0E0H, #55H ;is the same as
MOV A, #55H ;which means load 55H into A (A=55H)

MOV 0F0H, #25H ;is the same as


MOV B, #25H ;which means load 25H into B (B=25H)

MOV 0E0H, R2 ;is the same as


MOV A, R2 ;which means copy R2 into A

MOV 0F0H, R0 ;is the same as


MOV B, R0 ;which means copy R0 into B
Example
Register Indirect Addressing Mode
❑ In this addressing mode, address of the data (source data to transfer) is given in the
register operand.
❑ The address of the data is available in registers.
❑ A register is used as a pointer to the data.
❑ Only register R0 and R1 are used for this purpose and all register banks are allowed.
❑ R2 – R7 cannot be used to hold the address of an operand located in RAM.
❑ When R0 and R1 hold the addresses of RAM locations, they must be preceded by
the “@” sign.
Register Indirect Addressing Mode
MOV A, @R0 ❑ This is a 1-byte instruction, and the
program counter increments 1. ❑ The opcode for MOV A, @R0
is E6H. Assuming that RB0 is
selected. The R0 of RB0 holds
the data 20H.
❑ The value inside R0 is
considered as an address,
which holds the data to be
transferred to accumulator.
❑ Program control moves to 20H
where it locates the data 2FH
and it transfers 2FH to
accumulator. after executing
this instruction.
Register Indirect Addressing Mode
❑ Write a program to copy the value 55H into RAM memory locations 40H to 41H using
(a) Direct addressing mode.
(b) Register indirect addressing mode.
Register Indirect Addressing Mode
❑ The advantage is that it makes accessing data dynamic rather than static as indirect
addressing mode.
❑ Looping is not possible indirect addressing mode.
❑ R0 and R1 are the only registers that can be used for pointers in register indirect
addressing mode
❑ Since R0 and R1 are 8 bits wide, their use is limited to access any information in
the internal RAM.
❑ When accessing externally connected RAM, we need 16-bit pointer. In such case,
the DPTR register is used
Indexed Addressing Mode
❑ Indexed addressing mode is widely used in accessing data elements in the program
ROM.
❑ The instruction used for this purpose is MOVC A, @A+DPTR.
❑ Use instruction MOVC, “C” means code byte.
MOVC A, @A+DPTR
MOVC A, @A+PC
❑ The source operand is @A+DPTR and we will get the source data (to transfer)
from this location.
❑ The contents of Accumulator are added to the 16-bit register DPTR to form the
16-bit address of the needed data.
❑ 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.
Indexed Addressing Mode
MOVC A, @A+DPTR
❑ The opcode for the instruction is 93H.
❑ DPTR holds the value 01FE, where 01
is located in DPH and FE is located in
DPL.
❑ Accumulator now has the value 02H.
❑ A 16-bit addition is performed and
now 01FE H+02 H results in 0200 H.
❑ What ever data is in 0200 H will
get transferred to accumulator.
❑ The previous value inside accumulator
(02H) will get replaced with new data
from 0200H.
Any Questions?

24
Thank you!

You might also like