Upload
esse-raaiz
View
69
Download
7
Embed Size (px)
DESCRIPTION
8051 addressing modes notes
Citation preview
1
The 8051 Microcontrollerand Embedded Systems
Chapter 5
Addressing Modes
From the text by Mazidi & Mazidi (2000)Presentation developed by Martin Hebel
3
• Data can be addressed in various ways, such as register, RAM or code space.
• The 8051 provides 5 addressing modes:– Immediate– Register– Direct– Register Indirect– Indexed
4
Immediate Addressing• Operand is a constant, or value written in
code.
• Signified by a leading #
MOV A, #25MOV R4, #85HMOV DPTR, #2550H
ACCEL EQU 32MOV A, #ACCEL
5
Register Addressing• R0-R7 are the registers being addressed.
• The actual RAM location depends on which bank is selected.MOV A, R0MOV R1, AMOV R4, R7
• Register instructions typically use fewer bytes and may be faster than direct addressing.
6
Direct Addressing• Used to access RAM addresses 00 – FFh,
though typically above register banks.MOV A, 45HMOV R1, 50MOV 35H, A
These perform the same if Register Bank 0 is selected:MOV 4, AMOV R4, A
7
SFR and Addresses• Special Function Registers (SFRs) are in
RAM locations 80H-FFH.
• Contain A, PSW, DTPT, B, and numerous other registers used by the 8051.
• All registers are accessible using direct addressing with either their address or mnemonic:MOV 0E0H,#55MOV A, #55
10
Often, when using the accumulator, it is part of the OpCode:MOV A, #55OpCode means to Move into AOperand (2nd byte) is value 55.
Some instructions, such as PUSH and POP, cannot use A (not part of opCode) and must use direct addressing:PUSH 0E0HPUSH Acc
11
Register Indirect• R0 and R1 are used to POINT to a RAM
address.
• The @ is used to indicate Register Indirect addressing.
• Allows loops and other means to access a range of RAM.
13
Indexed Addressing• Data pointer is used to access data in ROM.• Accumulator is used as a pointer offset
MOVC A, @A+DPTR
ORG 0000HMOV DPTR, #200HMOV A, #00H
loop: MOVC A, @A+DPTRMOV SBUF A
…ORG 200H
MyData: DB "Hello World!"
14
• Can be used to index a lookup table
MOV DPTR, #Squares
MOV A, P1MOVC A, @A+DPTR
…
ORG 300HSquares: DB 0, 1, 4, 9, 16, 25, (etc)
15
• Write a program that will copy the value of the DIP switches into memory using register indirect addressing when SW1 is toggled. Copy 10 bytes of data.
• After the 10 bytes are stored, replay them on the LEDs.
16
Single Bit Instructions
From the text by Mazidi & Mazidi (2000)Presentation developed by Martin Hebel
18
• Some instructions manipulate or operate based on a single bit.
SETB bit Sets the bit (1)CLR bit Clears the bit (0)CPL bit Compliment BitJB bit, target Jump bit setJNB bit, target Jump bit not setJBC bit, target Jump if bit set then
clear
19
• All bits of all 4 ports may be independently addressed:
SETB P2.4CLR P1.3MOV C, P2.1
Wait: JNB P2.2, Wait
20
• Many SFRs in the 8051 are bit addressable, but some are not.
• Just as RAM has byte addresses, addressable bits also have bit addresses.
22
Operations with CY• CY is the work-horse of the bit operations
just as the Accumulator is for bytes.