Sunteți pe pagina 1din 51

B.N.M.I.T MP Manual ;Binary Search-1A .model small .stack 200 .

data a dw 1111h,3333h,5555h,7777h,9999h len dw ($-a)/2 key dw 2333h msg1 db 10,13,'successful search','$' msg2 db 10,13,'Unsuccessful search','$' .code mov ax,@data ; Initialization of Data Segment mov ds,ax ; Inside Code Segment mov ax,key mov si,0 mov di,len dec di again: cmp si,di ja notfound mov bx,si add bx,di shr bx,01 mov bp,bx dec bx shl bx,01 cmp ax,a[bx] je found jc midbig inc bp mov si,bp jmp again midbig: dec bp mov di,bp jmp again found: lea dx,msg1 jmp exit notfound: lea dx,msg2 exit: mov ah,09h int 21h mov ah,4ch int 21h end Dept. CSE ; ax = Search key ; si = low ; di = high ; low > high

; bx = low + high ; bx = mid ; pointer adjustment ; Searching for key element ; mid = key ; si(low) = mid + 1

; di (high) = mid - 1

; interrupt to display the ; message ; interrupt to end the ; program 1

B.N.M.I.T MP Manual ; linking of 2 macros which are (2A) included as library files with include c:\masm\jalaja\2a1.mac include c:\masm\jalaja\2a2.mac .model small .stack 200 .data msg db 10,13,"enter the data end with enter key",'$' a db 10 dup(?) .code mov ax,@data ; initialization of data segment mov ds,ax ; inside code segment lea dx,msg mov ah,09h int 21h mov si,0 again: read cmp al,13 je disp mov a[si],al inc si jmp again disp: mov dl,0ah mov ah,02 int 21h mov cx,si mov si,0 begin: mov dl,a[si] writ inc si loop begin mov ah,4ch int 21h end ;------2a1.mac-----read macro mov ah,01 int 21h endm ;-----2a2.mac-----writ macro mov ah,02 int 21h endm Dept. CSE ; interrupt to print ; the message

; macro to accept i/p ; till ENTER key is pressed

; interrupt to move the ; cursor to next line

; macro to print a character

; interrupt to accept i/p

; interrupt to print a character

B.N.M.I.T ; sort the no using bubble sort(3A) .model small .stack 200 .data a db 23h,43h,12h,55h,11h len dw ($-a) .code mov ax,@data ; initialization of data segment mov ds,ax ; inside code segment mov bx,len dec bx outl: mov cx,bx mov si,0 inl: mov al,a[si] inc si cmp al,a[si] jb next xchg al,a[si] mov a[si-1],al next: loop inl dec bx jnz outl mov ah,4ch int 21h end ; interrupt to end the code segment ; outer loop from 0 to n-1 ; inner loop from 0 to outer loop

MP Manual

; comparison of 2 elements ; if greater exchange

Dept. CSE

B.N.M.I.T ; to accept alphanumeric character(4A) ; and display its ASCII EQUIVALENT .model small .stack 200 .data ascii db 2 dup(?) msg db "enter the alph or numeric data",'$' .code mov ax,@data ; initialization of data segment mov ds,ax ; inside code segment mov ah,00 mov al,02 int 10h lea dx,msg mov ah,09h int 21h mov ah,01h int 21h mov bl,al and al,0f0h mov cl,4 shr al,cl cmp al,09 jle ad30 add al,07 ad30: add al,30h mov ascii,al mov al,bl and al,0fh cmp al,09h jle sum30 add al,07 sum30: add al,30h mov ascii+1,al mov dh,0ch mov dl,28h mov bh,00 mov ah,02h int 10h Dept. CSE ; retaining lower 4-bits ; to clear the screen

MP Manual

; interrupt to print the message ; interrupt to accept an i/p

; mask off LSB 4-bits & retain higher 4-bits ; conversion to its ascii value

; conversion to its ascii value

; positioning row ; and column to centre ;of the screen in page 0

B.N.M.I.T mov bl,2 mov si,0 ag: mov dl,ascii[si] mov ah,02 int 21h inc si dec bl jnz ag mov ah,4ch int 21h end

MP Manual

; interrupt to print a character

; interrupt to end the program

Dept. CSE

