You are on page 1of 12

OUTPUT:

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:

INTERNAL AND EXTERNAL DATA TRANSFER OPERATIONS


AIM:
To write an 8051 ALP to exchange the block of data between internal and external memory
locations using keil vision4 IDE.

SINGLE BYTE DATA TRANSFER


ALGORITHM:
1. Initialize internal RAM address 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 A register value to B register.
5. Move the value in the address pointed by R0 to A register.
6. Move the value in the A register to address pointed by DPTR.
7. Move the value in B register to address pointed by R0.
8. Terminate the program.

CODING:
Label

L1:

Mnemonics

Comments

ORG 0000H
XSEG AT 01H
X:DS 10
CSEG AT 0H

Initialize original address


Select external memory starting address
Reserve 10 memory locations
Select code memory space

MOV

R0,#16H

Internal RAM address

MOV

DPTR,#01H

External RAM address

MOVX

A,@DPTR

Get data1 from external RAM

MOV

B,A

Load the data 1 into B register

CLR

Clear accumulator

MOV

A,@R0

Get data 2 from internal RAM

XCH

A,B

Exchange the content

MOV

@R0,A

Load the data 2 into internal RAM

MOV

A,B

Load the data 1 in the accumulator

MOVX

@DPTR,A

Load the data 1 into external RAM

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

MULTIBYTE DATA TRANSFER

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

Initialize original address


Select external memory starting address
Reserve 10 memory locations
Select code memory space

MOV R5,#05H

Move the number of bytes to be transferred in R5

MOV R0,#16H

Internal RAM address

MOV DPTR,#01H

External RAM address

MOVX A,@DPTR

Get data1 from external RAM

MOV B,A

Load the data 1 into B register

CLR A

Clear accumulator

MOV A,@R0

Get data 2 from internal RAM

XCH A,B

Exchange the content

MOV @R0,A

Load the data 2 into internal RAM

MOV A,B

Load the data 1 in the accumulator

MOVX @DPTR,A

Load the data 1 into external RAM

INC DPTR

Increment external RAM address

INC R0

Increment internal RAM address

L1:

DJNZ R5,L2
SJMP L1

Jump to L2 if count not equal to zero


Short jump to 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

8-BIT ARRAY ADDITION


ALGORITHM:
1. Initialize count value in R5 register.
2. Initialize external RAM address in DPTR.
3. Initialize R0 with 00H.
4. Move the value in the address pointed by DPTR to A register.
5. Move A register value to B register.
6.
7.
8.
9.

Increment DPTR and move the value from DPTR to A register.


Add the values in A and B registers.
Move the value in A register to B register.
If carry exist, increment R0 else no operation.

10. Decrement count in R5.


11. Check if Count is zero? If not go to step 6.
12. If yes, move the B register value to A register and move it to external RAM memory.
13. Increment DPTR, move the value of R0 register to A register and move it to external RAM
memory.

14. Terminate the program.

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.

You might also like