Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

BHARATI VIDYAPEETH

(DEEMED TO BE UNIVERSITY)

Project Report
For the fulfilment of Project Based Learning
At
COLLEGE OF ENGINEERING, PUNE – 43

SUBJECT: COMPUTER ORGANISATION AND DESIGN

1
TOPIC

IMPLEMENT BINARY SEARCH


USING
ASSEMBLY LANGUAGE

Submitted By:

AMIT KUMAR GHOSH Roll no: -18; PRN No: - 2114110081


JYOTISH KUMAR MAHATO Roll no: -48; PRN No: -2114110112
SAHEBJEET SINGH Roll no: -09; PRN NO: -2114110072
PRATYUSH KHUNT Roll no: -10; PRN NO: - 2114110073
RAJ ARYAN Roll no. 06; PRN NO: -2114110069

Submitted To: Prof. Shruti Gunjotikar

2
ACKNOWLEDGEMENT
At the outset of this project-based learning we want to extend my
whole hearted gratitude to all the faculty members without the help of
whom this project could’ t have been possible. We want to extend our
heartily regard to Prof. Shruti mam, under the guidance of whom we
have completed this report and which also helped us in doing a lot of
research and also we have learned many new things. We would also
like to thank other faculty members for their whole hearted
cooperation and valuable guidance. We would also like to thank our
friends for their valuable suggestions and guidance to make this report
a successful one.

3
CONTENTS

Sl.no. Topic Page no.

1. Introduction 5

2. What is Assembly Language? 6

3. What is Binary Search? 7


3.1 Binary Search Algorithm

4. Binary Search using Assembly Language 8-9


4.1 CODE

5. CODE OUTPUT 10

6. Benefits Of Learning Assembly 11


Language

7. Features 12

8. Advantages and Disadvantages 13

9. Conclusion 14

4
INTRODUCTION
Each personal computer has a microprocessor that manages the
computer's arithmetical, logical, and control activities.

Each family of processors has its own set of instructions for handling
various operations such as getting input from keyboard, displaying
information on screen, and performing various other jobs. These set of
instructions are called 'machine language instructions'.

A processor understands only machine language instructions, which


are strings of 1's and 0's. However, machine language is too obscure
and complex for using in software development. So, the low-level
assembly language is designed for a specific family of processors that
represents various instructions in symbolic code and a more
understandable form.

5
WHAT IS ASSEMBLY LANGUAGE?
Assembly Language is a low-level programming language. It helps in
understanding the programming language to machine code. In
computers, there is an assembler that helps in converting the
assembly code into machine code executable. Assembly language is
designed to understand the instruction and provide it to machine
language for further processing. It mainly depends on the architecture
of the system, whether it is the operating system or computer
architecture.

Assembly Language mainly consists of mnemonic processor


instructions or data and other statements or instructions. It is
produced with the help of compiling the high-level language source
code like C, C++. Assembly Language helps in fine-tuning the
program.

6
WHAT IS BINARY SEARCH?
Binary Search is a searching algorithm used in a sorted array
by repeatedly dividing the search interval in half. The idea of binary
search is to use the information that the array is sorted and reduce
the time complexity to O (Log n).

Binary Search Algorithm:

The basic steps to perform Binary Search are:


• Begin with the mid element of the whole array as a search
key.
• If the value of the search key is equal to the item, then return
an index of the search key.
• Or if the value of the search key is less than the item in the
middle of the interval, narrow the interval to the lower half.
• Otherwise, narrow it to the upper half.
• Repeatedly check from the second point until the value is
found or the interval is empty.

7
Binary Search using Assembly Language:
CODE:
.model small
.data
arr dw
0000h,1111h,2222h,3333h,4444h,5555h,6666h,7777h,8888h
len dw ($-arr)/2 ;len=(last_index - first_index)/2
key equ 4444h ;key to Search
msg1 db "key is found at ";If found then the message executes
res db " position", 0, "$";determines the position of the element
where it is found
msg2 db 'key not found!!!!!!!!!!!!!. $';If not found then the message
executes

