0% found this document useful (0 votes)
36 views56 pages

EEE MPMC Lab Manual

Uploaded by

subbaiyal6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views56 pages

EEE MPMC Lab Manual

Uploaded by

subbaiyal6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

I PROGRAMMING USING 8085 MICROPROCESSOR

1. A) Addition of two 8 bit numbers using 8085

AIM:

To write assembly language program the addition, subtraction, multiplication and


division of two 8bit numbers.

ADDITION ALGORITHM:

1. Start
2. Load the first data from memory to accumulator and move it to B register
3. Load the second data from the memory to accumulator
4. Clear ‘C’ register
5. Add the content of B register to the accumulator
6. Check for carry=1,go to step7 else carry=0 go to step8
7. Increment the C register
8. Store the sum in memory
9. Move the carry to accumulator and store in memory
10. Stop

ADDITION PROGRAMME:

LDA 4500
MOV B, A
LDA 4501
MVI C, 00
ADD B
JNC 400E
INR C
STA 4502
MOV A, C
STA 4503
HLT

OUTPUT:
Input address Input data Output address Output data
Without carry
With carry

1 B) Subtraction of two 8 bit numbers using 8085

SUBTRACTION ALGORITHM:

1. Start
2. Load the (data to be subtracted) subtrahend from memory to accumulator and move
it to B register
3. Load the minuend from memory to accumulator
4. Clear register to account for sign of result
5. Subtract the content of B register from the content of accumulator
6. Check for carry. if carry=0 then go to step8, if carry=1 then go to step7
7. Increment C register
8. Store the different in memory
9. Move the content of C register (sign bit) to accumulator and store in memory
10. Stop
SUBTRACTION PROGRAMME:
LDA 4500
MOV B, A
LDA 4501
SUB B
JNC 400E
INR C
STA 4502
MOV A, C
STA 4503
HLT

OUTPUT:
Input address Input data Output address Output data
Without carry
With carry

1 C) Multiplication of two 8 bit numbers using 8085

MULTIPLICATION ALGORITHM:

1. Start
2. Load the multiplicand (data to be multiplied) from memory to accumulator and
move it to B register
3. Load the multiplier from memory to accumulator and move it to C register
4. Clear accumulator and D register
5. Add the content of B register with the accumulator content
6. Check for carry. If carry=0 then go to step8. If carry=1 then go to step7
7. Increment D register
8. Decrement C register
9. Check for zero flag condition. If zero flag=1 then go to step5. If zero flag=0 then go
to step10
10. Store the product output in memory
11. Move the content of D (carry) to accumulator and store in memory
12. Stop
MULTIPLICATION PROGRAMME:
LDA 4050
MOV B, A
LDA 4051
MOVC, A
MVI A, 00
MVI D, 00
ADD B
JNC 4011
INR D
DCR C
JNZ 400C
STA 4052
MOV A, D
STA 4053
HLT

OUTPUT:
Input address Input data Output address Output data
Without carry
With carry
1 D) DIVISION of two 8 bit numbers using 8085

DIVISION ALGORITHM:
1. Start
2. Load the divisor from the memory to accumulator and move to B register
3. Load the divided (the data to be divided) from memory to accumulator
4. Clear C register
5. Compare the content of accumulator with the content of B register. i.e if divided is
more than divisor (or) less than divisor
6. Check for carry. If divided is less than divisor carry=1, then go to step10. If divided
is more than divisor carry=0, then go to step7
7. Subtract the content of B register
8. Increment C register and compare the contents of accumulator and B register
9. Check for carry, if carry=0 then go to step7. If carry=1,then go to step10
10. Store the result (reminder) in memory
11. Move the content of C (quotient) to accumulator and store in memory
12. Stop.

DIVISION PROGRAMME :
LDA 4050
MOV B, A
LDA 4051
MVI C,00
CMP B
JC LOOP
SUB B
INR C
CMP B
JNC 400D
STA 4052
MOV A,C
STA 4053
HLT

OUTPUT:
Input address Input data Output address Output data
With reminder
2. PROGRAMMING USING 8086
2. A) ADDITION OF TWO 32 BIT NUMBERS

AIM:

To write an assembly language program to add two 32 bit numbers.

