8051 Program to Add two 8 Bit numbers

Microprocessor8085Microcontroller

Intel 8051 is an 8-bit microcontroller. It has many powerful instructions and IO accessing techniques. In this section, we will see one of the simplest program using 8051.

Here we will add two8-bit numbers using this microcontroller. The register A(Accumulator) is used as one operand in the operations. There are seven registers R0 – R7 in different register banks. We can use any of them as the second operand.

We are taking two number 5FH and D8H at location 20H and 21H, After adding them, the result will be stored at location 30H and 31H.  

Address
Value


.
.
.
20H
5FH
21H
D8H


.
.
.
30H
00H
31H
00H


.
.
.


Program

MOVR0,#20H;set source address 20H to R0
MOVR1,#30H;set destination address 30H to R1
MOVA,@R0; take the value from source to register A
MOVR5,A; Move the value from A to R5
MOVR4,#00H; Clear register R4 to store carry
INCR0; Point to the next location
MOVA,@R0; take the value from source to register A
ADDA,R5;Add R5 with A and store to register A
JNC SAVE
INCR4; Increment R4 to get carry
MOVB,R4;Get carry to register B
MOV@R1,B; Store the carry first
INCR1; Increase R1 to point to the next address
SAVE:   MOV@R1,A;Store the result  
HALT:   SJMP HALT ;Stop the program

So by adding 5FH + D8H, the result will be 137H. The 01H will be stored at 30H, and 37 is stored at 31H.

Output

Address
Value


.
.
.
20H
5FH
21H
D8H


.
.
.
30H
01H
31H
37H


.
.
.
raja
Published on 31-Dec-2018 10:25:24
Advertisements