Anda di halaman 1dari 17

MICROPROCESSOR LAB

Submitted by:-Varun Kant

SID:- 16104088

Submitted to:-Prof Amita


INDEX
S.NO EXPERIMENTS
1 WAP to perform addition of 2 hexadecimal numbers in 8086
microprocessor
2 WAP to perform subtraction of two numbers in 8086
microprocessor
3 WAP to perform multiplication of two 16-bit numbers in 8086
microprocessor
4 WAP to get 2's complement of 5 hexadecimal nos’ in 8086
microprocessor
5 WAP to find greatest number from 10 hexadecimal numbers in
8086 microprocessor.

6 WAP to find the smallest number from 10 hexadecimal numbers


in 8086 microprocessor.

7 Write a program to sort string number of bytes in ascending


order
8 Write a program to sort string number of bytes in descending
order
9 WAP To convert Gray code to 8 bit Binary number.

10 WAP to find factorial of a hexadecimal no.


11 WAP to separate even and odd numbers from a string

12 WAP to search byte out of string


13 WAP to store any number of string in reverse order.

14 To convert 8 bit binary number to gray code


15 To interface stepper motor with 8086 microprocessor.
EXPERIMENT NO- 1

AIM : WAP to perform addition of 2 hexadecimal numbers in 8086 microprocessor

MEMORY MNEMONICS COMMENTS


LOCATION
4000 CLC Clear Carry flag
MOV AX,4343 Initialise data segment, put 1st number in AX
MOV BX,1111 Put 2nd number in BX.
ADD AX,BX Add contents of BX with AX and store
result in AX.
HLT Halt

OUTPUT:

Input output
Register Data Register Data
AX 4343 AX 5454
BX 1111
EXPERIMENT NO – 2

AIM : WAP to perform subtraction of two numbers in 8086 microprocessor

MEMORY MNEMONICS COMMENTS


LOCATION
4000 CLC Clear Carry flag
MOV AX,4343 Initialise data segment, put 1st number in AX
MOV BX,1111 Put 2nd number in BX.
SUB AX,BX Substract contents of BX from AX and store
result in AX.
HLT Halt

OUTPUT:

Input output
Register Data Register Data
AX 4343 AX 3232
BX 1111
EXPERIMENT NO -3

AIM : WAP to perform multiplication of two 16-bit numbers in 8086 microprocessor.

MEMORY MNEMONICS COMMENTS


LOCATION
4000 CLC Clear Carry flag
MOV AX,4343 Initialise data segment, put 1st number in AX
MOV BX,1111 Put 2nd number in BX.
MUL BX Multiply contents of BX with AX and store
result in AX.
HLT Halt

OUTPUT:

Input Output
Register Data Register Data
AX 4343 AX EA73
BX 1111 DX 047B
EXPERIMENT NO -4
AIM: WAP to get 2's complement of 5 hexadecimal nos’ in 8086 microprocessor.

LABEL CODE COMMENTS

MOV CX,05 Initialize the counter register with value 10


MOV SI,0700 Initialize source index register with the address of 1st Number
MOV DI,4000 Load the destination index register with initial destination address
MOV AL,[SI] Move the contents of Source Index Register to Accumulator

XX NEG AL Negate the contents of Accumulator


MOV [DI],AL Move the contents of accumulator to contents addressed by DI
INC SI Point at next location shown by Source index register
INC DI Point at next location shown by Destination index register
LOOP XX Repeat the steps from 060B
HLT Halt

OUTPUT:

INPUT: RESULT:
0700: 05 0400: FA
0701: 01 0401: FE
0702: 0D 0402: F3
0703: 2F 0403: D0
0704: 09 0404: F6
0705: 06 0405: F9
EXPERIMENT NO – 5
AIM : WAP to find greatest number from 10 hexadecimal numbers in 8086
microprocessor.

LABEL CODE COMMENTS


MOV SI,0800 The offset address 0800 to SI
MOV CX,000A The counter is initiated with 10
MOV AH,00 Move the value 00 to AH
YY CMP AH,[SI] Compare the value AH with value in SI
JAE XX Jump to 040E if value in AH is greater or equal
to value in SI
MOV AH,[SI] Move the value from SI toAH
XX INC SI Increment the value of SI
LOOPNE Decrement the counter value if not zero
MOV [SI],AH Move the value from AH toSI
HLT HALT

OUTPUT:

INPUT Results:

0800: 09 0810:FF
0801: FF
0802: 04
0803: 05
0804: 07
0805: 08
0806: F9
0807: 00
0808: 01
0809:06
EXPERIMENT NO- 6
AIM: WAP to find smallest number from 10 hexadecimal numbers in 8086
microprocessor.
LABEL CODE COMMENTS
CLC Clear Carry Flag
MOV SI,0500 The offset address 0500 moved to SI
MOV CX,000A The counter is initiated to 10
MOV AH,FF The value FF is moved to AH
X xx XX CMP [SI],AH Comparing the value in SI with
AH(FF)
JAE YY Jump to 040E if [SI] is greater than or equal to AH

