mit

78
5/27/2018 mit-slidepdf.com http://slidepdf.com/reader/full/mit55cf97f2550346d0339499e0 1/78  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 :  C N .  L N = 10 .   N .   C .   I . I .  C .   ADD , .  I I .  D .   AL.  D . F : B D : 01 02 03 04 05 06 07 08 09 0A : 01 + 02 + 03 + 04 + 05 + 06 + 07 + 08 + 09 + 0A = 37 H  Algorithm : : I . : I I . : I C . : I . :  A , . : I .. I. : D C. : C C, I. : D . : .  Flowchart : Refer flowchart A.1. 

Upload: pooja-bk

Post on 17-Oct-2015

193 views

Category:

Documents


0 download

DESCRIPTION

lab manual

TRANSCRIPT

  • 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) L-2 Lab Manual

    Program :

    Label Instruction Comment

    .model small

    .data

    blk1 db 01, 02, 03, 04, 05, 06, 07, 08, 09, 0AH

    count dw 0AH

    .code

    mov ax, @data initialise data segment

    mov ds, ax

    mov ax, 0

    mov si, offset blk1

    initialise pointer

    mov cx, count initialise counter

    cld df=0

    l1: add al, [si] 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

    l2: 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 if letter add 37H else only add

    30H

    l4: add dl, 30H

    mov ah, 02 INT 21H (Display character)

    int 21H

    dec ch Decrement Count

    jnz l2

    mov ah, 4cH Terminate Program

    int 21H

    end 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 : Initialise the data in the source memory and destination memory.

    Step II : Initialise SI and DI with source and destination address.

    Step III : Initialise CX register with the count.

    Step IV : Initialise the direction flag to zero.

    Step V : Transfer the data block byte by byte to destination.

    Step VI : Decrement CX.

    Step VII : Check for count in CX, if not zero goto step V else goto step VIII.

    Step VIII : Display the bytes in destination location.

    Step IX : Stop.

  • Micropro. & Interfacing Techniques (PU) L-4 Lab Manual

    Flowchart : Refer flowchart A.2(a).

    Program :

    Label Instruction Comment

    .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 initialize data & extra

    segment

    mov ds, ax

    mov es, ax

    mov si, offset src_blk si to point to source

    block

    mov di, offset dest_blk di to point to

    destination block

    mov cx, count initialize counter

    cld df=0

    again : rep movsb transfer contents

    mov di, offset dest_blk di to point to

    destination block

    mov bh, 0Ah initialize counter

    up: mov bl, [di] store result in bl

    mov cx, 0204h Count of digits to be

    displayed in ch and

    digits to be mrolled

    in cl

    l1: 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, 09h check if digit is 0-9 or

    letter A-F

    jbe l12

    add dl, 07h if letter add 37H else

    only add 30H

    l12: add dl, 30h

    Flowchart A.2(a)

  • Micropro. & Interfacing Techniques (PU) L-5 Lab Manual

    Label Instruction Comment

    mov ah, 02 Function 02 under

    INT 21H

    int 21h

    dec ch Decrement Count

    jnz l1

    dec bh decrement counter

    inc di

    mov ah, 02h display space between

    bytes

    mov dl, ' '

    int 21h

    cmp bh, 00h repeat till all bytes are

    displayed

    jne up

    mov ah, 4ch 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>

  • Micropro. & Interfacing Techniques (PU) L-6 Lab Manual

    (B) To perform overlapped block transfer

    Program Statement :

    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 Comment

    .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 initialize data & extra

    segment

    mov ds, ax

    mov es, ax

  • Micropro. & Interfacing Techniques (PU) L-7 Lab Manual

    Label Instruction Comment

    mov si, offset src_blk si to point to source block

    mov di, offset dest_blk di to point to destination

    block

    mov cx, count initialize counter

    cld df=0

    again: rep movsb transfer contents

    mov di, offset dest_blk di to point to destination

    block

    mov bh, 0Ah initialize counter

    up: mov bl, [di] store result in bl

    mov cx, 0204h Count of digits to be

    displayed in ch and digits

    to be rolled in cl

    l1: 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, 09h check if digit is 0-9 or letter

    A-F

    jbe l12

    add dl, 07h if letter add 37H else only

    add 30H

    l12: add dl, 30h

    mov ah, 02 Function 02 under

    INT 21H

    int 21h

    dec ch Decrement Count

    jnz l1

    dec bh decrement counter

    inc di

    mov ah, 02h display space between bytes

    mov dl, ' '

    int 21h

    cmp bh, 00h repeat till all bytes are

    displayed

    jne up

    mov ah, 4ch normal termination to dos

    int 21h

    end

    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 : Initialize the data segment.

    Step II : Initialize BX = 0000 H and DH = 00H.

  • Micropro. & Interfacing Techniques (PU) L-9 Lab Manual

    Step III : Load the number in AX.

    Step IV : Compare number with 10000 decimal. If below goto step VII else goto

    step V.

    Step V : Subtract 10,000 decimal from AX and add 1 decimal to DH

    Step VI : Jump to step IV.

    Step VII : Compare number in AX with 1000, if below goto step X else goto

    step VIII.

    Step VIII : Subtract 1000 decimal from AX and add 1000 decimal to BX.

    Step IX : Jump to step VII.

    Step X : Compare the number in AX with 100 decimal if below goto step XIII

    Step XI : Subtract 100 decimal from AX and add 100 decimal to BX.

    Step XII : Jump to step X

    Step XIII : Compare number in AX with 10. If below goto step XVI

    Step XIV : Subtract 10 decimal from AX and add 10 decimal to BX..

    Step XV : Jump to step XIII.

    Step XVI : Add remainder in AX with result in BX.

    Step XVII : Display the result in DH and BX.

    Step XVIII : Stop.

    Flowchart : Refer flowchart A.3(a).

    Program :

    Label Instruction Comment

    .model small

    .stack 100

    .code

    mov ax, 0ffffh hex number to find it's bcd

    mov bx, 0000

    mov dh, 0

    l9 : cmp ax, 10000 if ax>10000

    jb l2

    sub ax, 10000 subtract 10000

    inc dh add 1 to dh

    jmp l9

    l2 : cmp ax, 1000 if ax>1000

    jb l4

    sub ax, 1000

    add bx, 1000h add 1000h to result

    jmp l2

    l4 : cmp ax, 100 if ax>100

    jb l6

    sub ax, 100

  • Micropro. & Interfacing Techniques (PU) L-10 Lab Manual

    Label Instruction Comment

    add bx, 100h add 100h to result

    jmp l4

    l6 : cmp ax, 10 if ax>10

    jb l8

    sub ax, 10

    add bx, 10h add 10h to result

    jmp l6

    l8 : add bx, ax add remainder to result

    mov ah, 02

    mov cx, 0204h Count to display 2 digits

    go: rol dh, cl

    mov dl, dh

    and dl, 0fh

    add dl, 30h display 2 msb digits

    int 21h

    dec ch

    jnz go

    mov ch, 04h Count of digits to be displayed

    mov cl, 04h Count to roll by 4 bits

    l12: 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 l14

    add dl, 07 if letter add 37H else only add

    30H

    l14: add dl, 30H

    mov ah, 02 Function 2 under INT 21H (Display character)

    int 21H

    dec ch Decrement Count

    jnz l12

    mov ah, 4cH Terminate Program

    int 21H

    end

    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 : Initialize the data segment.

    Step II : Load the MSB of word in register AX.

    Step III : Compare it with 0, if zero goto step VII else goto step IV.

    Step IV : decrement AX and initalize BX = 0000.

    Step V : add 10000 decimal to BX.

    Step VI : Jump to step III.

    Step VII : Load LSB of word in register AX.

    Step VIII : Compare it with 1000, if below ogto step XII else goto step IX.

    Step IX : subtract 1000 H from AX.

    Step X : Add 1000 decimal to BX.

  • Micropro. & Interfacing Techniques (PU) L-12 Lab Manual

    Step XI : Jump to step VIII

    Step XII : Compare number in AX now with 100 H, if below goto step XVI, else

    goto step XIII.

    Step XIII : Subtract 100 H from AX.

    Step XIV : Add 100 decimal to BX.

    Step XV : Jump to step XII.

    Step XVI : Compare number in AX with 10H, if below goto step XX, else goto

    step XVII.

    Step XVII : Subtract 10 H from AX

    Step XVIII : Add 10 decimal to BX

    Step XIX : Jump to step XVI

    Step XX : Add contents of AX and BX.

    Step XXI : Display the result.

    Step XXII : 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

    mov ax, word ptr a+2 checking msb no

    mov bx, 0000h intialize hex result

    l11: cmp ax, 0 cmp ax

    jz l10

    dec ax if ax=1 then it means

    no>10000

    add bx, 10000 so add 10000 to bx

    jmp l11

    l10: mov ax, word ptr a load lsb part in ax

    l2 : cmp ax, 1000h if ax>1000h

    jb l4

    sub ax, 1000h

    add bx, 1000 add 1000 to result

    jmp l2

  • Micropro. & Interfacing Techniques (PU) L-13 Lab Manual

    Label Instruction Comment

    l4 : cmp ax, 100h 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 : add bx, ax add remainder to result

    mov ch, 04h Count of digits to be

    displayed

    mov cl, 04h Count to roll by 4 bits

    mov bx, ax Result in reg bx

    l2: 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 if letter add 37H else only

    add 30H

    l4: 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 : Initialize the data and stack memory.

    Step II : Using Macro display Menu.

    1. Accept 2. Length 3. Reverse

    4. Palindrome 5. Exit.

  • Micropro. & Interfacing Techniques (PU) L-15 Lab Manual

    Step III : Accept choice from user using INT 21H, function 01H.

    Step IV : IS choice = 1 jump to step XI else goto step V.

    Step V : IS choice = 2 jump to step XIV else goto step VI.

    Step VI : IS choice = 3 jump to step XVII else goto step VII.

    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) L-16 Lab Manual

    Program :

    Label Instruction Comment

    TITLE STRING OPERATIONS

    MESS MACRO MSG DEFINITION OF MACRO MESS

    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 Intialize data and extra segment

    mov ds, ax

    mov es, ax

    ak : mess msg1 display menu

    mess msg21

    mess msg22

    mess msg23

    mess msg24

    mess msg25

    mess msg3 accept choice

    mov ah, 01h

  • Micropro. & Interfacing Techniques (PU) L-17 Lab Manual

    Label Instruction Comment

    int 21h

    mov bl, al Choice BL

    cmp bl, 31h if choice=1

    je acc Accept string

    cmp bl, 32h if choice=2

    je len Find lenth of string

    cmp bl, 33h if choice=3

    je rev Reverse string

    cmp bl, 34h if choice=4

    je pal Check if string is palindrome

    cmp bl, 35h if choice=5

    je endd exit

    mess msg4 Wrong Choice

    jmp ak

    acc : call accept

    jmp ak

    len : call lent

    jmp ak

    rev : call reverse

    jmp ak

    pal: call pall

    jmp ak

    endd: mov ah, 4ch

    int 21h accept procedure

    accept proc near

    mess msg5

    mov ah, 0ah Accept String

    lea dx, str1

    int 21h

    RET

    accept endp length procedure

    lent proc near

    mess msg7

    mov dl, str1+1 Dl contains length of String

    or dl, 30h

    mov ah, 02h Display Length

    int 21h

    ret

    lent endp reverse procedure

  • Micropro. & Interfacing Techniques (PU) L-18 Lab Manual

    Label Instruction Comment

    reverse proc near

    mess msg6

    mov ch, 00h

    mov cl, str1+1 Cl has length of string

    sub cl, 01h

    lea si, str1+2 DESTINATION STRING

    lea di, str1+2 DESTINATION STRING

    repz movsb COPY TO TRAVERSE TILL END

    OF FIRST STR

    mov cl, str1+1

    lea di, str3+2 DESTINATION STRING

    loop1: mov dx, [si] dx contains rightmost character

    mov ah, 02h

    int 21h display character

    mov [di], dx copy character to destination

    dec si

    inc di

    dec cl

    cmp cl, 00h

    jne loop1

    ret

    reverse endp palindrome procedure

    pall proc near

    mess msg6

    mov ah, 09h

    lea dx, str1+2 str1 contains original string

    int 21h

    call reverse str3 has reversed string

    lea di, str3+2

    mov ah, 00h

    mov dh, 00h

    lea si , str1+2

    mov cl, str1+1 CL contains Length of string

    loop2 mov al, byte ptr[si]

    mov bl, byte ptr[di]

    dec cl Decrement count

    cmp cl, 00h

    je loopa

    cmp al, bl Compare characters

  • Micropro. & Interfacing Techniques (PU) L-19 Lab Manual

    Label Instruction Comment

    je loop3 if same goto loop3

    loopa cmp cl, 00h if checked all characters

    je loop4

    mess msg9 the strings are not same

    jmp loop5

    loop4 mess msg8 the strings are same

    loop5 ret

    loop3 inc si

    inc di

    jmp loop2 now check next character

    pall endp

    end 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) Concatenation of two strings (b) 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) L-21 Lab Manual

    (A) 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 Comment

    page 100, 50

    title string concatenatation

    mess macro msg definition of macro mess

    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 data initialisation

  • Micropro. & Interfacing Techniques (PU) L-22 Lab Manual

    Instruction Comment

    mov ds, ax

    mov es, ax

    mess msg1 accept string1 from user

    function 0ah

    mov ah, 0ah under int 21h

    lea dx, str1

    int 21h

    mess msg2 accept string1 from user function 0ah

    mov ah, 0ah under int 21h

    lea dx, str2

    int 21h

    call concat call procedure

    mov ah, 4ch normal termination to dos

    int 21h

    concat proc near begin procedure

    mov ch, 00h

    mov cl, str1+1 cl=length of string1

    lea si, str1+2 destination string

    lea di, str1+2 destination string

    repz movsb copy to traverse till end of

    string1

    mov ch, 00h

    mov cl, str2+1 cl=length of string2

    lea si, str2+2 source string

    cld df=0

    repz movsb copy to traverse till end of string2

    mess msg3 display concatenated string use function 09h

    lea si, str1 under int 21h

    mov ah, 09h

    lea dx, str1+2

    int 21h

    ret

    concat endp end procedure

    end 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 : Initialize the data memory.

    Step II : Allocate data memory to save the strings.

    Step III : Initialize DS and ES register.

    Step IV : Accept the first string.

    Step V : Accept the second string.

    Step VI : Load the number of characters of first string in CL.

    Step VII : Load the number of characters of second string in CH register.

    Step VIII : Compare the lengths of the two strings. If not go to step XIII.

    Step IX : Load number of characters to be compared in CX.

  • Micropro. & Interfacing Techniques (PU) L-24 Lab Manual

    Step X : Compare the strings, character by character. If not same goto step XIII.

    Step XI : Print equal strings using Macro.

    Step XII : Jump to step XIV.

    Step XIII : Print unequal strings using Macro.

    Step XIV : Stop.

    Flowchart : Refer flowchart A.5(b).

    Program :

    Label Instruction Comment

    PRINT MACRO MES Macro to display

    string

    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 Initialize DS and ES

    mov ds, ax

    mov es, ax

    print ms1

    mov ah, 0ah ACCEPT first

    STRING

    lea dx, buff

    int 21h

    Flowchart A.5(b)

  • Micropro. & Interfacing Techniques (PU) L-25 Lab Manual

    Label Instruction Comment

    lea si, buff

    print ms2

    mov ah, 0ah ACCEPT OTHER

    STRING

    lea dx, buff1

    int 21h

    mov cl, buff+1 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 Number of

    characters

    lea di, buff1

    cld

    repe cmpsb Compare string

    char by char

    jnz para if not same

    goto PARA

    print ms3 Strings are equal

    jmp quit

    para:

    print ms4 Strings are Unequal

    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

  • 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 : Initialize data memory with main string, substring.

    Step II : Initialize the DS and ES.

    Step III : Accept the main string from user.

    Step IV : Accept the substring from user.

    Step V : CL = count of main string.

    Step VI : DL = count of substring.

    Step VII : Compare the first character of substring with main string till there is 0

    match.

    Step VIII : Subtract the length of substring to remaining length of main string till

    match is found. If there is nothing goto step XIII.

    Step IX : If result is negative, terminate program.

    Step X : Compare all other substring with main string.

    Step XI : If they match, store FF in the AL.

    Step XII : If they dont match store 00 in AL.

    Step XIII : Stop.

    Flowchart : Refer flowchart A.5(c).

  • Micropro. & Interfacing Techniques (PU) L-27 Lab Manual

    Program :

    Label Instruction Comment

    mess macro msg 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 Initialize data

    section

    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

  • Micropro. & Interfacing Techniques (PU) L-28 Lab Manual

    Label Instruction 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]

    next: 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: mov cx, 00

    mov bh, cl

    jmp endd

    endd: mov ch, 02h Count of digits to

    be displayed

    mov cl, 04h Count to roll by 4

    bits

    l2: rol bh, cl roll bl so that

    msb comes to lsb

    mov dl, bh 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

    Flowchart A.5(c)

  • Micropro. & Interfacing Techniques (PU) L-29 Lab Manual

    Label Instruction Comment

    jbe l4

    add dl, 07 if letter add 37H

    else only add 30H

    l4: add dl, 30H

    mov ah, 02 Function 2 under

    INT 21H(Display character)

    int 21H

    dec ch Decrement Count

    jnz l2

    mov ah, 4ch

    int 21h

    end

    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 Instruction Comment

    .model small

    .data

    a db 12H

    b db 10H

    .code

    mov ax, @data Initialize data section

    mov ds, ax

    mov al, a Load number1 in al

    mov bl, b Load number2 in bl

    mov ah, 0

    mov dx, 0 intialize result

    ad: add dx, ax add numbers. Result in dx

    dec bl dec number

    cmp bl, 0

    jnz ad

    mov ch, 04h Count of digits to be displayed

  • Micropro. & Interfacing Techniques (PU) L-31 Lab Manual

    Label Instruction Comment

    mov cl, 04h Count to roll by 4 bits

    mov bx, dx Result in reg bx

    l2: 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 if letter add 37H else only add 30H

    l4: 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

    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.

    Flowchart A.6(a)

  • 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 0 0 1 0 0 0 0

    CY

    BL = 0 0 0 1 0 0 0 0 0

    CY

    2

    0

    Step II : 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,

    BL = 0 0 1 0 0 0 0 0 0 CY

    4

    0

    Carry is not there.

    Decrement count, count=2

    Step III : Add number with itself

    AX = 44

    + 44

    88 H

    Rotate BL to left,

    BL = 0 1 0 0 0 0 0 0 0

    CY

    8

    0

    Carry is not there.

  • Micropro. & Interfacing Techniques (PU) L-33 Lab Manual

    Step IV : Decrement counter count = 1.

    Add number with itself as carry is not there.

    AX = 88

    + 88

    110 H

    Rotate BL to left,

    BL = 1 0 0 0 0 0 0 0 0

    CY

    0

    0

    Carry is there.

    Step V : Decrement counter = 0.

    Carry is present.

    add AX, BX 0110 i.e. 11 H + 0000 10 H 0110 H 0110 H

    Algorithm :

    Step I : Initialise the data segment.

    Step II : Get the first number.

    Step III : Get the second number.

    Step IV : Initialize count = 04.

    Step V : number 1 = number 1 2. Step VI : Shift multiplier to left alongwith carry.

    Step VII : Check for carry, if present goto step VIII else goto step IX.

    Step VIII : number 1 = number1 + shifted number 2.

    Step IX : Decrement counter.

    Step X : If not zero, goto step V.

    Step XI : Display the result.

    Step XII : Stop.

    Flowchart : Refer flowchart A.6(b).

    Label Instruction Comment

    .model small

    .data

    a db 11H

    b db 10H

    .code

    mov ax, @data Initialize data section

    mov ds, ax

    mov al, a Load number1 in al

    mov bl, b Load number2 in bl

    mov ah, 0

    mov dl, 04h initialize counter

  • Micropro. & Interfacing Techniques (PU) L-34 Lab Manual

    Label Instruction Comment

    ad: add ax, ax add numbers. Result in dx

    rcl bl, 01

    jnc skip

    add ax, bx

    skip: dec dl dec number

    jnz ad

    mov ch, 04h Count of digits to be displayed

    mov cl, 04h Count to roll by 4 bits

    mov bx, ax Result in reg bx

    l2: 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 if letter add 37H else only add

    30H

    l4: 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

    Result : Flowchart A.6 (b)

    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>

  • Micropro. & Interfacing Techniques (PU) L-35 Lab Manual

    Program 7 : 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

    FINIT Initialize coprocessor

    FLDZ accumulation = 0

    XOR BX, BX clear pointer

    MOV CX, N counter

    loop_acc : 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

    loop_final : 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 ADCS 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 = 99H

    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.

  • Micropro. & Interfacing Techniques (PU) L-38 Lab Manual

    Label Instruction Comment

    L1: MOV AL, 00H 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

    JMP L1

    The observation table will include.

    Analog input

    (V)

    Digital

    equivalent Output =

    255 voltage5V

    0

    1

    2

    3

    4

    5

    Flowchart B.1(a)

  • 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 : Make Run /

    Hold signal high.

    Step III : Check for status. Is it 0. If not wait till status = 0.

    Step IV : Make Run /

    Hold signal low.

    Step V : Read low order byte on Port A.

    Step VI : Read higher nibble on Port B.

    Step VII : 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 Terminate

    INT 21 H

    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 ADCs.

    ADC 0809 8 bit

    ADC 7109 12 bit

    Flowchart B.1(b)

  • Micropro. & Interfacing Techniques (PU) L-41 Lab Manual

    Program 2 : Write 8086 ALP to interface DAC and generate following waveforms on oscilloscope.

    (i) Square wave variable duty cycle and frequency. (ii) Sine wave variable frequency. (iii) Ramp wave variable direction. (iv) Trapezoidal wave. (v) 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 = T

    ON

    TON

    + TOFF

    = T

    ON

    Frequency

    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 Instruction Comment

    . MODEL SMALL

    . CODE

    MOV AL, 80 H Initialize Port A = Output Port.

    MOV DX, 00 H Load DX with port address of port A.

    MOV AL, 00 H

    L1 : OUT DX, AL Ouput contents of AL through

    port A.

    INC AL Increment AL.

    CMP AL, FF H Compare AL with FF H, if not

    continue.

    JNZ L1

    L2 : DEC AL Decrement AL.

    OUT DX, DL Output contents of AL to port A.

    JNZ L2 Decrement till AL = 00.

    JNZ L1 If AL = 00, goto L1 i.e. start from

    beginning.

    (ii) 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.

    Degrees Equation Digital equivalent in

    decimal

    Digital Equivalent in

    Hex

    0 (128 + 128 sin 0) 128 80H 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) 256 255 FFH 100 (128 + 128 sin 100) 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

  • Micropro. & Interfacing Techniques (PU) L-44 Lab Manual

    Degrees Equation Digital equivalent in

    decimal

    Digital Equivalent in

    Hex

    260 (128 + 128 sin 260) 02 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 360 (128 + 128 sin 360) 128 80H

    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 : Initialize the date segment.

    Step II : Initialize BX to point to start of look up table.

    Step III : Initialize count in CL.

    Step IV : Load the value from look up table.

    Step V : Output that value on port A of 8255.

    Step VI : Increment BX to point next value.

    Step VII : Decrement count.

    Step VIII : Check if count = 0 ? If not, goto step IV.

    Step IX : Initialize CL with count.

    Step X : Decrement BX to point value from look up table.

    Step XI : Load AL with value from look up table.

    Step XII : Output the value in AL on port A of 8255.

    Step XIII : Decrement count.

    Step XIV : Check if count = 0 ? If not, goto step X.

    Step XV : Initialize CL = count

    Step XVI : Initialize AH = FFH i.e. count for subtraction.

    Step XVII : Load the value from look up table in AL.

    Step XVIII : AL = AL FFH i.e. compute the digitial equivalent value.

    Step XIX : Output value in AL, to port A of 8255.

    Step XX : Increment BX to next value in look up table.

    Step XXI : Decrement count.

    Step XXII : Is count = 0 ? If not, goto XVI.

    Step XXIII : Initialize CL with count.

    Step XXIV : Decrement BX with next value in the look up table.

  • Micropro. & Interfacing Techniques (PU) L-45 Lab Manual

    Step XXV : Initialize AH = FFH.

    Step XXVI : Load the value from look up table in AL.

    Step XXVII : Compute the digital equaivalent AL = AL FFH

    Step XXVIII : Output the value in AL, on port A of 8255.

    Step XXIX : Decrement count.

    Step XXX : If not zero, goto step XXIV.

    Step XXXI : Go back to start.

    Program :

    Label Instruction Comment

    .model small

    .data

    PORTA EQU 80H

    look_up dB 80H, 96H, 0ABH, 0COH,

    0D2H, 0E2H, 0EFH,

    0F8H, 0FEH, 0FFH

    Count dB 0AH

    .code

    START : MOV AX, @Data Initialize data segment.

    MOV DS, AX Generates sine wave from 0 to 90 MOV BX, offset look_up Initialize BX to start of look up table.

    MOV CL, count Initialize count.

    L1 : MOV AL, [BX] AL = Value from look up table.

    MOV DX, PORTA DX = address of port A.

    OUT DX, AL Send data on port A.

    INC BX Increment BX to next value from look up table.

    DEC CL Decrement count.

    JNZ L1 If count 0, continue till all values are sent on output Generates sine wave from 90 to 180. MOV CL, Count Initialize counter.

    L2 : DEC BX Decrement look up table pointer

    MOV AL, [BX] AL = Value from look up table

    MOV DX, Port A DX = address of Port A.

    OUT DX, AL

    DEC CL Decrement count.

    JNZ L2 If count 0, goto L2. Generates sine wave from 180 to 270. MOV CL, Count Initialize counter.

    L3 : MOV AH, FFH Load count for subtraction.

    MOV AL, [BX] AL = Value from look up table.

    SUB AL, AH Calculate digital equivalent value.

    MOV DX, Port A DX = address of port A.

    OUT DX, AL

  • Micropro. & Interfacing Techniques (PU) L-46 Lab Manual

    Label Instruction Comment

    INC BX

    DEC CL Decrement count.

    JNZ L3 If count 0 goto L3 Generates sine wave from 270 to 360. MOV CL, Count Initialize counter.

    L4 : DEC BX Decrement look up table pointer.

    MOV AH, FFH Load count for subtraction.

    MOV AL, [BX] AL = Value from look up table.

    SUB AL, AH

    MOV DX, Port A OUT DX, AL

    DEC CL Decrement count

    JNZ L4

    JMP START Continue

    (iii) Ramp wave : Variable Direction :

    Explanation :

    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 : Start

    Step II : Initialize AL.

    Step III : Initialize BL = AL i.e. store AL value in register BL.

    Step IV : AND AL with 80H, to check MSB.

    Step V : If MSB = 1 goto step XIV.

    Step VI : Load AL with value from BL.

    Step VII : Output contents of AL through port A.

    Step VIII : Increment AL by 1.

  • Micropro. & Interfacing Techniques (PU) L-47 Lab Manual

    Step IX : Check if AL = FFH ? If not, goto step VI.

    Step X : Decrement AL by one.

    Step XI : Output contents of AL through port A.

    Step XII : 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)

  • Micropro. & Interfacing Techniques (PU) L-48 Lab Manual

    Program :

    Label Instruction Comment

    .model small

    .code

    MOV AL, 80H Initialize Port A of 8255 as output port.

    MOV DX, 00H Load DX with port address of port A.

    MOV AL, FFH Initialize AL

    MOV BL, AL

    AND AL, 80H Check for MSB

    JZ SKIP

    MOV AL, BL Initialize AL

    L1 : OUT DX, AL Output contents on port A.

    INC AL

    CMP AL, FFH Compare AL with FFH.

    JNZ L1

    L2 : DEC AL Decrement AL.

    OUT DX, AL

    JNZ L2.

    JNZ L1.

    SKIP : MOV AL, BL Initialize AL back.

    JMP L2.

    (iv) Trapezoidal wave :

    Explanation :

    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) L-49 Lab Manual

    Algorithm :

    Step I : Initialize the data section.

    Step II : Initialize port A as output port.

    Step III : Initialize AL = 80H i.e. initial value of the trapezoidal wave.

    Step IV : Output contents of AL on port A of 8255.

    Step V : Increment AL.

    Step VI : Check if AL = FFH ? If not, go to step IV.

    Step VII : Output contents of AL i.e. FFH on port A.

    Step VIII : Call delay 1.

    Step IX : Decrement AL.

    Step X : Output the contents of AL on port A of 8255.

    Step XI : Is AL = 00 ? If not go to step IX.

    Step XII : Output the contents of AL i.e. 00H on port A.

    Step XIII : Call delay 2

    Step XIV : Increment AL.

    Step XV : Output the contents of AL on port A.

    Step XVI : Check if AL = FFH ? If not, go to step XIV.

    Step XVII : Jump to step VII.

    Flowchart : Refer Flowchart B.2(c).

    Flowchart B.2(c)

  • 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) L-51 Lab Manual

    (v) Staircase wave :

    Explanation :

    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 Lab Manual

    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 : Is count = 00 ? If not, go to step XII.

    Step XVIII : Jump step IV.

    Flowchart : Refer Flowchart B.2(d).

    Flowchart B.2(d)

  • Micropro. & Interfacing Techniques (PU) L-53 Lab Manual

    Program :

    Label Instruction Comment

    . model small

    . data

    PORT A EQU 0050H

    STEP DB 02H, 04H, 08H, 10H, 20H, 40H, 80H, FFH.

    COUNT DB 08H.

    . code

    MOV AX, @ Data Initialize data segment.

    MOV DS, AX

    MOV AL, 80H Initialize 8255 Port A as output port.

    MOV DX, Port A DX = address of Port A.

    OUT DX, AL

    MOV CL, COUNT Initialize CL = 08H.

    MOV AL, 00H Initialize AL = 00H.

    Call delay

    MOV BX, OFFSET STEP BX = Start of STEP.

    L1 : MOV AL, [BX] AL = Step value.

    OUT DX, AL Output contents of AL on Port A.

    CALL DELAY

    INC BX Increment BX to point next step value.

    DEC CL Decrement count.

    JNZ L1

    MOV CL, COUNT Initialize CL = count.

    L2 : DEC BX Decrement BX to point next step value.

    MOV AL, [BX]

    OUT DX, AL Output contents of AL on Port A.

    Call delay

    DEC COUNT

    JNZ L2

    JMP L1

    DELAY PROC

    MOV CH, FFH

    L3 : DEC CH

    JNZ L3

    DELAY ENDP

    Program 3 : 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) If C key is pressed - clockwise rotation. ii) 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) L-55 Lab Manual

    Flowchart : Refer Flowchart B.3.

    Program :

    Label 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) L-56 Lab Manual

    Label 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.

    MESS MSG 7 display wrong choice

    JMP L1 display Menu again.

    clkrot : 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.

    MOV BL, 04H Load sequence count.

    L1 : 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 : Initialize the data section.

    Step II : Initialize the pointer to point to the string.

    Step III : 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 0 1 0 X 0 1 0 = A2H

    Label Instruction Comment

    . 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 Initialize the data segment.

    MOV DS, AX

    LEA BX, MSG 4 Initialize pointer to start of string.

    MOV DX, CWR DX = control word register address.

  • Micropro. & Interfacing Techniques (PU) L-60 Lab Manual

    Label Instruction Comment

    MOV AL, 0A2H Load control word in AL.

    OUT DX, AL

    MOV AL, 07H Make INTEA

    high to enable INTRA.

    OUT DX, AL

    MOV AL, 00H

    OUT DX, AL Make PC0 low, so give

    INIT signal to

    the printer for initialisation.

    Back : MOV CX, 0FFFH Wait for 50 s, so that printer will get Initialized.

    DEC CX

    LOOP BACK

    MOV AL, 01H INIT = 1

    OUT DX, AX

    UP : MOV DX, PORT B

    IN AL, DX

    MOV AH, AL Save the status in AH also.

    AND AL, 01H

    JNZ CHECK Check for BUSY signal. If high goto CHECK.

    MOV AL, [BX] Load the first character in AL.

    MOV DX, Port A Load the address of Port A in DX.

    OUT DX, AL Send the character to be printed.

    MOV DX, Port C DX = address of Port C.

    L2 : IN AL, DX Check for

    ACK by checking status of

    INTRA.

    JNZ L2

    MOV CL, COUNT Load count in CL.

    DEC CL Decrement count.

    JNZ UP Continue till all the characters are

    printed.

    JMP ENDD

    CHECK : MOV AL, AH Load the printer status in AL.

    AND AL, 02H Check for PE signal high.

    MOV AL, AH Load status in AL.

    JZ CHECK 1

    LEA DX, MSG 1 Display Message Printer out of Paper.

    MOV AH, 09H

    INT 21H

    CHECK1 : AND AL, 04HCheck for

    ERROR signal.

    JNZ UP

    LEA DX, MSG 2 Display Message Printer offline.

    MOV AH, 09H

    INT 21H

  • Micropro. & Interfacing Techniques (PU) L-61 Lab Manual

    Label Instruction Comment

    JMP UP

    ENDD : LEA DX, MSG 3 Display Message Printing

    completed.

    MOV AH, 09H

    INT 21H

    MOV AH, 4CH Terminate Program.

    INT 21H

    END.

    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 re-triggerable 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

    MOV AL, 31 H ; Counter 0, mode 0 CWR

    MOV DX, 5006 ; CWR address

    OUT DX, AL ; Loads control word in the CWR

    (ii) 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. Count value =

    Required period

    Input period =

    1 ms

    1 s = (1000)10 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) 12 digit display to display roll nos. from 1 to 12 (ii) Display scan time 15.24 msec. and external clock is 3 MHz. (iii) Clear code is FF H

    D7 D6 D5 D4 D3 D2 D1 D0

    dp g f e d c b a

    Soln. :

    Step I : 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,

    D7 D6 D5 D4 D3 D2 D1 D0

    0 0 0 0 0 0 0 0 = 18 H

    Step II : Specification (ii) gives external clock frequency and display scan time.

    Scan time = Display scan time24

    = 10.24

    16 = 640 s.

    Clock cycle time = 640 s64

    = 10 s Internal clock = 100 kHz

    PPPPP = 3 106

    100 103 = 3010 = 1E H (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 g f e d c b a Data Address

    (D7 D6 D5 D4 D3 D2 D1 D0)

    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

    Step V : (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

    1

    1

    A6

    0

    0

    A5

    1

    1

    A4

    0

    1

    A3

    0

    0

    A2

    0

    0

    A1

    1

    1

    A0

    0

    0

    Here addresses show a change in A4 bit. Hence A4 of micropro