6422.addressing modes
TRANSCRIPT
-
8/4/2019 6422.Addressing Modes
1/13
Addressing Modes
Rupinder Jawanda
Assistant Professor
ECE deptt.
CU
-
8/4/2019 6422.Addressing Modes
2/13
Introduction CPU can access data in various ways, which
are called addressing modes. Addressing Modes are an integral part of
each computers instruction set.
Data is stored at a SOURCE address andcopied to a DESTINATION address.
There are 28 distinct mnemonics that copydata from source to destination, they may be
divided into following types: MOV destination, source
PUSH source , or POP destination
XCH destination, source
-
8/4/2019 6422.Addressing Modes
3/13
Addressing Modes
The following addressing modes are usedto access the data :
Immediate Addressing Mode
Register Addressing Mode
Direct Addressing Mode
Register Indirect Addressing Mode
Indexed Addressing Mode
-
8/4/2019 6422.Addressing Modes
4/13
Immediate Addressing Mode The source operand is a constant rather
than a variable and constant can beincorporated into instruction as a byte ofimmediate data.
In Assembly language, immediate operandsare preceded by a pound sign #.
Value can be loaded into any registers,including 16-bit DPTR register.
MOV A , #nH or
MOV Ri , # nH (i varies from 0 to 7 )Examples :MOV A,#45H ;load 45H into AMOV R4,#79 ;load 79 into R4
Impossible to have immediate data as a destination
-
8/4/2019 6422.Addressing Modes
5/13
Register Addressing Mode
Use registers to hold the data to bemanipulated.
Certain register names may be used as apart of opcode mnemonic as source or
destinations of data.MOV A , Ri or
MOV Ri , A (i varies from 0 to 7)
Examples :MOV A, R4
MOV R7, A
Register to Register moves using Register Addressing Mode occur between A andR0 to R7
-
8/4/2019 6422.Addressing Modes
6/13
Direct Addressing Mode All 128 bytes of internal RAM and SFRs may be
addressed directly using the single-byte addressassigned to each RAM location and each SFR.MOV A, addressMOV address, AMOV Ri, addressMOV address, RiMOV address1, address2Examples:MOV A, 45HMOV 45H, AMOV R5, 89HMOV OEOH , 80H
MOV instructions that refer to the direct addresses above 7F that are not SFRswill result in errors.
-
8/4/2019 6422.Addressing Modes
7/13
PUSH And POP Opcodes
Only direct addressing mode is allowed
for pushing or popping the stack
PUSH Source Address
POP Destination Address
PUSH A ---- invalid
PUSH OEOH --- valid
POP R2 ---- invalidPOP 2 ---- valid
RAM ends at address 7FH ; PUSHes above 7FH result in errors.SP is usually set at addresses above the register banks.
-
8/4/2019 6422.Addressing Modes
8/13
Register Indirect Addressing Mode Indirect Addressing mode uses a register to hold the actual
address that will be used in the data move.
For MOV opcodes register R0 and R1 are used, often calledDATA POINTERS, to hold the address of one of the datalocations which could be a RAM or an SFR address.
Mnemonic used for Indirect addressing mode is @
MOV @Rp, #n H
MOV @Rp , address
MOV @Rp , A
MOV A, @Rp (p varies between 0 and 1)
Examples :
MOV @R1, #35HMOV A, @R0
MOV 78H, @R1
* R2R7 cannot be used to hold the address of an operand located in RAM
* The advantage is that it makes accessing data dynamic rather than static as indirect addressing mode
-
8/4/2019 6422.Addressing Modes
9/13
Indexed Addressing Mode Indexed addressing mode is widely used in accessing
data elements of look-up table entries located in theprogram ROM. Access to this data is made possible by using indirect
addressing mode and register A in conjunction witheither the PC or DPTR.
MOVC A,@A+DPTR or MOVC A,@A+PCinstructions are used for this purpose.
Use instruction MOVC, C means code The contents of A are added to the pointing register
(DPTR or PC) to form the 16-bit address of theneeded data.
The data is then fetched from the ROM address soformed and placed in the A register.
-
8/4/2019 6422.Addressing Modes
10/13
Indexed Addressing ModeExamples :
MOV DPTR , # 0500HMOV A , # 50 H
MOVC A, @A+ DPTR ( Copy the contents of address 550H toA)
MOV PC , # 2000HMOV A , # 50H
MOVC A, @ A+PC ( Copies the content of address 2051 to A)
NOTE :
PC is incremented by one ( to point to the next instruction)before it is added to A to form the final address of the codebyte
MOVC is normally used with internal or external ROM andcan address 4K of internal or 64 K bytes of external code.
-
8/4/2019 6422.Addressing Modes
11/13
External Data Moves 64Kbytes of RAM and ROM can be added externally.
Opcodes that access this external memory always use indirect
addressing to specify the external memory. R0, R1 and DPTRuse to hold the address of the data byte in
external RAM.
R0 and R1 are limited to external RAM address range of 00H to0FFH.
DPTR can address the maximum RAM space of 0000H - 0FFFFH X is added to the MOV to serve as a reminder that data move is
external to 8051
MOV X A, @Rp ( copy the contents of external address in Rp to A)
MOVX A, @DPTR (copy the contents of external address in DPTR
to A)Note :
All external data moves involve Register A
MOVX is normally used with external RAM or I/O addresses.
-
8/4/2019 6422.Addressing Modes
12/13
Data Exchanges
MOV, PUSH and POP opcodes involve copying from thesource to destination.
Exchange instructions actually move the data in twodirections i.e. from source to destination and fromdestination to source.
All addressing modes except the immediate may be usedin XCH(exchange) opcodes
XCH A, Rr (exchange data bytes between A & Rr)XCH A, addressXCH A, @RpXCHD A, @Rp (exchange lower nibble between A and
address in Rp)Examples:XCH A, R5XCH A, 0F9H
XCHD A, @R1
-
8/4/2019 6422.Addressing Modes
13/13
Data Exchanges
All exchanges are internal to 8051.
All exchanges use register A.
When using XCHD, upper nibble of A andthe Register Rp do not change.