ALGORITHM:

Step 1: Take the least significant bit of first and second number as input

Step 2: Add them and store in a memory location

Step 3: Take the most significant number of the first and second number as input

Step 4: Add them with carry generated in step 2 and store

Step 5: Terminate the program

PROGRAM:

Title 32 bit addition

.model small

.data

S1 dw 1357h

S2 dw 2468h

S3 dw 1011h

S4 dw 0012h

S5 dw ?

S6 dw ?
.code

main proc near

mov ax,@data

mov ds,ax

mov ax,s1

mov bx,s2

add ax,bx

mov s5,ax

mov ax,s3

mov bx,s4

adc ax,bx

mov s6,ax

mov ah, 4ch

int 21h

main endp

end main

INPUT

0002:

0003:

0004:

0005:

0006:
0007:

0008:

0009:

OUTPUT

000A:

000B:

000C:

000D:

RESULT: Thus the assembly language program for 32 bit addition was written and output
was verified.

2. B) ADDITION OF TWO 64 BIT NUMBERS

AIM:

To write an assembly language program to add two 64 bit numbers.

ALGORITHM:

Step 1: Take the least significant word of first and second number as input

Step 2: Add them and store in memory location

Step 3: Take the most significant numbers of a first and second number as input

Step 4: Add them with the carry generated in step 2

Step 5: Terminate the program


PROGRAM:

Title 64 bit addition

.model small

.data

S1 dw 1111h

S2 dw 1010h

S3 dw 1221h

S4 dw 1421h

S5 dw 1212h

S6 dw 1354h

S7 dw 1411h

S8 dw 1311h

S9 dw ?

S10 dw ?

S11 dw ?

S12 dw ?

.code

main proc near

mov ax,@data

mov ds,ax

mov ax,s1
mov bx,s2

add ax,bx

mov s9,ax

add ax,bx

mov s9,ax

mov ax,s3

mov bx,s4

adc ax,bx

mov s10,ax

mov ax,s5

mov bx,s6

adc ax,bx

mov s11,ax

mov ax,s7

mov bx,s8

adc ax,bx

mov s12,ax

mov ah,4ch

int 21h

main endp

end main
INPUT:

000A:

000B:

000C:

000D:

000E:

000F:

0010:

0011:

0012:

0013:

0014:

0015:

0016:

0017:

0018:

0019:

OUTPUT

001A:

001B:

001C:

001D:
001E:

001F:

0020:

0021:

RESULT:

Thus the assembly language program for 64 bit addition was written and the output was
verified.

3.a) COUNTING THE NUMBER OF 1’s IN A GIVEN WORD

AIM

To write an assembly language program to count the number of 1’s in a given word.

ALGORITHM

STEP 1: Get the word where number of 1’s need to be found as input.

STEP 2: Shift the input to the right enough carry bit by 1 bit position and check for the
carry.

STEP 3: If carry is present, increment a register otherwise repeat steps 2 and 3 16H to 10H
times.

STEP 4: Store the contents of the register in a memory location which is the result as
which number of 1’s present in the word.

STEP 5: Terminate the program.


PROGRAM:

title counting

.model small

.data

S1 dw 0DEF1h

S2 dw ?

.code

main proc near

mov ax,@data

mov ds,ax

mov ax,s1

mov bl,00h

mov cl,10h

lable 2: rcr ax,01h

jnc lable

inc bl

lable: loop lable 2

mov s2,bl

mov ah,4ch

int 21h

main endp

end main
MODEL CALCUATION

Given word: 0EFD1h

Hexadecimal

E – 1101

F – 1111

D – 1101

1 – 0001

E F D 1

8421 CODE: 1101 1111 1101 0001

No. of 1’s : 11 – 0Bh

OBSERVATION

INPUT OUTPUT

0000: 0002:

0001:

RESULT

Thus, the assembly language program for counting the number of 1’s in a given word was
written and the output was verified.
3. B) SWAPPING OF A GIVEN WORD

AIM

To write an assembly language program to perform swapping of a given word.

ALGORITHM

STEP 1: Get the word for which the swapping has to be done as input.

STEP 2: Initialize a register with a count 08h.

STEP 3: Shift the input to the right by 1 bit position.

