Program for Arithmatic operations in 89C51

jojo January 18, 2011 1 Comment

AIM: To write programs for

i. Addition

ii. Subtraction

iii. Multiplication

iv. Division

of two numbers in 89C51.

    Addition

PROGRAM

MOV R0,#00

MOV DPTR,#4200

MOVX A,@DPTR

MOV B,A

INC DPTR

MOVX A,@DPTR

ADD A,B

JNC LABEL1

INC R0

LABEL1 : INC DPTR

MOVX @DPTR,A

MOV A,R0

INC DPTR

MOVX @DPTR,A

HERE : SJMP HERE

SAMPLE OUTPUT

ADDRESSES

DATA

INPUT/OUTPUT

4200

05

Input

4201

04

Input

4202

09

Output

4203

00

Output

    Subtraction

PROGRAM

MOV R0,#00

MOV DPTR,#4200

MOVX A,@DPTR

MOV B,A

INC DPTR

MOVX A,@DPTR

SUBB A,B

JNC LABEL1

INC R0

LABEL1 INC DPTR

MOVX @DPTR,A

MOV A,R0

INC DPTR

MOVX @DPTR,A

HERE SJMP HERE

SAMPLE OUTPUT

ADDRESSES

DATA

INPUT/OUTPUT

4200

01

Input

4201

05

Input

4202

04

Output

4203

00

Output

    Multiplication

PROGRAM

MOV R0,#00

MOV DPTR,#4200

MOVX A,@DPTR

MOV B,A

INC DPTR

MOVX A,@DPTR

MUL AB

INC DPTR

MOVX @DPTR,A

MOV A,B

INC DPTR

MOVX @DPTR,A

LABEL SJMP LABEL

SAMPLE OUTPUT

ADDRESSES

DATA

INPUT/OUTPUT

4200

01

Input

4201

0A

Input

4202

0A

Output

4203

00

Output

    Division

PROGRAM

MOV R0,#00

MOV DPTR,#4200

MOVX A,@DPTR

MOV B,A

INC DPTR

MOVX A,@DPTR,A

DIV AB

INC DPTR

MOVX @DPTR,A

MOV A,B

INC DPTR

MOVX @DPTR,A

LABEL SJMP LABEL

SAMPLE OUTPUT

ADDRESSES

DATA

INPUT/OUTPUT

4200

01

Input

4201

0A

Input

4202

0A

Output

4203

00

Output

RESULT:

Programs for

i. Addition

ii. Subtraction

iii. Multiplication

iv. Division

of two numbers were prepared and the output was obtained.

Comments
  • Mani
    February 9, 2011

    It excellent..

Leave a Reply to Mani Cancel reply

Your email address will not be published. Required fields are marked *