You are on page 1of 11

A Project Report

On

“Convert BCD number to equivalent HEXADECIMAL number”


Submitted & Presented in the fulfillment of the
requirement for the award of Diploma in
Computer Engg.

By

Ms.Doke S.M.
Mr.Surve A.S.
Ms.Shaikh S.A.
Ms.Ubale R.J.

Under The Guidance of


Ms.Sugandhi.P.S

Department of
COMPUTER ENGINEERING
NEW SATARA COLLEGE OF ENGINEERING AND
MANAGMENT,
KORTI-PANDHARPUR

A.Y. 2022-2023

1
NEW SATARA COLLEGE OF ENGINEERING AND MANAGMENT,
KORTI-
PANDHARPUR

This is to certify that the project report “Convert BCD number to equivalent

HEXADECIMAL number” ”has been presented successfully and submitted

by,

Name Of The Students Exam Seat No.

Ms. DOKE SWAPNALI MOHAN

Mr.SURVE ARYAN SOPAN

Ms.SHAIKH SANIYA AHAMAD

Ms. UBALE ROSHANI JITENDRA

Student of MIC (Com.Eng.) class in the fulfillment for the award of Diploma in

Com.Engg as per curriculum laid by the Maharashtra State Board of Technical

Education, Mumbai. during the academic year 2023-2024

Subject teacher H.O.D Principal.


Prof..Sugandhi.P.S Prof. Puri S.B. Prof. Londhe. V.H.

2
Acknowledgement

It gives me great pleasure to express my gratitude towards MIC teacher Ms.Sugandhi.P.S

for her guidance support and encouragement throughout the duration of the project without his

motivation and help the successful completion of this project would not have been possible.

We are very much thankful of Mr. Puri S.B. HOD General Science Dept. for

the great support and guidance.

We are also equally indebted to our principal Prof. Londhe V. H. for his valuable

help whenever needed.

3
Index

Sr. No Title Page No.

5
1 Introduction

2 Algorithm 6

Flowchart
7
3

Program
4 8-9

5 Explanation 10

6 Reference 11

4
Introduction

In computing, BCD (Binary Coded Decimal) is a way of representing decimal numbers using
four bits per decimal digit. Each decimal digit is represented by its binary equivalent, with a
separate nibble (four bits) for the tens and units places. BCD is often used in computer systems
that require precise decimal arithmetic, such as financial applications.

To convert a BCD number to its equivalent hexadecimal representation, you can use the
following steps:

1. Separate the BCD number into groups of four bits (also known as nibbles).
2.
3. Convert each nibble to its equivalent hexadecimal value using the following table:
4. Concatenate the hexadecimal values obtained from step 2 to form the final hexadecimal
representation of the BCD number.

For example, let's convert the BCD number 0100 0001 0110 1001 to its equivalent hexadecimal
representation:

1. Separate the BCD number into groups of four bits: 0100 0001 0110 1001.
2. Convert each nibble to its equivalent hexadecimal value: 4 0 1 6 9.
3. Concatenate the hexadecimal values: 40169.

Therefore, the BCD number 0100 0001 0110 1001 is equivalent to the hexadecimal number
40169.

5
 Algorithm –

STEP 1 ; START

STEP 2 Assign value 500 in SI and 600 in DI ,Move the contents of [SI] in BL.

STEP 3: Use AND instruction to calculate AND between 0F and contents of BL.

STEP 4 : Move the contents of [SI] in AL.

STEP 5: Use AND instruction to calculate AND between F0 and contents of AL.

STEP 6 :Move 04 in CL.

STEP 7;Use ROR instruction on AL.

STEP 8:Move 0A in DL.

STEP 9:Use MUL instruction to multiply AL with DL.

STEP 10:Use ADD instruction to add AL with BL.

STEP 11: Move the contents of AL in [DI].

STEP 12: Halt the program

STEP 13:STOP.

6
 flowchart

7
 program
The program defines a BCD input string as well as a buffer for the hexadecimal output. It then
initializes the registers and sets up a loop to convert each nibble of the BCD input to its
hexadecimal equivalent.

