Sie sind auf Seite 1von 71

Microprocessor Lab Manual(10CSL48)

1. a) Search a key element in a list of n 16-bit numbers using the Binary search algorithm.
Algorithm Step 1: Initialize the data segment Step 2: Set low and high pointer Step 3: find the mid value Step 4: mid=(low+high)/2 Step 5: Make it even Step 6: Compare a[mid] with the key Step 7: if it is equal display msg1 else msg2 Step 8: stop

Program: data segment a dw 19,10,23,25,24h n dw 5h msg1 db 'successful$' key dw 29h msg2 db 'unsuccessful$' data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov si,0
Dept of CSE Page 1

Microprocessor Lab Manual(10CSL48)


mov cx,n mov ax,cx mov bx,02 mul bx mov di,ax loc1: cmp si,di ja m2 mov bx,si add bx,di shr bx,01 and bx,0fffeh mov ax,a[bx] cmp ax,key jz m1 jb loc2 mov di,bx sub di,02 jmp loc1 loc2: mov si,bx add si,02 jmp loc1 m2: lea dx,msg2 jmp print m1: lea dx,msg1 jmp print
Dept of CSE Page 2

Microprocessor Lab Manual(10CSL48)


print: mov ah,09h int 21h mov ah,4ch int 21h code ends end start

Output: Input 5 Successful

Dept of CSE

Page 3

Microprocessor Lab Manual(10CSL48)


2. a) Write two ALP modules stored in two different files; one module is to read a character from the keyboard and the other one is to display a character. Use the above two modules to read a string of characters from the keyboard terminated by the carriage return and print the string on the display in the next line.
Algorithm step1: Include read & display macro step2: Initialize data segment step3: Display msg step4: Invoke Macro to read a character with out echo step5: Check for carriage return key, if it true terminate step6: If it is not Carriage return invoke Macro Disp to Display Character step7: Repeat Step 4 & step5 till enter key step8: Stop if enter key is pressed Program: data segment blank db 0ah,'$' a dw 20 dup(?) data ends code segment assume cs:code, ds:data include r.asm include d.asm start: mov ax,data mov ds,ax lea si,a mov cx,0
Dept of CSE Page 4

Microprocessor Lab Manual(10CSL48)


loc1: read cmp al,0dh jz loc2 mov [si],al inc si inc cx jmp loc1 loc2: lea dx,blank mov ah,09h int 21h lea si,a displ: mov dl,[si] display inc si loop displ mov ah,4ch int 21h code ends end start Output: Input: Enter the string Madam Output: Entered String is Madam

Dept of CSE

Page 5

Microprocessor Lab Manual(10CSL48)


3. a) Sort a given set of n numbers in ascending order using the Bubble Sort algorithm.
Algoritm Step1: Initialize the data segment Step2: Initialize 8-Bit array Step3: Use bx as counter for n-1 passes Step4: Use cx as the counter for comparison Step5: Compare a[i] with a[i+1] Step6: If a[i]>=a[i+1] if True do exchange other wise no exchange Step7: Repeat step 5 & 6 for the next set of numbers till the comparisons are equal to Zero Step8: Repeat step 4 to 7 till Passes equal to Zero Step9: Stop

Program: data segment a db 66h,77h,22h,33h,44h,99h,11h,55h,88h s dw $-a data ends code segment assume cs:code, ds:data start: mov ax,data mov ds,ax mov bx,s dec bx outloop: mov cx,bx
Dept of CSE Page 6

Microprocessor Lab Manual(10CSL48)


mov si,00h inloop: mov al,a[si] inc si cmp al,a[si] jb next xchg al,a[si] mov a[si-1],al next: loop inloop dec bx jnz outloop int 3h align 16 code ends end start

Output: Input: 66h,77h,22h,33h,44h,99h,11h,55h,88h

Dept of CSE

Page 7

Microprocessor Lab Manual(10CSL48)


4. a) Read an alphanumeric character and display its equivalent ASCII code at the center of the screen.
Algorithm: step1: Initialize the data segment step2: Display Msg 1 step3: Read data from Keyboard without echo step4: Check for ESC Key if yes exit step5: All AL Contents the ASCII Code for the key pressed step6: Make it unpacked convert that in to Two ASCII codes & place it in res step7: Set cursor at 12, 40 step8: Display ASCII code of the key pressed

Program: data segment ascii db 2 dup(?) data ends code segment assume cs:code, ds:data start: mov ax,data mov ds,ax mov ah,00h mov al,02h int 10h mov ah,01h int 21h

