0% found this document useful (0 votes)
11 views25 pages

8086 Programs

The document outlines a series of experiments involving basic arithmetic operations and data manipulation using the EMU 8086 apparatus. It includes algorithms for addition, subtraction, multiplication, and division of both 8-bit and 16-bit numbers, as well as tasks like finding the largest and smallest numbers in an array, arranging numbers, and string operations. Each experiment is detailed with machine code examples and expected outputs.

Uploaded by

kamleshkc191
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)
11 views25 pages

8086 Programs

The document outlines a series of experiments involving basic arithmetic operations and data manipulation using the EMU 8086 apparatus. It includes algorithms for addition, subtraction, multiplication, and division of both 8-bit and 16-bit numbers, as well as tasks like finding the largest and smallest numbers in an array, arranging numbers, and string operations. Each experiment is detailed with machine code examples and expected outputs.

Uploaded by

kamleshkc191
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/ 25

List of Experiments:

1. Addition of two 8-bit numbers.

2. Addition of two 16-bit numbers.

3. Subtraction of two 16-bit numbers.

4. Multiplication of two numbers.

5. Division of two numbers.

6. Finding out largest number in a given array.

7. Finding out smallest number in a given array.

8. Arrange the given numbers in ascending order.

9. Arrange the given numbers in descending order.

10. Copying strings from source to destination.

11. Fibonacci series of a sequence.

12. Comparison of two strings.

13. Search a string using scan instruction.

14. Factorial of a given number.

15. Addition of two 2X2 matrices.


1. Addition of two 8-bit numbers

Aim: Write an algorithm to perform addition of two 8-bit numbers

Apparatus: EMU 8086

* Using immediate and register addressing modes:

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B0 04 mov al, 04h
[ 2] 0002: B3 08 movbl, 08h
[ 3] 0004: 02 C3 add al, bl
[ 4] 0006: F4 hlt
===============================================================

Output: AX = 000CH

• Using direct and register addressing modes:

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: C6 06 78 05 07 mov [1400], 07h
[ 2] 0005: C6 06 79 05 08 mov [1401], 08h
[ 3] 000A: A0 78 05 mov al, [1400]
[ 4] 000D: 8A 1E 79 05 movbl, [1401]
[ 5] 0011: 02 C3 add al, bl
[ 6] 0013: F4 hlt
===============================================================
Output: AX = 000FH
• Using direct and immediate addressing modes:

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: C6 06 78 05 07 mov [1400], 07h
[ 2] 0005: B3 08 movbl, 08h
[ 3] 0007: 00 1E 78 05 add [1400], bl
[ 4] 000B: A1 78 05 movax, [1400]
[ 5] 000E: F4 hlt

===============================================================

Output: [1400] = 0FH


[1401] = 00H and AX = 000FH

2. Addition of two 16-bit numbers

Aim: Write an algorithm to perform addition of two 16-bit numbers

Apparatus: EMU 8086

* Using immediate and register addressing modes:

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B8 04 10 movax, 1004h
[ 2] 0003: BB 02 10 movbx, 1002h
[ 3] 0006: 03 C3 add ax, bx
[ 4] 0008: F4 hlt
===============================================================

Output: AX = 2006H
• Using direct and register addressing modes:

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================

[ 1] 0000: C6 06 78 05 01 mov [1400], 01h

[ 2] 0005: C6 06 79 05 02 mov [1401], 02h

[ 3] 000A: C6 06 7A 05 02 mov [1402], 02h

[ 4] 000F: C6 06 7B 05 03 mov [1403], 03h

[ 5] 0014: A1 78 05 movax, [1400]

[ 6] 0017: 8B 1E 7A 05 movbx, [1402]

[ 7] 001B: 03 C3 add ax, bx

[ 8] 001D: F4 hlt

===============================================================

Output: AX = 0503H

• Using direct and immediate addressing modes:

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================

