16-bit Hex is converted to BCD and 16-bit BCD is converted to equivalent Hex value using Assembly programming.
BCD to Hex Conversion
Aim:
To perform BCD to Hex number conversion using Assembly language for 8086 microprocessor.
Software Used:
MASM
Program Code:
CODE	SEGMENT	
	        MOV BX, DX
	        AND BX, 0F000H
	        MOV CL, 0CH
	        SHR BX, CL
	        MOV BH, DH
	        AND BH, 0FH
	        MOV SI, BX
	        MOV BX, DX
	        AND BX, 00F0H
	        MOV CL, 04H
	        SHR BX, CL
	        MOV BH, DL
	        AND BH, 0FH
	        MOV DI, BX
	        MOV BX, SI
	        MOV AX, 03E8H
	        AND BX, 000FH
	        MUL BX
	        MOV DX, AX
	        MOV BX, SI
	        MOV AL, 64H
	        MUL BH
	        ADD DX, AX
	        MOV BX, DI
	        MOV AL, 0AH
	        MUL BL
	        ADD DX, AX
	        MOV CL, 08H
	        SHR BX, CL
	        ADD DX, BX
	        HLT
CODE	ENDS
	        END
Sample Input and Output:
Input BCD Value: 4522h
Output Hex Value: 11AAh
Result:
BCD to Hex conversion is performed.
Hex to BCD Conversion
Aim:
To perform Hex to BCD number conversion using Assembly language for 8086 microprocessor.
To perform Hex to BCD number conversion using Assembly language for 8086 microprocessor.
Software Used:
MASM
Program Code:
CODE	SEGMENT	
	        MOV AX, DX
	        CWD
	        MOV DI, 03E8H
	        DIV DI
	        MOV BX, AX
	        MOV AX, DX
	        CWD
	        MOV DI, 0064H
	        DIV DI
	        MOV SI, AX
	        MOV AX, DX
	        CWD
	        MOV DI, 000AH
	        DIV DI
	        MOV CL, 04H
	        SHL AX, CL
	        OR DX, AX
	        MOV CL, 04H
	        SHL BX, CL
	        OR BX, SI
	        MOV DH, BL
	        HLT
CODE	ENDS
	        END
Sample Input and Output:
Input Hex Value: 11AAh
Output BCD Value: 4522h
Result:
Hex to BCD conversion is performed.
No comments:
Post a Comment