119
Naveen.H,Lecturer 1 ADVANCED MICROPROCESSOR LAB (06ECL68) Lab Manual By Naveen.H Department of Electronics and Communication M.S.Engineering College Bangalore-562110

ADVANCED MICROPROCESSOR LAB · ADVANCED MICROPROCESSOR LAB ... b) Seven segment display interface c) ... Addition and subtraction of multipression numbers. 1. ALP to add two 8bit

Embed Size (px)

Citation preview

Naveen.H,Lecturer

1

ADVANCED

MICROPROCESSOR LAB

(06ECL68)

Lab Manual

By

Naveen.H

Department of Electronics and Communication

M.S.Engineering College

Bangalore-562110

Naveen.H,Lecturer

2

SYALLABUS

Programs involving

1) Data transfer instructions like:

i] Byte and word data transfer in different addressing modes.

ii] Block move (with and without overlap)

iii] Block interchange

2) Arithmetic & logical operations like:

i] Addition and Subtraction of multi precision nos.

ii] Multiplication and Division of signed and unsigned Hexadecimal nos.

iii] ASCII adjustment instructions

iv] Code conversions

v] Arithmetic programs to find square cube, LCM, GCD, factorial

3) Bit manipulation instructions like checking:

i] Whether given data is positive or negative

ii] Whether given data is odd or even

iii] Logical 1’s and 0’s in a given data

iv] 2 out 5 code

v] Bit wise and nibble wise palindrome

4) Branch/Loop instructions like:

i] Arrays: addition/subtraction of N nos.

Finding largest and smallest nos.

Ascending and descending order

ii] Near and Far Conditional and Unconditional jumps, Calls and Return

5) Programs on String manipulation like string transfer, string reversing, searching

for a string, etc.

Naveen.H,Lecturer

3

6) Programs involving Software interrupts

Programs to use DOS interrupt INT 21h Function calls for Reading a Character

from keyboard, Buffered Keyboard input, Display of character/ String on console

II) Experiments on interfacing 8086 with the following interfacing modules through DIO

(Digital Input/Output-PCI bus compatible) card

a) Matrix keyboard interfacing

b) Seven segment display interface

c) Logical controller interface

d) Stepper motor interface

III) Other Interfacing Programs

a) Interfacing a printer to an X86 microcomputer

b) PC to PC Communication

Naveen.H,Lecturer

4

CONTENTS

1. Programs involving data transfer instruction

1. ALP to transfer a word data in different addressing modes.

2. ALP to transfer a byte data in different addressing modes.

3. ALP to transfer a block of data byte from one memory location to another without overlap.

4. ALP to transfer a block of data word from one memory location to another without overlap.

5. a. ALP to transfer a block of data byte from one memory location to another with overlap.

b. ALP to transfer a block of data byte from one memory location to another with overlap

6. ALP to transfer a block of data word from one memory location to another with overlap.

7. ALP to Interchange a block of data from one memory location to another without using

‘XCHG’ instruction.

8. ALP to Interchange a block of data from one memory location to another by using ‘XCHG’

instruction.

9. (*) ALP for left shifting of data without overlap

10. (*)ALP for right shifting of data without overlap

2. Programs Involving Arithmetic operation

Addition and subtraction of multipression numbers.

1. ALP to add two 8bit numbers

2. a) ALP to add two 16bit numbers by word ptr

b) ALP to add two 16bit numbers by using loop

3. a) ALP to add two 32bit numbers

b) ALP to add two 32 bit numbers using word ptr

4. a) ALP to add two 64bit numbers

b) ALP to add two 64 bit numbers using word ptr

5. (*) ALP to add two 128bit numbers

Naveen.H,Lecturer

5

6. ALP to sub two 8bit numbers

7. a ) ALP to sub two 16bit numbers word ptr.

b)ALP to sub two 16bit numbers using loop

8. a) ALP to sub two 32bit numbers

b) ALP to sub two 32bit numbers using word ptr

9. a) ALP to sub two 64 bit numbers

b) ALP to sub two 64bit numbers using word ptr

10(*) ALP to sub two 128 bit numbers

Multiplication and Division of signed and unsigned hexadecimal numbers

1. ALP to multiply two 8bit unsigned numbers.

2. ALP to multiply 8bit signed number and 8bit unsigned number.

3. ALP to multiply two 8bit signed numbers .

4. ALP to multiply two 16bit unsigned numbers

5. ALP to multiply two 16bit signed numbers

6. ALP to multiply 16bit unsigned number and 16bit signed number

7. ALP to Divide two 8bit unsigned numbers

8. ALP to Divide two 8bit signed numbers

9. ALP to Divide 16bit signed number by 8bit unsigned number.

10. ALP to divide 16bit signed number by 8bit signed number.

11. ALP to divide 32bit number by 16bit number

ASCII Adjustment Instructions.

1.ALP using AAA instruction.

2.ALP using AAS instruction.

Naveen.H,Lecturer

6

3.ALP using AAM instruction.

4. ALP using AAD instruction.

Code Conversions

1. ALP to convert binary to Ascii number.

2. a) ALP to Convert Ascii to binary number.

b(*)ALP to Convert Ascii to Hex number.

3. ALP to Convert BCD to binary number.

4. a) ALP to Convert Binary to BCD number(only 8bit).

b) ALP to Convert Binary to BCD number(16bit/8bit).

Arithmetic programs to find

1. ALP to find Square of a given number

2. ALP to find cube of a given number

3. ALP to find LCM of a given number

4. ALP to find GCD of a given number

5. ALP to factorial of a given number

3 Bit manipulation instructions.

1. ALP to find Whether given data is positive or negative

2. ALP to find Whether given data is odd or even

3. ALP to find Logical 1’s and 0’s in a given data

4. ALP to find 2 out 5 code.

5. ALP to find the given number is Bit wise palindrome or not

Naveen.H,Lecturer

7

6.a) ALP to find the given number is nibble wise palindrome or not.

b) ALP to find the given data byteis nibble wise palindrome or not.

4 Branch/Loop instructions like.

1. ALP to add N numbers of data in an array and display result on screen

2. ALP to Sub N numbers of data in an array and display result on screen 3. ALP to Find average of N numbers in an array and display result on screen

4. ALP to Find the largest number in an array and display result on screen

5. ALP to find the smallest number in an array and display result on screen

6. ALP to sort the numbers in ascending order in an array using insertion sort

technique

7. ALP to sort the numbers in Descending order in an array using insertion sort technique.

5.Programs on String manipulation.

1.ALP to transfer a String from one location to another location.

2. ALP reverse a given String.

3. ALP to Search a Character in a given string

4 ALP to Check weather a given string is Palindrome or not.

6. Programs involving Software interrupts.

1.ALP To read a Character from the Keyboard.

2.ALP to read a Character from the keyboard with buffered input

3.ALP to display a character on console

4. ALP to display a string on console.

All dos programs in one

5.(*) ALP to Create a new file

6(*) ALP to read a new file.

Naveen.H,Lecturer

8

II) Experiments on interfacing 8086 with the following interfacing modules through DIO (Digital Input/Output-

PCI bus compatible) card

1. ALP To interface Matrix keyboard to 8086 through 8255

2. ALP to interface Logical controller to 8086 through 8255.

a) ALP to interface Logical Controller for not gate to 8086 through 8255

b) ALP to interface Logical Controller for and gate to 8086 through 8255

c) ALP to interface Logical Controller for or gate to 8086 through 8255

d) ALP to interface Logical Controller for xor gate to 8086 through 8255

e) ALP tointerface Logical Controller for xnor gate to 8086 through 8255

f) ALP to interface Logical Controller for nor gate to 8086 through 8255

g)ALP tointerface Logical Controller for nand gate to 8086 through 8255

3. ALP to interface Stepper motor to 8086 through 8255.

a) ALP to interface Stepper motor in clockwise direction to 8086 through 8255.

b) ALP to interface Stepper motor in anticlockwise direction to 8086 through 8255.

c) ALP to interface Stepper motor 90 degree in clockwise and 180 in anticlockwise to 8086 through 8255.

4. ALP to interface Seven segment display to 8086 through 8255

a) ALP to display a message using Seven segment display to 8086 through 8255

b) ALP to display a moving message using Seven segment display to 8086 through 8255

Naveen.H,Lecturer

9

Naveen.H,Lecturer

10

8086 Instruction Set Summary

The following is a brief summary of the 8086 instruction set:

Data Transfer Instructions

MOV Move byte or word to register or memory

IN, OUT Input byte or word from port, output word to port

LEA Load effective address

LDS, LES Load pointer using data segment, extra segment

PUSH, POP Push word onto stack, pop word off stack

XCHG Exchange byte or word

XLAT Translate byte using look-up table

Logical Instructions

