Vous êtes sur la page 1sur 53

K.Sridhar Raju

www.engglabs.blogspot.com

K.Sridhar Raju www.engglabs.blogspot.com MICROPROCESSORS & MICROCONTROLLERS LAB MANUAL By K.Sridhar Raju www.engglabs.blogspot.com

MICROPROCESSORS

&

MICROCONTROLLERS

LAB MANUAL

By K.Sridhar Raju www.engglabs.blogspot.com

INDEX

Description

Page No

  • 1. List of experiments

3

  • 2. 8086 kit details and operating procedure

4

  • 3. Program and data sheet

6

  • 4. Addition, Subtraction, Multiplication, Division Programs

8-12

  • 5. Addressing Modes

13

  • 6. Factorial

14

  • 7. Positive and negative numbers from given series numbers.

15

  • 8. Program to generate Fibonacci Series

16

  • 9. program for block exchange

17

  • 10. Find square of a number using XLAT instruction

18

  • 11. Find the Greatest Common Divisor (GCD) of two numbers.

19

  • 12. Copy a string of 6 bytes from memory to memory

20

  • 13. Compare two strings

21

  • 14. Packed BCD to unpacked BCD

22

  • 15. Number of logic ones in a byte

23

  • 16. Addition of a series of bytes from a given array

24

  • 17. Find the largest number

25

  • 18. Code conversions I. Binary to BCD, II. Hexadecimal to ASCII

26

  • 19. Linear search

27

  • 20. Two multi-byte numbers addition

28

  • 21. Sorting

29

  • 22. Square wave generation and Rate generator using 8253

30

  • 23. Read voltage & display in digital using ADC with 8255

32

  • 24. Square, triangular, sin wave generation using DAC with 8255

33

  • 25. Interfacing 7-seg LED (CC,CA, BCD to 7-seg) with 8255

36

  • 26. Interface stepper motor with 8255

37

  • 27. Interface key board with 8255

39

  • 28. Single LED interfacing with 8255 (bit set mode)

42

  • 29. Digital Input and output card with 8255

43

  • 30. Program Interface eight LED‟s with 8051

44

  • 31. Interface stepper motor with 8051

45

  • 32. Interfacing 7-seg LED with 8051

46

  • 33. MASM based programs

49

2

MICROPROCESSORS AND MICROCONTROLLERS LAB

CODE: EC 333

PART A

B.E 3/4 ECE- I Semester

[Experiments on assembly programming for 8086 using Assembler]

  • 1. Study and use of 8086 microprocessor trainer kit and execution of programs

  • 2. Programs using different addressing modes.

  • 3. Multiplication and division.

  • 4. Single byte, multi byte binary and BCD addition and Subtraction.

  • 5. Code conversions.

  • 6. String Searching and Sorting.

  • 7. Generation of waveforms and gating applications using 8253/8254 timers.

  • 8. Generation of waveforms using DAC interface.

  • 9. Monitor utilities of 8086 kit for keyboard/displaying results.

PART B

[Experiments on assembly programming for 8051 using Assembler]

  • 10. Familiarity and use of 8051/8031 Microcontroller trainer kit and execution of programs.

  • 11. Programs using different addressing modes.

  • 12. Timer and counter programming.

  • 13. Interfacing for D/A applications.

  • 14. Interfacing for A/D applications

  • 15. Interfacing traffic signal control.

  • 16. Program to control stepper motor.

  • 17. 7-segment display/LCD display interfacing.

  • 18. Keyboard interfacing.

3

STUDY OF 8086 KIT

  • 1. Study 8086 microprocessor and identify various components in 8086 trainer kit.

  • 2. Crystal Oscillator generates 20MHz clock. Clk 2(divide by 2) pin 14 , (8086 clk is 10MHz) Clk 4(divide by 4 )pin 15, (8254 clk is 5MHz) Clk 8(divide by 8)pin 13,(8255 clk is 2.5 MHz)

Operating Commands for SDA 8086 kit:

Step 1: Switch on the kit/ Reset the trainer. ALS SDA 86-STA

Step 2: Key in „A‟ to go to Assembler mode

ALS 86 ASSEMBLER Step 3: User has to key in Enter key. Line Assembler Prompt is now displayed. > The Assembler is waiting for an assembler commands which can be one of the following:

Step 4: SG 0 to set the segment to 0 Step 5: Label Clear LC to clear the previous label for new session. Step 6: DA 4000: Disassemble and Assemble. The user can key in assembler mnemonics. The assembler expects inputs from the user to assemble from 0000:4000. 4000 B83412 MOV AX,#1234 Step 7: Assembler has now disassembled the instruction at 0000:4000 and has displayed

on LCD and is waiting for N key. Display by Assembler User has three choices:

@

N

  • 1. User can key in a fresh instruction followed by Enter key.

  • 2. User can key in Enter key if he does not want to alter the display code.

  • 3. User can key in ! to come out of Assembler mode and then key in EX and

Enter key. Step 8: MOV AL, [4100] <cr> User has entered the above instruction.

4

MOV A00041 MOV AL,4100

User Response DA prompt Next instruction is disassembled and displayed

N @ 4003 BB3412 MOV BX,1234

User response

N

DA prompt

@

User can change the instruction and press Enter or to without change the instruction

Next instruction is disassembled and displayed User response DA prompt User response New instruction is disassembled and displayed User response to exit from DA mode option 3 Assembler prompt User response

4006 01D8 ADD AX,BX N @ INT 3 <cr> 4008 CC INT 3 ! > EX *

Return to monitor GO COMMAND The execute user program command allows the user to execute a program that user has

entered. The message „GO‟ appears in the first line of the display, when the user presses the „G‟ key. The current user CS:IP and the instruction are displayed and the user can change the address, if required, by either entering a “Segment: Offset” or just an offset.

The command is executed when the user presses enter key. The user can stop execution of

the program at a specified address by including an “INT 3”.

EXAM/MODIFY THE REGISTER CONTENTS

Press twice „R‟

EXAM REGISTER

BX

Press „P‟ for previous register and „,‟ for next register.

EXAM / MODIFY THE MEMORY CONTENTS

Press „E‟ twice