MOV AH,[SI] Move the value in SI to AH


YY INC SI Increment SI
LOOPNE XX Decrement the counter value as CX=CX-1, if not zero,
continue processing
MOV [SI],AH Move the value in AH to SI

HLT HALT

OUTPUT:

Example: Result

0500: FF 0500: 02
0501: FE
0502: 09
0503: 06
0504: 07
0505: 03
0506: F7
0507: FF
0508: 02
0509: AB
EXPERIMENT NO -7
AIM: Write a program to sort string number of bytes in ascending order

LABEL CODE COMMENTS


MOV SI, 0500 SI points to string at 0500, first element
being the length of string.
MOV BX, [SI] BX is initialised with first value
DEC BX BX decrement by one
MOV CX, [SI] The value in SI is moved to CX
DEC CX CX register value is decremented
YY MOV SI, 0502 SI moves to next location , where the string
starts
MOV AL,[SI] AL is loaded with first value of strings.
INC SI SI points to the next number
CMP AL,[SI] AL is compared with next number
JAE XX If AL register values is greater than the
succeeding number, it jumps to label up
XCHG AL,[SI] Else values of first and second elements are
exchanged
DEC SI SI is decremented
MOV[SI], AL Succeeding number is exchanged with number
at first position of string
XX INC SI SI is incremented
LOOP YY Process is repeated till last number
HLT Program ends

OUTPUT:

Example: Results:

0500: 0005H 0500: 0005H

0501: FFH 0501: FFH

0502: 06H 0502: 0CH

0503: 08H 0503: 0BH

0504: 0BH 0504: 08H

0505: 0CH 0505: 06H


EXPERIMENT NO – 8
AIM: Write a programme to sort number of bytes in descending order.

LABEL CODE COMMENTS


MOV SI, 0500 SI points to string at 0500, first element
being the length of string.
MOV BX, [SI] BX is initialised with first value
DEC BX BX decrement by one
MOV CX, [SI] The value in SI is moved to CX
DEC CX CX register value is decremented
YY MOV SI, 0502 SI moves to next location , where the string
starts
MOV AL,[SI] AL is loaded with first value of strings.
INC SI SI points to the next number
CMP AL,[SI] AL is compared with next number
JAE XX If AL register values is greater than the
succeeding number, it jumps to label up
XCHG AL,[SI] Else values of first and second elements are
exchanged
DEC SI SI is decremented
MOV[SI], AL Succeeding number is exchanged with number
at first position of string
XX INC SI SI is incremented
LOOP YY Process is repeated till last number
HLT Program ends

OUTPUT:
Example: Results:

0500: 0005H 0500: 0005H


0501: FFH 0501: FFH
0502: 06H 0502: 0CH
0503: 08H 0503: 0BH
0504: 0BH 0504: 08H
0505: 0CH 0505: 06H
EXPERIMENT NO – 9
AIM: Write a Program to convert Gray code to 8 bit Binary number

CODE COMMENTS
MOV DI,7000 The final result will be displayed
MOV CX,02
MOV AL,B3 Content moved to AL

MOV BL,AL Content copied to BL

SHR BL, CX Shift right applied to BL

XOR AL,BL XOR applied on AL, BL

MOV BL,AL Content copied to BL

SHR BL, 01 Shift right applied to BL

XOR AL,BL XOR applied on AL, BL

MOV [DI], AL Content moved to the address specified by DI

HLT Halt

OUTPUT:

INPUT Result:

B3 EA
EXPERIMENT NO – 10
AIM: Write a Program to find the factorial of a number.

LABEL CODE COMMENTS


MOV SI,3000 The number, stored at location 2000 moved to SI
MOV DI,3002 DI points to location 2002
MOV CX,[SI] CX register obtains the value of the number
MOV AX,CX The number is copied to AX
DEC CX CX register’s value is decremented
XX MUL CX CX value is by default multiplied with AX DEC CX
JNZ XX Checks if CX is zero or not, if its zero it bypasses the LOOP

MOV [DI],AX Result in AX is copied to location pointed by DI


HLT Program ends

OUTPUT:

INPUT: Result:
3000: 07H 3002: 13B0H
3000: 08H 3002: 9D80H
EXPERIMENT NO – 11
AIM: Write a Program to separate odd and even number from a string

LABEL CODE COMMENTS


