0% found this document useful (0 votes)
81 views32 pages

Microprocessor Lab Mnual

The document contains 6 programs for reversing blocks of data in memory. Program 5 uses a dummy block to reverse the data block by copying bytes from the end of the source block to the destination block. Program 6 reverses the block in place by exchanging the first and last bytes, then decrementing the pointers towards the middle.

Uploaded by

Yogeesha G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views32 pages

Microprocessor Lab Mnual

The document contains 6 programs for reversing blocks of data in memory. Program 5 uses a dummy block to reverse the data block by copying bytes from the end of the source block to the destination block. Program 6 reverses the block in place by exchanging the first and last bytes, then decrementing the pointers towards the middle.

Uploaded by

Yogeesha G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 32

DATA TRANSFER GROUP PROGRAMS

1. program to load all registers with data 1000

LABEL MNEMONICS COMMENTS


MOV AX,1000 Mov the data 1000 to AX reg
MOV BX,AX Copy the data from AX to BX reg
MOV CX,AX Copy the data from AX to CX reg
MOV DX,AX Copy the data from AX to DX reg
MOV SI,AX Copy the data from AX to SI reg
MOV DI,AX Copy the data from AX to DI reg
MOV SP,AX Copy the data from AX to SP reg
MOV BP,AX Copy the data from AX to BP reg
INT 3 end

2. Program for block transfer without overlapping.

LABEL MNEMONICS COMMENTS


MOV SI,2000 Pointer to source block
MOV DI,3000 Pointer to destination block
MOV CX,N Length of blocks as counter
BACK: MOV AL,[SI] Get data byte from source pointer
MOV [DI],AL Store it in destination location
INC SI Increment source block
INC DI Increment destination block
LOOP BACK Repeat till the counter is 00
INT3 End

3. Program for block transfer with overlapping blocks

LABEL MNEMONICS COMMENTS


MOV CX,08 Initialize counter to block length
MOV SI,2000 Get source starting address in SI
MOV DI,2002 Get destination starting address in DI
CMP SI,DI Compare source start with destination start
JC BOTTOM Is C = 1? If yes go to bottom transfer
DIRECT: MOV AL,[SI] If no start transfer from top
MOV [DI],AL Get data byte from source and store in destination
INC SI Increment SI register
INC DI Increment DI register
LOOP DIRECT Repeat till the counter is 00
INT3 End
BOTTOM: ADD SI,CX Add count to SI
DEC SI Decrement SI to point to the last location
ADD DI,CX Add count to DI
DEC DI Decrement DI to point to the last location
REPEAT: MOV AL,[SI] Get data byte from source
MOV [DI],AL Store it in destination
DEC SI Decrement source pointer
DEC DI Decrement destination pointer
LOOP REPEAT Repeat till the counter is 00
INT3 end

4. Program to interchange two blocks of memory data.

LABEL MNEMONICS COMMENTS


MOV CL,06 CL as counter for length of blocks
MOV SI,2000 Pointer to one block
MOV DI,3000 Pointer to another block
BACK: MOV AL,[SI] Get data byte from SI pointer to AL
XCHG [DI],AL Exchange AL contents with DI pointer
MOV [SI],AL Store it in SI pointer location
INC SI Increment source pointer
INC DI Increment destination pointer
DEC CL Decrement counter
JNZ BACK Repeat exchange if counter ≠ 00
INT3 End

5. Program to reverse a block of data byte using dummy block.

LABEL MNEMONICS COMMENTS


MOV SI,2000 Pointer to block of data
MOV DI,3000 Pointer to store reversed data
MOV CL,06 Block length as counter
ADD SI,CX Add SI to CX
DEC SI Decrement SI to point to the last location
BACK: MOV AL,[SI] Get data from source block
MOV [DI],AL Store it in destination pointer
INC DI Destination pointer is incremented
DEC SI Decrement source pointer
LOOP BACK Repeat transfer
INT3 end

6. Program to reverse a block of data byte at the source memory without using
dummy block.

LABEL MNEMONICS COMMENTS