Within the loop, the program gets the next nibble from the BCD input, converts it to
hexadecimal, and stores it in the output buffer. It then advances the input and output pointers
and repeats the process until all nibbles have been converted.

After the loop, the program null-terminates the output buffer and prints it to the console using
the write system call. Finally, it exits the program with a return code of 0.

To run the program, you'll need to assemble and link it using a tool like NASM and then
execute the resulting binary. Note that the program assumes a Linux environment and uses the
32-bit x86 calling convention.

BCD to Hex in macroprocessor


Here's an example macroprocessor program that takes a BCD input and converts it to its
equivalent hexadecimal representation using the MASM macroprocessor:

section .data
bcd_input db '0100000101101001' ; BCD input as a string
bcd_length equ $ - bcd_input ; Length of BCD input in bytes
hex_output db 8 dup(0) ; Hexadecimal output buffer

section .text
global _start

_start:
; Initialize registers
xor eax, eax ; Clear EAX register
xor ebx, ebx ; Clear EBX register
xor ecx, ecx ; Clear ECX register
xor edx, edx ; Clear EDX register

; Convert BCD to hexadecimal


mov ecx, bcd_length ; Set ECX to length of BCD input
mov ebx, bcd_input ; Set EBX to address of BCD input
lea esi, hex_output ; Set ESI to address of hex output buffer

convert_loop:
; Get next nibble from BCD input
mov al, [ebx]
and al, 0x0F

; Convert nibble to hexadecimal and store in output buffer


cmp al, 10

8
jl convert_digit
add al, 7

convert_digit:
add al, 0x30
mov [esi], al
inc esi
inc ebx
loop convert_loop

; Null-terminate output buffer


mov byte [esi], 0

; Print hexadecimal output


mov eax, 4 ; System call for write
mov ebx, 1 ; File descriptor for stdout
mov ecx, hex_output ; Address of output buffer
mov edx, 8 ; Length of output buffer
int 0x80 ; Call kernel

; Exit program
mov eax, 1 ; System call for exit
xor ebx, ebx ; Return code 0
int 0x80 ; Call kernel

9
 Explanation
The program defines the BCD input and hexadecimal output strings, as well as two macros:
CONVERT_NIBBLE and BCD_TO_HEX.

The CONVERT_NIBBLE macro takes a nibble and an output pointer as arguments and
converts the nibble to its hexadecimal representation using a conditional statement and stores it
in the output buffer. The BCD_TO_HEX macro takes input and output pointers as arguments
and sets up a loop to convert each nibble of the BCD input to its hexadecimal equivalent using
the CONVERT_NIBBLE macro.

The main program calls the BCD_TO_HEX macro with the BCD input and hexadecimal
output buffer as arguments, and then prints the output buffer to the console using the write
system call. Finally, it exits the program with a return code of 0.

To run the program, you'll need to assemble and link it using a tool like MASM and then
execute the resulting binary. Note that the program assumes a Windows environment and uses
the 32-bit x86 calling convention.

The program defines the BCD input and hexadecimal output strings in the .data section. It then
sets up the DS register and initializes the pointers and registers for the conversion process in the
.text section.

The convert_loop section sets up a loop to convert each nibble of the BCD input to its
hexadecimal equivalent. It calls the convert_nibble subroutine to convert each nibble and store
the result in the output buffer.

The convert_nibble subroutine takes a nibble in the BL register and converts it to its
hexadecimal representation using a conditional statement. It stores the result in the output
buffer and returns to the calling code.

After the conversion is complete, the program null-terminates the output string and prints it to
the console using the int 21h interrupt with function code 9h. Finally, it exits the program with
an interrupt call to int 21h with function code 4Ch.

To run the program, you'll need to assemble it using an 8086 assembler like NASM and then
execute the resulting binary. Note that the program assumes a DOS environment and uses the
16-bit x86 calling convention.
Regenerate response

10
 Refreance

Link 1. www.geeksforgeeks.org
Link 2. www.tutorialspoint.com
And my subject teacher Ms.Sugandhi.P.S & Book

11

You might also like