B.N.M.I.T ; to reverse and check for PALINDROME(5A) print macro msg lea dx,msg mov ah,09h ; interrupt to print the message int 21h endm .model small .stack 200 .data msg1 db 10,13,'string is PALINDROME','$' msg2 db 10,13,'string is NOT PALINDROME','$' str1 db 'diddd$' len dw ($-str1-1) str2 db 20 dup(?) .code mov ax,@data ; initializing data & extra segment mov ds,ax ; inside code segment mov es,ax lea si,str1 lea di,str2 mov cx,len add si,len dec si back: mov al,[si] mov [di],al inc di dec si loop back cld lea si,str1 lea di,str2 mov cx,len repe cmpsb jz pali lea dx,msg2 jmp exit pali: lea dx,msg1 exit: mov ah,09h int 21h mov ah,4ch int 21h end Dept. CSE

MP Manual

; reversing the string

; DF=0

; compare string byte by byte if equal

; interrupt to print the message ; interrupt to end the program

B.N.M.I.T ;string comparison and print its length(6a)

MP Manual

;---macro to move cursor to new line--newline macro mov dl,13 ; ascii value of enter key mov ah,02 ; interrupt to place the cursor to next line int 21h mov dl,10 mov ah,02 int 21h endm ; ascii value of blank space ; interrupt to fill the entire line with blank space

;---macro to print the message----print macro msg lea dx,msg mov ah,09h int 21h endm .model small .stack 200 .data str1 db 20 dup(?) str2 db 20 dup(?) m1 db 'STRINGS ARE EQUAL','$' m2 db 'STRINGS ARE NOT EQUAL','$' len1 db ? len2 db ? m3 db 'enter first string :','$' m4 db 'enter second string :','$' m5 db 'length of first string :','$' m6 db 'length of second string :','$' .code mov ax,@data mov ds,ax mov es,ax print m3 lea si,str1 call readstr mov len1,bl newline print m4 lea si,str2 call readstr mov len2,bl newline Dept. CSE ; macro to print the message ; procedure to accept the string ; macro to place the cursor to new line ; macro to print the message ; procedure to accept the string ; macro to place the cursor to new line 7

B.N.M.I.T print m5 mov al,len1 call ech newline print m6 mov al,len2 call ech newline mov al,len1 cmp al,len2 jnz notequal lea si,str1 lea di,str2 cld mov ch,00 mov cl,len1 repe cmpsb jne notequal print m1 jmp exit notequal: print m2 exit: mov ah,4ch int 21h

MP Manual ; macro to print the message ; procedure to print the length ; macro to place the cursor to new line ; macro to print the message ; procedure to print the length ; macro to place the cursor to new line ; if length of string1 > string2

; compare string byte by byte if equal

;-----procedure to read the string---readstr proc mov bl,00 l1: mov ah,01 int 21h cmp al,0dh je exi inc bl mov [si],al inc si jmp l1 exi: ret readstr endp

; interrupt to accept the data

Dept. CSE

B.N.M.I.T ;-----procedure to display the length---ech proc mov bl,al and al,0f0h mov cl,4 shr al,cl cmp al,09h jle ad30 add al,07 ad30: add al,30h mov dl,al mov ah,02 int 21h mov al,bl and al,0fh add al,30h mov dl,al mov ah,02 int 21h ret ech endp end ;end of code segment ; getting lower 4-bits ; converting to its ascii value

MP Manual

; getting higher 4-bits ; converting to its ascii value

Dept. CSE

B.N.M.I.T ; to accept the name and display at(7a) ; specified position on the screen .model small .stack 200 .data blank10 db ' $' prompt db 'what is your name? :$' rowpos db 10 colpos db 27 myname db 50,0,50 dup(?) .code mov ax,@data ; initialization of data segment mov ds,ax ; inside code segment mov cx,200 ag: lea dx,blank10 mov ah,09 int 21h loop ag mov dh,rowpos mov dl,colpos mov ah,02 mov bh,0 int 10h lea dx,prompt mov ah,09h int 21h lea dx,myname mov ah,0ah int 21h mov ah,4ch int 21h end

MP Manual

; interrupt filling ; entire screen with blank space ; placing cursor at bottom of the screen ; dh=row address ; dl=column address ; bh=page 0 ; interrupt to place the cursor ; interrupt to print the message ; interrupt to accept the message

Dept. CSE

10