STEP 4: Decrement the counter by 1 carry time when the shifting is done.

STEP 5: Repeat the steps 3 and 4 till the counter is zero.

STEP 6: Terminate the program.

PROGRAM

title swapping

.model small

.data

S1 dw 0AB09h

S2 dw ?

.code

main proc near

mov ax,@data

mov ds,ax

mov ax,s1
mov cl,08h

step1: ror ax, 01h

loop step1

mov s2,ax

mov ah,4ch

int 21h

main endp

end main

MODEL CALCULATION

Input Number: BC09

Output Number: 09BC

OBSERVATION

INPUT OUTPUT

0005: 0007:

0006: 0008:

RESULT

Thus, the assembly language program for swapping of a given 16 bit data was written and
output was verified.
4. A) ARITHMETIC MEAN OF N-NUMBERS

AIM:

To write an assembly language program to perform arithmetic mean of n-numbers.

ALGORITHM:

1. Get the 3 words whose arithmetic mean has to be found.

2. Store the data.

3. Add the words and store it.

4. If carry comes increment the register.

5. Divide the sum of 3 words by 3.

6. Store the final result.

7. Terminate the program.

PROGRAM:

title arithmetic mean

. model small

. data

s1 dw 0002H,0003H,0004H

count db 03H

s2 dw ?

.code

main proc near

mov ax,@data
mov ds,ax

mov cl,count

mov dl,cl

lea si,s1

mov ax, [si]

dec cl

lab1: inc si

inc si

add ax,[si]

loop lab1

div dl

mov s2,ax

mov ah,4ch

int 21h

main endp

end main

MODEL CALCULATION:

Hexadecimal number decimal equivalent

0002h 2

0003h 3

0004h 4

Arithmetic mean = (2+3+4)/3 = 9/3 = 3


OBSERVATION:

sample i/p: sample o/p:

0002 : 0008:

0003: 0009:

0004:

0005:

0006:

0007:

RESULT:

Thus, the assembly language program for finding the arithmetic mean of n-number was
written and the output was verified.
4.b)ARITHMETIC MEAN OF SQUARE OF N-NUMBERS

AIM:

To write an assembly language program to find arithmetic mean of squares of n-numbers.

ALGORITHM:

1.Get the data as input.

2.Square the first data.

3.Add the required data to a clear register.

4.Increment the counter by 1.

5.Repeat the steps 2,3 and 4 till the count is zero.

6.Divide the added result with the total no. of data.

7.Terminate the program.

PROGRAM:

title arithmetic mean of square

.model small

.data

s1 dw 0005H.0003H,0004H

count db 03H

s2 dw ?

. code

main proc near

mov ax ,@data
mov ds ,ax

lea si,s1

mov cl,count

mov bx,0000H

step : mov ax ,[si]

mul ax

add bx , ax

inc si

inc si

loop step

mov ax , bx

mov dl , count

div dl

mov s2 , ax

mov ah , 4ch

int 21h

main endp

end main
MODEL CALCULATION:

hexadecimal number decimal equivalent

0005h: 5

0003h: 3

0004h: 4

Arithmetic mean of square of n-numbers = (52+32+42)/3 = 50/3

Quotient = 16

Remainder = 02

(16)d = 10h

(02)d = 02h

OBSERVATION:

Sample i/p: sample o/p:

0008: 000F:

0009: 0010:

000A:

000B:

000C:

RESULT:

Thus, the assembly language program for finding the arithmetic mean of
squares of n-numbers was written and output was verified.
5. A) BCD TO ASCII CONVERSION

AIM :

To write an assembly language program to convert BCD to ASCII code


conversion.

ALGORITHM:

1.Get the BCD to ASCII numbers as input.

2.Mark the low and higher order nibble by AND instruction using OFH and
OFOH.

3.Low order marked nibble rotated four times to the right.

4.Add the two data with 30H.

5.Terminate the program.

PROGRAM:

title bcd to ascii conversion

.model small

.data

S1 db 25H

S2 db ?

S3 db ?

.Code

main proc near


mov ax,@data

mov ds,ax

mov al,s1

mov cl,04H

AND al,0F0H

AND bl,0FH