EXAMBYTE

Modify the address as required and press „,‟ for check data

5678

C1

Press „W‟

EXAMWORD

Give the address as required and press „,‟ for check data

5678

41C1

5

PROGRAM SHEET:

Address Instruction code Label Mnemonic Comment
Address
Instruction code
Label
Mnemonic
Comment

6

DATA SHEET:

MEMORY LOCATION / REGISTER DATA (HEX)
MEMORY LOCATION / REGISTER
DATA (HEX)

7

1. AIM: TO PERFORM ADDITION OF TWO BYTES Apparatus: 8086 kit, power supply Procedure/ Algorithm:

  • 1. Load the first number in register AX.

  • 2. Load the second number in register BX.

  • 3. Perform addition operation on the register contents.

Program:

MOV AX, 1234 h

MOV BX, 2753h

ADD AX, BX MOV CL, 00 ADC CL, 00 INT 3 Result:

SUM

AX: 3987 H

CARRY

CL: 0

Check with different data: ABCD and 9DEF

8

2.

AIM: TO PERFORM SUBTRACTION OF TWO BYTES

Apparatus: 8086 kit, power supply

Procedure/ Algorithm:

  • 1. Load the minuend in a register AX.

  • 2. Load the subtrahend in the second register BX.

  • 3. Perform subtraction operation on the register contents.

Program:

MOV AX, 5678H

MOV BX, 1234H SUB AX, BX INT 3

Result:

AX: 4444H Check with different data as:

 
 

Sign Flag

Zero Flag

AX > BX

0

0

AX = BX

0

1

AX < BX

1

0

 

9

3.

AIM: TO PERFORM MULTIPLICATION OF TWO BYTES

Apparatus: 8086 kit, power supply

Procedure/ Algorithm:

  • 1. Load the multiplicand in a register AX.

  • 2. Load the multiplier in the second register BX.

  • 3. Perform multiplication operation on the register contents.

Data:

Program:

MOV AX, 2080 MOV BX, 0070 MUL BX INT 3

Result:

AX: 38C0 H lower sixteen bit

DX:

02 H

higher byte

i.e.

0238C0 H

Check with different data as:

10

4.

AIM: TO PERFORM DIVISION OF TWO BYTES

Apparatus: 8086 kit, power supply

Procedure/ Algorithm:

  • 1. Load the dividend in a register.

  • 2. Load the divisor in the second register.

  • 3. Perform division operation on the register contents.

Program:

MOV AX, 2056 MOV BX, 0004 DIV BX INT 3

Result:

Quotient in

AX: 0815 h

Reminder in DX: 02h Check with different data:

Dividend is 16 bit and divisor is 8 bit Divide error/ over flow

MOV AX, 2056 MOV BL, 04/45 DIV BL INT 3

Quotient in

AL: 77 h

Reminder in AH: 43h

11

5.

AIM: WRITE AN ALP FOR 8086 USING ALL ADDRESSING MODES.

Apparatus: 8086 kit, power supply

Procedure/ Algorithm:

  • 1. Initialize the contents of segment registers or general purpose registers using immediate addressing mode.

  • 2. The contents of memory locations can also be initialized using direct and indirect addressing modes.

Program:

MOV AX, 0000H MOV DS, AX MOV AX, 1234 MOV SI, 5000 MOV [SI], AX MOV [5000], AX MOV 2[SI], AX MOV BX, 1000

MOV [BX][SI], AX MOV 2[BX][SI], AX INT 3 Result:

DS: 0000

AX: 1234H,

BX: 1000

5000: 34

6000: 34

SI: 5000

5001: 12

6001: 34

5002: 34

6002: 34

5003: 12

6003: 12

12

6.

Aim: Write an ALP for finding the FACTORIAL of a given number.

Apparatus: 8086 kit, power supply Procedure/ Algorithm:

  • 1. Initialize the data segment.

  • 2. Set product to one.

  • 3. Inialise the pointer and fetch the data from the memory location using a pointer.

  • 4. Multiply the data with product.

  • 5. Repeat this until data becomes zero.

  • 6. Increment pointer to store the final product obtained as the factorial of the given number.

Program

next:

MOV AX, 0000H MOV DS, AX MOV AX,1 MOV SI, 4100h MOV CX, [SI] MUL CX LOOP next INC SI MOV [SI], AX INT 3

hint: 4101 data should be zero.

Input

Address

Data:

 

4100

: 04

(Input should be ≤ 8)

Result:

4101

: 18h

4102

:

00

13

7.

AIM: WRITE A PROGRAM TO FIND OUT THE NUMBER OF POSITIVE NUMBERS AND NEGATIVE NUMBERS FROM A GIVEN SERIES OF SIGNED NUMBERS.

Apparatus: 8086 kit, power supply

Procedure/ Algorithm:

  • 1. Initialize two registers for storing the number of positive and negative numbers.

  • 2. Set the value of the counter.

  • 3. Set data segment and pointer.

  • 4. Get byte from memory to register.

  • 5. Rotate register content left through carry by one bit position.

  • 6. Check the carry flag.

  • 7. If carry =1 then increment negative counter and go to step number 7.

  • 8. If there is no carry, increment the positive counter and go to step number 7.

  • 9. Increment pointer.

    • 10. Decrement counter.

    • 11. If counter is not equal to zero go to step 4.

    • 12. Store the result.

    • 13. Stop the program.

Program:

Input

MOV BX, 0000H

Data:

MOV AX, 0000H

6000: F8

MOV DS, AX; To initialize data segment

6001: 02

MOV SI, 6000H;Set pointer

6002: 82

MOV CX, 0006H;Set Count

6003: 48

L3: MOV AL, [SI];

6004: 22

RCL AL, 1;Rotate left through carry

6005: C8

JNC L1;Check the carry

 

INC BH; Increment negative count

F8=1111 1000

JMP L2;

02=0000 0010

L1: INC BL; Increment positive count

82= 1000 0010

L2:INC SI; Increment pointer

48= 0100 1000

LOOP L3; Decrement count

22= 0010 0010

MOV [SI], BL;

C8= 1101 1000

INC SI;

 

MOV [SI], BH;

 