B.N.M.I.T ; Factorial of a number using(8a) ; recursive approach .model small .stack 200 .data n dw 4 res dw ? .code mov ax,@data mov ds,ax mov ax,n call fact int 3 ;---factorial procedure--fact proc cmp ax,00 je exit push ax dec ax call fact pop ax mul res mov res,ax ret exit: mov res,1 ret fact endp end

MP Manual

; initialization of data segment ; inside code segment ; procedure finding the factorial ; break point interrupt

; procedure called recursively

Dept. CSE

11

B.N.M.I.T ; NCR using recursion(9A) .model small .stack 200 .data n db 4 r db 2 ncr db ? .code mov ax,@data mov ds,ax mov ncr,0 mov al,n mov bl,r call ncrrec int 3

MP Manual

; initialization of data segment ; inside code segment

; procedure to find ncr ; return address 1

;-------ncr procedure--------ncrrec proc para1: cmp al,bl ; if n=r then ncr=1 je para8 para2: cmp bl,0 ; if r=0 then ncr=1 je para8 para3: cmp bl,1 ; if r=1 then ncr=n je para10 para4: dec al cmp bl,al je para9 para5: push ax push bx call ncrrec para6: pop bx ;return address 2 pop ax dec bl push ax push bx call ncrrec para7: pop bx pop ax ret Dept. CSE 12

B.N.M.I.T para8: inc ncr ret para9: inc ncr para10: add ncr,al ret ncrrec endp end

MP Manual

Dept. CSE

13

B.N.M.I.T ; searching for sub-string in main string(10A)

MP Manual

.model small .stack 200 .data msg1 db 'this is a day' len1 dw ($-msg1) msg2 db 'ias' len2 dw ($-msg2) msg3 db 10,13,'SUBSTRING IS PRESENT','$' msg4 db 10,13,'SUBSTRING IS NOT PRESENT','$' .code mov ax,@data ; initialization of data & extra segment mov ds,ax ; inside code segment mov es,ax lea di,msg1 lea si,msg2 clc cld mov cx,len1 l1: mov al,[si] push si repne scasb jnz notfound push di push cx inc cx sub cx,len2 jb notfound inc si mov cx,len2 dec cx repe cmpsb jz found pop cx pop di pop si jmp l1 notfound: lea dx,msg4 jmp l2 Dept. CSE ; comparing string byte by byte ; scanning the main string byte by byte

; CF=0 ; DF=0

14

B.N.M.I.T found: lea dx,msg3 l2: mov ah,09h int 21h mov ah,4ch int 21h end

MP Manual

; interrupt to print the message

Dept. CSE

15

B.N.M.I.T ; to generate FIBONACCI series(11A) .model small .stack 200 .data n dw 6 str db 30 dup(?) .code mov ax,@data mov ds,ax lea si,str mov [si],0 mov [si+1],1 mov cx,n sub cx,2 back: mov al,[si] add al,[si+1] mov [si+2],al inc si loop back int 3 end

MP Manual

; initialization of data segment ; inside the code segment ;initializing first number ;initializing second number

; adding first & second number ; storing at as third number

; break point interrupt

Dept. CSE

16

B.N.M.I.T ; to display SYSTEM TIME(12A) .model small .stack 200 .data msg db ' hrs : min','$' .code mov ax,@data mov ds,ax mov ah,2ch int 21h mov al,ch mov si,02 l1: mov ah,00 aam or ax,3030h push ax mov dl,ah mov ah,02h int 21h pop ax mov dl,al mov ah,02 int 21h dec si jz exit lea dx,msg mov ah,09h int 21h mov al,cl jmp l1 exit: mov ah,4ch int 21h end ; interrupt to end code segment ; interrupt to print the message ; converting to ascii ; interrupt to ; accept system time

MP Manual

; printing on to screen

Dept. CSE

17

B.N.M.I.T ; to generate DECIMAL UP counter 00 99(13A) print macro space lea dx,space mov ah,09h int 21h endm .model small .stack 200 .data space db " $" w1 db 0 w2 db 0 .code mov ax,@data mov ds,ax st1: mov al,99h mov cx,100 rpt: add al,1 daa push ax push cx call display print space pop cx pop ax loop rpt stop: mov ah,4ch int 21h ;------display procedure-----display proc mov ch,al mov cl,4 ror al,cl and al,0fh add al,30h mov dl,al mov ah,02h int 21h Dept. CSE ; getting first 4-bits ; converting to ascii ; to display the data 18