NOT Logical NOT of byte or word (one's complement)

AND Logical AND of byte or word

OR Logical OR of byte or word

XOR Logical exclusive-OR of byte or word

TEST Test byte or word (AND without storing)

Shift and Rotate Instructions

SHL, SHR Logical shift left, right byte or word by 1 or CL

SAL, SAR Arithmetic shift left, right byte or word by 1 or CL

ROL, ROR Rotate left, right byte or word by 1 or CL

RCL, RCR Rotate left, right through carry byte or word by 1 or CL

Naveen.H,Lecturer

11

Arithmetic Instructions

ADD, SUB Add, subtract byte or word

ADC, SBB Add, subtract byte or word and carry (borrow)

INC, DEC Increment, decrement byte or word

NEG Negate byte or word (two's complement)

CMP Compare byte or word (subtract without storing)

MUL, DIV Multiply, divide byte or word (unsigned)

IMUL, IDIV Integer multiply, divide byte or word (signed)

CBW, CWD Convert byte to word, word to double word (useful

before multiply/divide)

AAA, AAS, AAM, AAD ASCII adjust for addition, subtraction, multiplication,

division (ASCII codes 30-39)

DAA, DAS Decimal adjust for addition, subtraction (binary coded

decimal numbers)

Transfer Instructions

JMP Unconditional jump

JA (JNBE) Jump if above (not below or equal)

JAE (JNB) Jump if above or equal (not below)

JB (JNAE) Jump if below (not above or equal)

JBE (JNA) Jump if below or equal (not above)

JE (JZ) Jump if equal (zero)

JG (JNLE) Jump if greater (not less or equal)

JGE (JNL) Jump if greater or equal (not less)

JL (JNGE) Jump if less (not greater nor equal)

JLE (JNG) Jump if less or equal (not greater)

JC, JNC Jump if carry set, carry not set

Naveen.H,Lecturer

12

JO, JNO Jump if overflow, no overflow

JS, JNS Jump if sign, no sign

JNP (JPO) Jump if no parity (parity odd)

JP (JPE) Jump if parity (parity even)

LOOP Loop unconditional, count in CX

LOOPE (LOOPZ) Loop if equal (zero), count in CX

LOOPNE (LOOPNZ) Loop if not equal (not zero), count in CX

JCXZ Jump if CX equals zero

Subroutine and Interrupt Instructions

CALL, RET Call, return from procedure

INT, INTO Software interrupt, interrupt if overflow

IRET Return from interrupt

String Instructions

MOVS Move byte or word string

MOVSB, MOVSW Move byte, word string

CMPS Compare byte or word string

SCAS Scan byte or word string

LODS, STOS Load, store byte or word string

REP Repeat

REPE, REPZ Repeat while equal, zero

REPNE, REPNZ Repeat while not equal (zero)

Processor Control Instructions

STC, CLC, CMC Set, clear, complement carry flag

STD, CLD Set, clear direction flag

STI, CLI Set, clear interrupt enable flag

Naveen.H,Lecturer

13

LAHF, SAHF Load AH from flags, store AH into flags

PUSHF, POPF Push flags onto stack, pop flags off stack

ESC Escape to external processor interface

LOCK Lock bus during next instruction

NOP No operation (do nothing)

WAIT Wait for signal on TEST input

HLT Halt processor

DOS INT 21h - DOS Function Codes

Naveen.H,Lecturer

14

ASSEMBLING AND EXECUTING THE PROGRAM

Writing an ALP

Assembly level programs generally abbreviated as ALP are written in text editor EDIT.

Type EDIT in front of the command prompt to open an untitled text file.

EDIT<file name> After typing the program save the file with appropriate file name

with an extension .ASM

Ex: Add.ASM

Assembling an ALP

To assemble an ALP we needed executable file called MASM.EXE. Only if this file is in

current working directory we can assemble the program.

The command is MASM<filename.ASM> If the program is free from all syntactical

errors, this command will give the OBJECT file.

In case of errors it list out the number of errors, warnings and kind of error.

Note:No object file is created until all errors are rectified.

Linking

After successful assembling of the program we have to link it to get Executable file.

The command is LINK<File name.OBJ> This command results in <Filename.exe>

which can be executed in front of the command prompt.

Executing the Program

Open the program in debugger by the command(note only exe files can be open)by the

command. CV <Filename.exe> This will open the program in debugger screen where in

you can view the assemble code with the CS and IP values at the left most side and the

machine code.

Register content ,memory content also be viewed using VIEW option of the debugger.

Execute option in the menu in the menu can be used to execute the program either in

single steps(F8) or burst execution(F5).

Naveen.H,Lecturer

15

1. copy entire masm file to drive C:

2. go to start

3. press run

4. open CMD

5. if some other folder... remove those folders using cd..

Ex. H:\ documents and settings\master> cd..

H:\ documents and settings> cd..

H:\>

6. then enter the directory to which you have stored masm file as shown below

H:\> C:

C:\>

7. to open the masm file enter as shown below

C:\> cd masm

C:\masm>

8. to edit your program

C:\masm>edit 1.asm

9.after typing save and exit

10.to convert to .obj file

C:\masm>masm 1.asm

[1.obj] is created

checks for errors

11. to convert to .exe file

C:\masm>link 1.obj

[1.exe] is created

12.To debug

C:\masm>td 1.exe

Naveen.H,Lecturer

16

13. will get 8086 CPU

14. use Breakpoint at the last instruction of program

15. for step by step execution press F8

for full execution press F9

to see result on the dos screen press alt+f5 or go to windows,press user screen

16. view results using DUMP(DS segment) or through dos screen

17. Write down the result for before execution and after excution from DS segment

18. for Bit manupulation progrmms, check for different cases.

Naveen.H,Lecturer

17

1. Programs involving data transfer instruction

1. ALP to transfer a word data in different addressing modes.

Filename:wdadd.asm

Program is tested and found ok

.model small

.stack[100]

.data

num dw 4321h

.code

Mov ax,@data

Mov ds,ax

mov dx,2222h

Mov ax,1234h ;immediate addressing

Mov bx,ax ;register addressing

Mov ax,num ;direct addressing

Mov si,1000h

mov [si],bl

Mov al,[si] ;indirect addressing

mov [si+100h],dl

Mov bl,[si+100h] ;relative addressing

Mov bx,1000h

mov [si+bx],3333h

Mov ax,[si+bx] ;base index addressing

mov [si+bx+100h],4444h

Mov cx,[si+bx+100h] ;relative base index addressing

Mov ah,4ch

Int 21h

End

2. ALP to transfer a byte data in different addressing modes.

Naveen.H,Lecturer

18

Filename:bdadd.asm

Program is tested and found ok

.model small

.stack[100]

.data

num db 21h

.code

Mov ax,@data

Mov ds,ax

mov dl,22h

Mov al,12h ;immediate addressing

Mov bl,al ;register addressing

Mov al,num ;direct addressing

Mov si,1000h

mov [si],bl

Mov al,[si] ;indirect addressing

mov [si+100h],dl

Mov bl,[si+100h] ;relative addressing

Mov bx,1000h

mov [si+bx],33h

Mov al,[si+bx] ;base index addressing

mov [si+bx+100h],44h

Mov cl,[si+bx+100h] ;relative base index addressing

Mov ah,4ch

Int 21h

End

3. ALP to transfer a block of data byte from one memory location to another

without overlap.

Naveen.H,Lecturer

19

Filename:bdtwo.asm

Program is tested and found ok

.model small

.stack[100]

.data

n1 db 11h,12h,13h,14h,15h

n2 db 5 dup(0)

.code

mov ax,@data

mov ds,ax

mov cx,04h

lea si,n1

lea di,n2

loc: mov dl,[si]

mov [di],dl

inc si

inc di

dec cx

jnz loc

mov ah,4ch

int 21h

end

4. ALP to transfer a block of data word from one memory location to another

without overlap.

Naveen.H,Lecturer

20

Filename:wdtwo.asm

Program is tested and found ok

.model small

.stack[100]

.data

n1 dw 1111h,1112h,1223h,1224h,1225h,3456h,5678h,4444h

n2 dw 8 dup(0)

.code

mov ax,@data

mov ds,ax

mov cx,08h

lea si,n1

lea di,n

loc: mov dx,[si]

mov [di],dx

inc si

inc si

inc di

inc di

dec cx

jnz loc

mov ah,4ch

int 21h

end

5. a. ALP to transfer a block of data byte from one memory location to another

with overlap.

Naveen.H,Lecturer

21

Filename:bdtw.asm

Program is tested and found ok

.model small

.stack[100]

.data

n2 db 3 dup(0)

n1 db 11h,12h,13h,14h,15h

.code

mov ax,@data

mov ds,ax

mov cx,05h

lea si,n1

lea di,n2

loc: mov dl,[si]

mov [di],dl

inc si

inc di

dec cx

jnz loc

mov ah,4ch

int 21h

end

b. ALP to transfer a block of data byte from one memory location to another with

overlap

Naveen.H,Lecturer

22

Filename:bdtw1.asm

Program is tested and found ok

.model small

.stack[100]

.data

n1 db 11h,12h,13h,14h,15h

n2 db 16h,17h,18h,19h,20h

.code

mov ax,@data

mov ds,ax

mov cx,05h

lea si,n1

lea di,n2

loc: mov dl,[si+4]

mov [di],dl

dec si

dec di

dec cx

jnz loc

mov ah,4ch

int 21h

end

6 ALP to transfer a block of data word from one memory location to another with

overlap.

Naveen.H,Lecturer

23

Filename:wdtw.asm

Program is tested and found ok

.model small

.stack[100]

.data

n2 dw 5 dup(0)

n1 dw 1111h,1112h,1223h,1224h,1225h,3456h,5678h,4444h

.code

mov ax,@data

mov ds,ax

mov cx,08h

lea si,n1

lea di,n2

loc: mov dx,[si]

mov [di],dx

inc si

inc si

inc di

inc di

dec cx

jnz loc

mov ah,4ch

int 21h

end

7. Interchange a block of data from one memory location to another without

using ‘XCHG’ instruction.

Filename:exch1.asm

Naveen.H,Lecturer

24

Program is tested and found ok

.model small

.stack 256

.data

n1 db 11h,12h,13h,14h,15h

n2 db 22h,33h,44h,55h,66h

.code

mov ax,@data

mov ds,ax

mov cx,05h

lea si,n1

lea di,n2

loc : mov al,[si]

mov bl,[di]

mov [di],al

mov [si],bl

inc si

inc di

dec cx

jnz loc

mov ah,4ch

int 21h

end

8. ALP to Interchange a block of data from one memory location to another by

using ‘XCHG’ instruction.

Filename:exch.asm

Naveen.H,Lecturer

25

Program is tested and found ok

.model small

.stack 256

.data

n1 db 11h,12h,13h,14h,15h

n2 db 22h,33h,44h,55h,66h

.code

mov ax,@data

mov ds,ax

mov cx,05h

lea si,n1

lea di,n2

loc : mov dl,[si]

xchg [di],dl

mov [si],dl

inc si

inc di

dec cx

jnz loc

mov ah,4ch

int 21h

end

9(*) Alp for left shifting of data without overlap

Filename:ls.asm

Program is tested and found ok

Naveen.H,Lecturer

26

.model small

.stack[100]

.data

n2 db 5 dup(0)

n1 db 11h,12h,13h,14h,15h

.code

mov ax,@data

mov ds,ax

mov cx,05h

lea si,n1

lea di,n2

loc: mov dl,[si]

mov [di],dl

inc si

inc di

dec cx

jnz loc

mov ah,4ch

int 21h

end

10(*)ALP for right shifting of data without overlap

Filename:rs.asm

Program is tested and found ok

Naveen.H,Lecturer

27

.model small

.stack[100]

.data

src db 11h,12h,13h,14h,15h

.code

mov ax,@data

mov ds,ax

mov cx,05h

lea si,src

lea di,src+5

loc: mov dl,[si+4]

mov [di],dl

dec si

dec di

dec cx

jnz loc

mov ah,4ch

int 21h

end

2. Programs Involving Arithmetic operation

Addition and subtraction of Multipression numbers.

10. Write an ALP to add two 8bit numbers

Naveen.H,Lecturer

28

Filename:8adc.asm

Program is tested and found ok

.model small

.stack [256]

.data

n1 db 12h,13h

result db(0)

carry db(0)

.code

mov ax,@data

mov ds,ax

mov al,n1

add al,n1+1

mov result,al

adc carry,00h

mov ah,4ch

int 21h

11. a) Write an ALP to add two 16bit numbers

Filename:16add1.asm

.model small

.data

n1 dd 0aaaah

n2 dd 9999h

result dd(0)

carry db(0)

.code

mov ax,@data

mov ds,ax

mov ax,word ptr n1

mov bx,word ptr n2

clc

add ax,bx

mov word ptr result,ax

adc carry,00h

mov ah,4ch

int 21h

end

b)

