0% found this document useful (0 votes)
12 views5 pages

8051 Programs and Algorithms

The document outlines various 8051 assembly language programs and algorithms, including 16-bit addition, subtraction, multiplication, and division, as well as methods for calculating the square and cube of a number. Each section provides a high-level algorithm followed by corresponding assembly code examples. Additionally, it discusses data transfer methods between registers, RAM, and external memory.

Uploaded by

agdhivya2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

8051 Programs and Algorithms

The document outlines various 8051 assembly language programs and algorithms, including 16-bit addition, subtraction, multiplication, and division, as well as methods for calculating the square and cube of a number. Each section provides a high-level algorithm followed by corresponding assembly code examples. Additionally, it discusses data transfer methods between registers, RAM, and external memory.

Uploaded by

agdhivya2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

8051 Assembly Language Programs and

Algorithms
1. 16-bit Addition

Algorithm:
 • Clear carry.
 • Add lower bytes.
 • Add higher bytes with carry.
 • Store result.

Code:

CLR C

MOV A, #34H

ADDC A, #78H

MOV DPTR, #4150H

MOVX @DPTR, A

MOV A, #12H

ADDC A, #56H

INC DPTR

MOVX @DPTR, A

2. 16-bit Subtraction

Algorithm:
 • Clear carry.
 • Subtract lower bytes using SUBB.
 • Subtract higher bytes with borrow.
 • Store result.
Code:

CLR C

MOV A, #78H

SUBB A, #10H

MOV DPTR, #4150H

MOVX @DPTR, A

INC DPTR

MOV A, #50H

SUBB A, #10H

MOVX @DPTR, A

3. Square of a Number (8-bit)

Algorithm:
 • Read number from external memory.
 • Copy it to B.
 • Multiply A × B.
 • Store A (low byte), B (high byte).

Code:

ORG 4100H

MOV DPTR, #4200H

MOVX A, @DPTR

MOV B, A

MUL AB

INC DPTR

MOVX @DPTR, A
INC DPTR

MOV A, B

MOVX @DPTR, A

4. Cube of a Number (8-bit)

Algorithm:
 • Load number.
 • Square it using MUL AB.
 • Save result temporarily.
 • Multiply square result with original number.
 • Store final result.

Code:

ORG 4100H

MOV DPTR, #4200H

MOVX A, @DPTR

MOV R0, A

MOV B, A

MUL AB

MOV R1, A

MOV R2, B

MOV A, R1

MOV B, R0

MUL AB

INC DPTR

MOVX @DPTR, A
INC DPTR

MOV A, B

MOVX @DPTR, A

5. 16-bit Multiplication (Concept)

Algorithm:
 • Multiply 4 byte-pairs.
 • Add intermediate results.
 • Store 32-bit final result.

Code:

; Note: Requires multiple MUL AB and ADD operations manually.

; Example implementation omitted due to 8051 limitations.

6. 16-bit Division (by 8-bit)

Algorithm:
 • Load high byte.
 • If ≠ 0, overflow.
 • Load low byte in A.
 • Load divisor in B.
 • DIV AB.
 • A = Quotient, B = Remainder.

Code:

; Example:

MOV A, #64H

MOV B, #0AH

DIV AB

; A = Quotient, B = Remainder
7. Data Transfer (Registers, RAM, External)

Algorithm:
 • Move between registers using MOV.
 • Move to internal RAM via address (e.g., 30H).
 • Use MOVX for external memory.

Code:

ORG 0000H

MOV A, #0AH

MOV R0, A

MOV 30H, A

MOV R1, 30H

MOV DPTR, #4000H

MOVX @DPTR, A

MOVX A, @DPTR

MOV R2, A

SJMP $

You might also like