MOV CL,N Counter for block length
MOV DL,02
MOV AH,00
MOV AL,CL
DIV DL Divide count by 2
MOV SI,200 Pointer to memory location
MOV DI,SI Copy it to DI
ADD DI,CX
DEC DI Point to the last location
BACK: MOV BL,[SI] Get first byte in BL
XCHG BL,[SI] Exchange it with the last byte
MOV [SI],BL
INC SI Increment SI pointer
DEC DI Decrement DI pointer
DEC AL Decrement counter
JNZ BACK Repeat till the counter becomes 00
INT 3 End

3. ARITHMETIC AND LOGICAL GROUP PROGRAMS

A. ADDITION PROGRAMS

1. Program to add two 16-Bit binary numbers assuming data is in registers

LABEL MNEMONICS COMMENTS


MOV CL,00 Clear CL to hold carry after addition
MOV AX,2222
MOV BX,3333
ADD AX,BX
JNB STOP
INC CL
STOP: INT 3

2. Program to add two 16-Bit binary numbers assuming data is in memory

LABEL MNEMONICS COMMENTS


MOV CL,00
MOV SI,2000
MOV AX,[SI]
MOV DX,[SI+02]
ADD AX,DX
JNB STOP
MOV CL,01
STOP: INT 3

3. Program to add two n – byte binary number

LABEL MNEMONICS COMMENTS


CLC
MOV SI,2000
MOV DI,3000
MOV BP,4000
MOV CL,04
BACK: MOV AL,[SI]
ADC AL,[DI]
MOV [BP],AL
INC SI
INC DI
INC BP
DEC CL
JNZ BACK
JNB STOP
MOV CL,01
MOV [BP],CL
STOP: INT 3

4. Program to add n –bit binary numbers

LABEL MNEMONICS COMMENTS


CLC
MOV CX,04
MOV BH,00
MOV AX,0000
MOV SI,2000
BACK: ADD AX,[SI]
JNB NEXT
INC BH
NEXT: ADD SI,+02
LOOP BACK
INT 3

5. Program to add n – 8 bit BCD numbers stored from 2000H

LABEL MNEMONICS COMMENTS


MOV AX,0000
MOV SI,2000
MOV CL,04
BACK: ADD AL,[SI]
DAA
JNC NEXT
XCHG AL,AH
ADD AL,01
DAA
XCHG AL,AH
NEXT: INC SI
DEC CL
JNZ BACK
INT 3
6. Program to add two 16 - bit BCD numbers

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV DI,3000
CLC
MOV AL,[SI]
ADD AL,[DI]
DAA
XCHG AL,AH
MOV AL,[SI+01]
ADC AL,[DI+01]
DAA
XCHG AL,AH
INT 3

7. Program to add two n-byte BCD numbers

LABEL MNEMONICS COMMENTS


CLC
MOV CL,04
MOV SI,2000
MOV DI,3000
MOV BP,4000
PUSH F
BACK: POP F
MOV AL,[SI]
ADC AL,[DI]
DAA
MOV [BP+00],AL
INC SI
INC DI
INC BP
XCHG AL,CL
PUSH F
ADD AL,99
DAA
XCHG AL,CL
JNZ BACK
INT 3

8. Program to add a set of 8 bit binary numbers. The array of numbers is


terminated by 00.

LABEL MNEMONICS COMMENTS


MOV AX,0000
MOV SI,2000
MOV CX,0000
LOOP: MOV BL,[SI]
CMP BL,000
JZ END
ADD AL,BL
JNB BELOW
INC AH
BELOW: INC SI
INC CX
JMP LOOP
END: INT 3

B. SUBTRACTION PROGRAMS
9. Program to perform 8 bit binary subtraction using 1’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV BL,[SI+1]
NOT BL
ADD AL,BL
JNC NEXT
ADD AL,01
NEXT: MOV [SI+2],AL
INT 3

10. Program to perform16 bit binary subtraction using 1’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AX,[SI]
MOV BX,[SI+2]
NOT BX
ADD AX,BX
JNC NEXT
ADD AX,01
NEXT: MOV [SI+4],AX
INT 3

11. Program to perform 8 bit binary subtraction using 2’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV BL,[SI+1]
NEG BL
ADD AL,BL
MOV [SI+2],AL
INT 3
12. Program to perform16 bit binary subtraction using 2’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AX,[SI]
MOV BX,[SI+2]
NEG BX
ADD AX,BX
MOV [SI+4],AX
INT 3

