Skip to content
Related Articles

Related Articles

8086 program to convert 8 bit BCD number into ASCII Code
  • Last Updated : 22 Aug, 2018

Problem – Write an assembly language program in 8086 microprocessor to convert 8 bit BCD number to its respective ACSII Code.

Assuption –
Starting address of program: 400
Input memory location: 2000
Output memory location: 3000

Example :

Input: 
DATA: 98H in memory location 2000

Output:
DATA: 38H in memory location 3000 and 
      39H in memory location 3001 

Algorithm –

  1. Load contents of memory location 2000 in register AL
  2. Copy contents of register AL in register AH
  3. Perform AND operation on register AL with 0F
  4. Assign 04 to CL Register
  5. Shift the contents of AH by executing SHR instruction using CL
  6. Perform OR operation on register AX with 3030
  7. Store the content of AX in memory location 3000

Program –



Memory AddressMnemonicsComments
400MOV AL, [2000]AL<-[2000]
404MOV AH, ALAH<-AL
406AND AL, 0FAL <- (AL AND 0F)
408MOV CL, 04CL <- 04
40ASHR AH, CLShift AH content Right by 4 bits(value of CL)
40COR AX, 3030AX <- (AX OR 3030)
40FMOV [3000], AX[3000]<-AX
413HLTStop Execution

Explanation –

  1. MOV AL, [2000]: loads contents of memory location 2000 in AL
  2. MOV AH, AL: copy contents of AL in AH
  3. AND AL, 0F: do AND operation on AL with 0F
  4. MOV CL, 04 assign 04 to CL register
  5. SHR AH, CL: shift the content of AH register right by 4 bits i.e. value of CL register
  6. OR AX, 3030: do OR operation on AX with 3030
  7. MOV [3000], AX: stores the content of AX register pair in 3000 memory address
  8. HLT: stops executing the program

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :