Sie sind auf Seite 1von 23

NRI Institute Of Technology

UNIT-II

2.1) Arithmetic instruction ALP’s

2.2) Logical instruction ALP’s

2.3) Sorting and String manipulation ALP

CSE III B.Tech I SEMESTER

103

MPI

NRI Institute Of Technology

2.1) Arithmetic instruction ALP’s:

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

3

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

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

CSE III B.Tech I SEMESTER

MNEMONIC

OPERAND

MOV

AL, 09

MOV

BL, 06

MUL

BL

AAM

INT

3

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

3

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

 

MOV

AX, 0000

MOV

BX, 3050

MOV

DX,0000

MOV

CX,0004

MOV

SI, 3000

MOV

DI,3010

 

L1:

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

CSE III B.Tech I SEMESTER

107

MPI

NRI Institute Of Technology

 

JNB

L2

INC

DX

L2:

INT

3

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

MNEMONIC

OPERAND

 

MOV

AX, 0000

MOV

BX, 3050

MOV

DX,0000

CSE III B.Tech I SEMESTER

108

MPI

NRI Institute Of Technology

 

MOV

CX,0004

MOV

SI, 3000

MOV

DI,3010

L1:

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

L2:

INT

3

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

 

MOV

BL, 00

MOV

DL, 01

MOV

CX, 0005

MOV

SI, 2600

MOV

[SI], BL

 

L1:

INC

SI

 

MOV

[SI], DL

ADD

BL, DL

XCHG

BL, DL

LOOP

L1

INT

3

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

 

MOV

SI, 2500

MOV

DI, 2600

MOV

AX, [SI]

MOV

CX, AX

DEC

CX

 

L1:

MUL

CX

 

LOOP

LI

MOV

[DI], AX

INT

3

CSE III B.Tech I SEMESTER

111

MPI

NRI Institute Of Technology

2.2) Logical instructions ALP’s:

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

3

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

3)

operation.

PROCEDURE:

Write

an

8086

1. Start the program

assembly

language

program

for

logical

AND

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

MNEMONIC

OPERAND

 

MOV

AX, 0012

MOV

BX, 0FFFF

AND

AX, BX

INT

3

CSE III B.Tech I SEMESTER

114

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

3

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

MNEMONIC

OPERAND

 

MOV

AL, 0F

MOV

BL, 00

TEST

AL, BL

INT

3

CSE III B.Tech I SEMESTER

115

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

3

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

MNEMONIC

OPERAND

 

MOV

AX, 0AAAA

MOV

CL, 01

CSE III B.Tech I SEMESTER

116

MPI

NRI Institute Of Technology

RCR

AX, CL

INT

3

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

3

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

3

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

3

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

3

12)

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

right

Write

an

8086

assembly

language

program

for

rotate

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

3

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

MNEMONIC

OPERAND

 

MOV

CX,000A

MOV

SI, 3000

MOV

DI, 4000

 

TOP:

MOV

AX, [SI]

 

ADD

SI, 02

CALL

BELOW

MOV

[DI], AX

ADD

DI, 02

DEC

CX

JNZ

TOP

INT

3

 

BELOW:

MOV

BX, 0F0F

 

AND

AX, BX

CSE III B.Tech I SEMESTER

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

MNEMONIC

OPERAND

 

MOV

CX, 000A

MOV

SI, 3000

MOV

DI, 4000

 

TOP:

MOV

AX, [SI]

 

ADD

SI, 02

CALL

BELOW

CSE III B.Tech I SEMESTER

121

MPI

NRI Institute Of Technology

BELOW:

CSE III B.Tech I SEMESTER

MOV

[DI], AX

ADD

DI, 02

DEC

CX

JNZ

TOP

INT

3

MOV

BX, 3030

OR

AX, BX

RET

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

 

MOV

DX, 0004

MOV

SI, 2102

MOV

DI, 2102

DEC

DX

 

L 3:

MOV

CX, DX

 

MOV

AX, [SI]

 

L2:

ADD

DI, 02

CSE III B.Tech I SEMESTER

123

MPI

NRI Institute Of Technology

 

CMP

AX, [DI]

JLE

L1

XCHG

AX, [DI]

L1:

LOOP

L2

XCHG

AX, [SI]

ADD

SI, 02

MOV

DI, SI

DEC

DX

JNE

L3

INT

3

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

 

MOV

DX, 0004

MOV

SI, 2102

MOV

DI, 2102

DEC

DX

 

L 3:

MOV

CX, DX

 

MOV

AX, [SI]

 

L2:

ADD

DI, 02

 

CMP

AX, [DI]

JNL

L1

XCHG

AX, [DI]

 

L1:

LOOP

L2

 

XCHG

AX, [SI]

ADD

SI, 02

MOV

DI, SI

DEC

DX

JNE

L3

INT

3

CSE III B.Tech I SEMESTER

125

MPI