Dept of CSE

Page 8

Microprocessor Lab Manual(10CSL48)


mov bl,al mov cl,04 shr al,cl add al,30h mov ascii,al mov al,bl and al,0fh cmp al,09h jbe down add al,07h down: add al,30h mov ascii+1,al mov dh,0bh mov dl,25h mov ah,02h int 10h mov bh,02h mov si,00h l2: mov dl,ascii[si] mov ah,02h int 21h inc si dec bh jnz l2 mov ah,4ch
Dept of CSE Page 9

Microprocessor Lab Manual(10CSL48)


int 21h align 16 code ends end start

Output: Input: Enter the Alpha Numeric Character: A output: 41

Dept of CSE

Page 10

Microprocessor Lab Manual(10CSL48)


5. a) Reverse a given string and check whether it is a palindrome or not.
Algorithm step1: Initialize the String in Data segment step2: Initialize Msg's in Data Segment step3: Initialize Data & Extra Segment step4: Find the length of the string step5: Reverse the String step6: Compare original String with reverse String step7: if it is equal Display Msg1 else Msg2 step8: Terminate Program: data segment msg1 db 'it is a palindrome$' msg2 db 'it is not a palindrome$' str db 'rever$' rstr dw $-str data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov es,ax mov cx,05h lea si,str

Dept of CSE

Page 11

Microprocessor Lab Manual(10CSL48)


lea di,rstr add di,cx dec di rev: mov al,[si] mov [di],al inc si dec di loop rev cld lea si,str lea di,rstr mov cx,05h repe cmpsb je palindrome lea dx,msg2 jmp print Palindrome: lea dx,msg1 print: mov ah,09h int 21h mov ah,4ch int 21h align 16 code ends end start

Dept of CSE

Page 12

Microprocessor Lab Manual(10CSL48)


Output: Input: Enter the String: Madam Output: Entered String is Palindrome

Dept of CSE

Page 13

Microprocessor Lab Manual(10CSL48)


6. a) Read two strings, store them in locations STR1 and STR2. Check whether they are equal or not and display appropriate messages. Also display the length of the stored strings.
ALGORITHM: step1: Initialize the String1 & String2 in Data segment step2: Initialize Msg's in Data Segment step3: Initialize Data & Extra Segment step4: Find the length of the string1 & String2 step5: Compare Len1 & Len2 Step6: if it is not equal display msg other wise go to String Comparison step7: Terminate Program data segment m1 db 10,13,'enter the string1:$' m2 db 10,13,'enter the string2:$' m3 db 10,13,'length of string1:$' m4 db 10,13,'length of string2:$' m5 db 10,13,'string1 is equal to string2$' m6 db 10,13,'string1 is not equal to string2$' str1 db 80 dup(40) str2 db 80 dup(40) l1 db ? l2 db ? data ends disp macro msg
Dept of CSE Page 14

Microprocessor Lab Manual(10CSL48)


lea dx,msg mov ah,09h int 21h endm code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov es,ax disp m1 lea dx,str1 call read disp m2 lea dx,str2 call read mov al,[str1+1] mov l1,al mov al,[str2+1] mov l2,al cmp al,l1 jne strnoteq mov ch,00 mov cl,l1 lea si,str1 lea di,str2
Dept of CSE Page 15

Microprocessor Lab Manual(10CSL48)


cld jne strnoteq disp m5 jmp next strnoteq: disp m6 next: disp m3 mov al,l1 call displ disp m4 mov al,l2 call displ mov ah,4ch int 21h read proc mov ah,0ah int 21h ret read endp displ proc aam mov bx,ax add bx,3030h mov ah,02h mov dl,bh int 21h
Dept of CSE Page 16

Microprocessor Lab Manual(10CSL48)


mov dl,bl int 21h ret displ endp code ends end start

Output: Input: Enter First String: Oxford Enter the Second String: Oxford

Output: Strings are equal Length of String is six

Dept of CSE

Page 17

Microprocessor Lab Manual(10CSL48)


7. a) Read your name from the keyboard and display it at a specified location on the screen after the message What is your name? You must clear the entire screen before display.

Algorithm: Step1: Initialize msg in Data segment Step2: Initialize data segment Step3: Read name from keyboard Step4: Press enter key to go for next line & display the msg Step5: Call procedure to clear the screen Step6: call procedure to set the cursor & display msg Step7: Stop

program:

