mit
December 13, 2016 | Author: Pooja Bk | Category: N/A
Short Description
lab manual...
Description
Micropro. & Interfacing Techniques (PU)
L-1
Lab Manual
List of Experiments Group A
Program 1 :
Write X86/64 Assembly language program (ALP) to add array of N hexadecimal numbers stored in the memory. Accept input from the user.
Explanation :
Consider that a block of N bytes is present at source location. Let the number of bytes N = 10 for example. We have to add these N bytes. We will initialize this as count in the CX register. We know that source address is in the SI register. This SI register will act as pointer. Clear the direction flag. Using ADD instruction add the contents, byte by byte of the block. Increment SI to point to next element. Decrement the counter and add the contents till all the contents are added. Result is stored in AL. Display the contents using display routine. For example : Block Data : 01 02 03 04 05 06 07 08 09 0A Result : 01 + 02 + 03 + 04 + 05 + 06 + 07 + 08 + 09 + 0A = 37 H
Algorithm : Step I : Initialise the data segment. Step II : Initialise SI as pointer with source address. Step III : Initialise CX register with count. Step IV : Initialise direction flag to zero. Step V : Add data, byte by byte. Step VI : Increment pointer i.e. SI. Step VII : Decrement counter CX. Step VIII : Check for count in CX, if not zero goto step V else goto step IX. Step IX : Display the result of addition. Step X : Stop.
Flowchart : Refer flowchart A.1.
Micropro. & Interfacing Techniques (PU)
l2:
Lab Manual
Program :
Label
l1:
L-2
Instruction .model small .data blk1 db 01, 02, 03, 04, 05, 06, 07, 08, 09, 0AH count dw 0AH .code mov ax, @data mov ds, ax mov ax, 0 mov si, offset blk1 mov cx, count cld add al, [si]
Comment
initialise data segment
initialise pointer initialise counter df=0 add numbers
inc si
increment pointer
dec count
decrement counter
jnz l1
check if all nos are added
mov ch, 02h
Count of digits to be displayed
mov cl, 04h
Count to roll by 4 bits
mov bl, al
Result in reg bl
rol bl, cl
roll bl so that msb comes to lsb
mov dl, bl
load dl with data to be displayed
and dl, 0fH
get only lsb
cmp dl, 09
check if digit is 0-9 or letter A-F
jbe l4 add dl, 07 l4:
if letter add 37H else only add 30H
add dl, 30H mov ah, 02
INT 21H (Display character)
int 21H dec ch
Decrement Count
jnz l2 mov ah, 4cH int 21H end
Terminate Program Flowchart A.1
Micropro. & Interfacing Techniques (PU)
L-3
Lab Manual
Result :
C:\programs>tasm blkadd.asm Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: blkadd.asm Error messages: None Warning messages: None Passes: 1 Remaining memory: 437k C:\programs>tlink blkadd Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>blkadd
37 Program 2 :
Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without string specific instructions). Block containing data can be defined in the data segment.
(A)
To perform non-overlapped block transfer
Program statement :
Write an ALP to move a block of N bytes of data from source to destination and display the result. (Non-overlapped block transfer)
Explanation :
Consider that a block of data of N bytes is present at source location. Now this block of N bytes is to be moved from source location to a destination location. Let the number of bytes N = 10. We will have to initialize this as count in the CX register. We know that source address is in the SI register and destination address is in the DI register. Clear the direction flag. Using the string instruction move the data from source location to the destination location. It is assumed that data is moved within the same segment. Hence the DS and ES are initialized to the same segment value. Display the contents using display routine.
Algorithm :
Step I Step II Step III Step IV Step V Step VI Step VII Step VIII Step IX
: : : : : : : : :
Initialise the data in the source memory and destination memory. Initialise SI and DI with source and destination address. Initialise CX register with the count. Initialise the direction flag to zero. Transfer the data block byte by byte to destination. Decrement CX. Check for count in CX, if not zero goto step V else goto step VIII. Display the bytes in destination location. Stop.
Micropro. & Interfacing Techniques (PU)
Flowchart : Refer flowchart A.2(a).
Program :
Label
Instruction .model small .data src_blk db 01, 02, 03, 04, 05, 06, 07, 08, 09, 0AH dest_blk db 10 dup(?) count dw 0AH .code mov ax, @data mov ds, ax mov es, ax mov si, offset src_blk mov di, offset dest_blk
again :
mov cx, count cld rep movsb mov di, offset dest_blk
up:
mov bh, 0Ah mov bl, [di] mov cx, 0204h
l1:
rol bl, cl mov dl, bl and dl, 0fh cmp dl, 09h jbe l12 add dl, 07h
l12:
add dl, 30h
L-4
Lab Manual
Comment
initialize data & extra segment
si to point to source block di to point to destination block initialize counter df=0 transfer contents di to point to destination block initialize counter store result in bl Count of digits to be displayed in ch and digits to be mrolled in cl roll bl so that msb comes to lsb load dl with data to be displayed get only lsb check if digit is 0-9 or letter A-F if letter add 37H else only add 30H
Flowchart A.2(a)
Micropro. & Interfacing Techniques (PU)
Label
Instruction mov ah, 02 int 21h dec ch jnz l1 dec bh inc di mov ah, 02h mov dl, ' ' int 21h cmp bh, 00h jne up mov ah, 4ch
L-5
Comment Function 02 under INT 21H Decrement Count decrement counter display space between bytes
repeat till all bytes are displayed normal termination to dos
int 21h end
Result :
C:\programs>tlink revblock Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>tasm block Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: block.ASM Error messages: None Warning messages: None Passes:
1
Remaining memory: 437k C:\programs>tlink block Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>block
01 02 03 04 05 06 07 08 09 0A C:\programs>
Lab Manual
Micropro. & Interfacing Techniques (PU)
L-6
(B)
To perform overlapped block transfer
Program Statement :
Lab Manual
Write a program in the ALP of 8086 to move a block of N data bytes from source to destination. The source begins at 2001 H and destination begins at location 2005 H. (Overlapped block transfer) Explanation : The source block is at address 2001 H and destination block is at address 2005 H. Let the number of bytes in the block to be transferred be 10. Initialize this as count in CX register. Now enter the data bytes in source block which you want to transfer to the destination block. Here the destination block is overlapping the source block. So first we will transfer the contents of last location, the second last location and so on till all bytes are transferred. As SI and DI both are pointing to last location of source and data block, once the data is transferred, we will use STD i.e. set direction flag which autodecrements the SI and DI registers. Display the result. Algorithm : Step I : Initialize the data section with addresses of source and destination block. Step II : Initialize SI = start of source block. Step III : Enter data into source block. Step IV : Initialize DI = start of destination block. Step V : DI = DI + (count – 1) i.e. DI = last location of destination block. Step VI : Initialize counter = 10. Step VII : Autodecrement SI, DI. Step VIII : Transfer contents from source location to destination location. Step IX : Decrement counter. Step X : Is counter = 0 ? If not go to step VIII. Step XI : Display the contents. Step XII : Stop. Flowchart : Refer flowchart A.2(b).
Program :
Label
Instruction .model small .data src_blk db 01, 02, 03, 04, 05, 06, 07, 08, 09, 0AH dest_blk db 10 dup(?) count dw 0AH .code mov ax, @data mov ds, ax mov es, ax
Comment
initialize segment
data
&
extra
Micropro. & Interfacing Techniques (PU)
Label
again:
Instruction mov si, offset src_blk mov di, offset dest_blk mov cx, count cld rep movsb mov di, offset dest_blk
up:
mov bh, 0Ah mov bl, [di] mov cx, 0204h
l1:
rol bl, cl mov dl, bl and dl, 0fh cmp dl, 09h jbe l12 add dl, 07h
l12:
add dl, 30h mov ah, 02 int 21h dec ch jnz l1 dec bh inc di mov ah, 02h mov dl, ' ' int 21h cmp bh, 00h jne up mov ah, 4ch int 21h end
L-7
Lab Manual
Comment si to point to source block di to point to destination block initialize counter df=0 transfer contents di to point to destination block initialize counter store result in bl Count of digits to be displayed in ch and digits to be rolled in cl roll bl so that msb comes to lsb load dl with data to be displayed get only lsb check if digit is 0-9 or letter A-F if letter add 37H else only add 30H Function 02 under INT 21H Decrement Count decrement counter display space between bytes
repeat till all bytes are displayed normal termination to dos
Flowchart A.2(b)
Micropro. & Interfacing Techniques (PU)
L-8
Lab Manual
Result :
C:\programs>tlink revblock Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>tasm block Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: block.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 437k C:\programs>tlink block Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>block 01 02 03 04 05 06 07 08 09 0A C:\programs> Program 3 :
Write 64 bit ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD number into its equivalent HEX number. Make your program user friendly to accept the choice from user for : (a) HEX to BCD (b) BCD to HEX (c) EXIT. Display proper strings to prompt the user while accepting the input and displaying the result. (use of 64-bit registers is expected)
(A)
HEX to BCD
Program statement : Write 8086 ALP to convert 4 digit Hex number to its equivalent BCD number.
Explanation : We have a 4 digit Hex number whose equivalent binary number is to be found.i.e. FFFF H. Initially we compare FFFF H with decimal 10000 ( 2710 H in Hex ). If number is greater than 10,000 we add it to DH register. Also, we subtract decimal 10,000 from FFFF H, each time comparision is made. Then we compare the number obtained in AX by 1000 decimal. Each time we subtract 1000 decimal from AX and add 1000 decimal to BX. Then we compare number obtained in AX by 100 decimals. Each time we subtract 100 decimal from AX and add 100 decimal to BX to obtain BCD equivalent. Then we compare number obtained in AX with 10 decimal. Each time we subtract 10 decimal from AX and we add 10 decimal to BX. Finally we add the result in BX with remainder in AX. The final result is present in register DH with contains the 5th bit if present and register AX. Display the result.
Algorithm :
Step I Step II
: :
Initialize the data segment. Initialize BX = 0000 H and DH = 00H.
Micropro. & Interfacing Techniques (PU)
Step III Step IV
: :
Step V Step VI Step VII
: : :
Step VIII Step IX Step X Step XI Step XII Step XIII Step XIV Step XV Step XVI Step XVII Step XVIII
: : : : : : : : : : :
Flowchart : Refer flowchart A.3(a).
Program :
l9 :
l2 :
l4 :
Lab Manual
Load the number in AX. Compare number with 10000 decimal. If below goto step VII else goto step V. Subtract 10,000 decimal from AX and add 1 decimal to DH Jump to step IV. Compare number in AX with 1000, if below goto step X else goto step VIII. Subtract 1000 decimal from AX and add 1000 decimal to BX. Jump to step VII. Compare the number in AX with 100 decimal if below goto step XIII Subtract 100 decimal from AX and add 100 decimal to BX. Jump to step X Compare number in AX with 10. If below goto step XVI Subtract 10 decimal from AX and add 10 decimal to BX.. Jump to step XIII. Add remainder in AX with result in BX. Display the result in DH and BX. Stop.
Label
L-9
Instruction .model small .stack 100 .code mov ax, 0ffffh mov bx, 0000 mov dh, 0 cmp ax, 10000 jb l2 sub ax, 10000 inc dh jmp l9 cmp ax, 1000 jb l4 sub ax, 1000 add bx, 1000h jmp l2 cmp ax, 100 jb l6 sub ax, 100
Comment
hex number to find it's bcd
if ax>10000 subtract 10000 add 1 to dh if ax>1000
add 1000h to result if ax>100
Micropro. & Interfacing Techniques (PU)
Label
l6 :
l8 :
go:
l12:
Instruction add bx, 100h jmp l4 cmp ax, 10 jb l8 sub ax, 10 add bx, 10h jmp l6 add bx, ax mov ah, 02 mov cx, 0204h rol dh, cl mov dl, dh and dl, 0fh add dl, 30h int 21h dec ch jnz go mov ch, 04h mov cl, 04h rol bx, cl mov dl, bl and dl, 0fH cmp dl, 09 jbe l14 add dl, 07
l14:
add dl, 30H mov ah, 02 int 21H dec ch jnz l12 mov ah, 4cH int 21H end
L-10
Lab Manual
Comment add 100h to result if ax>10
add 10h to result add remainder to result Count to display 2 digits
display 2 msb digits
Count of digits to be displayed Count to roll by 4 bits roll bl so that msb comes to lsb load dl with data to be displayed get only lsb check if digit is 0-9 or letter A-F if letter add 37H else only add 30H Function 2 under INT 21H (Display character) Decrement Count Terminate Program
Flowchart A.3(a)
Micropro. & Interfacing Techniques (PU)
L-11
Lab Manual
Result :
C:\programs>tasm hex2bcd.asm Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: hex2bcd.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 437k C:\programs>tlink hex2bcd Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International C:\programs>hex2bcd
065535 (B)
BCD to HEX
Program statement :
Write 8086 ALP to convert 5 digit BCD number to its equivalent Hex number.
Explanation :
We are given a five digit BCD number whose HEX equivalent is to be found i.e. 65535 whose HEX equivalent is to be found. First we will find the Hex equivalent of 60,000. We will compare 60,000H with 10,000H. Each time we compare a counter is decremented by 10,000 and we add 10,000 decimal (2710 Hex). Then we will find the equivalent of 5000. Now we will compare 5000H with 1000H. Each time we compare the counter decrements by 1000 and we add 1000 decimal (3E8 H). Then we find the equivalent of 500H by comparing it with 100H. Each time counter decrements by 100 and we add decimal 100 (64 H). Then we find equivalent of 30H by comparing it with 10H. Each time counter decrements by 10 and we add 10 decimal (0A H). Then, equivalent of 5 is 5H.
Finally, all the equivalents obtained are added to get the equivalent of 65535.
Algorithm :
Step I Step II Step III
: : :
Initialize the data segment. Load the MSB of word in register AX. Compare it with 0, if zero goto step VII else goto step IV.
Step IV Step V Step VI Step VII Step VIII Step IX
: : : : : :
decrement AX and initalize BX = 0000. add 10000 decimal to BX. Jump to step III. Load LSB of word in register AX. Compare it with 1000, if below ogto step XII else goto step IX. subtract 1000 H from AX.
Step X
:
Add 1000 decimal to BX.
Micropro. & Interfacing Techniques (PU)
Step XI Step XII
: :
Step XIII Step XIV Step XV
: : :
Step XVI
:
L-12
Lab Manual
Jump to step VIII Compare number in AX now with 100 H, if below goto step XVI, else goto step XIII. Subtract 100 H from AX. Add 100 decimal to BX. Jump to step XII.
Step XVII :
Compare number in AX with 10H, if below goto step XX, else goto step XVII. Subtract 10 H from AX
Step XVIII Step XIX Step XX Step XXI Step XXII
Add 10 decimal to BX Jump to step XVI Add contents of AX and BX. Display the result. Stop.
: : : : :
Flowchart : Refer flowchart A.3(b).
Program :
Label
Instruction
Comment
.model small .stack 100 .data a dd 00065535h .code mov ax, @data
Intialize data segment
mov ds, ax
l11:
mov ax, word ptr a+2
checking msb no
mov bx, 0000h
intialize hex result
cmp ax, 0
cmp ax
jz l10 dec ax
l10: l2 :
add bx, 10000 jmp l11 mov ax, word ptr a cmp ax, 1000h jb l4 sub ax, 1000h add bx, 1000 jmp l2
if ax=1 then it means no>10000 so add 10000 to bx load lsb part in ax if ax>1000h
add 1000 to result
Micropro. & Interfacing Techniques (PU)
Label l4 :
Instruction cmp ax, 100h
L-13
Lab Manual
Comment if ax>100h
jb l6 sub ax, 100h add bx, 100
add 100 to result
jmp l4 l6 :
cmp ax, 10h
if ax>10h
jb l8 sub ax, 10h add bx, 10
add 10 to result
jmp l6 l8 :
l2:
add bx, ax
add remainder to result
mov ch, 04h
Count of displayed
mov cl, 04h
Count to roll by 4 bits
mov bx, ax
Result in reg bx
rol bx, cl
roll bl so that msb comes to lsb
mov dl, bl
load dl with data to be displayed
and dl, 0fH
get only lsb
cmp dl, 09
check if digit is 0-9 or letter A-F
digits
to
be
jbe l4 add dl, 07 l4:
if letter add 37H else only add 30H
add dl, 30H mov ah, 02
Function 2 under INT 21H (Display character)
int 21H dec ch
Decrement Count
jnz l2 mov ah, 4cH
Terminate Program
int 21H end
Flowchart A.3(b)
Micropro. & Interfacing Techniques (PU)
L-14
Lab Manual
Result :
C:\programs>tasm bcd2hex.asm Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: bcd2hex.asm Error messages: None Warning messages: None Passes: 1 Remaining memory: 437k C:\programs>tlink bcd2hex Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International C:\programs>bcd2hex
FFFF Program 4 :
Write X86/64 ALP for the following operations on the string entered by the user. (use of 64-bit registers is expected) (a) Calculate Length of the string (b) Reverse the string (c) Check whether the string is palindrome or not OR Make your program user friendly by providing MENU like: (a) Enter the string (b) Calculate length of string (c) Reverse string (d) Check palindrome (e) Exit Display appropriate messages to prompt the user while accepting the input and displaying the result.
Explanation :
Using Macro display the Menu for entering string, calculate length, reverse, palindrome and exit. Accept the choice from user using INT 21H function 01H. If choice = 1, call procedure for accepting string. Using interrupt INT 21H, function 0AH accept the string and end procedure. Return back to display Menu. If choice = 2, call procedure for finding length of the string. Display length and return back to display Menu. If choice = 3, call procedure to reverse the string. Display the reverse string and return back to display Menu. If choice = 4, call procedure to check if entered string is palindrome. If palindrome displays, the string is a palindrome, otherwise display String is not a palindrome. If choice = 5, terminate the program. If any other key is pressed display invalid choice.
Algorithm :
Step I Step II
: Initialize the data and stack memory. : Using Macro display Menu. 1. Accept 2. Length 4. Palindrome 5. Exit.
3.
Reverse
Micropro. & Interfacing Techniques (PU)
Step III Step IV Step V
L-15
Lab Manual
: Accept choice from user using INT 21H, function 01H. : IS choice = 1 jump to step XI else goto step V. : IS choice = 2 jump to step XIV else goto step VI.
Step VI Step VII
: IS choice = 3 jump to step XVII else goto step VII. : IS choice = 4 jump to step XX else goto step VIII. Step VIII : IS choice = 5 jump to step XXIII else goto step IX. Step IX : Display Wrong choice. Step X : Jump to step II. Step XI : Call procedure accept. Step XII : Accept string using INT 21H, function 0AH. Step XIII : Return to main program and goto step II. Step XIV : Call procedure length. Step XV : Calculate the length of string and display it using INT 21H, function 02H. Step XVI : Return back to main program and jump to step II. Step XVII : Call procedure reverse. Step XVIII : Reverse the string and display it. Step XIX : Return back to main program and jump to step II. Step XX : Call procedure palindrome. Step XXI : Check if string is palindrome. If yes display string is palindrome else string is not a palindrome. Step XXII : Return back to main program and jump to step II. Step XXIII : Terminate the program and stop.
Flowchart : Refer flowchart A.4.
Flowchart A.4
Micropro. & Interfacing Techniques (PU)
Lab Manual
Program :
Label
ak :
L-16
Instruction TITLE STRING OPERATIONS MESS MACRO MSG MOV AH, 09H LEA DX, MSG INT 21H ENDM .MODEL SMALL .STACK 100H .DATA STR1 DB 25 , ? , 25 DUP('$') STR3 DB 25 , ? , 25 DUP('$') MSG1 DB 0AH, 0DH, 'MENU $' MSG21 DB 0AH, 0DH, '1.ACCEPT $' MSG22 DB 0AH, 0DH, '2.LENGTH $' MSG23 DB 0AH, 0DH, '3.REVERSE $' MSG24 DB 0AH, 0DH, '4.PALINDROME $' MSG25 DB 0AH, 0DH, '5.EXIT $' MSG3 DB 0AH, 0DH, 'ENTER YOUR CHOICE : $' MSG4 DB 0AH, 0DH, 'WRONG CHOICE $' MSG5 DB 0AH, 0DH, 'ENTER THE STRING : $' MSG6 DB 0AH, 0DH, 'STRING IS : $' MSG7 DB 0AH, 0DH,'LENGTH IS : $' MSG8 DB 0AH, 0DH, 'THE STRING IS A PALINDROME $' MSG9 DB 0AH, 0DH, 'THE STRING IS NOT A PALINDROME $' .CODE mov ax, @data mov ds, ax mov es, ax mess msg1 mess msg21 mess msg22 mess msg23 mess msg24 mess msg25 mess msg3 mov ah, 01h
Comment DEFINITION OF MACRO MESS
Intialize data and extra segment
display menu
accept choice
Micropro. & Interfacing Techniques (PU)
Label
acc : len : rev : pal: endd:
Instruction int 21h mov bl, al cmp bl, 31h je acc cmp bl, 32h je len cmp bl, 33h je rev cmp bl, 34h je pal cmp bl, 35h je endd mess msg4 jmp ak call accept jmp ak call lent jmp ak call reverse jmp ak call pall jmp ak mov ah, 4ch int 21h accept proc near mess msg5 mov ah, 0ah lea dx, str1 int 21h RET accept endp lent proc near mess msg7 mov dl, str1+1 or dl, 30h mov ah, 02h int 21h ret lent endp
L-17
Lab Manual
Comment Choice BL if choice=1 Accept string if choice=2 Find lenth of string if choice=3 Reverse string if choice=4 Check if string is palindrome if choice=5 exit Wrong Choice
accept procedure
Accept String
length procedure
Dl contains length of String Display Length
reverse procedure
Micropro. & Interfacing Techniques (PU)
Label
Instruction reverse proc near mess msg6 mov ch, 00h mov cl, str1+1 sub cl, 01h lea si, str1+2 lea di, str1+2 repz movsb
loop1:
loop2
mov cl, str1+1 lea di, str3+2 mov dx, [si] mov ah, 02h int 21h mov [di], dx dec si inc di dec cl cmp cl, 00h jne loop1 ret reverse endp pall proc near mess msg6 mov ah, 09h lea dx, str1+2 int 21h call reverse lea di, str3+2 mov ah, 00h mov dh, 00h lea si , str1+2 mov cl, str1+1 mov al, byte ptr[si] mov bl, byte ptr[di] dec cl cmp cl, 00h je loopa cmp al, bl
L-18
Lab Manual
Comment
Cl has length of string DESTINATION STRING DESTINATION STRING COPY TO TRAVERSE TILL END OF FIRST STR DESTINATION STRING dx contains rightmost character display character copy character to destination
palindrome procedure
str1 contains original string str3 has reversed string
CL contains Length of string
Decrement count
Compare characters
Micropro. & Interfacing Techniques (PU)
Label loopa
loop4 loop5 loop3
Instruction je loop3 cmp cl, 00h je loop4 mess msg9 jmp loop5 mess msg8 ret inc si inc di jmp loop2 pall endp end
L-19
Lab Manual
Comment if same goto loop3 if checked all characters the strings are not same the strings are same
now check next character end
Result : C:\programs>tasm str Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: str.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 434k C:\programs>tlink str Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International C:\programs>str MENU 1. ACCEPT 2. LENGTH 3. REVERSE 4. PALINDROME 5. EXIT ENTER YOUR CHOICE : 1 ENTER THE STRING : college MENU 1. ACCEPT 2. LENGTH 3. REVERSE 4. PALINDROME 5. EXIT ENTER YOUR CHOICE : 2 LENGTH IS : 7
Micropro. & Interfacing Techniques (PU)
L-20
Lab Manual
MENU 1. ACCEPT 2. LENGTH 3. REVERSE 4. PALINDROME 5. EXIT ENTER YOUR CHOICE : 3 STRING IS : egelloc MENU 1. ACCEPT 2. LENGTH 3. REVERSE 4. PALINDROME 5. EXIT ENTER YOUR CHOICE : 4 STRING IS : college STRING IS : egelloc THE STRING IS NOT A PALINDROME MENU 1. ACCEPT 2. LENGTH 3. REVERSE 4. PALINDROME 5. EXIT ENTER YOUR CHOICE : 1 ENTER THE STRING : madam MENU 1. ACCEPT 2. LENGTH 3. REVERSE 4. PALINDROME 5. EXIT ENTER YOUR CHOICE : 4 STRING IS : madam STRING IS : madam THE STRING IS A PALINDROME Program 5 :
Write 8086 ALP to perform string manipulation. The strings to be accepted from the user is to be stored in data segment of program_l and write FAR PROCEDURES in code segment program_2 for following operations on the string: (a) (b)
Concatenation of two strings Number of occurrences of a sub-string in the given string Use PUBLIC and EXTERN directive. Create .OBJ files of both the modules and link them to create an EXE file.
Micropro. & Interfacing Techniques (PU) (A)
L-21
Lab Manual
Concatenation of two strings
Program Statement : Write a program in the assembly language of 8086, to concatenate two strings.
Explanation :
Firstly, we will accept the two strings to be concatenated. Then, we will call procedure CONCAT which will concatenate the two strings. Display the concatenated strings.
Algorithm : Step I : Start. Step II : Accept string 1 from user. Step III : Accept string 2 from user. Step IV : Call procedure CONCAT. Step V : Load length of string 1 in CX. Step VI : Load the address of source string 1 in SI and DI. Step VII : Copy the contents of string 1 to destination string. Step VIII : Load SI with address of string 2. Step IX : Copy the contents of string 2 to destination string. Step X : Display the concatenated string. Step XI : Procedure and return to calling program Step XII : Stop.
Flowchart : Refer flowchart A.5(a).
Program :
Instruction page 100, 50 title string concatenatation mess macro msg mov ah, 09h lea dx, msg int 21h endm .model small .stack 100h .data str1 db 25 , ? , 25 dup('$') str2 db 25 , ? , 25 dup('$') msg1 db 0ah, 0dh, 'enter the string1: $' msg2 db 0ah, 0dh, 'enter the string2: $' msg3 db 0ah, 0dh, 'concatenated string is : $' .code mov ax, @data
Comment
definition of macro mess
data initialisation
Micropro. & Interfacing Techniques (PU)
Instruction mov ds, ax mov es, ax mess msg1 mov ah, 0ah lea dx, str1 int 21h mess msg2 mov ah, 0ah lea dx, str2 int 21h call concat mov ah, 4ch int 21h concat proc near mov ch, 00h mov cl, str1+1 lea si, str1+2 lea di, str1+2 repz movsb mov ch, 00h mov cl, str2+1 lea si, str2+2 cld repz movsb mess msg3 lea si, str1 mov ah, 09h lea dx, str1+2 int 21h ret concat endp end
L-22
Lab Manual
Comment
accept string1 function 0ah under int 21h
from
user
accept string1 function 0ah under int 21h
from
user
call procedure normal termination to dos begin procedure cl=length of string1 destination string destination string copy to traverse till end of string1 cl=length of string2 source string df=0 copy to traverse till end of string2 display concatenated string use function 09h under int 21h
end procedure end program Flowchart A.5(a)
Micropro. & Interfacing Techniques (PU)
L-23
Lab Manual
Result :
C:\programs>TASM STR1 Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: STR1.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 437k C:\programs>TLINK STR1 Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International C:\programs>STR1 ENTER THE STRING1: HELLO ENTER THE STRING2: MONICA CONCATENATED STRING IS : HELLOMONICA C:\programs> (B)
Compare two strings
Program statement :
Write a program in the ALP of 8086 to check the data in two strings are equal, if equal display the message “equal strings”, and if not display the message “unequal strings”.
Explanation :
We will accept two strings from the user. After accepting the strings, the first step in string comparison is to check whether their string lengths are equal. If the string lengths are not equal, we print the message unequal strings. If the string lengths are equal, we check if the contents of two strings are equal. The lengths of the two stings are initialized in the CX register. The source and destination address are initialized in DS : SI and ES : DI registers. Using the string instruction REPE CMPSB, two data are compared character by character. If all the characters are matching display the message “equal strings” otherwise display “unequal strings”.
Algorithm :
Step I Step II Step III Step IV Step V Step VI Step VII Step VIII Step IX
: : : : : : : : :
Initialize the data memory. Allocate data memory to save the strings. Initialize DS and ES register. Accept the first string. Accept the second string. Load the number of characters of first string in CL. Load the number of characters of second string in CH register. Compare the lengths of the two strings. If not go to step XIII. Load number of characters to be compared in CX.
Micropro. & Interfacing Techniques (PU)
Step X Step XI Step XII Step XIII Step XIV
: : : : :
Lab Manual
Compare the strings, character by character. If not same goto step XIII. Print “equal strings” using Macro. Jump to step XIV. Print “unequal strings” using Macro. Stop.
Flowchart : Refer flowchart A.5(b).
Program :
Label
L-24
Instruction PRINT MACRO MES MOV AH, 09H LEA DX, MES INT 21H ENDM .MODEL SMALL .DATA MS1 DB 10, 13, "ENTER FIRST STRING : $" MS2 DB 10, 13, "ENTER SECOND STRING : $" MS3 DB 10, 13, "EQUAL STRINGS $" MS4 DB 10, 13, "UNEQUAL STRINGS $" MS5 DB 10, 13, "$" BUFF DB 25 , ? , 25 DUP('$') BUFF1 DB 25 , ? , 25 DUP('$') .CODE mov ax, @data mov ds, ax mov es, ax print ms1 mov ah, 0ah lea dx, buff int 21h
Comment Macro to display string
Initialize DS and ES
ACCEPT first STRING
Flowchart A.5(b)
Micropro. & Interfacing Techniques (PU)
Label
Instruction lea si, buff print ms2 mov ah, 0ah lea dx, buff1 int 21h mov cl, buff+1
L-25
Comment
ACCEPT OTHER STRING
Number of characters in str1
mov ch, buff1+1
Number of characters in str2
cmp ch, cl
check if length is same
jnz para mov ch, 00 mov cl, buff+1 lea di, buff1 cld repe cmpsb
Number of characters
Compare string char by char
jnz para
if not same goto PARA
print ms3 jmp quit
Strings are equal
print ms4
Strings are Unequal
para:
quit: mov ah, 4ch int 21h end
Result :
C:\programs>tasm COMPARE.ASM Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: COMPARE.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 437k
Lab Manual
Micropro. & Interfacing Techniques (PU)
L-26
Lab Manual
C:\programs>TLINK COMPARE.OBJ Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>COMPARE ENTER FIRST STRING : hello ENTER SECOND STRING : hell UNEQUAL STRINGS C:\programs>COMPARE ENTER FIRST STRING : hello ENTER SECOND STRING : hello EQUAL STRINGS (C)
Number of occurrences of sub-string in the given string
Program Statement : Write an assembly language program that determines if a given sub-string is present or not in a main string of characters. The result is to be stored in a register AL with FF : present, 00 : absent
Explanation :
The substring is checked in the main string by comparing the first character of substring with the characters of the main string. If there is a match of first character, then it is required to check whether the length of the substring is less than or equal to the remaining prortion of the main string. If the condition is satisfied comparision continues. If string does not match, then first character of substring is checked for remaining length of main string for the match and process continues. If match is found, FF is stored in AL otherwise AL = 00H.
Algorithm :
Step I Step II Step III Step IV Step V Step VI Step VII
: : : : : : :
Step VIII : Step IX Step X Step XI Step XII Step XIII
: : : : :
Initialize data memory with main string, substring. Initialize the DS and ES. Accept the main string from user. Accept the substring from user. CL = count of main string. DL = count of substring. Compare the first character of substring with main string till there is 0 match. Subtract the length of substring to remaining length of main string till match is found. If there is nothing goto step XIII. If result is negative, terminate program. Compare all other substring with main string. If they match, store FF in the AL. If they don’t match store 00 in AL. Stop.
Flowchart : Refer flowchart A.5(c).
Micropro. & Interfacing Techniques (PU)
L-27
Program :
Label
Instruction mess macro msg
Comment definition of macro mess
mov ah, 09h lea dx, msg int 21h endm .model small .data STR1 DB 25 , ? , 25 DUP('$') Substr1 DB 25 , ? , 25 DUP('$') msg1 db 10, 13, 'Enter the string : $' msg2 db 10, 13, 'Enter the substring : $' msg3 db 10, 13, '$' count1 dw ? count2 dw ? res db 0 addr dw 0 buff db 25 , ? , 25 DUP('$') .code mov ax, @data mov ds, ax mov es, ax mess msg1 mov ah, 0ah lea dx, str1 int 21h mov cl, str1+1 mov ch, 00 mov count1, cx mess msg2 mov ah, 0ah lea dx, substr1
Initialize data section
Lab Manual
Micropro. & Interfacing Techniques (PU)
Label
next:
Instruction
L-28
Lab Manual
Comment
int 21h mov dl, substr1+1 mov dh, 00 mov count2, dx mess msg3 mov si, offset substr1 mov di, offset str1 cld mov al, [si] repnz scasb inc si mov dx, cx sub cx, count2 jb stop mov cx, count2 dec cx repz cmpsb cmp cx, 00 jnz stop mov al, 0ffh mov bh, al jmp endd
stop:
endd:
mov cx, 00 mov bh, cl jmp endd mov ch, 02h mov cl, 04h
l2:
rol bh, cl mov dl, bh and dl, 0fH cmp dl, 09
Count of digits to be displayed Count to roll by 4 bits roll bl so that msb comes to lsb load dl with data to be displayed get only lsb check if digit is 0-9 or letter A-F
Flowchart A.5(c)
Micropro. & Interfacing Techniques (PU)
Label
Instruction jbe l4 add dl, 07
l4:
add dl, 30H mov ah, 02
int 21H dec ch jnz l2 mov ah, 4ch int 21h end
L-29
Lab Manual
Comment if letter add 37H else only add 30H Function 2 under INT 21H(Display character) Decrement Count
Result :
F:\C\PROGRAMS>TASM SUBSTR Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: SUBSTR.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 441k F:\C\PROGRAMS>TLINK SUBSTR Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack F:\C\PROGRAMS>SUBSTR Enter the string : TODAY IS FRIDAY Enter the substring : IS
FF F:\C\PROGRAMS> Program 6 :
Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use successive addition and add and shift method. Accept input from the user. (use of 64-bit registers is expected)
(A)
Successive Addition Method :
Program statement : Assuming that MUL instruction is not available in the instruction set of 8086, write a program in assembly language of 8086 to simulate the MUL instruction. Assuming that two digits are available in AL and BL registers. Use successive addition method.
Micropro. & Interfacing Techniques (PU)
L-30
Lab Manual
Explanation :
Consider that a byte is present in the AL register and second byte is present in the BL register. We have to multiply the byte in AL with the byte in BL. We will multiply the numbers using successive addition method. In successive addition method, one number is accepted and other number is taken as a counter. The first number is added with itself, till the counter decrements to zero. Result is stored in DX register. Display the result, using display routine. For example : AL = 12 H, BL = 10 H Result = 12H + 12H + 12H + 12H + 12H + 12H + 12H + 12H + 12H + 12H Result = 0120 H
Algorithm : Step I : Initialise the data segment. Step II : Get the first number. Step III : Get the second number as counter. Step IV : Initialize result = 0. Step V : Result = Result + First number. Step VI : Decrement counter Step VII : If count 0, go to step V. Step VIII : Display the result. Step IX : Stop.
Flowchart : Refer flowchart A.6(a).
Program :
Label
ad:
Instruction .model small .data a db 12H b db 10H .code mov ax, @data mov ds, ax mov al, a mov bl, b mov ah, 0 mov dx, 0 add dx, ax dec bl
Comment
Initialize data section Load number1 in al Load number2 in bl intialize result add numbers. Result in dx dec number
cmp bl, 0 jnz ad mov ch, 04h
Count of digits to be displayed
Micropro. & Interfacing Techniques (PU)
Label
l2:
Instruction
L-31
Lab Manual
Comment
mov cl, 04h
Count to roll by 4 bits
mov bx, dx
Result in reg bx
rol bx, cl
roll bl so that msb comes to lsb
mov dl, bl
load dl with data to be displayed
and dl, 0fH
get only lsb
cmp dl, 09
check if digit is 0-9 or letter A-F
jbe l4 add dl, 07 l4:
if letter add 37H else only add 30H
add dl, 30H mov ah, 02
Function 2 under INT 21H (Display character)
int 21H dec ch
Decrement Count
jnz l2 mov ah, 4cH
Terminate Program
int 21H end
Flowchart A.6(a)
Result :
C:\programs>tasm succmul.asm Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: succmul.asm Error messages: None Warning messages: None Passes: 1 Remaining memory: 438k C:\programs>tlink succmul Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>succmul
0120 (B)
Add and Shift Method :
Program statement :
Assuming that MUL instruction is not available in the instruction set of 8086, write a program in assembly language of 8086 to simulate the MUL instruction. Assuming that two digits are available in AL and BL registers. Use add and shift method.
Micropro. & Interfacing Techniques (PU)
L-32
Lab Manual
Explanation :
Consider that one byte is present in the AL register and another byte is present in the BL register. We have to multiply the byte in AL with the byte in BL. We will multiply the numbers using add and shift method. In this method, you add number with itself and rotate the other number each time and shift it by one bit to left alongwith carry. If carry is present add the two numbers. Initialise the count to 4 as we are scanning for 4 digits. Decrement counter each time the bits are added. The result is stored in AX. Display the result. For example : AL = 11 H, BL = 10 H, Count = 4 Step I : AX = 11 + 11 22 H Rotate BL by one bit to left along with carry. BL = 10 H 0 0
BL =
Step II
Step III
0 CY
CY 0
0
1
0
0
1
0
0
0
0
0
0
0
2
0
0
0
: Now decrement counter count = 3. Check for carry, carry is not there so add number with itself. AX = 22 + 22 44 H Rotate BL to left, 0 BL = 0 1 0 0 0 0 0 0 CY 4 0 Carry is not there. Decrement count, count=2 : Add number with itself AX =
44 44 88 H
+ Rotate BL to left, 0 BL = CY Carry is not there.
1
0
0 8
0
0
0
0 0
0
Micropro. & Interfacing Techniques (PU)
Step IV :
Carry is there. Decrement counter = 0. Carry is present. add AX, BX 0110 + 0000 0110 H
i.e.
0
11 H 10 H 0110 H
Algorithm :
Step I Step II Step III Step IV Step V Step VI Step VII Step VIII Step IX Step X Step XI Step XII
Lab Manual
Decrement counter count = 1. Add number with itself as carry is not there. AX = 88 + 88 110 H Rotate BL to left, 1 0 0 0 0 0 0 0 BL = CY 0 0
Step V :
L-33
: : : : : : : : : : : :
Initialise the data segment. Get the first number. Get the second number. Initialize count = 04. number 1 = number 1 2. Shift multiplier to left alongwith carry. Check for carry, if present goto step VIII else goto step IX. number 1 = number1 + shifted number 2. Decrement counter. If not zero, goto step V. Display the result. Stop.
Flowchart : Refer flowchart A.6(b).
Label
Instruction .model small .data a db 11H b db 10H .code mov ax, @data mov ds, ax mov al, a mov bl, b mov ah, 0 mov dl, 04h
Comment
Initialize data section Load number1 in al Load number2 in bl initialize counter
Micropro. & Interfacing Techniques (PU)
Label ad:
skip:
l2:
Instruction add ax, ax rcl bl, 01 jnc skip add ax, bx dec dl jnz ad mov ch, 04h mov cl, 04h mov bx, ax rol bx, cl mov dl, bl and dl, 0fH cmp dl, 09 jbe l4 add dl, 07
l4:
add dl, 30H mov ah, 02 int 21H dec ch jnz l2 mov ah, 4cH int 21H end
L-34
Comment add numbers. Result in dx
dec number Count of digits to be displayed Count to roll by 4 bits Result in reg bx roll bl so that msb comes to lsb load dl with data to be displayed get only lsb check if digit is 0-9 or letter A-F if letter add 37H else only add 30H Function 2 under INT 21H (Display character) Decrement Count Terminate Program
Result :
C:\programs>tasm shaddmul.asm Turbo Assembler Version 3.0 Copyright (c) 1988, 1991 Borland International Assembling file: shaddmul.asm Error messages: None Warning messages: None Passes: 1 Remaining memory: 438k C:\programs>tlink shaddmul.obj Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International Warning: No stack C:\programs>shaddmul
0110 C:\programs>
Lab Manual
Flowchart A.6 (b)
Micropro. & Interfacing Techniques (PU) Program 7 :
L-35
Lab Manual
Write 8087 ALP to obtain : (i) Mean (ii) Variance (iii) Standard Deviation For a given set of data elements defined in data segment. Also display result.
Program : Title Implement mathematical equation
Label
Instruction
Comment
.model small .stack 100 .8087 .data array_x DQ 10 DUP (112233H) N DW 10 MEAN DQ ? answer DQ ? .code MOV AX, @data
Initialize data segment
MOV DS, AX
loop_acc :
loop_final :
FINIT
Initialize coprocessor
FLDZ
accumulation = 0
XOR BX, BX
clear pointer
MOV CX, N
counter
FADD array_x [BX]
add x(I) to TUS
ADD BX, 8
Point to next element
LOOP loop_acc
Repeat N times
FIDIV N
[Accumulation] N
FST MEAN
Store mean
FLDZ
Store 0 to TOS
XOR BX, BX
clear pointer
MOV CX, N
Counter
FLD array_x[BX]
Load data pointed by pointer
ADD BX, 8
offset
FSUB ST, ST(2)
X(I) MEAN = TOS
FMUL ST, ST(0)
= TOS
FADDP ST(1), ST
Accumulate
LOOP loop_final
loop till N = 0
FST answer
store answer
end
Micropro. & Interfacing Techniques (PU)
L-36
Lab Manual
Group B Programs of 8255 Program 1 :
Write 8086 ALP to convert an analog signal in the range of 0V to 5V to its corresponding digital signal using successive approximation ADC and dual slope ADC. Find the resolution used in both the ADC’S and compare the results.
Explanation :
ADC-0809 is an 8 bit successive approximation ADC. This chip has 8 channels alongwith multiplexer. The channel select has address lines A, B, C. We will use channel 0 as input. Thus, address lines A, B, C will be grounded for channel 0. The ALE pin is connected to the clock input. At the time of power on the valid channel address is latched at the rising edge of the ALE singal. ADC 0809 has an SOC (start of conversion) pin. A positive going pulse of short duration, is applied to this pin. This pin starts the A/D conversion process. The OE should always be high, when data is to be read. After the conversion, EOC is given through PC7 indicating end of conversion. The port A and C are defined in the input mode, whereas port B of 8255 is configured in output mode. The data is read through port A of 8255. Positive (d.c.) and negative (d.c.) or (a.c.) voltage is applied as the analog input at channel 0. Hence decoupling capacitors are used to maintain minimum noise level. Internal oscillator can be enabled only when A/D conversion is to be done. The oscillator oscillates till the INT.SOC enables pin PB2 of the 8255.
Fig. 1
Micropro. & Interfacing Techniques (PU)
L-37
Lab Manual
Algorithm : Step I : Initialize the data section. Step II : Initialize AL with control word. Step III : Output contents of AL i.e. control word on control register. Step IV : Load AL = 00H. Step V : Output contents of AL on port B, to select channel 0. Step VI : Send the ALE high. Step VII : Call some delay i.e. wait for atleast 2.5 s. Step VIII : Make SOC high. Step IX : Wait for atleast 0.5 s. Step X : Make SOC low. Step XI : Check for EOC. Step XII : If not wait. Step XIII : Read the digital input availables on port A. Step XIV : Go to step IV.
Control word : I/O
Mode
A
PA
Pcu
Mode B
PB
PCL
1
0
0
1
1
0
0
1
Flowchart : Refer flowchart B.1(a).
Program :
Label
Instruction
Comment
.model small .data Port A EQU 0000 H Port B EQU 0002 H Port C EQU 0004 H CWR EQU 0006 H .code MOV AX, @ Data MOV DS, AX MOV AL, 99H
AL = Control word.
MOV DX, CWR
DX = address of control word register.
OUT DX, AL
Output control word on control word register.
= 99H
Micropro. & Interfacing Techniques (PU)
Label L1:
Instruction MOV AL, 00H
L-38
Lab Manual
Comment AL = 00 to select channel 0.
MOV DX, Port B OUT DX, AL
Send address to select channel 0.
MOV AL, 08H OUT DX, AL
Latch the given address by sending ALE high.
Call Delay
Wait for 2.5 s.
MOV AL, 18H
Make SOC high.
OUT DX, AL NOP
Wait for atleast 0.5 s.
MOV AL, 08H OUT DX, AL
Make SOC low.
MOV DX, Port C CHECK :
IN DX, AL
Check for EOC.
AND AL, 01H JZ CHECK MOV DX, Port A IN DX, AL
Flowchart B.1(a)
JMP L1 The observation table will include. Analog input (V) 0 1 2 3 4 5
Digital equivalent
Output =
255 voltage 5V
Micropro. & Interfacing Techniques (PU)
L-39
Lab Manual
Using Dual Slope ADC : IC 7109 is used. It is a 12-bit dual slope A/D converter. ––––––
It has RUN /Hold input and STATUS output, which monitors and control conversion timing. It can operate with upto 30 conversions per second. Fig. 2 shows the interfacing diagram.
Fig. 2 : Interfacing 8255, ADC 7109 and 8086
Algorithm :
Step I
: Initialize the data section.
Step II Step III
: Make Run / Hold signal high. : Check for status. Is it 0. If not wait till status = 0.
Step IV Step V Step VI Step VII
: : : :
––––––
––––––
Make Run / Hold signal low. Read low order byte on Port A. Read higher nibble on Port B. Stop.
Flowchart : Refer flowchart B.1(b).
Micropro. & Interfacing Techniques (PU)
L-40
Lab Manual
Program :
Label
Instruction
Comment
.model small .data Port AEQU 0000 H Port BEQU 0001 H Port CEQU 0002 H CWR EQU 0003 H .Code MOV AX, @Data MOV DS, AX MOV AL, 92H
Initialize 8255 with control word.
MOV DX, CWR OUT DX, AL
Output control word on CWR.
MOV AL, 80H MOV DX, Port C OUT DX, AL
Send the RUN signal to ADC.
MOV DX, Port B BACK :
IN DX, AL
Stack for the status signal
AND AL, 40H JNZ BACK
If it is high check again.
MOV AL, 00H
Make RUN / HOLD signal low.
––––––––
MOV DX, Port C OUT DX, AL MOV DX, Port A
If low read lower byte.
IN DX, AL MOV DX, Port B
Get higher nibble
IN DX, AL MOV AH, 4CH INT 21 H
Terminate Flowchart B.1(b)
END After execution of program 12 bit digital data is available on Port A and Port B of the 8255. The higher nibble is on Port B and lower byte on Port A. The resolution for both ADC’s. ADC 0809 – 8 bit ADC 7109 – 12 bit
Micropro. & Interfacing Techniques (PU) Program 2 :
L-41
Lab Manual
Write 8086 ALP to interface DAC and generate following waveforms on oscilloscope. (i) (ii) (iii) (iv) (v)
Square wave – variable duty cycle and frequency. Sine wave – variable frequency. Ramp wave – variable direction. Trapezoidal wave. Stair case wave.
(i)
Square wave – Variable duty cycle and frequency :
Explanation :
]
We are asked to generate a square wave using DAC interface. To generate square wave we will output FFH and then 00H on port A of 8255. The output of 8255 (Port A) is connected to the DAC 0808. We also have to vary duty cycle. Variation in duty cycle will automatically change the frequency as, duty cycle
TON TON = T +T = Frequency ON OFF
According to our duty cycle requirement, we can change the DELAY between the two outputs FFH (for output high) and 00H (for output low).
Fig. 3 Algorithm : Step I : Initialize 8255 Port A as output port. Step II : Initialize AL = 00 H. Step III : Ouput the contents of AL through Step IV : Increment AL by one. Step V : Check if AL = FF H ? If not, goto step III. Step VI : Decrement AL by one. Step VII : Output AL through port A.
Micropro. & Interfacing Techniques (PU)
L-42
Lab Manual
Step VIII : Compare AL with 00. If AL = 00, goto step III. Step IX : If not, goto step VI.
Flowchart : Refer Flowchart B.2(a).
Program :
Label
L1 :
Instruction . MODEL SMALL . CODE MOV AL, 80 H MOV DX, 00 H MOV AL, 00 H OUT DX, AL INC AL CMP AL, FF H
L2 :
(ii)
JNZ L1 DEC AL OUT DX, DL JNZ L2 JNZ L1
Comment
Initialize Port A = Output Port. Load DX with port address of port A. Ouput contents of AL through port A. Increment AL. Compare AL with FF H, if not continue. Decrement AL. Output contents of AL to port A. Decrement till AL = 00. If AL = 00, goto L1 i.e. start from beginning.
Sine wave – Variable frequency :
Flowchart B.2(a)
Explanation : In order to generate a sine wave, we have to output digital equivalent values which represent the sine wave signal as shown in Fig. 4.
Fig. 4
Micropro. & Interfacing Techniques (PU)
L-43
Lab Manual
Digital data 00H represents – 2.5 V, and FFH represents + 2.5 V. The value of sin 0 = 0 sin 90 = 1 sin 270 = – 1 sin 360 = 0 The range of 0 to 90, is distributed in 128 decimal steps. Therefore, taking offset as 128. The magnitude = 128 + 128 sin x Where x : angle in degrees inorder to change, the frequency either increase or decrease the steps. The look up table shows the digital equivalent values, for the sine wave.
0
(128 + 128 sin 0)
Digital equivalent in decimal 128
10
(128 + 128 sin 10)
150
96H
20
(128 + 128 sin 20)
171
ABH
30
(128 + 128 sin 30)
192
C0H
40
(128 + 128 sin 40)
156
D2H
50
(128 + 128 sin 50)
226
E2H
60
(128 + 128 sin 60)
239
EFH
70
(128 + 128 sin 70)
248
F8H
80
(128 + 128 sin 80)
254
FEH
90
(128 + 128 sin 90)
FFH
100
(128 + 128 sin 100)
256 255 254
FEH
110
(128 + 128 sin 110)
248
F8H
120
(128 + 128 sin 120)
239
EFH
130
(128 + 128 sin 130)
226
E2H
140
(128 + 128 sin 140)
156
D2H
150
(128 + 128 sin 150)
192
C0H
160
(128 + 128 sin 160)
171
ABH
170
(128 + 128 sin 170)
150
96H
180
(128 + 128 sin 180)
128
80H
190
(128 + 128 sin 190)
106
6AH
200
(128 + 128 sin 200)
84
54H
210
(128 + 128 sin 210)
64
40H
220
(128 + 128 sin 220)
46
2EH
230
(128 + 128 sin 230)
30
1EH
240
(128 + 128 sin 240)
17
11H
250
(128 + 128 sin 250)
08
08H
Degrees
Equation
Digital Equivalent in Hex 80H
Micropro. & Interfacing Techniques (PU)
L-44
Lab Manual
(128 + 128 sin 260)
Digital equivalent in decimal 02
Digital Equivalent in Hex 02H
270
(128 + 128 sin 270)
00
00H
280
(128 + 128 sin 280)
02
02H
290
(128 + 128 sin 290)
08
08H
300
(128 + 128 sin 300)
17
11H
310
(128 + 128 sin 310)
30
1EH
320
(128 + 128 sin 320)
46
2EH
330
(128 + 128 sin 330)
64
40H
340
(128 + 128 sin 340)
84
54H
350
(128 + 128 sin 350)
106
6AH
(128 + 128 sin 360)
128
80H
Degrees
Equation
260
360
Instead of storing all these values, we store the digital values from 0 to 90, as these values repeat again i.e. We store the first 10 values and generate the remaining values at the time of execution.
Algorithm :
Step I Step II Step III Step IV Step V Step VI Step VII Step VIII Step IX Step X Step XI Step XII Step XIII Step XIV Step XV Step XVI Step XVII Step XVIII Step XIX Step XX Step XXI Step XXII Step XXIII Step XXIV
: : : : : : : : : : : : : : : : : : : : : : : :
Initialize the date segment. Initialize BX to point to start of look up table. Initialize count in CL. Load the value from look up table. Output that value on port A of 8255. Increment BX to point next value. Decrement count. Check if count = 0 ? If not, goto step IV. Initialize CL with count. Decrement BX to point value from look up table. Load AL with value from look up table. Output the value in AL on port A of 8255. Decrement count. Check if count = 0 ? If not, goto step X. Initialize CL = count Initialize AH = FFH i.e. count for subtraction. Load the value from look up table in AL. AL = AL – FFH i.e. compute the digitial equivalent value. Output value in AL, to port A of 8255. Increment BX to next value in look up table. Decrement count. Is count = 0 ? If not, goto XVI. Initialize CL with count. Decrement BX with next value in the look up table.
Micropro. & Interfacing Techniques (PU)
Step XXV Step XXVI Step XXVII Step XXVIII Step XXIX Step XXX Step XXXI
START :
L2 :
L3 :
Lab Manual
Initialize AH = FFH. Load the value from look up table in AL. Compute the digital equaivalent AL = AL – FFH Output the value in AL, on port A of 8255. Decrement count. If not zero, goto step XXIV. Go back to start.
Program :
Label
L1 :
: : : : : : :
L-45
Instruction .model small .data PORTA EQU 80H look_up dB 80H, 96H, 0ABH, 0COH, 0D2H, 0E2H, 0EFH, 0F8H, 0FEH, 0FFH Count dB 0AH .code MOV AX, @Data MOV DS, AX MOV BX, offset look_up MOV CL, count MOV AL, [BX] MOV DX, PORTA OUT DX, AL INC BX DEC CL JNZ L1 MOV CL, Count DEC BX MOV AL, [BX] MOV DX, Port A OUT DX, AL DEC CL JNZ L2 MOV CL, Count MOV AH, FFH MOV AL, [BX] SUB AL, AH MOV DX, Port A OUT DX, AL
Comment
Initialize data segment. Generates sine wave from 0 to 90 Initialize BX to start of look up table. Initialize count. AL = Value from look up table. DX = address of port A. Send data on port A. Increment BX to next value from look up table. Decrement count. If count 0, continue till all values are sent on output Generates sine wave from 90 to 180. Initialize counter. Decrement look up table pointer AL = Value from look up table DX = address of Port A. Decrement count. If count 0, goto L2. Generates sine wave from 180 to 270. Initialize counter. Load count for subtraction. AL = Value from look up table. Calculate digital equivalent value. DX = address of port A.
Micropro. & Interfacing Techniques (PU)
Label
L4 :
Instruction INC BX DEC CL JNZ L3 MOV CL, Count DEC BX MOV AH, FFH MOV AL, [BX] SUB AL, AH MOV DX, Port A OUT DX, AL DEC CL JNZ L4 JMP START
(iii)
Ramp wave : Variable Direction :
Explanation :
L-46
Lab Manual
Comment Decrement count. If count 0 goto L3 Generates sine wave from 270 to 360. Initialize counter. Decrement look up table pointer. Load count for subtraction. AL = Value from look up table.
Decrement count Continue
We are asked to generate a ramp wave using DAC interface. To generate ramp wave we will output 00 to FFH and FFH to 00H. If we want a ramp wave with reverse direction then, we output in reverse manner. If we want ramp wave in forward direction, we will initialize, AL = 00H, otherwise AL = FFH for reverse direction.
Fig. 5
Algorithm :
Step I Step II Step III Step IV Step V Step VI Step VII Step VIII
: : : : : : : :
Start Initialize AL. Initialize BL = AL i.e. store AL value in register BL. AND AL with 80H, to check MSB. If MSB = 1 goto step XIV. Load AL with value from BL. Output contents of AL through port A. Increment AL by 1.
Micropro. & Interfacing Techniques (PU)
Step IX Step X Step XI Step XII
: : : :
L-47
Check if AL = FFH ? If not, goto step VI. Decrement AL by one. Output contents of AL through port A. Compare AL with 00H ? If yes, goto step VII.
Step XIII : If not goto step X. Step XIV : Load AL back. Step XV : Jump to step X.
Flowchart : Refer Flowchart B.2(b).
Flowchart B.2(b)
Lab Manual
Micropro. & Interfacing Techniques (PU)
L-48
Lab Manual
Program :
Label
L1 :
L2 :
SKIP :
Instruction .model small .code MOV AL, 80H MOV DX, 00H MOV AL, FFH MOV BL, AL AND AL, 80H JZ SKIP MOV AL, BL OUT DX, AL INC AL CMP AL, FFH JNZ L1 DEC AL OUT DX, AL JNZ L2. JNZ L1. MOV AL, BL JMP L2.
(iv)
Trapezoidal wave :
Explanation :
Comment
Initialize Port A of 8255 as output port. Load DX with port address of port A. Initialize AL Check for MSB Initialize AL Output contents on port A. Compare AL with FFH. Decrement AL.
Initialize AL back.
We have to generate a trapezoidal wave using DAC interface. To generate trapezoidal wave, first we will see the trapezoidal wave. Port A of 8255 is used as output port.
Fig. 6 : Trapezoidal wave Now here, we will output the Part A, Part B, Part C, Part D and the Part E. In Part A, we will output 80 H to FFH. In Part B, we will output FFH, for a certain delay. In Part C, we will output FFH to 00H. In Part D, we will output 00H, for a certain delay. In Part E, we will output 00H to FFH.
Micropro. & Interfacing Techniques (PU)
Algorithm :
Step I Step II Step III Step IV Step V Step VI Step VII Step VIII Step IX Step X Step XI Step XII Step XIII Step XIV Step XV Step XVI Step XVII
L-49
: : : : : : : : : : : : : : : : :
Initialize the data section. Initialize port A as output port. Initialize AL = 80H i.e. initial value of the trapezoidal wave. Output contents of AL on port A of 8255. Increment AL. Check if AL = FFH ? If not, go to step IV. Output contents of AL i.e. FFH on port A. Call delay 1. Decrement AL. Output the contents of AL on port A of 8255. Is AL = 00 ? If not go to step IX. Output the contents of AL i.e. 00H on port A. Call delay 2 Increment AL. Output the contents of AL on port A. Check if AL = FFH ? If not, go to step XIV. Jump to step VII.
Flowchart : Refer Flowchart B.2(c).
Flowchart B.2(c)
Lab Manual
Micropro. & Interfacing Techniques (PU)
L-50
Lab Manual
Program : Label Instruction Comment . model small . data PORTA EQU 0006H address of Port A. Value db 80H initial value of trapezoidal wave. . code MOV AX, @ Data. Initialize the data segment. MOV DS, AX MOV AL, 80H Initialize port A as output port. MOV DX, Port A DX = address of Port A of 8255. OUT DX, AL MOV AL, Value Initialize AL with initial value of trapezoidal wave. L1 : MOV DX, AL Output the contents of AL on port A. INC AL Increment AL. CMP AL, FFH Compare AL with FFH. JNZ L1 UP : OUT DX, AL Output FFH on port A. CALL DELAY 1 L2 : DEC AL Decrement AL. OUT DX, AL Output contents of AL on port A. CMP AL, 00H Compare AL with 00H. JNZ L2 OUT DX, AL Output 00H on port A. CALL DELAY 2 L3 : INC AL Increment AL OUT DX, AL Increment contents on AL on port A. CMP AL, FFH Compare AL with FFH. JNZ L3 If not zero, continue. JMP UP The delay 1 and delay 2 routines, will be different because at the output we want a trapezoidal wave. Trapezoidal wave duration is not symmetric. Thus, delay routines are different. DELAY 1 PROC L4 : MOV BL, FFH Count for delay DEC BL Decrement count. JNZ L4 DELAY 1 ENDP DELAY 2 PROC L5 : MOV BH, 70H Count for delay DEC BH Decrement count. JNZ L5 DELAY 2 ENDP
Micropro. & Interfacing Techniques (PU)
(v)
Staircase wave :
Explanation :
L-51
Lab Manual
We have to generate a staircase wave using DAC interface. Fig. 7 shows a staircase wave.
Fig. 7 We have considered 8 levels for drawing the stair case wave i.e. 2, 4, 8, 16, 32, 64, 128 and 256. Their hex equivalent are 02 H, 04 H, 08 H, 10 H, 20 H, 40 H, 80 H and Hex equivalent for 255 is FFH. We will store these values in an array. You can also increase or decrease the levels, for staircase waveform. Each level will be outputted on Port A of 8255 which is configured as output port.
Algorithm :
Step I
:
Initialize the data section.
Step II
:
Initialize BX to the start of array.
Step III
:
Initialize port A of 8255 as output port.
Step IV
:
Initialize count = 08H.
Step V
:
Load AL with first step of staircase.
Step VI
:
Output the contents of AL on port A.
Step VII
:
Call delay.
Step VIII
:
Increment BX to point next step value.
Step IX
:
Decrement count.
Step X
:
Check if count = 0 ? If not, go to step V.
Step XI
:
Initialize count = 08H in CL.
Step XII
:
Decrement BX to next value.
Micropro. & Interfacing Techniques (PU)
L-52
Step XIII
:
Load the value, pointed by BX in AL register.
Step XIV
:
Output the contents of AL on port A.
Step XV
:
Call delay.
Step XVI
:
Decrement count.
Step XVII : Step XVIII :
Is count = 00 ? If not, go to step XII. Jump step IV.
Flowchart : Refer Flowchart B.2(d).
Flowchart B.2(d)
Lab Manual
Micropro. & Interfacing Techniques (PU)
L2 :
L3 :
Lab Manual
Program :
Label
L1 :
L-53
Instruction . model small . data PORT A EQU 0050H STEP DB 02H, 04H, 08H, 10H, 20H, 40H, 80H, FFH. COUNT DB 08H. . code MOV AX, @ Data MOV DS, AX MOV AL, 80H MOV DX, Port A OUT DX, AL MOV CL, COUNT MOV AL, 00H Call delay MOV BX, OFFSET STEP MOV AL, [BX] OUT DX, AL CALL DELAY INC BX DEC CL JNZ L1 MOV CL, COUNT DEC BX MOV AL, [BX] OUT DX, AL Call delay DEC COUNT JNZ L2 JMP L1 DELAY PROC MOV CH, FFH DEC CH JNZ L3 DELAY ENDP
Program 3 :
Comment
Initialize data segment. Initialize 8255 Port A as output port. DX = address of Port A. Initialize CL = 08H. Initialize AL = 00H. BX = Start of STEP. AL = Step value. Output contents of AL on Port A. Increment BX to point next step value. Decrement count. Initialize CL = count. Decrement BX to point next step value. Output contents of AL on Port A.
Write 8086 ALP to rotate a stepper motor for given number of steps at a given angle and in the given direction of rotation based on the user choice such as, i) ii)
If ‘C’ key is pressed - clockwise rotation. If ‘A’ key is pressed – anticlockwise rotation.
Micropro. & Interfacing Techniques (PU)
L-54
Lab Manual
iii) If ‘B’ is pressed – ½ clockwise and Vz anticlockwise rotation. iv) If ‘S’ key is pressed – stop rotation. Also write routines to accelerate and deaccelerate the motor.
Explanation :
The block diagram of a microprocessor based control scheme for a stepper motor is shown in Fig. 8. The motor has four windings A, B, C and D which are driven by a single phase excitation scheme i.e. at a time only one winding is energized. The sequence in which the windings are to be energized is stored in the memory of the microprocessor system in the form of a look up table. The 8255 is configured such that port A acts as an output port. The output of the 8255 are used to drive the four transistors. The freewheeling diodes are connected across each phase of the phase windings to protect the transistors against high forward voltage at the time of their turn off. When the look up table is output on the output port in the sequence 0AH, 09H, 05H, 06H, the motor rotates in clockwise direction. When the sequence of outputting the contents of look up table is reversed i.e. 06H, 05H, 09H, 0AH the motor starts rotating in counter clockwise or anticlockwise direction. If the sequence of rotation is 0AH, 09H, 06H, 05H the motor rotates is ½ clockwise and ½ anticlockwise rotation. The speed of motor can be changed by changing the rate at which look up table contents are being sent out. The position control is possible by programming the processor to keep a count of the number of pulses being sent out because each pulse corresponds to rotation through a specific angle.
Fig. 8
Micropro. & Interfacing Techniques (PU)
Flowchart : Refer Flowchart B.3.
Program :
Label
L-55
Lab Manual
Instruction
Comment
MESS MACRO MSG MOV AH, 09W LEA DX, MSG INT 21H ENDM . MODEL SMALL . DATA Clockwise DB 0AH, 09H, 05H, 06H Anticlockwise DB 06H, 05H, 09H, 0AH Half-clk DB 0AH, 09H, 06H, 05H. MSG 1 DB 0AH, 0DH, ‘Menu $’. MSG 2 DB 0AH, 0DH, ‘C : clockwise rotation’ MSG 3 DB 0AH, 0DH, ‘A : Anticlockwise rotation’. MSG 4 DB 0AH, 0DH, ‘B : ½ clockwise and ½ anticlockwise rotation’ MSG 5 DB 0A, 0DH, ‘S : Stop rotation’ MSG 6 DB 0A, 0DH, ‘Accept choice’. MSG 7 DB 0A, 0DH, ‘Wrong choice’. . CODE MOV AX, @Data MOV DS, AX L1 :
MESS MSG 1
Display Menu.
MESS MSG 2 MESS MSG 3 MESS MSG 4 MESS MSG 5 MESS MSG 6
Accept choice from user.
MOV AH, 01H INT 21H MOV BL, AL
Choice in BL
CMP BL, 41H
If choice = A
Micropro. & Interfacing Techniques (PU)
Label
L-56
Lab Manual
Instruction
Comment
JE clkrot CMP BL, 42H
Is choice = B. (42 is ASCII equivalent for B)
JE half CMP BL, 43H
Is choice = ‘C’.
JE antirot CMP BL, 53H
Is choice = ‘S’.
JE endd.
clkrot :
MESS MSG 7
display ‘wrong choice’
JMP L1
display Menu again.
CALL clockwiserot JMP L1
half :
CALL halfclockhalfanti JMP L1
antirot :
CALL anticlockwiserot. JMP L1
endd:
MOV AH, 4CH INT 21H. clockwiserot PROC NEAR MOV AL, 80H
Initialize port A as output port.
MOV DX, 00
Load port address of port A in DX.
OUT DX, AL
Output contents of AL on port A.
MOV SI, Offset clockwise. L1 :
MOV BL, 04H
Load sequence count.
MOV AL, [SI]
AL = code
OUT DX, AL
Output the excitation code on port A.
CALL DELAY
Wait
INC SI
Increment SI to point next code.
DEC BL
decrement sequence count
JNZ L1 RET clockwiserot ENDP.
Micropro. & Interfacing Techniques (PU)
L-57
Lab Manual
Flowchart B.3 Program 4 :
Write 8086 ALP to print a text message on printer using centronix parallel printer interface.
Explanation :
Whenever data on computer is to be printed, the computer sends an INIT pulse first, in order to initialize the printer. The computer then checks for a BUSY signal, in order to know whether the printer is ready to receive data or not. If the BUSY signal is not low, then the computer checks for the PE signal. If this signal is high, then display message that the “Printer is OUT OF PAPER”. If the PE signal is low the computer checks –––––– for the ERROR signal. If this signal is low, it indicates that printer is in “Paper End” state, “Offline” state and “Error” state. In such a case display message “PRINTER OFFLINE” and stop.
Micropro. & Interfacing Techniques (PU)
L-58
Lab Manual
Fig. 9
Fig. 10 If the BUSY signal is low, then the computer sends an ASCII code on eight parallel ––– data lines. The computer also sends a STB signal to the printer, to indicate that valid –––– data is available on the data bus. In response, the printer sends an ACK (acknowledgement) signal, to indicate that data to be printed is received. The rising edge –––– of the ACK signal, resets the BUSY signal from the printer. When the computer sees that BUSY signal is low, it sends the next character along with strobe and the sequence is repeated till the last character to be printed is transferred. Fig. 10 shows the circuit for interfacing centronix type parallel input printer to 8255 A. Port A is used as an output –––––– port, to send 8-bit data to the printer. Port B is used an input port to check the ERROR , PE and BUSY signals. –––– ––– The port C signals, PC7 is used as an ACK signal and PC6 is used as STB signal. –––– The PC0 is used to send INIT signal to initialize the printer.
Micropro. & Interfacing Techniques (PU)
L-59
Lab Manual
Algorithm :
Step I Step II Step III
: Initialize the data section. : Initialize the pointer to point to the string. : Initialize the counter with number of characters in the string that are to be printed. Step IV : Initialize the 8255, port A with output port, portB as input port. –––– Step V : Send INIT signal to initialize the printer. Step VI : Check for BUSY signal. If it is low go to step VII, else go to step XIII. Step VII : Send the character to be printed. –––– –––– Step VIII : Check for ACK . If not received, then wait till the ACK signal is received. Step IX : Increment the string pointer, to point to the next character to be printed. Step X : Decrement the counter. Step XI : Is counter = 0 ? If yes, go to step XVII. Step XII : If not goto step VI. Step XIII : Check if PE signal is high. If not, go to step XV. Step XIV : Display message “Paper out”. –––––– Step XV : Check if ERROR signal is low. If not goto step XVII. Step XVI : Display message “Printer offline”. Step XVII : Stop. Flowchart : Refer flowchart B.4. Program : The control word for 8255 is I/O Mode A PA PCU Mode B PB PCL 1 Label
0
1
0
X
0
Instruction . model small . data PORTA EQU 0000 PORTB EQU 0002 PORTC EQU 0004 CWR EQU 0006 MSG 1 DB 10, 13, ‘Printer Out of Printer’. MSG 2 DB 10, 13, ‘Printer offline’. MSG 3 DB 10, 13, ‘Printing completed’. MSG 4 DB 10, 13, ‘This matter is to be printed’. COUNT DB 15. . code MOV AX, @ Data MOV DS, AX LEA BX, MSG 4 MOV DX, CWR
1
0
= A2H Comment
Initialize the data segment. Initialize pointer to start of string. DX = control word register address.
Micropro. & Interfacing Techniques (PU)
Label
Instruction MOV AL, 0A2H OUT DX, AL MOV AL, 07H OUT DX, AL MOV AL, 00H OUT DX, AL
Back :
MOV CX, 0FFFH DEC CX LOOP BACK MOV AL, 01H
UP :
L2 :
OUT DX, AX MOV DX, PORT B IN AL, DX MOV AH, AL AND AL, 01H JNZ CHECK MOV AL, [BX] MOV DX, Port A OUT DX, AL MOV DX, Port C IN AL, DX JNZ L2 MOV CL, COUNT DEC CL JNZ UP
CHECK :
CHECK1 :
JMP ENDD MOV AL, AH AND AL, 02H MOV AL, AH JZ CHECK 1 LEA DX, MSG 1 MOV AH, 09H INT 21H AND AL, 04H JNZ UP LEA DX, MSG 2 MOV AH, 09H INT 21H
L-60
Lab Manual
Comment Load control word in AL. Make INTEA high to enable INTRA.
–––– Make PC0 low, so give INIT signal to the printer for initialisation. Wait for 50 s, so that printer will get Initialized.
–––– INIT = 1
Save the status in AH also. Check for BUSY signal. If high goto CHECK. Load the first character in AL. Load the address of Port A in DX. Send the character to be printed. DX = address of Port C. –––– Check for ACK by checking status of INTRA. Load count in CL. Decrement count. Continue till all the characters are printed. Load the printer status in AL. Check for PE signal high. Load status in AL. Display Message “Printer out of Paper”.
–––––– Check for ERROR signal. Display Message “Printer offline”.
Micropro. & Interfacing Techniques (PU)
Label ENDD :
L-61
Instruction JMP UP LEA DX, MSG 3
Lab Manual
Comment Display Message “Printing completed”.
MOV AH, 09H INT 21H MOV AH, 4CH INT 21H END.
Terminate Program.
Flowchart B.4
Micropro. & Interfacing Techniques (PU)
L-62
Lab Manual
Programs of 8253 Program 1 :
Write 8086 ALP to program 8253 in mode 0, modify the program for hardware retriggerable monoshot mode. Generate a square wave with a pulse of 1 ms. Comment on the difference between Hardware Triggered and software triggered strobe mode. Observe the waveform at GATE and OUT pin of IC 8254 on CRO. (i)
To program 8254 in mode 0 means to initialize it.
Control word Corel A
(ii)
MOV AL, 31 H ; Counter 0, mode 0 CWR MOV DX, 5006 ; CWR address OUT DX, AL ; Loads control word in the CWR The modification in the above program, for mode 5 i.e. Hardware retriggerable monoshot mode is only to change the control word.
Control word
Corel B
MOV AL, 3BH ; Counter 0, mode 5 CWR MOV DX, 5006 ; CWR address OUT DX, AL ; Loads control word in CWR. (iii) Program to generate a square wave with a pulse of 1 ms. Step 1 : Assume the Counter 0 is used to generate square wave and addresses of Counter 0 = 10 H and Control register = 13 H. Step 2 : The output period required is 1 ms. The input frequency is 1 MHz, so input period = 1 s. Required period 1 ms Count value = Input period = = (1000)10 1 s Step 3
: The control word format to initialize counter 0, 16 bit counter, BCD counting and square wave generator mode will be as follows :
Corel C
Micropro. & Interfacing Techniques (PU)
L-63
Lab Manual
Step 4 : The 8253 initialisation program will be as follows : MOV AL, 37H ; Initialise counter 0, MOV DX, 0013 H ; mode 3 CWR address OUT DX, AL ; 16 bit count and BCD counter MOV AL, 00H ; Load LSB count value to counter 0 MOV DX, 10H OUT DX, AL MOV AL, 10H ; Load MSB count value to counter 0 MOV DX, 10H OUT DX, AL (iv) For the difference between Hardware triggered and software triggered strobe mode please refer chapter 16. (v) For the wave forms at GATE and OUT pin of IC 8254.
Programs of 8279 Program 1 :
Write a program to initialize and operate 8279 for the following specifications. The addresses of 8279 are A2 H and B2 H (i) (ii) (iii)
Soln. : Step I
D7
D6
D5
D4
D3
D2
D1
D0
dp
g
f
e
d
c
b
a
:
According to specification (i) the 8279 should be initialized in 16 digit right entry mode. (a) Keyboard /display mode set command : DD = 11; KKK should be encoded KKK = 000 ; The command word is,
Step II :
12 digit display to display roll nos. from 1 to 12 Display scan time 15.24 msec. and external clock is 3 MHz. Clear code is FF H
D7
D6
D5
D4
D3
D2
D1
D0
0
0
0
0
0
0
0
0
= 18 H
Specification (ii) gives external clock frequency and display scan time. Display scan time 10.24 Scan time = = 16 = 640 s. 24 Clock cycle time Internal clock PPPPP
640 s 64 = 10 s = 100 kHz 3 106 = 3010 = 1E H = 100 103
=
(b) Program clock : PPPPP = 11110; The command word is, 0011 1110 = 3E H. Step III : (c) Clear code command : The command word is, 1101 1100 = DC H; CD2CD1CD0 = 111, CF = 0, CA = 0
Micropro. & Interfacing Techniques (PU)
L-64
Lab Manual
Step IV :
According to specification (iii) the display is common anode type that is logic 0 corresponds to segment ‘ON’ and logic 1 corresponds to segment ‘OFF’. It also gives the connection of segments with A3 - A0 and B3 - B0 lines. We will have look up Table B.4 as follows : Table B.4 : Look-up Table dp (D7
Step V :
g D6
f D5
e D4
d D3
c D2
b D1
a D0)
Data
Address
1 1 1 1 1 1 0 0 1 F9 2000 2 1 0 1 0 0 1 0 0 A4 2001 3 1 0 1 1 0 0 0 0 B0 2002 4 1 0 0 1 1 0 0 1 99 2003 5 1 0 0 1 0 0 1 0 92 2004 6 1 0 0 0 0 0 1 0 82 2005 7 1 1 1 1 1 0 0 0 f8 2006 8 1 0 0 0 0 0 0 0 80 2007 9 1 0 0 1 0 0 0 0 90 2008 A 1 0 0 0 1 0 0 0 88 2009 B 1 0 0 0 0 0 1 1 83 200A C 1 1 0 0 0 1 1 0 C6 200B (d) Write display RAM command : In right entry mode, the status of display is given as follows :
According to specification digit 12 to digit 15 are not connected. Hence the first entry should be displayed on rightmost digit (digit 11). After first entry, it shifts the address of digit and then displays contents of corresponding location. i.e. first entry will be displayed on digit 12 AI = 1, A3A2A1A0 = 1100 Hence the command word is, 1001 1100 = 9C H Step VI : Now we can find address of control/status and data register. A7
A6
A5
A4
A3
A2
A1
A0
1 1
0 0
1 1
0 1
0 0
0 0
1 1
0 0
Here addresses show a change in A4 bit. Hence A4 of microprocessor is connected to A0 line of 8279. The address of control/status register is B2 while the address of data register is A2. Step VII : Flowchart of the program is shown in Fig.10(a)
Micropro. & Interfacing Techniques (PU)
L-65
Lab Manual
Title INITIALIZATION OF 8279 Label Instruction Comments .model small .code
MOV AL, 00H OUT B2 H, AL MOV AL, 3E H OUT B2, AL MOV AL, DC H OUT B2, AL MOV AL, 9C H OUT B2, AL L2: L1:
MOV BX, 2000 H MOV CX, 000F H MOV AL, [BX]
Keyboard/display mode set command Program CLK Command Clear code command 9CH for left entry mode Write display RAM command Character counter Read character code from memory
OUT A2 H, AL CALL DELAY (1 sec.) INC BX DEC CX LOOPNE L1 LOOP L2 end
Fig. 10(a)
Programs of 8251 Program 1:
Perform an experiment to establish communication between two 8251 systems A and B. Program 8251 system A in asynchronous transmitter mode and 8251 system B in asynchronous receiver mode. Write an ALP to transmit the data from system A and receive the data at system B. The requirements are as follows:
Transmission :
A message is stored as ASCII characters in the memory. A message specifies the number of characters to be transmitted as the first byte.
Reception : (i) (ii)
Message is retrieved and stored in the memory. Successful reception should be indicated. The interfacing schematic will be as Fig. 11. The mode word required for asynchronous mode, 8 bit character. We assume baud rate factor 16, No parity check and 1 stop bit.
Micropro. & Interfacing Techniques (PU)
L-66
Lab Manual
Fig. 11 The mode word format for transmitter and receiver will be as follows :
COREL 20
(iii)
Command word format to enable Tx and Rx will be as follows :
COREL 21
(iv) (v) (vi)
Status word to check TxRDy will be 01H and RxRDy will be 02H. The flow chart for both systems will be as shown Flowchart B.5. Program for both systems will be same.
Program :
Label
Instruction
Comment
MOV BX, address1
Memory pointer for Tx
MOV DX, address2
Memory pointer for Rx
Micropro. & Interfacing Techniques (PU)
Label
L-67
Lab Manual
Instruction MOV AL, 00 H
Comment Dummy 00's to 8251
OUT F3 H, AL OUT F3 H, AL OUT F3 H, AL MOV AL, 40 H
Internally reset 8251
OUT F3 H, AL MOV AL, 4E H
Mode word
OUT F3 H, AL MOV AL, 15 H
Command word
OUT F3 H, AL UP :
IN AL, F3 H
Status word
AND AL, 01 H TEST AL, 01 H
Check TxRDy
CALL Tx data
call subroutine 1
IN AL, F3 H
status word
AND AL, 02 H TEST AL, 02 H
Check RxRDy
CALL Rx data
Call subroutine 2
LOOP UP
Go to up.
Subroutine 1 Tx data MOV AL, [BX]
Take data from memory
OUT F2 H, AL
Data 8251 Tx
INC BX
memory pointer = memory pointer + 1
RET
Go to main program.
Subroutine 2 Rx data IN F2 H, AL
Take data from Rx
MOV [DX], AL
Store data in memory
INC DX
Memory pointer = Memory pointer +1
RET
Go to main program
Micropro. & Interfacing Techniques (PU)
L-68
Lab Manual
Flowchart B.5
8259 Programs Program 1 :
Write 8086 APL to interface 8259 in cascade mode (M/S) and demonstrate execution of ISR in following manner : Main program will display two digits up counter. When slave IRQ interrupt occurs, it clears the counter and starts up counting again. When Master IR1 interrupt occurs, it resets the counter to FFH and starts down counting.
Explanation :
Fig. 12 shows the interfacing of 8259 with 8086 in cascaded mode. Eight interrupt lines IR0-IR7 are connected to the interrupt request register (IRR).A microprocessor uses
Micropro. & Interfacing Techniques (PU)
L-69
Lab Manual
two PICs to provide 15 interrupt inputs (7 on the master PIC and 8 on the slave one). the following table lists the interrupt sources on the PC . Input on 8259A
Priority
80x86 INT
Highest
08h
Timer Chip
IRQ 1
09h
Keyboard
IRQ 2
0Ah
Cascade for controller 2 (IRQ 8-15)
IRQ 9/1
71h
CGA vertical retrace (and other IRQ 2 devices)
IRQ 8/0
70h
Real-time clock
IRQ 10/2
72h
Reserved
IRQ 11/3
73h
Reserved
IRQ 12/4
74h
Reserved in AT, auxiliary device on PS/2 systems
IRQ 13/5
75h
FPU interrupt
IRQ 14/6
76h
Hard disk controller
IRQ 15/7
77h
Reserved
IRQ 3
0Bh
Serial Port 2
IRQ 4
0Ch
Serial Port 1
IRQ 5
0Dh
Parallel port 2 in AT, reserved in PS/2 systems
IRQ 6
0Eh
Diskette drive
0Fh
Parallel Port 1
IRQ 0
IRQ 7
Lowest
Device
For cascaded 8259, the INT pin of the slaves are connected to interrupt request pins ––––– ––––– (IR0 – IR7) and INTA to the INTA of master 8259. The CAS2 – CAS0 lines work as output for the master and input for the slave. The CAS2 – CAS0 lines act as select lines for addressing the slaves. Fig. 12 shows cascaded 8259 interfaced with 8086 in maximum mode.
Micropro. & Interfacing Techniques (PU)
L-70
Lab Manual
Fig. 12 : Interfacing 8259 with 8086 (8259 – cascaded, 8086 – maximum mode)
m(12.15)
Program :
Label START:
L1 :
Instruction MOV AX,1000H MOV DS,AX MOV AX,4000H MOV SS,AX MOV SP,0500H MOV AX,0000H MOV ES,AX MOV AX,1000H MOV [ES:0008H],AX MOV AX,2000H MOV [ES:0009H],AX STI JMP L1
Comment
Enable interrupt
Micropro. & Interfacing Techniques (PU)
L-71
Lab Manual
Interrupt service routine, Instruction MOV AL,[08H] INC AL DAA POP AX MOV AL,[09H] DEC AL POP AX IRET
TSR Programs Program 1 :
Write a TSR program in 8086 ALP to implement Real Time Clock (RTC). Read the Real Time from CMOS chip by suitable INT and FUNCTION and display the RTC at the bottom right corner on the screen. Access the video RAM directly in your routine.
Program : Label
Instruction .model small .stack 100h .code
resi: push ax push bx push cx push dx push es push di mov ax,0b800h mov es,ax mov di,140 mov ah,02 int 1Ah mov bx,cx mov ah,07 mov cx,0504h cld
Comment
Micropro. & Interfacing Techniques (PU)
Label l2:
l3:
l4:
l5: l6:
l7:
jmp dword ptr cs: data: init :
L-72
Instruction cmp ch,03 jne l3 mov al,':' jmp l4 rol bx,cl mov al,bl and al,0fh add al,30h stosw dec ch jnz l2 mov cx,0304h cld mov al,':' jmp l7 rol dh,cl mov al,dh and al,0fh add al,30h stosw dec ch jnz l6 pop di pop es pop dx pop cx pop bx pop ax old_ip old_ip dw 0 old_cs dw 0 mov ax,cs mov ds,ax mov ah,35h mov al,08 int 21h mov word ptr old_ip,bx mov word ptr old_cs,es mov ah,25h
Lab Manual
Comment
Micropro. & Interfacing Techniques (PU)
Label
L-73
Instruction mov al,08 lea dx,resi int 21h lea dx,init add dx,100h mov cl,4 shr dx,cl inc dx mov ah,31h mov al,00 int 21h end init
Lab Manual
Comment
TSR Programs Program 1 :
Write a TSR program in 8086 ALP to implement Screen Saver. Screen Saver should get activated if the keyboard is idle for 7 seconds. Access the video RAM directly in your routine.
Program : Label
Instruction .model small .stack 500h .code
resi_timer: cmp cs:flag,1 je timer_2 dec cs:count jnz timer_quit push cx push ax push dx push es push di push si push ds mov cx,0b800h mov ds,cx mov si,00 mov cx,cs
Micropro. & Interfacing Techniques (PU)
Label
timer_quit: timer_2 :
Instruction mov es,cx lea di,buf cld mov cx,2000 rep movsw mov cs:flag,1 mov cx,0b800h mov es,cx mov di,0 mov cx,2000 mov ax,0720h cld rep stosw pop ds pop si pop di pop es pop dx pop ax pop cx jmp dword ptr cs:old_ip_timer dec cs:spd jnz timer_2_quit mov cs:spd,2 push cx push ax push dx push es push di push si push ds mov cx,0b800h mov es,cx mov di,cs:pos mov ax,0720h cld stosw
L-74
Lab Manual
Micropro. & Interfacing Techniques (PU)
Label
Instruction inc cs: pos inc cs: pos cmp cs: pos,4000 jb t4 mov cs: pos,0
t4:
mov di,cs:pos mov cx,cs
t8:
timer_2_quit: resi_kbd:
mov ds,cx mov cx,5 lea si,string mov ah,07 lodsb stosw loop t8 pop ds pop si pop di pop es pop dx pop ax pop cx jmp dword ptr cs: old_ip_timer mov cs:count,182 cmp cs:flag,0 je kbd_quit push cx push ax push dx push es push di push si push ds mov cx,0b800h mov es,cx mov di,00 mov cx,cs mov ds,cx lea si,buf cld
L-75
Lab Manual
Micropro. & Interfacing Techniques (PU)
Label
kbd_quit:
init :
Instruction mov cx,2000 rep movsw mov cs:flag,0 pop ds pop si pop di pop es pop dx pop ax pop cx jmp dword ptr cs:old_ip_kbd old_ip_timer dw ? old_cs_timer dw ? old_ip_kbd dw ? old_cs_kbd dw ? flag db 0 count dw 182 buf db 4000 dup(0) pos dw 0 spd db 2 string db 'HELLO' mov ax,cs mov ds,ax mov ah,35h mov al,8 int 21h mov word ptr old_ip_timer,bx mov word ptr old_cs_timer,es mov ah,25h mov al,8 lea dx,resi_timer int 21h mov ah,35h mov al,9 int 21h mov word ptr old_ip_kbd,bx mov word ptr old_cs_kbd,es mov ah,25h mov al,9
L-76
Lab Manual
Micropro. & Interfacing Techniques (PU)
Label
L-77
Lab Manual
Instruction lea dx,resi_kbd int 21h lea dx,init add dx,100h mov cl,4 shr dx,cl inc dx mov ah,31h mov al,00 int 21h end init
Micropro. & Interfacing Techniques (PU)
L-78
Note
Lab Manual
View more...
Comments