Вы находитесь на странице: 1из 17

PROJECT REPORT

ON
FINDING COMPOSITE NUMBER USING MASM
SUBMITTED
IN THE PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR
THE AWARD OF THE DEGREE OF

BACHELOR OF TECHNOLOGY
IN
ELECTRONICS AND COMMUNICATION

BY
Sushanth - 16311A0488
M.RAMESH - 16311A0489
Y.SAIKIRAN REDDY -16311A0493

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING


SREENIDHI INSTITUTE OF SCIENCE & TECHNOLOGY
Yamnampet, Ghatkesar, Hyderabad – 501301
DECLARATION

We hereby declare that the project entitled FINDING COMPOSITE NUMBER


USING MASM submitted in partial fullfilment of the requirements for the award of
degree of Bachelor of Technology in Electronics and Communication Engineering. This
dissertation is our original work and the project has not formed the basis for the award of any
degree, associate ship, fellowship or any other similar titles and no part of it has been
published or sent for the publication at the time of submission.

Sushanth - 16311A0488
M.RAMESH - 16311A0489
Y.SAIKIRAN REDDY -16311A0493
Sreenidhi Institute of Science and Technology

Yamnampet, Ghatkesar, Hyderabad - 501 301


Date:04/10/18

CERTIFICATE

This is to certify that the project report entitled “FINDING COMPOSITE NUMBER
USING MASM” being submitted by P.AKHIL YADAV(16311A04AG),P.SHIVA
KUMAR(16311A04AH) in partial fulfillment for the award of Bachelor of Technology
degree in Electronics and Communication Engineering, Sreenidhi Institute of Science &
Technology (Autonomous institution) affiliated to Jawaharlal Nehru Technological
University, Kukatpally Hyderabad (Telangana), is a record of bonafide work carried out by
them under our guidance and supervision.
The results embodied in the report have not been submitted to any other University or
Institution for the award of any degree or diploma.

Lab Project Coordinator Head Of The Department


MRS Dr.S.P.V.SUBBA RAO
Assistant Professor Professor
ECE Dept ECE Dept
CONTENTS:

1.ABSTRACT
2.AIM
3.SOFTWARE REQUIRED
4.THEORY
5.PROCEDURE
6.ALGORITHM
7.PROGRAM CODE
8.OUTPUT
9.FLOW CHART
10.CONCLUSION
11.RESULT
Sreenidhi Institute Of Science and Technology
Yamnampet,Ghatkesar,Hyderabad-501301
Department Of Electronics & Communication Engineering

Title: FINDING COMPOSITE NUMBER USING MASM


Abstract:- Assembly language is a family of backward-compatible assembly languages,
which provide some level of compatibility all the way back to the 8086. assembly
languagesare used to produce object code for the x86 class of processors. Like all assembly
languages, it uses short mnemonics to represent the fundamental instructions that the CPU in
a computer can understand and follow.
A composite number is a positive integer that can be formed by multiplying together
two smaller positive integers. Equivalently, it is a positive integer that has at least one divisor
other than 1 and itself. Every positive integer is composite, prime, or the unit 1, so the
composite numbers are exactly the numbers that are not prime and not a unit.
One way to classify composite numbers is by counting the number of prime factors. A
composite number with two prime factors is a semiprime or 2-almost prime (the factors need
not be distinct, hence squares of primes are included). A composite number with three
distinct prime factors is a sphenic number. In some applications, it is necessary to
differentiate between composite numbers with an odd number of distinct prime factors and
those with an even number of distinct prime factors.

Submitted By
P.AKHIL YADAV (16311A04AG)
P.SHIVA KUMAR (16311A04AH)
AIM:Write an assembly language program for determining if a given number is composite
or not using 8086 microprocessor.

SOFTWARE REQUIRED: MASM Software

THEORY:
Assembly language is a family of backward-compatible assembly languages, which provide
some level of compatibility all the way back to the Intel 8008 introduced in April 1972.
x86 assembly languagesare used to produce object code for the x86 class of processors. Like
all assembly languages, it uses short mnemonics to represent the fundamental instructions
that the CPU in a computer can understand and follow. Compilers sometimes produce
assembly code as an intermediate step when translating a high level program into machine
code. Regarded as a programming language, assembly coding is machine-specific and low
level. Assembly languages are more typically used for detailed and time critical applications
such as small real-time embedded systems or operating system kernels and device drivers.
Each x86 assembly instruction is represented by a mnemonic which, often combined with one
or more operands, translates to one or more bytes called an opcode; the NOP instruction
translates to 0x90, for instance and the HLT instruction translates to 0xF4. There are
potential opcodes with no documented mnemonic which different processors may interpret
differently, making a program using them behave inconsistently or even generate an
exception on some processors. These opcodes often turn up in code writing competitions as a
way to make the code smaller, faster, more elegant or just show off the author's prowess.