data segment myname db 20 dup(0,'$') enter db 10,13,'enter the name:$' msg db 10,13,' data ends your name is:$'

code segment assume cs:code, ds:data start: mov ax,data mov ds,ax
Dept of CSE Page 18

Microprocessor Lab Manual(10CSL48)


lea dx,enter mov ah,09h int 21h mov cx,0000h lea si,myname input: mov ah,01h int 21h cmp al,0dh jz count mov [si],al inc si inc cx jmp input count: mov ah,0fh int 10h mov ah,00h mov al,02h int 10h mov bh,00h mov dh,20 mov dl,30 mov ah,02h int 10h lea dx,msg mov ah,09h
Dept of CSE Page 19

Microprocessor Lab Manual(10CSL48)


int 21h lea dx,myname mov ah,09h int 21h mov ah,4ch int 21h code ends end start

output: Enter name: Basha What is ur name: Basha

Dept of CSE

Page 20

Microprocessor Lab Manual(10CSL48)


8. a) Compute nCr using recursive procedure. Assume that n and r are non-negative integers.
Algorithm: Step1: Initialize input n,r step2: Reserve memory ncr to store the result in data segment step3: Load ax with n & bx with r step4: call recursive function step5: Stop step6: If n=r or r=0 then ncr=1 step7: If r=1 or r=n-1 then ncr=n step8: If step 6 & 7 are false then find ncr recursively step9:Stop

program: data segment n dw 5 r dw 4 ncr dw 0 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,n mov bx,r
Dept of CSE Page 21

Microprocessor Lab Manual(10CSL48)


call ncrpro int 3h align 16 ncrpro proc cmp bx,ax je res1 cmp bx,01 je resn dec ax cmp bx,ax je incr push ax push bx call ncrpro pop bx pop ax dec bx push ax push bx call ncrpro pop bx pop ax ret res1: inc ncr ret
Dept of CSE Page 22

Microprocessor Lab Manual(10CSL48)


incr: inc ncr resn: add ncr,ax ret ncrpro endp code ends end start

Output: A

Dept of CSE

Page 23

Microprocessor Lab Manual(10CSL48)


9. a) Read the current time from the system and display it in the standard format on the screen.
Algorithm: Step1: Initialize the data segment step2: Display Msg step3: Initialize ah with 2ch to get the system time step4: call procedure to convert binary to BCD step5: Display converted BCD number on the screen using DOS interrupt Step6: Return back to main when job is done step7: Stop program: data segment msg db 10,13,'current time is:$' data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax lea dx,msg mov ah,09h int 21h mov ah,2ch int 21h mov al,ch call disp mov dl,':' mov ah,02h
Dept of CSE Page 24

Microprocessor Lab Manual(10CSL48)


int 21h mov al,cl call disp mov dl,':' mov ah,02h int 21h mov al,dh call disp mov ah,4ch int 21h disp proc aam add ax,3030h mov bx,ax mov dl,bh mov ah,02h int 21h mov dl,bl mov ah,02h int 21h ret disp endp code ends end start output: Current Time is : 22:05
Dept of CSE Page 25

Microprocessor Lab Manual(10CSL48)


10. a) Write a program to simulate a Decimal Up-counter to display 00- 99.
Algorithm: Step1: Initialize the data segment Step2: Display Msg Step3: Call procedure to set cursor at center (12, 40) Step4: Call procedure to display counter Step5: Provide delay Step6: Repeat steps 3,4 & 5 till Counter = 99 Step7: Stop count any time by pressing any key Step8: Stop

Program: data segment msg db 10,13,'press any key to quit:$' data ends code segment assume cs:code, ds:data start:mov ax,data mov ds,ax lea dx,msg mov ah,09h int 21h mov ah,00 mov al,00 next_num: push ax
Dept of CSE Page 26

Microprocessor Lab Manual(10CSL48)


call setcursor call disp call delay mov ah,01h int 16h jnz exit pop ax add al,01 daa cmp al,0 jnz next_num exit: mov ah,4ch int 21h setcursor proc mov ah,02h mov dh,12 mov dl,40 int 10h ret setcursor endp disp proc mov bl,al mov dl,al mov cl,04 shr dl,cl
Dept of CSE Page 27

Microprocessor Lab Manual(10CSL48)


add dl,30h mov ah,02h int 21h mov dl,bl and dl,0fh add dl,30h mov ah,02h int 21h ret disp endp delay proc mov bx,0ffffh b2: mov cx,0fffh b1: loop b1 dec bx jnz b2 ret delay endp code ends end start