.code
start:
mov ax,@data;Initializing the data segment
mov ds,ax ;it is ds, not dx
mov bx,00 ;low
mov dx,len ;high
mov cx,key ;key

again:
cmp bx,dx ;while(low<high)
ja fail ;if(low<high) then its not found case
mov ax,bx
add ax,dx;low+high
shr ax,1 ;(low+high)/2
mov si,ax ;have an index
add si,si ;for 16 bit data
cmp cx,arr[si] ;if(key==array[mid])
jae big ;search in the RIGHT part of the array
dec ax ;dec high(search in the LEFT part of the array)
mov dx,ax ;make this as new high
jmp again ;continue searching

big:
je success ;found case
inc ax ;inc low
mov bx,ax ;make this as new low
8
jmp again ;continue searching

success:
add al,01
add al,30h ;add 30h (or '0') to the position(AL)
;(just to convert to ASCII)
lea si,res
mov [si],al ;move the position to our variable
lea dx,msg1 ;load the Effective Address to DX
jmp disp ;display the result

fail:
lea dx,msg2 ;load the msg2 and display it

disp:
mov ah,09h ;to terminate
int 21h;Using DOS interrupt 21h
mov ah,4ch ;to terminate
int 21h;Using DOS interrupt 21h
end

9
CODE OUTPUT:

10
BENEFITS OF LEARNING ASSEMBLY LANGUAGE
The learning of assembly language is still important for programmers.
It helps in taking complete control over the system and its resources.
By learning assembly language, the programmer can write the code to
access registers and retrieve the memory address of pointers and
values. It mainly helps in speed optimization that increases efficiency
and performance.

Assembly language learning helps in understanding the processor and


memory functions. If the programmer is writing any program that
needs to be a compiler, that means the programmer should have a
complete understanding of the processor. Assembly language helps in
understanding the work of processors and memory. It is cryptic and
symbolic language.

Assembly Language helps in contacting the hardware directly. This


language is mainly based on computer architecture, and it recognizes
a certain type of processor and its different for different CPUs.
Assembly language refers to transparency compared to other high-
level languages. It has a small number of operations, but it is helpful
in understanding the algorithms and other flow of controls. It makes
the code less complex and easy debugging as well.

11
FEATURES
The features of the assembly language are mentioned below:

1. It can use mnemonic than numeric operation code, and it also

provides the information of any error in the code.

2. This language helps in specifying the symbolic operand that

means it does not need to specify the machine address of that

operand. It can be represented in the form of a symbol.

3. The data can be declared by using decimal notation.

4. Assembly language helps programmers to write human-readable

code that is almost similar to machine language. Machine

language is difficult to understand and read as it is just a series

of numbers. Assembly language helps in providing full control of

what tasks a computer is performing.

12
ADVANTAGES

1. It allows complex jobs to run in a simpler way.

2. It is memory efficient, as it requires less memory.

3. It is faster in speed, as its execution time is less.

4. It is mainly hardware-oriented.

5. It requires less instruction to get the result.

6. It is used for critical jobs.

7. It is not required to keep track of memory locations.

8. It is a low-level embedded system.

DISADVANTAGES

1. It takes a lot of time and effort to write the code for the same.

2. It is very complex and difficult to understand.

3. The syntax is difficult to remember.

4. It has a lack of portability of program between different

computer architectures.

5. It needs more size or memory of the computer to run the long

programs written in Assembly Language.

13
CONCLUSION
Assembly language is very important for understanding the computer

architecture and programs for the programmers. The programmers

mainly used many other programming languages for application

development and software, but assembly language is also important.

It helps programmers to achieve a lot if they implement the assembly

language. Assemblies contain a lot of metadata that is version number,

localization details, and other product details. It is an important part

and provided to the user after digitally signed.

If an individual wants to know how the system works and the

processor as well, then assembly language is the one that solves the

purpose. It helps in all aspects, from understanding the algorithm of

the program to the processor working and registering the registers of

the computer. It depends on individual choice with which language to

continue.

14

You might also like