ai09 508 mp lab manual x86

32
Laboratory Manual AE&I Engineering Department, Govt.Engg.College Kozhikode Page 35 SECTION II ASSEMBLY LANGUAGE PROGRAMMING BASED ON 8086 KIT

Upload: arunbabu

Post on 27-Dec-2015

57 views

Category:

Documents


3 download

DESCRIPTION

it is the lab manual for 8086 microprocessor based on the calicut university syllabus

TRANSCRIPT

Page 1: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 35

SECTION II

ASSEMBLY LANGUAGE PROGRAMMING

BASED ON 8086 KIT

Page 2: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 36

Page 3: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 37

EXPERIMENT NO.6

FAMILIARIZATION OF 8086 TRAINER KIT

AIM:

To familiarize 8086 microprocessor trainer kit

GENERAL DESCRIPTION:

M 86-02 is a single board microprocessor trainer or development kit configured around the

INTEL’s 16 bit microprocessor. This kit can be used to train engineers to control any

industrial process and to develop between 8086 systems.

The kit has been changed to operate in the maximum mode processor 8087 and I/O processor

8089 can be added on board. 8086 can be also replaced by 8088 CPU.

The kit communication with the outside world through a IBM PC compatible keyboard with

20*2 LCD display. The kit also has the capacity of interfacing with PC. M86-02 is packaged

up with powerful monitor is 16k bytes of facility programmed EPROMS and 16k BSF or

read/write memory.

The on board resident system monitor software is very powerful. It provides various software

commands like BLOCK, MOVE, SINGLE STEP, EXECUTE FILE etc which are helpful in

debugging/developing software. An on board line assembler provides user to write program

in assembly language. The serial input output communication is made possible through 8251.

COMMAND DESCRIPTION:

A – ASSEMBLE:

This command is used to convert the input assembly language to machine language. In the

memory come under this command ‘N’ followed by an enter or an arrow down key to go new

step. Maximum of 35 words are allowed for all inputs.

G – PROCEED TO THE ADDRESS FOR EXECUTION:

The ‘GO’ command which causes the machine language statements to be executed. This

command executed the packed program and allows user to especially the address at which the

execution will stop.

I – INTERRUPT:

These interrupt = [effective address] can be set in for +ve program execution the CPU will

continuously make a single step sub program for checking IP register has the same value at

the interrupt is address. It will enter the interrupt sub program. Enter command I will

interrupt program.

Page 4: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 38

Page 5: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 39

U – UNASSEMBLE:

The unassembled command decodes the values of a group memory location mnemonics and

display on the display. Ones enter this command input the proper design address.

RESULT:

Familiarized the 8086 microprocessor trainer kit.

*****

Page 6: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 40

Page 7: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 41

EXPERIMENT NO.7

ARITHMETIC OPERATION-I

AIM:

a. Write assembly language program for addition of two 64 bit numbers

b. Write assembly language program for subtraction of two 64 bit numbers

c. Write assembly language program to perform 16×16 multiplication

EQUIPMENT REUIRED:

8086 Trainer Kit, Keyboard, Power chord

ALGORITHM:

a) 64 bit addition

Step 1: Initialize memory pointer with lower order address of result

Step 2: Initialize memory pointer with the lower order address of first number

Step 3: Initialize a register as pointer with the lower order address of second number

Step 4: Initialize a count register with number of bytes to be added i.e.04H

Step 5: Add the lower order bytes of two numbers and store the result

Step 6: Increment the byte counter and result pointer.

Step 7: Decrement the byte count.

Step 8: If the byte count is zero, go to the next step, otherwise go to step 5.

Step 9: Check for carry .If carry flag is set and then go to next step. Otherwise stop.

Step 10: Store the carry

Page 8: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 42

Page 9: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 43

b) 64 bit subtraction

Step 1: Initialize memory pointer with lower order address of result

Step 2: Initialize memory pointer with the lower order address of first number

Step 3: Initialize a register as pointer with the lower order address of second number

Step 4: Initialize a count register with number of bytes to be added i.e.04H

Step 5: Subtract the lower order bytes of two numbers and store the result

