Wednesday, 7 March 2012

MP & MC Programs


PROGRAM 1:      8-BIT ADDITION

   CODE SEGMENT
ASSUME CS: CODE
START:  MOV AL, 25H
                MOV BL, 12H
               ADD AL, BL
               INT 3
   CODE ENDS
END START


RESULT:

AX = 


PROGRAM 2:      8-BIT SUBTRACTION

CODE SEGMENT
ASSUME CS: CODE
START:  MOV AL, 25H
                MOV BL, 12H
               SUB AL, BL
               INT 3
   CODE ENDS
END START




RESULT:

AX =


PROGRAM 3:   8-BIT MULTIPLICATION
                                      (UNSIGNED)
CODE SEGMENT
                ASSUME CS: CODE

START:  
SUB AX, AX
SUB BX, BX
MOV AL, 09
MOV BL, 08
MUL BL
INT 3
CODE ENDS
END START 





RESULT: AX =


PROGRAM 4: 8-BIT MULTIPLICATION (SIGNED)


CODE SEGMENT
                ASSUME CS: CODE
START:  
SUB AX, AX
SUB BX, BX
MOV AL, F7    ; NEGATIVE NUMBER IN AL
MOV BL, 08
IMUL BL          ; SIGNED MULTIPLICATION
INT 3
CODE ENDS
END START 





RESULT: AX =


PROGRAM 5:     8-BIT DIVISION (SIGNED)


CODE SEGMENT
                ASSUME CS: CODE
START:  
SUB AX, AX
SUB BX, BX
MOV AL, F7    ; NEGATIVE NUMBER IN AL
MOV BL, 08
IDIV BL           ; SIGNED MULTIPLICATION
INT 3
CODE ENDS
END START 





RESULT: AX =             ; QUOTIENT IN AL
                                      ; REMAINDER IN AH


 PROGRAM 6:   8-BIT DIVISION (UNSIGNED)

CODE SEGMENT
                ASSUME CS: CODE
START:  
SUB AX, AX
SUB BX, BX
MOV AL, 09
MOV BL, 08
DIV BL
INT 3
    CODE ENDS
END START 





RESULT:
AX =                                                 ; QUOTIENT IN AL
                                                ; REMAINDER IN AH


PROGRAM 7:      16-BIT ADDITION

   CODE SEGMENT
ASSUME CS: CODE
START:  MOV AX, 2512H
                MOV BX, 1223H
               ADD AX, BX
               INT 3
   CODE ENDS
END START


RESULT:

AX = 


 PROGRAM 8:      16-BIT SUBTRACTION

CODE SEGMENT
ASSUME CS: CODE
START:  MOV AX, 2512H
                MOV BX, 1223H
               SUB AX, BX
               INT 3
   CODE ENDS
END START




RESULT:

AX =


PROGRAM 9:  16-BIT MULTIPLICATION
                                (UNSIGNED)


CODE SEGMENT
                ASSUME CS: CODE

START:  
SUB AX, AX
SUB BX, BX
SUB DX,DX
MOV AX, 1234H
MOV BX, 5678H
MUL BX
INT 3
CODE ENDS
END START 





RESULT:

AX =

DX =


PROGRAM 10:    16-BIT MULTIPLICATION   (SIGNED)



        CODE SEGMENT
                ASSUME CS: CODE

      START:SUB AX, AX
SUB BX, BX
SUB DX, DX
MOV AX, EDCCH
MOV BX, 5678H
IMUL BX
INT 3
                CODE ENDS
       END START 





RESULT:

AX =

DX =


PROGRAM 11:  16-BIT DIVISION (SIGNED)



CODE SEGMENT
                ASSUME CS: CODE

START:  
SUB AX, AX
SUB BX, BX
SUB DX, DX
MOV AX, 1234H
MOV BX, 5678H
IDIV BX
INT 3
CODE ENDS
END START




RESULT:

AX =                                                          ; QUOTIENT IN AX

DX =                                                          ; REMAINDER IN DX