Output: The counter is running from 00 to 99 successfully

Dept of CSE

Page 28

Microprocessor Lab Manual(10CSL48)


11. a) Read a pair of input co-ordinates in BCD and move the cursor to the specified location on the screen.
Algorithm: Step1: Declare Macro Step2: Initailze Msg in Data Segment Step3: Reserve the Memory for row & col Step4: Initailze Data segment Step5: Display Msg1 Step6: Read row Number Step7: Display Msg2 Step8: Read col number Step9: Set the cursor to respective row & col given by user Step10: Display Msg3 Step11: Press any key to exit

Program: data segment msg1 db 10,13,'enter the row no(min:00 & max:24):$' msg2 db 10,13,'enter the col no(min:00 & max:77):$' msg3 db 10,13,'press any key to quit:$' row db ? col db ? data ends

disp macro msg


Dept of CSE Page 29

Microprocessor Lab Manual(10CSL48)


lea dx,msg mov ah,09h int 21h endm code segment assume cs:code,ds:data start: mov ax,data mov ds,ax disp msg1 call read mov row,al disp msg2 call read mov col,al disp msg3 mov ah,02h mov dh,row mov dl,col int 10h mov ah,08h int 21h mov ah,4ch int 21h read proc mov ah,01h
Dept of CSE Page 30

Microprocessor Lab Manual(10CSL48)


int 21h and al,0fh mov bl,al mov ah,01h int 21h and al,0fh mov ah,bl aad ret read endp code ends end start

output: enter the row no(min:00 & max:24):24:12 enter the col no(min:00 & max:77):40

Dept of CSE

Page 31

Microprocessor Lab Manual(10CSL48)


12. a) Write a program to create a file (input file) and to delete an existing file.
Algorithm: Step1: Declare Macro Step2: Initialize msg in data segment Step3: Initialize data segment Step4: call the procedure for creating & then deleting the file Step5: if Creation & deletion Procedures fail Error Step6: Stop

Program: .MODEL SMALL DISPLAY MACRO MSG LEA DX, MSG MOV AH, 09H INT 21H ENDM .DATA MSG1 DB 0DH, 0AH, "ENTER THE FILE NAME :: $"

MSG2 DB 0DH, 0AH, "FILE CREATED SUCCESSFULLY $" MSG3 DB 0DH, 0AH, "CREATION FAILED.$" MSG4 DB 0DH, 0AH, "ENTER THE FILE NAME TO DELETE :: $" MSG5 DB 0DH, 0AH, "DELETED SUCCESSFULLY $" MSG6 DB 0DH, 0AH, "DELETION FAILED $" FNAME DB 40H DUP (?)

Dept of CSE

Page 32

Microprocessor Lab Manual(10CSL48)


FNAME2 DB 40H DUP (?) .CODE START : MOV AX, @DATA MOV DS, AX DISPLAY MSG1 MOV SI, OFFSET FNAME BACK: MOV AH, 01H INT 21H CMP AL, 0DH JE NEXT MOV [SI], AL INC SI JMP BACK NEXT: MOV [SI], BYTE PTR '$' LEA DX, FNAME MOV CX, 00H MOV AH, 3CH INT 21H JC FAILED DISPLAY MSG2 JMP NEXT1 FAILED: DISPLAY MSG3 NEXT1: DISPLAY MSG4 MOV SI, OFFSET FNAME2 BACK1: MOV AH, 01H
Dept of CSE Page 33

Microprocessor Lab Manual(10CSL48)


INT 21H CMP AL, 0DH JE NEXT2 MOV [SI], AL INC SI JMP BACK1 NEXT2 : MOV [SI], BYTE PTR '$' LEA DX, FNAME2 MOV AH, 41H INT 21H JC DFAIL DISPLAY MSG5 JMP FINAL DFAIL: DISPLAY MSG6 FINAL: MOV AH, 4CH INT 21H END START

output: Input: Enter the fail name to create: Enter the fail name to delete: output: Fail created successfully

Dept of CSE

Page 34

Microprocessor Lab Manual(10CSL48) Hardware Interfacing Programs 1b) Read the status of eight input bits from the Logic Controller Interface and display FF if it is the parity of the input read is even; otherwise display 00.
Program
data segment pa equ 0b400h pb equ 0b401h cr equ 0b403h cw db 83h msg db'no of 1s:$' data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm inpb macro mov dx,pb in al,dx endm outpa macro mov dx,pa out dx,al endm exit macro mov ah,4ch
Dept of CSE Page 35

