Experiment-1 (ES)

You might also like

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

Experiment - 1

Aim -:
Aim 1 -: A program to add 2 numbers where number are stored in
internal memory.

Aim 2 -: A program to add 2 numbers where number are stored in


external memory.

Aim 3 -: A program to add first 10 natural numbers where number are


stored in internal memory.

Program -:

Aim 1 :- A program to add 2 numbers where number


are stored in internal memory.

Program :-

ORG 0000H ; Starting address is given to the compiler as


0000H.

MOV A, #10H ; Data 10H is directly given to the Accumulator.

MOV R0, #20H ; Data is directly given to register R0.

ADD A, R0 ; Content of the Accumulator and register R0 are


added.

MOV 40H, A ; Sum in the Accumulator is stored in the memory


location 40H.

END ; Completion of the code.


Aim 2 :- A program to add 2 numbers where number
are stored in external memory.

Program :-

ORG 0000H ; Starting address is given to the compiler as


0000H.

MOV DPTR, #0000H ; Store the data from the memory


location to the Data pointer.

MOVX A, @DPTR ; Move the data from the Data pointer


to the Accumulator.

MOV R0, A ; Move the contents of the Accumulator to register


R0.

INC DPTR ; Increment the Data pointer.

MOVX A, @DPTR ;Move the data from the Data pointer to the
Accumulator.

ADD A, R0 ; Contents of the accumulator and register R0 are


added.

INC DPTR ; Increment the Data pointer.

MOVX @DPTR, A ; Move the contents of the Accumulator to


the Data pointer.

END ; Completion of the code.


Aim 3 :- 8051 code to add the first 10 natural
numbers.

Program :-

ORG 0000H ; Starting address is given to the compiler as


0000H.

MOV R2, #00D ; Data 00H is stored in register R2.

MOV A, R2 ; Move the contents of register R0 to the


Accumulator.

MOV R1, #10D ; Data 10D is stored in register R1.

LOOP1: ; A loop is initialized to facilitate quick addition.

ADD A, R1 ; Contents of the Accumulator and register R1 are


added.

DJNZ R1, LOOP1 ; Register R1 is decremented until zero is obtained


and Loop1 runs until then.
MOV R3, A ; Move the contents of register R3 to the
Accumulator.

END ; Completion of the code

You might also like