13. Program to perform 8 bit BCD subtraction using 9’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV BL,[SI+1]
MOV CL,99
SUB CL,BL
ADD AL,CL
DAA
JNC NEXT
ADD AL,01
DAA
NEXT: MOV [SI+2],AL
INT 3

14. Program to perform 16 bit BCD subtraction using 9’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AX,[SI]
MOV BX,[SI+2]
MOV CX,9999
SUB CX,BX
ADD AL,CL
DAA
XCHG AH,AL
ADC AL,CH
DAA
XCHG AH,AL
JNC NEXT
ADD AL,01
DAA
XCHG AH,AL
ADC AL,00
DAA
XCHG AH,AL
NEXT: MOV [SI+4],AX
INT 3

15. Program to perform 8 bit BCD subtraction using 10’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV BL,[SI+1]
MOV CL,99
SUB CL,BL
ADD AL,CL
DAA
ADD AL,01
DAA
MOV [SI+2],AL
NEXT: INT 3

16. Program to perform 16 bit BCD subtraction using 10’s complement method

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AX,[SI]
MOV BX,[SI+2]
MOV CX,9999
SUB CX,BX
ADD AL,CL
DAA
XCHG AH,AL
ADC AL,CH
DAA
XCHG AH,AL
ADD AL,01
DAA
XCHG AH,AL
ADC AL,00
DAA
XCHG AH,AL
MOV [SI+4],AX
NEXT: INT 3

17. Program to perform 8 bit BCD subtraction

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV BL,[SI+1]
SUB AL,BL
DAS
MOV [SI+2],AL
INT 3

18. Program to perform 16 bit BCD subtraction

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AX,[SI]
MOV BX,[SI+2]
SUB AL,BL
DAS
XCHG AL,AH
SBB AL,BH
DAS
XCHG AL,AH
MOV [SI+4],AX
INT 3

19. Program to subtract one N – byte number from another N – byte number

LABEL MNEMONICS COMMENTS


CLC
MOV CX,[500]
MOV SI,2000
MOV DI,3000
MOV BP,4000
BACK: MOV AL,[SI]
SBB AL,[DI]
MOV [BP],AL
INC SI
INC DI
INC BP
LOOP BACK
INT 3

C. MULTIPLICATION PROGRAMS

20. Program to multiply two 8bit signed binary numbers

LABEL MNEMONICS COMMENTS


MOV AL,N1
MOV BL,N2
IMUL BL
INT 3

21. Program to multiply two 16bit signed binary numbers

LABEL MNEMONICS COMMENTS


MOV AX,N1
MOV BX,N2
IMUL BX
INT 3

22. Program to multiply two 8bit unsigned binary numbers

LABEL MNEMONICS COMMENTS


MOV AL,12
MOV BL,21
MUL BL
INT 3

23. Program to multiply two 16bit unsigned binary numbers

LABEL MNEMONICS COMMENTS


MOV AX,1111
MOV BX,2222
MUL BX
INT 3

24. Program to multiply two 8bit BCD numbers

LABEL MNEMONICS COMMENTS


CLC
MOV AX,0000
MOV SI,0200
MOV BL,[SI]
MOV CL,[SI+01]
BACK: ADD AL,BL
DAA
XCHG AL,AH
ADC AL,00
DAA
XCHG AL,AH
XCHG AL,CL
ADD AL,99
DAA
XCHG AL,CL
JNZ BACK
MOV [SI+02],AX
INT 3

25. Program to multiply two 16 bit BCD numbers

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOC DI,3000
CLC
MOV AX,0000
MOV DX,0000
MOV BX,[SI]
MOV CX,[DI]
BACK: ADD AL,BL
DAA
XCHG AL,AH
ADC AL,BH
DAA
XCHG AL,AH
JNC NEXT
XCHG AX,DX
ADC AL,00
DAA
XCHG AL,AH
ADC AL,00
DAA
XCHG AL,AH
XCHG AX,DX
NEXT: XCHG AX,CX
ADD AL,99
DAA
XCHG AL,AH
ADC AL,99
DAA
XCHG AL,AH
XCHG AX,CX
CMP CX,00
JNZ BACK
MOV [SI+2],AX
MOV [SI+4],DX
INT 3

