Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

3 1 Cse Mpi Unit 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

NRI Institute Of Technology

UNIT-II
2.1) Arithmetic instruction ALPs
2.2) Logical instruction ALPs
2.3) Sorting and String manipulation ALP

CSE III B.Tech I SEMESTER

103

MPI

NRI Institute Of Technology

2.1) Arithmetic instruction ALPs:


1) Write an 8086 assembly language program for addition of two ASCII

numbers.
PROCEDURE:
1. Start the program
2. Move the data byte 39 to AL register
3. Move the data byte 35 to BL register
4. Add the contents BL to the contents of AL. Result will be stored in AL register.
5. Use the instruction AAA to adjust the result to correct unpacked BCD
5. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE

LABEL

MNEMONIC

OPERAND

MOV

AL, 39

MOV

BL, 35

ADD

AL, BL

AAA
INT

2) Write an 8086 assembly language program for subtract two ASCII


numbers.
PROCEDURE:
1. Start the program
2. Move the data byte 39 to AL register
3. Move the data byte 35 to BL register
4. Subtract the contents of BL from the contents of AL. Result will be stored in AX
register.
5. Use the instruction AAS to adjust the result to correct unpacked BCD
5. Stop the program by using Interrupt.

CSE III B.Tech I SEMESTER

104

MPI

NRI Institute Of Technology

Program: ADDRESS OPCODE

LABEL

MNEMONIC

OPERAND

MOV

AL, 39

MOV

BL, 35

SUB

AL, BL

AAS
INT

3) Write an 8086 assembly language program for multiplication of two


ASCII numbers.
PROCEDURE:
1. Start the program
2. Move the data byte 09 to AL register
3. Move the data byte to 06 BL register
4. Multiply the contents of AL with the contents of AL. Result will be stored in AX
register.
5. Use the instruction AAM to adjust the result to correct unpacked BCD.
6. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE LABEL

MNEMONIC OPERAND
MOV

AL, 09

MOV

BL, 06

MUL

BL

AAM
INT

CSE III B.Tech I SEMESTER

105

MPI

NRI Institute Of Technology


4) Write an 8086 assembly language program for division of two ASCII
numbers.
PROCEDURE:
1. Start the program
2. Move the data 0507 to AX register
3. Move the data 09 to CH register
4. Use the AAD instruction to adjust the content of AX to correct unpacked BCD before
division operation.
5. Divide the contents of AX with the contents of CH. Result will be stored in AX
register.
6. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE LABEL

MNEMONIC OPERAND
MOV

AX, 0507

MOV

CH, 09

AAD
DIV

CH

INT

5) Write an 8086 assembly language program for GCM of given


numbers.
PROCEDURE:
1. Start the program
2. Move the data word10000 to AX register
3. Move the data word 3050 to BX register
4. Move the data word 0000 to DX register
5. Move the data word 0004 to CX register
6 Move the data word 3000 to source index register.
7. Move the data word 3010 to destination index register
8. Move the contents of source index register to AX register

CSE III B.Tech I SEMESTER

106

MPI

NRI Institute Of Technology


9. Add the contents of destination index register to the contents of AX
10. Move the result in AX to memory location whose offset address is in BX register
11. Increment source index register twice
12. Increment destination index register twice.
13. Increment BX register.
14. Decrement CX register.
15. Check the flag register whether zero flag is set or reset. Jump to specified memory
location if it is reset. Otherwise Check the flag register whether borrow flag is set or
reset. Jump to specified memory location if it is not set. Otherwise increment DX
register.
16. Stop the program by using Interrupt.
PROGRAM: ADDRESS

LABEL

MNEMONIC OPERAND

L1:

CSE III B.Tech I SEMESTER

107

MOV

AX, 0000

MOV

BX, 3050

MOV

DX,0000

MOV

CX,0004

MOV

SI, 3000

MOV

DI,3010

MOV

AX, [SI]

ADC

AX, [DI]

MOV

[BX], AX

INC

SI

INC

SI

INC

DI

INC

DI

INC

