exp02_Microprocessor
exp02_Microprocessor
Experiment 2
Addition of Binary and BCD Numbers using Intel
8085 Microprocessor
Contents
1 Aim 2
8 Viva Questions 30
1
Microprocessor Laboratory Experiment 2
1 Aim
After completing this experiment, the student should be able to:
1. Understand the principles of binary addition and explain the generation of carry
during arithmetic operations.
2. Perform binary addition using immediate data, registers and memory operands in
the Intel 8085 microprocessor.
3. Observe and interpret the Carry flag generated during binary addition and under-
stand its significance in arithmetic operations.
4. Perform multi-byte binary addition using the ADC instruction and understand the
concept of carry propagation.
5. Perform addition of packed BCD numbers using the DAA instruction and distinguish
between binary and BCD arithmetic.
6. Develop assembly language programs for binary and BCD addition, convert them
into machine language programs, and execute them using the Intel 8085 program-
ming trainer kit.
7. Observe and interpret the contents of processor registers, memory locations and
status flags during program execution.
2
Microprocessor Laboratory Experiment 2
Concept Introduced
This activity introduces the following concepts:
• Binary addition
• Sum bit and Carry bit
• XOR gate and AND gate
• Carry propagation
• Multi-bit binary addition
A Output
B
3
Microprocessor Laboratory Experiment 2
AND Gate
The AND gate is a digital logic gate that produces a logic HIGH output only when both
input bits are logic HIGH. If either input is logic LOW, the output remains logic LOW.
The logical symbol for an AND gate is shown in Figure 2.
A Output
B
Sum = A ⊕ B (1)
Carry = A · B (2)
where ⊕ denotes the Exclusive OR (XOR) operation and · denotes the logical AND
operation.
During the addition of multi-bit binary numbers, the Carry generated at one bit posi-
tion is transferred to the next higher bit position, where it participates in the subsequent
addition. This transfer of Carry from one bit position to the next is known as carry
propagation and forms the basis of multi-bit binary addition.
4
Microprocessor Laboratory Experiment 2
Carry Propagation
During one-bit binary addition, the Carry bit is generated only when both input bits
are equal to 1. While this Carry bit is not required for one-bit addition, it becomes
essential when adding binary numbers containing two or more bits. In such cases, the
Carry generated at one bit position is added to the next higher bit position. This process
is known as carry propagation.
The addition of multi-bit binary numbers therefore consists of a sequence of one-bit
additions, beginning with the least significant bit (LSB) and proceeding towards the most
significant bit (MSB). At each stage, the Sum bit is recorded at the current bit position,
while the Carry bit, if generated, is propagated to the next higher bit position.
Carry Propagation
During one-bit binary addition, the Carry bit generated at one bit position is added to
the next higher bit position whenever binary numbers containing two or more bits are
added. This transfer of the Carry from one bit position to the next is known as carry
propagation. Consequently, multi-bit binary addition is performed as a sequence of one-
bit additions, beginning with the least significant bit (LSB) and proceeding towards the
most significant bit (MSB).
The following examples illustrate the process of carry propagation during binary ad-
dition.
1
1 1
+ 0 1
1 0 0
The addition begins with the least significant bit. The addition of 1 + 1 produces
a Sum of 0 and generates a Carry of 1. This Carry is propagated to the next higher
bit position, where it is added along with the remaining input bits. The final result is
therefore 100.
1 1
1 0 1 1
+ 0 1 1 0
1 0 0 0 1
In this example, Carry is generated at successive bit positions and propagated towards
the higher-order bits until the complete addition is performed. The same procedure is
followed irrespective of the number of bits present in the operands.
5
Microprocessor Laboratory Experiment 2
1 1 1 1 1 1
1 0 1 1 0 1 1 0
+ 0 1 0 1 1 1 0 1
1 0 0 0 1 0 0 1 1
Therefore,
Exercise
Complete the following table (Table 3) by converting the given hexadecimal operands
into their binary equivalents. Perform the binary addition and record the final result in
both binary and hexadecimal formats.
Q-1: Why are XOR and AND gates sufficient to implement one-bit binary addition?
Q-2: Under what condition is a Carry generated during one-bit binary addition?
Q-3: What is meant by carry propagation? Why is it necessary during multi-bit binary
addition?
6
Microprocessor Laboratory Experiment 2
Q-4: Why does binary addition always begin with the least significant bit (LSB)?
Q-5: Why are hexadecimal numbers commonly used to represent binary data in micro-
processor programming, even though arithmetic operations are performed using
binary numbers?
7
Microprocessor Laboratory Experiment 2
Concept Introduced
This activity introduces the following concepts:
• Register-based addition
A ← A + data (3)
8
Microprocessor Laboratory Experiment 2
A←A+r (4)
where r may be one of the general-purpose registers B, C, D, E, H or L. For example,
1 ADD C
A ← A + [HL] (5)
where [HL] denotes the contents of the memory location addressed by the H-L register
pair.
For example, if the H-L register pair contains 2050H and the contents of that memory
location are 25H, the instruction
1 ADD M
performs
A ← A + 25H.
In all three cases, the result of the addition is placed in the Accumulator. The three
instructions therefore differ in the source from which the second operand is obtained.
9
Microprocessor Laboratory Experiment 2
Procedure
1. Press the RESET key to initialize the trainer kit.
2. Press the EXMEM key and enter the memory address 2050H.
3. Enter the first operand 25H at memory location 2050H using the DATA INS key.
5. Press the EXMEM key and enter the starting memory address 2000H.
6. Using the machine code determined in the previous section, enter the complete
program into memory. Press the DATA INS key after entering each byte and use
the NEXT key to advance to the next memory location.
8. Press the GO key and enter the starting address 2000H. The program executes the
addition and stores the result at memory location 2051H.
10
Microprocessor Laboratory Experiment 2
9. Press the EXMEM key and enter the memory address 2051H. Record the contents
of memory location 2051H in Table 5.
Results
Repeat the addition using the operand combinations given below. For each case, modify
the contents of memory location 2050H and the immediate operand in the ADI instruction.
Execute the program and record the result stored at memory location 2051H.
Q-2: What value was stored at memory location 2051H after program execution?
Q-3: Which instruction loaded the first operand into the Accumulator?
Q-5: Why is the result stored at a different memory location from the original operand?
11
Microprocessor Laboratory Experiment 2
stored in register B to the second operand in the Accumulator. The result is stored at
memory location 2052H.
1 LDA 2050H
2 MOV B,A
3 LDA 2051H
4 ADD B
5 STA 2052H
6 HLT
Procedure
1. Press the RESET key to initialize the trainer kit.
2. Press the EXMEM key and enter the memory address 2051H.
3. Enter the first operand 25H at memory location 2051H using the DATA INS key.
4. Press the EXMEM key and enter the memory address 2052H.
5. Enter the second operand 13H at memory location 2052H using the DATA INS
key.
7. Press the EXMEM key and enter the starting memory address 2000H.
12
Microprocessor Laboratory Experiment 2
8. Using the machine code determined in the previous section, enter the complete
program into memory. Press the DATA INS key after entering each byte and use
the NEXT key to advance to the next memory location.
10. Press the GO key and enter the starting address 2000H. The program executes the
addition and stores the result at memory location 2053H.
11. Press the EXMEM key and enter the memory address 2053H. Record the contents
of memory location 2053H in Table 7.
Results
Repeat the addition using the operand combinations given below. Modify the contents
of memory locations 2050H and 2051H before each execution. Record the contents of
memory location 2052H after program execution.
Contents of
2050H 2051H 2052H
18H 27H
36H 49H
68H 17H
C4H 2BH
D8H 3AH
Q-3: Which instruction transfers the first operand from memory to register B?
Q-5: How does the method of addition in this task differ from the use of ADI in Task 1?
13
Microprocessor Laboratory Experiment 2
In this task, five 8-bit hexadecimal numbers stored in consecutive memory locations
are added. The first number is loaded into the Accumulator, and the remaining numbers
are added sequentially using the ADD M instruction. The INR L instruction is used to
advance the H-L register pair to the next memory location after each addition. The final
result is stored at a specified memory location.
For example, if five numbers are stored at memory locations 2050H to 2054H, the
result of their addition is stored at memory location 2060H.
Procedure
1. Press the RESET key to initialize the trainer kit.
2. Press the EXMEM key and enter the memory address 2050H.
3. Enter the five operands at memory locations 2050H to 2054H using the DATA INS
key and the NEXT key to advance to the next memory location.
5. Press the EXMEM key and enter the starting memory address 2000H.
14
Microprocessor Laboratory Experiment 2
6. Using the machine code determined in the previous section, enter the complete
program into memory. Press the DATA INS key after entering each byte and use
the NEXT key to advance to the next memory location.
8. Press the GO key and enter the starting address 2000H. The program accesses the
five operands sequentially using the H-L register pair and adds them using the ADD
M instruction. The final result is stored at memory location 2060H.
9. Press the EXMEM key and enter the memory address 2060H. Record the contents
of memory location 2060H in Table 9.
Results
Repeat the addition using the sets of operands given below (Table 9). Store the five
operands at memory locations 2050H to 2054H, execute the program, and record the
result stored at memory location 2060H.
Contents of
2050H 2051H 2052H 2053H 2054H 2060H
12H 23H 14H 31H 10H
25H 36H 17H 24H 12H
A5H 38H 27H 16H 14H
15
Microprocessor Laboratory Experiment 2
Q-1: Which memory locations contain the five operands used in the addition?
Q-2: Which register pair is used to access the operands stored in memory?
Q-4: How does the ADD M instruction obtain the operand to be added to the Accumula-
tor?
Q-5: What happens to the result when the sum of the values exceeds FFH?
16
Microprocessor Laboratory Experiment 2
Concept Introduced
This activity introduces the following concepts:
• Flag Register
• POP D instruction
17
Microprocessor Laboratory Experiment 2
A = 15H
and the additional bit is indicated by
CY = 1.
For an addition that does not exceed FFH, no Carry is generated. For example,
CY = 0.
Thus, the 8-bit result stored in the Accumulator and the Carry flag together provide
information about the complete result of an 8-bit addition.
does not alter the contents of the Accumulator or the Flag Register. Instead, it saves
their current contents on the stack.
D←A
E←F
where F denotes the Flag Register.
Thus, the Flag Register becomes available in register E. Its contents can then be stored
in memory using a memory-transfer instruction. This provides a means of observing the
Flag Register when it cannot be examined directly through the trainer kit’s register
examination facility.
18
Microprocessor Laboratory Experiment 2
Table 10: Machine Language Program for Observing the Carry Flag
Procedure
1. Press the RESET key to initialize the trainer kit.
2. Press the EXMEM key and enter the memory address 2051H.
19
Microprocessor Laboratory Experiment 2
3. Enter the first operand F5H at memory location 2051H using the DATA INS key.
4. Press the EXMEM key and enter the memory address 2052H.
5. Enter the second operand 20H at memory location 2052H using the DATA INS
key.
7. Press the EXMEM key and enter the starting memory address 2000H.
8. Using the machine code determined in the previous section, enter the complete
program into memory. Press the DATA INS key after entering each byte and use
the NEXT key to advance to the next memory location.
10. Press the GO key and enter the starting address 2000H. The program performs
the addition, stores the result at memory location 2053H, and stores the contents
of the Flag Register at memory location 2054H.
11. Press the EXMEM key and examine memory locations 2051H to 2054H. Record
the observed values in Table 11.
Results
Repeat the addition using the operand combinations given below. Store the two operands
at memory locations 2051H and 2052H, execute the program, and record the result and
Flag Register contents at memory locations 2053H and 2054H, respectively.
Contents of
2051H 2052H 2053H 2054H
68H 27H
B7H 5AH
D4H 3EH
E9H 47H
34H 25H
72H 16H
Q-2: For an addition that generated a Carry, what was the value stored at memory
location 2053H?
20
Microprocessor Laboratory Experiment 2
Q-3: For an addition that generated a Carry, what was the corresponding value of the
Carry flag in the Flag Register stored at memory location 2054H?
Q-4: Compare the mathematical sum of the two operands with the value stored at mem-
ory location 2053H. What happens when the mathematical sum exceeds FFH?
Q-5: Which bit of the Flag Register represents the Carry flag?
Q-6: Why is the Flag Register required in addition to the 8-bit result stored in the
Accumulator?
21
Microprocessor Laboratory Experiment 2
Concept Introduced
This activity introduces the following concepts:
F 52H + 1E0H .
The operands can be written as
0F 52H + 01E0H .
The lower-order bytes are added first:
22
Microprocessor Laboratory Experiment 2
1132H .
The inclusion of the Carry from the lower-order byte is essential for obtaining the
correct multi-byte result.
A ← A + operand + CY (6)
During multi-byte addition, the lower-order bytes are added first using ADD. If this
addition produces a Carry, the Carry flag is set to logic HIGH. The higher-order bytes
are then added using ADC, so that the Carry generated by the lower-order addition is
included automatically.
23
Microprocessor Laboratory Experiment 2
Procedure
1. Press the RESET key to initialize the trainer kit.
2. Press the EXMEM key and enter the memory address 2050H.
3. Enter the four bytes of the two operands at memory locations 2050H to 2053H using
the DATA INS key and the NEXT key to advance to the next memory location.
4. Press the RESET key.
5. Press the EXMEM key and enter the starting memory address 2000H.
6. Using the machine code determined in the previous section, enter the complete
program into memory. Press the DATA INS key after entering each byte and use
the NEXT key to advance to the next memory location.
7. Press the RESET key.
8. Press the GO key and enter the starting address 2000H. The program performs
the lower-byte addition using ADD M and the higher-byte addition using ADC M. The
result is stored at memory locations 2054H and 2055H.
9. Press the EXMEM key and examine memory locations 2054H and 2055H. Record
the observed result in Table 13.
24
Microprocessor Laboratory Experiment 2
Results
Perform the multi-byte addition for the operand pairs given below. Express each operand
as two 8-bit bytes and store the lower-order byte first in memory locations 2050H–2051H
and 2052H–2053H, respectively. Execute the program and record the contents of the
result locations 2054H and 2055H.
Operands Contents of
Operand 1 Operand 2 2050H 2051H 2052H 2053H 2054H 2055H
F 52H 1E0H
A35H 124H
7C8H 295H
B42H 31DH
E8AH 196H
456H 2A3H
Q-1: How are the given multi-byte hexadecimal operands divided into lower-order and
higher-order bytes?
Q-5: What happens to the Carry flag when the addition of the lower-order bytes exceeds
F FH ?
Q-6: Which instruction includes the Carry generated during the lower-byte addition in
the higher-byte addition?
Q-7: Compare the results obtained for cases in which the lower-byte addition generates
a Carry with those in which no Carry is generated.
Q-8: Why would using ADD M instead of ADC M for the higher-order byte produce an
incorrect result when the lower-byte addition generates a Carry?
25
Microprocessor Laboratory Experiment 2
Concept Introduced
This activity introduces the following concepts:
26
Microprocessor Laboratory Experiment 2
25BCD + 37BCD .
The ordinary binary addition produces
25 + 37 = 62.
The DAA instruction examines the result of the preceding addition and the relevant
condition flags to determine whether decimal adjustment is required. Thus, DAA is used
immediately after the binary addition of packed BCD operands when a valid BCD result
is required.
27
Microprocessor Laboratory Experiment 2
Table 14: Machine Language Program for BCD Addition and Decimal Adjustment
Procedure
1. Press the RESET key to initialize the trainer kit.
2. Press the EXMEM key and enter the memory address 2050H.
3. Enter the first packed BCD operand 25BCD at memory location 2050H using the
DATA INS key.
4. Press the EXMEM key and enter the memory address 2051H.
5. Enter the second packed BCD operand 37BCD at memory location 2051H using the
DATA INS key.
7. Press the EXMEM key and enter the starting memory address 2000H.
8. Using the machine code determined in the previous section, enter the complete
program into memory. Press the DATA INS key after entering each byte and use
the NEXT key to advance to the next memory location.
10. Press the GO key and enter the starting address 2000H. The program performs the
BCD addition, stores the unadjusted binary result at memory location 2052H, and
stores the adjusted BCD result at memory location 2053H.
11. Press the EXMEM key and examine memory locations 2050H to 2053H. Record
the observed values in Table 15.
28
Microprocessor Laboratory Experiment 2
Results
Repeat the BCD addition using the operand combinations given below. Store the two
packed BCD operands at memory locations 2050H and 2051H. Execute the program and
record the contents of memory locations 2052H and 2053H after program execution.
Contents of
2050H 2051H 2052H 2053H
Operands Results
25BCD 37BCD
18BCD 21BCD
46BCD 38BCD
57BCD 26BCD
63BCD 19BCD
78BCD 15BCD
Q-1: Which memory location contains the first packed BCD operand?
Q-2: Which memory location contains the second packed BCD operand?
Q-3: Which memory location contains the result immediately after the ADD instruction?
Q-4: Which memory location contains the result after executing the DAA instruction?
Q-5: For which additions was the result obtained immediately after ADD not a valid
packed BCD number?
Q-6: Compare the contents of memory locations 2052H and 2053H. What change is
produced by the DAA instruction?
Q-7: Why is the DAA instruction required when adding packed BCD numbers?
29
Microprocessor Laboratory Experiment 2
Instruction Purpose
ADI Adds 8-bit immediate data to the contents of the Accumulator.
ADD r Adds the contents of the specified register to the Accumulator.
ADD M Adds the contents of the memory location addressed by the H-L register
pair to the Accumulator.
PUSH PSW Stores the contents of the Accumulator and Flag Register on the stack.
POP D Transfers two bytes from the stack to the D-E register pair.
ADC Adds the specified operand and the Carry flag to the contents of the
Accumulator.
DAA Adjusts the Accumulator contents to form a valid packed BCD result
after BCD addition.
8 Viva Questions
Answer the following questions based on the concepts and experiments performed in this
experiment.
1. What is the role of the Accumulator during an addition operation in the Intel 8085?
[BL1]
2. What is the difference between the ADI and ADD instructions? [BL2]
4. Why is the H-L register pair used with the operand M? [BL2]
9. In which register does the Flag Register become available after executing POP D?
[BL1]
12. Why must the lower-order byte be added before the higher-order byte during multi-
byte addition? [BL2]
30
Microprocessor Laboratory Experiment 2
14. Why can ordinary binary addition produce an invalid BCD result? [BL2]
16. Explain why 25H +37H produces 5CH after ordinary binary addition but 62BCD
after DAA. [BL4]
End of Experiment 2
31