Exp 07 Arithmatic Operations Using 8051
Exp 07 Arithmatic Operations Using 8051
23EC2106R
PROCESSORS AND CONTROLLERS
Lab Experiment - 7
Theory:
• Write few points about 8051 features.
Input Data:
• For 8-bit Addition & Subtraction, use A8H, F9H.
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
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:
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