26. Program to multiply two 32 bit binary numbers

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOC DI,3000
MOV BP,5000
MOV AX,[SI]
MOV BX,[DI]
MUL BX
MOV [BP],AX
BACK: MOV CX,DX
MOV AX,[SI+2]
MOV BX,[DI]
MUL BX
ADD CX,AX
ADC DX,00
PUSH DX
MOV AX,[SI]
MOV BX,[DI+2]
MUL BX
ADD CX,AX
POP AX
ADC AX,DXMOV
[BP+2],CX
PUSH AX
NEXT: MOV CX,00
ADC CX,00
MOV AX,[SI+2]
MOV BX,[DI+2]
MUL BX
POP BX
ADD AX,BX
ADC DX,CX
MOV [BP+4],AX
MOV [BP+6],DX
INT 3

D. DIVISION PROGRAMS

27. Program to divide a 8 bit/ 8 bit unsigned binary numbers

LABEL MNEMONICS COMMENTS


MOV AL,16
MOV AH,00
MOV BL,04
DIV BL
INT 3

28. Program to divide a 16bit/ 8 bit unsigned binary numbers

LABEL MNEMONICS COMMENTS


MOV AX,1512
MOV CL,62
DIV CL
INT 3

29. Program to divide a 8 bit/ 8 bit signed binary numbers

LABEL MNEMONICS COMMENTS


MOV AL,no.1
CBW
MOV CL, no.2
IDIV CL
INT 3

30. Program to divide a 16 bit/ 16 bit signed binary numbers

LABEL MNEMONICS COMMENTS


MOV AX,no.1
CBD
MOV BX, no.2
IDIV BX
INT 3

31. Program to divide a 32 bit/ 16 bit signed binary numbers

LABEL MNEMONICS COMMENTS


MOV SI,3000
MOV AX,[SI]
MOV DX,[SI+2]
MOV BX, [SI+4]
DIV BX
INT 3

E. OTHER PROGRAMS

32. Program to find HCF of two 8 bit binary numbers

LABEL MNEMONICS COMMENTS


MOV AL,34
MOV BL,16
MOV AH,00
DIV BL
CMP AH,00
JZ END
MOV AL,BL
MOV BL,AH
JMP LOOP
END: INT 3

33. Program to find LCM of two 8 bit binary numbers

LABEL MNEMONICS COMMENTS


MOV AL,09
MOV BL,03
MOV CL,AL
MOV BH,AL
LOOP: MOV AH,00
DIV BL
CMP AH,00
JZ FOUND
ADD BH,CL
MOV AL,BH
JMP LOOP
FOUND: INT 3

34. Program to find square root of two 8 bit binary numbers


LABEL MNEMONICS COMMENTS
MOV BL,19
MOV BH,01
BACK: CALL SQR
CMP BL,AL
JZ FOUND
JC FOUND
INC BH
JMP BACK
FOUND: INT 3
SQR: MOV AL,BH
MUL BH
RET

35. Program to find cube root of two 8 bit binary numbers

LABEL MNEMONICS COMMENTS


MOV BL,08
MOV BH,01
BACK: CALL CUBE
CMP BL,AL
JZ FOUND
JC FOUND
INC BH
JMP BACK
FOUND: INT 3
CUBE: MOV AL,BH
MUL BH
MUL BH
RET

36. Program to find factorial of an 8 bit binary numbers

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV AH,00
MOV BL,AL
DEC BL
FACT: MOV CX,0000
MOV BH,BL
LOOP: ADD CX,AX
DEC BH
JNZ LOOP
XCHG AX,CX
DEC BL
JNZ FACT
INC SI
MOV[SI],AX
INT 3

37. Program to implement BCD counter on the monitor

LABEL MNEMONICS COMMENTS


MOV BX,0000
REPEAT: MOV AX,BX
AAM
ADD AX,3030
PUSH AX
MOV DL,AH
MOV AH,02
INT 21
POP AX
MOV DL,AL
MOV AH,02
INT 21
MOV DL,0D
MOV AH,02
INT 21
MOV CX,01FF
BACK: PUSH CX
MOV CX,FFFF
HERE: LOOP HERE
POP CX
LOOP BACK
INC BX
CMP BX,64
JNZ REPEAT
INT3