Microprocessor Lab Manual(10CSL48)


int 21h endm code segment assume cs:code,ds:data start: initds init8255 inpb mov bl,al mov bh,00 mov cx,08 next_bit: ror al,01 jnc next inc bh next: loop next_bit mov al,bl or al,al jpe led_glow mov al,00h disp: outpa call delay lea dx,msg mov ah,09h int 21h mov dl,bh add dl,30h mov ah,02h int 21h exit led_glow: mov al,0ffh jmp disp delay proc
Dept of CSE Page 36

Microprocessor Lab Manual(10CSL48)


mov ax,0fffh b2: mov cx,0ffffh b1: loop b1 dec ax jnz b2 ret delay endp code ends end start

Dept of CSE

Page 37

Microprocessor Lab Manual(10CSL48) 2b) Implement a BCD Up-Down Counter on the Logic Controller Interface. Program:
data segment pa equ 0b400h pb equ 0b401h cw db 82h cr equ 0b403h msg1 db 10,13,"1.BCD up down counter","2.Ring Counter" msg2 db 10,13, "Enter your choice$" msg3 db 10,13, "Press any key to quit$" msg4 db 10,13, "Invalid choice$" data ends initds macro mov ax,data mov ds,ax endm init_8255 macro mov al,cw mov dx,cr out dx,al
Dept of CSE Page 38

Microprocessor Lab Manual(10CSL48)


endm disp macro msg lea dx,msg mov ah,09h int 21h endm inpb macro mov dx,pb in al,dx endm outpa macro mov dx,pa out dx,al endm exit macro mov ah,4ch int 21h endm code segment assume cs:code,ds:data start:
Dept of CSE Page 39

Microprocessor Lab Manual(10CSL48)


initds init_8255 disp msg1 disp msg2 mov ah,01h int 21h cmp al,'1' je BCD cmp al,'2' je ring disp msg4 exit BCD:disp msg3 mov al,0 up: outpa call delay call kbhit add al,01 daa cmp al,099h jne up
Dept of CSE Page 40

Microprocessor Lab Manual(10CSL48)


down: outpa call delay call kbhit add ah,099h daa cmp al,099 jne down exit ring:disp msg3 mov al,01h next: outpa call delay call kbhit ror al,1 jmp next delay proc mov bx,0fffh b2: mov cx,0ffffh b1: loop b1 dec bx
Dept of CSE Page 41

Microprocessor Lab Manual(10CSL48)


jnz b2 ret delay endp kbhit proc push ax mov ah,01h int 16h jnz done pop ax ret done: exit kbhit endp code ends end start

3b) Read the status of two 8-bit inputs (X & Y) from the Logic Controller Interface and display X*Y. Program
data segment pa equ 0b400h pb equ 0b401h cw db 82h cr equ 0b403h
Dept of CSE Page 42

Microprocessor Lab Manual(10CSL48)


m1 db 10,13,'Set value for X,then press any key$' M2 db 10,13,'Set value for Y,then press any key$' data ends initds macro mov ax,data mov ds,ax endm disp macro msg lea dx,msg mov ah,09h int 21h endm init_8255 macro mov al,cw mov dx,cr out dx,al endm inpb macro mov dx,pb in al,dx endm outpa macro mov dx,pa out dx,al endm exit macro mov ah,4ch int 21h
Dept of CSE Page 43

Microprocessor Lab Manual(10CSL48)


endm code segment assume cs:code,ds:data start: initds init_8255 disp m1 mov ah,08h int 21h inpb mov bl,al disp m2 mov ah,08h int 21h inpb mul bl outpa call delay mov al,ah outpa exit delay proc mov bx,0fffh b2:mov cx,0ffffh b1:loop b1 dec bx jnz b1 ret delay endp code ends end start
Dept of CSE Page 44

Microprocessor Lab Manual(10CSL48)

4 b) Display messages FIRE and HELP alternately with flickering effects on a 7segment display interface for a suitable period of time. Ensure a flashing rate that makes it easy to read both the messages (Examiner does not specify these delay values nor is it necessary for the student to compute these values). Program
data segment pc equ 0b402h pb equ 0b401h cw db 80h cr equ 0b403h m1 db 10,13,"Press any key to quit$" msg1 db 86h,88h,0cfh,8eh msg2 db 8ch,0c7h,86h,89h data ends initds macro mov ax,data mov ds,ax endm init_8255 macro mov al,cw mov dx,cr out dx,al endm outpb macro mov dx,pb out dx,al endm
Dept of CSE Page 45