PROGRAM 12:  16-BIT DIVISION (UNSIGNED)



CODE SEGMENT
                ASSUME CS: CODE

START:  
SUB AX, AX
SUB BX, BX
SUB DX, DX
MOV AX, 1234H
MOV BX, 5678H
DIV BX
INT 3
CODE ENDS
END START

RESULT:

AX =                                                          ; QUOTIENT IN AX

DX =                                                          ; REMAINDER IN DX


PROGRAM 13:  32-BIT ADDITION


DATA SEGMENT
          NUM1 DD ?
          NUM2 DD ?
           SUM  DW  4 DUP (?)
           CARRY DB   ?
DATA ENDS
CODE SEGMENT
    ASSUME CS: CODE, DS: DATA
    START: MOV AX, DATA
           MOV DS, AX
           MOV CL, 00H
           MOV AX, WORD PTR NUM1
           ADD WORD PTR NUM2
           MOV SUM+2, AX
           MOV SUM,DX
           MOV AX, WORD PTR NUM1+2
           ADC AX,  WORD PTR NUM2+2
           JNC  NOCARRY
           INC CL
 NOCARRY:  MOV SUM+6, AX
          MOV SUM+4,DX
           MOV CARRY, CL
           INT 3
CODE ENDS
END START


Result:

Input:

   
    Output:


PROGRAM 14:  32-BIT SUBTRACTION

DATA SEGMENT
          NUM1 DD  ?
          NUM2  DD  ?
           SUM DW 4 DUP (?)
           CARRY DB   ?
DATA ENDS
CODE SEGMENT
    ASSUME CS: CODE, DS: DATA
    START: MOV AX, DATA
           MOV DS, AX
           MOV CL, 00H
           MOV AX, WORD PTR NUM1
           SUB AX,WORD PTR NUM2
           MOV SUM+2, AX
           MOV SUM,DX
           MOV AX, WORD PTR NUM1+2
           SBB AX, WORD PTR NUM2+2
           JNC  NOCARRY
           INC CL
 NOCARRY:  MOV SUM+6, AX
          MOV SUM+4,DX
           MOV CARRY, CL
           INT 3
CODE ENDS
END START


Result:

Input:

   
    Output:


PROGRAM 15:  32-BIT MULTIPLICATION



 DATA SEGMENT
          NUM1 DD  ?
          NUM2 DD  ?                                                                                     
          SUM DW 4 DUP (?)
  DATA ENDS
CODE SEGMENT
    ASSUME CS: CODE, DS: DATA
    START: MOV AX, DATA
           MOV DS, AX
           MOV CL, 00H
           MOV AX, WORD PTR NUM1
           Mul WORD PTR NUM2
           MOV SUM, AX
           MOV SUM+2,DX
           MOV AX, WORD PTR NUM1+2
           Mul WORD PTR NUM2+2
           MOV SUM+4, AX
           MOV SUM+6,DX
                      INT 3
CODE ENDS
END START


Result:

Input:

   
    Output


PROGRAM 16:  32-BIT DIVISION



 DATA SEGMENT
          NUM1 DD ?
          NUM2 DW ?                                                                                      
          SUM DW 2 DUP (?)
  DATA ENDS
CODE SEGMENT
    ASSUME CS: CODE, DS: DATA
    START: MOV AX, DATA
           MOV DS, AX
           MOV AX, WORD PTR NUM1
           DIV WORD PTR NUM2
           MOV SUM, AX
           MOV SUM+2,DX
           INT 3
CODE ENDS
END START


PROGRAM 17:      MULTIBYTE ADDITION


DATA SEGMENT
NUM1 DD?
                    NUM2 DD?
                    SUM DW 2 DUP (?)
                    CARRY DB   ?
DATA ENDS
CODE SEGMENT
         ASSUME CS: CODE, DS: DATA
   START: MOV AX, DATA
           MOV DS, AX
           MOV CL, 00H
           MOV AX, WORD PTR NUM1
           ADD AX, WORD PTR NUM2
           MOV SUM, AX
           MOV AX, WORD PTR NUM1+2
           ADC AX, WORD PTR NUM2+2
           JNC NOCARRY
           INC CL
 NOCARRY:        MOV SUM+2, AX
                             MOV CARRY, CL
                             INT 3
