You are on page 1of 44

EXP.

Aim: A) Write a program to add two 8 bit nos


B) Write a program to add two 16 bit nos

Apparatus: Tasm software

Theory:
The add instruction requires either the addend or the augend to be in a register, unless the
source operand is immediate since the addressing modes permitted for the source and destination
are register-register, memory to register, register to memory, register to immediate, and finally
memory to immediate. Hence one of the operands is initially moved to AX. Then using the add
instruction, 16-bit addition is performed.

ALGORITHM: ADDITION OF TWO 8 BIT NUMBERS

Step1: Get the first number in accumulator.


Step2: Get the second number in a register.
Step3: Add the two numbers.
Step4: Store the result in the memory specified
Program:

A) Addition of two 8-bit numbers:


data segment
n1 db 20h
n2 db 50h
ans db ?
data ends

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

mov al,n1
mov bl,n2
add al,bl
mov ans,al

mov ax,4c00h
int 21h
code ends
end start

B) Addition of two 16-bit numbers:


data segment
n1 dw 1000h
n2 dw 2000h
ans dw ?
data ends

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

mov ax,n1
mov bx,n2
add ax,bx
mov ans,ax

mov ax,4c00H
int 21h
code ends
end start
Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm exetention
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.

Result:
Conclusion: We have used the ‘ADD’ instruction in TASM to add two 16-bit and 8-bit
numbers in hex each.
EXP 2

AIM : A)Write a program to multiply two 8-bit numbers


B)Write a program to multiply two 16-bit numbers

Apparatus: Tasm software

Theory:
The 8086 Processor provides both signed and unsigned multiply in their instruction set
to overcome the loss of efficiency in performing the repeated addition. The MUL instruction can
have both 16 and 8 bit operands and the multiplicand is AX or AL, accordingly the result for a
byte multiply is a 16 bit number in AX while that for a word multiply is a 32 bit number, the
lower word of which is in AX and the higher word in DX.

Algorithm:
Step1: Initialize the data segment.
Step2: Get the first number in AX register.
Step3: Get the second number .
Step4: Multiply the two numbers and result is in DX:AX.
Step5: Stop.
Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.
Program:
A) Multiply 2 8-bit numbers
data segment
n1 db 69h
n2 db 69h
ans dw ?
data ends

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

mov al,n1
mov cl,n2
mul cx
mov ans,ax

mov ax,4c00h
int 21h
code ends
end start

B) Multiply 2 16-bit numbers


data segment
n1 dw 1500h
n2 dw 2500h
ans1 dw ?
ans2 dw ?
data ends

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

mov ax,n1
mov cx,n2
mul cx
mov ans1,ax
mov ans2,dx

mov ax,4c00h
int 21h
code ends
end start

Result:

Experiment 2a
(8bit)
Experiment 2b
(16bit)

Conclusion: We have used the MUL instruction to multiply two numbers and the result is
stored in AX.
EXP. 3

AIM : Write a program to find average of two numbers

Apparatus: Tasm software

Theory: The 8086 Processor provides both signed and unsigned divide in their Instruction set to
overcome the loss of efficiency in performing the repeated subtraction.

Division Dividend Operand Quotient:


(DIV or IDIV) (Divisor) Remainder

Word/Byte AX Register or AL : AH
Memory

Dword/Word DX:AX Register or AX : DX


Memory

Qword/Dword EDX: EAX Register or EAX : EDX


Memory

Algorithm:
Step1: Initialise the data segment.
Step2: Get the first number in AX register i.e. dividend.
Step3: Get the second number in BL i.e. divisor.
Step4: Divide the two numbers. Result is in register AX.
Step5: Stop.

Procedure:

Steps to be followed to execute 8086 program in tasm software

 Write Assembly language program in notepad.


 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.

Program:
data segment
n1 dw 0222h
n2 dw 0333h
n3 dw 0002h
ans dw?
data ends
code segment
start:assume ds:data;cs: code
mov ax,data
mov ds,ax
mov ax,0000h
mov ax,n1
mov bx,n2
add ax,bx
mov dx,0000h
mov cx,n3
div cx
mov ans,ax
mov ax,4c00h
int 21h
code ends
end start