MP Manual

; initialization of data segment ; inside code segment ; initial value ; count =100 ; conversion to BCD

; procedure to display the number ; space between numbers

B.N.M.I.T mov al,ch and al,0fh add al,30h mov dl,al mov ah,02h int 21h ret display endp end

MP Manual

; converting to ascii ; printing on to screen

Dept. CSE

19

B.N.M.I.T ; to position the cursor (14A) ; at specified row and column ;----macro to read row and col---readnum macro num mov ah,01h ; interrupt to read first number int 21h sub al,'0' mov cl,4 ror al,cl mov num,al mov ah,01 int 21h sub al,'0' add num,al endm ;----macro to print msg ----print macro msg lea dx,msg mov ah,09h int 21h endm ; convertion to decimal from ascii

MP Manual

; placing it to tens place from unit place ; accepting the second digit ; convertion to decimal from ascii ; adding to previous data placed at tens place

.model small .stack 200 .data row db ? col db ? m1 db 10,13,'enter the row:','$' m2 db 10,13,'enter the col:','$' .code mov ax,@data ; initialization of data segment mov ds,ax ; into code segment print m1 readnum row print m2 readnum col mov ah,00 mov al,02 int 10h ; macro to print the message ;macro to read 2-digit number ; macro to print the message ;macro to read 2-digit number ; interrupt to clear the screen

Dept. CSE

20

B.N.M.I.T mov ah,02 mov dh,row mov dl,col mov bh,00 int 10h mov ah,01 int 21h mov ah,4ch int 21h end

MP Manual

; interrupt to position the cursor at specified ; row & column

Dept. CSE

21

B.N.M.I.T ; program to create and to delete a file (15A) print macro msg lea dx,msg mov ah,09h int 21h endm

MP Manual

.model small .stack 200 .data fname db 'c:\masm\jalaja\name.txt',0 m2 db 10,13,'enter 1) to create 2) to delete','$' m3 db 10,13,'FILE CREATED','$' m4 db 10,13,'FILE NOT CREATED','$' m5 db 10,13,'FILE DELETED','$' m6 db 10,13,'FILE NOT FOUND','$' m7 db 10,13,'INVALID CHOICE','$' op db ? fhandle dw ? .code mov ax,@data ; initialization of data segment mov ds,ax ; into code segment mov ah,00 mov al,02 int 10h print m2 mov ah,01 int 21h mov op,al cmp op,'1' je create cmp op,'2' je delete jmp invalid create: mov ah,3ch xor cx,cx mov dx,seg fname mov ds,dx lea dx,fname int 21h jc cerror mov fhandle,ax Dept. CSE ; interrupt to create the file ; initialization into specified seg ; interrupt to clear the screen

; macro to print the message ; interrupt to accept the choice

22

B.N.M.I.T print m3 jmp ter cerror: print m4 jmp ter delete: mov ah,41h xor cx,cx mov dx,seg fname mov ds,dx lea dx,fname int 21h jc derror mov fhandle,ax print m5 jmp ter derror: print m6 jmp ter invalid: print m7 ter: mov ah,4ch int 21h end ***********END OF PART A********* ; interrupt to delete the file

MP Manual

; initialization into specified seg

Dept. CSE

23

B.N.M.I.T ; to check for odd or even(1B)

MP Manual

.model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h msg db 'press any key to come to dos prompt','$' .code mov ax,@data mov ds,ax lea dx,msg mov ah,09h int 21h mov al,8ah mov dx,ctrl out dx,al bg: mov dx,pb in al,dx mov cx,8 mov bl,0 ag: rol al,1 jnc noinbl inc bl noinbl: loop ag mov al,bl mov dx,pc out dx,al mov dx,pa ror bl,1 jc disp00 mov al,0ffh jmp nxt disp00: mov al,00 Dept. CSE 24 ; o/p through port c ; accept the i/p ; interrupt to display the message

; control word decision ; pa=o/p ; pb=i/p

B.N.M.I.T nxt: out dx,al mov dl,0ffh mov ah,06h int 21h jz bg mov ah,4ch int 21h end

MP Manual ; o/p through port a ; interrupt that waits until any key ; or i/p is accepted