CODE ENDS
END START

RESULT:



PROGRAM 18:      MULTIBYTE SUBTRACTION

DATA SEGMENT
NUM1 DD?
                    NUM2 DD?
          RESULT DW 2 DUP (?)
          CARRY DB   ?
DATA ENDS
CODE SEGMENT
         ASSUME CS: CODE, DS: DATA
   START: MOV AX, DATA
           MOV DS, AX
           MOV CL, 00H
           MOV AX, WORD PTR NUM1
           SUB AX, WORD PTR NUM2
           MOV RESULT, AX
           MOV AX, WORD PTR NUM1+2
           SBB AX, WORD PTR NUM2+2
           JNC NOCARRY
           INC CL
 NOCARRY:        MOV RESULT+2, AX
                             MOV CARRY, CL
                             INT 3
CODE ENDS
END START

RESULT:



PROGRAM19 : Evaluate the given signed arithmetic operation.
       Q = ((V – (X * Y + Z – 540))/ X
.DATA                                  
V DW 0640HH
X DW 0005H
Y DW 0002H
Z DW 0020H
Q DW?
R DW?
.CODE
ASSUME CS: CODE, DS: DATA
START:    MOV AX, @DATA               
                   MOV DS, AX
                   MOV AX, 0005H
MOV BX,0002H
                   IMUL BX
                   MOV CX, AX
                   MOV BX, DX
                    MOV AX, 0020H
                   CWD
                   ADD CX, AX
                   ADC BX, DX
                   SUB CX, 540H
                   SBB BX, 0
                   MOV AX, 0640H
                   CWD
                   SUB AX, CX
                   SBB DX, BX
                   IDIV X
                   MOV Q, AX
                   MOV R, DX
END START



PROGRAM 20:      ASCII   8-BIT   ADDITION
                  
CODE SEGMENT
ASSUME CS: CODE
START:
SUB AX, AX
SUB BX, BX
MOV SI, 2050
MOV AL, [SI]
INC SI
MOV BL, [SI]
ADD AL, BL      ; CHECK THE CARRY FLAG (IF THE RESULT IS EXCEED
; THE 8-BIT THEN    CARRY FLAG =1)
 AAA
INC SI
MOV [SI], AL
INT 3
CODE ENDS
END START


DATA:                                                       RESULT:


PROGRAM 21 :  ASCII   8-BIT   SUBTRACTION
                  

CODE SEGMENT
ASSUME CS: CODE
START:
SUB AX, AX
SUB BX, BX
MOV SI, 2050
MOV AL, [SI]
INC SI
MOV BL, [SI]
SUB AL, BL      ; CHECK THE CARRY FLAG (IF THE RESULT IS EXCEED
       ; THE 8-BIT THEN    CARRY FLAG =1)
 AAS
INC SI
MOV [SI], AL
INT 3
CODE ENDS
END START


DATA:                                                       RESULT:



PROGRAM 22: ASCII   8-BIT  MULTIPLICATION
                  
CODE SEGMENT
ASSUME CS: CODE
START:
SUB AX, AX
SUB BX, BX
MOV SI, 2050
MOV AL, [SI]
INC SI
MOV BL, [SI]
MUL BL     
 AAM
INC SI
MOV [SI], AL
INC SI
MOV [SI], AH    ; IF THE RESULT EXCEDD THE 8-BIT THEN
                             ; EXTRA DATA IN AH REGISTER

INT 3
CODE ENDS
END START

DATA:                                                       RESULT:


PROGRAM 23:       ASCII   8-BIT   DIVISION
                  
CODE SEGMENT

ASSUME CS: CODE
START:
SUB AX, AX
SUB BX, BX
MOV SI, 2050
MOV AL, [SI]
INC SI
MOV BL, [SI]
AAD
DIV BL
INC SI
MOV [SI], AL                          ; (QUOTIENT IN AL REGISTER)
INC SI
MOV [SI], AH                           ; (REMAINDER IN AH REGISTER)     
INT 3
CODE ENDS
END START




DATA:                                                       RESULT:


PROGRAM 24:  PRINT NO.OF POSITIVE NO'S   
                            AND NO.OF NEGATIVE NO'S

DATA SEGMENT
LIST DW 1234H, 3413H, 0FFFH,B2C3H, 3456H    
COUNT EQU 05H
POS DB?
NEG1 DB?
DATA ENDS

CODE SEGMENT

ASSUME CS: CODE, DS: DATA

 START: MOV AX, DATA
             MOV DS, AX
             MOV SI, OFFSET LIST
             MOV CX, COUNT
             MOV DX, 0000H
             MOV BX, 0000H
AGAIN: MOV AX,[SI]
             ROL AX, 1
             JC NEGE
             INC DX
              JMP NEXT

NEGE:INC BX

NEXT:ADD SI, 02
              DEC CX
              JNZ AGAIN
              MOV POS, BX
              MOV NEG1, DX
              INT 21
CODE ENDS
END START


PROGRAM 25:   PROGRAM TO COMPUTE NCR USING RECURSIVE PROCEDURE
DATA SEGMENT
             N DB ?
             R DB  ?
             NF DW ?
             RF DW ?
             RESULT  DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA  ;       INITIALIZE DATA SEGMENT
MOV DS,AX
MOV CH,00H
MOV CL,N  
CALL FACT  ;            N FACTORIAL
MOV NF,AX  ;           SAVE N FACTORIAL
MOV CL,R
CALL FACT  ;           R FACTORIAL
MOV RF,AX   ;          SAVE R FACTORIAL
MOV CL,N
SUB CL,R   ;             N-R
CALL FACT  ;         N-R FACTORIAL
MOV BX,AX   ;         SAVE N-R FACTORIAL
MOV DX,00H
MOV AX,NF
DIV BX   ;              AX=N!/(N-R)!
DIV RF   ;             AX=N!/(N-R)!R!
MOV RESULT,AX
INT 21H
FACT PROC NEAR
MOV AX,01H
BACK: MUL CX
LOOP BACK
RET
FACT    ENDP
CODE ENDS
END START


PROGRAM 26:  PACKED BCD TO UNPACKED BCD

 DATA SEGMENT
        PBCD   DB?
        UPBCD DW?

DATA ENDS

CODE SEGMENT
   
ASSUME CS: CODE, DS: DATA
   
START: MOV AX, DATA
           MOV DS, AX
           MOV AL, PBCD
           MOV BL, AL
           AND BL, 0FH
           AND AL, 0F0H
           MOV CL, 04
           ROR AL, CL
           MOV AH, AL
           MOV AL, BL
           MOV UPBCD, AX
           INT 3
         
CODE ENDS
            
END START


PROGRAM 27:  BCD TO ASCII CONVERSION

DATA SEGMENT
          BCD  DB    47H
          ASC  DW   1   DUP (?)
DATA ENDS
CODE   SEGMENT
          ASSUME CS: CODE, DS: DATA
START:
          MOV   AX, DATA
          MOV   DS, AX
          MOV   AL, BCD
          MOV   BL, AL
          AND   BL, 0FH
          AND   AL, 0F0H
          MOV   CL, O4H
          ROR   AL, CL
          MOV   AH, AL
          MOV   AL, BL
          ADD   AX, 3030H
          MOV   ASC, AX
          INT 3

CODE ENDS

END START


PROGRAM 28:   BINARY TO BCD CONVERSION

DATA SEGMENT
          BIN   DB    0FH
          BCD  DW   DUP (?)
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
          MOV AX, DATA
          MOV DS, AX
          MOV AL, BIN
          MOV AH, 00H
          MOV CX, 0000H
          MOV BL, 64H
          CMP AL, BL
          JB   NEXT
          DIV   BL
          MOV CH, AL
          MOV AL, AH
NEXT: MOV BL, 0AH
          CMP AL, BL
          DIV BL
          JB NEXT 1
          DIV BL
          MOV CL, 04H
          ROL AL, CL
          MOV CL, AL
        MOV AL, AH
NEXT 1:   ADD CL, AL
          MOV BCD, CX
          INT 3
CODE ENDS
END START


PROGRAM 29:  TO CONVERT 2 BCD NUMBERS TO HEXA DECIMAL NUMBER

DATA SEGMENT
          BCD  DB    52H
          HEX DW    DUP (?)
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
                MOV AX, DATA
                MOV DS, AX
                MOV AL, BCD
                MOV BL,AL
                AND AL, #0F
                MOV BH,AL
                MOV CL,#04
                ROR   BL,CL
                AND BL,#0F
                MOV AL,#OA
                MUL BL
               ADD AL,BH
                INT3
CODE ENDS
END START


PROGRAM 30:  TO CONVERT  HEXA DECIMAL NUMBER  TO BCD

DATA SEGMENT
          HEX  DB    8FH
          BCD  DW   DUP (?)
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, HEX
MOV BL,#64
DIV BL
MOV CH,AL
MOV AL,AH
MOV AH,#00
MOV BL,#0A
DIV BL
XCHG AL,#0A
MOV CL,#04
ROL AH,CL
AND AH,#0F0
OR AL,AH
MOV AH,CH
INT03

               
CODE ENDS
END START


PROGRAM 31:  TO CONVERT A NUMBER FROM   BINARY TO GRAY CODE

DATA SEGMENT
          BIN   DB    8FH
          GRAY DW DUP (?)
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV CX,#000F
MOV DI, BIN
STD
ET:   MOV AL,CL
MOV DL, AL
AND DL,#80
MOV BL, AL
MOV AH, #00
ADD AX, AX
XOR BL,AL
SHR BL,01
OR BL,DL
STOSB
LOOP ET
INT 3
CODE ENDS
END START


PROGRAM 32:  TO CONVERT A NUMBER FROM   GRAY CODE TO BINARY CODE


DATA SEGMENT
          HEX  DB    8FH
          BCD  DW   DUP (?)
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
                MOV AX, DATA
                MOV DS, AX
                MOV AL, HEX
                MOV CX,#08

               MOV BL,AL
              AND BL,#80
       L1: SHR BL,01
              XOR BL,AL
             LOOP L1
             INT 03
       CODE ENDS
        END START


PROGRAM 33:  PROGRAM TO SHIFT THE GIVEN NUMBER TO LEFT

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, #34
               MOV DS, AX
               MOV CX, 04
               SHL AX, CX
              INT 03

CODE ENDS
END START

PROGRAM 34:  PROGRAM TO SHIFT THE GIVEN NUMBER TO ARITHEMETIC RIGHT

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, #34
               MOV DS, AX
               MOV CX, 04
               SAR AX, CX
              INT 03

CODE ENDS
END START


PROGRAM 35:  PROGRAM TO SHIFT THE GIVEN NUMBER TO  RIGHT

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, #34
               MOV DS, AX
               MOV CX, 04
               SHR AX, CX
              INT 03

CODE ENDS
END START




PROGRAM 36:  PROGRAM TO ROTATE  THE GIVEN NUMBER TO  LEFT

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, #34
               MOV DS, AX
               MOV CX, 04
               ROL AX, CX
              INT 03

CODE ENDS
END START


PROGRAM 37:  PROGRAM TO ROTATE  THE GIVEN NUMBER TO  RIGHT

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, #34
               MOV DS, AX
               MOV CX, 04
               ROR AX, CX
              INT 03

CODE ENDS
END START



PROGRAM 38:  PROGRAM TO ROTATE  THE GIVEN NUMBER TO  LEFT
WITH CARRY

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, #34
               MOV DS, AX
               MOV CX, 04
               RLC AX, CX
              INT 03

CODE ENDS
END START


PROGRAM 39:  PROGRAM TO ROTATE  THE GIVEN NUMBER TO  RIGHT
WITH CARRY

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, #34
               MOV DS, AX
               MOV CX, 04
               RRC AX, CX
              INT 03

CODE ENDS
END START


PROGRAM 40:
PROGRAM TO KNOW PALINDROME  OF THE STRING

DATA SEGMENT
          STR1 DB "CARRY","$"
          STR2 DB 6 DUP(0)
        STR3 DB "PALINDROME",'$'
          STR4 DB " NOT A PALINDROME",'$'
DATA ENDS

CODE SEGMENT

ASSUME CS: CODE,DS:DATA

START: MOV AX,DATA

              MOV DS,AX
              MOV ES,AX

              MOV SI,OFFSET STR1
              MOV DI,OFFSET STR2
              ADD DI,04H

              MOV CX,05H
BACK: MOV AL,[SI]
              MOV [DI],AL

              INC SI
             DEC DI

             LOOP BACK
            ADD DI,05H

            MOV AL,'$'
            MOV [DI],AL

            MOV SI,OFFSET STR1
            MOV DI, OFFSET STR2
          MOV CX,05H    
           CLD

          REPE   CMPSB           
          JNZ LAL2   

          MOV AH, 09H
          MOV DX, OFFSET STR3
                  
          INT 21H

          JMP LLL3

LAL2:  MOV AH, 09H

             MOV DX, OFFSET STR4
                  
             INT 21H

LLL3:   MOV AH, 4CH
            INT 21H

CODE ENDS
END START


PROGRAM 41: MOVE STRING OF DATA FROM ONE MEMORY LOCATION TO OTHER MEMORY LOCATION

DATA SEGMENT
          SRCSTR EQU 2000H
          DESTSTR EQU 3000H
        COUNT EQU 0FH
DATA ENDS
CODE SEGMENT
          ASSUME CS: CODE, DS: DATA
   START: MOV AX, DATA
          MOV DS, AX
          MOV ES, AX
          MOV SI, SRCSTR
          MOV DI, DESTSTR
          MOV CX, COUNT
          CLD
    REP   MOVSW
               INT 3

CODE ENDS

END START


DATA SEGMENT
STR DB 01H, 05H, 06H, 07H
COUNT EQU 02H
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV CL,COUNT
MOV SI,OFFSET STR
MOV DI, 0003H
BACK:MOV AL,[SI]
XCHG [DI],AL
MOV [SI],AL
INC SI
DEC DI
DEC CL
JNZ BACK
MOV AH, 4CH
INT 21H

CODE ENDS
END START


PROGRAM 42:  STRING INSERTION
DATA SEGMENT
STRING1 DB 'EMPTY VESSELS MORE NOISE$'
STRLEN EQU ($-STRING1)
DATA ENDS
EXTRA SEGMENT
STRING2 DB STRLEN+5 DUP(0)
EXTRA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START: MOV AX,DATA
         MOV DS,AX
         MOV SI,OFFSET STRING1
         MOV DI,OFFSET STRING2
         CLD
         MOV CX,14
         REP MOVSB
         MOV DL,5
BACK: MOV AH,01
          INT 21H

       STOS STRING2
        DEC DL
        JNZ BACK
        MOV CX,11
        REP MOVSB
        NOP
          MOV AH,4CH
          INT 21H
    CODE ENDS
    END START


PROGRAM 43:  STRING DELETION

DATASEGMENT
STRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$'
STRLEN EQU ($-STRING1)
DATA ENDS
EXTRA SEGMENT
STRING2 DB STRLEN-5 DUP(0)
EXTRA ENDS
CODE SEGMENT.
ASSUME CS:CODE,DS:DATA,ES:EXTRA
                  START: MOV AX,DATA
                                      MOV DS,AX
                                      MOV AX,EXTRA
                                      MOV ES,AX
                                      MOV SI,OFFSET STRING1
                                      MOV DI,OFFSET STRING2
                                      CLD
                                      MOV CX,13
                                      REP MOVSB
                                      CLD
                                      MOV SI,18
                                      MOV CX,12
                                      REP MOVSB
                                      MOV AH,4CH
                                      INT 21H
                             CODE ENDS
                             END START


PROGRAM 44:  LENGTH OF THE STRING
DATA SEGMENT
STR DB 10H,11H,12H,07H,05H,09H,20H
LENGTH DB?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, 00H
MOV CL, 00H
MOV SI, OFFSET STR
BACK: CMP AL,[SI]
JNC GO
INC CL
INC SI
JNZ BACK
GO: MOV LENGTH, CL
MOV AH, 4CH
INT 21H

CODE ENDS

END START


PROGRAM 45:  STRING COMPARISION
DATA SEGMENT
STRING1 DB 'EMPTY'
STRLEN EQU ($-STRING1)
NOTSFUL DB 'STRINGS ARE UNEQUAL$'
SFUL DB 'STRINGS ARE EQUAL$'
DATA ENDS
EXTRA SEGMENT
STRING2 DB 'EMPTY'
EXTRA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START: MOV AX,DATA
MOV DS,AX                                   
MOV AX,EXTRA
MOV ES,AX
MOV SI,OFFSET STRING1
MOV DI,OFFSET STRING2
CLD
MOV CX,LENGTH STRING1
MOV CX,STRLEN
REP CMPSB
JZ FORW
MOV AH,09H
MOV DX,OFFSET NOTSFUL
INT 21H
JMP EXITP
FORW:MOV AH,09H
          MOV DX,OFFSET SFUL
          INT 21H
EXITP: NOP
          MOV AH,4CH
          INT 21H
        CODE ENDS END START

END START


PROGRAM 46:  ASCENDING ORDER
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
               START: MOV SI, 1000H
                   MOV DI, 1100H
                   MOV CX, 09
                   REP MOVSB
                   MOV DX, 07
  P1:       MOV DI, 1100H
                   MOV CX, 07
 P2:        MOV AL, [DI]
                   CMP AL, [DI+1]
                   JBE P3
                   XCHG AL, [DI+1]
                   XCHG [DI], AL
  P3:       INC DI
                   LOOP P2
                   DEC DX
                   JNZ P1
                   INT 3

CODE ENDS

END START


PROGRAM 47:  DESCENDING ORDER
CODE SEGMENT
ASSUME CS: CODE
START: MOV SI, 1000H
                   MOV DI, 1100H
                   MOV CX, 09
                   REP MOVSB
                   MOV DX, 07
    P1:     MOV DI, 1100H
                   MOV CX, 07
    P2:     MOV AL, [DI]
                   CMP AL, [DI+1]
                   JAE P3
                   XCHG AL, [DI+1]
                   XCHG [DI], AL
     P3:    INC DI
                   LOOP P2
                   DEC DX
                   JNZ P1
                   INT 3

CODE ENDS
END START


PROGRAM 48:  FIND NO.OF EVEN NO’S AND   NO.OF ODD NO’S
DATA SEGMENT
LIST DW 1234H, 5678H, 9ABCH, 0DEF1H, 23245H
COUNT EQU 05H
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
                   MOV DS, AX
                   MOV SI, OFFSET LIST
                   MOV CX, COUNT
       BACK: MOV AX, [SI]
                   ROR AX, 1
                   JC ODD
                   INC DX
                   JMP NEXT
          ODD:          INC BX
        NEXT: ADD SI, 02
                   DEC CX
                   JNZ BACK
                   INT 3
CODE ENDS
END START


PROGRAM 49: DISPLAY THE STRING
DATA SEGMENT
MESSAGE DB 10, 13,’KITE COLLEGES’, 10, 13,’$’
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
      START: MOV AX, DATA
                   MOV DS, AX
                   MOV DX, OFFSET MESSAGE
                   MOV AH, 09H
                   INT 21H
                   MOV AX, 4C00H
                   INT 21H
CODE ENDS
END START







No comments:

Post a Comment

Home