Assembly Language Program for Unpacking the Packed BCD number in 8085 Microprocessor

Binary coded decimal (BCD) is a way to express each of the decimal digits with a binary code. This means that each decimal digit, 0 through 9, is represented by a binary code of four bits.

Eg: 98 => 10011000

Unpacking the BCD number is separating each BCD digit.

Eg: 98 can be separated as 09 and 08. So we can say 10011000 [98] is packed and 00001001 [09] & 00001000 [08] are unpacked.


You might like to go through Step by step Process to add two packed BCD Numbers


Assembly language program to unpack the packed BCD number

// Manually store the packed BCD number [eg: 98 in this case] in the memory locations 3000H
// Store the result i.e, the unpacked numbers in the memory locations 3001H and 3002H
// For this Example result will be 09 and 08
// 3000<-09, 3001<-08

#ORG 0000H
#BEGIN 0000H

    LDA 3000H  //Get the packed BCD number from the memory
    MOV B,A
    MVI C,04
    ANI F0     // A = 90H

L1: RRC        // Need to be rotated right for 4 times to get A = 09H
    DCR C
    JNZ L1

    STA 3001
    MOV A,B
    ANI 0F     // A = 08H
    STA 3002
    HLT

#ORG 3000H
#DB 98H

Now when you would run the program it would give you the memory locations with the following values:

Unpacking BCD Number

Note: The above Hex codes have been assembled and simulated on Jubin’s 8085 Simulator.

Hope the post would help you. If any doubt, please mention the same in the comment section, we would revert back to you.

 

Multiplication of 8-Bit Numbers in 8085 Microprocessor: Illustration of 3 Different Cases

8085 is a very basic microprocessor with the capability of limited arithmetic and logical operations. It has dedicated arithmetic instructions for addition, subtraction, increment and decrement. If we want to perform a multiplication operation then we need to write a program for it. Multiplication is nothing but repeated addition. This post presents assembly language program for the multiplication of two 8-bits numbers with the illustration of 3 different cases.

The maximum result from the multiplication of two 8-bit numbers can be up-to 16-bits.

FFH x FFH = FE01H

The following three cases can arise for the multiplication of different 8-bit numbers:

(i) The generated result is a 8-bit number

eg: 02H x 03H = 06H

(ii) The generated result is a 9-bit number with “1” at the ninth bit

eg: FFH x 02H = 1FEH

(iii) The generated result is lager than 9-bit number

eg: A7H x F2H = 9DDEH


You might find Different Coding Styles of Verilog Language interesting


Let’s start with the 1st case and move on to the 3rd case:

The generated result is a 8-bit number:

Result below 8-bits

// Manually store the multiplicand and the multiplier in the memory locations 4200H & 4201H respectively
// For this case let's say multiplicand = 03H and the multiplier = 04H
// Store the result in the memory location 4202H and 4203H
// For this Example result will be 03H x 04H = 0CH
// 4202<-00H, 4203<-0CH

#ORG 0000H
#BEGIN 0000H

    LDA 4200H  // Fetched the Multiplicand
    MOV B,A    
    LDA 4201H  // Fetched the Multiplier
    MOV D,A
    MVI A,00H  // Cleared the Acuumulator for multiple addition of the Multiplicand
L1: ADD B
    DCR D
    JNZ L1     // Repeated Addition for multiplication
    STA 4203
    HLT

#ORG 4200H
#DB 03H, 04H

 Now when you would run the program it would give you the memory locations with the following values

Memory Location

Input

4200     4201

03         04

Output

4202     4203

00        0C

In this case we get 00H in 4202H as there is no carry generated in this example. Let’s consider the 2nd case example (FFH x 02H = 1FEH) where a carry would be generated. The above program would generate the result as FEH but the carry would be 00H. Let’s modify the program to deal with this type of situation.

The generated result is a 9-bit number with “1” at the ninth bit:

Result 9-bits

// For this case let's say multiplicand = FFH and the multiplier = 02H
// Result would be FFH x 02H = 1FEH
// 4202<-01H, 4203<-FEH

#ORG 0000H
#BEGIN 0000H

    MVI C,00H  // Preserves the Carry  
    LDA 4200H  // Fetched the Multiplicand
    MOV B,A    
    LDA 4201H  // Fetched the Multiplier
    MOV D,A
    MVI A,00H  // Cleared the Acuumulator for multiple addition of the Multiplicand
L1: ADD B
    DCR D
    JNZ L1     // Repeated addition for multiplication
    JNC L2     // Jump if no carry generated
    INR C
L2: STA 4203
    MOV A,C
    STA 4202
    HLT

#ORG 4200H
#DB FFH, 02H

Now when you would run the program it would give you the memory locations with the following values

Memory Location

Input

4200     4201

FF         02

Output

4202     4203

01        FE

In this case we get 01H in 4202H as there is a single carry generated in this example. Let’s consider the 3rd case example (A7H x F2H = 9DDEH) where multiple carries would be generated during the repeated additions. The above program would generate the result as DEH but the carry would be 01H. Let’s modify the program to deal with this type of situation.

The generated result is lager than 9-bit number:

Result more than 9-bits

// For this case let's say multiplicand = A7H and the multiplier = F2H
// Result would be A7H x F2H = 9DDEH
// 4202<-9DH, 4203<-DEH