Step1: ROR al,01H

Loop step1

OR al,30H

OR bl,30H

mov s2,al

mov s3,bl

mov ah,4ch

int 21h

main endp

end main
MODEL CALCULATIONS:

Input BCD no=

ASCII=( + ) ( + )

Output=

OBSERVERATION:

Sample input: sample output:

0005: 0006:

0007:

RESULT:

Thus the assembly language program for BCD to ASCII conversion was
written and output was verified.

5.b) ASCII TO BCD CONVERSION

AIM:

To write an assembly language program to convert ASCII to BCD code


using 8086 processor

ALGORITHM:

1.Get the ASCII number as input.

2.Mark the highest order nibble by and with 0FH.

3.Rotate the content of first data as to make lower order nibble to become higher order
nibble.

4.Add the contents of the two no. obtained after step 2 and 3.
5.Store the memory location.

6.Terminate the program.

PROGRAM:

Title ascii to bcd

.model small

.stack 64

.data

S1 db 37h,34h

S2 db ?

.code

main proc near

mov ax,@data

mov ds,ax

lea si,s1

lea di,s2

mov c1,04h

mov al,[si]

mov bl,al

inc si

mov al,[si]

AND al,0fh
AND bl,0fh

lab1: ror bl,01h

loop lab1

OR al,bl

mov [di],al

mov ah,4ch

int 21h

main endp

end main

MODEL CALCULATION:

ASCII : 37h 34h

AND 37 with 0fh

AND 34 with 0fh

37+0f=07h 34+0f=04h

0000 0111

rotate 07h to the right 4 times

0111 0000

7 0

Add (OR) 70 with 04

70+04=74h
OBSERVATION:

Sample input: sample output:

0000: 0002:

0001:

RESULT:

Thus the assembly language program for ascii to bcd conversion was written and
the output was verified.

6. A)_FINDING THE LARGEST NUMBER IN A GIVEN n-NUMBERS

AIM : To write an assembly language program to find the largest of n-numbers.

ALGORITHM :

Step 1 : Load the data that needs to be compared.

Step 2 : Compare ith and (i+1)th number using compare instruction.

Step 3 : Compare the carry.

Step 4 : If carry is present , exchange the two numbers so that ax contains the largest
number otherwise go to Step 3.

Step 5 : Decrement cl by 1 and repeat from 2 till cl goes to zero.

Step 6 : Show that [ax] in a memory location.

Step 7 : Terminate the program.


PROGRAM:

title largest no. search

.model small

.data

s1 dw 0005H,0008H,0003H,0007H

s2 dw ?

.code

main proc near

mov ax, @data

mov ds,ax

lea si,s1

lea di,s2

mov ax, [si]

mov cl, 04H

dec cl

step2 : inc si

inc si

cmp ax, [si]

step1: dec cl

jnz step 2

mov [di], ax

mov ah, 4ch

int 21h
main endp

end main

OBSERVATION :

Sample I/p

0006 : 05

0007 : 00

0008 : 08

0009 : 00

000A : 03

000B : 00

000C : 07

000D : 00

Sample O/p

000E : 08

000F : 00

RESULT :

Thus the assembly language program for searching the largest number was written and the
output was verified.

6.b) FINDING THE SMALLEST NUMBER IN A GIVEN n-NUMBERS


AIM : To write an assembly language program to find the smallest of n-numbers.

ALGORITHM :

Step 1 : Load the data that needs to be compared.

Step 2 : Compare ith and (i+1)th number using compare instruction.

Step 3 : Compare the carry.

Step 4 : If carry is present , exchange the two numbers so that ax contains the smallest
number otherwise go to Step 3.

Step 5 : Decrement cl by 1 and repeat from 2 till cl goes to zero.

Step 6 : Show that [ax] in a memory location.

Step 7 : Terminate the program.

PROGRAM:

title smallest no. search

.model small

.data

s1 dw 0005H,0008H,0003H,0007H

s2 dw ?

.code

main proc near

mov ax, @data

mov ds,ax
lea si,s1

lea di,s2

mov cl, 04H

mov ax , [si]

dec cl

step2 : inc si

inc si

cmp ax, [si]

JC step1

mov ax , [si]

step1 : dec cl

