EEE MPMC Lab Manual
EEE MPMC Lab Manual
AIM:
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
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
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:
ALGORITHM:
Step 1: Take the least significant bit of first and second number as input
Step 3: Take the most significant number of the first and second number as input
PROGRAM:
.model small
.data
S1 dw 1357h
S2 dw 2468h
S3 dw 1011h
S4 dw 0012h
S5 dw ?
S6 dw ?
.code
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
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.
AIM:
ALGORITHM:
Step 1: Take the least significant word of first and second number as input
Step 3: Take the most significant numbers of a first and second number as input
.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
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.
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.
title counting
.model small
.data
S1 dw 0DEF1h
S2 dw ?
.code
mov ax,@data
mov ds,ax
mov ax,s1
mov bl,00h
mov cl,10h
jnc lable
inc bl
mov s2,bl
mov ah,4ch
int 21h
main endp
end main
MODEL CALCUATION
Hexadecimal
E – 1101
F – 1111
D – 1101
1 – 0001
E F D 1
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
ALGORITHM
STEP 1: Get the word for which the swapping has to be done as input.
STEP 4: Decrement the counter by 1 carry time when the shifting is done.
PROGRAM
title swapping
.model small
.data
S1 dw 0AB09h
S2 dw ?
.code
mov ax,@data
mov ds,ax
mov ax,s1
mov cl,08h
loop step1
mov s2,ax
mov ah,4ch
int 21h
main endp
end main
MODEL CALCULATION
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:
ALGORITHM:
PROGRAM:
. model small
. data
s1 dw 0002H,0003H,0004H
count db 03H
s2 dw ?
.code
mov ax,@data
mov ds,ax
mov cl,count
mov dl,cl
lea si,s1
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:
0002h 2
0003h 3
0004h 4
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:
ALGORITHM:
PROGRAM:
.model small
.data
s1 dw 0005H.0003H,0004H
count db 03H
s2 dw ?
. code
mov ax ,@data
mov ds ,ax
lea si,s1
mov cl,count
mov bx,0000H
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:
0005h: 5
0003h: 3
0004h: 4
Quotient = 16
Remainder = 02
(16)d = 10h
(02)d = 02h
OBSERVATION:
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 :
ALGORITHM:
2.Mark the low and higher order nibble by AND instruction using OFH and
OFOH.
PROGRAM:
.model small
.data
S1 db 25H
S2 db ?
S3 db ?
.Code
mov ds,ax
mov al,s1
mov cl,04H
AND al,0F0H
AND bl,0FH
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:
ASCII=( + ) ( + )
Output=
OBSERVERATION:
0005: 0006:
0007:
RESULT:
Thus the assembly language program for BCD to ASCII conversion was
written and output was verified.
AIM:
ALGORITHM:
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.
PROGRAM:
.model small
.stack 64
.data
S1 db 37h,34h
S2 db ?
.code
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
loop lab1
OR al,bl
mov [di],al
mov ah,4ch
int 21h
main endp
end main
MODEL CALCULATION:
37+0f=07h 34+0f=04h
0000 0111
0111 0000
7 0
70+04=74h
OBSERVATION:
0000: 0002:
0001:
RESULT:
Thus the assembly language program for ascii to bcd conversion was written and
the output was verified.
ALGORITHM :
Step 4 : If carry is present , exchange the two numbers so that ax contains the largest
number otherwise go to Step 3.
.model small
.data
s1 dw 0005H,0008H,0003H,0007H
s2 dw ?
.code
mov ds,ax
lea si,s1
lea di,s2
dec cl
step2 : inc si
inc si
step1: dec cl
jnz step 2
mov [di], ax
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.
ALGORITHM :
Step 4 : If carry is present , exchange the two numbers so that ax contains the smallest
number otherwise go to Step 3.
PROGRAM:
.model small
.data
s1 dw 0005H,0008H,0003H,0007H
s2 dw ?
.code
mov ds,ax
lea si,s1
lea di,s2
mov ax , [si]
dec cl
step2 : inc si
inc si
JC step1
mov ax , [si]
step1 : dec cl
JNZ step2
mov [di],ax
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.
AIM:
ALGORITHM:
PROGRAM:
title ascending sort
.model small
.data
S1 dw 0009H,0006H,0003H,0002H,0001H
.code
mov ax,@data
mov ds,ax
mov bl,05h
dec bl
step3:lea si, S1
mov cl,bl
inc si
inc si
JC step1
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.
Algorithm:
PROGRAM:
. model small
.data
S1 dw 0009H,0006H,0003H,0002H,0001H
.code
mov ax,@data
mov ds,ax
mov bl,05h
dec bl
mov cl,bl
step2: mov ax, [si]
inc si
inc si
JNC step1
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.
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
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.
AIM:
ALGORITHM:
PROGRAM:
.model small
.data
.code
Mov ax,@data
Mov ds,ax
mov cl,04h
lea si,mat1
lea di,mat3
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]
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
ALGORITHM:
FOR SUBROUTINE:
5) Add to BP register
. model small
.data
s1 dw 0001H,0002H,0003H,0004H
s2 dw 0005H,0006H,0007H,0008H
prod1 dw ?
prod2 dw ?
prod3 dw ?
prod4 dw ?
.code
mov cl ,02H
mov BP,0000H
mov bx,[di]
mul bx
add BP,ax
inc si
inc si
dec cl
jnz step1
ret
prod endp
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;
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
0013: 00 0017: 00
0014:16 0018: 32
RESULT: Thus the assembly language for matrix multiplication was written and output
was verified.
ALGORITHM:
8) ON zero,jump to step 1
PROGRAM:
title LCM and GCD
.model small
.data
S1 dw 0038H,0023H
output dw ?
.code
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
mov bx,cx
mov dx,0000h
Step2: div bx
CMP dx,0000h
JZ step1
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.
AIM : To write an assembly language program to find the factorial of a given number
ALGORITHM:
title factorial
.model small
.data
s1 dw 0005H
s2 dw ?
.code
mov ds,ax
lea si , s1
lea di, s2
mov cx, ax
mov bx, ax
dec cx
JZ step1
mul bx
loop step2
step1 : mov[di], ax
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.
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 5: Load [di] with ax to increase ‘di’ two times then load [di] with bx.
STEP 7: Decrement ‘cl’ again, compare cx with 2, if not zero then go to step 6.
PROGRAM
.model small
.data
S1 db 06h
.code
mov ds, ax
lea si, s1
dec cl
dec cl
mov [si], bl
inc si
mov [si], al
dec 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.