0% found this document useful (0 votes)
16 views9 pages

Pracical 2

The document outlines two methods for adding 16-bit numbers using the 8085 assembly language: one using 8-bit operations and the other using 16-bit operations, with corresponding algorithms and programs provided. It also explains how to add two decimal numbers using the DAA instruction to ensure valid BCD results, detailing the process with examples. Additionally, it includes timing information for the DAA instruction execution.

Uploaded by

avani.raval
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)
16 views9 pages

Pracical 2

The document outlines two methods for adding 16-bit numbers using the 8085 assembly language: one using 8-bit operations and the other using 16-bit operations, with corresponding algorithms and programs provided. It also explains how to add two decimal numbers using the DAA instruction to ensure valid BCD results, detailing the process with examples. Additionally, it includes timing information for the DAA instruction execution.

Uploaded by

avani.raval
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/ 9

8085 program to add two 16 bit

numbers

a) Addition of 16 bit numbers using 8 bit operation – It is a lengthy


method and requires more memory as compared to 16 bit operation.
Algorithm –
1. Load the lower part of first number in B register
2. Load the lower part of second number in A (accumulator)
3. Add both the numbers and store
4. Load the higher part of first number in B register
5. Load the higher part of second number in A (accumulator)
6. Add both the numbers with carry from the lower bytes (if any) and store at
the next location
MEMORY
ADDRESS MNEMONICS COMMENTS

2000 LDA 2050 A ← 2050

2003 MOV B, A B←A

2004 LDA 2052 A ← 2052

2007 ADD B A ← A+B

2008 STA 3050 A → 3050

200B LDA 2051 A ← 2051

200E MOV B, A B←A

200F LDA 2053 A ← 2053

2012 ADC B A ← A+B+CY

2013 STA 3051 A → 3051

(b) Addition of 16 bit numbers using 16 bit operation – It is a very short


method and less memory is also required as compared to 8 bit operation.
Algorithm –
1. Load both the lower and the higher bits of first number at once
2. Copy the first number to another register pair
3. Load both the lower and the higher bits of second number at once
4. Add both the register pairs and store the result in a memory location
Program –
Program –
MEMORY
ADDRESS MNEMONICS COMMENTS

2000 LHLD 2050 H-L ← 2050

2003 XCHG D H&E L


MEMORY
ADDRESS MNEMONICS COMMENTS

2004 LHLD 2052 H-L ← 2052

H ← H+D & L ←
2007 DAD D L+E

2008 SHLD 3050 A → 3050

200B HLT Stops execution

Explanation –
1. LHLD 2050 loads the value at 2050 in L register and that in 2051 in H
register (first number)
2. XCHG copies the content of H to D register and L to S register
3. LHLD 2052 loads the value at 2052 in L register and that in 2053 in H
register (second number)
4. DAD D adds the value of H with D and L with E and stores the result in H
and L
5. SHLD 3050 stores the result at memory location 3050
6. HLT stops execution

a) Write an 8085 assembly language program to add two decimal numbers using DAA
instruction
Let us consider we want to add two decimal numbers 38 and 45. They will be
represented in BCD as 0011 1000 and 0100 0101. The addition results in 0111
1101. But the answer will be incorrect if we want to interpret this result as a BCD
number. The result will be not only incorrect but also illegal as 1101, which we
obtained as the last nibble in the answer is not a valid BCD number. Here, in such
situations, we can use DAA to have the BCD sum as outcome. All that is required to
be done is to add the BCD numbers and store the result in A, and then execute the
DAA instruction.
Here is the detailing of the calculations −
38 ---> 0011 1000
+ 45 ---> 0100 0101
---- ---------
83 0111 1101
---- ----
7 D
The working of DAA instruction depends on the contents of the AL register, Cy, and
AC flags. In effect, it adds 00H, 06H, 60H, or 66H to Accumulator so as to get the
correct BCD answer in the Accumulator. So here is the illustration of the remedial
actions against the previous example −
38 ---> 0011 1000
+ 45 ---> 0100 0101
---- --------- 1
83 0111 1101 0111 1101
---- ---- + 0110 (06H)
7 D ---------
1000 0011 ---> 83 (Decimal sum)
As the summary of all related rules are listed below −
 If the LS hex digit in A is <= 9 and AC flag is 0, the LS hex digit value will not
be altered.
 If the LS hex digit is >9, or if AC flag is set to 1, it adds 6 to the LS hex digit of
A. If carry results, then it increments the MS hex digit if this addition resulted
in a carry to the MS digit position. In this process, the Cy flag will be set to 1 if
the MS hex digit was incremented from F to 0.
 If the MS hex digit is <= 9 and Cy flag is 0, the MS hex digit will not be altered,
and Cy flag is reset to 0.
 If the MS hex digit is > 9, or if Cy flag is set to 1, it adds 6 to the MS hex digit
of A and sets Cy flag to 1.
Note that for decimal subtraction DAA instruction cannot be used. Due to
unavailability of decimal subtraction in Intel 8085 instruction set, a series of
instructions are to be executed to perform decimal subtraction.
Let us consider some examples −
Example – 1
Addres Hex Mnemoni Comment
s Codes c

2000 3E MVI A, A ← 38H


38H

2001 38 38H as operand

2002 06 MVI B, B ← 45H


45H
Addres Hex Mnemoni Comment
s Codes c

2003 45 45H as operand

2004 80 ADD B A ← A + B; A <- 38H + 45H; A ← 7DH

2005 27 DAA A ← 83H (Decimal Sum), S = 1,Z = 0,Ac = 1,P = 0,Cy = 0 06H
got added with the Accumulator content. As Cy=0, so interpreted
result is 83 in decimal

Example – 2
Addres Hex Mnemoni Comment
s Codes c

2000 3E MVI A, A ← 38H


38H

2001 38 38H as operand

2002 06 MVI B, B ← 41H


41H

2003 41 41H as operand

2004 80 ADD B A ← A + B; A <- 38H + 41H; A <- 79H

2005 27 DAA A ← 79H (Decimal Sum), S = 0,Z = 0,Ac = 0,P = 0,Cy = 0 00H
got added with the Accumulator content. As Cy = 0, so
interpreted result is 79 in decimal

Example – 3
Addres Hex Mnemonic Comment
s Codes

2000 3E MVI A, A ← 83H


Addres Hex Mnemonic Comment
s Codes

83H

2001 83 83H as operand

2002 06 MVI B, B ← 54H


54H

2003 54 54H as operand

2004 80 ADD B A ← A + B; A ← 83H + 54H; A ← D7H

2005 27 DAA A ← 37H (Decimal Sum), S=0,Z=0,Ac=0,P=0,Cy=1 60H got


added with the Accumulator content. As Cy=1, so interpreted
result is 137 in decimal

Example – 4
Addres Hex Mnemonic Comment
s Codes

2000 3E MVI A, A ← 88H


88H

2001 88 88H as operand

2002 06 MVI B, B ← 44H


44H

2003 44 44H as operand

2004 80 ADD B A ← A + B; A <- 88H + 44H; A ← CCH

2005 27 DAA A ← 32H (Decimal Sum), S=0,Z=0,Ac=0,P=0,Cy=1 66H got


added with the Accumulator content. As Cy=1, so interpreted
Addres Hex Mnemonic Comment
s Codes

result is 132 in decimal

The timing diagram against this instruction DAA execution is as follows −


Summary − So this instruction DAA requires 1-Byte, 1-Machine Cycle (Opcode
Fetch) and 4 T-States for execution as shown in the timing diagram.

You might also like