#ORG 0000H
#BEGIN 0000H

    MVI C,00H  // Preserves the Carry  
    LDA 4200H  // Fetched the Multiplicand
    MOV B,A    
    LDA 4201H  // Fetched the Multiplier
    MOV D,A
    MVI A,00H  // Cleared the Acuumulator for multiple addition of the Multiplicand
L1: ADD B
    JC L2      // Jump if carry generated
    DCR D
    JNZ L1     // Repeated addition for multiplication
    JMP L3     // Jump after the repeated additions get completed
L2: INR C
    DCR D
    JNZ L1
L3: STA 4203
    MOV A,C
    STA 4202
    HLT

#ORG 4200H
#DB A7H, F2H

Memory Location

Input

4200     4201

A7         F2

Output

4202     4203

9D        DE

Note: The above Hex codes have been assembled and simulated on Jubin’s 8085 Simulator.

Hope the post would help you. If any doubt, please mention the same in the comment section, we would revert back to you.

Addition of 16-bit Numbers in 8085

This post would present you with assembly language program for 16-bit addition in 8085 microprocessor. The following Hex Code is a generic one for both no-carry and carry generation situation.

// Manually store 1st 16-bit number in the memory location 2000H & 2001H in reverse order
// For Example 1st number = B349H; i.e, 2000<-49H & 2001H<-B3H
// Manually store 2nd 16-bit number in the memory location 2002H & 2003H in reverse order
// For Example 2nd number = 81B6H; i.e, 2002<-B6H & 2003<-81H
// Store the result in the memory location 2004H, 2005H
// Store the carry in the memory location 2006H
// For this Example result will be B349H + 81B6H = 134FFH
// 2004<-FFH, 2005<-34H, 2006<-01H

#BEGIN 0000H       // Program counter will be loaded with 0000H
LHLD 2000H         // L<-49H, H<-B3H; HL=B349H
XCHG               // DE<-HL; DE = B349H
LHLD 2002H         // L<-B6H, H<-81H
MVI C,00H          // Clear the Register C
DAD D              // HL<-HL+DE; HL<-34FFH
JNC LABEL          // Jump to the position LABEL
INR C              // C<-01H

LABEL: SHLD 2004H  // 2004H<-FFH, 2005H<-34H
       MOV A,C     // A<-C
       STA 2006H   // 2006<-01H
HLT                // Stop the Program

#ORG 2000H         // Loads the DB values starting from this address
#DB 49H,B3H,B6H,81H



Memory Location

Input

2000     2001     2002     2003

49         B3        B6         81

Output

2004     2005     2006

FF        34         01

Note: The above Hex code has been assembled and simulated on Jubin’s 8085 Simulator. If you find any error wile assembling the above code then just remove the comment lines written right to the code lines.

Addition of 8-bit Numbers in 8085

This post would present you with assembly language program for 8-bit addition in 8085 microprocessor. We will consider 2 different cases of addition

(i) Addition of two 8-bit numbers generating no carry

(ii) Addition of two 8-bit numbers generating a carry

Addition of two 8-bit numbers generating no carry

// Manually store 1st number in the memory location 2000H
// For Example 1st number = 18H; i.e, 2000<-18H
// Manually store 2nd number in the memory location 2001H
// For Example 2nd number = 29H; i.e, 2001<-29H
// Store the result in the memory location 2003H
// For this Example result will be 18H + 29H = 41H

#BEGIN 0000H     // Program counter will be loaded with 0000H
LDA 2000H        // A<-18H
MOV B,A          // B<-18H
LDA 2001H        // A<-29H
ADD B            // A<-A+B; A<-41H
STA 2003H        // 2003<-41H
HLT              // Stop the Program

#ORG 2000H       // Loads the DB values starting from this address
#DB 18H,29H

Note: If you find any error wile assembling the above code then just remove the comment lines written right to the code lines.

Following are the screenshots after assembling the above Hex code” and the memory content after simulating the code”.

8-bit addition assembler

Assembled Code

8-bit addition Memory Editor

Memory Content

Note: The code has been assembled and simulated on Jubin’s 8085 Simulator

Addition of two 8-bit numbers generating a carry

The following Hex Code is applicable for no carry generation also. This program is a generic one for both no-carry and carry generation situation.

// Manually store 1st number in the memory location 2000H
// For Example 1st number = A9H; i.e, 2000<-A9H
// Manually store 2nd number in the memory location 2001H
// For Example 2nd number = B8H; i.e, 2001<-B8H
// Store the result in the memory location 2002H
// Store the carry in the memory location 2003H
// For this Example result will be A9H + B8H = 161H
// 2003<-01H, 2002<-61H

#BEGIN 0000H     // Program counter will be loaded with 0000H
LDA 2000H        // A<-A9H
MOV B,A          // B<-A9H
LDA 2001H        // A<B89H
MVI C,00H        // Clear the Register C
ADD B            // A<-A+B; A<-61H
JNC LABEL        // Jump to the position LABEL
INR C            // C<-01H

LABEL: STA 2002H // 2002H<-61H
       MOV A,C   // A<-C
       STA 2003H // 2003<-01H
HLT              // Stop the Program

#ORG 2000H       // Loads the DB values starting from this address
#DB A9H,B8H