[ 1] 0000: C6 06 78 05 01 mov [1400], 01h


[ 2] 0005: C6 06 79 05 02 mov [1401], 02h
[ 3] 000A: C6 06 7A 05 02 mov [1402], 02h
[ 4] 000F: C6 06 7B 05 01 mov [1403], 05h
[ 5] 0014: A1 78 05 movax, [1400]
[ 6] 0017: 03 06 7A 05 add ax, [1402]
[ 7] 001B: A3 7C 05 mov [1404], ax
[ 8] 001E: F4 hlt
===============================================================

Output: [1404] = 03H

[1405] = 07H and AX = 0703H

3. Subtraction of two 16-bit numbers

Aim: Write an algorithm to perform subtraction of two 16-bit numbers

Apparatus: EMU 8086

• Immediate and register addressing modes:

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================

[ 1] 0000: B8 02 00 movax, 0002h

[ 2] 0003: BB 03 00 movbx, 0004h

[ 3] 0006: 2B C3 sub ax, bx

[ 4] 0008: F4 hlt

===============================================================

Output: AX = FFFEH (2’s complement of -2) and SF = 1

• Direct and register addressing modes:


=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================

[ 1] 0000: BE 00 14 movsi, 1400h


[ 2] 0003: C7 06 78 05 02 10 mov [1400], 1002h
[ 3] 0009: C7 06 7A 05 03 10 mov [1402], 1003h
[ 4] 000F: A1 78 05 movax, [1400]
[ 5] 0012: 46 incsi
[ 6] 0013: 46 incsi
[ 7] 0014: 8B CE mov cx, si
[ 8] 0016: 8B 1E 7A 05 movbx, [1402]
[ 9] 001A: 2B C3 subax, bx
[ 10] 001C: F4 hlt
===============================================================

Output: AX = FFFFH and CX = 1402H

4. Multiplication of two numbers

Aim: Write an algorithm to perform multiplication of two numbers

Apparatus: EMU 8086

• Using conventional way 8-bit multiplication

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B0 20 mov al, 20h
[ 2] 0002: A2 78 05 mov [1400], al
[ 3] 0005: B3 20 movbl, 20h
[ 4] 0007: B1 1F mov cl, 1Fh
[ 5] 0009: 03 06 78 05 cc: add ax, [1400]
[ 6] 000D: FE C9 dec cl
[ 7] 000F: 75 F8 jnz cc
[ 8] 0011: F4 hlt
===============================================================
Output: AX = 0400H

• Using conventional way 16-bit multiplication

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B8 01 00 movax, 0005h
[ 2] 0003: A3 78 05 mov [1400], ax
[ 3] 0006: BB 08 00 movbx, 0008h
[ 4] 0009: B9 07 00 mov cx, 0007h
[ 5] 000C: BA 00 00 mov dx, 0000h
[ 6] 000F: 03 06 78 05 cc: add ax, [1400]
[ 7] 0013: 73 01 jnc bb
[ 8] 0015: 42 inc dx
[ 9] 0016: 49 bb: dec cx
[ 10] 0017: 75 F6 jnz cc
[ 11] 0019: F4 hlt
===============================================================

Output: AX = 0028H

• Using multiplication instruction 8-bit multiplication

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B0 02 mov al, 72h
[ 2] 0002: B3 03 movbl, 73h
[ 3] 0004: F6 E3 mulbl
[ 4] 0006: F4 hlt
===============================================================

Output: AX = 3336H

• Using multiplication instruction 16-bit multiplication

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B8 72 70 movax, 7072h
[ 2] 0003: BB 73 70 movbx, 7073h
[ 3] 0006: F7 E3 mulbx
[ 4] 0008: F4 hlt
===============================================================

Output: AX = 6336H and DX = 3164

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B0 02 mov al, 02h (positive number)
[ 2] 0002: B3 93 movbl, 93h (2’s complement of –ve number ‘6D’)
[ 3] 0004: F6 EB imulbl
[ 4] 0006: F4 hlt
===============================================================

