0% found this document useful (0 votes)
84 views

C-1 Record PDF

This document appears to be a lab record for a Computer Architecture and Microprocessors course. It contains an index listing 31 experiments conducted, along with brief descriptions of the first experiment which involved visualizing internal computer components like the motherboard, northbridge, southbridge, different types of memory (RAM, ROM, cache), and secondary storage devices. It also defines CMOS and microprocessors.

Uploaded by

sarala devi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

C-1 Record PDF

This document appears to be a lab record for a Computer Architecture and Microprocessors course. It contains an index listing 31 experiments conducted, along with brief descriptions of the first experiment which involved visualizing internal computer components like the motherboard, northbridge, southbridge, different types of memory (RAM, ROM, cache), and secondary storage devices. It also defines CMOS and microprocessors.

Uploaded by

sarala devi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

Chaitanya Bharathi Institute of Technology (Autonomous)

Department of Computer Science and Engineering

Year-II Semester-IV

COMPUTER ARCHITECTURE AND MICRO PROCESSORS LAB RECORD

(Code- 16CSC07)
Submitted to Submitted by

Mr B Sateesh, Student Name:

Assistant Professor, Roll no:

Dept of CSE . B.E-2/ 4, CSE-1


Chaitanya Bharathi Institute of Technology (Autonomous)

Department of Computer Science and Engineering

Year-II Semester-4

CERTIFICATE

This is to certify that this is an organized record of the work done by Mr./Miss.
________________bearing Roll No._______________ of B.E –II/IV, CSE, III
semester in the Data Structures lab during the academic year 2019-20.

Number of experiments conducted: 31

Internal Examiner External Examiner


INDEX

S.NO NAME OF THE PROGRAM PAGE NUMBER

1. Visualizing and understanding the working principles of


all internal components of computer

2. Convert Signed decimal number to Signed binary number


using 2’s complement.

3. Any to any number system convertor

4. Implementation of binary addition

5. Implementation of Booth’s multiplication algorithm

6. Implementation of Restoring algorithm

7. Implementation of Non restoring division


algorithm

8. Demonstration of all addressing modes using 8086


emulator

9. Addition of two 16bit numbers using 8bit registers

10. Addition of two 32bit numbers using 16bit registers

11. Demonstration of mul, imul, div and idiv

12. Packed BCD arithmetic [daa, das]

13. Un packed BCD arithmetic [ aaa, aas, aam, aad]

14. Inputting and outputting a char, string using


int21h

15. Demonstration of shift and rotate [ with and without


carry]
16. Demonstration of logical operators, compare and
negate

17. Demonstration of stack operations and flag register


instructions PUSH, POP, PUSHF, POPF, LAHF and SAHF

18. Finding the maximum of three numbers using INT


21h

19. Finding whether given number is positive or


negative using int21h
i.e., output string should be displayed as positive
or negative

20. Finding whether given number is even or odd


using int21h
i.e., output string should be displayed as even or
odd

21. Setting and unsetting Trap flag bit in flag register

22. Demonstration of Looping in 8086

23. Demonstration of string instructions [all five


instructions 8,16 bit]

24. BLOCK transfer

25. String copy using string instructions

26. String reverse using string instructions

27. Palindrome using strings

28. Bubble Sort

29. Demonstration of procedures using stacks

30. Demonstration of macros

31. SUM, AVG of given array elements


1.AIM: To visualize and understand the working principles of all internal components of
computer such as memories, secondary storage devices, CMOS.
DESCRIPTION:
Motherboard
A motherboard is the main printed circuit board found in general purpose computers and other
expandable systems. It holds, and allows, communication between many of the crucial
electronic components of a system, such as the central processing unit and memory, and
provides connectors for other peripherals.

North Bridge
Northbridge or host bridge is one of the two chips in the core logic chipset architecture on a PC
motherboard, the other being the south bridge. The Northbridge, also known as Memory
Controller Hub, is usually paired with a Southbridge.
South Bridge
The Southbridge is one of the two chips in the core logic chipset on a personal
computer motherboard, the other being the Northbridge. The Southbridge typically
implements the slower capabilities of the motherboard in a Northbridge/Southbridge chipset
computer architecture.
Memory
In computing, memory refers to a device that is used to store information for immediate use in
a computer or related computer hardware device.
It typically refers to semiconductor memory.
Cache Memory is a special very high-speed memory. It is used to speed up and synchronizing
with high-speed CPU. Cache memory is costlier than main memory or disk memory but
economical than CPU registers. Cache memory is an extremely fast memory type that acts as a
buffer between RAM and the CPU. It holds frequently requested data and instructions so that
they are immediately available to the CPU when needed.

Random Access Memory


RAM (Random Access Memory) is the internal memory of the CPU for storing data, program, and
program result. It is a read/write memory which stores data until the machine is working. As soon
as the machine is switched off, data is erased. Data in the RAM can be accessed randomly but it
is very expensive. RAM is volatile, i.e. data stored in it is lost when we switch off the computer or
if there is a power failure. Hence, a backup Uninterruptible Power System (UPS) is often used
with computers. RAM is small, both in terms of its physical size and in the amount of data it can
hold.
RAM is of two types −
• Static RAM (SRAM)
• Dynamic RAM (DRAM)
Static RAM
The word static indicates that the memory retains its contents as long as power is being supplied.
However, data is lost when the power gets down due to volatile nature. SRAM chips use a matrix
of 6-transistors and no capacitors. Transistors do not require power to prevent leakage, so SRAM
need not be refreshed on a regular basis.
There is extra space in the matrix, hence SRAM uses more chips than DRAM for the same amount
of storage space, making the manufacturing costs higher. SRAM is thus used as cache memory
and has very fast access.
Characteristic of Static RAM
• Long life • No need to refresh • Faster • Used as cache memory • Large size • Expensive
• High power consumption
Dynamic RAM
DRAM, unlike SRAM, must be continually refreshed in order to maintain the data. This is done by
placing the memory on a refresh circuit that rewrites the data several hundred times per second.
DRAM is used for most system memory as it is cheap and small. All DRAMs are made up of
memory cells, which are composed of one capacitor and one transistor.
Characteristics of Dynamic RAM
• Short data lifetime • Needs to be refreshed continuously • Slower as compared to SRAM
• Used as RAM • Smaller in size • Less expensive • Less power consumption
ROM
ROM stands for Read Only Memory. The memory from which we can only read but cannot write
on it. This type of memory is non-volatile. The information is stored permanently in such
memories during manufacture. A ROM stores such instructions that are required to start a
computer. This operation is referred to as bootstrap. ROM chips are not only used in the
computer but also in other electronic items like washing machine and microwave oven.
MROM (Masked ROM)
The very first ROMs were hard-wired devices that contained a pre-programmed set of data or
instructions. These kind of ROMs are known as masked ROMs, which are inexpensive.
PROM (Programmable Read Only Memory)
PROM is read-only memory that can be modified only once by a user. The user buys a blank PROM
and enters the desired contents using a PROM program. Inside the PROM chip, there are small
fuses which are burnt open during programming. It can be programmed only once and is not
erasable.
EPROM (Erasable and Programmable Read Only Memory)
EPROM can be erased by exposing it to ultra-violet light for a duration of up to 40 minutes.
Usually, an EPROM eraser achieves this function. During programming, an electrical charge is
trapped in an insulated gate region. The charge is retained for more than 10 years because the
charge has no leakage path. For erasing this charge, ultra-violet light is passed through a quartz
crystal window (lid).
EEPROM (Electrically Erasable and Programmable Read Only Memory)
EEPROM is programmed and erased electrically. It can be erased and reprogrammed about ten
thousand times. Both erasing and programming take about 4 to 10 ms (millisecond). In EEPROM,
any location can be selectively erased and programmed.
Advantages of ROM:
• Non-volatile in nature • Cannot be accidentally changed • Cheaper than RAMs
• Easy to test • More reliable than RAMs • Static and do not require refreshing
• Contents are always known and can be verified.\
Secondary Storage Devices A secondary storage device refers to any non-volatile storage
device that is internal or external to the computer. It can be any storage device beyond the
primary storage that enables permanent data storage.A secondary storage device is also known
as an auxiliary storage device or external storage. Secondary storage devices are primarily
referred to a storage devices that serve as an addition to the computer's primary storage, RAM
and cache memory. Typically, secondary storage allows for the storage of data ranging from a
few megabytes to petabytes. These devices store virtually all programs and applications stored
on a computer, including the operating system, device drivers, applications and general user
data.
CMOS
CMOS is short for complementary metal-oxide semiconductor. CMOS is an onboard, battery
powered semiconductor chip inside computers that stores information. This information ranges
from the system time and date to system hardware settings for your computer. The picture
shows an example of the most common CMOS coin cell battery (Panasonic CR 2032 3V) used to
power the CMOS memory.
MICROPROCESSOR
A microprocessor is an electronic component that is used by a computer to do its work. It has
ALU (arithmetic and logic unit), a control unit, registers, bus systems and a clock to perform
computational tasks. Microprocessors contain both combinational and sequential digital
logic.Microprocessors operate on numbers and symbols represented in the binary number
syste