Dept. CSE

25

B.N.M.I.T MP Manual ; BCD RING COUNTER(2B1) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h msg db 'press any key to come to dos prompt$' .code mov ax,@data ; initialization of data segment in CS mov ds,ax lea dx,msg mov ah,09h int 21h mov al,8ah mov dx,ctrl out dx,al mov al,01 mov dx,pa back: push ax push dx out dx,al call delay mov dl,0ffh mov ah,06h int 21h jnz exit pop dx pop ax rol al,1 jmp back exit: mov ah,4ch int 21h ;-----delay procedure-----delay proc mov di,2000h tere:mov cx,0ffffh here:loop here dec di jnz tere ret delay endp end Dept. CSE ; interrupt that waits until any key is pessed ; interrupt to display the message ; control word decision

; procedure with suitable delay

26

B.N.M.I.T ; BCD UP(1)-DOWN(1) COUNTER(2B2)

MP Manual

.model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h msg db 'press any key to come to dos prompt$' .code mov ax,@data ; initialization of data segment in CS mov ds,ax lea dx,msg mov ah,09h int 21h mov al,8ah mov dx,ctrl out dx,al mov al,0 back: push ax mov dx,pa out dx,al call delay mov dl,0ffh mov ah,06h int 21h jnz exit mov dx,pb in al,dx ror al,1 pop ax jc up down: sub al,1 das jmp back up: add al,1 daa jmp back exit: mov ah,4ch int 21h Dept. CSE ; interrupt that waits until any key is pessed ; interrupt to display the message ; control word decision

; accepting the i/p from port B

27

B.N.M.I.T ;---delay procedure----delay proc mov di,2000h tere:mov cx,0ffffh here:loop here dec di jnz tere ret delay endp end

MP Manual

; procedure with suitable delay

Dept. CSE

28

B.N.M.I.T ; MULTIPLICATION OF 8 bit * 4 bit(3B)

MP Manual

.model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h msg db 'press any key to come to dos prompt$' .code mov ax,@data ; initialization of data segment in CS mov ds,ax lea dx,msg mov ah,09h int 21h mov al,8ah mov dx,ctrl out dx,al bg: mov dx,pb in al,dx mov bl,al mov dx,pc in al,dx mov cl,4 ror al,cl and al,0fh mul bl mov dx,pa out dx,al mov dx,pc out dx,al mov ah,06h mov dl,0ffh int 21h jz bg mov ah,4ch int 21h end ; interrupt that waits until any key is pessed ; accepting the 1st i/p from port B ; interrupt to display the message

; control word decision

; accepting the 2nd i/p from port

Dept. CSE

29

B.N.M.I.T ;TO DISPLAY FIRE AND HELP ALTERNATIVELY(4B)

MP Manual

.model small .stack 200 .data pa=0d880h pb=0d881h ; port address assigned in order pc=0d882h ctrl=0d883h msg db 'press any to come to dos prompt$' fire db 86h,0ceh,0cfh,8eh blnk db 0ffh,0ffh,0ffh,0ffh help db 8ch,0c7h,86h,89h .code mov ax,@data ; initialization of data segment in CS mov ds,ax lea dx,msg mov ah,09h int 21h mov dx,ctrl mov al,80h out dx,al start: lea si,fire call disp call delay lea si,blnk call disp call delay lea si,help call disp call delay lea si,blnk call disp call delay mov ah,01 int 16h jz start mov ah,4ch int 21h ;-----display procedure---disp proc Dept. CSE ; interrupt that waits until any key is pessed ; interrupt to display the message

; control word decision

30

B.N.M.I.T mov cx,4 nxtchr: mov bl,8 mov al,[si] nxtbit: rol al,1 mov dx,pb out dx,al push ax mov dx,pc mov al,00 out dx,al mov al,11h out dx,al pop ax dec bl jnz nxtbit inc si loop nxtchr ret disp endp ;-----delay procedure-----delay proc mov di,0ffffh tere:mov cx,2000h here:loop here dec di jnz tere ret delay endp end ; giving the clock pulse

MP Manual

; procedure with suitable delay

Dept. CSE

31

B.N.M.I.T

MP Manual