Output: AX = FF26H (2’s complement of –ve number ‘DA’)

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B8 6D 8A movax, 8A6Dh (2’s complement of –ve ‘7593’)
[ 2] 0003: BB 45 68 movbx, 6845h (positive number)
[ 3] 0006: F7 EB imulbx
[ 4] 0008: F4 hlt
===============================================================

Output: AX = 9761H , DX = D01CH (2’s complement of –ve number ‘2FE3689F’)

5. Division of two numbers

Aim: Write an algorithm to perform division of two numbers

Apparatus: EMU 8086

• Using conventional way 8-bit division

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B0 20 mov al, 20h
[ 2] 0002: B3 03 movbl, 03h
[ 3] 0004: B1 00 mov cl, 00h
[ 4] 0006: FE C1 loo: inc cl
[ 5] 0008: 3A C3 cmp al, bl
[ 6] 000A: 7C 0A jl loo2
[ 7] 000C: 74 04 je loo1
[ 8] 000E: 2A C3 sub al, bl
[ 9] 0010: 79 F4 jns loo
[ 10] 0012: 2A C3 loo1: sub al, bl
[ 11] 0014: FE C1 inc cl
[ 12] 0016: FE C9 loo2: dec cl
[ 13] 0018: F4 hlt
===============================================================

Output: Quotient: CL = 0AH, Remainder: AL = 02H

• Using conventional way 16-bit division


=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B8 21 01 movax, 0121h
[ 2] 0003: BB 30 00 movbx, 0030h
[ 3] 0006: B9 00 00 mov cx, 0000h
[ 4] 0009: 41 loo: inc cx
[ 5] 000A: 3B C3 cmpax, bx
[ 6] 000C: 7C 09 jl loo2
[ 7] 000E: 74 04 je loo1
[ 8] 0010: 2B C3 sub ax, bx
[ 9] 0012: 79 F5 jns loo
[ 10] 0014: 2B C3 loo1:sub ax, bx
[ 11] 0016: 41 inc cx
[ 12] 0017: 49 loo2: dec cx
[ 13] 0018: F4 hlt
===============================================================

Output: Quotient: CX = 0006H, Reminder: AL = 0001H

• Using division instruction 16-bit division

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B8 0B 00 movax, 000Bh
[ 2] 0003: BB 03 00 movbx, 0003h
[ 3] 0006: F7 F3 div bx
[ 4] 0008: F4 hlt
===============================================================
Output: Quotient: AX = 03H, Reminder: DX = 02H

• Division with –ve number


=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: B8 FA 26 movax, 008Ah
[ 2] 0003: B1 8A mov cl, 8Ah (2’s complement of –ve ‘76’)
[ 3] 0005: F6 F9 idiv cl
[ 4] 0007: F4 hlt
===============================================================

Output: Quotient: AL = FFH (2’s complement of –ve ‘01’),

Reminder: AH = 14H

6. Finding out largest number in a given array

Aim: Find out largest number in a given array and store it in AX register.

Apparatus: EMU 8086