38. Program to convert 8 bit binary number to ASCII

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
CMP AL,09
JC SMALL
ADD AL,37
INT 3
SMALL: ADD AL,30
INT 3

39. Program to convert 8 bit ASCII to binary

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
CMP AL,40
JC SMALL
SUB AL,37
JMP LAST
SMALL: SUB AL,30
LAST: INC SI
MOC [SI],AL
INT 3

40. Program to convert 8 bit BCD number into binary number

LABEL MNEMONICS COMMENTS


MOV BL,00
MOV CL,04
MOV SI,2000
MOV AL,[SI]
AND AL,F0
ROL AL,CL
CMP AL,00
JZ NEXT
BACK: ADD BL,0A
DEC AL
JNZ BACK
NEXT: MOV AL,[SI]
AND AL,0F
ADD AL,BL
INT 3

41. Program to convert 8 bit binary number to BCD number

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV BX,FFFF
BACK: INC BL
SUB AL,64
JNC BACK
ADD AL,64
LOOP: INC BH
SUB AL,0A
JNC LOOP
ADD AL,0A
MOV CL,04
ROR BH,CL
ADD AL,BH
MOV [SI+1],AL
MOV [SI+2],BL
INT 3
42. Program to convert 16 bit binary number to BCD number

LABEL MNEMONICS COMMENTS


MOV AX,0FFF
MOV CX,FFFF
MOV BX,FFFF
NEXT: INC CH
SUB AX,2710
JNC NEXT
ADD AX,2710
BACK1: INC CL
SUB AX,3E8
JNC BACK1
ADD AX,3E8
BACK2: INC BH
SUB AX,64
JNC BACK2
ADD AX,64
BACK3: INC BL
SUB AX,0A
JNC BACK3
ADD AX,0A
MOV DL,CL
MOV CL,04
ROR DL,CL
ADD BH,DL
ROR BL,CL
ADD BL,AL
MOV [2000],BL
MOV [2000+1],BH
MOV [2000+2],CH
INT 3

43. Program to convert 16 bit BCD number to binary number

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AX,[SI]
MOV DX,0000
MOV BX,AX
AND BH,F0
MOV CL,04
ROR BH,CL
CMP BH,00
JZ NEXT
LOOP1: ADD DX,3E8
DEC BH
JNZ LOOP1
NEXT: AND AH,0F
CMP AH,00
JZ NEXT1
LOOP2: ADD DX,64
DEC AH
JNZ LOOP2
NEXT1: AND BL,F0
ROR BL,CL
CMP BL,00
JZ NEXT2
LOOP3: ADD DX,0A
DEC BL
JNZ LOOP3
NEXT2: AND AL,0F
ADD DX,AL
INT 3

44. Program to convert packed 2 – digit BCD to ASCII

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
AND AL,0F
MOV BL,[SI]
AND BL,F0
MOV CL,04
ROR BL,CL
ADD AL,30
ADD BL,30
INT 3

45. Program to convert packed 2 – digit BCD to ASCII

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOV BL,[SI+1]
SUB AL,30
SUB BL,30
MOV CL,04
ROR BL,CL
ADD AL,BL
INT 3

4. BIT MANIPULATION GROUP PROGRAMS

1. Program to count number of 1’s and 0’s of given 8bit


LABEL MNEMONICS COMMENTS
MOV SI,2000
MOV AL,[SI]
MOC CX,08
MOV BX,00
BACK: ROR AL,1
JC ONE
INC BL
JMP NEXT
ONE: INC BH
NEXT: LOOP BACK
INC SI
MOV [SI],BL
INC SI
MOV [SI],BH
INT 3

2. Program to count number of 1’s and 0’s in 16 bit binary number.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOC CX,10h
MOV BX,00
BACK: ROR AL,1
JC ONE
INC BL
JMP NEXT
ONE: INC BH
NEXT: LOOP BACK
INC SI
INC SI
MOV [SI],BL
INC SI
MOV [SI],BH
INT 3