;TO DISPLAY 12 char in rolling fashion(5B) .model small .stack 200 .data pa=0d880h pb=0d881h ; port address assigned in order pc=0d882h ctrl=0d883h msg db 'press any to come to dos prompt$' table db 80h,0c0h,80h,92h, 80h,0c0h,80h,92h , 80h,0c0h,80h,82h .code mov ax,@data ; initialization of data segment in CS mov ds,ax lea dx,msg mov ah,09h int 21h mov dx,ctrl mov al,80h out dx,al start: lea si,table mov cx,12 nxtchr: mov al,[si] call disp call delay mov ah,01 int 16h jnz exit inc si loop nxtchr jmp start exit: mov ah,4ch int 21h ;-----display procedure---disp proc mov bl,8 nxtbit: Dept. CSE ; interrupt to display the message

; control word decision

; interrupt that waits until any key is pessed

32

B.N.M.I.T rol al,1 mov dx,pb out dx,al push ax mov dx,pc mov al,00 out dx,al mov al,11h out dx,al pop ax dec bl jnz nxtbit ret disp endp ;-----delay procedure-----delay proc mov di,0ffffh tere:mov bx,2000h here:dec bx jnz here dec di jnz tere ret delay endp end ; giving the clock pulse

MP Manual

; procedure with suitable delay

Dept. CSE

33

B.N.M.I.T

MP Manual

;TO DISPLAY 12 char in rolling fashion(6B) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h binary dw 0ffffh bcd db 5 dup(?) msg db 'press any to come to dos prompt$' table db 0c0h,0f9h,0a4h,0b0h,99h db 92h,82h,0f8h,80h,98h .code mov ax,@data mov ds,ax lea dx,msg mov ah,09h int 21h mov dx,ctrl mov al,80h out dx,al mov cx,binary mov ax,0 mov bl,0 jcxz exit ag: add al,01 daa jnc noinc add ah,01 mov al,ah daa mov ah,al mov al,00 jnc noinc inc bl Dept. CSE ; initialization of data segment in CS

; interrupt to display the message

; control word decision

34

B.N.M.I.T noinc: loop ag exit: mov bcd+4,bl mov dx,ax mov bl,10h mov ah,0 mov al,dl div bl mov bcd,ah mov bcd+1,al mov ah,0 mov al,dh div bl mov bcd+2,ah mov bcd+3,al call disp mov ah,4ch int 21h ;-----display procedure---disp proc mov cx,5 mov si,0 nxtchr: mov ah,8 mov al,bcd[si] lea bx,table xlat nxtbit: rol al,1 mov dx,pb out dx,al mov bl,al ; push ax mov dx,pc mov al,00 out dx,al mov al,0ffh out dx,al dec ah jz overchk mov al,bl jmp nxtbit overchk: Dept. CSE

MP Manual

; giving the clock pulse

35

B.N.M.I.T call delay inc si loop nxtchr ret disp endp ;-----delay procedure-----delay proc mov di,0ffffh tere:mov bx,2000h here:dec bx jnz here dec di jnz tere ret delay endp end

MP Manual

; procedure with suitable delay

Dept. CSE

36

B.N.M.I.T

MP Manual

; STEPPER MOTOR IN CLOCK WISE(7B) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h n dw 10 msg db 'rotation in clock wise','$' .code mov ax,@data ; initialization of data segment in CS mov ds,ax lea dx,msg mov ah,09h int 21h mov al,80h mov dx,ctrl out dx,al mov cx,n mov dx,pc mov al,88h ag: out dx,al push cx call delay pop cx ror al,1 loop ag mov ah,4ch int 21h ;---delay procedure--delay proc mov di,2000h tere:mov cx,0ffffh here:loop here dec di jnz tere ret Dept. CSE ; output the data through port ; interrupt to display the message

; control word decision

; procedure with suitable delay

37

B.N.M.I.T delay endp end

MP Manual

; STEPPER MOTOR IN ANTI-CLOCK WISE(8B) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h n dw 10 msg db 'rotation in anti-clock wise','$' .code mov ax,@data ; initialization of data segment mov ds,ax lea dx,msg mov ah,09h int 21h mov al,80h mov dx,ctrl out dx,al mov cx,n mov dx,pc mov al,88h ag: out dx,al push cx call delay pop cx rol al,1 loop ag mov ah,4ch int 21h ;---delay procedure--delay proc mov di,2000h tere:mov cx,0ffffh here:loop here dec di jnz tere ret Dept. CSE ; output the data through port ; control word decision