14

INT 03

 

Result:

Negative No BH:03

Positive No

BL :03

Questions: Modify the above program for counting odd and even numbers in a given series of numbers and compare instruction in 8086.

15

8. AIM: WRITE A PROGRAM TO GENERATE FIBONACCI SERIES.

Apparatus: 8086 kit, power supply Algorithm/ Procedure:

 

1.

Initialize a=0

2.

Initialize b=1

3.

while i<m do write (a, b), a=a+b, b=a+b, i=i+1

 

4.

Stop the program

Program:

 

MOV AX, 0000H;

 

Result:

MOV DS, AX

; To initialize Data Segment

4200: 00

MOV CL, 0AH

; Set counter

4201: 01

XOR AL, AL

; Clear Accumulator

4202:01

MOV SI,4200H

 

4203: 02

MOV [SI], AL

; Move first number to AL

4204: 03

ADD AL, 01H;

 

4205: 05

INC SI

; Increment pointer

4206: 08

MOV [SI], AL

 

4207: 0D

MOV 1[SI],AL

 

4208: 15

INC SI;

 

4209: 22

SUB CL,03

; three numbers are generated

 

back: ADD AL, [SI];

   

INC SI;

   

MOV [SI], AL;

   

DEC SI;

   

MOV AL, [SI];

   

INC SI;

   
 

LOOP

back

; repeat same up to count is zero

 

INT 03

   

Questions:

 
 

1.

 

divisor of them.

 

2.

Write an ALP to find the factorial of a given number.

 

Given two positive integers m and n, write an ALP to find the greatest common

16

9. AIM: WRITE A PROGRAM FOR BLOCK EXCHANGE

Apparatus: 8086 kit, power supply Algorithms/ Procedure;

 

1.

Set source and destination pointers.

2.

Set counter.

3.

Get content of source pointer into one of the register (AL).

 

4.

Get the content of destination pointer into another register (BL).

 

5.

Place BL content into the source block and place AL content into the source block.

6.

Increment both the pointers.

7.

Decrement counter.

8.

If count not equal to zero go to step 3.

9.

Stop the program.

Program:

 

MOV AX, 0000H;

Data:

Result:

MOV DS, AX; To initialize data segment

5000:11

6000:AA

5000:AA

6000:11

MOV ES, AX; To initialize extra segment

5001:22

6001: BB

5001: BB

6001:22

MOV SI, 5000H; Set source pointer

5002:33

6002: CC

5002: CC

6002:33

MOV DI, 6000H; Set destination pointer

5003:44

6003: DD

5003: DD

6003:44

MOV CX, 000AH; Set counter

5004:55

6004: EE

5004: EE

6004:55

L1: MOV AL, [SI];

5005:66

6005: FF

5005: FF

6005:66

MOV BL, [DI];

       

MOV [DI], AL;

       

MOV [SI], BL;

       
 

INC SI;

       

INC DI; Increment pointers

       

LOOP L1;

       

INT 3; Break point

       

Questions:

 
 

1.

Write an ALP to copy data from one memory area to another.

 

2.

Modify the above program to exchange reverse order.

3.

Explain LOOP, LOOPE, LOOPNE instructions.

 

17

10. AIM: TO WRITE AN ALP TO FIND SQUARE OF A NUMBER USING LOOK-UP (XLAT) TABLE.

Apparatus: 8086 kit, power supply

Algorithm/ Procedure:

1.

Store the values of squares from 0 to 9 in continuous memory locations.

2.

Read the number for which square is required.

 

3.

Form the address in BX register.

4.

Store the result in another register.

Program:

Data:

MOV AX, 0000 H

 

6000: 00

MOV DS, AX

; To initialize Data segment register

 

MOV BX, 6000H

; To set Offset address

6001: 01

MOV AL, 04

; Load code into AL

6002: 04

XLAT

; Translate one code to another code

6003: 09

MOV CL, AL

; Store result in CL

6004: 16

INT 3

; Breakpoint

6005: 25

 

6006: 36

Result:

AL = 16

6007:49

 

6008:64

XLAT

AL = [BX+AL]

AL = [BX+AL]

6009:81

Questions:

1.

Can we find factorials using Look-up Tables?

 

2.

Can we find sum of numbers using Look-up Tables?

3.

What will you store in memory for questions 1 & 2?

4.

Where are the changes required? Program or data or both?

5.

Write the programs for above logic.

18

11. AIM: WRITE A PROGRAM FOR GIVEN TWO POSITIVE INTEGERS N AND M, TO FIND THE GREATEST COMMON DIVISOR (GCD) OF TWO NUMBERS.

Apparatus: 8086 kit, power supply

PROGRAM:

DATA

MOV SI,4050H

Input

Result

MOV DI,4060H

4050: 08

4060: 02

MOV AL,[SI]

4051: 02

 

MOV BL,1[SI]

   

CMP AL,BL

   

JNC GO

   

XCHG AL,BL

   

GO:MOV AH,00

   

DIV BL

   

CMP AH,00

   

JZ AGAIN

   

MOV AL,BL

   

MOV BL,AH

   

JMP GO

   

AGAIN:MOV [DI],BL

   

INT 3

   

Questions:

  • 1. Write an ALP to reverse the given digits.

  • 2. Explain IMUL and IDIV Instructions with help of examples.

19

12. AIM: WRITE AN ALP TO COPY A STRING OF 6 BYTES FROM MEMORY STARTING FROM 2000:0004H INTO MEMORY STARTING FROM

3000:0014H.

Apparatus: 8086 kit, power supply.

Algorithm/Procedure:

  • 1. Clear Direction Flag.(DF=0 i.e auto increment mode)

  • 2. Set data segment and source index pointer.

  • 3. Set extra segment and destination index.

  • 4. Set counter.

  • 5. Copy the string bytes from source to destination until count =0.

Program:

 

CLD

; clear Direction Flag for auto increment

Data:

 

MOV AX, 2000H

 

Input

Result:

MOV DS, AX

; Initialize DS

2000:0004: 11

3000:0014:AA

MOV AX, 3000H

 

2000:0005: 22

3000:0015:BB

MOV ES, AX