• 8-bit numbers

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
==============================================================
[ 1] 0000: C6 06 C8 00 10 mov [0200], 10h
[ 2] 0005: C6 06 C9 00 00 mov [0201], 00h
[ 3] 000A: C6 06 CA 00 41 mov [0202], 41h
[ 4] 000F: C6 06 CB 00 83 mov [0203], 83h
[ 5] 0014: C6 06 CC 00 58 mov [0204], 58h
[ 6] 0019: C6 06 CD 00 72 mov [0205], 72h
[ 7] 001E: C6 06 CE 00 39 mov [0206], 39h
[ 8] 0023: C6 06 CF 00 46 mov [0207], 46h
[ 9] 0028: C6 06 D0 00 53 mov [0208], 53h
[ 10] 002D: C6 06 D1 00 84 mov [0209], 84h
[ 11] 0032: C6 06 D2 00 30 mov [0210], 30h
[ 12] 0037: C6 06 D3 00 00 mov [0211], 00h
[ 13] 003C: B0 00 mov al, 00h
[ 14] 003E: BE C8 00 movsi, 0200
[ 15] 0041: 8A 0C mov cl, [si]
[ 16] 0043: 46 incsi
[ 17] 0044: 46 back: incsi
[ 18] 0045: 3A 04 cmp al, [si]
[ 19] 0047: 73 02 jae go
[ 20] 0049: 8A 04 mov al, [si]
[ 21] 004B: E2 F7 go: loop back
[ 22] 004D: F4 hlt
==============================================================
Output: AX = 84H

• 16-bit numbers

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: C6 06 C8 00 06 mov [0200],06h
[ 2] 0005: C6 06 C9 00 00 mov [0201],00h
[ 3] 000A: C6 06 CA 00 41 mov [0202],41h
[ 4] 000F: C6 06 CB 00 83 mov [0203],83h
[ 5] 0014: C6 06 CC 00 58 mov [0204],58h
[ 6] 0019: C6 06 CD 00 72 mov [0205],72h
[ 7] 001E: C6 06 CE 00 39 mov [0206],39h
[ 8] 0023: C6 06 CF 00 46 mov [0207],46h
[ 9] 0028: C6 06 D0 00 53 mov [0208],53h
[ 10] 002D: C6 06 D1 00 90 mov [0209],90h
[ 11] 0032: C6 06 D2 00 30 mov [0210],30h
[ 12] 0037: C6 06 D3 00 06 mov [0211],06h
[ 13] 003C: C6 06 D4 00 99 mov [0212],99h
[ 14] 0041: B8 00 41 mov ax,4100h
[ 15] 0044: BE C8 00 mov si,0200
[ 16] 0047: 8A 0C mov cl,[si]
[ 17] 0049: 46 incsi
[ 18] 004A: 46 back:incsi
[ 19] 004B: 46 incsi
[ 20] 004C: 3B 04 cmpax,[si]
[ 21] 004E: 73 02 jae go
[ 22] 0050: 8B 04 movax,[si]
[ 23] 0052: E2 F6 go: loop back
[ 24] 0054: F4 hlt
===============================================================
Output: AX = 9906H

7. Finding out smallest number in a given array

Aim: Find out the smallest number in a given array and store it in AX register.

Apparatus: EMU 8086

• 8-bit numbers

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: C6 06 C8 00 0A mov [0200],0ah
[ 2] 0005: C6 06 C9 00 05 mov [0201],05h
[ 3] 000A: C6 06 CA 00 11 mov [0202],11h
[ 4] 000F: C6 06 CB 00 13 mov [0203],13h
[ 5] 0014: C6 06 CC 00 58 mov [0204],58h
[ 6] 0019: C6 06 CD 00 22 mov [0205],22h
[ 7] 001E: C6 06 CE 00 39 mov [0206],39h
[ 8] 0023: C6 06 CF 00 16 mov [0207],16h
[ 9] 0028: C6 06 D0 00 53 mov [0208],53h
[ 10] 002D: C6 06 D1 00 14 mov [0209],14h
[ 11] 0032: C6 06 D2 00 30 mov [0210],30h
[ 12] 0037: C6 06 D3 00 04 mov [0211],04h
[ 13] 003C: B0 05 mov al,05h
[ 14] 003E: BE C8 00 mov si,0200
[ 15] 0041: 8A 0C mov cl,[si]
[ 16] 0043: 46 incsi
[ 17] 0044: 46 back:incsi
[ 18] 0045: 3A 04 cmp al,[si]
[ 19] 0047: 7C 02 jl go
[ 20] 0049: 8A 04 mov al,[si]
[ 21] 004B: E2 F7 go: loop back
[ 22] 004D: F4 hlt
===============================================================
Output: AX = 04H