BX

INC

BX

DEC

CX

JNZ

L1

MPI

NRI Institute Of Technology

L2:

JNB

L2

INC

DX

INT

6) Write an 8086 assembly language program for multi byte subtraction.


PROCEDURE:
1. Start the program
2. Move the data word10000 to AX register
3. Move the data word 3050 to BX register
4. Move the data word 0000 to DX register
5. Move the data word 0004 to CX register
6 Move the data word 3000 to source index register.
7. Move the data word 3010 to destination index register
8. Move the contents of source index register to AX register
9. Subtract the contents of destination index register from the contents of AX
10. Move the result in AX to memory location whose offset address is in BX register
11. Increment source index register twice
12. Increment destination index register twice.
13. Increment BX register twice.
14. Decrement CX register.
15. Check the flag register whether zero flag is set or reset. Jump to specified memory
location if it is reset. Otherwise Check the flag register whether borrow flag is set or
reset. Jump to specified memory location if it is not set. Otherwise increment DX
register.
16. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE

LABEL

CSE III B.Tech I SEMESTER

MNEMONIC OPERAND

108

MOV

AX, 0000

MOV

BX, 3050

MOV

DX,0000

MPI

NRI Institute Of Technology

L1:

L2:

MOV

CX,0004

MOV

SI, 3000

MOV

DI,3010

MOV

AX, [SI]

SBB

AX, [DI]

MOV

[BX], AX

INC

SI

INC

SI

INC

DI

INC

DI

INC

BX

INC

BX

DEC

CX

JNZ

L1

JNB

L2

INC

DX

INT

7) Write an 8086 assembly language program for the generation of


Fibonacci series.
PROCEDURE:
1. Start the program
2. Move the data 00 to BL register
3. Move the data 01 to DL register
4. Move the data 2500 to CX register
5. Move the data 2600 to source index register
6. Move the contents of BL to the memory location whose offset address is specified in
SI
7. Increment source index register
8. Move the contents of DL to the memory location whose offset address is specified in
SI

CSE III B.Tech I SEMESTER

109

MPI

NRI Institute Of Technology


9. Add the contents of DL with the contents of BL and store the result in BL
10. Exchange the contents of BL and DL
11. Repeat from step 7 until count in CX register is equal to zero.
12. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE

LABEL

MNEMONIC OPERAND

L1:

MOV

BL, 00

MOV

DL, 01

MOV

CX, 0005

MOV

SI, 2600

MOV

[SI], BL

INC

SI

MOV

[SI], DL

ADD

BL, DL

XCHG

BL, DL

LOOP

L1

INT

8) Write an 8086 assembly language program for finding the factorial of a


given number.
PROCEDURE:
1. Start the program
2. Move the contents of data from the memory location [2500] to AL register
3. Move the contents of AL to CL register.
4. Decrement the contents of CX register
5. Multiply the contents of CL with the contents of AL. Result will be stored in AX
register. Repeat the multiplication until count in CX register is equal to zero.
6. Move the result to the memory location 2600
7. Stop the program by using Interrupt.

CSE III B.Tech I SEMESTER

110

MPI

NRI Institute Of Technology

PROGRAM: ADDRESS OPCODE

LABEL

MNEMONIC OPERAND

L1:

CSE III B.Tech I SEMESTER

111

MOV

SI, 2500

MOV

DI, 2600

MOV

AX, [SI]

MOV

CX, AX

DEC

CX

MUL

CX

LOOP

LI

MOV

[DI], AX

INT

MPI

NRI Institute Of Technology

2.2) Logical instructions ALPs:


Packed BCD to Unpacked BCD
Logical OR on two numbers
Logical AND on 2 numbers
Logical NOT on two numbers
Logical TEST operation
Rotate left through carry on a given number
Rotate right through carry on a given number
Rotate left operation on a given number
Rotate right operation on a given number
Shift arithmetic right on a given number
Shift given number right (SHR)
Shift given number left (SHL)
Conversion of ASCII to BCD
Conversion of BCD to ASCII