; Initialize ES

2000:0006: 33

3000:0016:CC

MOV SI, 0004H

; Offset of source location in DS

2000:0007: 44

3000:0017:DD

MOV DI, 0014H; Offset of destination location in ES

2000:0008: 55

3000:0018:EE

MOV CX, 0006H

; length of the string

2000:0009: 66

3000:0019:FF

REP

; repeat the same up to CX is zero

 

MOVSB

;copy a byte from source to destination ,if DF=0,increment SI & DI

INT

3

20

13. AIM: WRITE AN ALP TO COMPARE TWO STRINGS.

Apparatus: 8086 kit, power supply. Algorithm / Procedure:

1. Clear Direction Flag.( DF = 0 i.e auto increment mode) 2. Set Data Segment, extra
1.
Clear Direction Flag.( DF = 0 i.e auto increment mode)
2.
Set Data Segment, extra segment, source and destination index.
3.
Set counter.
4.
Compare the source string bytes with destination string bytes until count =0.
Program:
CLD
MOV AX, 0000H;
MOV DS, AX
MOV ES, AX
MOV SI, 5000H
MOV DI, 6000H
MOV CX, 0003H
REPE
CMPSB
; clear the Direction Flag
; Initialize DS
; Initialize ES
; Set source pointer
; Set destination pointer
; Set length of the string
; cx=cx-1, if ZF=1 repeat the same maximum CX time
; Compare with source to destination byte set flags according
the result, if
DF=0 increment the SI and DI
INT 3
Result: After the execution of the program, if both the strings are completely equal, i.e
CX becomes zero, the ZF is SET, and otherwise ZF is RESET.
D0
D15
Over flow
Direction
Interrupt
Trap
Zero
Sign
Parity
Auxiliary carry
Carry
Questions:
1.
Write an ALP to search a byte in a given string using SCANSB instruction.
2.
What are REP, REPE, REPNE prefix instructions? What is its use?

21

14.

AIM: WRITE AN ASSEMBLY LANGUAGE PROGRAM FOR PACKED BCD TO UNPACKED BCD

Apparatus: 8086 kit, power supply. Procedure / Algorithm:

  • 1. Set data segment and source pointer

  • 2. Get number into two registers

  • 3. Mask off upper nibble.

  • 4. Increment pointer.

  • 5. Place register value in the memory.

  • 6. Get lower nibble into memory.

  • 7. Mask off lower nibble

  • 8. Rotate four times right.

  • 9. Increment pointer.

    • 10. Store the result in memory.

Program:

MOV AX, 0000H

Data:

MOV DS, AX; To initialize data segment

0000:5000: 43

MOV SI, 5000; Set pointer

Result:

MOV AL, [SI];Get number into AL

0000:5001: 03

MOV BL, AL; as well as in to BL

0000:5002: 04

AND AL, 0FH; Mask upper nibble

 

INC SI; Increment pointer

 

MOV [SI], AL; Place least significant digit in memory

 

AND BL, 0F0H;Mask lower nibble

 

MOV CL, 04;Set count for number of rotations

 

ROR BL, CL; Rotate contents of BL

 

INC SI; Increment pointer

 

MOV [SI], BL; Place most significant digit in memory location

 

INT 3; Break Point

 

Questions:

  • 1. What is the difference between SHR & SAR?

  • 2. Write an ALP for combining least significant bits of memory locations 6000H & 6100H. Store the result in 6002H.

  • 3. Write an ALP to clear the memory locations 6010H & 601FH.

22

15. AIM: WRITE AN ALP TO FIND THE NUMBER OF LOGIC 1’S IN A BYTE.

Apparatus: 8086 Kit, Power Supply Procedure:

 

1.

Set count value to 08.

2.

Set one of the registers to 00 for storing number of 1‟s.

3.

Load number into one of the registers.

 

4.

Rotate left the contents of the register.

5.

Check the carry flag.

6.

If the carry flag is set then increment register otherwise go to step 3.

7.

Decrement count register.

 

8.

If count = 0 then stop the program, otherwise go to step 4.

9.

Stop the program.

Program:

Data:

 

MOV AX,0000

Input

MOV DS,AX

0000:4200 : 57

MOV SI,4200H

 

MOV CL,08

Result

MOV BL,00

0000:4201 : 05

MOV AL,[SI]

 

L2:ROL AL,01

 

JNC L1

 

INC BL

 

L1:LOOP L2

 

INC SI

 

MOV [SI],BL

 

INT 3

 
   

Questions:

 
 

1.

Modify the above program to find the number of zeros in a given byte.

2.

Write the above program using loop instruction.

3.

Explain NOT & NEG instructions in 8086.

 

23

16. AIM: TO WRITE AN ALP FOR THE ADDITION OF A SERIES OF BYTES FROM A GIVEN ARRAY. THE SERIES CONTAINS 10 BYTES.

Apparatus: 8086 Kit, Power supply Procedure / Algorithm:

 

1.

Set the data segment and source pointer.

2.

Set sum to zero.

3.

Set counter

4.

Add the contents specified by the pointer to the variable sum and store the sum in the same variable.

5.

Increment pointer and decrement counter.

6.

If count is zero then total = sum, otherwise go to step 4.

 

7.

Stop the program.

PROGRAM:

DATA

   

MOV AX, 0000H; Initialize data segment

0000:6000

01

MOV DS, AX;

0000:6001.

01

MOV CX, 0AH; set counter

0000:6002.

01

XOR AX, AX; set sum = 0

0000:6003.

01

MOV SI, 6000H; set pointer

0000:6004.

01

AGAIN: MOV BL, [SI]; Take the first number

0000:6005.

01

ADD AL, BL

0000:6006.

01

ADC AH, 00H;

0000:6007.

01

INC SI; Increment pointer

0000:6008.

FF

DEC CX; Decrement count

0000:6009.

FF

JNZ AGAIN; count is not zero do the same

RESULT

 

MOV [SI], AL; Store the sum

0000:600A

06

 

INC SI

0000:600B

02

MOV [SI], AH; Store the carry

   

INT 03H; Break point

   

Questions:

 
 

1.

Explain function of DAA instruction.

