GOVERNMENT POLYTECHNIC PUNE
(An Autonomous Institute of Maharashtra)
DEPARTMENT OF COMPUTER ENGINEERING
ACADEMIC YEAR : 2024-25
Micro-Project Report on the topic:
"Binary To Decimal Code Convertor”
Course: DIGITAL TECHNIQUES AND
MICROPROCESSOR
Course Code: CM31204
Guided by:
Smt . B. R. Amrutkar
Lecturer Government Polytechnic
Pune
1
GOVERNMENT POLYTECHNIC
PUNE
(An Autonomous Institute of Maharashtra)
DEPARTMENT OF COMPUTER ENGINEERING
ACADEMIC YEAR : 2024-25
CERTIFICATE
This is to certify that the micro-project entitled “Binary to
Decimal Code Convertor” is bonafide work carried out by:
Mohite Swaraj Sanjay – 2306121 of class Second Year in
partial fulfillment of the requirement for the completion of
course Digital Techniques and Microprocessor (CM31204)
- ODD 2024 of Diploma in Computer Engineering from
Government Polytechnic Pune. The report has been approved
as it satisfies the academic requirements in respect of micro-
project work prescribed for the course.
Prof. B.R Amrutkar Mrs. [Link] Dr. Rajendra [Link]
(Microproject Guide) (Head of Department) (Principal)
2
Project Report
Background
The Binary to Decimal Code Converter is an assembly language program designed to
convert an 8-bit binary input from the user into its decimal equivalent. Written for the
EMU 8086 environment, the program utilizes low-level I/O operations to read user input,
validate it, and perform the conversion. Assembly language programming provides a
deeper understanding of computer architecture and low-level operations compared to high-
level languages.
Problem Statement
As technology increasingly relies on binary representation, converting binary numbers to
decimal is a fundamental task in computing. However, users often require a straightforward
method to perform these conversions without needing extensive technical knowledge. This
program addresses the need for an efficient and user-friendly binary-to-decimal conversion
tool.
Objectives
The project aims to implement a functional Binary to Decimal Code Convertor using 8086
Assembly Language to manage key operations such as:
1. To provide a simple and intuitive user interface for binary input.
2. To validate user input ensuring it consists solely of binary digits (0s and 1s).
3. To convert the validated binary input into its decimal equivalent.
4. To display both signed and unsigned decimal representations of the binary input.
Structure Used
The program employs a modular structure that includes:
A main program that handles user interaction and data flow.
Subroutines for input handling (GET_STRING), output (PRINT_NUM
and PRINT_NUM_UNS), and validation.
Macros for common tasks, such as character printing.
3
Main Program Logic:
1. Display Welcome Message: The program starts by showing a welcome message to the user.
2. Prompt for Binary Input: It prompts the user to enter an 8-bit binary number.
3. Get User Input: The program reads the binary input using the GET_STRING procedure and
stores it in a buffer.
4. Input Validation: It checks each character to ensure they are valid binary digits ('0' or '1'). If
any invalid character is found, it jumps to an error message.
5. Binary to Decimal Conversion.
6. Output Decimal Results: The program checks if the value is signed and prints both the
unsigned and signed decimal results.
7. Error Handling: If invalid input is detected, it displays an error message.
8. Program Termination: It waits for a key press before terminating, allowing the user to see
the results.
Rationale for Key Design Choices
User Input Validation: Ensuring the input strictly consists of binary digits improves
robustness and user experience.
Modular Structure: Using procedures and macros enhances code readability,
maintainability, and reusability.
Direct Output: Utilizing BIOS interrupts for text output provides low-level control
over screen display, typical in assembly language
4
Cos Covered:
• CO1: Use the number system and codes of the digital system.
• CO2: Simplify Boolean expressions for logic circuit.
• CO3: Analyze 8086 microprocessor functionality.
• CO4: Develop assembly language programs.
• CO5: Use procedure and macro in assembly language programs..
Flow Chart:
5
Program :
ORG 100h
; Welcome Message
CALL print
DB 0dh, 0ah,
"Welcome to the
Binary to Decimal
Converter! Created by
Swaraj nd Sayali", 0
DB 0dh, 0ah, 0 ;
New line for better
formatting
; macro
; this macro prints a
char in AL and
advances
; the current cursor
position:
PUTC MACRO
char
PUSH AX
6
MOV AL, char
MOV AH,
0Eh
INT 10h
POP
AX ENDM
.data
; null terminated input
string:
DB "0"
s1 DB "00000000", 0
sum DW 0 ; result.
flag DB 0
.code
; Prompt for binary
input
CALL print
7
DB 0dh, 0ah, "8 bit
binary: ", 0
8
; get string:
MOV DX, 9 ; buffer
size (1+ for zero
terminator).
LEA DI, s1
CALL GET_STRING
; check that we really
got 8 zeros and ones
MOV CX, 8
MOV SI, OFFSET s1
check_s:
CMP [SI], 0
JNE ok0
MOV flag, 1
; terminated.
JMP convert
ok0:
CMP [SI], 'b'
9
JNE ok1
10
MOV flag, 1
; terminated.
JMP convert
ok1:
; wrong digit? Not
1/0?
CMP [SI], 31h
JNA ok2
JMP
error_not_valid
ok2:
INC SI
LOOP check_s
; start the conversion
from string to value in
SUM variable.
convert:
MOV BL, 1 ;
multiplier.
MOV CX, SI
11
SUB CX, OFFSET s1
DEC SI
JCXZ stop_program
next_digit:
MOV AL, [SI] ;
get digit.
SUB AL, 30h
MUL BL ;
no
change to AX.
ADD SUM, AX
SHL BL, 1
DEC SI ; go
to previous digit.
LOOP next_digit
; done! converted
number is in SUM.
; check if signed
12
TEST sum,
13
0000_0000_1000_00
00b
JNZ
print_signed_unsigne
print_unsigned:
CALL print
DB 0dh, 0ah,
"decimal: ", 0
MOV AX, SUM
CALL
PRINT_NUM_UNS
JMP stop_program
print_signed_unsigne
d:
CALL print
DB 0dh, 0ah,
"unsigned decimal: ",
; print out unsigned:
MOV AX, SUM
14
CALL
PRINT_NUM_UNS
CALL print
DB 0dh, 0ah, "signed
decimal: ", 0
; print out signed:
MOV AX, SUM
CBW ; convert byte
into word.
CALL PRINT_NUM
JMP stop_program
error_not_valid:
CALL print
DB 0dh, 0ah, "error:
only zeros and ones
are allowed!", 0
stop_program:
; wait for any key....
CALL print
DB 0dh, 0ah, "press
15
any key...", 0
MOV AH, 0
INT 16h
RET
; procedures
; copied from c:\
emu8086\emu8086.
inc
GET_STRING
PROC
NEAR
PUSH
AX PUSH
CX
PUSH DI
PUSH DX
MOV CX, 0
; char counter.
16
CMP DX, 1
; buffer too small?
JBE empty_buffer
17
DEC DX
; reserve space for last
zero.
;===============
=============
; loop to get and
process key presses:
wait_for_key:
MOV AH, 0
; get pressed
key. INT 16h
CMP AL, 13
; 'RETURN'
pressed? JZ
exit
CMP AL, 8
; 'BACKSPACE'
pressed?
JNE add_to_buffer
JCXZ wait_for_key
18
; nothing to remove!
19
DEC CX
DEC DI
PUTC 8
; backspace.
PUTC ''
; clear position.
PUTC 8
; backspace again.
JMP wait_for_key
add_to_buffer:
CMP CX, DX
; buffer is full?
JAE
wait_for_key ; if
so wait for
'BACKSPACE' or
'RETURN'...
MOV [DI],
AL
INC DI
INC CX
20
; print the key:
MOV AH,
0Eh
INT 10h
JMP wait_for_key
;===============
=============
exit:
; terminate by
null: MOV
[DI], 0
empty_buffer
: POP DX
POP DI
POP CX
POP AX
RET
GET_STRING
21
ENDP
22
; copied from c:\
emu8086\emu8086.
inc
PRINT_NUM
PROC
NEAR
PUSH DX
PUSH AX
CMP AX,
JNZ
not_zero PUTC
'0'
JMP
printed_pn
not_zero:
; the check SIGN
of AX,
23
; make absolute
if it's negative:
CMP AX, 0
JNS positive
24
NEG AX
PUTC '-'
positive:
CALL
PRINT_NUM_UNS
printed_pn:
POP AX
POP
DX RET
ENDP
; copied from c:\
emu8086\emu8086.
inc
PRINT_NUM_UN
S PROC NEAR
PUSH
AX PUSH
BX
25
PUSH CX
PUSH
DX
26
; flag to prevent printing zeros before number:
MOV CX, 1
; (result of "/
10000" is always less
or equal to 9).
MOV BX,
10000 ; 2710h -
divider.
; AX is zero?
CMP AX,
JZ
print_zero
begin_print:
; check divider
(if zero go to
end_print):
CMP BX,0
JZ end_print
27
; avoid printing
zeros before number:
28
CMP CX, 0
JE calc
; if AX<BX then
result of DIV will be
zero:
CMP AX, BX
JB skip
calc:
MOV CX, 0
; set flag.
MOV DX, 0
DIV BX
; AX =
DX:AX / BX
(DX=remainder).
; print last digit
; AH is always
ZERO, so it's ignored
ADD AL, 30h
; convert to ASCII
code.
29
PUTC AL
30
MOV AX, DX
; get remainder from
last div.
skip:
; calculate
BX=BX/10
PUSH AX
MOV DX, 0
MOV AX, BX
DIV CS:ten ;
AX = DX:AX / 10
(DX=remainder).
MOV BX,
AX POPAX
JMP
begin_print
print_zero:
PUTC '0'
end_print:
31
POP DX
POP CX
POP BX
POP
AX RET
ten DW 10
; used as divider.
ENDP
; print text that
follows the caller
print PROC
MOV CS:temp1, SI
; store SI register.
POP SI ;
get return address
(IP).
PUSH AX ;
store AX register.
next_char:
32
MOV
AL, CS:[SI]
INC SI
; next byte.
CMP AL, 0
JZ
printed_ok
MOV AH,
0Eh ;
teletype function.
INT 10h
JMP
next_char ;
loop. printed_ok:
POP AX ;
re-store AX register.
; SI should point to
next command after
; the CALL
33
instruction and string
definition:
PUSH SI ;
save new
return address
into the Stack.
MOV SI, CS:temp1
; re-store SI register.
RET
temp1 DW ? ;
variable to store
original value of
SI register.
ENDP
34
Output:
35
Real-Life Use:
1. Educational Tool for Learning
Understanding Number Systems: The program serves as a practical example for students
learning about binary and decimal number systems. It provides hands-on experience
with conversions, reinforcing theoretical concepts.
Assembly Language Proficiency: Students and learners can practice assembly programming,
improving their skills in low-level coding, debugging, and system architecture
comprehension.
2. Computer Science and Engineering Courses
Curriculum Integration: In computer science curricula, this program can be incorporated into
courses focused on computer architecture, low-level programming, or systems
programming, helping students grasp core concepts more effectively.
Lab Assignments: Instructors can assign this project to students as a lab task, encouraging
them to explore data manipulation and I/O operations.
3. Software Development Training
Foundation for Systems Programming: For those pursuing careers in systems
programming, understanding how to manipulate binary data at a low level is crucial. This
program provides a foundational experience in working with hardware-level data
processing.
Debugging Skills: As students work with assembly language, they develop debugging
skills that are transferable to higher-level languages and software development
environments.
4. Computer Architecture Understanding
Binary Representation Knowledge: Understanding how computers represent data in binary
is essential for anyone in the field of computer science. This program illustrates the binary-
to-decimal conversion process, deepening comprehension of data representation
Real-World Applications: Knowledge gained can be applied in scenarios like
understanding how data is processed in microcontrollers, embedded systems, and
various hardware configurations.
Interface Development: In projects involving user interfaces for hardware, understanding
5. Tool for Developers
36
Quick Conversion Utility: Developers can modify this program into a quick utility for on-
the-fly binary-to-decimal conversions while working on projects, improving productivity
in tasks requiring frequent number conversions.
37
Integration into Larger Projects: The logic of this program can be integrated into
larger software projects where binary data manipulation is necessary, such as file
format converters or network communication tools.
6. Support for Algorithm Development
Algorithm Understanding: By implementing this program, developers can better
understand algorithms that deal with binary data manipulation, such as sorting
algorithms that require bitwise operations, which are common in various computational
tasks.
Efficiency Exploration: This can also lead to discussions on efficiency in algorithms,
as binary data can be processed more quickly than decimal data in many cases.
Skills Developed :
1. Assembly Language Proficiency
Syntax Familiarity: Understanding the syntax and structure of assembly language, including
directives, macros, and procedures.
Instruction Set Knowledge: Gaining familiarity with the 8086 instruction set and how to utilize it
effectively for various operations.
2. Low-Level Data Manipulation
Memory Management: Learning how to manage memory effectively, including using registers
and pointers for data storage and retrieval.
Bitwise Operations: Developing skills in performing bitwise operations essential for handling
binary data.
3. Input and Output Handling
Keyboard Input Management: Gaining experience in capturing and processing user input
through keyboard interrupts.
Screen Output Techniques: Understanding how to manipulate screen output using BIOS
interrupts for text display.
4. Input Validation Techniques
Error Checking: Learning how to validate user input to ensure data integrity and robustness of
the program.
Handling Edge Cases: Developing skills to anticipate and manage incorrect input scenarios
gracefully.
5. Algorithmic Thinking
Conversion Logic: Understanding the algorithm for converting binary to decimal, reinforcing
logical thinking and problem-solving skills.
Looping and Control Structures: Practicing the use of loops and conditionals to manage program
flow and data processing.
38
6. Debugging Skills
39
Troubleshooting Techniques: Gaining experience in debugging assembly language code, which
often involves understanding how the CPU processes instructions at a low level.
Conclusion :
The Binary to Decimal Converter program is more than just a learning tool; it has practical
applications across various fields. By facilitating a deeper understanding of binary data
manipulation, it equips users with essential skills for careers in technology, engineering, and
computer science, enhancing both academic and professional opportunities.
40