Microprocessor Lab Manual(10CSL48)


outpc macro mov dx,pc out dx,al endm exit macro mov ah,4ch int 21h endm code segment assume cs:code, ds:data start: initds init_8255 lea dx,m1 mov ah,09h int 21h lea si,msg1 call disp call delay lea si,msg2 call disp call delay mov ah,01h int 16h

jz start mov ah,4ch int 21h disp proc


Dept of CSE Page 46

Microprocessor Lab Manual(10CSL48)


mov cx,04 next_char: mov bl,08 mov al,[si] next_bit: rol al,1 outpb push ax mov al,00h outpc mov al,11h outpc pop ax dec bl jnz next_bit inc si loop next_char ret disp endp delay proc mov bx,0fffh b2: mov cx,0ffffh b1: loop b1 dec bx jnz b2 ret delay endp code ends end start

Dept of CSE

Page 47

Microprocessor Lab Manual(10CSL48) 5b) Assume any suitable message of 12 characters length and display it in the rolling fashion on a 7-segment display interface for a suitable period of time. Ensure a flashing rate that makes it easy to read both the messages. (Examiner does not specify these delay values nor is it necessary for the student to compute these values). Program
data segment pb equ 0b401h pc equ 0b402h cr equ 0b403h cw db 80h m1 db 10,13,"press any key to exit$" ssc db 80h,0c0h,80h,92h,0ffh,0cfh,88h,92h,80h,0c0h,80h,82h data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm outpb macro mov dx,pb out dx,al endm outpc macro
Dept of CSE Page 48

Microprocessor Lab Manual(10CSL48)


mov dx,pc out dx,al endm code segment assume cs:code,ds:data start: initds init8255 lea dx,m1 mov ah,09h int 21h lea si,ssc mov cx,12 next_char: mov al,[si] call disp_char call delay call kbhit inc si loop next_char jmp start kbhit proc mov ah,1 int 16h jnz exit ret exit: mov ah,4ch int 21h kbhit endp disp_char proc mov bl,8 nxtbit: rol al,1
Dept of CSE Page 49

Microprocessor Lab Manual(10CSL48)


outpb push ax mov al,00h outpc mov al,11h outpc pop ax dec bl jnz nxtbit ret disp_char endp delay proc mov bx,0fffh b2: b1: mov di,0ffffh dec di jnz b1 dec bx jnz b2 ret delay endp code ends end start

Dept of CSE

Page 50

Microprocessor Lab Manual(10CSL48) 6 b) Convert a 16-bit binary value (assumed to be an unsigned integer) to BCD and display it from left to right and right to left for specified number of times on a 7-segment display interface. Program
data segment pb equ 0b401h pc equ 0b402h cr equ 0b403h cw db 80h m1 db 10,13,"press any key to exit$" msg db 0ffh,0ffh,0ffh,0ffh,?,?,?,?,0ffh,0ffh,0ffh,0ffh table db 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h,80h,98h bcd db 5 dup(?) num dw 00ffh data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm outpb macro mov dx,pb out dx,al endm outpc macro mov dx,pc
Dept of CSE Page 51

Microprocessor Lab Manual(10CSL48)


out dx,al endm code segment assume cs:code,ds:data start: initds init8255 lea dx,m1 mov ah,09h int 21h call bin_ssc start1: mov bh,10 lea di,msg back: mov si,di push bx call disp_msg call delay call kbhit pop bx inc di dec bh jnz back mov bh,10 lea di,msg+9 back1: mov si,di push bx call disp_msg call delay call kbhit pop bx dec di dec bh
Dept of CSE Page 52

Microprocessor Lab Manual(10CSL48)


jnz back1 jmp start1 bin_ssc proc lea si,bcd mov ax,num mov bx,10000 call conv mov bx,1000 call conv mov bx,100 call conv mov bx,10 call conv mov [si],dl lea si,bcd lea di,msg+8 lea bx,table mov cx,5 next: mov al,[si] xlat mov [di],al dec di inc si loop next ret bin_ssc endp conv proc mov dx,0 div bx mov [si],al mov ax,dx
Dept of CSE Page 53

Microprocessor Lab Manual(10CSL48)