Result:
Conclusion:
We have used the DIV instruction to add two numbers and then divide them. The AX register
stores quotient and the DX register stores the remainder.
EXP .4

AIM :- Block transfer using string instruction

Apparatus: Tasm software

Theory:
Register SI and DI must be initialized to point to the source/destination strings before executing
the string instructions. The string instructions automatically update SI and/or DI in anticipation of
processing the next string element. For this user have to set/reset DF flag to determine whether
pointer should auto increment (DF = 0) or should auto decrement (DF = 1).

Algorithm:
Step1: Initialize the data segment. Load Count value
Step2: Initialize SI and DI
Step3: Clear D bit of flag register.
Step4: Use string instruction and move until count becomes zero.
Step5: Stop.

Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.

Program:
A) Byte Transfer
data segment
block1 db 05 dup(07h)
counter db 05
data ends

extra segment
block2 db 05 dup(00h)
extra ends

code segment
start: assume ds:data,cs:code,es:extra
mov ax,data
mov ds,ax
mov ax,extra
mov es,ax
mov ax,0000h
lea si,block1
lea di,block2
mov cl,counter
cld
up:rep movsb
dec cl
jnz up
mov ax,4c00h
int 21h
code ends
end start

B) Word Transfer
data segment

count db 03h

block1 db 6 dup(0Bh)

data ends

extra segment

block2 db 6 dup(00h)

extra ends

code segment

start: assume cs:code, ds:data, es:extra

mov ax,data

mov ds,ax

mov ax,extra

mov es,ax

lea si,block1

lea di,block2

mov cl,count

cld

rep movsw

mov ax,4c00h
int 21h

code ends

end start

Result:
Conclusion: We defined two block and moved the bytes from one block to
another.
EXP5

AIM : Write a program to find the largest no. in a list of 5 nos.

Apparatus: Tasm software

Theory: To find the largest number in any given array, the contents of the array must be
compared with an arbitrary biggest number. The first number of the array is taken in a register AL.
The second number of the array is compared with the first one. If the first one is greater than the
second one, it is left unchanged. However if the second one is greater than the first, the second
number replaces the first one in the AL register. The procedure is repeated for every number in the
array and thus it requires n iterations. At the end of nth iteration the largest number will reside in
the register AL.

Algorithm:
Step1: Initialize the data segment
Step2: Initialize pointer.
Step3: Initialize counter.
Step4: Initialize base pointer for array.
Step5: Compare number with maximum. If no carry go to step VII
Step6: Save the maximum number
Step7: Decrement counter
Step8: Increment pointer
Step9: Check if count=0. If not go to step V
Step10: Store maximum number.
Step11: Display result.
Step12: Stop

Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.
Program:
data segment
block db 25h,14h,50h,04h,20h
counter db 05h
largest db ?
data ends

code segment
start: assume ds:data, cs:code
lea si, block
mov ax, data
mov ds, ax

mov cl,counter
mov al,[si]
up:inc si
cmp al,[si]
jnc down
mov al, [si]
down:dec cl
jnz up
mov largest,al

mov ax,4c00h
int 21h
code ends
end start

RESULT:
CONCLUSION: We defined a block and then searched for the largest among them and
then stored it in a variable.
EXP. 6
AIM: A) To find out number of even number in a block
B) Experiment to find out number of odd numbers in a block

APPARATUS: Tasm Software


Theory:
Rotate blocks are essential elements in most processors. They are useful on their own, but they also
are used in multiplication and division modules. In a binary computer, a left shift has the same effect
as a multiplication by 2, and a right shift has the same effect as a division by 2. Since shift and rotate
operations perform much more quickly than multiplication and division, they are useful as a tool in
program optimization.

ROL: left rotation, the bits that fall off at left end are put back at right end.
ROR:right rotation, the bits that fall off at right end are put back at left end