1) Write an 8086 assembly language program for conversion of packed


to unpacked BCD.
PROCEDURE:
1. Start the program
2. Move the data 00 to AL register
3. Move the data 00 to AH register
4. Move the content of AL to BL
5. Move the data 3010 to destination index
6. Perform logical AND operation on the contents of AL and 0F
7. Move this RESULT in AL to the memory location whose offset address is specified in
destination index.
8. Increment destination index register.
9. Move the data 04 to CL register
10. Shift right the content of BL by CL times.

CSE III B.Tech I SEMESTER

112

MPI

NRI Institute Of Technology


11. Move the contents of BL to the memory location whose offset address is stored in
destination index.
12. Increment destination index register.
13. Now perform the AND operation on contents of AH register. Repeat the steps from 8
to 12 by replacing BL by BH
14. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE

LABEL

MNEMONIC OPERAND
MOV

AL, 34

MOV

AH, 12

MOV

BL, AL

MOV

BH, AH

MOV

DI, 3010

AND

AL, 0F

MOV

[DI], AL

INC

DI

MOV

CL, 04

SHR

BL, CL

MOV

[DI], BL

INC

DI

AND

AH, 0F

MOV

[DI], AH

INC

DI

SHR

BH, CL

MOV

[DI], BH

INT

2) Write an 8086 assembly language program for logical OR operation.


PROCEDURE:

CSE III B.Tech I SEMESTER

113

MPI

NRI Institute Of Technology


1. Start the program
2. Move the data 1234 to AX register
3. Move the data FFFH to BX register
4. OR the contents of BX and the contents of AX. Result will be stored in AX register.
5. Stop the program by using Interrupt.
PROGRAM: -

ADDRESS OPCODE

LABEL

MNEMONIC OPERAND
MOV

AX, 1234

MOV

BX, 0FFFF

OR

AX, BX

INT

3) Write an 8086 assembly language program for logical AND


operation.
PROCEDURE:
1. Start the program
2. Move the data 0012 to AX register
3. Move the data FFFH to BX register
4. AND the contents of BX and the contents of AX. Result will be stored in AX register.
5. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE

LABEL

CSE III B.Tech I SEMESTER

MNEMONIC OPERAND

114

MOV

AX, 0012

MOV

BX, 0FFFF

AND

AX, BX

INT

MPI

NRI Institute Of Technology


4) Write an 8086 assembly language program for logical NOT
operation.
PROCEDURE:
1. Start the program
2. Move the data FFFF to AX register
3. NOT the contents of AX. Result will be stored in AX register.
5. Stop the program by using Interrupt.

ADDRESS OPCODE

LABEL

MNEMONIC OPERAND
MOV

AX, 0FFFF

NOT

AX

INT

5) Write an 8086 assembly language program for logical TEST


operation.
PROCEDURE:
1. Start the program
2. Move the data 0F to AL register
3. Move the data 00 to BL register
4. TEST the contents of AL and the contents of BL. Result will be stored in AL register.
5. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE

LABEL

CSE III B.Tech I SEMESTER

MNEMONIC OPERAND

115

MOV

AL, 0F

MOV

BL, 00

TEST

AL, BL

INT

MPI

NRI Institute Of Technology


6) Write an 8086 assembly language program for rotate left through
carry.
PROCEDURE:
1. Start the program
2. Move the data AAAA to AX register
3. Move the data 01 to CL register
4. Rotate the contents of AX register left through carry by the content of CL times. Result
will be stored in AX register.
5. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE LABEL MNEMONIC

OPERAND

MOV

AX, 0AAAA

MOV

CL, 01

RCL

AX, CL

INT

7) Write an 8086 assembly language program for rotate right through


carry.
PROCEDURE:
1. Start the program
2. Move the data AAAA to AX register
3. Move the data 01 to CL register
4. Rotate the contents of AX register right through carry by the content of CL times.
Result will be stored in AX register.
5. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE LABEL

CSE III B.Tech I SEMESTER

MNEMONIC OPERAND
MOV

AX, 0AAAA