2.

Modify above program for decimal addition.

3.

Write an ALP for decimal addition & decimal subtraction.

 

24

17. AIM: WRITE A PROGRAM TO FIND THE LARGEST NUMBER FROM A GIVEN ARRAY OF NUMBERS STORED IN THE LOCATIONS STARTING FROM A KNOWN ADDRESS.

Apparatus: 8086 Kit, Power supply Procedure / Algorithm:

  • 1. Set data segment and pointer

  • 2. set max=0 and counter = desired count value

  • 3. is max > [pointer], if yes decrement count. If no increment pointer

  • 4. if count = 0result = max, if no go to step 3

  • 5. result = max

  • 6. Stop the program.

Program:

Data:

 

MOV AX, 0000H

0000:5000

09

MOV DS, AX

0000:5001

03

MOV SI, 5000H

0000:5002

54

MOV CX, 0005H

0000:5003

65

L2: CMP AL, [SI]

0000:5004

02

JNC L1

Result

 

MOV AL, [SI]

0000:5005

65

L1: INC SI

   

LOOP L2

   

MOV [SI], AL

   

INT 03H

   

25

18. .

AIM: WRITE A PROGRAM FOR CODE CONVERSION

  • (a) BCD to Binary

  • (b) Hexadecimal to ASCII

Apparatus: 8086 kit, power supply

Algorithm/ Procedure: BCD to Binary

Program:

  • 1. Set data segment and pointer

MOV AX, 0000H

  • 2. Take number to AL.

MOV DS, AX

  • 3. Keep a copy in AH Register.

MOV SI, 5000H

  • 4. Mask off upper nibble.

MOV AL, [SI];

  • 5. Keep least significant nibble in CH Register.

MOV AH,AL

  • 6. Get byte from CL to AL.

AND AL, 0FH; Mask off upper nibble

  • 7. Mask off lower nibble.

MOV BL, AL;

  • 8. Rotate AL content 4 times right.

MOV AL, AH;

  • 9. Multiply AL content with 0Ah.

AND AL, 0F0H; Mask off lower nibble

  • 10. Add CH content to AL.

MOV CL, 04H;

  • 11. Store the result.

ROR AL, CL; Rotate AL content 4 times

  • 12. Stop the program.

MOV CH, 0AH;

 

MUL CH;

 

ADD AL,BL;

 

INC SI

 

MOV [SI],AL; Store the result

 

INT 3; Break point

26

This program converts hexadecimal no: 00 to FF only

Hexadecimal to ASCII conversion

MOV AX,0000

  • 1. Set data segment and pointer

MOV DS,AX

  • 2. Take number to AL.

 

MOV SI,4100H

  • 3. Keep a copy in AH Register.

MOV AL,[4100H]

  • 4. Mask off upper nibble.

 

MOV AH,AL

  • 5. Compare number with 09

 

AND AL,0FH

  • 6. If AL >09 ; AL = AL+07 or AL=AL

CALL CONVT

  • 7. AL= AL+30 = ASCII value of lower nibble

XCHG AL,AH

  • 8. Take number and mask lower nibble

MOV CL,04

  • 9. Similarly convert the as above

AND AL,0F0H

10. Store the value in memory

 

ROR AL,CL

Data

CALL CONVT

0000:4100

FF h

 

MOV [4101H],AX

0000:4101

46

 

INT 3

0000:4102

46

 

CONVT: CMP AL,09

     

JNC AGAIN

Data

 

ADD AL,30H

0000:4100

01

 

JMP GO

0000:4101

30

 

AGAIN: ADD AL,07

0000:4102

31

 

ADD AL,30H

     

GO:RET

Questions: Modify the above programs for converting ASCII to Hexadecimal code.

27

19.

AIM: WRITE AN ALP TO SEARCH A GIVEN ITEM FROM THE LIST USING LINEAR SEARCH TECHNIQUE.

Apparatus Requires: 8086 kit, Power Supply

Program:

Data:

 

MOV AX, 0000H;

0000:5000

86

MOV DS, AX; Initialize Data Segment Register

0000:5001

93

MOV CX, 0007H; Count of number of elements

0000:5002

34

MOV SI, 5000H; Set pointer

0000:5003

45

MOV DL, 01; loc=1

0000:5004

XX

MOV AL,XX ; Number to be searched

0000:5005

87

BACK: CMP AL, [SI];

0000:5006

64

JZ AHEAD; If number found, stop

   

INC SI;

   

INC DL;

   

LOOP BACK;

Result:

 

AHEAD: MOV [5020], DL; Result location

0000:5020

05

Location

INT 03h;

   

Questions:

  • 1. Write an ALP to search a given item from the list using Binary Search technique.

  • 2. Write an ALP for searching using string instructions.

28

20. WRITE AN ALP TO ADD TWO MULTI-BYTE NUMBERS AND STORE THE RESULT AS A THIRD NUMBER. (The numbers are stored in the form of byte list as the lowest byte is first.)

Apparatus: 8086 trainer kit and power supply. Algorithm:

Initially set segment and two index register to two given multi-byte number, base pointer to result, accumulator, carry flag and count register. Copy the first byte from source index to source register, add with carry of source register and first byte from destination index. Copy the result from source register to base pointer. Every time increment the base pointer for storing the result, loop continue till count is zero. Finally check carry flag and store in base pointer location.

Program:

MOV AX, 0000

 

Data:

MOV DS, AX;

set data segment to 0000

4100

A9 87 65 43 21

I st

No.

MOV CX, 05;

CX is counter

 

4105- FE DC BA 98 76

II nd No.

MOV SI, 4100H;

first multi byte number

410A-01 A8 64 1F DB 97

 

Result

MOV DI, 4105H;

second multi byte number

 

MOV BX, 410Ah;

result multi byte number

 

XOR AX, AX;

clear sum and carry flag

CLD

index register auto increment

NEXT: LODSB;

load AL from SI

 

ADC AL, [DI];

add with carry = AL + [DI]

MOV BYTE PTR [BX], AL;

sum copy to [BX]

INC BX

INC DI

LOOP NEXT;

loop continues up to CX is zero

JNC AHEAD;