JNZ step2

mov [di],ax

mov ah, 4ch

int 21h

main endp

end main

OBSERVATION :

Sample I/p

0004 : 05

0005 : 00

0006 : 08
0007 : 00

0008 : 03

000 :9 00

000A: 07

000B : 00

Sample O/p

000C : 03

000D : 00

RESULT :

Thus the assembly language program for searching the smallest number was written and
the output was verified.

7. A) SORTING OF N-NUMBERS (ASCENDING ORDER)

AIM:

To write an assembly language program for sorting of n-numbers in ascending order


using 8086 microprocessor.

ALGORITHM:

1. Get the number to be sorted.


2. Now the number in its respective register.
3. Store the number in ascending order.
4. Store the result in memory location and give the output.
5. Terminate the program.

PROGRAM:
title ascending sort

.model small

.data

S1 dw 0009H,0006H,0003H,0002H,0001H

.code

main proc near

mov ax,@data

mov ds,ax

mov bl,05h

dec bl

step3:lea si, S1

mov cl,bl

step2:mov ax, [si]

inc si

inc si

cmp ax, [si]

JC step1

XCHG ax, [si]

Mov[si-0002], ax

Step1: dec cl

JNZ step2

Dec bl

JNZ step3
mov ah,4ch

int 21h

main endp

end main

OBSERVATION:

SAMPLE OUTPUT:

0008 : 01

0009 : 00

000A : 02

000B : 00

000C : 03

000D : 00

000E : 06

000F : 00

0010 : 09

0011 : 00

RESULT:

Thus the assembly language program for sorting of given numbers in ascending order was
written and the output was verified.

7.B) SORTING OF N-NUMBERS (DESCENDING ORDER)


AIM:

To write an assembly language program for sorting of n-numbers in descending order


using 8086 microprocessor.

Algorithm:

1. Load the data that need to be sorted.


2. Set of counter as 5, decrement counter [bl].
3. Move the bl content to actual counter cl.
4. Compare ith term or (i+1)th term, decrement compare instruction.
5. If carry is present, exchange, if not present go to step1.
6. Decrement counter cl,if not zero.
7. Decrement counter bl, not zero repeat.
8. Terminate the program.

PROGRAM:

title ascending sort

. model small

.data

S1 dw 0009H,0006H,0003H,0002H,0001H

.code

main proc near

mov ax,@data

mov ds,ax

mov bl,05h

dec bl

step3: lea si, s1

mov cl,bl
step2: mov ax, [si]

inc si

inc si

cmp ax, [si]

JNC step1

XCHG ax, [si]

Mov [si-0002H], ax

Step1: dec cl

JNZ step2

Dec bl

JNZ step3

mov ah,4ch

int 21h

main endp

end main

OBSERVATION:

SAMPLE OUTPUT:

0008 : 09

0009 : 00

000A : 06

000B : 00

000C : 03
000D : 00

000E : 02

000F : 00

0010 : 01

0011 : 00

RESULT:

Thus the assembly language program for sorting of given numbers in descending order
was written and the output was verified.

9. BINARY TO GRAY CODE CONVERSION

AIM:

To write an assembly language program to convert binary code to gray code using look up
table approach.

Algorithm:

1. Initialise a memory pointer for the look up table and output datas in hexadecimal.
2. Get ‘n’ data as input.
3. Using XLAT instruction, the binary code is converted to gray code.
4. Store the data in memory location.
5. Terminate the program.

PROGRAM:
title binary to gray

.model small

.data

S1 db 00h, 01h, 03h, 02h, 06h, 07h,05h, 04h, 0Ch, 0Dh,0Eh, 0Fh, 0Ah, 0Bh, 09h, 08h

S2 db ?

.code

main proc near

mov ax,@data

mov ds,ax

mov al,05h

XLAT

mov s2,al

mov ah,4ch

int 21h

main endp

end main

MODEL CALCULATION:

05h= (0101)2

(0101)= binary

Gray=(0110)2 =(07)h

OBSERVATION:
INPUT: 0006:05 OUTPUT: 0010: 07

RESULT:

Thus the assembly language program for binary to gray code conversion was written and
the output was verified.

9.a) MATRIX ADDITION