______________________________________________________________________________
2.AIM: To Convert Signed decimal number to Signed binary number using 2’s complement.
DESCRIPTION: Two's complement is a mathematical operation on binary numbers, and is an
example of a radix complement. It is used in computing as a method of signed number
representation. The two's complement of a number is to take its ones' complement and add
one: the sum of a number and its ones' complement is all '1' bits, or 2N − 1; and by defini on,
the sum of a number and its two's complement is 2N.
Two's complement is the way every computer I chooses to represent integers. To get the two's
complement negative notation of an integer, you write out the number in binary. You then
invert the digits, and add one to the result.
Suppose we're working with 8 bit quantities (for simplicity's sake) and suppose we want to find
how -28 would be expressed in two's complement notation. First we write out 28 in binary
form.
00011100
Then we invert the digits. 0 becomes 1, 1 becomes 0.
11100011
Then we add 1.
11100100
PROGRAM:
def comp(str):
n = len(str)
i=n-1
while(i >= 0):
if (str[i] == '1'):
break
i=i-1
if (i==-1):
return '1'+str
k=i-1
while(k >= 0):
if (str[k] == '1'):
str = list(str)
str[k] = '0'
str = ''.join(str)
else:
str = list(str)
str[k] = '1'
str = ''.join(str)
k -= 1
return str
def dec_bin(x):
if(x==0):
return ''
else:
return dec_bin(x//2)+str(x%2)
while(1):
c=int(input("enter \n 1. decimal to 2's complement enter \n 2. 2's complement to decimal \n
3. quit "))
if(c!=1 and c!=2):
break;
elif(c==1):
l=int(input("enter number of bits"))
a=int(input("enter decimal number"))
if(a>=0):
ans=dec_bin(a).rjust(l,'0')
print("2's complement is:",ans)
if(a<0):
t=dec_bin(-a).rjust(l,'0')
k=comp(t)
print("2's complement is:",k)
elif(c==2):
l=int(input("enter number of bits"))
a=input("enter 2's complement")
r=a.rjust(l,'0')
ans=comp(r)
#k=len(a)
print(r[0],ans)
if(r[0]==1):
ans=0-int(ans,2)
print("minus")
else:
ans=int(ans,2)
print("decimal value is",ans)
OUTPUT:

______________________________________________________________________________
3.AIM: To implement any to any number system convertor
DESCRIPTION:
Decimal to Binary:
Decimal numbers can be converted to binary by repeated division of the number by 2
The remainders are to be read from bottom to top to obtain the binary equivalent.
Decimal to Octal:
Decimal numbers can be converted to octal by repeated division of the number by 8 while
recording the remainder read from bottom to top.
Decimal to Hexadecimal:
Decimal numbers can be converted to octal by repeated division of the number by 16 while
recording the remainder read from bottom to top.
Binary to Decimal:
The decimal number is equal to the sum of binary digits (dn) times their power of 2 (2**n)
Octal to Decimal:
Regular decimal number is the sum of the digits multiplied with 10**n.
Octal numbers are read the same way, but each digit counts 8**n instead of 10**n.
Multiply each digit of the octal number with its corresponding 8**n.
Hexadecimal to Decimal:
Hex is a base 16 number and decimal is a base 10 number. We need to know the decimal
equivalent of every hex number digit. Get the decimal equivalent of hex .Multiply every digit
with 16 power of digit location.Sum all the multipliers.
PROGRAM:
def bin_dec(x):
i=0
decimal=0
while(x != 0):
dec = x % 10
decimal = decimal + dec * pow(2, i)
x= x//10
i += 1
return decimal;
def oct_dec(x):
i=0
decimal=0
while(x != 0):
dec = x % 10
decimal = decimal + dec * pow(8, i)
x= x//10
i += 1
return decimal;
def hex_dec(x):
i=len(x)-1
decimal=0
for t in x:
if((t>='A' and t<='F')):
dec=ord(t)-ord('A')+10
elif((t>='a' and t<='f')):
dec=ord(t)-ord('a')+10
else:
dec=ord(t)-ord('0')
decimal = decimal + dec * pow(16, i)
i -= 1
return decimal;
def dec_bin(x):
if x==0: return ''
else:
return dec_bin(x//2) + str(x%2)
def dec_oct(x):
if x==0: return ''
else:
return dec_oct(x//8) + str(x%8)
def dec_hex(x):
if x==0: return ''
else:
if(x%16<10):
z=str(x%16)
else:
z=chr((x%16)-10 +ord('A'))
return dec_hex(x//16) + z
while(1):
aaa=int(input("enter 1. conversion 2.exit"))
if(aaa==1):
a=input("enter input number system: ")
b=input("enter the output number system: ")
if(a=="binary" and (b == "decimal")):
x=eval(input("enter number:"))
decimal=bin_dec(x)
print(decimal)
elif(a=='decimal' and b=='binary'):
x=eval(input("enter number:"))
binary=dec_bin(x)
print(binary)
elif(a=='decimal' and b=='octal'):
x=eval(input("enter number:"))
octal=dec_oct(x)
print(octal)
elif(a=='decimal' and b=='hex'):
x=eval(input("enter number:"))
hexa=dec_hex(x)
print(hexa)
elif(a=='octal' and b=='decimal'):
x=eval(input("enter number :"))
decimal=oct_dec(x)
print(decimal)
elif(a=='hex' and b=='decimal'):
x=input("enter number :")
decimal=hex_dec(x)
print(decimal)
elif(a=='binary' and b=='octal'):
x=eval(input("enter number :"))
y=bin_dec(x)
ans=dec_oct(y)
print(ans)
elif(a=='binary' and b=='hex'):
x=eval(input("enter number :"))
y=bin_dec(x)
ans=dec_hex(y)
print(ans)
elif(a=='octal' and b=='binary'):
x=eval(input("enter number :"))
y=oct_dec(x)
ans=dec_bin(y)
print(ans)
elif(a=='octal' and b=='hex'):
x=eval(input("enter number:"))
y=oct_dec(x)
ans=dec_hex(y)
print(ans)
elif(a=='hex' and b=='binary'):
x=input("enter number:")
y=hex_dec(x)
ans=dec_bin(y)
print(ans)
elif(a=='hex' and b=='octal'):
x=input("enter number:")
y=hex_dec(x)
ans=dec_oct(y)
print(ans)
else:
break
OUTPUT:
______________________________________________________________________________
4.AIM: To implement Binary addition
DESCRIPTION:
A basic Binary Adder circuit can be made from standard AND and Ex-OR gates allowing us to
“add” together two single bit binary numbers, A and B.The addition of these two digits
produces an output called the SUM of the addition and a second output called the CARRY or
Carry-out.The addition of the binary number system is similar to that of the decimal number
system. The only difference is that the decimal number system consists the digit from 0-9 and
their base is 10 whereas the binary number system consists only two digits (0 and 1) which
make their operation easier. There are four basic operations for binary addition, as mentioned
below:
0+0=0;0+1=1;1+0=1 and 1+1=10.
The idea is to start from last characters of two strings and compute digit sum one by one. If sum
becomes more than 1, then store carry for next digits.

PROGRAM:
def dec_bin(x):
if(x==0):
return ''
else:
return dec_bin(x//2)+str(x%2)
l=int(input("enter number of bits:"))
a=int(input("enter the number in decimal:"))
b=int(input("enter another number in decimal:"))
x=dec_bin(a)
y=dec_bin(b)
m=x.rjust(l,'0')
n=y.rjust(l,'0')
c=0
ans=''
for i in range(l-1,-1,-1):
r=c
if(m[i]=='1'):
r+=1
if(n[i]=='1'):
r+=1
if(r%2==1):
ans='1'+ans
else:
ans='0'+ans
if(r<2):
c=0
else:
c=1
if(c!=0):
ans='1'+ans
print(ans)
OUTPUT:

5.AIM: To implement Booth’s Binary multiplication algorithm.


DESCRIPTION : Booth's multiplication algorithm is a multiplication algorithm that multiplies
two signed binary numbers in two's complement notation. The binary multiplication operation
is a process of addition and shifting operation and this process has to be continued until all the
multiplier is done and finally the addition operation is made. Similar to the decimal system, the
multiplication of the binary numbers is done by multiplying the multiplicand with the multiplier.
The rules of binary multiplication are:
0x0=0; 0x1=0; 1x0=0 and 1x1=1.
Below is the flowchart for the booth’s algorithm:
PROGRAM:
def comp(str):
n = len(str)
i = n-1
while(i >= 0):
if (str[i] == '1'):
break
i=i-1
#if (i==-1):
#return '1'+str
k = i-1
while(k >= 0):

if (str[k] == '1'):
str = list(str)
str[k] = '0'
str = ''.join(str)
else:
str = list(str)
str[k] = '1'
str = ''.join(str)
k -= 1
return str
def bin_add(m,n):
c=0
ans=''
for i in range(3,-1,-1):
r=c
if(m[i]=='1'):
r+=1
if(n[i]=='1'):
r+=1
if(r%2==1):
ans='1'+ans
else:
ans='0'+ans
if(r<2):
c=0
else:
c=1
return ans;

def right_shift(ans):
ans=ans[:7]
ans=ans[0]+ans
return ans;

def dec_bin(x):
if(x==0):
return ''
else:
return dec_bin(x//2)+str(x%2)

m=int(input("enter multiplicand"))
q=int(input("enter multiplier"))
if(m>=0):
m=dec_bin(m).rjust(4,'0')
elif(m<0):
m=dec_bin(-m).rjust(4,'0')
m=comp(m)
if(q>=0):
q=dec_bin(q).rjust(4,'0')
elif(q<0):
q=dec_bin(-q).rjust(4,'0')
q=comp(q)
q=q.rjust(4,'0')
m=m.rjust(4,'0')
a='0000'
res=a+q
x='0'
for i in range(0,4):
y=q[-1]
if(x==y):
x=res[-1]
res=right_shift(res)
a=res[0:4]
q=res[4:8]
elif(x=='0' and y=='1'):
x=res[-1]
sub=comp(m)
a=bin_add(a,sub)
res=a+q
res=right_shift(res)
a=res[0:4]
q=res[4:8]
elif(x=='1' and y=='0'):
x=res[-1]
a=bin_add(a,m)
res=a+q
res=right_shift(res)
a=res[0:4]
q=res[4:8]
print(a,q)
if(a=='1111'):
print("-",end='')
print(int(comp(q),2))
else:
print(int(q,2))
OUTPUT:

_____________________________________________________________________________
6.AIM : To perform restoration algorithm.
DESCRIPTION : A division algorithm provides a quotient and a remainder when we divide two
number. ... Here, n-bit dividend is loaded in Q and divisor is loaded in M. Value of Register is
initially kept 0 and this is the register whose value is restored during iteration due to which it is
named Restoring.
Steps to perform restoration :
● Step-1: First the registers are initialized with corresponding values (Q = Dividend, M =
Divisor, A = 0, n = number of bits in dividend)
● Step-2: Then the content of register A and Q is shifted right as if they are a single unit
● Step-3: Then content of register M is subtracted from A and result is stored in A
● Step-4: Then the most significant bit of the A is checked if it is 0 the least significant bit
of Q is set to 1 otherwise if it is 1 the least significant bit of Q is set to 0 and value of
register A is restored i.e the value of A before the subtraction with M
● Step-5: The value of counter n is decremented
● Step-6: If the value of n becomes zero we get of the loop otherwise we repeat from 2
● Step-7: Finally, the register Q contain the quotient and A contain remainder
Below is the flowchart for the restoration algorithm:

PROGRAM :
''' left shift'''
def left_shift(ans):
z=ans[1:]
z=z+'0'
return z;

#2's complement

def comp(str):
n = len(str)
i = n-1
while(i >= 0):
if (str[i] == '1'):
break
i=i-1
k = i-1
while(k >= 0):

if (str[k] == '1'):
str = list(str)
str[k] = '0'
str = ''.join(str)
else:
str = list(str)
str[k] = '1'
str = ''.join(str)
k -= 1
return str
'''binary addition'''
def bin_add(m,n):
c=0
ans=''
for i in range(3,-1,-1):
r=c
if(m[i]=='1'):
r+=1
if(n[i]=='1'):
r+=1
if(r%2==1):
ans='1'+ans
else:
ans='0'+ans
if(r<2):
c=0
else:
c=1
return ans;

''' decimal to binary conversion'''


def dec_bin(x):
if(x==0):
return ''
else:
return dec_bin(x//2)+str(x%2)

q1=int(input("enter dividend:"))
m1=int(input("enter divisor:"))
q=dec_bin(abs(q1)).rjust(4,'0')
m=dec_bin(abs(m1)).rjust(4,'0')
a='0000'
res=a+q
m_c=comp(m)
for i in range(0,4):
res=left_shift(res)
a=bin_add(res[0:4],m_c)
res=a+res[4:8]
if(res[0]=='1'):
a=bin_add(res[0:4],m)
res=a+res[4:8]

else:
res=a+res[4:7]+'1'

print(res)
if(q1<0 and m1>0):
print("quotient",0-int(res[4:8],2))
print("remainder",0-int(res[0:4],2))
elif(q1>=0 and m1<0):
print("quotient",0-int(res[4:8],2))
print("remainder",int(res[0:4],2))
elif(q1<0 and m1<0):
print("quotient",int(res[4:8],2))
print("remainder",0-int(res[0:4],2))
else:
print("quotient",int(res[4:8],2))
print("remainder",int(res[0:4],2))

OUTPUT:
……………………………………………………………………………………………………………………………………………….
_____________________________________________________________________________

7.AIM: To perform Non-Restoration Algorithm.


DESCRIPTION: It is less complex than the restoring one because simpler operation are involved
i.e. addition and subtraction, also now restoring step is performed. In the method, rely on the
sign bit of the register which initially contain zero named as A.
Steps to perform Non-restoration :
● Step-1: First the registers are initialized with corresponding values (Q = Dividend, M =
Divisor, A = 0, n = number of bits in dividend)
● Step-2: Check the sign bit of register A
● Step-3: If it is 1 shift left content of AQ and perform A = A+M, otherwise shift left AQ
and perform A = A-M (means add 2’s complement of M to A and store it to A)
● Step-4: Again the sign bit of register A
● Step-5: If sign bit is 1 Q[0] become 0 otherwise Q[0] become 1 (Q[0] means least
significant bit of register Q)
● Step-6: Decrements value of N by 1
● Step-7: If N is not equal to zero go to Step 2 otherwise go to next step
● Step-8: If sign bit of A is 1 then perform A = A+M
● Step-9: Register Q contain quotient and A contain remainder
Below is the flowchart for the restoration algorithm:
PROGRAM:
''' left shift'''
def left_shift(ans):
z=ans[1:]
z=z+'0'
return z;

#2's complement

def comp(str):
n = len(str)
i = n-1
while(i >= 0):
if (str[i] == '1'):
break
i=i-1
k = i-1
while(k >= 0):

if (str[k] == '1'):
str = list(str)
str[k] = '0'
str = ''.join(str)
else:
str = list(str)
str[k] = '1'
str = ''.join(str)
k -= 1
return str
'''binary addition'''
def bin_add(m,n):
c=0
ans=''
for i in range(3,-1,-1):
r=c
if(m[i]=='1'):
r+=1
if(n[i]=='1'):
r+=1
if(r%2==1):
ans='1'+ans
else:
ans='0'+ans
if(r<2):
c=0
else:
c=1
return ans;

''' decimal to binary conversion'''


def dec_bin(x):
if(x==0):
return ''
else:
return dec_bin(x//2)+str(x%2)

q1=int(input("enter dividend:"))
m1=int(input("enter divisor:"))
q=dec_bin(abs(q1)).rjust(4,'0')
m=dec_bin(abs(m1)).rjust(4,'0')
a='0000'
res=a+q
f=0
m_c=comp(m)
for i in range(0,4):
res=left_shift(res)
if(f==0):
a=bin_add(res[0:4],m_c)
else:
a=bin_add(res[0:4],m)
f=0
res=a+res[4:8]
if(res[0]=='1'):
f=1
else:
res=a+res[4:7]+'1'

print(res)
if(q1<0 and m1>0):
print("quotient",0-int(res[4:8],2))
print("remainder",0-int(res[0:4],2))
elif(q1>=0 and m1<0):
print("quotient",0-int(res[4:8],2))
print("remainder",int(res[0:4],2))
elif(q1<0 and m1<0):
print("quotient",int(res[4:8],2))
print("remainder",0-int(res[0:4],2))
else:
print("quotient",int(res[4:8],2))

OUTPUT:
_____________________________________________________________________________
8.AIM:To demonstrate addressing modes using 8086 emulator
DESCRIPTION: The way of specifying data to be operated by an instruction is known as
addressing modes. This specifies that the given data is an immediate data or an address. It also
specifies whether the given operand is register or register pair.
Types of addressing modes:
1.Register mode – In this type of addressing mode both the operands are registers.
2.Immediate mode – In this type of addressing mode the source operand is a 8 bit or 16 bit
data. Destination operand can never be immediate data.
3.Displacement or direct mode – In this type of addressing mode the effective address is
directly given in the instruction as displacement.
4. Register indirect mode – In this addressing mode the effective address is in SI, DI or BX
5. Based indexed mode – In this the effective address is sum of base register and index
registerBase register: BX, BPIndex register: SI, DI The physical memory address is calculated
according to the base register.
6. Indexed mode – In this type of addressing mode the effective address is sum of index
register and displacement.
7. Based mode – In this the effective address is the sum of base register and displacement
8. Based indexed displacement mode – In this type of addressing mode the effective address is
the sum of index register, base register and displacement.
PROGRAM:
data segment
str db "hello$”
str2 db "corld$"
a db "camp$"
b db "cbit$"
data ends
code segment
assume cs:code ds:data es:extra
START:
MOV AX, data ;1
MOV DS, AX ;2 initializing segment register
MOV ES,AX ;3 initializing segment register
MOV AX, 2000H ;4 immediate mode
MOV CL, 0AH ;5 immediate mode
LEA SI,str2 ;6
LEA DI, b ;7
MOV BX,AX ;8 register mode
MOV Al, [0006h] ;9 direct mode
MOV Ch, [DI] ;10 register indirect mode
MOV BL, [SI] ;11 register indirect mode
MOV DH, [BX] ;12 register indirect mode
MOV AH, [BP+SI] ;13 based indexed mode
MOV AL, [BX+DI] ;14 based indexed mode
MOV BH, [SI+0002h] ; 15 indexed mode
MOV BL, [DI+0003h] ;16 indexed mode
MOV CH, [BP+ 0100] ;17 based mode
MOV CL, [SI+BP+2000] ;18 based indexed displacement mod
end start
code ends

OUTPUT:
After executing 1 TO 8 after executing 9 to 12 after executing 13 to 18

_____________________________________________________________________________
9.AIM: Write a program to execute addition of two 16-bit numbers using 8-bit registers.
DESCRIPTION:ADC is addition with carry. The ADC (Add with Carry) instruction adds the values
in destination and source , together with the carry flag. You can use ADC to synthesize
multiword arithmetic. In certain circumstances, the assembler can substitute one instruction
for another.ADD doen’t consider the carry flag
Syntax: adc dest, src ;dest: memory or register ; src: memory, register, or immediate Action:
dest = dest + src + CF
Two 16 bit numbers can be added using four 8 bit registers with the help of ADC.
The lower nibs of the two numbers are added using ADD instruction.This addition may produce
a carry which will be added to the sum of the higher nibs with the help of ADC instruction
PROGRAM:
code segment
assume cs:code
start:
mov al,0ffh
mov ah,12h
mov bl,01h
mov bh,00h
add al,bl
adc ah,bh
end start
code ends
OUTPUT:

10.AIM:Write a program to execute the addition of two 32-bit numbers using 16-bit register.
DESCRIPTION: ADC is addition with carry. The ADC (Add with Carry) instruction adds the values
in destination and source , together with the carry flag. You can use ADC to synthesize
multiword arithmetic. In certain circumstances, the assembler can substitute one instruction
for another.ADD doen’t consider the carry flag
Syntax: adc dest, src ;dest: memory or register ; src: memory, register, or immediate Action:
dest = dest + src + CF
Two 16 bit numbers can be added using four 8 bit registers with the help of ADC.
The lower nibs of the two numbers are added using ADD instruction.This addition may produce
a carry which will be added to the sum of the higher nibs with the help of ADC instruction
Since there are no 32 bit registers in 8086 ,we store a 32 bit number in two 16 bit registers.
In this case ,the first number is stored in the registers BX,AX(higher nib in BX,lower nib in
AX).The second number is stored in the registers DX,CX(higher nib ijn DX ,lower nib in CX).The
resulting sum is stored in BX,AX.
PROGRAM:
code segment
assume cs: code
start:
mov ax,0ffffh
mov bx,1234h
mov cx,0001h
mov dx,0000h
add ax,cx
adc bx,dx
end start
code ends

OUTPUT:
11. Demonstrate mul, imul, div, idiv
AIM: To demonstrate operations of mul, imul, div, and idiv.
DESCRIPTION:
Multiplication:
There are two instructions for multiplying binary data. The MUL (Multiply) instruction
handles unsigned data and the IMUL (Integer Multiply) handles signed data. Both
instructions affect the Carry and Overflow flag.
The syntax for the MUL/IMUL instructions is as follows −
MUL/IMUL multiplier
Multiplicand in both cases will be in an accumulator, depending upon the size of the
multiplicand and the multiplier and the generated product is also stored in two
registers depending upon the size of the operands.
 MUL − Used to multiply unsigned byte by byte/word by word.
 IMUL − Used to multiply signed byte by byte/word by word.
Division:
The division operation generates two elements - a quotient and a remainder. In
case of multiplication, overflow does not occur because double-length registers are
used to keep the product. However, in case of division, overflow may occur. The
processor generates an interrupt if overflow occurs.
The DIV (Divide) instruction is used for unsigned data and the IDIV (Integer Divide)
is used for signed data.
The format for the DIV/IDIV instruction −
DIV/IDIV divisor
The dividend is in an accumulator. Both the instructions can work with 8-bit, 16-bit or
32-bit operands. The operation affects all six status flags.
 DIV − Used to divide the unsigned word by byte or unsigned double word by word.
 IDIV − Used to divide the signed word by byte or signed double word by word.
PROGRAM:
mul and imul:
code segment
assume cs: code
start:
MOV AL, 10
MOV DL, 25
MUL DL
MOV DL, 0FFH ; DL= -1
MOV AL, 0BEH ; AL = -66
IMUL DL
code ends
end start

div and idiv:


code segment
assume cs: code
start:

mov ax, 0080h


mov bl, 2
div bl

code ends
end start

code segment
assume cs: code
start:

mov ax, -0080h


mov bl, -2
idiv bl

code ends
end start

OUTPUT:
12. Packed BCD arithmetic [daa, das]
AIM: To demonstrate arithmetic operations in Packed BCD.
DESCRIPTION:
In packed BCD representation, each digit is stored using four bits. Two decimal digits are packed
into a byte. For example, the number 1234 is stored as −

12 | 34H
There are two instructions for processing these numbers −
 DAA − Decimal Adjust A er Addi on
 DAS − decimal Adjust A er Subtrac on
There is no support for multiplication and division in packed BCD representation.
DAA − Used to adjust the decimal after the addition/subtraction operation.
DAS − Used to adjust decimal after subtraction.

PROGRAM:
DAA:
code segment
assume cs: code
start:

MOV AL, 27H


ADD AL, 35H
DAA

code ends
end start
DAS:
code segment
assume cs: code
start:

MOV AL, 27H


ADD AL, 35H
DAS

code ends
end start

OUTPUT:

DAA:
DAS:
13. Un-packed BCD arithmetic [aaa,aas,aam,aad]
AIM: To demonstrate the arithmetic operations in Un-packed BCD.
DESCRIPTION:
In unpacked BCD representation, each byte stores the binary equivalent of a decimal digit. For
example, the number 1234 is stored as −

01 02 03 04H

There are two instructions for processing these numbers −


 AAM − ASCII Adjust A er Mul plica on
 AAD − ASCII Adjust Before Division

The four ASCII adjust instructions, AAA, AAS, AAM, and AAD, can also be used with unpacked
BCD representation.
AAA − Used to adjust ASCII a er addi on.
AAS − Used to adjust ASCII codes a er subtrac on.
AAM − Used to adjust ASCII codes a er mul plica on.
AAD − Used to adjust ASCII codes a er division.

PROGRAM:
AAA:
code segment
assume cs: code
start:

MOV AL, 35H


MOV BL, 39H
ADD AL, BL
AAA

code ends
end start
AAS:
code segment
assume cs: code
start:

MOV AL, 39H


MOV BL, 35H
SUB AL, BL
AAS

code ends
end start

AAM:
code segment
assume cs: code
start:

MOV AL, 5
MOV BH, 9
MUL BH
AAM

code ends
end start
AAD:
code segment
assume cs: code
start:

MOV AX, 0603H


MOV CH, 09H
AAD
DIV CH

code ends
end start

OUTPUT:
AAA:
AAS:

AAM:
AAD:
14. Inputting and outputting a char, string using int21h
AIM: To demonstrate the inputting and outputting a char input/string using INT21H.

DESCRIPTION: INT 21h is the assembly language mnemonic for the Intel CPU command used to
perform a System call .It is a software interrupt which causes the function pointed by the 34th
vector in the interrupt table to be executed which is typically an MS-DOS API call.It is used for
text interface,IO,exiting and more.

INT 21h / AH=1 - read character from standard input, with echo, result is stored in AL. if there is
no character in the keyboard buffer, the function waits until any key is pressed. example: basic
8086 and dos interrupts that are currently supported by the emulator

Syntax: mov AH,01H , INT 21H

INT 21h / AH=2 - write character to standard output. entry: DL = character to write, after
execution AL = DL.

Syntax: mov AH,02H ,INT 21H

INT 21h/ AH=0Ah - input of a string to DS:DX, fist byte is buffer size, second byte is number of
chars actually read. this function does not add '$' in the end of string. to print using INT 21h /
AH=9 you must set dollar character at the end of it

Syntax:mov AH,0AH ,INT 21H

INT 21h / AH=9 - output of a string at DS:DX. String must be terminated by '$'.

Syntax:mov AH,09H ,INT 21H

PROGRAM:

Input & Output CHAR

Code:
code segment
assume cs:code,ds:data
start:
mov ah,01h ;to input
int 21h
mov dl,’b’
mov ah,02h ;to output
int 21h
code ends
end start

Output:

Input & Output String


Code:
data segment
c dw 10 dup('$')
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax

mov ah,0Ah ;to input


lea dx,c
int 21h

mov ah,09h ;to output


lea dx,c
int 21h
code ends
end start

OUTPUT:
Input

Output:
15. Demonstrate shift and rotate [ with and without carry] .

AIM : To demonstrate shift and rotate in 8086.

Description : As we know that any machine (system) works on machine language, which consists
of binary numbers. In the 8086 microprocessor, we have 16-bit registers to handle our data.
Sometimes, the need to perform some necessary shift and rotate operations on our data may
occur according to the given condition and requirement. So, for that purpose, we have various
Shift and Rotate instructions present in the 8086 microprocessor. Those instructions are:

1. SHR : Shift Right


2. SAR : Shift Arithmetic Right
3. SHL : Shift Left
4. SAL : Shift Arithmetic Left
5. ROL : Rotate Left
6. ROR : Rotate Right
7. RCL : Rotate Carry Left
8. RCR : Rotate Carry Righ

Program :
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
mov dl, 5
shl dl, 1

mov cl, 32h


shr cl, 1h

mov bl, -28h


shr bl, 3h

mov al,36h
sal al,1

mov bh, 40h


rol bh,1

mov ch, 01h


ror ch,3

clc
mov dh, 88h
rcl dh, 1
stc
mov ah, 10h
rcr ah, 1
CODE ENDS
END START

Output
16. Demonstrate logical operators , compare and negate
AIM: To demonstrate logical operators, compare and negate.

Description:
Logical instructions are the instructions which perform basic logical operations such as AND, OR,
etc. In 8086 microprocessor, the destination operand need not be the accumulator.

OPCODE OPERAND DESTINATION EXAMPLE

AND D, S D = D AND S AND AX, 0010

OR D, S D = D OR S OR AX, BX

NOT D D = NOT of D NOT AL

XOR D, S D = D XOR S XOR AL, BL

Program :

DATA SEGMENT
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
Mov AL, 02H
AND AL,03H
Mov BL, 02H
OR BL,03H
Mov CL, 02H
NOT CL
Mov DL, 02H
XOR DL,02H
CODE ENDS
END START
Output:
17. Demonstrate stack operations and flag register instructions PUSH, POP, PUSHF,
POPF, SAHF and LAHF.

AIM: To demonstrate stack operations and flag register instructions PUSH, POP, PUSHF, POPF,
SAHF, LAHF using ASSEMBLY LANGUAGE.

Description:

STACK OPERATIONS:

 PUSH - Pushes the given data at the top of the stack.


 POP - Pops the data from the top of the stack.

FLAG REGISTER INSTRUCTIONS:

 LAHF − Used to load AH with the low byte of the flag register.
 SAHF − Used to store AH register to low byte of the flag register.
 PUSHF − Used to copy the flag register at the top of the stack.
 POPF − Used to copy a word at the top of the stack to the flag register.

Program :

DATA SEGMENT START:


savedflag dw ?
ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV ax,15 ; assigns 15/0F to AX
push ax ; pushes ax to the top of stack
push 1 ; pushes 1 to the top of stack
push 2 ; pushes 2 to the top of stack
pushf ; pushes flag byte to the top of the stack
pop savedflag ;pops the daa from top of the stack and store in var
push savedflag ;pushes var data to top of the stack
popf ; pops the data from stack and copies in flag register
lahf ; assigns ah to lower byte of the flag byte
mov ah,2
sahf ; assigns lower flag byte to ah
ENDS
END START
Output :

1) Before push operation:

2) After push ax
3) After push 1 and push 2

4) After pushf

5) After pop
6) After LAHF (flag lower byte in ah)

7) After SAHF
18. Determine maximum of three numbers using int21h
AIM : To write 8086 program(Assembly Language) which determines the largest of
three numbers.

Description : CMP is an instruction which is used to compare to numbers and JGE is


an instruction which jumps to the desired position when the first register data is
greater than equal to second register data.

Program :
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AH,1
int 21h
mov bl,al ;Takes 1st input
int 21h
mov bh,al ;Takes 2nd input
int 21h
mov cl,al ;Takes 3rd input

cmp bl,bh ;Compares bl and bh


jge a ;Jumps to a if bl>=bh
;else
b:
cmp bh,cl ;Compares bh and cl
jge c ;Jumps to c if bh>=cl
mov ah,2
mov dl,cl
int 21h
jmp exit ;jumps to exit

c:
mov ah,2
mov dl,bh ;Largest element i.e here bh is moved to dl
int 21h ;ouput is shown
jmp exit

a:
cmp bl,cl
jge d
mov ah,2
mov dl,cl ;Largest element i.e here cl is moved to dl
int 21h ;ouput is shown
jmp exit

d:
mov ah,2
mov dl,bl ;Largest element i.e here bl is moved to dl
int 21h ;ouput is shown
jmp exit

exit:
mov ah,4ch
int 21h ;exits
ENDS
END START
Output :

Since 6 is the largest in [6,4,1]


So 6 is printed
19. Determine whether given number is positive or negative using int21h
AIM: To write 8086 program(Assembly Language) which determines whether a
number is positive or not.

Description: Using rotate we can determine whether a number is positive or not.A


number is said to be positive if and only if the the carry flag is 0 after performing the
rotate left with carry(RCL) operation.It is said to be negative if the carry flag is 1.

Program :
data segment
a dw -5
p dw 'positive$'
n dw 'negative$'
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,a
rcl bx,1
jc negative ;checks for carry flag
mov ah,09h
lea dx,p
int 21h
jmp down
negative: ;if cf=1
mov ah,09h
lea dx,n
int 21h
down:
rcr bx,1
code ends
end start
Output :
20. Determine whether given number is even or odd using int21h

AIM: To write 8086 program (Assembly Language) which determines whether a number is even or
odd.

DESCRIPTION : Using rotate we can determine whether a number is even or odd.A number is said
to be even if and only if the the carry flag is 0 after performing the rotate right with carry(RCR)
operation.It is said to be odd if the carry flag is 1.

PROGRAM :
data segment
a dw 5
e dw 'even$'
o dw 'odd$'
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,a
rcr bx,1
jc odd ;checks for carry flag
mov ah,09h
lea dx,e
int 21h
jmp down
odd: ;if cf=1
mov ah,09h
lea dx,o
int 21h
down:
rcl bx,1
code ends
end start
OUTPUT :
21.AIM: To Write a program for setting and unsetting Trap Flag bit in Flag Register.

DESCRIPTION:

This flag is used for on-chip debugging. If trap flag is set (1), the CPU automatically generates an
internal interrupt after each instruction, allowing a program to be inspected as it executes
instruction by instruction.If trap flag is reset (0), no function is performed.We can change trap
flag bit in flag register by pushf operation by which whole flag register Is pushed into stack and
then pop it out in any register and change the bit of trap flag by ‘OR’ or ‘AND’ operation on
register. Then by popf operation we put it back in flag register,Thus we can set or unset the trap
flag bit in flag register.

PROGRAM TO SET TRAP FLAG BIT:

data segment
msg1 db "Trap Flag is set$"
msg2 db "Trap flag is unset$"
data ends
code segment
assume cs:code, ds:data
start:
mov bx,data
mov ds,bx
pushf
pop bx
or bh,01H
rcr bh,01
jc down1:
mov ah,09h
mov dx, offset msg2
int 21h
jmp down2
down1:
mov ah,09h
mov dx, offset msg1
int 21h
down2:
rcl bh,01
pop ax
popf
code ends
end start

OUTPUT:

PROGRAM TO UNSET TRAP FLAG BIT:

data segment
msg1 db "Trap Flag is set$"
msg2 db "Trap flag is unset$"
data ends
code segment
assume cs:code, ds:data
start:
mov bx,data
mov ds,bx
pushf
pop bx
and bh,00H
rcr bh,01
jc down1:
mov ah,09h
mov dx, offset msg2
int 21h
jmp down2
down1:
mov ah,09h
mov dx, offset msg1
int 21h
down2:
rcl bh,01
pop ax
popf
code ends
end start

OUTPUT:

_____________________________________________________________________________

22.AIM: To demonstrate Looping in 8086.

DESCRIPTION: The process of executing the instructions repeatedly for more than ones is
called looping .There are many kinds of loops in different languages such as C,Python etc.While
lopp,For loop,do while loop etc.

Thus in 8086 also we have loops for executing instructions repeatedly. We have jmp
instruction. JMP instruction can be used for implementing loops .
We have a separate LOOP instruction which takes CX as its default register to decrement or
increment.

PROGRAM:

data segment
msg db "Hello$"
data ends
code segment
assume cs:code ds:data
start:
mov bx,data
mov ds,bx
mov cl,10
l1:
mov ah,09h
mov dx,offset msg
int 21h
dec cl
jnz l1
code ends
end start

OUTPUT:

PROGRAM(using loop):

data segment
msg db "Hello$"
data ends
code segment
assume cs:code ds:data
start:
mov bx,data
mov ds,bx
mov cx,10
l1:
mov ah,09h
mov dx,offset msg
int 21h
loop l1
code ends
end start

OUTPUT:
23.AIM : Write a program to demonstrate string instructions [ all five instructions 8,16 bit ] .
DESCRIPTION:

Type Opcode Description Syntax

Move MOVS / Transfers the contents of the the MOVSB


MOVSB / memory byte, word or double word ES:[DI]=DS:[SI];
MOVSW pointed to by SI relative to DS to the DI=DI ± 1;
SI=SI ± 1
memory byte, word or double word
pointed to by DI relative to ES. After the
MOVSW
transfer is made, the DI register is
ES:[DI]= DS:[SI];
automatically updated as follows:
DI=DI ± 2;
SI=SI ± 2
● DI is incremented if DF=0.
● DI is decremented if DF=1.

Compare CMPS / CMPSB Compares the contents of the the CMPSB


/ CMPSW memory byte, word or double word DS:[SI] = ES:[DI]
pointed to by SI relative to DS to the DI=DI ± 1;
memory byte, word or double word SI=SI ± 1
pointed to by DI relative to ES and CMPSW
changes the flags accordingly. After the ES:[DI]= DS:[SI];
comparison is made, the DI and SI DI=DI ± 2;
registers are automatically updated as SI=SI ± 2

follows:
● DI and SI are incremented if
DF=0.
● DI and SI are decremented if
DF=1.

Store STOS / STOSB / Transfers the contents of the AL, AX or STOSB


STOSW EAX registers to the memory byte, word ES : [DI] <- AL
DI <- DI ± 1
or double word pointed to by DI relative
to ES. After the transfer is made, the DI
STOSW
register is automatically updated as ES : [DI] <- AL;
follows: ES : [DI+1] <- AH
DI is incremented if DF=0. DI <- DI ± 2
DI is decremented if DF=1.

Scan SCAS / SCASB Compares the contents of the AL, AX or CMPSB


SCASW EAX register with the memory byte, DS:[SI] = ES:[DI]
word or double word pointed to by DI DI=DI ± 1;
relative to ES and changes the flags SI=SI ± 1
accordingly. After the comparison is CMPSW
made, the DI register is automatically ES:[DI]= DS:[SI];
updated as follows: DI=DI ± 2;
● DI is incremented if DF=0. SI=SI ± 2

● DI is decremented if DF=1

Load LODS / LODSB Loads the AL, AX or EAX registers with LODSB
/ LODSW the content of the memory byte, word AL <- DS:[SI] ;
or double word pointed to by SI relative SI <- SI ± 1
to DS. After the transfer is made, the SI LODSW
register is automatically updated as AL <- DS:[SI] ;
follows: AH <- DS:[SI];
● SI is incremented if DF=0.
SI <- SI ± 2
● SI is decremented if DF=1.
MOVSB Program code :

data segment
a db 'Welcome$'
b db 8 dup('$')
data ends
code segment
assume cs:code, ds:data, es:extra
start:
mov ax,data
mov ds,ax
mov es,ax
lea si,a
lea di,b
mov cx,08h
rep
movsb
mov ah,09h
lea dx,b
int 21h
code ends
end start

Output :
MOVSW Program Code:
data segment
a db 'Welcome$'
b db 8 dup('$')
data ends
code segment
assume cs:code, ds:data, es:extra

start:
mov ax,data
mov ds,ax
mov es,ax

lea si,a
lea di,b
mov cx,4h
rep
movsw
mov ah,09h
lea dx,b
int 21h
code ends
end start
OUTPUT:

LOADSB Program Code :


DATA segment
PROMPT DB "The contents of the variable STRING is : $"
STRING DB "Hello!"

code segment
assume cs:code
start:
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA DX, PROMPT ; load and print the string PROMPT
MOV AH, 9
INT 21H
LEA SI, STRING ; set SI=offset address of variable STRING
MOV CX, 6 ; set CX=6
CLD ; clear direction flag
MOV AH, 2 ; set output function
@OUTPUT_LOOP: ; loop label
LODSB ; set AL=DS:[SI]
MOV DL, AL ; set DL=AL
INT 21H ; print a character
LOOP @OUTPUT_LOOP ; jump to label @OUTPUT_LOOP while CX!=0
MOV AH, 4CH ; return control to DOS
INT 21H
END start
code ends

Output :

LODSW Program Code :


DATA segment
PROMPT DB "The contents of the variable STRING is : $"
STRING DB "Hello!"
code segment
assume cs:code ds:data
start:
MOV AX, data
MOV DS, AX
LEA DX, PROMPT
MOV AH, 9
INT 21H
LEA SI, STRING
MOV CX, 3
OUTPUT_LOOP:
LODSW
MOV Dl,al
MOV dh,ah
MOV AH,02
INT 21H
MOv dl,dh
int 21h
MOV dl,20h ;for printing space
int 21h
LOOP OUTPUT_LOOP
END start
code ends
Output :
CMPSB Program Code :
Data segment
STRG1 DB "camp$"
STRG2 DB "camp$"
RESULT DB "STRGS ARE EQUAL$"
RESULT1 DB "STRGS ARE NOT EQUAL$"
code segment
assume:cs code
start:
MOV AX, @DATA
MOV DS, AX
MOV ES, AX
MOV CL, 04H
LEA SI, STRG1
LEA DI, STRG2
CLD
REP CMPSB
JNZ LOOP1
MOV AH, 09H
LEA DX, RESULT
INT 21H
JMP A1
LOOP1: MOV AH, 09H
LEA DX, RESULT1
INT 21H
A1: MOV AH, 4CH
INT 21H
END start
code ends
Output :

CMPSW Program Code :


Data segment
STRG1 DB "camp$"
STRG2 DB "camp$"
RESULT DB "STRGS ARE EQUAL$"
RESULT1 DB "STRGS ARE NOT EQUAL$"
code segment
assume:cs code
start:
MOV AX, @DATA
MOV DS, AX
MOV ES, AX
MOV CL, 02H
LEA SI, STRG1
LEA DI, STRG2
CLD
REP CMPSW
JNZ LOOP1
MOV AH, 09H
LEA DX, RESULT
INT 21H
JMP A1
LOOP1: MOV AH, 09H
LEA DX, RESULT1
INT 21H
A1: MOV AH, 4CH
INT 21H
END start
code ends
Output :
STOSB Program Code :

data segment
STRING DB "Hello!$"
string2 db 6 dup('$')
data ends

code segment
assume cs:code es:extra ds:data
start:
MOV AX, data
MOV DS, AX
MOV ES,AX

LEA SI, STRING


LEA DI,string2
MOV CX, 6

LOOP1:
LODSB
STOSB
LOOP LOOP1
LEA DX,string2
MOV AH,09H
INT 21H
code ends
END start

Output :
STOSW Program Code :
data segment
STRING DB "Hello!$"
string2 db 6 dup('$')
data ends

code segment
assume cs:code es:extra ds:data
Start:
MOV AX, data
MOV DS, AX
MOV ES,AX

LEA SI, STRING


LEA DI,string2
MOV CX, 2
LOOP1:
LODSW
STOSW
LOOP LOOP1
LEA DX,string2
MOV AH,09H
INT 21H
code ends
END start

Output :

SCASB Program Code :


extra segment
string db "Hello$"
data segment
str db "Enter a character $"
str1 db " Character not found$"
str2 db " Character found$"
code segment
assume cs:code es:extra ds:data
start:
MOV BX, extra
MOV ES, BX
MOV BX,data
MOV DS,BX
LEA DI,string
MOV AL,'H'
MOV CX,5
LEA DX,str
mov AH,09h
INT 21H
MOV AH,01H
INT 21H
label1:
SCASB
JE label2
LOOP label1
JNZ label3
label2:
MOV AH,09H
LEA DX,str2
INT 21H
MOV AH,4CH
INT 21H
label3:
MOV AH,09H
LEA DX,str1
INT 21H
END start
code ends
Output :
SCASW Program Code :
extra segment
string db "Hello$"
data segment
str1 db " Word not found$"
str2 db " Word found$"
code segment
assume cs:code es:extra ds:data
start:
MOV BX, extra
MOV ES, BX
MOV BX,data
MOV DS,BX
LEA DI,string
MOV AL,'l'
MOV AH,'l'
MOV CX,3
label1:
SCASW
JE label2
LOOP label1
JNZ label3
label2:
MOV AH,09H
LEA DX,str2
INT 21H
MOV AH,4CH
INT 21H
label3:
MOV AH,09H
LEA DX,str1
INT 21H
END start
code ends

Output :
24.AIM: To Write an assembly language program to transfer a block of bytes from one memory
location to another memory location
DESCRIPTION: In this program ,the value of counter tells the number of bytes to be transferred
The 8-bit data which have to be transfer is stored in continuous memory location starting from
programmer specified address .The data is transferred to a continuous memory location
starting from address specified by programmer.
CLD instruction is used to clear the directional flag, i.e., DF=0.
REP instruction is used to repeat the step until value of CX is not equal to zero and value of CX is
decremented by one at every step, i.e.,
CX=CX-1
MOVSB instruction is used to transfer bytes only from source memory location (MADS) to
destination memory location (MAES).
MADS-->MAES
where MADS=DS*10+SI
MAES=ES*10+DI
Here, value of SI and DI is updated automatically.
PROGRAM:
data segment
a db 'HELLOWORLD$'
b db 8 dup('$')
data ends
code segment
assume cs:code, ds:data, es:extra
start:
mov ax,data
mov ds,ax
mov es,ax
lea si,a
lea di,b
mov cx,08h
rep
movsb
mov ah,09h
lea dx,b
int 21h
code ends
end start
OUTPUT:

______________________________________________________________________________
25.AIM: Write a program for string copy using string instructions.
DESCRIPTION:
String instructions were designed to operate on large data structures.The SI and DI
registers are used as pointers to the data structures being accessed or manipulated.The
operation of the dedicated registers stated above are used to simplify code and minimize its
size.
String instructions are:
LODS
STOS
MOVS
CMPS
SCAS

PROGRAM:
DATA SEGMENT
STR1 DB "ENTER YOUR STRING HERE ->$"
STR2 DB "YOUR STRING IS ->$"
STR3 DB "COPIED STRING IS ->$"
INSTR1 DB 20 DUP("$")
CSTR DB 20 DUP("$")
NEWLINE DB 10,13,"$"
N DB ?
S DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,INSTR1
;GET STRING
MOV AH,09H
LEA DX,STR1
INT 21H
MOV AH,0AH
MOV DX,SI
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
;PRINT THE STRING
MOV AH,09H
LEA DX,STR2
INT 21H
MOV AH,09H
LEA DX,INSTR1+2
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
;PRINT THE COPIED STRING
MOV AH,09H
LEA DX,STR3
INT 21H
MOV CL,INSTR1+1
ADD CL,1
ADD SI,2
LEA DI,CSTR
L1:
MOV BL,BYTE PTR[SI]
MOV BYTE PTR[DI],BL
INC SI
INC DI
CMP BYTE PTR[SI],"$"
JNE L1
MOV AH,09H
LEA DX,NEWLINE
INT 21H
MOV AH,09H
LEA DX,CSTR
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT:

______________________________________________________________________________
26.AIM: To write 8086 program(Assembly Language) to reverse a string using string
instructions (or) functions .
DESCRIPTION: 8086 Assembly is a low level programming language.Mnemonics are used in
writing the program.
Reversing a string means the string that will be given by the user to your program in a specific
sequence will get entirely reversed when the reverse of a string algorithm gets implemented on
that particular input string.
Ex: “raw” is input string then “war” is shown by the code upon exceuting program.
In 8086 to implement reversing of string ,we use string functions namely LODSB(loads a byte
from datasegment into AL ; source operand is a memory location whose address is read from
DS:SI ) and STOSB(copies a byte from AL and stores in a memory location whose address is
given by DI:ES).
In additional to the above mentioned we use direction flag which plays vital role in what
direction to be operated.(If DF=1 ,IP decrements else IP increments)
PROGRAM
seg segment
a db '$raw$'
c db '$after reversing : $'
b db 5 dup('$') ;initializes to b1($),b2($),b3($),b4($),b5($)
seg ends

code segment
assume cs:code, ds:seg, es:seg
start:
mov ax,seg
mov ds,ax
mov es,ax
lea si,a
lea di,[b+4] ;loads eff.address of b4
mov cx,04h
UP:
cld ;df=0
lodsb
std ;df=1
stosb
loop UP
mov ah,09h
lea dx,[c+1]
int 21h
mov ah,09h
lea dx,[b+1] ;loads eff.address of b2
int 21h ;b contains '$war$'
code ends
end start
Output:

____________________________________________________________________________
27.AIM: To check whether given string is palindrome or not.
DESCRIPTION:
This program checks whether the word is equal when reversed also. If the word and reversed
word are equal then it is true else false. Here we use the in-built registers of the processor and
find whether the given string is palindrome or not.
PROGRAM:
seg1 segment
a db '$madam$'
b db 7 dup('$')
str1 db 'Given string is a palindrome$'
str2 db 'Given string is not a palindrome$'
seg1 ends
code segment
assume cs:code, ds:seg1, es:seg1
start:
mov ax,seg1
mov ds,ax
mov es,ax
lea si,a
lea di,[b+6]
mov cx,07h
UP:
cld
lodsb
std
stosb
loop UP
lea si,a
lea di,b
mov cx,07h
cld
repe
cmpsb
jz down1
mov ah,09h
lea dx,str2
int 21h
jmp down2
down1:
mov ah,09h
lea dx,str1
int 21h
down2:
code ends
end start

OUTPUT

______________________________________________________________________________
28.AIM: Write a program to implement Bubble Sort.
DESCRIPTION:
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that
repeatedly steps through the list, compares adjacent elements and swaps them if they are in
the wrong order. The pass through the list is repeated until the list is sorted. The algorithm,
which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top
of the list.
PROGRAM:
data segment
array db 2,1,3,6,9
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
lea si,array
mov ch,04h
UP1:
lea si,array
mov cl,ch
UP2:
mov al,[si]
mov ah,[si+1]
cmp al,ah
jz skip
jc skip
mov [si],ah
mov [si+1],al
skip:
inc si
dec cl
jnz UP2
dec ch
jnz UP1
lea si,array
mov cx,05h
back:
mov ah,02h
mov dl,[si]
add dl,30h
int 21h
inc si
loop back
code ends
end start
OUTPUT

______________________________________________________________________________
29.AIM:To write a program to demonstrate procedures using stacks.

DESCRIPTION:A procedure is a set of code that can be branched to and returned from in such a
way that the code is as if it were inserted at the point from which it is branched to. The branch
to procedure is referred to as the call, and the corresponding branch back is known as the
return. The return is always made to the instruction immediately following the call regardless of
where the call is located.The CALL instruction not only branches to the indicated address, but
also pushes the return address onto the stack. The RET instruction simply pops the return
address from the stack. The registers used by the procedure need to be stored before their
contents are changed, and then restored just before their contents are changed, and then
restored just before the procedure is excited.
A CALL may be direct or indirect and intrasegment or intersegment. If the CALL is intersegment,
the return must be intersegment. Intersegment call must push both (IP) and (CS) onto the stack.
The return must correspondingly pop two words from the stack. In the case of intrasegment call,
only the contents of IP will be saved and retrieved when call and return instructions are used.
Procedures are used in the source code by placing a statement of the form at the beginning of
the procedure

Procedure name PROC Attribute and by terminating the procedure with a statement

Procedure name ENDP

The attribute that can be used will be either NEAR or FAR. If the attribute is NEAR, the RET
instruction will only pop a word into the IP register, but if it is FAR, it will also pop a word into the
CS register.

A procedure may be in:

1. The same code segment as the statement that calls it.

2. A code segment that is different from the one containing the statement that calls it, but in the
same source module as the calling statement.

3. A different source module and segment from the calling statement.

In the first case, the attribute could be NEAR provided that all calls are in the same code segment
as the procedure. For the latter two cases the attribute must be FAR. If the procedure is given a
FAR attribute, then all calls to it must be intersegment calls even if the call is from the same code
segment. For the third case, the procedure name must be declared in EXTRN and PUBLIC
statements.

When both the calling program and procedure share the same set of registers, it is necessary to
save the registers when entering a procedure, and restore them before returning to the calling
program.

PROGRAM:

data segment
a dw 'First arguement-1$'
b dw 'Second arguement-2$'
c dw 'Third arguement-3$'
d dw 'returned from function$'
data ends
code segment
assume cs:code,ds:code
start:
mov ax,data
mov ds,ax
lea bx,a
push bx
lea bx,b
push bx
lea bx,c
push bx
call demo
lea dx,d
mov ah,09h
int 21h
jmp down
demo proc near
pop bx
pop dx
mov ah,09h
int 21h
pop dx
mov ah,09h
int 21h
pop dx
mov ah,09h
int 21h
push bx
ret
down:
code ends
end start

OUTPUT:
______________________________________________________________________________

30.AIM:To write a program to demonstrate macros

DESCRIPTION:
A Macro is a set of instructions grouped under a single unit.
It is another method for implementing modular programming in the 8086 microprocessors
The Macro is different from the Procedure in a way that unlike calling and returning the control
as in procedures, the processor generates the code in the program every time whenever and
wherever a call to the Macro is made .A Macro can be defined in a program using the following
assembler directives:
MACRO (used after the name of Macro before starting the body of the Macro) and ENDM (at
the end of the Macro).
All the instructions that belong to the Macro lie within these two assembler directives.

PROGRAM:
demo macro
lea dx,a
mov ah,09h
int 21h
endm
data segment
a db 'Macro executed$'
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
demo
code ends
end start

OUTPUT:

31.AIM: To write a program for SUM, AVG of given array elements in 8086.

DESCRIPTION:
a) In the program of sum of elements in array ,
CX register stores total number of elements in the array .hence we add elemenst throughout
the loop and store the sum in AL .
SI stores the starting address of the array and increments accordingly to access the elements
sequentially.
if the sum of array is single bit we can directly display it by storing it in AL but,
In case of two digit numbers, we need to store both the digit in AH and AL respectively, so that
we can display both digits one by one .
For the case of sum greater than 2 digits, we need to store the array as DW(Data Word) .
b) In the program of average of elements in array,
CX stores the no. of elements in the array as in the program of sum of elements.
SI stores the starting address of the array and increments accordingly to access the elements
sequentially.
Initially AL stores the total sum, then divides the sum by the total no. of elements which is
stores in the BL register.
Next, we convert the hexadecimal value to decimal with appropriate instructions and display
them with the help of INT 21H
PROGRAMS
A) PROGRAM FOR SUM OF ELEMENTS IN ARRAY:
DATA SEGMENT
ARRAY DB 14,12,15,12,4,2,5,5,12
AVG DB ?
MSG DB "SUM = $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE

START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARRAY
LEA DX,MSG
MOV AH,9
INT 21H
MOV AX,00
MOV BL,9
MOV CX,9
LOOP1:
ADD AL,ARRAY[SI]
INC SI
LOOP LOOP1
MOV AH,0
MOV DL,10
DIV DL
ADD AX,3030H
MOV DH,AH
MOV DL,AL
MOV AH,02H
INT 21H
MOV DL,DH
INT 21H

ENDS
END START

OUTPUT:
B) PROGRAM FOR AVERAGE OF ELEMENTS IN ARRAY :
DATA SEGMENT
ARRAY DB 9,1,2,5,2,6,3,5,2
AVG DB ?
MSG DB "AVERAGE = $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARRAY
LEA DX,MSG
MOV AH,9
INT 21H
MOV AX,00
MOV BL,9
MOV CX,9
LOOP1:
ADD AL,ARRAY[SI]
INC SI
LOOP LOOP1
DIV BL
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
ENDS
END START
OUTPUT:

You might also like