if carry flag is set after adding

MOV BYTE PTR [BX], 01; the end bytes, copied in [BX]

AHEAD:

INT 03h;

halt.

29

21

SORTING GIVEN HEXADECIMAL NUMBERS

Apparatus: 8086 trainer kit and power supply.

INPUT

0D

0C

0B

0A

Sorting STEP-1

0C

0B

0A

0D

 

STEP-2

0B

0A

0C

0D

STEP-3

0A

0B

0C

0D

Programe

 

MOV AX,0000

   

INPUT

 

MOV DS,AX

   

4200

04

 

MOV SI,4200H

 

Count n

4201

0D

 

MOV BL,[SI]

   

4202

0A

 

DEC BL

 

Outer n = n-1

4203

0C

OUTL00P:

MOV CL,BL

 

Inner n = n-1

4204

0B

 

MOV SI,4201H

       

INL00P:

MOV AL,[SI]

       
 

INC SI

     
 

CMP AL,[SI]

 

sort

 
 

JC PROCEED

   

OUTPUT

 
 

XCHG [SI],AL

   

4201

0A

 

MOV -1[SI],AL

 

4202

0B

PROCEED:

LOOP

INL00P

 

4203

0C

 

DEC BL

   

4204

0D

 

JNZ OUTL00P

       
 

INT

3

     
       

30

22. Aim: To interface a PROGRAMMABLE TIMER 8253 to 8086 and generate a SQUARE WAVEFORM of period 1ms. (Mode 3) f = 1KHz

0000:4000

BA

CF

FF

MOV

DX,0FFCF

Control word

 

0000:4003

B0

36

MOV

AL,36h

 

0

0

1

1

0

1

1

0

=

36

0000:4005

0000:4006

0000:4009

EE

BA

B0

C9

88

FF

OUT

MOV

MOV

16 bit count
16 bit count

DX,AL DX,0FFC9 Counter 0

AL,88h

 

0000:400B

EE

OUT

DX,AL

 

Mode 3

0000:400C

B0

13

MOV

AL,13h

0000:400E

EE

OUT

DX,AL

Binary count

 

0000:400F

CC

INT

3

8086 Clock

f = 5 M Hz

O/P

       

Desired square wave f = 1K Hz

 
Desired square wave f = 1K Hz
 

Count = 5 M Hz / 1K Hz

 

1 ms

=

5000 D = 1388 H

 

RATE GENERATOR

(Mode 2)

0000:4000

BA

CF

FF

MOV

DX,0FFCF

 

0000:4003

B0

14

MOV

AL,14

 

0000:4005

EE

OUT

DX,AL

0000:4006

BA

C9

FF

MOV

DX,0FFC9

 

0000:4009

B0

05

MOV

AL,05

 

0000:400B

EE

OUT

DX,AL

0000:400C

CC

INT

3

Control word

0

0

0

1

0

1

0

0

 
Mode 2
Mode 2

Counter 0

byte count

 
         
 

Binary count

 
Binary count
 

1- clock period

 
 

31

SDA -86 - MEL 8253 ADDRESSES

Timer /Counter 0

: FFC9

Timer /Counter 1

: FFCB

Timer /Counter 2

: FFCD

Control Word Reg.

: FFCF

D0 to D7
D0
to
D7
CLK 8086 A 2
CLK
8086
A 2
Vcc CLK 0 OUT 0 A 1 8253 GATE 0 CS
Vcc
CLK 0
OUT 0
A 1
8253
GATE 0
CS
SDA -86 - MEL 8253 ADDRESSES Timer /Counter 0 : FFC9 Timer /Counter 1 : FFCB

To CRO

SDA -86 - MEL 8253 ADDRESSES Timer /Counter 0 : FFC9 Timer /Counter 1 : FFCB

+5 V

SDA -86 - MEL 8253 ADDRESSES Timer /Counter 0 : FFC9 Timer /Counter 1 : FFCB
A 1 I /O RD A 2 RD WR I/O WR
A 1
I /O RD
A 2
RD
WR
I/O WR
SDA -86 - MEL 8253 ADDRESSES Timer /Counter 0 : FFC9 Timer /Counter 1 : FFCB

32

23. Aim: Read the analog voltage and display in digital using A/D CONVERTOR Apparatus: 8086 kit, power supply , ADC module, 26-pin FRC Connector.

MOV AL,90H MOV DX,0FFC6 OUT DX,AL MOV AL,07 MOV DX,0FFC4H OUT DX,AL MOV DX,0FFC6 MOV AL,0EH OUT DX,AL MOV AL,0CH OUT DX,AL MOV AL,0FH OUT DX,AL MOV CX,3FFFH L1: LOOP L1 MOV AL,0EH OUT DX,AL MOV DX,0FFFC0 WAT:IN AL,DX AND AL,80 ROL AL,1 JNC WAT

set 8255 Port A I/P, port B&C is O/P mode

1

0

0

1

0

0

0

0

channel Selection Channel 07

BSR Mode Start of Conversion(SOC) = 0

Output Enable(0E)= 0

 
   

0

 

X

 

X

 

X

 
  • 1 0

1

0

   

SOC =1

 
 

0

X

X

X

1

1

1

1

delay

 

SOC = 0

 
   

0

 

X

 

X

 

X

 
  • 1 1

1

1

   

to Check for End of Conversion (EOC)i.e. conversion is completed or not

33

MOV DX,0FFC6H MOV AL,0D OUT DX,AL MOV DX,0FFC0 IN AL,DX INT 3

to enable the output to be read by the processor 0E = 1

0

X

X

X

1

1

0

1

Read the digital data in AL register

8255 PORT ADDRESSES

5V = FF h (255)

PORT A

FFC0H

1V = ?

PORT B

FFC2H

1V = 255/5V =(51) d =(33) h

PORT C

FFC4H

2V = 66h, 3V = 99h

CWR

FFC6H

4V = CCh, 5V = FFh

ANALOG INPUTS CH 00 D 0 to D 7 PA 0- PA 7 to O 0
ANALOG INPUTS
CH 00
D 0
to D 7
PA 0- PA 7 to O 0 – O 7
V ref + V ref -
EOC
A
A
PA 7
2
1
ALE
A
A
1
0
0809
PC 7
8086
SOC
RST
RD
PC 6
CH 07
I/ORD
PC 2
WR
I/OWR
PC 1
8255