MOV SI,0500 SI points to the string
MOV CX,0010 CX is given the number of numbers in the string
MOV BX,2000 BX points to string of odd numbers
MOV DI,3000 DI points to string of even numbers
XX MOV AX,[SI] AX is loaded with first number of string
ROR AX,01 Value in AX is rotated once to right
JC YY Jumps if carry flag is 1 i.e. odd number
MOV [DI],[SI] Original number gets loaded to DI string
INC DI DI points to next position of string
JMP ZZ Jump to label ZZ
YY MOV [BX],[SI] Original number gets loaded to BX string
INC BX BX points to next position of string
ZZ INC SI SI is moved to next number in string
LOOP XX The same process is repeated till CX equal zero
HLT Halt

OUTPUT:

INPUT Results: ODD EVEN

0500: 05H 2000: 05H 3000: ABH


0501: ABH 2001: 0FH 3001: 08H
0502: 0FH 2002: 03H 3002: 0AH
0503: 03H 2003: 05H 3003: 0CH
0504: 05H 2004: 09H
0505: 09H 2005: 07H
0506: 07H 2006: 0BH
0507: 08H 2007: 0DH
0508: 0AH
0509: 0CH
050A: 0BH
050B: 0DH
EXPERIENT NO- 12
AIM: Write a Program to search a number from the string

LABEL CODE COMMENTS


MOV SI,2000 SI points to string of numbers
MOV CX,0005H CX is initialized with the length of the string
MOV AL,05H AL is the number being searched for
MOV DI,5000H
XOR BL,BL BL is initialized with zero
YY CMP AL,[SI] AL is compared with first element of string
JZ XX If zero flag is set, jump to SKIP label
INC BL BX gets incremented by one
INC SI SI gets incremented by one
LOOP YY The same task is repeated for rest of numbers in string
XX MOV [DI],AL Move the content of AL to DX
HLT Halt

OUTPUT:

INPUT Results:

2000: 01H BL: 05H

2001: 05H

2002: 45H

2003: DFH

2004: EAH
EXPERIMENT NO – 13
AIM: WAP to store any number of string in reverse order.
LABEL CODE COMMENTS
MOV AX,0005H Initialise register AX with the number of bytes of the
string
MOV SI,0500 Copy the starting offset address of the string to the
register SI
DEC AX Decrement the contents of register AX by 1
ADD AX,SI Add the contents of AX and SI to obtain the ending
address of the string.The result is stored in the register
AX.
MOV DI,AX The ending address of the string is moved to the register
DI.
MOV CX, 0002H Copy the number of times the loop is to be run to the
counter register CX.(Let n be the nnumber of bytes string
is containing, if n is odd a numberf (n-1)/2 is moved to CX
and if n is even n/2 is moved to CX).
XX MOV BL,[SI] Copy the element stored at the memory location pointed
by SI to the register BL
XCHG BL,[DI] Exchange the elements of register BL and the element
stored at the memory location pointed by DI.
MOV [SI],BX Copy the contents of BL to the memory location pointed
by SI
INC SI Increment the contents of SI by 1 to point next memory
location
DEC DI Decrement the contents of DI by 1 to point the previous
memory location.
LOOP XX The process of exchanging the elements stored at
memory locations pointed by DI and SI has to be
continued till content of CX becomes 0. Hence LOOP is
used.
HLT Halt

INPUT: OUTPUT:

0500: 1 0500: 5
0501: 2 0501:4
0502:3 0502:3
0503:4 0503:2
0504: 5 0504:1
EXPERIMENT NO – 14

AIM: WAP to convert binary into gray code in 8086 microprocessor

CODE COMMENTS
MOV AX,000A Copying 000Ato AX
MOV BX,AX Copying AX to BX
SHR BX,AX Shift logical right BX by 1
XOR BX,AX XOR BX with AX and result store at BX
MOV[2000],BX Duplicate BX to [2000]
HLT Halt

OUTPUT : 0F
EXPERIMENT NO – 15
AIM: To interface and control a stepper motor using 8086 microprocessor.

ADDRESS CODE COMMENTS


400 MOV AL,80 Initialize 8255
402 OUT 86,AL
404 MOV AL,FA 1st step
406 OUT 80,AL
408 CALL DELAY1 Delay between two steps
40B MOV AL,F5 Second step
40D OUT 80,AL
40F CALL DELAY1 Delay between two steps
412 MOV AL,F5 Third step
414 OUT 80,AL
416 CALL DELAY1
419 MOV AL,F9
41B OUT 80,AL
41D CALL DELAY1
420 JMP 404
430 MOV BX ,0100 Delay routine
433 CALL DELAY
436 RET
437
439 CALL 043D Delay routine
43C RET
43D DEC BX
43E NOP
441 JNE 043D
443 RET

Anda mungkin juga menyukai