Saturday, March 24, 2012

Hexadecimal to BCD conversion using 8086

                      ASSUME CS:CODE,DS:DATA
                             DATA      SEGMENT
                                       ORG      2000H
                        HEXA           DB        55H, 99H, 77H, 22H
                     A_LENTH           EQU       $-ARRAY
                   DECI_NO             DB        12D DUP (0)
                   BCD_NO              DW       4 DUP (0)
                             DATA  ENDS
                             CODE      SEGMENT
                            START: MOV AX,DATA
                                       MOV DS,AX
                                       LEA SI,HEXA
                                       LEA DI,DECI_NO
                                       MOV CX,A_LENTH
                        BACK:          XOR AX,AX
                                       MOV AL,[SI]
                                       MOV BL,64H
                                       DIV BL
                                       MOV [DI],AL
                                       INC DI
                                       MOV AL,AH
                                       XOR AH,AH
                                       MOV BH,0AH
                                       DIV BH
                                       MOV [DI],AL
                                       INC DI
                                       MOV [DI],AH
                                       INC SI
                                       INC DI
                                       LOOP BACK
                                       CALL UP2P
                                       MOV AH,4CH
                                       INT 21H
                UP2P             PROC  NEAR
                                 MOV CH,A_LENTH
                                 LEA DI,DECI_NO
                                 LEA BP,BCD_NO
CONTINUE:                        XOR AX,AX
                                 MOV AH,[DI]
                                 INC DI
                                 MOV AL,[DI]
                                 MOV CL,4
                                 SHL AL,CL
                                 INC DI
                                 ADD AL,[DI]
                                 MOV DS:BP,AX
                                 INC DI
                                 INC BP
                                 INC BP
                                 DEC CH
                                 JNZ CONTINUE
                                 RET
                UP2P             ENDP
                                 CODE             ENDS
                                 END START

No comments:

Post a Comment

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...