Algorithm:
Step1: Initialize the data segment
Step2: Initialize pointer.
Step3: Initialize counter.
Step4: Initialize base pointer for array.
Step5: Rotate the number to right. If no carry go to step VII
Step6: Increment even counter by one
Step7: Decrement counter
Step8: Increment pointer
Step9: Check if count=0. If not go to step V
Step10: Store even counter.
Step11: Display result.
Step12: Stop

Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.

Program:
A) Even Number
data segment
block db 72h,43h,17h,48h,62h,08h
count db 06h
even db 00h
data ends

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

mov cl,count
mov dl,even
lea si,block
up:mov al,[si]
ror al,01h
jc down
inc dl
down: inc si
dec cl
jnz up
mov even,dl
mov ax,4c00h
int 21h
code ends
end start

B) Odd Number
data segment
block db 72h,43h,17h,48h,62h,08h
count db 06h
odd db 00h
data ends

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

mov cl,count
mov dl,odd
lea si,block
up:mov al,[si]
ror al,01h
jnc down
inc dl
down: inc si
dec cl
jnz up
mov odd,dl

mov ax,4c00h
int 21h
code ends
end start

Result:

--
Conclusion: We used ROR function to move data to right and identify if the right most
number is 0 or 1 which in turn helps us identify odd or even number.
EXP. 7

Aim: Write a program to arrange a given string in ascending / descending order.

Problem: The data string of 5 bytes is present in a data memory. Arrange the given string in
ascending/ descending order in same memory location (Data Given: 2h,7h,1h,3h,6h)

Theory:
For arranging a given string in Ascending/Descending order first decides which algorithm/method
we have to use. (e.g. Bubble Sort) By comparing 1st data of memory with rest of the data, we can
identify either 1st largest or 1st smallest byte. Place this byte at last address of data memory. Repeat
the same procedure or identification of next smallest or largest byte and arrange this byte above
the 1st one. Repeat the same procedure up to last byte. Use LEA instruction for offset.

Algorithm:
Step-1: Initialize the data memory segment from specified address.
Step-2: Initialize the outer counter (counter-1) for repetitive action of finding smallest / largest no.
among the string.
Step-2: Fetch 1st data from data memory location into any general-purpose register
Step-3: Initialize the inner counter (counter-2) for identification of 1 smallest/largest no. among
st

the string.
Step-4: Increment data memory offset & compares data of memory with GPR.
Step-5: Check the status of carry flag & swap the content of two memories depend upon
requirement.
Step-6: Decrement inner counter & check zero flag for 1st largest / smallest no. If ZF=0, repeat
from step 4. If ZF=1 then decrement outer counter & check again ZF, whether the ring is arrange
in ascending /descending order. If ZF=0, then repeat the procedure from step-2.
Step-6: If ZF=1 then terminate the program by using DOS interrupt.

Note : For Ascending Order jge instruction should be replaced by jle instruction.

Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.

Program:
A)Ascending
data segment
block db 04h,50h,24h,03h,28h
data ends

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

mov ch,04h
up2: mov cl,04h
lea SI,block

up1:mov al,[SI]
mov bl,[SI+1]
cmp al,bl
jc down
xchg al,[SI+1]
xchg al,[SI]

down: INC SI
dec cl
jnz up1
dec ch
jnz up2

mov ax,4c00h
int 21h
code ends
end start

B) Descending
data segment
block db 04h,50h,24h,03h,28h
data ends

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

mov ch,04h
up2: mov cl,04h
lea SI,block

up1:mov al,[SI]
mov bl,[SI+1]
cmp al,bl
jnc down
xchg al,[SI+1]
xchg al,[SI]

down: INC SI
dec cl
jnz up1
dec ch
jnz up2

mov ax,4c00h
int 21h
code ends
end start

Result: Experiment no. 8 Ascending

Descending
Conclusion:
The given data string is arranged in ascending/descending order and the result
of program is observed as follows
EXP.8
AIM :- Conversion of ASCII to packed BCD no.