MOV

CL, 01

116

MPI

NRI Institute Of Technology


RCR

AX, CL

INT

8) Write an 8086 assembly language program for rotate left.


PROCEDURE:
1. Start the program
2. Move the data AAAA to AX register
3. Move the data 01 to CL register
4. Rotate the contents of AX register left by the content of CL times. Result will be stored
in AX register.
5. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE LABEL

MNEMONIC OPERAND
MOV

AX, 0AAAA

MOV

CL, 01

ROL

AX, CL

INT

9) Write an 8086 assembly language program for rotate right operation.


PROCEDURE:
1. Start the program
2. Move the data AAAA to AX register
3. Move the data 01 to CL register
4. Rotate the contents of AX register right by the content of CL times. Result will be
stored in AX register.
5. Stop the program by using Interrupt.
PROGRAM: -

CSE III B.Tech I SEMESTER

117

MPI

NRI Institute Of Technology


ADDRESS OPCODE LABEL

MNEMONIC OPERAND
MOV

AX, 0AAAA

MOV

CL, 01

ROR

AX, CL

INT

10) Write an 8086 assembly language program for shift arithmetic right
operation.
PROCEDURE:
1. Start the program
2. Move the data AAAA to AX register
3. Move the data 01 to CL register
4. Shift the contents of AX register right by the content of CL times. Result will be stored
in AX register.
5. Stop the program by using Interrupt.
ADDRESS OPCODE LABEL

MNEMONIC OPERAND
MOV

AX, 0AAAA

MOV

CL, 01

SAR

AX, CL

INT

11) Write an 8086 assembly language program for shift left operation.
PROCEDURE:
1. Start the program
2. Move the data AAAA to AX register
3. Move the data 01 to CL register
4. Shift the contents of AX register left by the content of CL times. Result will be stored
in AX register.
5. Stop the program by using Interrupt.

CSE III B.Tech I SEMESTER

118

MPI

NRI Institute Of Technology


PROGRAM: ADDRESS OPCODE LABEL

MNEMONIC OPERAND
MOV

AX, 0AAAA

MOV

CL, 01

SHL

AX, CL

INT

12) Write an 8086 assembly language program for rotate right


operation.
PROCEDURE:
1. Start the program
2. Move the data AAAA to AX register
3. Move the data 01 to CL register
4. Rotate the contents of AX register right by the content of CL times. Result will be
stored in AX register.
5. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE LABEL

MNEMONIC OPERAND
MOV

AX, 0AAAA

MOV

CL, 01

SHR

AX, CL

INT

13) Write an 8086 assembly language program for conversion of ASCII


to BCD.
PROCEDURE:
1. Start the program
2. Move the data 000A to CX register

CSE III B.Tech I SEMESTER

119

MPI

NRI Institute Of Technology


3. Move the data 3000 to source index
4. Move the data 4000 to destination index
5. Move the contents of source index to AX register.
6. Add 02 to SI
7. Call the subroutine below
8. Move the contents of AX to the memory location whose offset address is specified in
destination index.
9. Add 02 to destination index.
10. Decrement CX
11. Check the flag register whether zero flag is set or reset. Jump to specified memory
location if zero flag not set. Otherwise terminate the program.
Subroutine: Move data 000F to BX register.
Add the contents of BX to the contents of AX
Return to main program.
PROGRAM: ADDRESS OPCODE

LABEL

TOP:

BELOW:

CSE III B.Tech I SEMESTER

MNEMONIC OPERAND
MOV

CX,000A

MOV

SI, 3000

MOV

DI, 4000

MOV

AX, [SI]

ADD

SI, 02

CALL

BELOW

MOV

[DI], AX

ADD

DI, 02

DEC

CX

JNZ

TOP

INT

MOV

BX, 0F0F

AND

AX, BX

120

MPI

NRI Institute Of Technology


RET

14) Write an 8086 assembly language program for conversion of BCD to