Filename:16addl.asm

.model small

.data

Naveen.H,Lecturer

29

d1 dw 9999h

d2 dw 0aaaah

d3 db 3 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+3

mov cx,04h

mov dl,00h

clc

up:mov al,[si]

adc al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

inc dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

12. a) Write an ALP to add two 32bit numbers

Filename:32add.asm

.model small

.data

Naveen.H,Lecturer

30

d1 dd 99999999h

d2 dd 0aaaaaaaah

d3 db 11 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+5

mov cx,04h

mov dl,00h

clc

up:mov al,[si]

adc al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

inc dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

b) Write an ALP to add two 32 bit numbers using word ptr

Filename:32add1.asm

.model small

Naveen.H,Lecturer

31

.stack

.data

n1 dd 0f2222222h

n2 dd 33333333h

result dd(0)

carry db(0)

.code

mov ax,@data

mov ds,ax

mov ax,word ptr n1

mov bx,word ptr n2

clc

add ax,bx

mov bx,word ptr n1+2

mov cx,word ptr n2+2

adc bx,cx

mov word ptr result+2,bx

mov word ptr result,ax

adc carry,00h

mov ah,4ch

int 21h

end

13. a) Write an ALP to add two 64bit numbers

Filename:64add.asm

Naveen.H,Lecturer

32

.model small

.data

d1 dq 1234567812345678h

d2 dq 1234567812345678h

d3 db 09 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+8

mov cx,08h

mov dl,00h

clc

up:mov al,[si]

adc al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

inc dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

b) Write an ALP to add two 64 bit numbers using word ptr

Filename:64add1.asm

Naveen.H,Lecturer

33

.model small

.stack

.data

n2 dq 0f222222222222222h

n1 dq 3333333333333333h

result dd(0)

carry db(0)

.code

mov ax,@data

mov ds,ax

mov ax,word ptr n1

mov bx,word ptr n2

clc

add ax,bx

mov word ptr result,ax

mov bx,word ptr n1+2

mov cx,word ptr n2+2

adc bx,cx

mov word ptr result+2,bx

mov ax,word ptr n1+4

mov bx,word ptr n2+4

adc ax,bx

mov word ptr result+4,ax

mov bx,word ptr n1+6

mov cx,word ptr n2+6

adc bx,cx

mov word ptr result+6,bx

adc carry,00h

mov ah,4ch

int 21h

end

14. (*) Write an ALP to add two 128bit numbers

Filename:128add.asm

Naveen.H,Lecturer

34

.model small

.data

d1 dt 99999999999999999999h

d2 dt 0aaaaaaaaaaaaaaaaaaaah

d3 db 11 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+10

mov cx,0ah

mov dl,00h

clc

up:mov al,[si]

adc al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

inc dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

15. Write an ALP to sub two 8bit numbers

Filename:8sbb.asm

Naveen.H,Lecturer

35

.model small

.stack [256]

.data

n1 db 14h,13h

result db(0)

borrow db(0)

.code

mov ax,@data

mov ds,ax

mov al,n1

sub al,n1+1

mov result,al

sbb carry,00h

mov ah,4ch

int 21h

16. a ) Write an ALP to sub two 16bit numbers.

Filename:16sbb.asm

.model small

.stack

.data

n1 dd 0aaaah

n2 dd 9999h

result dd(0)

borrow db(0)

.code

mov ax,@data

mov ds,ax

mov ax,word ptr n1

mov bx,word ptr n2

clc

sub ax,bx

mov word ptr result,ax

sbb borrow,00h

mov ah,4ch

int 21h

end

b)

Filename:16sbbl.asm

Naveen.H,Lecturer

36

.model small

.data

d1 dw 9999h

d2 dw 0aaaah

d3 db 3 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+3

mov cx,04h

mov dl,00h

clc

up:mov al,[si]

sbb al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

dec dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

17. a) Write an ALP to sub two 32bit numbers

Filename:32sub.asm

.model small

Naveen.H,Lecturer

37

.data

d1 dt 99999999h

d2 dt 0aaaaaaaah

d3 db 05 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+5

mov cx,04h

mov dl,00h

clc

up:mov al,[si]

sbb al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

dec dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

c) Write an ALP to sub two 32bit numbers using word ptr

Filename:32sub1.asm

Naveen.H,Lecturer

38

.model small

.stack

.data

n1 dd 0f2222222h

n2 dd 33333333h

result dd(0)

borrow db(0)

.code

mov ax,@data

mov ds,ax

mov ax,word ptr n1

mov bx,word ptr n2

clc

sub ax,bx

mov bx,word ptr n1+2

mov cx,word ptr n2+2

sbb bx,cx

mov word ptr result+2,bx

mov word ptr result,ax

adc borrow,00h

mov ah,4ch

int 21h

end

18. a) Write an ALP to sub two 64 bit numbers

Filename:64sub.asm

.model small

Naveen.H,Lecturer

39

.data

d1 dq 9999999999999999h

d2 dq 0aaaaaaaaaaaaaaaah

d3 db 9 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+8

mov cx,08h

mov dl,00h

clc

up:mov al,[si]

sbb al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

dec dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

b) Write an ALP to sub two 64bit numbers using word ptr

Filename:64sub1.asm

Naveen.H,Lecturer

40

.model small

.stack

.data

n2 dq 0f222222222222222h

n1 dq 3333333333333333h

result dd(0)

borrow db(0)

.code

mov ax,@data

mov ds,ax

mov ax,word ptr n1

mov bx,word ptr n2

clc

sub ax,bx

mov word ptr result,ax

mov bx,word ptr n1+2

mov cx,word ptr n2+2

sbb bx,cx