Apparatus: Tasm software

Theory:
Packed BCD means that each byte contains two BCD digits, one digit in the upper nibble and
the other digit in the lower nibble.
For example, the number 74 would be expressed by the single byte 0x74.
Unpacked BCD would only have one BCD digit per byte. (Or more generally, one digit per CPU
word.)
For example, the number 74 would be expressed by the separate integers 0x07 and 0x04.

Algorithm:

Step1: Initialize the data segment.


Step2: Get the first number in AL register.
Step3: Clear the upper nibble of AL
Step4: Rotate 4 times left.
Step5: Get 2 number and add it with AL.
nd

Step6: Store the result.


Step7: Stop.

Procedure:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command tasm/zi file name .asm
 Write command tlink/v file name .obj
 Write command td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select view tab then select variable to see the result.
Program:
A) ASCII to packed BCD
data segment
no1 db '4'
no2 db '5'
result db 00h
data ends

code segment
start:assume ds:data,cs:code
mov ax,data
mov ds,ax
mov al,no1
and al,0fh
ror al,04h
mov bl,no2
and bl,0fh
add al,bl
mov result,al

mov ax,4c00h
int 21h
code ends
end start

B) ASCII to BCD using AAA


data segment
no1 db '4'
no2 db '5'
result db 00h
data ends

code segment
start:assume ds:data,cs:code
mov ax,data
mov ds,ax
mov al,no1
mov bl,no2
add al,bl
aaa
mov result,al

mov ax,4c00h
int 21h
code ends
end start
RESULT:
Ascii to bcd

Ascii to bcd with aaa


CONCLUSION: We define two ASCII characters and them convert them to BCD
characters.

EXP. 9

AIM: Write a program in assembly language to search a given data in a predefined


array. If the data is found in the array then display “Found”, otherwise “Not Found”.

APPARATUS: Tasm Software

THEORY:
The given data is stored in a register, and then it is compared with each
element of the array. The comparison is terminated once the data is found or after
comparing all the elements of the array. One register can be used to keep track of
the position of the element being compared. One of the index register can be used to
hold the address of the element being compared.
 DOS and BIOS Interrupts
 DOS and BIOS interrupts are used to perform some very useful functions,
such as displaying data to the monitor, reading data from keyboard, etc.
 They are used by identifying the interrupt option type, which is the value
stored in register AH and providing, whatever extra information that the
specific option requires.
 BIOS Interrupt 10H
 Option 9H – Write a character and its attribute at the cursor position.

 Registers used:
 AH = 9H.
 AL = ASCII value.
 BH = display page.
 BL = attribute.
 CX = number of characters to write.
 Use of $ sign in the input read and print command
The variable message contains ‘Found’ (or, ‘Not Found’) followed by the ‘$’ character.
We terminate the string with the ‘$’ character because there is an MS-DOS subprogram
(number 9h) for displaying strings which expects the string to be terminated by
the ‘$’ character.
 Labels
A label can be placed at the beginning of a statement. During assembly, the label is
assigned the current value of the active location counter and serves as an
instruction operand. There are two types of lables:
 Symbolic
Numeric
Symbolic Labels:
A symbolic label consists of an identifier (or symbol) followed by a colon (:)
(ASCII 0x3A). Symbolic labels must be defined only once. Symbolic labels
have global scope and appear in the object file's symbol table.
Symbolic labels with identifiers beginning with a period (.) (ASCII 0x2E) are
considered to have local scope and are not included in the object file's symbol
table.
Numeric Labels:
A numeric label consists of a single digit in the range zero (0) through nine (9)
followed by a colon (:). Numeric labels are used only for local reference and are
not included in the object file's symbol table. Numeric labels have limited scope
and can be redefined repeatedly.

