Professional Documents
Culture Documents
1
The physical address linked
with different SFR’s are listed
in table-5. So
MOV A, #25H
is the same as
MOV 0E0H , #25H
(try this with pinnacle)
90
- See example 7 for accessing
port using Direct add-mode
- PUSH A Invalid
2
- See example 8 for PUSH and pop
- In Register indirect addressing mode: register is used as a pointer to the data. Only register R0 and R1 are used
for this purpose and R2 –R7 cannot be used to hold the address of an operand located in RAM,
Example 9: MOV A, @R0 ; move contents of RAM, whose address is held by R0 into A
MOV @R1, B ;move contents of B into RAM, whose address is held by R1
Example 10: Write a program to copy the value of RAM PA=34h into ex RaM memory locations PA= 40H
using
(a) Direct addressing mode, (b) Register indirect addressing mode without a loop, and
(c) Using Register Indirect Memory addressing mode with a loop:
Solutions (a) MOV A, #55H ;load A with value 55H
MOV 40H, A ;copy A to RAM location 40H
MOV 41H, A ;copy A to RAM location 41H
(b) MOV A, #55H ;load A with value 55H
MOV R0, #40H ;load the pointer. R0=40H
MOV @R0, A ;copy A to RAM R0 points to
INC R0 ;increment pointer. Now R0=41h
MOV @R0, A ;copy A to RAM R0 points to
(c) MOV A, #55H ;A=55H
MOV R0, #40H ;load pointer.R0=40H,
MOV R2, #02 ;load counter, R2=3
AGAIN: MOV @R0, A ;copy 55 to RAM R0 points to p.a=40h
INC R0 ;increment R0 pointer
DJNZ R2, AGAIN ;loop until counter = zero
- The advantage of using Register direct Memory addressing mode is it allows data access in a dynamic rather
than static method, as in Direct addressing mode Looping is not possible in Direct addressing mode
Example 11: Write a program to copy a block of 10 (Dec) bytes of data from RAM addresses: 35H to 60H
Solution: MOV R0,#35H ;source pointer
MOV R1,#60H ;destination pointer
MOV R3,#10 ;counter
BACK: MOV A,@R0 ;get a byte from source
MOV @R1,A ;copy it to destination
INC R0 ;increment source pointer
INC R1 ;increment destination pointer
DJNZ R3,BACK ;keep doing for ten bytes
- Home work 1: Write an efficient program that will clear 17D RAM locations starting from P.A.=25H
- 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
- Whether accessing externally connected RAM or on-chip ROM, we need 16-bit pointer. In such case, the DPTR
register is used
3
- Indexed addressing mode is widely used in accessing data elements of look-up table entries located in the
program ROM (internal and/or external)
If data
ROM
with
only
Table
of
data
DB…
then
use
MOVX
- MOV DPTR, #1234H…..MOVX A, @ DPTR ext. RAM data byte-contents of P.A.=1234H is moved to ‘A’
this is different from indirect memory addressing mode of RAM as contents of @DPTR is loaded in Register A
- Example
- MOV A,#0H ; MOV DPTR, #34H ; MOVC A,@A+DPTR ‘A’ is loaded with content of ROM P.A.=1234H
- MOV DPTR, #34H; MOVX@ DPTR, A ‘A’ is loaded with content of ext. RAM with P.A.=1234H
Example1: Write a program to copy the value of RAM PA=34h into ext- RAM PA= 40H
Solution: MOV DPTR, #0040h…. MOV A,34H….MOVX@DPTR,A
(remember that from ROM we can only “read data”)
Example2: In 8053, write a program to copy the value of RAM PA=42h into ext- ROM PA= 50H
Solution: MOV DPTR, #0000h…. MOV A,34H….MOVC @A+DPTR,A (will not work, as cannot write)
Note this is applicable for internal ROM-less microcontroller 8053
4
Example 12: In this program, assume that the word “USA”is
Physical address ASCII Hex code
burned into internal ROM locations starting at 200H. And
200H U 55H
that the program is burned into ROM locations starting at 0.
Analyze how the program works and state where “USA”is 201H S 53H
202H A 41H
stored after this program is run.
Solution: ORG 300H ; Point to memory location with physical address (PA) 300H
DB 00h, 01h, 04h, 09h, 10h ; To initialize the values of x2 and store them from PA=300H
MOV P1, #0FFH ; Set P1 as input port
L3: MOV A,P1 ; Take input ‘x’ from ‘P1’ and store the byte in register ‘A’. The allowed range of inputted
data is from 00H to 04H (means, x=00H, x=01 H, x=02 H, x=03 H, x=04 H).
MOV DPTR, #300H ; DPTR=300H look-up table address note that address > FFH
MOVC A, @A+DPTR ; get the NUMBER STORED IN ADDRESS (A+DPTR) = 300H ;
MOV P2, A ; Output the value of ‘A’ through P2 which is equal to squire (x2) of the
5
SJMP L3 ; inputted data from P1 (x)
- Review: In many applications, the size of program code does not leave any room to share the
64K-byte code space with data
� The 8051 has another 64K bytes of memory space set aside exclusively for data storage
� This data memory space is referred to as external memory and it is accessed only by the
MOVX instruction
� The 8051 has a total of 128K bytes of memory space
� 64K bytes of code and 64K bytes of data
� The data space cannot be shared between code and data
6
Physical address for
6th BIT location of
byte with P.A of 24H
(like 24.6, but not- allowed)
7
8
9
REVIEW:
10
11
Remember 6th and 7th BITs are
part of BYTE-data P.A of 20H
12
13
14