3. Program to check whether an 8 bit binary number is 2 out of 5 code or not.

LABEL MNEMONICS COMMENTS


MOV AL,00
MOV BL,[2000]
MOV CX,05
TEST BL,0E
JNZ FALSE
BACK: SHR BL,1
JNC NEXT
INC AL
NEXT: LOOP BACK
CMP AL,02
JNZ FALSE
MOV AL,00
INT 3
FALSE: MOV AL,FF
INT3

4. Program to check whether an 8 bit binary number is nibble wise palindrome


or not.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOC CH,FF
MOV CL,04
ROR AL,CL
CMP AL,[SI]
JNZ NOT-PAL
INC CH
NOT-PAL: INC SI
MOV [SI],CH
INT 3

5. Program to check whether 16 bit binary number is byte wise palindrome or


not.

LABEL MNEMONICS COMMENTS


CLC
MOV CH,00
MOV SI,2000
MOV AL,[SI+1]
MOV CL,04
ROR AL,CL
CMP AL,[SI]
JNZ NOT-PAL
DEC CH
NOT-PAL: MOV [SI+2],CH
INT 3

6. Program to check whether an 8 bit binary number is bit wise palindrome or


not.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
MOC CH,00
MOV CL,08
MOV BL,00
BACK: ROR AL,1
RCRBL,1
DEC CL
JNZ BACK
CMP BL,[SI]
JZ VALID
DEC CH
VALID: INC SI
MOV [SI],CH
INT 3

7. Program to check whether 16 bit binary number is bit wise palindrome or


not.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV DL,00
MOV AX,[SI]
MOC BX,00
MOV CX,10h
BACK: ROL AX,1
RCR BX,1
LOOP BACK
CMP BX,[SI]
JZ PAL
DEC DL
VALID: INC SI
MOV [SI],DL
INT 3

8. Program to verify that a given 8 bit binary number is prime or not.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV AL,[SI]
CMP AL,00
JZ ILLEGAL
CMP AL,01
JZ ILLEGAL
CMP AL,02
JZ PRIME
CMP AL,03
JZ PRIME
MOV BL,02
MOV AH,00
DIV BL
MOV BH,AL
INC BH
CMP AH,00
JZ NOTPRIME
LOOP1: MOV AL,[SI]
INC BL
MOV AH,00
DIV BL
CMP AH,00
JZ NOTPRIME
CMP BH,BL
JNZ LOOP1
INC SI
PRIME: MOV CH,00
INT 3
INC SI
NOTPRIME: MOV CH,FF
INT 3
ILLEGAL: MOV CH,AA
INT 3

SORTING GROUP PROGRAMS

1. Program to count odd and even numbers in an array of numbers.

LABEL MNEMONICS COMMENTS


MOV CX,06
MOV SI,2000
MOV AL,00
MOV BL,00
BACK: MOV DL,[SI]
SHR DL,1
JNC EVEN
INC BL
JMP NEXT
EVEN: INC AL
NEXT: INC SI
LOOP BACK
INT 3

2. Program to count positive and negative numbers in an array of numbers.

LABEL MNEMONICS COMMENTS


MOV CX,8
MOV SI,2000
MOV AL,00
MOV BL,00
BACK: MOV DL,[SI]
SHL DL,1
JNC POSITIVE
INC BL
JMP NEXT
EVEN: INC AL
NEXT: INC SI
LOOP BACK
INT 3

3. Program to find nth smallest number.

LABEL MNEMONICS COMMENTS


MOV BH,00
MOV AL,00
BACK1: MOV CL,0A
MOV SI,2000
BACK2: CMP AL,[SI]
JZ NEXT1
NEXT: INC SI
DEC CL
JNZ BACK2
INC AL
JMP BACK1
NEXT1: MOV CH,FF
MOV [SI],CH
INC BH
CMP BH,3
JNZ NEXT
MOV [400],AL
INT 3

4. Program to find nth largest number.

LABEL MNEMONICS COMMENTS


MOV BH,00
MOV AL,FF
BACK1: MOV CL,0A
MOV SI,2000
BACK2: CMP AL,[SI]
JZ LOOP
NEXT: INC SI
DEC CL
JNZ BACK2
DEC AL
JMP BACK1
LOOP: MOV CH,00
MOV [SI],CH
INC BH
CMP BH,6
JNZ NEXT
MOV [400],AL
INT 3
5. Program to arrange numbers in ascending order.

