8051 Programs Using Kit: Exp No: Date: Arithmetic Operations Using 8051

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

8051 PROGRAMS USING KIT

EXP NO: DATE:


ARITHMETIC OPERATIONS USING 8051
Aim:

To perform the arithmetic operations such as addition, subtraction, multiplication and division
on 8051 microcontroller

Apparatus Required:
8051 microcontroller Trainer kit – 1nNo

8-bit Addition
Algorithm:

1. Start
2. Get the I operand in accumulator and the II operand with the content of accumulator
using ADD
3. Store the result in memory
4. Stop the execution

Program:

Label Address Op. Code Mnemonics Comments


START 4500 CLR C Clear carry
MOV A,#72H Move data 1 to (A)
ADD A,#15H Add data with (A)
MOV 10H,A (DPTR)←(A)
HERE HERE: SJMP
HERE

Flowchart:
START

Clear carry flag

Move Data-1 to A

Add/Subtract 2nd data with A

Store result in memory

STOP
Test data:

Inputs: A =72H

A = 15H

Output: 87

Output Screenshots:
8-bit Subtraction:

Algorithm:

1. Start
2. Get the two numbers, which are to be subtracted
3. Subtract the two numbers using SUBB and store the result in the corresponding memory
location
4. Stop

Program:

Label Address Op. Code Mnemonics Comments


START 4500 CLR C Clear carry

MOV A, #72H Move data 1 to (A)

SUBB A, #15H Sub data 2 from (A)

MOV 01H, A (DPTR)←(A)

HERE: HERE: SJMP HERE

Test data:
Inputs: A – 72H Output: 5D
A – 15H
Output Screenshots:
8-bit multiplication
Algorithm:
1. Start
2. Get the two numbers, which are to be multiplied
3. Multiply the two numbers using MUL and store the LSB of result in the accumulator and
MSB of result in register
4. Stop the execution
Program:

Label Address Op. Code Mnemonics Comments


START 4500 MOV A, #72H Move data 1 to (A)

MOV B, #15H Move data 2 to (B)

MUL AB Multiply A, B

MOV 01H, A

MOV A, B Move content of B to A

MOV 02H, A

HERE: HERE: SJMP HERE

Flow chart:

Start

Get multiplier in A

Get multiplicand in B

Multiply A and B

Store result in memory

Stop

Test data:

Inputs: DATA1 = 72H

DATA2 = 15H

Outputs: 95A

8 –bit Division
Algorithm:
1. Start
2. Get the two numbers, which are to be divided
3. Divide the two numbers using DIV and store the question in the accumulator and remainder
in register B
4. Stop the execution
Program:

Label Address Op. Code Mnemonics Comments


START 4500 MOV A, #72H Move data 1 to (A)
MOV B, #15H Move data 2 to (B)
DIV AB Divide A,B
MOV 01H, A
MOV A, B Move Content of B to A
MOV 02H, A
HERE: HERE: SJMP HERE

Flow chart: Start

Get dividend in A

Get divisor in B

Divide A by B

Store result in memory

stop
Test data:

Inputs: DATA1 = 72H Outputs: Quotient = 5


DATA2 = 15H Remainder = 9

Output Screenshots:
Result:
Thus the above programs have been implemented and executed and the required outputs have been
obtained.
EXP NO: DATE:

SQUARE OF THE NUMBER USING 8051

Aim:

To write an ALP program to square the given number.

Apparatus Required:

8051 microcontroller kit 1

Algorithm:

1. Start the program


2. Get the input value in accumulator
3. Move the input to another register
4. Multiply the accumulator with another register.
5. Store the value
6. Stop

Program:

START

Get the input in the accumulator

Move the value to another register


from accumulator

Multiply the accumulator with


another register

Store the value in memory

STOP
Program:

Label Address Op. Code Mnemonics Comments


START 4500 MOV A,#03H Load the input
MOV B, A Move the value to B
MUL AB Multiply A&B
MOV 01H, A

MOV A, B

MOV 02H, A
STOP STOP: SJMP STOP

Input: 03H Output: 09H

Output Screenshots:
Result:.

Thus the above program has been implemented and executed and the required output has
been obtained.

EXP NO: DATE:


CUBE OF THE NUMBER USING 8051
Aim:

To write an ALP program to find the cube of the given number.

Algorithm:

1. Start the program


2. Get the input value in accumulator
3. Move the input to another register and push the value in stack
4. Multiply the accumulator with another register.
5. Pop the value from stack
6. Multiply with the accumulator
7. Stop the program.
Program:

Label Address Op. Code Mnemonics Comments

START 4500 MOV A, #02H


MOV R0, A
MOV B, A
MUL AB
PUSH B
MOV B, A
MOV A, R0
MUL AB
MOV 01H, A
MOV R2, A
POP B
MOV A, R0
MUL AB
ADD A, R2
MOV 01H, A
MOV A, B
MOV 01H, A
LCALL 0003H

Input: 03H Output: 1B

Output Screenshots:
Result:

Thus the above program has been implemented and executed and the required output has been
obtained.

You might also like