mov word ptr result+2,bx

mov ax,word ptr n1+4

mov bx,word ptr n2+4

sbb ax,bx

mov word ptr result+4,ax

mov bx,word ptr n1+6

mov cx,word ptr n2+6

sbb bx,cx

mov word ptr result+6,bx

sbb carry,00h

mov ah,4ch

int 21h

end

10(*) Write an ALP to sub two 128 bit numbers

Filename:128sub.asm

Naveen.H,Lecturer

41

.model small

.data

d1 dt 99999999999999999999h

d2 dt 0aaaaaaaaaaaaaaaaaaaah

d3 db 11 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea si,d1

lea di,d2

lea bx,d3+10

mov cx,0ah

mov dl,00h

clc

up:mov al,[si]

sbb al,[di]

mov [bx],al

inc si

inc di

dec bx

dec cx

jnz up

jnc down

dec dl

down:mov [bx],dl

mov ah,4ch

int 21h

end

Multiplication and Division of signed and unsigned hexadecimal numbers

12. ALP to multiply two 8bit unsigned numbers.

Filename:8mul.asm

Naveen.H,Lecturer

42

.model small

.stack 256

.data

n1 db 12h

n2 db 15h

res dw ?

.code

mov ax,@data

mov ds,ax

mov al,n1

mov bl,n2

mul bl

mov res,ax

hlt

end

13. ALP to multiply 8bit signed number and 8bit unsigned number.

Filename:8imul.asm

.model small

Naveen.H,Lecturer

43

.stack 256

.data

n1 db -10h

n2 db 05h

res dw ?

.code

mov ax,@data

mov ds,ax

mov al,n1

mov bl,n2

mul bl

mov res,ax

hlt

end

14. ALP to multiply two 8bit signed numbers .

Filename:8imul.asm

.model small

Naveen.H,Lecturer

44

.stack 256

.data

n1 db -10h

n2 db -05h

res dw ?

.code

mov ax,@data

mov ds,ax

mov al,n1

mov bl,n2

mul bl

mov res,ax

hlt

end

15. ALP to multiply two 16bit unsigned numbers

Filename:16mul.asm

.model small

Naveen.H,Lecturer

45

.stack 256

.data

n1 dw 4168h

n2 dw 2134h

res dw ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

mov bx,n2

mul bx

mov res,ax

mov res+2,dx

hlt

end

16. ALP to multiply two 16bit signed numbers

Filename:16imul.asm

.model small

Naveen.H,Lecturer

46

.stack 256

.data

n1 dw -4168h

n2 dw -2134h

res dw ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

mov bx,n2

imul bx

mov res,ax

mov res+2,dx

hlt

end

17. ALP to multiply 16bit unsigned number and 16bit signed number

Filename:16imul.asm

.model small

Naveen.H,Lecturer

47

.stack 256

.data

n1 dw -4168h

n2 dw 2134h

res dw ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

mov bx,n2

imul bx

mov res,ax

mov res+2,dx

hlt

end

18. ALP to Divide two 8bit unsigned numbers

Filename:8div.asm

.model small

Naveen.H,Lecturer

48

.stack 256

.data

n1 db 12h

n2 db 05h

resq db ?

resr db ?

.code

mov ax,@data

mov ds,ax

mov al,n1

mov ah,00h

mov bl,n2

div bl

mov resq,al

mov resr,ah

hlt

end

19. ALP to Divide two 8bit signed numbers

Filename:8idiv.asm

.model small

Naveen.H,Lecturer

49

.stack 256

.data

n1 db -10h

n2 db -05h

resq db ?

resr db ?

.code

mov ax,@data

mov ds,ax

mov al,n1

cbw

mov bl,n2

idiv bl

mov resq,al

mov resr,ah

hlt

end

20. ALP to Divide 16bit unsigned number by 8bit unsigned number.

Filename:16div.asm

.model small

Naveen.H,Lecturer

50

.stack 256

.data

n1 dw 1000h

n2 db 50h

resq dw ?

resr dw ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

mov dx,00h

mov bx,n2

div bx

mov resq,ax

mov resr,dx

hlt

end

21. ALP to divide 16bit signed number by 8bit signed number.

Filename:16idiv.asm

.model small

Naveen.H,Lecturer

51

.stack 256

.data

n1 dw -1000h

n2 db -50h

resq dw ?

resr dw ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

cwd

mov bx,n2

idiv bx

mov resq,ax

mov resr,dx

hlt

end

22. ALP to divide 32bit number by 16bit number.

Filename:32div.asm

.model small

Naveen.H,Lecturer

52

.data

num dd 12345678h

num1 dw 3456h

res dw 02 dup(0)

.code

mov ax,@data

mov ds,ax

lea si,num

mov dx,[si+2]

mov ax,[si]

mov bx,num1

div bx

lea di,res

mov [di],dx

mov [di+2],ax

mov ah,4ch

int 21h

end

ASCII Adjustment Instructions.

1. ALP using AAA instruction.

a)

Naveen.H,Lecturer

53

Filename:aaa.asm

.model small

.stack[100]

.data

n1 db 10h,09h

n2 dw ?

.code

mov ax,@data

mov ds,ax

mov al,n1

mov ah,00h

mov bl,n1+1

add al,bl

aaa

add ax,3030h

mov n2,ax

mov ah,4ch

int 21h

end

b) Filename:aaa1.asm .model small

.code

mov ax,@data

Naveen.H,Lecturer

54

mov ds,ax

mov al,'8'

mov ah,00h

add al,'9'

aaa

add ax,3030h

mov ah,4ch

int 21h

end

2.ALP using AAS instruction.

Filename:aas.asm .model small

.data

n1 db 08h,07h

n2 dw ?

.code

mov ax,@data

mov ds,ax

mov al,n1

mov ah,00h

mov bl,n1+1

sub al,bl

aas

add ax,3030h

mov n2,ax

mov ah,4ch

int 21h

end

3.ALP using AAM instruction.

Filename:aam.asm

.model small

Naveen.H,Lecturer

55

.stack[100]

.data

n1 db 08h,07h

n2 dw ?

.code

mov ax,@data

mov ds,ax

mov al,n1

mov ah,00h

mov bl,n1+1

mul bl

aam

add ax,3030h

mov n2,ax

mov ah,4ch

int 21h

end

4. ALP using AAD instruction.

Filename:aad.asm

.model small

Naveen.H,Lecturer

56

.stack[100]

.data

n1 dw 0308h

n2 db 06h

resq db ?

resr db ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

mov bl,n2

aad

div bl

add ax,3030h

mov resq,al

mov resr,ah

mov ah,4ch

int 21h

end

Code Conversions

1. ALP to convert Binary to Ascii number.

Filename:bintasc.asm

Naveen.H,Lecturer

57

.model small

.stack 256

.data

n1 db 29

n2 db ?

.code

mov ax,@data

mov ds,ax

mov ax,00h

lea di,n2

mov al,n1

mov bl,10

up:div bl

add ah,30h

mov [di],ah

inc di

cmp al,00h

mov ah,00h

jne up

mov ah,4ch

int 21h

end

2. a) ALP to Convert Ascii to binary number.

Filename:asctbin.asm

.model small

Naveen.H,Lecturer

58

.stack 256

.data

n1 dw 3239h

n2 db ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

and ax,00ffh

sub al,30h

mov n2,al

mov ax,off00h

sub ah,30h

mov cl,04h

ror ah,cl

add ah,n2

mov n2,ah

mov ah,4ch

int 21h

end

b(*)ALP to Convert Ascii to Hex number.

Filename:ascthex.asm

.model small

Naveen.H,Lecturer

59

.stack 256

.data

n1 dw 3536h

n2 db ?

.code

mov ax,@data

mov ds,ax

mov ax,n1

and ax,0ff00h

sub ah,30h

mov al,ah

mov bl,0ah

mul bl

mov dl,al

mov ax,n1

and ax,00ffh

sub al,30h

add al,dl

mov n2,al

mov ah,4ch

int 21h

end

3. ALP to Convert BCD to binary number.

Filename:bthex.asm

.model small

Naveen.H,Lecturer

60

.stack

.data

n1 db 83h

result db(0)

.code

mov ax,@data

mov ds,ax

mov al,n1

mov cl,04h

and al,0fh

mov bl,al

mov al,n1

and al,0f0h

rol al,cl

mov dl,0ah

mul dl

add al,bl

mov result,al

mov ah,4ch

int 21h

end

4. a) ALP to Convert Binary to BCD number(only 8bit).

Filename:bintbcd.asm

.model small

Naveen.H,Lecturer

61

.data

num db 0ffh

;num db 63h

res db 03 dup(0)

.code

Mov ax,@data

Mov ds,ax

Mov al,num

Mov ah,00h

Mov bl,64h

div bl

Lea si,res

Mov [si],al

Mov al,ah

mov ah,0h

mov bl,0ah

div bl

mov [si+1],al

mov [si+2],ah

mov ah,4ch

int 21h

end

b) ALP to Convert Binary to BCD number(16bit/8bit).

Filename:hetb1.asm

.model small

Naveen.H,Lecturer