x86 processors have a collection of registers available to be used as stores for binary data.
Collectively the data and address registers are called the general registers. Each register has a
special purpose in addition to what they can all do:

 AX multiply/divide, string load & store


 CX count for string operations & shifts
 DX port address for IN and OUT
 BX index register for MOVE
 SP points to top of stack
 BP points to base of stack frame
 SI points to a source in stream operations
 DI points to a destination in stream operations
Along with the general registers there are additionally the:

 IP instruction pointer
 FLAGS
 segment registers (CS, DS, ES, FS, GS, SS) which determine where a 64k segment starts
(no FS & GS in 80286 & earlier)
 extra extension registers (MMX, 3DNow!, SSE, etc.) (Pentium & later only).
In general, the features of the modern x86 instruction set are:

 A compact encoding
 Variable length and alignment independent (encoded as little endian, as is all data in
the x86 architecture)
 Mainly one-address and two-address instructions, that is to say, the first operand is
also the destination.
 Memory operands as both source and destination are supported (frequently used to
read/write stack elements addressed using small immediate offsets).
 Both general and implicit register usage; although all seven (counting ebp ) general
registers in 32-bit mode, and all fifteen (counting rbp ) general registers in 64-bit
mode, can be freely used as accumulators or for addressing, most of them are
also implicitly used by certain (more or less) special instructions; affected registers
must therefore be temporarily preserved (normally stacked), if active during such
instruction sequences.
 Produces conditional flags implicitly through most integer ALU instructions.
 Supports various addressing modes including immediate, offset, and scaled index but not
PC-relative, except jumps (introduced as an improvement in the x86-64 architecture).
 Includes floating point to a stack of registers.
 Contains special support for atomic read-modify-write instructions
( xchg , cmpxchg / cmpxchg8b , xadd , and integer instructions which combine with
the lock prefix)
 SIMD instructions (instructions which perform parallel simultaneous single instructions
on many operands encoded in adjacent cells of wider registers).

A composite number is a positive integer that can be formed by multiplying together two
smaller positive integers. Equivalently, it is a positive integer that has at least one divisor
other than 1 and itself. Every positive integer is composite, prime, or the unit 1, so the
composite numbers are exactly the numbers that are not prime and not a unit.

One way to classify composite numbers is by counting the number of prime factors. A
composite number with two prime factors is a semiprime or 2-almost prime (the factors need
not be distinct, hence squares of primes are included). A composite number with three
distinct prime factors is a sphenic number. In some applications, it is necessary to
differentiate between composite numbers with an odd number of distinct prime factors and
those with an even number of distinct prime factors.

Composite numbers have also been called "rectangular numbers", but that name can also
refer to the pronic numbers, numbers that are the product of two consecutive integers.

PROCEDURE:
1. Load the data from the memory location into the accumulator
2. Initialize register C with 00H. This stores the number of divisors of n
3. Move the value in the accumulator in E. This will act as an iterator for the loop from n
to 1.
4. Move the value in the accumulator in B. B permanently stores n because the value in
the accumulator will change
5. Move the value in E to D and perform division with the accumulator as the dividend
and D as the divisor.
6. Division: Keep subtracting D from A till the value in A either becomes 0 or less than 0.
After this, check the value in the accumulator. If it’s equal to 0, then increment the
count of divisors by incrementing the value in C by one
7. Restore the value of the accumulator by moving the value in B to A and continue with
the loop till E becomes 0
8. Now, move the number of divisors from C to A and check if it’s equal to 2 or not. If it
is, then store 01H to 202AH (arbitrary), else store 00H.

ALGORITHM:
Step1 : Take n as input.

Step2 : Run a loop from i = n to 1. For each iteration, check if i divides n completely or not.
If it does, then i is n’s divisor

Step3 : Keep a count of the total number of divisors of n

Step4 : If the count of divisors is not equal to 2, then the number is composite, else prime

Step5:Stop

PROGRAM:
assume cs:code,ds:data
data segment
const db 02h
list db 01h,02h,03h,04h,05h,06h,07h,10h,16h,11h
comp db ?
data ends
code segment
start:mov ax,data
mov ds,ax
xor ax,ax
xor bx,bx
xor cx,cx
lea si,list
lea di,comp
mov al,[si]
inc si
mov al,[si]
inc si
mov cl,08h
up2:mov bl,const
mov dl,00h
up:mov ax,0000h
mov al,[si]
div bl
inc bl
cmp ah,00h
jnz down1
inc dl
down1:mov al,[si]
cmp al,bl
jz down
jmp up
down:cmp dl,00h
jnz com
jmp next
com:mov al,[si]
mov [di],al
inc di
next:inc si
dec cl
jnz up2
int 03h
code ends
end start
OUTPUT:
FLOW CHART:
CONCLUSION:
1.Composite numbers are the numbers which have more than two factors.
2.Composite numbers are not the only categories into which we can group numbers.
3. A composite number is a whole number that can be made by multiplying other whole
numbers.
4.Numbers other than prime numbers are called composite numbers.

RESULT:
The Program code got executed successfully and we have separated composite numbers from
a list of numbers.

Вам также может понравиться