0% found this document useful (0 votes)
9 views

Embedded System

Uploaded by

relaxationsoul92
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Embedded System

Uploaded by

relaxationsoul92
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Technical Report for CA2 Evaluation

Embedded System (PE-EC703A)

Topic: Arithmetical & Logical


Programming in 8051 Microcontroller

Name: SOUMYADIP MONDAL


University Roll No: 12000321081; Sem: 7th ;
Dept: Electronics & Communication Engineering ;
Session: 2024-25-Odd
Dr. B.C. Roy Engineering College.
INTRODUCTION
The 8051 microcontroller, originally developed by Intel in the 1980s, has
become one of the most popular microcontrollers in the field of embedded
systems due to its efficient architecture, ease of programming, and widespread
support. It operates as an 8-bit processor, meaning it can process data in 8-bit
chunks, which makes it well-suited for controlling devices, performing data
acquisition, and handling real-time operations in embedded systems.
At the heart of the 8051’s functionality is its ability to perform arithmetic and
logical operations. These operations form the core of many computing tasks,
such as data processing, decision-making, and device control. Arithmetic
operations allow the 8051 to perform calculations such as addition,
subtraction, multiplication, and division, which are crucial for tasks like sensor
data analysis, timing control, and real-world signal processing. Meanwhile,
logical operations enable the manipulation of bits, facilitating control of
devices, conditional branching, and optimization of performance through
operations like AND, OR, XOR, and shifting.
ARITHMETIC INSTRUCTION IN 8051 MICROCONTROLLER

Arithmetic instructions in the 8051 microcontroller allow for the manipulation


of numerical data, which is essential for performing calculations like addition,
subtraction, multiplication, and division. These operations are executed
primarily using the accumulator (A) and sometimes the B register. In this
section, we will go into detail about the arithmetic instructions available in the
8051 and how they work.

1. Addition (ADD and ADDC)


Addition in the 8051 is done using the ADD and ADDC instructions. The
ADD instruction adds the contents of a register or immediate value to
the accumulator (A). The ADDC instruction is similar to ADD, but it also
adds the carry flag (CY) to the result, making it useful for multi-byte
addition.
Syntax:
 ADD A, source: Adds the source operand to the accumulator.
 ADDC A, source: Adds the source operand and the carry flag to the
accumulator.
Operation:
 The result of the addition is stored in the accumulator (A).
 The source can be a direct register (R0-R7), immediate value, or a
memory location.
 If the result exceeds 8 bits (255 in decimal), the carry flag (CY) is set

Example:
MOV A, #25h ; Load A with 25h (37 in decimal)
MOV R0, #13h ; Load R0 with 13h (19 in decimal)
ADD A, R0 ; A = A + R0 = 25h + 13h = 38h (56 in decimal)
If the result is greater than 255 (FFh), the carry flag (CY) will be set, and
the lower 8 bits will be stored in A.
2. Subtraction (SUBB)
The SUBB instruction performs subtraction by subtracting the source operand
and the borrow (CY) from the accumulator (A). If there is no borrow, CY is
considered zero.
Syntax:
 SUBB A, source: Subtracts the source operand and the carry (borrow)
flag from the accumulator.
Operation:
 The result is stored in the accumulator.
 The source can be a register, an immediate value, or a memory location.
 If the result requires borrowing, the carry flag (CY) is set.
Example:
 MOV A, #30h ; Load A with 30h (48 in decimal)
 MOV R2, #10h ; Load R2 with 10h (16 in decimal)
 SUBB A, R2 ; A = A - R2 = 30h - 10h = 20h (32 in decimal)

If borrowing is required (i.e., if the source operand is larger than the


accumulator value), the carry flag will be set, indicating a borrow
condition.

Multi-byte Subtraction Example:


 MOV A, #40h ; Load A with 40h
 MOV R3, #20h ; Load R3 with 20h
 CLR C ; Clear carry flag (no borrow initially)
 SUBB A, R3 ; A = A - R3 - CY = 40h - 20h - 0 = 20h.

Flags Affected by Arithmetic Operations


 Carry Flag (CY): Indicates if the result has overflowed beyond 8 bits.
 Overflow Flag (OV): Set when the result of a multiplication or signed
addition/subtraction exceeds the 8-bit limit.
 Auxiliary Carry Flag (AC): Used in BCD (binary-coded decimal)
operations.
 Parity Flag (P): Reflects the parity of the result stored in A. It is set if the
number of 1s in A is even, otherwise it is cleared.

Logical Instructions in 8051 Microcontroller


Logical instructions allow the manipulation of individual bits or bytes of data.
These instructions are essential for decision-making, controlling hardware, and
managing program flow in embedded applications.
1. AND (ANL)
The ANL instruction performs a bitwise logical AND between the accumulator
and the source operand. The result is stored in the accumulator.
 Syntax: ANL A, source
 Operation: A = A AND source
Example:
 MOV A, #0Fh ; Load A with 0Fh (00001111 in binary)
 MOV R4, #F0h ; Load R4 with F0h (11110000 in binary)
 ANL A, R4 ; A = 0Fh AND F0h = 00h (00000000 in binary)

2. OR(ORL)
The ORL instruction performs a bitwise logical OR between the accumulator
and the source operand. The result is stored in the accumulator.
Syntax: ORL A, source
Operation: A = A OR source
Examples:
 MOV A, #0Fh ; Load A with 0Fh (00001111 in binary)
 MOV R5, #F0h ; Load R5 with F0h (11110000 in binary)
 ORL A, R5 ; A = 0Fh OR F0h = FFh (11111111 in binary)
Conclusion
The 8051 microcontroller’s arithmetic and logical operations form the
foundation for many embedded systems applications. These instructions allow
the microcontroller to perform fundamental tasks such as data manipulation,
decision-making, and controlling external hardware devices. The efficient
handling of arithmetic operations (like addition, subtraction, multiplication, and
division) and logical operations (such as AND, OR, XOR, and bit shifting) enables
the 8051 to manage a wide variety of real-time processes essential in fields
ranging from simple home automation to complex industrial systems.
The arithmetic instructions provide a mechanism for performing crucial
numerical calculations. For instance, addition and subtraction are
indispensable for applications like calculating sensor readings, adjusting timers,
or managing counters.

You might also like