62

.stack

.data

n1 dw 00ffh

res dw 4 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,n1

mov bx,0ah

mov cx,04h

lea di,res

re:mov dx,00h

div bx

mov [di],dx

dec cx

inc di

cmp ax,00h

jnz re

int 21h

mov ah,4ch

end

Arithmetic programs to find

1. ALP to find Square of a given number

Filename:squ.asm

Naveen.H,Lecturer

63

.model small

.stack [256]

.data

n1 dw 0ffffh

res dw 2 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,n1

mov bx,ax

mov dx,00h

mul bx

mov res,ax

mov res+2,dx

mov ah,4ch

int 21h

end

2. ALP to find cube of a given number

Filename:cube1.asm

.model small

.data

Naveen.H,Lecturer

64

num dw 0111h

res dq(0)

.code

Mov ax,@data

Mov ds,ax

Mov ax,num

Mul num

Mov cx,dx

Mul num

mov word ptr res,ax

mov bx,dx

mov ax,cx

mul num

Add ax,bx

Mov dx,00h

mov word ptr res+2,ax

mov word ptr res+4,dx

Mov ah,4ch

Int 21h

End

3. ALP to find LCM of a given number

Filename:lcm.asm .model small

.stack 64

.data

Naveen.H,Lecturer

65

num dw 12,14

lcm dw 2 dup(0)

.code

mov ax,@data

mov ds,ax

mov ax,num

mov bx,num+2

mov dx,0

cmp ax,bx

jnc again

xchg ax,bx

mov num,ax

mov num+2,bx

again: push ax

push dx

div bx

cmp dx,00h

je store

pop dx

pop ax

add ax,num

jnc no_increment

inc dx

no_increment: jmp again

store: pop lcm+2

pop lcm

mov ah,4ch

int 21h

end

4. ALP to find GCD of a given number

Filename:gcd.asm

.model small

.data

Naveen.H,Lecturer

66

num dw 15,32

Gcd dw ?

.code

Mov ax,@data

Mov ds,ax

Mov ax,num

Mov bx,num+2

Again:cmp ax,bx

Je exit

Jb down

Divaxbx:mov dx,0

Div bx

Cmp dx,0

Je exit

Mov ax,dx

Jmp again

Down:xchg ax,bx

Jmp divaxbx

Exit:mov gcd,bx

Mov gcd+2,ax

Mov ah,4ch

Int 21h

End

5. ALP to find factorial of a given number

Filename:fac.asm

.model small

Naveen.H,Lecturer

67

.stack [256]

.data

num dw 08h

res dd(0)

.code

mov ax,@data

mov ds,ax

mov ax,01h

mov cx,num

mov bx,num

up : mul bx

dec bx

dec cx

jnz up

mov word ptr res,ax

mov word ptr res+2,dx

hlt

end

3 Bit manipulation instructions.

1. ALP to find Whether given data is positive or negative

Filename:posrneg.asm

Naveen.H,Lecturer

68

.model small

.data

n1 db -09H

n2 db 0ah,0dh,"the data is positive $"

n3 db 0ah,0dh,"the data is negative $"

.code

mov ax,@data

mov ds,ax

clc ;Clear carry

mov al,n1

and al,10h

jz d1

mov dx,offset n3

mov ah,09h

int 21h

jmp end1

d1:mov dx,offset n2

mov ah,09h

int 21h

end1:mov ah,4ch

int 21h

end

2. ALP to find Whether given data is odd or even

Filename:oddreven.asm

.model small

.data

Naveen.H,Lecturer

69

n1 db 0feH

n2 db 0ah,0dh,"the given data is odd $"

n3 db 0ah,0dh,"the given data is even$"

.code

mov ax,@data

mov ds,ax

mov ah,00h

mov bl,02h

mov al,n1

div bl

cmp ah,00h

jz down

lea dx,n2

mov ah,09h

int 21h

jmp end1

down:lea dx,n3

mov ah,09h

int 21h

end1:mov ah,4ch

int 21h

end

3. ALP to find Logical 1’s and 0’s in a given data

a)

Filename:1nd0.asm

.model small

Naveen.H,Lecturer

70

.stack 64

.data

num dw 40h

n1 db(0)

n2 db(0)

.code

mov ax,@data

mov ds,ax

lea si,n1

lea di,n2

clc

mov bx,00h

mov dx,00h

mov ax,num

mov cx,08h

up: rcl al,01h

jnc d1

inc bl

mov [si],bl

jmp down

d1: inc dl

mov [di],dl

down : dec cx

jnz up

mov ah,4ch

int 21h

Naveen.H,Lecturer

71

end

b) To display number of 1’s on to console

Filename:11nd00.asm

.model small

.data

n1 dw 0fff0h

n3 db 04 dup(0)

mes1 db 0ah,0dh,"no of 1's$"

.code

mov ax,@data

mov ds,ax

mov bx,00h

lea si,n3

clc

mov cl,10h

mov ax,n1

up:rcl ax,01

jnc d1

inc bl

d1:mov [si],bl

dec cx

jnz up

mov dl,[si]

and dl,0f0h

mov cl,04h

ror dl,cl

Naveen.H,Lecturer

72

cmp dl,0ah

jc d11

add dl,07h

d11:add dl,30h

mov ah,02h

int 21h

mov dl,[si]

and dl,0fh

cmp dl,0ah

jc d12

add dl,07h

d12:add dl,30h

mov ah,02h

int 21h

mov ah,4ch

int 21h

end

4. ALP to find 2 out 5 code.

Filename:2of5.asm .model small

.data

n1 db 0ah,0dh,"the code is 2 out of 5 code$"

Naveen.H,Lecturer

73

n2 db 0ah,0dh,"the code is not a 2 out of 5 code$"

n3 db 0ch

.code

mov ax,@data

mov ds,ax

mov al,n3

mov dl,00h

and al,0e0h

jnz invalid

mov bl,05h

mov al, n3

up:ror al,01h

jnc d1

inc dl

d1:dec bl

jnz up

cmp dl,02h

jnz invalid

lea dx,n1

mov ah,09h int 21h

int 21h end1: mov ah,4ch

jmp end1 int 21h

invalid:lea dx,n2 end

mov ah,09h

5.ALP to find the given number is Bit wise palindrome or not

Filename:pal.asm

.model small

.data

Naveen.H,Lecturer

74

msg1 db 0ah,0dh,'it is a palindrome$'

msg2 db 0ah,0dh,'it is not a palindrome$'

num dw 4444h

.code

mov ax,@data

mov ds,ax

mov ax,num

mov cl,10h

mov bx,00

clc ;Clear carry

back:rol ax,01

rcr bx,01

dec cl

jnz back

cmp ax,bx

jz pali

mov ah,09h

lea dx,msg2

int 21h

jmp last

pali:mov ah,09h last:mov ah,4ch

lea dx,msg1 int 21h

int 21h end

6.a) ALP to find the given number is nibble wise palindrome or not.

Filename:npal.asm

.model small

.data

Naveen.H,Lecturer

75

num dw 8448h

msg1 db 0ah,0dh,"it is a palindrome$"

msg2 db 0ah,0dh,"it is not a palindrome$"

.code

mov ax,@data

mov ds,ax

mov ax,num

mov cl,04

mov bx,ax

clc

up:ror bl,01

dec cl

jnz up

cmp bh,bl

jz pali

mov ah,09h

lea dx,msg2

int 21h

jmp end1

pali:mov ah,09h end1:mov ah,4ch

lea dx,msg1 int 21h

int 21h end

b)ALP to find the given data byte is nibblewise palindrome or not

Filename:nbpal.asm

.model small

.data

Naveen.H,Lecturer

76

n1 db 44h

msg db 10,13,"number is palindrome $"

msg1 db 10,13,"number is not a palindrome $"

.code

mov ax,@data

mov ds,ax

mov al,n1

and al,0f0h

mov cl,04h

ror al,cl

mov bl,al

mov al,n1

and al,0fh

mov cl,al

cmp bl,cl

jnz npal

lea dx,msg

mov ah,09h

int 21h

jmp last

npal:lea dx,msg1 last:mov ah,4ch

mov ah,09h int 21h

int 21h end

4 Branch/Loop instructions like.

8. ALP to add N numbers of data in an array

Filename:addn.asm

.model small

Naveen.H,Lecturer

77

.data

arr dw 1111h,2222h,3333h,4444h,5555h

len EQU ($-arr)/2

sum dw 2 dup(0)

.code

mov ax,@data

mov ds,ax

lea si,arr

lea di,sum

mov cx,len

xor ax,ax

mov dx,00h

clc

up:adc ax,[si]

inc si

inc si

dec cx

jnz up

jnc down

inc dx

down:mov [di],ax

mov [di+2],dx

mov ah,4ch

int 21h

end

9. ALP to Sub N numbers of data in an array

Filename:sbbn.asm

.model small

.data

arr dw 50h,30h,06h,05h,10h

Naveen.H,Lecturer

78

len EQU ($-arr)/2

sum dw 2 dup(0)

.code

mov ax,@data

mov ds,ax

lea si,arr

lea di,sum

mov cx,len