PC 0

00 to 5V DC

8086 Interfacing with ADC0809 through PPI8255

Questions:

  • 1. Explain the different modes of operation of 8255.

Kit No: NIFC 07A, Channel No.08

  • 2. Explain the Control Word format of 8255 in I/O and BSR mode.

  • 3. What is the function of ADC 804 IC?

34

24. Aim: Write an ALP to generate SQUARE WAVE USING DAC module.

Apparatus: 8086 kit, power supply unit, DAC module, 26-pin FRC Connector, CRO.

Description:

  • 1. Use Port A of 8255 in output mode and write control word of 8255 into control word register in simple I/O mode for data transfer.

  • 2. Send high value to Accumulator.

  • 3. Send Accumulator value to port A.

  • 4. Call delay sub-routine.

  • 5. Send low value to Accumulator.

  • 6. Send accumulator value to the port.

  • 7. Call delay sub-routine.

  • 8. Jump to Step 2, for continues square wave generation.

( 8-Bit Digital to Analog Converter) through 8255 PPI

0000:4005

B0

50

   

MOV

AL,80

0000:4007

BA

C6

FF

 

MOV

DX,0FFC6

0000:400A

EE

     

OUT

DX

0000:400B

BA

C0

FF

 

MOV

DX,0FFC0

0000:400E

B0

00

 

Rpt

MOV

AL,00

0000:4010

EE

     

OUT

DX

0000:4011

E8

     

CALL DELAY

0000:4014

B0

FF

   

MOV

AL,FF

0000:4016

EE

     

OUT

DX

0000:4017

 

E8

   

CALL DELAY

0000:4020

 

EB

   

JMP

Rpt

           

Delay program

 

0000:4022

B9

FF

00

 

MOV

CX,00FF

0000:4025

E2

   

here

LOOP

here

0000:4027

C3

     

RET

1 0 0 0 0 0 0 0 I/O Port A Port A Port B,C Mode
1
0
0
0
0
0
0
0
I/O
Port A
Port A
Port B,C
Mode
Mode 0
O/P
Output Ports

DELAY CALCULATION:

CLOCK CYCLES