• 16-bit numbers

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
===============================================================
[ 1] 0000: C6 06 C8 00 06 mov [0200],06h
[ 2] 0005: C6 06 C9 00 05 mov [0201],05h
[ 3] 000A: C6 06 CA 00 01 mov [0202],01h
[ 4] 000F: C6 06 CB 00 13 mov [0203],13h
[ 5] 0014: C6 06 CC 00 58 mov [0204],58h
[ 6] 0019: C6 06 CD 00 22 mov [0205],22h
[ 7] 001E: C6 06 CE 00 39 mov [0206],39h
[ 8] 0023: C6 06 CF 00 16 mov [0207],16h
[ 9] 0028: C6 06 D0 00 53 mov [0208],53h
[ 10] 002D: C6 06 D1 00 14 mov [0209],14h
[ 11] 0032: C6 06 D2 00 30 mov [0210],30h
[ 12] 0037: C6 06 D3 00 04 mov [0211],04h
[ 13] 003C: C6 06 D4 00 90 mov [0212],90h
[ 14] 0041: B8 05 01 mov ax,0105h
[ 15] 0044: BE C8 00 mov si,0200
[ 16] 0047: 8A 0C mov cl,[si]
[ 17] 0049: 46 incsi
[ 18] 004A: 46 back:incsi
[ 19] 004B: 46 incsi
[ 20] 004C: 3B 04 cmpax,[si]
[ 21] 004E: 76 02 jbe go
[ 22] 0050: 8B 04 movax,[si]
[ 23] 0052: E2 F6 go: loop back
[ 24] 0054: F4 hlt
===============================================================
Output: AX = 0105H

8. Arrange the given numbers in ascending order

Aim: Arrange the given array numbers in ascending order.

Apparatus: EMU 8086

• 8-bit numbers

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: C6 06 C8 00 38 MOV [0200],38h
[ 2] 0005: C6 06 C9 00 47 MOV [0201],47h
[ 3] 000A: C6 06 CA 00 02 MOV [0202],02h
[ 4] 000F: C6 06 CB 00 11 MOV [0203],11h
[ 5] 0014: C6 06 CC 00 29 MOV [0204],29h
[ 6] 0019: C6 06 CD 00 34 mov [0205],34h
[ 7] 001E: B9 05 00 MOV CX,0006h
[ 8] 0021: 49 DEC CX
[ 9] 0022: 8B D1 Again: MOV DX,CX
[ 10] 0024: BE C8 00 MOV SI,0200
[ 11] 0027: 8A 04 Up: MOV AL,[SI]
[ 12] 0029: 46 INC SI
[ 13] 002A: 8A 1C MOV BL,[SI]
[ 14] 002C: 3A C3 CMP AL,BL
[ 15] 002E: 7E 08 JLE Next
[ 16] 0030: 86 C3 XCHG AL,BL
[ 17] 0032: 88 1C MOV [SI],BL
[ 18] 0034: 4E DEC SI
[ 19] 0035: 88 04 MOV [SI],AL
[ 20] 0037: 46 INC SI
[ 21] 0038: 4A Next: DEC DX
[ 22] 0039: 75 EC JNZ Up
[ 23] 003B: 49 DEC CX
[ 24] 003C: 75 E4 JNZ Again
[ 25] 003E: A0 C8 00 mov al,[0200]
[ 26] 0041: 8A 26 C9 00 mov ah,[0201]
[ 27] 0045: 8A 1E CA 00 movbl,[0202]
[ 28] 0049: 8A 3E CB 00 movbh,[0203]
[ 29] 004D: 8A 0E CC 00 mov cl,[0204]
[ 30] 0051: F4 hlt
=================================================================

Output: AL = 02H AH = 11H BL = 29H