xor ax,ax

mov dx,00h

clc

up:sbb ax,[si]

inc si

inc si

dec cx

jnz up

jnc down

dec dx

down:mov [di],ax

mov [di+2],dx

mov ah,4ch

int 21h

end

10. ALP to Find average of N numbers in an array

Filename:avg.asm

.model small

.stack

.data

Naveen.H,Lecturer

79

array db 02h,04h,06h,08h,10h,12h,14h,16h,18h,20h

ary_cnt equ ($-array)

sum dw(0)

avg db(0)

.code

mov ax,@data

mov ds,ax

mov cx,ary_cnt

lea si,array

clc

xor ax,ax

back:adc al,[si]

inc si

dec cx

jnz back

mov sum,ax

mov cl,ary_cnt

div cl

mov avg,ax

mov ah,4ch

int 21h

end

11. ALP to Find the largest number in an array

Filename:largest.asm

.model small

.data

array dw 2222h,8567h,4589h,5555h,1111h

Naveen.H,Lecturer

80

ary_cnt EQU ($-array)/2

res dw 02 dup(0)

.code

mov ax,@data

mov ds,ax

lea bx, array

mov cx,ary_cnt

mov ax,[bx]

up:cmp ax,[bx+2]

jnc below

mov ax,[bx+2]

below:inc bx

inc bx

dec cx

jnz up

mov res,ax

mov ah,4ch

int 21h

end

12. ALP to find the smallest number in an array and display on screen

Filename:small.asm

.model small

.data

array dw 2222h,8567h,4589h,5555h,1123h

Naveen.H,Lecturer

81

ary_cnt EQU ($-array)/2

res dw 02 dup(0)

msg db 0ah,0dh,'smallest number in an array is: $'

.code

mov ax,@data

mov ds,ax

lea bx, array

mov cx,ary_cnt-1

mov ax,[bx]

up:cmp ax,[bx+2]

jc below

mov ax,[bx+2]

below:inc bx

inc bx

dec cx

jnz up

mov res,ax

lea dx,msg

mov ah,09h

int 21h

mov dl,res+1

and dl,0f0h

mov cl,04h

ror dl,cl

cmp dl,0ah

jc d1

add dl,07h

d1:add dl,30h

mov ah,02h

int 21h

mov dl,res+1

and dl,0fh

cmp dl,0ah

jc d2

Naveen.H,Lecturer

82

add dl,07h

d2:add dl,30h

mov ah,02h

int 21h

mov dl,res

and dl,0f0h

mov cl,04h

ror dl,cl

cmp dl,0ah

jc d3

add dl,07h

d3:add dl,30h

mov ah,02h

int 21h

mov dl,res

and dl,0fh

cmp dl,0ah

jc d4

add dl,07h

d4:add dl,30h

mov ah,02h

int 21h

mov ah,4ch

int 21h

end

13. ALP to sort the numbers in ascending order in an array using insertion sort

technique

Filename:asc.asm

.model small

.data

n1 dw 0ffffh,5555h,3333h,7777h

Naveen.H,Lecturer

83

count dw 04h

.code

mov ax,@data

mov ds,ax

mov bx,count

dec bx

l2: mov cx,bx

mov si,00h ;si=0

l1: mov ax,n1[si]

inc si

inc si

cmp ax,n1[si]

jc rep1

xchg ax,n1[si]

mov n1[si-2],ax

rep1:loop l1

dec bx

jnz l2

mov ah,4ch

int 21h

end

14. ALP to sort the numbers in Descending order in an array using insertion

sort technique.

Filename:des.asm

.model small

.data

n1 dw 0ffffh,5555h,3333h,7777h

count dw 04h

Naveen.H,Lecturer

84

.code

mov ax,@data

mov ds,ax

mov bx,count

dec bx

l2: mov cx,bx

mov si,00h ;si=0

l1: mov ax,n1[si]

inc si

inc si

cmp ax,n1[si]

jnc rep1

xchg ax,n1[si]

mov n1[si-2],ax

rep1:loop l1

dec bx

jnz l2

mov ah,4ch

int 21h

end

5.Programs on String manipulation.

1.ALP to transfer a String from one location to another location.

Filename:str.asm

.model small

.data

Naveen.H,Lecturer

85

src db 'electronics$'

dst db 25 dup(0)

.code

mov ax,@data

mov ds,ax

mov es,ax

lea si,src

lea di,dst

cld

mov cx,0bh

rep movsb

mov ah,4ch

int 21h

end

2. ALP reverse a given String.

Filename:rstr.asm

.model small

.data

mes1 db 0ah,0dh,"enter the string",0ah,0dh,"$"

blank db " ", 0ah,0dh,"$"

Naveen.H,Lecturer

86

string db 18 dup(0)

.code

mov ax,@data

mov ds,ax

mov es,ax

mov dx,offset mes1

mov ah,09h

int 21h

mov si,offset string

add si,14h

mov dl,24h

mov [si],dl

cops:mov ah,01h

int 21h

cmp al,0dh

jz rev

dec si mov ah,09h

mov [si],al mov dx,si

jmp cops int 21h

rev:mov dx,offset blank mov ah,4ch

mov ah,09h int 21h

int 21h end

3. ALP to Search a Character in a given string

Filename:char.asm

.model small

.data

string db "electronics$"

enter db "j"

Naveen.H,Lecturer

87

msg db 0ah,0dh,"character found$"

msg1 db 0ah,0dh,"charcter not found$"

char db 02 dup(0)

.code

mov ax,@data

mov ds,ax

mov es,ax

mov cl,0ah

lea si,string

up:mov al,[si]

cmp al,enter

jz found

inc si

dec cl

jnz up

nfound:lea dx,msg1

mov ah,09h

int 21h

jmp end1

found:lea dx,msg end1:mov ah,4ch

mov ah,09h int 21h

int 21h end

4 ALP to Check weather a given string is Palindrome or not.

Filename:strpal.asm

.model small

.data

str1 db 'loril'

Naveen.H,Lecturer

88

len equ $-str1

str2 db 20 dup(0)

mes1 db 10,13,'word is palindrome $'

mes2 db 10,13,'word is not palindrome $'

.code

mov ax,@data

mov ds,ax

mov es,ax

lea si,str1

lea di,str2+len-1

mov cx,len

up: cld

lodsb

std

stosb

loop up

lea si,str1

lea di,str2

cld

mov cx,len

repe cmpsb

cmp cx,0h

jnz notpalin

lea dx,mes1

Naveen.H,Lecturer

89

mov ah,09h

int 21h

jmp exit

notpalin: lea dx,mes2

mov ah,09h

int 21h

exit: mov ah,4ch

int 21h

end

6. Programs involving Software interrupts.

1.ALP To read a Character from the Keyboard.

Filename:key1.asm .model small

.data

.code

mov ax,@data

Naveen.H,Lecturer

90

mov ds,ax

mov ah,01h

int 21h

mov ah,4ch

int 21h

end

2.ALP to read a Character from the keyboard with buffered input

Filename:key.asm .model small

.stack[256]

.data

buff db 8h

db 0h

db 30 dup(0)

.code

mov ax,@data

mov ds,ax

mov ah,0ah

lea dx,buff

int 21h

hlt

end

3.ALP to display a character on console

Filename:rchar.asm .model small

.data

.code

mov ax,@data

mov ds,ax

Naveen.H,Lecturer

91

mov ah,06h

mov dl,'a'

int 21h

mov ah,4ch

int 21h

end

5. ALP to display a string on console.

Filename:disstr.asm .model small

.data

mes db 10,13.'electronics $'

.code

mov ax,@data

mov ds,ax

mov ah,09h

lea dx,mes

int 21h

mov ah,4ch

Int 21h

end

all in one Dos programs

Filename:tdosin.asm

.model small

.data

key db ?

buf db 20 dup(0)

mes db 10,13,'electronics$'

Naveen.H,Lecturer

92

.code

mov ax,@data

mov ds,ax

mov ah,01h

int 21h

mov key,al

mov buf,10

mov ah,0ah

lea dx,buf

int 21h

mov ah,06h

mov dl,'a'

int 21h

mov ah,09h

lea dx,mes

int 21h

mov ah,4ch

int 21h

end

5.(*) ALP to Create a new file

Filename:new.asm

data segment

filename db'hello.new'

data ends

code segment

assume cs:code, ds:data

Naveen.H,Lecturer

93

start: mov ax,data

mov ds,ax

mov ah,3ch

mov cx,0

mov dx,offset filename

int 21h

code ends

end start

6(*) ALP to read a new file.

Filename:read.asm

data segment

mes db 10,13,'enter some data in the file$'

filename db 'hello.new'

buffer db 22 dup(0)

mes1 db 10,13, 'error in file handling$'

Naveen.H,Lecturer

94

data ends

code segment

assume cs:code,ds:data

start: mov ax,data

mov ds,ax

mov ah,09h

lea dx,mes

int 21h

mov buffer,20

mov ah,0ah

mov dx,offset buffer

int 21h

mov ah,3ch

mov cx,0

mov dx,offset filename

int 21h

mov bx,ax

mov ah,40h