; procedure with suitable delay

38

B.N.M.I.T delay endp end

MP Manual

; STEPPER MOTOR IN CLOCK WISE(n steps)(9B) ; & ANTI-CLOCK WISE(n-steps) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h n dw 10 msg db 'rotation in clock & anti clock wise','$' .code mov ax,@data ; initialization of data segment mov ds,ax lea dx,msg mov ah,09h int 21h mov al,80h mov dx,ctrl out dx,al mov cx,n mov dx,pc mov al,88h ag: out dx,al push cx call delay pop cx ror al,1 loop ag mov cx,n mov dx,pc mov al,88h bg: out dx,al push cx call delay pop cx rol al,1 loop bg Dept. CSE ; output the data through port ; interrupt to display the message

; control word decision

39

B.N.M.I.T mov ah,4ch int 21h ;---delay procedure--delay proc mov di,2000h tere:mov cx,0ffffh here:loop here dec di jnz tere ret delay endp end

MP Manual

; procedure with suitable delay

Dept. CSE

40

B.N.M.I.T

MP Manual

; ROW & COLUMN INFORMATION(10B) ; OF THE KEY PRESSED .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h prompt db 'press any key to come to dos prompt',10,13,'$' m1 db 'the key pressed is :' scancode db ?,10,13,'$' msg db 'the row & col address :' aski db ?,' ',?,10,13,'$' table db '0123456789+-*/.%ce' .code mov ax,@data ; initialization of data segment mov ds,ax mov al,90h mov dx,ctrl out dx,al mov ah,09h lea dx,prompt int 21h ag: mov ah,06 mov dl,0ffh int 21h jnz quit call scan cmp si,0 je ag push ax push bx mov cl,3 rol bh,cl add bh,ah Dept. CSE 41 ; interrupt that waits until any key is pessed ; control word decision ; interrupt to display the message

B.N.M.I.T mov al,bh lea dx,table xlat mov scancode,al lea dx,m1 mov ah,09h int 21h pop bx pop ax add bh,30h mov aski,bh add ah,30h mov aski+2,ah lea dx,msg mov ah,09h int 21h mov di,2fffh mov cx,0ffffh here:loop here dec di jnz here jmp ag quit: mov ah,4ch int 21h ;*****SCAN PROCEDURE****** scan proc mov si,0 mov cx,3 mov bh,0 mov al,80h nxtrow: rol al,1 mov bl,al mov dx,pc out dx,al mov dx,pa in al,dx Dept. CSE ; row selection

MP Manual

; interrupt to display the message

; procedure with suitable delay

; accepting the i/p from port A

42

B.N.M.I.T cmp al,0 jnz keyid mov al,bl inc bh loop nxtrow ret keyid: mov si,1 mov cx,08 mov ah,0 ag2: ror al,1 jc skip inc ah loop ag2 skip: ret scan endp end

MP Manual

Dept. CSE

43

B.N.M.I.T

MP Manual

; SIMPLE CALCULATOR(11B); DOING ADD & SUB .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h result db ? inputs db 3 dup(?) msg db 'enter the input as NUM1 +/- NUM2',10,13,'$' .code mov ax,@data ; initialization of data segment mov ds,ax mov al,90h mov dx,ctrl out dx,al mov ah,09h lea dx,msg int 21h mov cx,3 mov di,0 ag2: push cx ag1: call scan cmp si,0 je ag1 mov cl,3 rol bh,cl add bh,ah mov inputs[di],bh mov bp,20000 tere:mov cx,0ffffh here:loop here dec bp jnz tere inc di pop cx Dept. CSE ; procedure with suitable delay ; control word decision

; interrupt to display the message

44

B.N.M.I.T loop ag2 mov al,inputs cmp inputs+1,0ah jne minus add al,inputs+2 mov result,al jmp quit minus: sub al,inputs+2 mov result,al quit: mov dl,result add dl,30h mov ah,02 int 21h mov ah,4ch int 21h ;*****SCAN PROCEDURE****** scan proc mov si,0 mov cx,3 mov bh,0 mov al,80h nxtrow: rol al,1 mov bl,al mov dx,pc out dx,al mov dx,pa in al,dx cmp al,0 jnz keyid mov al,bl inc bh loop nxtrow ret keyid: mov si,1 mov cx,08 mov ah,0 agg: ror al,1 jc skip inc ah Dept. CSE ; Row selection

