Professional Documents
Culture Documents
Internal RAM
memory
location
INPUT
Data External RAM
memory
location
BEFORE EXCHANGING:
AFTER EXCHANGING:
Data
Internal RAM
memory
location
OUTPUT
Data External RAM
memory
location
Data
Ex. No:
Date:
CODING:
Label
L1:
Mnemonics
Comments
ORG 0000H
XSEG AT 01H
X:DS 10
CSEG AT 0H
MOV
R0,#16H
MOV
DPTR,#01H
MOVX
A,@DPTR
MOV
B,A
CLR
Clear accumulator
MOV
A,@R0
XCH
A,B
MOV
@R0,A
MOV
A,B
MOVX
@DPTR,A
SJMP
L1
OUTPUT:
Internal
RAM
memory
location
INPUT
Data External
RAM
memory
location
BEFORE EXCHANGING:
AFTER EXCHANGING:
Data
Internal
RAM
memor
y
location
Dat
a
OUTPUT
External
RAM
memory
location
Data
ALGORITHM:
1. Initialize count value in R5 register.
2. Initialize internal RAM address in R0 register.
3. Initialize external RAM address in DPTR.
4. Move the value in the address pointed by DPTR to A register.
5. Move A register value to B register.
6. Move the value in the address pointed by R0 to A register.
7. Move the value in the A register to address pointed by DPTR.
8. Move the value in B register to address pointed by R0.
9. Increment DPTR and R0 value.
10. Decrement count in R5.
11. Check if Count is zero? If not go to step 5.
12. If yes, terminate the program.
CODING:
Label
L2:
Mnemonics
Comments
ORG 0000H
XSEG AT 01H
X:DS 10
CSEG AT 0H
MOV R5,#05H
MOV R0,#16H
MOV DPTR,#01H
MOVX A,@DPTR
MOV B,A
CLR A
Clear accumulator
MOV A,@R0
XCH A,B
MOV @R0,A
MOV A,B
MOVX @DPTR,A
INC DPTR
INC R0
L1:
DJNZ R5,L2
SJMP L1
OUTPUT:
ADDITION
External RAM
memory locations
Input
External RAM
memory locations
Output
SUBTRACTION
External RAM
memory locations
Input
External RAM
memory locations
Output
Ex No:
DATA MANIPULATION
AIM:
To write an 8051 ALP to perform addition, subtraction and array addition using keil
vision4 IDE.
ADDITION /SUBTRACTION
ALGORITHM:
1. Initialize the carry value in R0 register.
2. Initialize external RAM address in DPTR.
3. Move the value in the address pointed by DPTR to A register.
4. Move the A register value to the B register.
5. Increment DPTR and move the value from DPTR to A register.
6. Add/subtract the values in A and B registers.
7. Increment DPTR and move the value from A register to DPTR.
8. If carry exist, increment R0 and move the value to A register.
9. Move the A register to DPTR.
10. Terminate the program.
CODING:
Label
L1:
L2:
Mnemonic
ORG 0000H
XSEG AT 01H
X:DS 10
CSEG AT 0H
MOV
DPTR,#01H
MOV
R0,#00H
MOVX
A,@DPTR
MOV
B,A
INC
DPTR
MOVX
A,@DPTR
ADD/SUBB A,B
INC
DPTR
MOVX
@DPTR,A
INC
DPTR
JNC
L1
INC
R0
MOV
A,R0
MOVX
@DPTR,A
NOP
SJMP
L2
OUTPUT:
Comments
;Initialize origin address
;Select external memory starting address
;Reserve 10 memory locations
;Select code memory space
;External RAM Address
;Load 00 to R0 register
;Get data1 byte from external RAM
;Load data1 into B register
;Increment External RAM Address
;Get data2 byte from external RAM
;Add/Subtract the two data
;Increment External RAM Address
;Load data3 to external RAM
;Increment External RAM Address
;Jump to L1 if no carry
;Increment R0 register
;Load the content of R0 to accumulator
;Load carry to external RAM
;No operation
ARRAY ADDITON
External RAM
memory locations
Input
External RAM
memory locations
Output
CODING:
Label
L2:
L1:
Mnemonic
ORG 0000H
XSEG AT 01H
X:DS 10
CSEG AT 0H
MOV
R5,#05H
MOV
DPTR,#01H
MOV
R0,#00H
MOVX
A,@DPTR
MOV
B,A
INC
DPTR
MOVX
A,@DPTR
ADD
A,B
MOV
B,A
JNC
L1
INC
R0
NOP
INC
DPTR
DJNZ
R5,L2
MOV
A,B
MOVX
@DPTR,A
INC
DPTR
MOV
A,R0
MOVX
@DPTR,A
Comments
;Initialize origin address
;Select external memory starting address
;Reserve 10 memory locations
;Select code memory space
;Move the no. of bytes to be added in R5
;External RAM Address
;Load 00 to R0 register
;Get data1 byte from external RAM
;Load data1 into B register
;Increment External RAM Address
;Get data2 byte from external RAM
;Add the two data
;Load data3 into B register
;Jump to L1 if no carry
;Increment R0 register
;No operation
;Increment External RAM Address
;Jump to L2 if count not equal to zero
;Load result to accumulator
;Load result to external RAM
;Increment External RAM Address
;Load carry from R0 to accumulator
;Load carry to carry to external RAM
RESULT:
Thus the 8051 ALP to perform data transfer and data manipulation operations is successfully
executed and their results are verified using Keil vision4 IDE.