AIM:

To Write an Assembly Language Program To Perform Matrix Addition

ALGORITHM:

1. Get the data as input.


2. Get the matrix of 2x2.
3. Add the two matrixes.
4. Decrement the count by one.
5. Repeat the step 3 and step 4 till the count is zero.
6. Store the result.
7. Terminate the program.

PROGRAM:

title matrix addition

.model small

.data

mat1 dw 0004h, 0006h, 0008h, 0003h

mat2 dw 0009h, 0007h, 0002h, 0005h


mat3 dw ?

.code

Main proc near

Mov ax,@data

Mov ds,ax

mov cl,04h

lea si,mat1

lea di,mat3

step1: mov ax,[si]

mov bx, [si+0008h]

add ax,bx

mov [di],ax

inc si

inc si

inc di

inc di

dec cl

jnz step1

mov ah,4ch

int 21h

main endp

end main
MATRIX CALCULATION:
[0004 0006] + [0009 0007] = [0D 0D]

[0008 0003] [0002 0005 ] [0A 08]

OBSERVATION:
INPUT: OUTPUT:

0001: 04 0011: 0D

0002: 00 0012: 00

0003: 06 0013: 0D

0004: 00 0014: 00

0005: 08 0015: 0A

0006: 00 0016:00

0007: 03 0017: 08

0008: 00 0018: 00

0009: 09

000A: 00

000B: 07

000C: 00

000D: 02

000E: 00

000F: 05

0010: 00

RESULT:
Thus the assembly language program for matrix addition was written and the output was
verified.

9.b)MATRIX MULTIPLICATION

AIM: To write assembly language program to perform matrix multiplication of 2*2


matrix

ALGORITHM:

1) Get the data input and assigned variable as offset address.

2) Load the memory location of matrix 1 and 2 in SI, DI register respectively.

3) Call the subroutine program

4) Show the output of step3 in variable assiged for output

5) Repeat the 3 & 4 four times to get the product matrix

6) Terminate the program

FOR SUBROUTINE:

1) Initialize the cl register with no of rows of matrix

2) Clear base point register

3) Load an element from matrix 1 & 2 in ax and bx

4) Multiply the content of gpr

5) Add to BP register

6) Increment memory pointer

7) Decrement by 1 and repeat step 3 till 0

8) Return to main program


PROGRAM:

title matrix multiplication

. model small

.data

s1 dw 0001H,0002H,0003H,0004H

s2 dw 0005H,0006H,0007H,0008H

prod1 dw ?

prod2 dw ?

prod3 dw ?

prod4 dw ?

.code

prod proc near

mov cl ,02H

mov BP,0000H

step1: mov ax [si]

mov bx,[di]

mul bx

add BP,ax

inc si

inc si

add di, 0004H

dec cl

jnz step1
ret

prod endp

main proc near

mov ax ,@data

mov ds,ax

lea si,s1

lea di,s2

call prod

mov prod1,BP

sub di,0006H

sub si,0004H

call prod

mov prod3, BP

sub di,0006H

sub si,0004H

call prod

mov prod4,BP

mov ah,4ch

int 21h

main endp

end main
MODEL CALCULATION;

[ 0001h 0002h] [0005h 0006] [0013h 0016h]

[0003h 0004h] * [0007 0008h] = [002B 0032h]

observation

sample input:

0002:01 000A:05

0003:00 000B:00

0004:02 000C:06

0005:00 000D:00

0006:03 000E:07

0007: 00 000F:00

0008:04 0010:08

0009:00

sample o/p:

0011: 00 0015: 00

0012 :13 0016: 2B

0013: 00 0017: 00

0014:16 0018: 32

RESULT: Thus the assembly language for matrix multiplication was written and output
was verified.

10. LCM AND GCD OF 16 BIT NUMBER


AIM: To write an assembly language program to find LCM and GCD of two 16 bit
numbers.

ALGORITHM:

1) Initialize the data

2) Compare the two data

3) Load the value in a register

4) Compare the two data

5) liquide larges no by small no

6) Find the quotient and remainder

7) Compare the data

8) ON zero,jump to step 1

9) meue contents of dx to cx.

10) Jump to step 4

11) Reduce the content of si by 2