BH = 34H CL = 38H

Note: The elements in ascending order are stored in memory as follows:


[0200] = 02H

[0201] = 11H

[0202] = 29H

[0203] = 34H

[0204] = 38H

[0205] = 47H

9. Arrange the given numbers in Descending order


Aim: Arrange the given array numbers in descending order.

Apparatus: EMU 8086

• 8-bit numbers

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: C6 06 C8 00 38 MOV [0200],38h
[ 2] 0005: C6 06 C9 00 47 MOV [0201],47h
[ 3] 000A: C6 06 CA 00 02 MOV [0202],02h
[ 4] 000F: C6 06 CB 00 11 MOV [0203],11h
[ 5] 0014: C6 06 CC 00 29 MOV [0204],29h
[ 6] 0019: C6 06 CD 00 34 mov [0205],34h
[ 7] 001E: B9 05 00 MOV CX,0006h
[ 8] 0021: 49 DEC CX
[ 9] 0022: 8B D1 Again: MOV DX,CX
[ 10] 0024: BE C8 00 MOV SI,0200
[ 11] 0027: 8A 04 Up: MOV AL,[SI]
[ 12] 0029: 46 INC SI
[ 13] 002A: 8A 1C MOV BL,[SI]
[ 14] 002C: 3A C3 CMP AL,BL
[ 15] 002E: 7D 08 JGE Next
[ 16] 0030: 86 C3 XCHG AL,BL
[ 17] 0032: 88 1C MOV [SI],BL
[ 18] 0034: 4E DEC SI
[ 19] 0035: 88 04 MOV [SI],AL
[ 20] 0037: 46 INC SI
[ 21] 0038: 4A Next: DEC DX
[ 22] 0039: 75 EC JNZ Up
[ 23] 003B: 49 DEC CX
[ 24] 003C: 75 E4 JNZ Again
[ 25] 003E: A0 C8 00 mov al,[0200]
[ 26] 0041: 8A 26 C9 00 mov ah,[0201]
[ 27] 0045: 8A 1E CA 00 movbl,[0202]
[ 28] 0049: 8A 3E CB 00 movbh,[0203]
[ 29] 004D: 8A 0E CC 00 mov cl,[0204]
[ 30] 0051: F4 hlt
=================================================================
Output: AL = 47H AH = 38H BL = 34H
BH = 29H CL = 11H

Note: The elements in ascending order are stored in memory as follows:


[0200] = 47H

[0201] = 38H

[0202] = 34H

[0203] = 29H

[0204] = 11H

[0205] = 02H

10. Copying strings from source to destination.

Aim: Write an algorithm for copying strings from source memory to destination memory.

Apparatus: EMU 8086

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: C6 06 C8 00 05 mov [0200],05h
[ 2] 0005: C6 06 C9 00 01 mov [0201],01h
[ 3] 000A: C6 06 CA 00 04 mov [0202],04h
[ 4] 000F: C6 06 CB 00 02 mov [0203],02h
[ 5] 0014: C6 06 CC 00 10 mov [0204],10h
[ 6] 0019: C6 06 CD 00 15 mov [0205],15h
[ 7] 001E: C6 06 CE 00 25 mov [0206],25h
[ 8] 0023: FC cld
[ 9] 0024: BE C8 00 mov si,0200
[ 10] 0027: BF 2C 01 mov di,0300
[ 11] 002A: 8A 0C mov cl,[si]
[ 12] 002C: 46 incsi
[ 13] 002D: A4 back:movsb
[ 14] 002E: E2 FD loop back
[ 15] 0030: A0 2C 01 mov al,[0300]
[ 16] 0033: 8A 1E 2D 01 movbl,[0301]
[ 17] 0037: 8A 0E 2E 01 mov cl,[0302]
[ 18] 003B: F4 hlt
=================================================================
Output: AX = 01H, BX = 04H, CX = 02H.