mov cx,20

mov dx, offset buffer

int 21h

jc error

jmp exit

error: mov dx,offset mes1

mov ah,09h

int 21h

Naveen.H,Lecturer

95

exit: mov ah,4ch

int 21h

code ends

end start

II) Experiments on interfacing 8086 with the following interfacing modules through DIO (Digital Input/Output-

PCI bus compatible) card

1. ALP To interface Matrix keyboard to 8086 through 8255.

Filename:keyboard.asm

display macro msg

mov ah,09h

int 21h

endm

Naveen.H,Lecturer

96

data segment

lut db "0123456789+-*/=%CEdddddd"

row db ?

col db ?

pos db ?

msg1 db "Press any key on 3*8 keyboard $"

msg3 db 10,13,"Row no.is: $"

msg4 db 10,13,"Col no,is: $"

msg2 db 10,13,"Value of key pressed no.is: $"

data ends

code segment

assume cs:code,ds:data

start:mov ax,data

mov ds,ax

mov al,90h

mov dx,0d883h

out dx,al

display msg1

poll:mov al,80h

mov pos,00

mov row,01

nextrow:rol al,01

mov bl,al

mov dx,0d882h

out dx,al

mov col,01

Naveen.H,Lecturer

97

mov dx,0d880h

in al,dx

mov col,01

nextcol:ror al,01

jc found

inc pos

inc col

cmp col,08

jle nextcol

inc row

cmp row,03

mov al,bl

jle nextrow

jmp poll

found:display msg3

mov dl,row

add dl,30h

mov ah,02h

int 21h

display msg4

mov dl,col

add dl,30h

mov ah,02h

int 21h

display msg2

lea si,lut

Naveen.H,Lecturer

98

mov cl,pos

moc ch,00

add si,cx

mov dl,[si]

mov ah,02h

int 21h

mov ah,04ch

int 21h

code ends

end start

2. ALP to interface Logical controller to 8086 through 8255.

a) ALP to interface Logical Controller for not gate to 8086 through 8255

Filename:notlc1.asm

.model small

.data

cr EQU 0d883h

PA EQU 0d880h

PB EQU 0d881h

PC EQU 0d882h

Naveen.H,Lecturer

99

.code

mov ax,@data

mov ds,ax

mov al,82h

mov dx,CR

out dx,al

getkey:mov dx,PB

in al,dx

not al

mov dx,PA

out dx,al

mov ah,01h

int 16h

jz getkey

mov ah,4ch

int 21h

end

b) ALP to interface Logical Controller for and gate to 8086 through 8255

Filename:andlc2.asm

data segment

pa equ 0d880h

pb equ 0d881h

pc equ 0d882h

cr equ 0d883h

data ends

Naveen.H,Lecturer

100

code segment

assume cs:code, ds:data

start: mov ax, data

mov ds, ax

mov ax, 082h

mov dx, cr

out dx,ax

repeat: mov dx, pb

in al,dx

and al, 03h

cmp al,03h

jz display

mov al,00h

mov dx, pa ;output to porta

out dx,al

jmp repeat

display: mov al,0ffh

mov dx,pa ;output to porta

out dx, al

jmp repeat

code ends

end start

d) ALP to interface Logical Controller for or gate to 8086 through 8255

Filename:orlc2.asm

data segment

pa equ 0d880h

Naveen.H,Lecturer

101

pb equ 0d881h

pc equ 0d882h

cr equ 0d883h

data ends

code segment

assume cs:code, ds:data

start: mov ax, data

mov ds, ax

mov ax, 082h

mov dx, cr

out dx,ax

repeat: mov dx, pb

in al,dx

and al, 03h

cmp al,00h

jz display

mov al,0ffh

mov dx, pa ;output to porta

out dx,al

jmp repeat

display: mov al,00h

mov dx,pa ;output to porta

out dx, al

jmp repeat

code ends

end start

Naveen.H,Lecturer

102

e) ALP to interface Logical Controller for xor gate to 8086 through 8255

Filename:xorlc2.asm

data segment

pa equ 0d880h

pb equ 0d881h

pc equ 0d882h

cr equ 0d883h

data ends

code segment

assume cs:code, ds:data

start: mov ax, data

mov ds, ax

mov ax, 082h

mov dx, cr

out dx,ax

repeat: mov dx, pb

in al,dx

and al, 03h

cmp al,00h

jz display

cmp al,03h

jz display

mov al,0ffh

mov dx, pa ;output to porta

out dx,al

jmp repeat

Naveen.H,Lecturer

103

display: mov al,00h

mov dx,pa ;output to porta

out dx, al

jmp repeat

code ends

end start

f) ALP to interface Logical Controller for xnor gate to 8086 through 8255

Filename:xnorlc2.asm

data segment

pa equ 0d880h

pb equ 0d881h

pc equ 0d882h

cr equ 0d883h

data ends

code segment

assume cs:code, ds:data

start: mov ax, data

mov ds, ax

mov ax, 082h

mov dx, cr

out dx,ax

repeat: mov dx, pb

in al,dx

and al, 03h

cmp al,00h

jz display

Naveen.H,Lecturer

104

cmp al,03h

jz display

mov al,00h

mov dx, pa ;output to porta

out dx,al

jmp repeat

display: mov al,0ffh

mov dx,pa ;output to porta

out dx, al

jmp repeat

code ends

end start

g) ALP to interface Logical Controller for nor gate to 8086 through 8255

Filename:norlc2.asm

data segment

pa equ 0d880h

pb equ 0d881h

pc equ 0d882h

cr equ 0d883h

data ends

Naveen.H,Lecturer

105

code segment

assume cs:code, ds:data

start: mov ax, data

mov ds, ax

mov ax, 082h

mov dx, cr

out dx,ax

repeat: mov dx, pb

in al,dx

and al, 03h

cmp al,00h

jz display

mov al,00h

mov dx, pa ;output to porta

out dx,al

jmp repeat

display: mov al,0ffh

mov dx,pa ;output to porta

out dx, al

jmp repeat

code ends

end start

g)ALP to interface Logical Controller for nand gate to 8086 through 8255

Filename:nandlc2.asm

data segment

pa equ 0d880h

Naveen.H,Lecturer

106

pb equ 0d881h

pc equ 0d882h

cr equ 0d883h

data ends

code segment

assume cs:code, ds:data

start: mov ax, data

mov ds, ax

mov ax, 082h

mov dx, cr

out dx,ax

repeat: mov dx, pb

in al,dx

and al, 03h

cmp al,03h

jz display

mov al,0ffh

mov dx, pa ;output to porta

out dx,al

jmp repeat

display: mov al,00h

mov dx,pa ;output to porta

out dx, al

jmp repeat

code ends

end start

Naveen.H,Lecturer

107

3. ALP to interface Stepper motor to 8086 through 8255.

a) ALP to interface Stepper motor in clockwise direction to 8086 through 8255.

Filename:cstp.asm code segment

assume cs:code

start:mov al,80h

mov dx,0d883h

out dx,al

mov si,20

Naveen.H,Lecturer

108

mov dx,0d882h

mov al,77h

back: out dx,al

call delay

ror al,01h

dec si

jnz back

mov ah,04ch

int 21h

delay proc near

mov cx,0ffffh

up2: mov bx,0ffffh

up1: dec bx

jnz up1

dec cx

jnz up2

ret

delay endp

code ends

end start

b) ALP to interface Stepper motor in anticlockwise direction to 8086 through 8255.

Filename:acstp.asm code segment

assume cs:code

start: mov al,80h

mov dx,0d883h

out dx,al

mov si,20

Naveen.H,Lecturer

109

mov dx,0d882h

mov al,77h

back: out dx,al

call delay

rol al,01h

dec si

jnz back

mov ah,04ch

int 21h

delay proc near

mov cx,0ffffh

up2: mov bx,0ffffh

up1: dec bx

jnz up1

dec cx

jnz up2

ret

delay endp

code ends

end start

h) ALP to interface Stepper motor 90 degree in clockwise and 180 in

anticlockwise to 8086 through 8255.

Filename:90c180ac.asm

code segment

assume cs:code

start: mov al,80h

mov dx,0d883h

Naveen.H,Lecturer

110

out dx,al

mov si,50

mov dx,0d882h

mov al,77h

back: out dx,al

call delay

ror al,01h

dec si

jnz back

mov dx,0d882h

mov si,100

mov al,77h

back1: out dx,al

call delay

rol al,01h

dec si

jnz back1

mov ah,01ch

int 21h

delay proc near

mov cx,7000h

up2: mov bx,7000h

up1: dec bx

jnz up1

dec cx

jnz up2

Naveen.H,Lecturer

111

ret

delay endp

code ends

end start

4. ALP to interface Seven segment display to 8086 through 8255

a) ALP to display a message using Seven segment display to 8086 through

8255

Filename:fire.asm

data segment

fire db 71h,06h,50h,79h,0,0

blank db 0,0,0,0,0,0

Naveen.H,Lecturer

112

help db 76h,79h,38h,73h,0,0

data ends

code segment

assume cs:code,ds:data

start:mov ax,data

mov ds,ax

mov dx,0d883h