LABEL MNEMONICS COMMENTS


MOV CL,9 ************
LOOP: MOV BL,8
MOV SI,2000
BACK: MOV AL,[SI]
INC SI
CMP AL,[SI]
JC NEXT
XCHG AL,[SI]
DEC SI
MOV [SI],AL
INC SI
NEXT: DEC BL
JNZ BACK
DEC CL
JNZ LOOP
INT 3

6. Program to arrange numbers in descending order.

LABEL MNEMONICS COMMENTS


MOV CL,9 ***************************
LOOP: MOV BL,8
MOV SI,2000
BACK: MOV AL,[SI]
INC SI
CMP AL,[SI]
JNC NEXT
XCHG AL,[SI]
DEC SI
MOV [SI],AL
INC SI
NEXT: DEC BL
JNZ BACK
DEC CL
JNZ LOOP
INT 3

7. Program to generate FIBBONACCI series.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV CL,9
MOV BL,00
MOV AL,01
DEC CL
INC SI
MOV [SI],AL
DEC CL
BACK: INC SI
MOV CH,AL
ADD AL,BL
MOV [SI],AL
MOV BL,CH
DEC CL
JNZ BACK
INT 3

8. Program to generate prime numbers.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV CL,05
MOV CH,03
MOV [SI],CH
INC CH
DEC CL
JZ STOP
NEXT NO: INC CH
MOV BL,02
MOV AL,CH
MOV AH,00
DIV BL
MOV BH,AL
INC BH
CMP AH,00
JZ NEXT NO
REPEAT: MOV AL,CH
MOV AH,00
INC BL
DIV BL
CMP AH,00
JZ NEXT NO
CMP BH,BL
JNZ REPEAT
INC SI
MOV [SI],CH
DEC CL
JNZ NEXT NO
STOP: INT 3

STRING GROUP PROGRAMS

1. Program to find the length of the string with out using string instructions.
LABEL MNEMONICS COMMENTS
MOV SI,2000
MOV CL,00
BACK: MOV AL,[SI]
CMP AL,24
JZ NEXT
INC CL
INC SI
JMP BACK
NEXT: MOV [300],CL
INT 3

2. Program to find the number of vowels in a string with out using string
instructions.

LABEL MNEMONICS COMMENTS


MOV SI,2000
MOV CL,05
MOV DL,00
BACK1: MOV CH,0A
MOV DI,400
MOV AL,[SI]
BACK: CMP AL,[DI]
JZ NEXT
INC DL
NEXT: INC DI
DEC CH
JNZ BACK
INC SI
DEC CL
JNZ BACK1
MOV [301],DL
INT 3

3. Program to find the length of the string using string instructions.

LABEL MNEMONICS COMMENTS


CLD
MOV DI,2000
MOV AL,24
MOV CX,FFFF
REPNZ SCASB
NOT CX
DEC CX
MOV [300],CX
INT 3

4. Program to find the number of vowels in a string using string instructions.


LABEL MNEMONICS COMMENTS
MOV SI,2000
MOV DL,00
MOV CL,09
BACK1: MOV DI,400
CLD
MOV CH,0A
LODSB
BACK: SCASB
JNZ NEXT
INC DL
NEXT: DEC CH
JNZ BACK
DEC CL
JNZ BACK1
MOV [500],DL
INT 3

5. Program to convert uppercase string to lowercase string.

LABEL MNEMONICS COMMENTS


CLD
MOV DI,3000
MOV SI,2000
MOV CX,0005
BACK: LODSB
CMP AL,5B
JNB BELOW
ADD AL,20
BELOW: STOSB
LOOP BACK
INT 3

6. Program to convert lowercase string to uppercase string.

LABEL MNEMONICS COMMENTS


CLD
MOV SI,2000
MOV DI,3000
MOV CX,0007
BACK: LODSB
CMP AL,5B
JB BELOW
SUB AL,20
BELOW: STOSB
LOOP BACK
INT 3
7. Program to count number of occurrences of a particular character.