ALOGORITHM:
Step1: Define the block and load the data (i.e. array) into it.
Step2: Define a temporary variable (say Variable) and get an element of the array
in this variable.
Step3: Define two more variables (say Msg1 and Msg2) to display the string
‘Found’ and ‘Not Found’ and store them in these two variables (8 bit register each)
respectively.
Step4: Initialize the counter depending on the length of the array defined.
Step5: Initialize the base pointer for array.
Step6: Move the element of array present in temporary variable to AL register.
Step7: Compare an element of array in the temporary variable (in AL) with the data
present in the base pointer address.
Step8: If zero flag is set then display the message (or string) ‘Found’.
Step9: If the zero flag is not set then increment the pointer by one.
Step10: Decrease the counter by one.
Step11: If the counter becomes zero then display the error message ‘Not Found’,
otherwise jump to step 7 (compare AL – [SI])
Step12: Stop.

PROCEDURE:
Steps to be followed to execute 8086 program in tasm software
 Write Assembly language program in notepad.
 Save this program file in tasm /bin folder with .asm extension
 Go to window start then select run
 Type command cmd (command window will pop up for dos prompt).
 Change the directory (cd\)
 Select path c:cd tasm/bin
 Write command: tasm/zi file name .asm
 Write command: tlink/v file name .obj
 Write command: td file name .exe
 Program Window will appear
 Select view tab then select cpu
 Press F8 to execute program in single step mode
 Select window tab then select screen view to see the result on the command
prompt.

PROGRAM:
data segment
block db 0BBh,72h,0FFh,07Ah,0FFh,12h,08h
count db 07h
result db ?
data ends

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

mov al,0FFh
mov bl,00h
mov cl,count
lea si,block
up:
cmp al,[si]
jnz down
inc bl
down: inc si
dec cl
jnz up
mov result,bl

mov ax,4c00h
int 21h
code ends
end start
RESULT:

Conclusion: We search a given byte among the given memory locations and count the number
of times they have been repeated.
Exp. 10
Aim: To analyse 80386 and Pentium processor
INTRODUCTION:
80386: Limitations of 286 are as follows
• 16-bit ALU
• 64K segment size
• cannot be easily switched back and forth between real and protected mode
– to come back to the real mode from protected mode, you have to switch off the
286
To overcome these problems 80386 was created. It has
• 32 bit ALU
• segment size can be as large as 4G
– a program can have as many as 16K segments.
– So, a program has access to 4Gx16K=64TB of virtual memory
• 386 has a virtual 86 mode which allows easy switching between real and protected
modes.

PENTIUM:
• Introduced in '93 but was expected in 1992
• Pentium signals an improvement to the architecture found in 486
• Faster numeric processor
• Operates about 5 times faster than the 486 numeric processor
• A dual integer processor
• Often allows two instructions per clock
• Branch prediction logic
• MMX instructions --- a later introduction to Pentium

FEATURES:
8086
• Alternatively referred to as a 386 or the i386
• Intel introduced the first 32-bit chip, 80386, in October 1985 as an upgrade to the 80286
processor
• Intel stopped producing 386 since September 2007.
• 386 incorporates 275,000 transistor
• 386 was capable of performing more than five million instructions every second (MIPS)
• 386 was available in clock speeds between 12 and 40MHz.

PENTIUM:
1. 64 bit data bus
2. 8 bytes of data information can be transferred to and from memory in a single
bus cycle
3. Supports burst read and burst write back cycles
4. Supports pipelining
5. Instruction cache
6. 8 KB of dedicated instruction cache
7. Two Integer execution units, one Floating point execution unit
8. Dual instruction pipeline
9. 256 lines between instruction cache and prefetch buffers; allows 32 bytes to be
transferred from cache to buffer
10. Data cache
11. 8 KB dedicate data cache gives data to execution units
12. 32 byte lines
13. Two parallel integer execution units
14. Allows the execution of two instructions to be executed simultaneously in a single
processor clock
15. Floating point unit
PENTIUM:
ftp://download.intel.com/design/pro/datashts/24357001.pdf
BLOCK DIAGRAM OF 80386
BLOCK DIAGRAM OF Pentium

CONCLUSION:
Learnt about the features, architecture and data sheet of 80386 and Pentium.

You might also like