12) Multiply the content of bx

13) Divide the content of cx

14) Increase the value of di by 2

15) Terminate the program

PROGRAM:
title LCM and GCD

.model small

.data

S1 dw 0038H,0023H

output dw ?

.code

main proc near

mov ax,@data

mov ds,ax

lea si,s1

lea di,output

mov ax,[si]

inc si

inc si

mov bx,[si]

CMP ax,bx

JZ step1

JNC step2

mov cx,ax

Step4: mov ax,bx

mov bx,cx

mov dx,0000h

Step2: div bx
CMP dx,0000h

JZ step1

Step3: mov cx,dx

JMP step4

Step1:mov [di],bx

mov cx,bx

mov ax,[si]

mov bx,[si-0002H]

mul bx

div cx

mov[di+0002H],ax

mov ah,4CH

int 21H

main endp

end main

Model calculation:

0036H=(56)10

0023H=(35)10

LCM=7*8*5=(280)10=(118)H

GCD=(7)10=(7)H

OBSERVATION:
Sample input: sample output:

0000:38 0004:07

0001:00 0005:00

0002:23 0006:18

0003:00 0007:01

RESULT:

Thus the assembly language programme for LCM and GCD was written and the output
was verified.

11. A) FACTORIAL OF A GIVEN NUMBER

AIM : To write an assembly language program to find the factorial of a given number

ALGORITHM:

Step 1 : Initialize the given pointer for the data

Step 2 : Move the contents of memory pointer to general purpose registers.

Step 3 : Duplicate the contents of general purpose register to B,C registers.

Step 4 : Decrement cl.

Step 5 : Decrement the [B].

Step 6 : Multiply [A] and [B].

Step 7 : Repeat steps from [5] till C becomes zero.

Step 8 : Terminate the program.


PROGRAM:

title factorial

.model small

.data

s1 dw 0005H

s2 dw ?

.code

main proc near

mov ax, @data

mov ds,ax

lea si , s1

lea di, s2

mov ax, [si]

mov cx, ax

mov bx, ax

dec cx

step2 : sub bx, 0001H

JZ step1

mul bx

loop step2

step1 : mov[di], ax

mov ah, 4ch

int 21h
main endp

end main

MODEL CALCULATIONS

Given Number = 5

5! = 5*4*3*2*1

= 120

(120)10 = (78)H

OBSERVATIONS

Sample I/p

0002 : 05

Sample O/p

0003 : 00

0004 : 78

RESULT :

Thus the assembly language program to find the factorial of a given number was written
and the output was verified.

12. B) FIBONACCI SERIES


AIM

To write an assembly language program to find out the Fibonacci series.

ALGORITHM

STEP 1: Load the number upto which Fibonacci series is supposed to be generated.

STEP 2: Initialize registers ax with’0’, bx with ‘1’i.e. the first number of series.

STEP 3: Compare input (7) to 1, if not zero then go to step 2.

STEP 4: Compare 7 with 2, if not zero go to step 2.

STEP 5: Load [di] with ax to increase ‘di’ two times then load [di] with bx.

STEP 6: Add ax,bx.

STEP 7: Decrement ‘cl’ again, compare cx with 2, if not zero then go to step 6.

STEP 8: Terminate the program.

PROGRAM

title Fibonacci series

.model small

.data

S1 db 06h

.code

main proc near

mov ax, @data

mov ds, ax

lea si, s1

mov cl, [si]


inc si

mov al, 01h

mov bl, 00h

dec cl

dec cl

mov [si], bl

inc si

mov [si], al

dec si

step 1: add al, [si]

inc si

inc si

mov [si], al

dec si

dec si

jnz step1

mov ah,4ch

int 21h

main endp

end main

MODEL CALCULATION

STEP 1: 0000

+01
0001

STEP 2: 0001

+01

0002

STEP 3: 0002

+01

0003

STEP 4: 0003

+02

0005

SERIES: 0 1 1 2 3 5

OBSERVATION

0007: 000D:

0008: 000E:

0009: 000F:

000A: 0010:

000B: 0011:

000C: 0012:

RESULT

Thus, the assembly language program for finding the Fibonacci series was written and
output was verified.

You might also like