mov al,80h

out dx,al

repeat:mov di,100

fire1:mov si,offset fire

call display

dec di

jnz fire1

mov di,100

blank1:mov si,offset blank

call display

dec di

jnz blank1

mov di,100

help1:mov si,offset help

call display

dec di

jnz help1

mov di,100

Naveen.H,Lecturer

113

blank2:mov si,offset blank

call display

dec di

jnz blank2

mov ah,01h

int 16h

jz repeat

mov ah,04ch

int 21h

display proc near

mov bl,05

nextchar:mov al,bl

mov dx,0d882h

out dx,al

mov al,[si]

mov dx,0d880h

out dx,al

call delay

dec bl

inc si

cmp bl,-1

jne nextchar

ret

display endp

delay proc near

push bx

Naveen.H,Lecturer

114

push cx

mov bx,0010h

up2:mov cx,0ffffh

up1:dec cx

jnz up1

dec bx

jnz up2

pop cx

pop bx

ret

delay endp

code ends

end start

b) ALP to display a moving message using Seven segment display to 8086

through 8255

Filename:movdis.asm

data segment

character12 db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,77h,7ch,0,0,0,0,0,0

data ends

code segment

assume cs:code,ds:data

Naveen.H,Lecturer

115

start:mov ax,data

mov ds,ax

mov al,80h

mov dx,0d883h

out dx,al

mov bp,offset character12

r1:mov di,100

r2:mov si,bp

call display

dec di

jnz r2

inc bp

cmp bp,0013

jne r1

mov ah,04ch

int 21h

display proc near

mov bl,05

nextchar:mov al,bl

mov dx,0d882h

out dx,al

mov al,[si]

mov dx,0d880h

out dx,al

call delay

dec bl

inc si

Naveen.H,Lecturer

116

cmp bl,-1

jne nextchar

ret

display endp

delay proc near

push bx

push cx

mov bx,0010h

up2:mov cx,0ffffh

up1:dec cx

jnz up1

dec bx

jnz up2

pop cx

pop bx

ret

delay endp

code ends

end start

Naveen.H,Lecturer

117

VIVA QUESTIONS IN ADVANCED MICROPROCESSOR

1. List all the modern microprocessor

2. Name some 16 bit Processor (8086, 80286, 80386L, EX)

3. Name some 32 bit processors (80386DX, 80486, PENTIUM OVERDRIVE)

4. Name some 64 bit processor (Pentium, Pentium pro, Pentium II, Xeon, Pentium III,

and Pentium IV)

5. List the address bus width and the memory size of all the processor.

6. The memory map of any IBM COMPATIBLE PC consists of three main parts, name

them [transient memory area, system area, Extended memory system]

7. The first I MB of the memory area is called as …………… (Real memory area)

8. What does the TPA hold (interrupt vectors, bios, DOS, IO.SYS, MSDOS, DEVICE

DRIVERS, command.com)

9. The system area contain programs in …………memory(ROM)

10. What are the main two parts of 8086 internal architecture.(BIU,EU)

11. Name the registers in BIU (CS, DS, ES, SS, IP)

12. Name the registers in EU.( AX, BX, CX, DX, SP, BP, SI, DI)

13. Name the flag registers in 8086. (O, D, I, T, S, Z, A, P, C)

14. How is the real memory semented?

15. What is the advantage of segmentation.

16. Name the default segment and offset register combinations.

17. What is the relocatable program.

18. Name the three main addressing modes in 8086.

19. Name the data addressing modes. And the program addressing modes. Give

examples

20. Explain MOV AL, ‘A’, MOV AX, NUMBER, MOV [BP], DL, MOV CH,[1000],

MOV[BX+SI],SP, MOV ARRAY[SI],BL, MOV DH,[BX+DI+10H]

21. Name the programme memory addressing modes. (Direct, relative, indirect)

22. What is an intersegment and intrasegment jump.

23. Differentiate near and short jumps (+_32k and +127to_128 bytes)

24. Differentiate near and far jumps.

25. Differentiate push and pop instructions.

26. Explain PUSH word ptr [BX], POP F.

27. JMP TABLE[BX]

28. Explain the following : ASSUME,DB,DD,DW,DQ,END

29. Give the opcode format for 8086 instructions.

(op(1-2b),(mode,reg,rem),(displacement-0-2b))

30. Explain LES BX, LEA AX, DATA, LDS DI,LIST

31. Explain how the string instructions are executed.

32. List some string instructions

33. Explain the significance of REP Prefix.

34. Explain XCHG, LAHF, SAHF, XLAT

35. What are the two types of I/O addressing modes. ( fixed port ,variable port)

36. What do you mean by segment override prefix.

37. Explain the following directives. NEAR ,FAR,BYTE PTR,ORG,OFFSET,ORG

38. Differentiate END, ENDP, ENDM

39.Differntiare PROC AND macro

40. What are the two basic formats used by assemblers. Where are they used. (Models,

full segment definition)

41. Explain ADD BYTE PTR (.model tiny (64kb), .model small(128 kb), .model huge.

Naveen.H,Lecturer

118

42. Explain ADD BYTE PTR [DI], 3, SBB BYTE PTR [DI],5, CMP[DI], 0CH , IMUL

BYTE PTR [BX], IDIV SI, CWD, CBW.

43. DAA, (ONLY ON AL), AAA, AAD, AAM, AAS.

44. Name the logical instructions. How can we invert number .(XOR WITH 1s)

45. Differentiate TEST and CMP, and NOT& NEG, SAR & SHR, RCL & ROL, SCAS

& CMPS, REPE SCASB &REPNE &SCASB

46. Which are the flags affected. JA(Z=0 C=0), JB(C=0), JG (Z=0 S=0), JLE( Z=1 S<>0)

47. LOOP, LOOPNE, LOOPE LOOPZ

48. Differentiate NEAR & FAR CALL, NEAR RET & FAR RET

49. Explain, maskable, non maskable, vectored, non vectored, software & Hardware

Interrupts.

50. What are interrupt vectors. (4 byte no. stored in the first 1024 bytes of memory.

There are 256 interrupt vectors. Each vector contains value of CS & IP, 32 vectors are

reserved for present and future. 32 to 255 are available for users.

51. Name the interrupt instructions. ( INT, INT0, INT3)

52. Give significance of INT0, INT3.

53. Give the significance of IRET instruction how is it different from RET. (Like far

RET retrieves 6 bytes from stack, two for IP, two for CS and two for flags.)

54. Explain the operation of real mode interrupt.

55. Explain the protected mode interrupt.

56. Explain how the interrupt flag bit IF and TF are used during an interrupt

57. Name the hardware and soft ware interrupt of 8086, explain about them. (NMI,

INTR are hardware interrupts. INT, INT0, INT3, BOYND, are the software interrupts)

58. How can you expand the interrupt structure. ( using 74LS 244 7 more interrupts can

accommodated. Daisy chained interrupt is better as it requires only one interrupt

vector.)

59. Give a general description of 8259 interrupt controller.

61. Explain the above pins of 8086 TEST, READY, RESET, BHE/S7, MN/MX, ALE,

DT/R, DEN, HOLD, HLDA, SO, RO/GT1, LOCK, QS1-QS0.

62. Name the maximum mode pins.

63. Name the minimum mode pins.

64. Name the function of 8284

65 How does the RESET function.

66. What is the clock frequency of the 8086.

67. How are the address and data buses are separated.

68. What is the function of the following 74LS373, 245, 244

69. Differentiate between minimum mode and maximum mode of operation.

70. What are the two methods of interfacing memory. ( linear and absolute decoding)

71. What do you understand by linear and absolute decoding.

72. What is the maximum memory capacity of 8086

73. Name the difference between 8086,8088.

74, Name the difference between 8085 and 8086.

75. Name the types of memory used in microprocessor based system.

76. What is the function of the 8288 controller

77. What are the various signals in a RAM and ROM memories.

78. Name the following. 8255, 8155, 8259, 8253, 8257, 8251

79. Give the format of control word register.

80. Explain the PPI you know.

81. Explain the modes of 8255.

82. Explain the basic function of 8279.

83. How are the delays obtained in a microprocessor based system

Naveen.H,Lecturer

119

84. What is an arithmetic coprocessor, What are its functions. (multiply, devide, add,

subtract, square root, calculate partial tangent, partial arctangent and logarithms)

85. What are the data types used. ( 16,32, 64 bit signed integers, 18 bit BCD data, 32, 64

and 80 bit floating point nos.)

86. What are the advantages of the 8087 coprocessor. (many times faster than the

microprocessor)

87. How can we use the DOS function calls.

88. What is the function of int21 interrupts.

89. Explain PUBLIC and EXTERN statements.

90. What do you mean by modular programming, how is it accomplished in 8086.

91. what are libraries.

92. Differentiate between MACRO and PROCEDURE.

93. What are the conditional statements used in a MACRO. (REPEAT, WHILE)

94. What are the different methods of reading the keyboard using DOS function calls.

95. How can we use XLAT instruction for look up tables.

96. What are the two methods of interfacing I/O ( memory mapped I/O and I/O mapped

I/O)