inc si ret conv endp kbhit proc mov ah,1 int 16h jnz exit ret exit: mov ah,4ch int 21h kbhit endp disp_msg proc mov cx,4 next_char: nxtbit: rol al,1 outpb push ax mov al,00h outpc mov al,11h outpc pop ax dec bl jnz nxtbit inc si loop next_char ret disp_msg endp delay proc mov bx,05ffh
Dept of CSE Page 54

mov bl,8

mov al,[si]

Microprocessor Lab Manual(10CSL48)


b2: b1: mov cx,0ffffh loop b1 dec bx jnz b2 ret delay endp code ends end start

7b) Scan a 8 x 3 keypad for key closure and to store the code of the key pressed in a memory location or display on screen. Also display row and column numbers of the key pressed. Program
data segment pa equ 0b400h pb equ 0b401h pc equ 0b402h cr equ 0b403h m1 db 10,13,10,13,"enter key is:$" m2 db 10,13,10,13,"row number is:$" m3 db 10,13,10,13,"column number is:$" m4 db 10,13,10,13,"press 'C'from system keyboard to continue$" m5 db 10,13,10,13,"press any key from KB_INTERFACE$" row db ? col db ? cw db 90h data ends initds macro mov ax,data
Dept of CSE Page 55

Microprocessor Lab Manual(10CSL48)


mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm disp_msg macro msg lea dx,msg mov ah,09h int 21h endm outpc macro mov dx,pc out dx,al endm inpa macro mov dx,pa in al,dx endm code segment assume cs:code,ds:data start: initds init8255 disp_msg m5 mov al,80h mov row,1 mov col,1 mov ch,0 mov bl,3 mov al,80h
Dept of CSE Page 56

Microprocessor Lab Manual(10CSL48)


nextrow: rol al,1 mov bh,al outpc mov cl,8 inpa nextcol: ror al,1 jc display inc ch inc col dec cl jnz nextcol mov col,1 inc row mov al,bh dec bl jnz nextrow start1: jmp start display: disp_msg m1 mov dl,ch cmp dl,0ah jc digit add dl,07h digit: add dl,30h call disp_char add row,30h add col,30h disp_msg m2 mov dl,row call disp_char disp_msg m3
Dept of CSE Page 57

Microprocessor Lab Manual(10CSL48)


mov dl,col call disp_char disp_msg m4 mov ah,8 int 21h push ax disp_msg m5 pop ax cmp al,'c' jz start1 mov ah,4ch int 21h disp_char proc mov ah,2 int 21h ret disp_char endp code ends end start

Dept of CSE

Page 58

Microprocessor Lab Manual(10CSL48) 8b) Drive a Stepper Motor interface to rotate the motor in specified direction (clockwise or counter-clockwise) by N steps (Direction and N are specified by the examiner). Introduce suitable delay between successive steps. (Any arbitrary value for the delay may be assumed by the student). Program
data segment pa equ 0b400h cr equ 0b403h step_size db 90h cw db 80h data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm outpa macro mov dx,pa out dx,al endm code segment assume cs:code,ds:data start: initds init8255 mov bl,step_size
Dept of CSE Page 59

Microprocessor Lab Manual(10CSL48)


mov al,88h back: outpa call delay rol al,1 dec bl jnz back mov ah,4ch int 21h delay proc push bx mov bx,01ffh b2: b1: mov cx,0fffh loop b1 dec bx jnz b2 pop bx ret delay endp code ends end start

Dept of CSE

Page 60

Microprocessor Lab Manual(10CSL48) 9b) Generate the Sine Wave using DAC interface (The output of the DAC is to be displayed on the CRO). Program
data segment pa equ 0b400h pb equ 0b401h cr equ 0b403h cw db 80h table db 80h,96h,0abh,0c0h,0d2h,0e2h,0eeh,0f8h,0feh,0ffh db 0feh,0f8h,0eeh,0e2h,0d2h,0c0h,0abh,96h,80h db 69h,54h,40h,2dh,1dh,11h,07h,01h,00h db 01h,07h,11h,1dh,2dh,40h,54h,69h,80h msg db 10,13,"press any key to exit$" data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al
Dept of CSE Page 61

Microprocessor Lab Manual(10CSL48)


endm disp_msg macro msg lea dx,msg mov ah,09h int 21h endm outpa macro mov dx,pa out dx,al endm code segment assume cs:code,ds:data start: initds init8255 disp_msg msg label1: mov cx,25h lea si,table back: mov al,[si] outpa call delay inc si
Dept of CSE Page 62