Step 6: Increment the byte counter and result pointer.

Step 7: Decrement the byte count.

Step 8: If the byte count is zero, go to the next step, otherwise go to step 5.

Step 9: Check for borrow .If carry flag is set and then go to next step. Otherwise stop.

Step 10: Store the borrow

c) 16×16 multiplication

Step 1: Initialize memory pointer with lower order address of result

Step 2: Initialize memory pointer for the multiplicand

Step 3: Initialize a register as pointer for the multiplier

Step 4: Multiply the numbers through accumulator

Step 5: Store the result

Page 10: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 44

OBSERVATION:

a) 64-bit addition

1. First 64-bit data: 01 03 12 32 01 03 12 32 @ 2007-2000

Second 64-bit data: 10 30 21 32 10 30 21 23 @200F-2008

Expected result: 11 33 33 64 11 33 33 55 @2807-2800

Observed result:

2. First 64-bit data:

Second 64-bit data:

Expected result:

Observed result:

Page 11: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 45

PROGRAM:

a) 64-bit addition

Address Hex code Label Mnemonics Comments

0400 BF 00 28 MOV DI,2800 Set DI register as pointer for result.

0403 MOV SI,2000 Set SI register as pointer for first data.

0406 MOV BX,2008 Set BX register as pointer for second

data.

0409 MOV CX,0004 Load the counter for no. of 16 bits in CX

register.

040C CLC Clear the carry flag.

040D BACK MOV AX,[SI] Get the first 16 bits of first data in A X

register.

040F ADC AX,[BX] Add the corresponding 16 bit of second

data to AX register.

0411 MOV [DI],AX Store the sum of corresponding 16 bits in

memory.

0413 INC BX Increment BX two times to get next two

bytes. 0414 INC BX

0415 INC DI Increment DI two times to store the next

two bytes. 0416 INC DI

0417 INC SI Increment SI two times to fetch next two

bytes 0418 INC SI

0419 LOOP BACK Loop is executed up to counter is zero.

041B JNC HALT Jump to last step if no carry.

041D MOV AX,0001 Store one in memory if carry is present.

0420 INC DI DI register is incremented to store carry

0421 INC DI

0422 MOV [DI],AX Store the carry

0424 HALT INT 3 Stop execution.

Page 12: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 46

OBSERVATION:

b) 64-bit subtraction

1. First 64-bit data: 07 07 07 07 07 07 07 07 @ 3007-3000

Second 64-bit data: 02 02 02 02 02 02 02 02 @300F-3008

Expected result: 05 05 05 05 05 05 05 05 @3507-3500

Observed result:

2. First 64-bit data:

Second 64-bit data:

Expected result:

Observed result:

c) 16x16 multiplication

1. Multiplicand value: 11 11 @ 2501-2500

Multiplier value: 23 23 @2001-2000

Expected result: 02 57 A8 53 @ 3003-3000

Observed result:

2. Multiplicand value:

Multiplier value:

Expected result:

Observed result:

:

Page 13: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 47

a) 64-bit subtraction

Address Hex code Label Mnemonics Comments

0500 38 00 35 MOV DI,3500 Set DI register as pointer for result.

0503 MOV SI,3000 Set SI register as pointer for first data.

0506 MOV BX,3008 Set BX register as pointer for second

data.

0509 MOV CX,0004 Load the counter for no.of 16 bits in CX

register.

050C CLC Clear the carry flag.

050D BACK MOV AX,[BX] Get the first 16 bits of first data in AX

register.

050F SBB AX,[BX] Subtract the corresponding byte of

second data to AX register.

0511 MOV [DI],AX Store the difference of corresponding 16

bits in memory.

0513 INC BX Increment BX two times to get next two

bytes. 0514 INC BX

0515 INC DI Increment DI two times to store the next

two bytes. 0516 INC DI

0517 INC SI Increment SI two times to fetch next two

bytes 0518 INC SI

0519 LOOP BACK Loop is executed up to counter is zero.

051B JNC HALT Jump to last step if no carry.

051D MOV AX,0001 Store one in memory if borrow is present.

0520 INC DI DI register is incremented to store

borrow. 0521 INC DI

