0% found this document useful (0 votes)
28 views15 pages

Exp 07 Arithmatic Operations Using 8051

hgfk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views15 pages

Exp 07 Arithmatic Operations Using 8051

hgfk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Department of ECE

23EC2106R
PROCESSORS AND CONTROLLERS
Lab Experiment - 7

ARITHMETIC OPERATIONS USING 8051


Exp 7: ARITHMETIC OPERATIONS USING 8051
Aim
a. To Develop an Assembly Language Program (ALP) for following arithmetic operations
on 8-bit data. Consider input is in RAM locations 30H &31H and Output will be stored
in RAM locations 32H & 33H.
1. Addition
2. Subtraction
3. Multiplication
4. Division
b. To develop an Assembly Language Program (ALP) to add an array of 10 bytes starting
from RAM location 30H and store the result in RAM locations 40H and 41H

Software used: MCU 8051 IDE


Exp 7: ARITHMETIC OPERATIONS USING 8051

Theory:
• Write few points about 8051 features.

• Write a paragraph about CPU registers (A & B).

• Write a paragraph about PSW.


Exp 7: ARITHMETIC OPERATIONS USING 8086

Input Data:
• For 8-bit Addition & Subtraction, use A8H, F9H.

• For 8-bit Multiplication & Division, use E6H, 5CH.

• For an array of addition, use the following 10 bytes:


05H, 06H, 07H, 08H, 09H, 0AH, 0BH, 0CH, 0DH, 0EH.
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Addition Program:
Program Comment
ORG 0000H Store the below program from ROM location 0000H
MOV A, 30H Move the contents of RAM location 30H into A register
MOV B, 31H Move the contents of RAM location 31H into B register
MOV R0, #00H Move the data 00H into R0 register
ADD A, B Add the contents of A register with B register which keeps the result in A register
JNC LABEL Jump to LABEL address if no carry is generated (Jump if CY=0)
INC R0 Increment the contents of R0 register by 1 (i.e. if carry is generated)
LABEL: MOV 32H, A Move the contents A register into RAM location 32H
MOV 33H, R0 Move the contents R0 register into RAM location 33H
END End the Program.
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Addition: Observations
Input Data: CPU Registers Output Data:

RAM Data Before Addition At the end of the program RAM Data
Location Byte Location Byte
A A8 A A1
30H A8 32H A1
B F9 B F9
31H F9 33H 01

PSW: CY AC F0 RS1 RS0 OV P

1 1 0 0 0 0 - 1
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Subtraction Program:
Program Comment
ORG 0000H Store the below program from ROM location 0000H
MOV A, 30H Move the contents of RAM location 30H into A register
MOV B, 31H Move the contents of RAM location 31H into B register
MOV R0, #00H Move the data 00H into R0 register
CLR C Clear the carry flag (i.e. CY=0)
SUBB A, B Subtract the contents of B register from A register which keeps the result in A register
JNC LABEL Jump to LABEL address if no carry is generated (Jump if CY=0)
INC R0 Increment the contents of R0 register by 1 (i.e. if carry is generated)
LABEL: MOV 32H, A Move the contents A register into RAM location 32H
MOV 33H, R0 Move the contents R0 register into RAM location 33H
END End the Program.
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Subtraction: Observations
Input Data: CPU Registers Output Data:

RAM Data Before subtraction After subtraction RAM Data


Location Byte Location Byte
A A8 A AF
30H A8 32H AF
B F9 B F9
31H F9 33H 01

PSW: CY AC F0 RS1 RS0 OV P

1 1 0 0 0 0 - 0
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Multiplication Program:
Program Comment
ORG 0000H Store the below program from ROM location 0000H
MOV A, 30H Move the contents of RAM location 30H into A register
MOV B, 31H Move the contents of RAM location 31H into B register
MUL AB Multiply the contents of A register with B register. (This keeps the lower byte
of result in A register and higher byte of result in B register).
MOV 32H, A Move the contents A register into RAM location 32H
MOV 33H, B Move the contents B register into RAM location 33H
END End the Program.
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Multiplication: Observations
Input Data: CPU Registers Output Data:

RAM Data Before Addition At the end of the program RAM Data
Location Byte Location Byte
A E6 A A8
30H E6 32H A8
B 5C B 52
31H 5C 33H 52
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Division Program:
Program Comment
ORG 0000H Store the below program from ROM location 0000H
MOV A, 30H Move the contents of RAM location 30H into A register
MOV B, 31H Move the contents of RAM location 31H into B register
DIV AB Divide the contents of A register with B register. (This keeps the Quotient of
result in A register and remainder of result in B register).
MOV 32H, A Move the contents A register into RAM location 32H
MOV 33H, B Move the contents B register into RAM location 33H
END End the Program.
Exp 7: ARITHMETIC OPERATIONS USING 8051
8-bit Division: Observations
Input Data: CPU Registers Output Data:

RAM Data Before Addition At the end of the program RAM Data
Location Byte Location Byte
A E6 A 02
30H E6 32H 02
B 5C B 2E
31H 5C 33H 2E
Exp 7: ARITHMETIC OPERATIONS USING 8051
Addition of array of 10 Bytes Program:
Program Comment
ORG 0000H Store the below program from ROM location 0000H
MOV R0, #30H Move the value 30H (starting address of an array) into R0 register
MOV R1, #00H Move the value 00H into R1 register for storing the carry if any
MOV R2, #09H Move the value 09H (which is count) into R2 register
MOV A, @R0 Move the contents of RAM location specified by Ro into A register
BACK: INC R0 Increment the contents of R0 register by 1
MOV B, @R0 Move the contents of RAM location specified by Ro into B register
ADD A, B Add the contents of A register with B register
JNC LABEL Jump to LABEL address if no carry is generated (Jump if CY=0)
INC R1 Increment the contents of R1 register by 1 (i.e. if carry is generated)
LABEL: DJNZ R2, BACK Decrease R2 value and if it is Not Zero, Jump to the BACK address
MOV 40H, A Move the contents A register into RAM location 40H
MOV 41H, R1 Move the contents R1 register into RAM location 41H
END End the Program.
Exp 7: ARITHMETIC OPERATIONS USING 8051
Result:

a) An Assembly Language Program (ALP) for the following arithmetic operations are
developed for the given 8-bit data.
1. Addition
2. Subtraction
3. Multiplication
4. Division

b) An Assembly Language Program (ALP) to add an array of 10 bytes starting from RAM
location 30H is developed and stored the result in RAM locations 40H and 41H
THANK YOU

N L PRASAD

You might also like