MP Manual

; accepting the i/p from port A

45

B.N.M.I.T MP Manual loop agg skip: ret scan endp end ; GENERATION OF SINE WAVE(12B) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h table db 0,2,8,17,30,46,64,84,105,127 db 150,171,191,209,225,238,247,253,255 msg db 'press any key to come to dos prompt','$' .code mov ax,@data ; initialization of data segment mov ds,ax lea dx,msg mov ah,09h int 21h mov dx,ctrl mov al,80h out dx,al start: mov cx,18 lea si,table back: mov al,[si] mov dx,pa out dx,al mov dx,pb out dx,al inc si loop back mov cx,18 bac: mov al,[si] mov dx,pa out dx,al mov dx,pb out dx,al dec si loop bac mov ah,01 Dept. CSE ; interrupt to display the message

; control word decision

; output the data through port

; output the data through port ; output the data through port

46

B.N.M.I.T MP Manual int 16h jz start mov ah,4ch int 21h end ; GENERATION OF HALF-RECTIFIED WAVE(13B) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h table db 0,22,44,63,82,97,110,120,125,127 db 125,120,110,97,82,63,42,22 msg db 'press any key to come to dos prompt','$' .code mov ax,@data ; initialization of data segment mov ds,ax lea dx,msg mov ah,09h int 21h mov dx,ctrl mov al,80h out dx,al start: mov cx,18 lea si,table back: mov al,[si] mov dx,pa out dx,al mov dx,pb out dx,al inc si loop back mov cx,18 back1: mov al,00 mov dx,pa out dx,al mov dx,pb out dx,al loop back1 mov ah,01 int 16h Dept. CSE ; interrupt to display the message

; control word decision

; output the data through port ; output the data through port

; output the data through port

; interrupt that waits until any key is pessed 47

B.N.M.I.T jz start mov ah,4ch int 21h

MP Manual

end ; GENERATION OF FULL-RECTIFIED WAVE(14B) .model small .stack 200 .data pa=0d880h ; port address assigned in order pb=0d881h pc=0d882h ctrl=0d883h table db 0,22,44,63,82,97,110,120,125,127 db 125,120,110,97,82,63,42,22 msg db 'press any key to come to dos prompt','$' .code mov ax,@data ; initialization of data segment mov ds,ax lea dx,msg mov ah,09h int 21h mov dx,ctrl mov al,80h out dx,al start: mov cx,18 lea si,table back: mov al,[si] mov dx,pa out dx,al mov dx,pb out dx,al inc si loop back mov ah,01 int 16h jz start mov ah,4ch int 21h end Dept. CSE 48 ; interrupt that waits until any key is pessed ; interrupt to display the message

; control word decision

; output the data through port

B.N.M.I.T

MP Manual

; ELEVATOR INTERFACE(15B) .model small .stack 200 .data pa=0d880h pb=0d881h pc=0d882h ctrl=0d883h .code mov ax,@data mov ds,ax mov dx,ctrl mov al,82h out dx,al mov dx,pa mov al,0 out dx,al mov al,0f0h out dx,al mov dx,pb scan: in al,dx and al,0fh cmp al,0fh jz scan mov ch,0 findagn: shr al,1 jnc firid inc ch jmp findagn firid: mov bh,ch rol ch,1 add ch,bh add ch,0f0h Dept. CSE 49

; port address assigned in order

; initialization of data segment ; inside the code segment ; control word decision ; initializing all leds to 0 or OFF

; 1st led is ON

; accept the i/p

; servicing floor

B.N.M.I.T mov al,0f0h again: inc al mov dx,pa out dx,al push cx call delay pop cx cmp ch,al jne again down: mov si,5 back: push cx call delay pop cx dec si jnz back and al,0fh out dx,al or al,0f0h dngain: out dx,al push cx call delay pop cx dec al cmp al,0efh jne dngain mov ah,4ch int 21h delay proc mov di,0ffffh there: mov cx,2400h here: loop here dec di jnz there ret delay endp end Dept. CSE ; traversing down ward ; procedure with suitable delay

MP Manual

; procedure with suitable delay

50

B.N.M.I.T

MP Manual

Dept. CSE

51

S-ar putea să vă placă și