0522 MOV [DI],AX Store the borrow .

0524 HALT INT 3 Stop execution.

c)16x16 multiplication

Address Hex code Label Mnemonics Comments

0600 BF 00 30 MOV DI,3000 Set DI register as pointer for result.

0603 MOV SI,2000 Set SI register as pointer for first data.

0606 MOV

BX,[2500]

Set BX register as pointer for second

data.

060A MOV AX,[SI] Get the first data in AX register.

060C MUL BX Content of AX is multiplied with content

of BX.

060E MOV [DI],AX Result is stored in DI

0609 INC DI Increment DI twice.

0610 INC DI

0612 MOV [DI],DX Content of DX register is moved to DI.

0614 INT 3 Stop execution.

Page 14: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 48

Page 15: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 49

RESULT:

The following programs were assembled, executed using 8086 trainer kit and outputs were

verified.

a) 64 bit addition

b) 64 bit subtraction

c) 16×16 multiplication

*****

Page 16: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 50

Page 17: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 51

EXPERIMENT NO.8

ARRAY OPERATIONS

AIM:

a) Write assembly language program to find the square of a number using look up table

(LUT) method

b) Write assembly language program for sorting of an array of N elements

c) Write assembly language program to find the sum and average of an array of N numbers

EQUIPMENTS REQUIRED:

8086 Trainer kit, Keyboard, Power chord

ALGORITHM:

a) Square of a number using LUT

Step 1: Pre-store the square values of N numbers in memory as look up table (LUT)

Step 2: Initialize memory pointer for the result and base address of LUT

Step 3: Add the input value with the base address of LUT as an offset

Step 4: Read out the LUT content and store in a memory location

b) Sorting of an array of N elements

Step 1: Initialize a count register for the array size N

Step 2: Initialize memory pointer for the input data

Step 3: Compare the accumulator with consecutive data in memory using bubble sorting

Step 5: Decrement the count register on each comparison and exit on zero

c) Sum and Average of N numbers

Step 1: Initialize memory pointer for the input and for the result

Step 2: Initialize the count register with array size N

Step 3: Add consecutive numbers in memory through accumulator

Step 4: Decrement the count register

Step 5: If zero go to step 6, else repeat step 4

Step 6: Calculate the average and store the result

Page 18: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 52

OBSERVATION:

a) Square of a number using LUT

1. Input data: 00 0A @ 3001-3000

Expected result: 00 64 @ 3003-3002

Observed result:

2. Input data:

Expected result:

Observed result:

b) Sorting of an array of N elements

1. Number of elements: 00 03H @2301-2300

Input numbers: 6757, 5431, ADDA @ 2302-2307

Expected result: 5431, 6757, ADDA @ 2302-2307

Observed result:

2. Number of elements: 00 0AH @2301-2300

Input numbers: 0009,0008,0007,0006,0005,0004,0003,0002,0001,0000 @2302-2315

Expected result: 0000, 0001,0002,0003,0004,0005,0006,0007,0008,0009 @ 2302-2315

Observed result:

Page 19: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 53

a) Square of a number using LUT

Memory

address

Hex code Label Mnemonics Comments

0400 BF 02 30 MOV DI,3002 Initialize the result pointer

0403 MOV SI,2500 Base address of LUT

0406 MOV BX,[3000] Load the input data

0408 ADD SI,BX LUT adr = base adr+offset

040A MOV AX, [SI] Read square value from LUT

040C MOV [DI], AX Output the result to memory

0410 INT 3 Stop execution

b) Sorting of an array of N elements

Memory

address

Hex

code

Label Mnemonics Comments

0600 MOV BX,[2300] The no: of operand in BX

0604 DEC BX Find N-1

0605 LOOP1 MOV CX,BX Counter of N-1 is stored

0607 MOV SI,2302 SI is pointed to 2302

060A LOOP2 MOV AX,[SI] 1st no: is taken to AX

060C ADD SI,0002 The SI is incremented twice

0610 CMP AX,[SI] AX-[SI] Operation

0612 JB GO If AX> [SI] go to GO

0614 XCHG [SI],AX The AX&SI are exchanged