LABEL MNEMONICS COMMENTS


CLD
MOV BL,00
MOV DI,0300
MOV CX,0005
MOV SI,2000
MOV AL,[SI]
BACK: SCASB
JNZ BELOW
INC BL
BELOW: LOOP BACK
INT 3

8. Program to count number of words in a string.

LABEL MNEMONICS COMMENTS


CLD
MOV CX,30
MOV DI,300
MOV AL,20
MOV AH,01
BACK: SCASB
JNZ NEXT
INC AH
NEXT: LOOP BACK
MOV [400],AH
INT 3

9. Program to replace a character by another.

LABEL MNEMONICS COMMENTS


CLD
MOV DI,300
MOV CX,0006
MOV SI,200
MOV AL,[SI]
BACK: SCASB
JNZ NEXT
MOV BL,[SI+01]
MOV [DI-01],BL
NEXT: LOOP BACK
INT 3
10. Program to find whether the given string is palindrome or not.

LABEL MNEMONICS COMMENTS


MOV BL,00
MOV SI,200
MOV DI,SI
MOV CX,0006
ADD DI,CX
DEC DI
SHR CX,01
BACK: CLD
LODSB
STD
SCASB
JNZ BELOW
LOOP BACK
INT 3
BELOW: DEC BL
INT 3
11. Program to reverse the given string.

LABEL MNEMONICS COMMENTS


MOV CX,0006
MOV SI,2000
MOV DI,3000
ADD DI,CX
DEC DI
BACK: CLD
LODSB
STD
STOSB
LOOP BACK
INT 3

INT 21h DOS INTERRUPT ROUTINES

1. Program to read a character from the keyboard.

LABEL MNEMONICS COMMENTS


MOV AH,01
INT 21h
INT 3

2. Buffered keyboard input [To read string of characters from keyboard].

LABEL MNEMONICS COMMENTS


MOV DX,300
MOV AH,0A
INT 21h
INT 3

3. Program to display a character on the console.

LABEL MNEMONICS COMMENTS


MOV DL,41
MOV AH,02
INT 21h
INT 3

4. Program to display string on the console.

LABEL MNEMONICS COMMENTS


MOV DX,200
MOV AH,09
INT 21h
INT 3

5. Program to print a character on the printer.

LABEL MNEMONICS COMMENTS


MOV DL,41
MOV AH,05
INT 21h
INT 3

6. Program to read a data byte from the keyboard.

LABEL MNEMONICS COMMENTS


MOV CL,04
MOV AH,01
INT 21h
CMP AL,40
JC NEXT
SUB AL,07
NEXT: SUB AL,30
ROL AL,CL
MOV BH,AL
MOV AH,01
INT 21
CMP AL,40
JC NEXT1
SUB AL,07
NEXT1: SUB AL,30
OR AL,BH
INT3

7. Program to read system time.


LABEL MNEMONICS COMMENTS
MOV AH,2Ch
INT 21h
INT 3

8. Program to read system date.

LABEL MNEMONICS COMMENTS


MOV AH,2Ah
INT 21h
INT 3

9. Program to set system time.

LABEL MNEMONICS COMMENTS


MOV AH,2Dh
MOV CH,12
MOV CL,20
MOV DH,52
MOV DL,052
INT 21h
INT 3

10. Program to set system date.

LABEL MNEMONICS COMMENTS


MOV AH,2Bh
MOV CX,06
MOV DH,10
MOV DL,29
INT 21h
INT 3

11. Program to create a file.

LABEL MNEMONICS COMMENTS


MOV CX,00
MOV DX,200
MOV AH,3C
INT 21h
INT 3

12. Program to write into a file.

LABEL MNEMONICS COMMENTS


MOV AX,3D02h
MOV DX,200
INT 21h
MOV BX,AX
MOV AH,40
MOV CX,8
MOV DX,300
INT 21h
MOV AH,3E
INT 21h
INT 3

13. Program to read from a file.

LABEL MNEMONICS COMMENTS


MOV AX,3D02h
MOV DX,200
INT 21h
MOV BX,AX
MOV AH,3F
MOV CX,8
MOV DX,500
INT 21h
MOV AH,3E
INT 21h
INT 3

You might also like