Microprocessor Lab Manual(10CSL48)


loop back mov ah,1h int 16h jz label1 mov ah,4ch int 21h delay proc mov bx,0fffh l2: dec bx jnz l2 ret delay endp code ends end start

Dept of CSE

Page 63

Microprocessor Lab Manual(10CSL48) 10b) Generate a Half Rectified Sine wave form using the DAC interface. (The output of the DAC is to be displayed on the CRO). Program
data segment pa equ 0b400h cr equ 0b403h cw db 80h table db 96h,0abh,0c0h,0d2h,0e2h,0eeh,0f8h,0feh,0ffh db 0feh,0f8h,0eeh,0e2h,0d2h,0c0h,0abh,96h,80h msg db 10,13,'preee any key to exit$' data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm outpa macro mov dx,pa out dx,al endm code segment assume cs:code ,ds:data start: initds init8255
Dept of CSE Page 64

Microprocessor Lab Manual(10CSL48)


lea dx,msg mov ah,09h int 21h l1: mov cx,12h lea si,table back: mov al,[si] outpa call delay inc si loop back call toff mov ah,01h int 16h jz l1 mov ah,4ch int 21h delay proc mov bx,0fffh l2: dec bx jnz l2 ret delay endp toff proc mov cx,09fffh b1: loop b1 ret toff endp code ends end start

Dept of CSE

Page 65

Microprocessor Lab Manual(10CSL48) 11b) Generate a Fully Rectified Sine waveform using the DAC interface. (The output of the DAC is to be displayed on the CRO). Program
data segment pa equ 0b400h cr equ 0b403h cw db 80h table db 96h,0abh,0c0h,0d2h,0e2h,0eeh,0f8h,0feh,0ffh db 0feh,0f8h,0eeh,0e2h,0d2h,0c0h,0abh,96h,80h msg db 10,13,'preee any key to exit$' data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm outpa macro mov dx,pa out dx,al endm code segment assume cs:code ,ds:data start:initds init8255 lea dx,msg mov ah,09h int 21h
Dept of CSE Page 66

Microprocessor Lab Manual(10CSL48)


l1:mov cx,12h lea si,table back:mov al,[si] outpa call delay inc si loop back mov ah,01h int 16h jz l1 mov ah,4ch int 21h delay proc mov bx,0fffh l2: dec bx jnz l2 ret delay endp code ends end start

Dept of CSE

Page 67

Microprocessor Lab Manual(10CSL48) 12 b) Drive an elevator interface in the following way: i. Initially the elevator should be in the ground floor, with all requests in OFF state. ii. When a request is made from a floor, the elevator should move to that floor, wait there for a couple of seconds (approximately), and then come down to ground floor and stop. If some requests occur during going up or coming down they should be ignored. Program
data segment pa equ 0b400h pb equ 0b401h cr equ 0b403h msg db 10,13,"press any key to exit$" floor db 00h,03h,06h,09h,0e0h,0d3h,0b6h,79h cw db 82h data ends initds macro mov ax,data mov ds,ax endm init8255 macro mov al,cw mov dx,cr out dx,al endm disp_msg macro msg lea dx,msg mov ah,09h int 21h endm outpa macro mov dx,pa
Dept of CSE Page 68

Microprocessor Lab Manual(10CSL48)


out dx,al endm inpb macro mov dx,pb in al,dx endm code segment assume cs:code,ds:data start: initds init8255 disp_msg msg mov bl,0 loop1: mov al,bl or al,0f0h outpa lea si,floor loop2: call kbhit inpb or al,0f0h mov cl,al sub al,0ffh jz loop2 loop3: mov al,cl ror al,1 mov cl,al jnc decide inc si jmp loop3 decide: call delay mov al,[si]
Dept of CSE Page 69

Microprocessor Lab Manual(10CSL48)


sub al,bl js down jz reset up: inc bl mov al,bl or al,0f0h outpa jmp decide down: dec bl mov al,bl or al,0f0h outpa jmp decide reset: add si,4 mov al,[si] outpa jmp loop1 kbhit: mov ah,1 int 16h jnz exit ret exit: mov ah,4ch int 21h delay proc push cx push bx mov bx,0ffh b2: b1: mov cx,0ffffh loop b1 dec bx jnz b2
Dept of CSE Page 70

Microprocessor Lab Manual(10CSL48)


pop bx pop cx ret delay endp code ends end start

Dept of CSE

Page 71

Das könnte Ihnen auch gefallen