Note: The elements in ascending order are stored in memory as follows:


[0300] = 01H

[0301] = 04H

[0302] = 02H

[0303] = 10H

[0304] = 15H

[0305] = 25H

11. Fibonacci series of a sequence

Aim: Write an algorithm to find out the Fibonacci series of a given sequence.

Apparatus: EMU 8086

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: B1 06 MOV CL,06
[ 2] 0002: BE B8 0B MOV SI,3000
[ 3] 0005: B0 00 MOV AL,00
[ 4] 0007: 88 04 MOV [SI],AL
[ 5] 0009: 46 INC SI
[ 6] 000A: B3 01 MOV BL,01
[ 7] 000C: 88 1C MOV [SI],BL
[ 8] 000E: 02 C3 L1:ADD AL,BL
[ 9] 0010: 8A D0 MOV DL,AL
[ 10] 0012: 46 INC SI
[ 11] 0013: 88 14 MOV [SI],DL
[ 12] 0015: 8A C3 MOV AL,BL
[ 13] 0017: 8A DA MOV BL,DL
[ 14] 0019: E2 F3 LOOP L1
[ 15] 001B: F4 hlt
=================================================================

Output: AX = 08H [Last two numbers in the sequence]


DX = 0DH

Note: The content stored in memory is as follows

[3000] = 00H
[3001] = 01H
[3002] = 02H
[3003] = 03H
[3004] = 05H
[3005] = 08H
[3006] = 0DH

12. Comparison of two strings


Aim: Write an algorithm to compare two strings using “REP” instruction.

Apparatus: EMU 8086

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: C6 06 E8 03 01 mov [1000], 01h
[ 2] 0005: C6 06 E9 03 02 mov [1001], 02h
[ 3] 000A: C6 06 EA 03 03 mov [1002], 03h
[ 4] 000F: C6 06 EB 03 04 mov [1003], 04h
[ 5] 0014: C6 06 D0 07 01 mov [2000], 01h
[ 6] 0019: C6 06 D1 07 02 mov [2001], 02h
[ 7] 001E: C6 06 D2 07 03 mov [2002], 03h
[ 8] 0023: C6 06 D3 07 04 mov [2003], 04h
[ 9] 0028: BE E8 03 MOV SI,1000
[ 10] 002B: BF D0 07 MOV DI,2000
[ 11] 002E: B9 04 00 MOV CX,0004
[ 12] 0031: FC CLD
[ 13] 0032: F3 A6 REP CMPSB
[ 14] 0034: 74 00 JE Last
[ 15] 0036: B3 0F last:mov bl,0FH
[ 16] 0038: F4 hlt
=================================================================
Output: BX = 0FH , CX = 00H

Note: The REP instruction repeats the corresponding loop until the condition mentioned it’s below is
satisfied. It will come out of the loop if the condition is satisfied.

================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: C6 06 E8 03 01 mov [1000], 01h
[ 2] 0005: C6 06 E9 03 02 mov [1001], 02h
[ 3] 000A: C6 06 EA 03 03 mov [1002], 03h
[ 4] 000F: C6 06 EB 03 04 mov [1003], 04h
[ 5] 0014: C6 06 D0 07 01 mov [2000], 01h
[ 6] 0019: C6 06 D1 07 02 mov [2001], 02h
[ 7] 001E: C6 06 D2 07 00 mov [2002], 00h
[ 8] 0023: C6 06 D3 07 04 mov [2003], 04h
[ 9] 0028: BE E8 03 MOV SI,1000
[ 10] 002B: BF D0 07 MOV DI,2000
[ 11] 002E: B9 04 00 MOV CX,0004
[ 12] 0031: FC CLD
[ 13] 0032: F3 A6 REP CMPSB
[ 14] 0034: 74 00 JE Last
[ 15] 0036: B3 0F last:mov bl,0FH
[ 16] 0038: F4 hlt
=================================================================
Output: BX = 0FH , CX = 01H