ASCII.
PROCEDURE:
1. Start the program
2. Move the data 000A to CX register
3. Move the data 3000 to source index
4. Move the data 4000 to destination index
5. Move the contents of source index to AX register.
6. Add 02 to SI
7. Call the subroutine below
8. Move the contents of AX to the memory location whose offset address is specified in
destination index.
9. Add 02 to destination index.
10. Decrement CX
11. Check the flag register whether zero flag is set or reset. Jump to specified memory
location if zero flag not set. Otherwise terminate the program.
Subroutine: Move data 3030 to BX register.
OR the contents of BX to the contents of AX
Return to main program.
PROGRAM: ADDRESS OPCODE

LABEL

TOP:

CSE III B.Tech I SEMESTER

MNEMONIC OPERAND
MOV

CX, 000A

MOV

SI, 3000

MOV

DI, 4000

MOV

AX, [SI]

ADD

SI, 02

CALL

BELOW

121

MPI

NRI Institute Of Technology

BELOW:

MOV

[DI], AX

ADD

DI, 02

DEC

CX

JNZ

TOP

INT

MOV

BX, 3030

OR

AX, BX

RET

CSE III B.Tech I SEMESTER

122

MPI

NRI Institute Of Technology

2.3) Sorting and String manipulation ALPS:


1) Write an 8086 assembly language program for sort the numbers in
ascending order.
PROCEDURE:
1. Start the program
2. Move the data 2100 to DX register
3. Move the data 2102 to source index and destination index
4. Decrement DX
5. Move the contents of DX to CX
6. Move the contents of SI to AX
7. Add 02 to DI
8. Compare the contents of AX and contents of destination index
9. Jump if less than or equal to one to the specified memory location.
10. Exchange the contents of Ax and the contents of destination index.
11. Repeat from step 2 until count in the CX register is equal to zero.
12. Exchange the contents of Ax and the contents of source index.
13. Add 02 to SI
14. Move the contents of source index to destination index.
15. Decrement DX
16. Jump if not equal to specified location.
17. Stop the program by using Interrupt.
PROGRAM: ADDRESS OPCODE

LABEL

MNEMONIC OPERAND

L 3:

L2:

CSE III B.Tech I SEMESTER

123

MOV

DX, 0004

MOV

SI, 2102

MOV

DI, 2102

DEC

DX

MOV

CX, DX

MOV

AX, [SI]

ADD

DI, 02

MPI

NRI Institute Of Technology

L1:

CMP

AX, [DI]

JLE

L1

XCHG

AX, [DI]

LOOP

L2

XCHG

AX, [SI]

ADD

SI, 02

MOV

DI, SI

DEC

DX

JNE

L3

INT

2) Write an 8086 assembly language program for sort the numbers in


descending order.
PROCEDURE:
1. Start the program
2. Move the data 2100 to DX register
3. Move the data 2102 to source index and destination index
4. Decrement DX
5. Move the contents of DX to CX
6. Move the contents of SI to AX
7. Add 02 to DI
8. Compare the contents of AX and contents of destination index
9. Jump if not less than to the specified memory location.
10. Exchange the contents of Ax and the contents of destination index.
11. Repeat from step 2 until count in the CX register is equal to zero.
12. Exchange the contents of Ax and the contents of source index.
13. Add 02 to SI
14. Move the contents of source index to destination index.
15. Decrement DX
16. Jump if not equal to specified location.
17. Stop the program by using Interrupt.

CSE III B.Tech I SEMESTER

124

MPI

NRI Institute Of Technology

PROGRAM: ADDRESS OPCODE

LABEL

MNEMONIC OPERAND

L 3:

L2:

L1:

CSE III B.Tech I SEMESTER

125

MOV

DX, 0004

MOV

SI, 2102

MOV

DI, 2102

DEC

DX

MOV

CX, DX

MOV

AX, [SI]

ADD

DI, 02

CMP

AX, [DI]

JNL

L1

XCHG

AX, [DI]

LOOP

L2

XCHG

AX, [SI]

ADD

SI, 02

MOV

DI, SI

DEC

DX

JNE

L3

INT

MPI

You might also like