0616 SUB SI,002 Decrement SI twice

061A MOV SI,AX Loading small no: to AX

061C ADD SI,0002 Increment SI for next 16-bit

0620 GO LOOP LOOP2 Repeat comparison process

up to CX not equal to zero

0622 DEC BX Decrement BX

0623 JNZ LOOP 1 Repeat when BX is not zero

0625 INT 3 Stop execution

Page 20: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 54

c) Sum and Average of N numbers

1. Number of elements: 03H @ 2000

Input data: 72,43,59 @ 2100-2102

Expected result: Sum: 10E, Average: 5A

Observed result:

2. Number of elements:

Input data:

Expected result: Sum: Average:

Observed result:

Page 21: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 55

c) Sum and Average of N numbers

Memory

address

Hex code Label Mnemonics Comments

0500 BE 00 21 MOV SI,2100 Set SI as pointer for array

0503 MOV DI,2200 Set DI as pointer for result

0506 MOV CX,[2000] Setting counter with no: of

elements in array

050A MOV AX,0000 Setting initial sum as zero

050D REPEAT ADD AL,[SI] Add first byte of array to sum

050F JNC AHEAD If no carry jump to AHEAD

0511 INC AH If there is carry then increment

AH register

0513 AHEAD INC SI Increment SI register for next

no: to be added

0514 LOOP REPEAT Addition is repeated till

counter becomes zero

0516 MOV [DI],AX Sorting the sum in memory

0518 MOV BL,[2000] Loading count value to BL

051C DIV BL Sum in AX is divided by BL

051E ADD DI,0002 Increment DI to store the

average

0522 MOV [DI],AX Store average in DI

0524 ADD DI,0002 Increment DI twice

0528 MOV [DI],DX Move the content of DX to DI

052A INT 3 Stop execution

RESULT:

Following programs assembled, executed using 8086 trainer kit and outputs were verified.

a) Square of a number using LUT method

b) Sorting an array of N-elements

c) Sum and average of an array of N- elements

*****

Page 22: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 56

Page 23: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 57

SECTION III

INTERFACING PROGRAMS BASED ON

8085/8086 KIT

Page 24: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 58

Page 25: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 59

EXPERIMENT NO.9

INTERFACING WITH STEPPER MOTOR

AIM:

a) Write Assembly language program to perform stepper motor interfacing

EQUIPMENTS REQUIRED:

8086 Trainer Kit, Keyboard, Power Chord, Stepper motor module, 26-pin FRC, External

supply connector

PROCEDURE:

1. Connect stepper motor interfacing module to 8255-I of 8086 Trainer Kit through 26 pin

FRC Cable

2. Be sure about the direction of the cable i.e. Pin No. 1 of module should be connected to

Pin No. 1 of 8255 connector

3. Connect +5V, ±12V, GND from the Trainer Kit (+5V & GND signals are available in the

25 & 26 pin of FRC 8255-I Connector)

4. Enter the program from 0400 for 8086 Kit LCD Kit and make sure that your program is

entered properly before execution

5. Execute your program from respective location & observe the results

ALGORITHM:

a) Stepper motor interfacing

Step 1: Initialize the Control Word Register and Port A as output of 8255 PPI

Step 2: Output the sequence F9-F5-F6-FA repeatedly from accumulator with delay of 1

sec through Port A to rotate stepper motor in anti-clockwise direction

Step 3: Reverse the sequence FA-F6-F5-F9 for clock-wise direction interfacing

Page 26: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 60

Stepper motor Interfacing diagram:

Stepper motor sequence table:

Step Q3 Q2 Q1 Q0 Modes

1 1 0 1 0 2 phase

excitation

2 0 1 1 0

3 0 1 0 1

4 1 0 0 1

Page 27: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 61

PROGRAM:

Memory

address

Hex code Label Mnemonics Comments

0400 B0 80 MOV AL,80 Port A is initialised

0402 OUT 76,AL

0404 START MOV AL,F9 Code for step 1

0406 OUT 70,AL

0408 CALL DELAY Delay between sequence for 1 sec

040B MOV AL,F5 Code for step 2