FF MOV CX,COUNT 4 HERE: LOOP HERE 17/5 RET 8 00 f DELAY: (N0. of clock
FF
MOV CX,COUNT
4
HERE:
LOOP HERE
17/5
RET
8
00
f
DELAY: (N0. of clock cycles) X one clock period
T
1 K Hz
=
(4 + (count
X 17) – 12
+ 8)
X
Count
=
1 K Hz/(17 X 0.2μs )

= 1/T

35

Interfacing Diagram:

B 0 to B 7 2.5K + 5 V D 0 to D 7 5K I
B 0 to B 7
2.5K
+ 5 V
D 0 to D 7
5K
I
RD
ORD
PORT A
V
I
WR
0
OWR
O/P to CRO
741
A
A
2
1
A
A
cs
1
0
+5 V or
12 V
Triangular wave generation
0000:4005
B0
80
MOV
AL,80
0000:4007
BA
C6
FF
MOV
DX,FFC6
0000:400A
EE
OUT
DX
0000:400B
BA
C0
FF
MOV
DX,FFC0
0000:400E
B0
00 Repeat:
MOV
AL,00
0000:4010
EE
Rise:
OUT
DX
0000:4011
FE
C0
INC
AL
0000:4013
3C
FF
CMP
AL,FF
0000:4015
75 JNZ
Rise
0000:4017
FE
C8
Decay:
DEC
AL
0000:4019
EE
OUT
DX
0000:401A
3C
00
CMP
AL,00
0000:401C
75
JNZ
Decay
0000:401E
EB
JMP
Repeat
8086
8255
DAC 0800
13
14
FF 00 T = Time period f = 1/T
FF
00
T = Time period
f =
1/T

36

Sin wave Generation

 

0000: 4000

       

MOV AL,80

 

0000: 4002

BA

C6

FF

 

MOV

DX,0FFC6

 

0000: 4004

EE

     

OUT

DX,AL

 

0000: 4005

BA

C0

FF

 

MOV DX,0FFC0

 

0000:4008

FC

     

CLD

 

0000:4009

B1

18

 

cont

MOV

CL,18

 

0000:400B

BE

50

41

 

MOV

SI,4150

 

0000:400E

8A

04

 

next

LODSB

 

0000:4010

EE

     

OUT

DX,AL

 

0000:4011

E2

F8

   

LOOP

next

 

0000:4013

EB

F0

   

JMP

cont

 
   

Lookup table

   

S.No

Address

Decimal

Hex

01.

4150

128

80

02.

4151

160

AD

03.

4152

192

C0

04.

4153

217

D9

05.

4154

238

EE

06.

4155

251

FB

07.

4156

255

FF

08.

4157

251

FB

09.

4158

238

EE

0A.

4159

217

D9

0B.

415A

192

C0

0C.

415B

160

A0

0D.

415C

128

80

0E.

415D

96

60

0F.

415E

64

40

10.

415F

37

25

11.

4160

17

11

12.

4161

4

04

13.

4162

0

00

14.

4163

4

04

15.

4164

17

11

16.

4165

37

25

17.

4166

64

40

18.

4167

96

60

19.

4168

128

80

37

25.

Aim: To INTERFACE 7-SEGMNET LED DISPLAY to 8086.

Apparatus: 8086 kit, power supply

Interfacing Diagram:

 

MOV AL, 80H

 

MOV DX, FFC6

 

OUT DX, AL

 

MOV DX, FFC0

 

CLD

REPEAT:

MOV SI, 4100

 

MOV BL, 07H

NEXT:

LODSB

 

OUT DX, AL

 

CALL DELAY

 

DEC BL

 

JNZ NEXT

 

JMP REPEAT

DELAY:

MOV CX,FFFF

HERE:

LOOP HERE

 

RET

Address

CA

CC

BCD

Display

  • 4100 3F

C0

   
  • 00 0

  • 4101 F9

 

06

 
  • 01 1

  • 4102 5B

A4

   
  • 02 2

  • 4103 4F

B0

   
  • 03 3

  • 4104 99

 

66

 
  • 04 4

  • 4105 6D

92

   
  • 05 5

  • 4106 7D

82

   
  • 06 6

8086 D 0 - 8255 D 7
8086
D 0 -
8255
D 7
FRC cable PA 7 - PA 0
FRC cable
PA 7 - PA 0

7-seg display

CC= Common Cathode

PA 0=a

PA 5=f PA 1=b PA 6=g PA 4=e PA 2=c PA 3=d PA 7=h
PA 5=f
PA 1=b
PA 6=g
PA 4=e
PA 2=c
PA 3=d
PA 7=h

8086

PA 0 - PA 3 8255 D 0 - D 7 FRC cable
PA 0 - PA 3
8255
D 0 -
D 7
FRC cable

7447

BCD to 7-segment

CA = Common Anode

CC= Common Cathod

BCD to 7 -Segment

25. Aim: To INTERFACE 7-SEGMNET LED DISPLAY to 8086. Apparatus: 8086 kit, power supply Interfacing Diagram:
25. Aim: To INTERFACE 7-SEGMNET LED DISPLAY to 8086. Apparatus: 8086 kit, power supply Interfacing Diagram:

7447 Pin Diagram

38

26. Aim: To INTERFACE STEPPER MOTOR to 8086.

Apparatus: 8086 kit, power supply, Stepper motor, stepper motor interface board.

Theory:

A stepper motor is a device used to obtain an accurate position control of rotating

shafts. A stepper motor employs rotation of its shaft in terms of steps rather than

continuous rotation as in case of AC or Dc motors. To rotate the shaft of the stepper

motor, a sequence of pulses is needed to be applied to the windings of the stepper

motor, in proper sequence. A popular scheme for rotation of a stepper motor shaft

applies pulses to two successive windings at a time but these are shifted only by one

position at a time. This scheme for rotation of stepper motor is shown in the following

figure and table.

ROTATING STEPPER MOTOR SHAFT

MOTION

STEP

Code

Winding 1

Winding 2

Winding 3

Winding 4

Clock wise

1

03

 
  • 0 1

0

 

1

step angle 1.8 0

2

06

 
  • 0 1

1

 

0

(full step)

3

0C

 
  • 1 0

1

 

0

4

09

 
  • 1 0

0

 

1

 

Anti-clock

1

03

 
  • 0 1

0

 

1

wise

2

09

 
  • 1 0

0

 

1

step angle 1.8 0

3

0C

 
  • 1 0

1

 

0

(full step)

4

06

 
  • 0 1

1

 

0

             
 

1

0C

 
  • 1 0

1

 

0

2

09

 
  • 1 0

0

 

1

Step angle

3

03

 
  • 0 1

0

 

1

4

06

 
  • 0 1

1

 

0

0.9

0

(half step)

5

08

 
  • 1 0

0

 

0

6

01

 
  • 0 0

0

 

1

7

02

 
  • 0 1

0

 

0

8

04

 
  • 0 0

1

 

0

39

The stepper motor connections for the four windings can be shown as follows: PA 0 PA
The stepper motor connections for the four windings can be shown as follows:
PA 0
PA 1
PA 2
PA 3

Program:

 

MOV DX, 0FFC6H

 
 

MOV AL, 80H

 
 

OUT DX, AL

 
 

MOV DX, 0FFC0H

 

CONT:

MOV AL, 33H;

33, 99,CC,66

NEXT:

OUT DX, AL

 
 

CALL DELAY

 
 

ROL AL, 1

(for anti-clock rotation ROR AL, 1)

 

LOOP NEXT

 
 

JMP CONT

 
   

DELAY

MOV CX, 0FFH (for decrease the speed 0FF to 0FFFH)

HERE:

LOOP HERE

 
 

RET

 
   
 

KIT

MOTOR

PA 0 =13 ORANGE

GREEN

PA 1 =10

BLUE

RED

PA 2 =07

YELLOW

YELLOW

PA 3 =04

BROWN

ORANGE

40

27. Aim: To interface a 3*8 KEYBOARD with 8086 using 8255 and write an ALP

for detecting a key closure and return the key code in AL. The debouncing period of

a key is 10ms. Use software key debouncing technique. DEBOUNCE is an available

10ms delay routine.

Apparatus: 8086 kit, power supply, key-board module.

Solution: Port C is used as output port for selecting row of keys while port A is used as

input port for sensing a closed key. Thus the key boards lines are selected one by one

through Port C and Port A lines are hold continuously till a key closure is sensed. Then

routine DEBOUNCE is called for key debouncing. The Key code is decided depending

upon the selected row and a low sensed column. The hardware circuit diagram is shown

in the figure.

27. Aim: To interface a 3*8 KEYBOARD with 8086 using 8255 and write an ALP for

Figure: Interfacing 3*8 keyboard

41

The port A and port C lower are used. The addresses of port A and C will be

respectively FFC0H and FFC4h while the address of CWR is FFC6h. The flowchart

of the entire program is given in the following figure.

The port A and port C lower are used. The addresses of port A and C

42

Program:

 

MOV AL,90H

Port A I/P, Port B&C O/P

 
 

MOV DX,0FFC6H

Control Word Register

 
 

OUT DX,AL

 
 

MOV BL,00

initialize key code counter

 
 

MOV AL,0FFH

making all rows high

 
 

MOV DX,0FFC4H

Port C

 

OUT DX,AL

 
 

MOV DX,0FFC0H

Port A

WAIT:

IN AL,DX

Reading Columns Port A

 
 

CMP AL,00

 
 

JZ WAIT

 
 

CALL DEBOUNCE

 
 

MOV BH,03

To high no of rows

 
 

MOV AL,80H

 

NXROW:

ROL AL,1H

Row 1=0

 

MOV CH,AL

 
 

MOV DX,0FFC4H

Checking row 0

 
 

OUT DX,AL

 
 

MOV DX,0FFC0H

 
 

IN AL,DX

Reading columns