13. Search a string using scan instruction

Aim: Write an algorithm to perform searching a string using “SCAN” instruction.

Apparatus: EMU 8086

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: C6 06 70 17 01 mov [6000],01H
[ 2] 0005: C6 06 71 17 06 mov [6001],06H
[ 3] 000A: C6 06 72 17 09 mov [6002],09H
[ 4] 000F: C6 06 73 17 11 mov [6003],11H
[ 5] 0014: C6 06 74 17 21 mov [6004],21H
[ 6] 0019: C6 06 75 17 27 mov [6005],27H
[ 7] 001E: C6 06 76 17 04 mov [6006],04H
[ 8] 0023: C6 06 77 17 19 mov [6007],19H
[ 9] 0028: C6 06 78 17 0E mov [6008],0EH
[ 10] 002D: C6 06 79 17 8E mov [6009],8EH
[ 11] 0032: BF 70 17 MOV DI, 6000
[ 12] 0035: B1 09 MOV CL, 09
[ 13] 0037: B0 09 MOV AL, 09H
[ 14] 0039: FC CLD
[ 15] 003A: F2 REPNZ
[ 16] 003B: AE SCASB
[ 17] 003C: F4 hlt
=================================================================
Output: CX = 06H:

Note: The number in AL is identified at position “input CX – output CX”


i. e., 09H-06H = 03H position from starting.

14. Factorial of a given number

Aim: Write an algorithm to find out factorial of a given number

Apparatus: EMU 8086

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================
[ 1] 0000: B8 06 00 MOV Ax, 0006H
[ 2] 0003: 33 C9 xorcx,cx
[ 3] 0005: 8B C8 MOV Cx, ax
[ 4] 0007: 83 F9 01 Back: cmp cx,01h
[ 5] 000A: 74 05 jzll
[ 6] 000C: 49 DEC Cx
[ 7] 000D: F7 E1 MUL Cx
[ 8] 000F: 75 F6 jnz back
[ 9] 0011: F4 ll: HLT
=================================================================
Output: AX = 02D0H
15. Addition of two 2X2 matrices

Aim: Write an algorithm to perform addition of two 2X2 matrices.

Apparatus: EMU 8086

=================================================================
[LINE] LOC: MACHINE CODE SOURCE
=================================================================

[ 1] 0000: C6 06 E8 03 01 mov [1000],01H


[ 2] 0005: C6 06 E9 03 01 mov [1001],01H
[ 3] 000A: C6 06 EA 03 01 mov [1002],01H
[ 4] 000F: C6 06 EB 03 01 mov [1003],01H
[ 5] 0014: C6 06 D0 07 01 mov [2000],01H
[ 6] 0019: C6 06 D1 07 01 mov [2001],01H
[ 7] 001E: C6 06 D2 07 01 mov [2002],01H
[ 8] 0023: C6 06 D3 07 02 mov [2003],01H
[ 9] 0028: B1 04 mov cl,04h
[ 10] 002A: BE 00 10 mov si,1000h
[ 11] 002D: BF 00 20 mov di,2000h
[ 12] 0030: 8A 04 back: mov al,[SI]
[ 13] 0032: 8A 1D movbl,[DI]
[ 14] 0034: 02 C3 add al,bl
[ 15] 0036: 88 05 mov [DI],al
[ 16] 0038: 46 incsi
[ 17] 0039: 47 inc di
[ 18] 003A: E2 F4 loop back
[ 19] 003C: A0 D0 07 mov al,[2000]
[ 20] 003F: 8A 26 D1 07 mov ah,[2001]
[ 21] 0043: 8A 1E D2 07 movbl,[2002]
[ 22] 0047: 8A 3E D3 07 movbh,[2003]
[ 23] 004B: F4 hlt
================================================================
Output: AL = 02H AH = 02H
BL = 02H BH = 02H

You might also like