040D OUT 70,AL

040F CALL DELAY Delay between sequence for 1 sec

0412 MOV AL,F6 Code for step 3

0414 OUT 70,AL

0416 CALL DELAY Delay between sequence for 1 sec

0419 MOV AL,FA Code for step 4

041B OUT 70,AL

041D CALL DELAY Delay between sequence for 1 sec

0420 JMP START Repeat the rotation

0423 DELAY MOV CX,0000 Delay routine for 1 sec

0426 LOOP DEC CX

0427 JNZ LOOP

0429 RET Return

RESULT:

Assembly language program for stepper motor interfacing assembled, executed and verified

the output.

*****

Page 28: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 62

Page 29: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 63

EXPERIMENT NO.10

INTERFACING WITH SEVEN SEGMENT DISPLAY

AIM:

a) Write Assembly language program to perform seven segment display

EQUIPMENTS REQUIRED:

8086 Trainer Kit, Keyboard, Power Chord, Seven segment display module, 26-pin FRC

PROCEDURE:

1. Connect seven segment interfacing module to 8255-I of 8086 Trainer Kit through 26 pin

FRC Cable

2. Be sure about the direction of the cable i.e. Pin No. 1 of module should be connected to

Pin No. 1 of 8255 connector

3. 5V & GND signals are available in the 25 & 26 pin of FRC 8255-I Connector)

4. Enter the program from 0600 for 8086 Kit LCD Kit and make sure that your program is

entered properly before execution

5. Execute your program from respective location & observe the results

ALGORITHM:

a) Seven segment display interfacing

Step 1: Initialize the Control Word Register and Port A as output of 8255 PPI

Step 2: Initialize Port C and Port B of 8255

Step 3: Initialize character count register for display

Step 4: Pre-store the decoder segment values for the word starting from memory 0500

Step 7: Read the segment values from memory through repeated loop

Page 30: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 64

Seven segment decoding format:

Display code for string “GOOD”:

Binary 0: ON

Binary 1: OFF

Character 8-bit binary code (hgfedcba) 8-bit hex code

G 1000 0010 82

O 1100 0000 C0

O 1100 0000 C0

D 1010 0001 A1

Memory table for display code:

Memory Address Display code

0500 82

0501 C0

0502 C0

0503 A1

b

c

d

e

f

g

h

a

Page 31: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 65

PROGRAM:

Memory

Address

Hex code Label Mnemonics Comments

0600 B0 80 MOV AL,80 Moving 80H to AL

0602 OUT 76,AL Initialise counter

0604 L22 MOV CX,0020 CX is loaded with 0020

0607 L1 MOV AL,00 AL is loaded with 00

0609 OUT 74,AL Port C is initialised

060B MOV AL,FF AL is loaded with FFH

060D OUT 72,AL Port B is initialised

060F MOV AL,01 Moving 01H to AL

0611 OUT 74,AL

0613 DEC CX Decrement counter

0614 JNE L1 Start jump to loop1

0614 L2 MOV SI,0500 Initialise SI with 0500

0619 MOV CL, 04 Initialise counter value as 4

061B L5 MOV BL,08

061D MOV BH,[SI] Moving the contents of SI to BH

061F L3 MOV AL,00

0621 OUT 76, AL

0623 MOV AL,[BH] Moving the contents of BH to AL

0625 RCL AL,01 Reloaded left by 1

0627 MOV BH,AL AL is loaded to BH

0629 RCL AL,01 Reloaded left by 1

062B OUT 72,AL

062D MOV AL,01

062F OUT 74,AL

0631 DEC BL Decrement BL

0633 JNE L3 Jump to L3

0635 MOV AX,0000

0638 L4 DEC AX

0639 JNE L4 Short jump to L4

063B INC SI Increment SI

063C DEC CL

063E JNE L5 Jump to L5 when A is not equal to 0

0641 JMP L22 Short jump to L22

RESULT:

Assembly language program for seven segment display assembled, executed and verified the

output.

*****

Page 32: AI09 508 Mp Lab Manual x86

Laboratory Manual

AE&I Engineering Department, Govt.Engg.College Kozhikode Page 66