Sei sulla pagina 1di 35

PROGRAME CODE :

TITLE Displaying a simple text


.MODEL SMALL
.STACK 100h
.DATA
MSG DB 13,10, " Audisankara College of Engineering & Technology
(ASCET) $"
.CODE
MOV AX,@DATA

; Get address of data segment

MOV DS,AX

; Store address in DS register

MOV AH, 09H

; displays a string

LEA DX, MSG

; msg is loaded to DX register

INT 21H

; Call to DOS

MOV AH,4CH

; Terminates the

INT 21H

; process from DOS.

END

PROGRAME CODE :
TITLE Finding that whether the given no. is even or odd
PRINT MACRO MSG
MOV AH, 09H
; displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
ST1 DB 13,10, " Enter a number : $"
ST2 DB 13,10, " Given number is even $"
ST3 DB 13,10, " Given number is odd $"
N DB 0
.CODE
MOV AX,@DATA
; Get address of data segment
MOV DS,AX
; Store address in DS register
PRINT ST1
;Printing first msg
MOV CL,10
; Move 10 to CL
READ:
; reading number
MOV AH, 01H
; reads a character
INT 21H
; call DOS
CMP AL,13
JE NEXT
MOV BL,AL
; Move AL to BL
MOV AL,N
; Move N to AL
MUL CL
; Multiply CL with AL
ADD AL,BL
; Move BL to AL
MOV N,AL
; Move AL to N
MOV AH, 01H
INT 21H
JMP READ
; Jump to READ lable
NEXT:
MOV AL,N
MOV BL,2
DIV BL
CMP AH,00
JE LAST
PRINT ST3
JMP CLOSE
LAST:
PRINT ST2
CLOSE:
MOV AH,4CH
INT 21H
END

; BL <- 2
; Is remainder in AH is equal to 0
; If so, goto next
; Goto last
; Call PRINT macro for ST2
; Request to end program execution
; Exit to DOS

PROGRAME CODE :
TITLE Addition of two numbers
PRINT MACRO MSG
MOV AH, 09H
; displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 10,13," Enter the first no : $"
MSG2 DB 10,13," Enter the second no : $"
ST2 DB 10,13," Division = $"
ST4 db " Not Possible (Dinominator > Numarator) $"
ST3 DB 10,13," You must enter numbers only $"
NUM DW ?
.CODE
MAIN PROC NEAR
MOV AX,@DATA
; Get address of data segment
MOV DS,AX
; Store address in DS register
PRINT MSG1
; Call PRINT macro for msg1
CALL READ
; Call READ procedure
MOV NUM,BX
PRINT MSG2
; Call PRINT macro for msg2
CALL READ
; Call READ procedure
PRINT ST2
XOR DX,DX
; Clear DX register
MOV AX,NUM
CMP AX,BX
JL LAST
DIV BX
CALL PNUM
JMP EXIT
LAST:
PRINT ST4
EXIT:
MOV AH,4CH
INT 21H
MAIN ENDP
READ PROC NEAR
XOR BX,BX
MOV AH,01H

; Compare AX & BX
; If less go to LAST
; Divide AX by BX
; Call PNUM procedure

; Request to end process


; Call for DOS

; Clear BX register
; Read a character

INT 21H
LOOP1:
CMP AL,13
JE NEXT
CMP AL,'0'
JNGE CLOSE
CMP AL,'9'
JNLE CLOSE
AND AX,000FH
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP LOOP1
NEXT:
RET
CLOSE:
PRINT ST3
MOV AH,4CH
INT 21H
READ ENDP
PNUM PROC NEAR
MOV CX,0000H
MOV BX,10
GOUT:
MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE GOUT
POUT:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP POUT
RET
PNUM ENDP
END

; Call for DOS


; Compare AL and 13
; if equal jump to NEXT
; Compare AL and '0'
; if equal jump to CLOSE
; Compare AL and '9'
; if equal jump to CLOSE
; Get the number in to AX
; Move AX to stack
; Multiply AX with BX
; Stack BX

; Go to Loop1
; Call return to MAIN procedure

; Clear CX register

; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX

; Request to print a character


; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Substraction of two numbers
PRINT MACRO MSG
MOV AH, 09H
; displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 10,13," Enter the first no : $"
MSG2 DB 10,13," Enter the second no : $"
ST1 DB 10,13," Substraction = $"
ST2 DB 10,13," You must enter numbers only $"
ST3 DB "-Ve Answer $"
NUM DW ?
.CODE
MAIN PROC NEAR
MOV AX,@DATA
; Get address of data segment
MOV DS,AX
; Store address in DS register
PRINT MSG1
; Call PRINT macro for msg1
CALL READ
; Call READ procedure
MOV NUM,BX
PRINT MSG2
; Call PRINT macro for msg2
CALL READ
; Call READ procedure
PRINT ST1
MOV AX,NUM
CMP AX,BX
JL NOUT
SUB AX,BX
; Substracte BX from AX
CALL PNUM
; Call PNUM procedure
JMP QUIT
NOUT:
PRINT ST3
QUIT:
MOV AH,4CH
; Request to end process
INT 21H
; Call for DOS
MAIN ENDP
READ PROC NEAR
XOR BX,BX
; Clear BX register
MOV AH,01H
; Read a character
INT 21H
; Call for DOS

LOOP1:
CMP AL,13
JE NEXT
CMP AL,'0'
JNGE CLOSE
CMP AL,'9'
JNLE CLOSE
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP LOOP1
NEXT:
RET
CLOSE:
PRINT ST3
MOV AH,4CH
INT 21H
READ ENDP
PNUM PROC NEAR
MOV CX,0000H
MOV BX,10
GOUT:
MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE GOUT
POUT:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP POUT
RET
PNUM ENDP
END

; Compare AL and 13
; if equal jump to NEXT
; Compare AL and '0'
; if equal jump to CLOSE
; Compare AL and '9'
; Get the number in to AX
; Move AX to stack
; Multiply AX with BX
; Stack BX

; Go to Loop1
; Call return to MAIN procedure

; Clear CX register

; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX

; Request to print a character


; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Multiplication of two numbers
PRINT MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM

; displays a string
; msg is loaded to DX register
; exit to DOS

.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 10,13," Enter the first no : $"
MSG2 DB 10,13," Enter the second no : $"
ST1 DB 10,13," Multiplication = $"
ST2 DB 10,13," You must enter numbers only $"
NUM DW ?
.CODE
MAIN PROC NEAR
MOV AX,@DATA
; Get address of data segment
MOV DS,AX
; Store address in DS register
PRINT MSG1
CALL READ
MOV NUM,BX

; Call PRINT macro for msg1


; Call READ procedure

PRINT MSG2
CALL READ
PRINT ST1
MOV AX,NUM
MUL BX
CALL PNUM
JMP QUIT
QUIT:
MOV AH,4CH
INT 21H
MAIN ENDP
READ PROC NEAR
XOR BX,BX
MOV AH,01H
INT 21H
LOOP1:
CMP AL,13
JE NEXT

; Call PRINT macro for msg2


; Call READ procedure

; Multiply AX with BX
; Call PNUM procedure

; Request to end process


; Call for DOS

; Clear BX register
; Read a character
; Call for DOS
Compare AL and 13
; if equal jump to NEXT

CMP AL,'0'
JNGE CLOSE
CMP AL,'9'
JNLE CLOSE
AND AX,000FH
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP LOOP1
NEXT:
RET
CLOSE:
PRINT ST3
MOV AH,4CH
INT 21H
READ ENDP
PNUM PROC NEAR
MOV CX,0000H
MOV BX,10
GOUT:
MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE GOUT
POUT:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP POUT
RET
PNUM ENDP
END

; Compare AL and '0'


; if equal jump to CLOSE
; Compare AL and '9'
; if equal jump to CLOSE
; Get the number in to AX
; Move AX to stack
; Multiply AX with BX
; Stack BX

; Go to Loop1
; Call return to MAIN procedure

; Clear CX register

; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX

; Request to print a character


; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Division of two numbers
PRINT MACRO MSG
MOV AH, 09H
; displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 10,13," Enter the first no : $"
MSG2 DB 10,13," Enter the second no : $"
ST2 DB 10,13," Division = $"
ST4 db " Not Possible (Dinominator > Numarator) $"
ST3 DB 10,13," You must enter numbers only $"
NUM DW ?
.CODE
MAIN PROC NEAR
MOV AX,@DATA
; Get address of data segment
MOV DS,AX
; Store address in DS register
PRINT MSG1
CALL READ
MOV NUM,BX
PRINT MSG2
CALL READ
PRINT ST2
XOR DX,DX
MOV AX,NUM
CMP AX,BX
JL LAST
DIV BX
CALL PNUM
JMP EXIT
LAST:
PRINT ST4
EXIT:
MOV AH,4CH
INT 21H
MAIN ENDP
READ PROC NEAR

; Call PRINT macro for msg1


; Call READ procedure

; Call PRINT macro for msg2


; Call READ procedure
; Clear DX register
; Compare AX & BX
; If less go to LAST
; Divide AX by BX
; Call PNUM procedure

; Request to end process


; Call for DOS

XOR BX,BX
MOV AH,01H
INT 21H
LOOP1:
CMP AL,13
JE NEXT
CMP AL,'0'
JNGE CLOSE
CMP AL,'9'
JNLE CLOSE
AND AX,000FH
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP LOOP1
NEXT:
RET
CLOSE:
PRINT ST3
MOV AH,4CH
INT 21H
READ ENDP
PNUM PROC NEAR
MOV CX,0000H
MOV BX,10
GOUT:
MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE GOUT
POUT:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP POUT
RET
PNUM ENDP
END

; Clear BX register
; Read a character
; Call for DOS
; Compare AL and 13
; if equal jump to NEXT
; Compare AL and '0'
; if equal jump to CLOSE
; Compare AL and '9'
; if equal jump to CLOSE
; Get the number in to AX
; Move AX to stack
; Multiply AX with BX
; Stack BX

; Go to Loop1
; Call return to MAIN procedure

; Clear CX register

; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX

; Request to print a character


; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Finding the Factorial of the given number
PRINT MACRO MSG
MOV AH, 09H
; displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
ST1 DB 10,13," Enter a number : $"
ST2 DB 10,13," Factorial Value = $"
ST3 DB 10,13," You must enter numbers only $"
ST4 DB "1 $"
.CODE
MAIN PROC NEAR
MOV AX,@DATA
; Get address of data segment
MOV DS,AX
; Store address in DS register
PRINT ST1
; Call PRINT macro for ST1
MOV AH,01H
; Read a character
INT 21H
; Call for DOS
CMP AL,'0'
JNGE LAST
CMP AL,'9'
JNLE LAST
SUB AL,30H
MOV CL,AL
PRINT ST2
CMP CL,0
JE ONE
MOV AX,0001H
FACT:
MUL CX
LOOP FACT
CALL PNUM
JMP EXIT
ONE:
PRINT ST4
JMP EXIT
LAST:
PRINT ST3
EXIT:
MOV AH,4CH

; Compare AL and '0'


; if equal jump to LAST
; Compare AL and '9'
; if equal jump toLAST
; Sustract 48 from al
; Move AL to CL
; Compare CL with 0
; If equal go to ONE
; AX 1
; Multiply AX with CX
; Do the loop up to CX=0
; Call PNUM procedure

; Request to end process

INT 21H
MAIN ENDP
PNUM PROC NEAR
MOV CX,0000H
MOV BX,10
GOUT:
MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE GOUT
POUT:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP POUT
RET
PNUM ENDP
END

; Call for DOS

; Clear CX register

; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX

; Request to print a character


; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Print the Fibonacci series up to the given number
PRINT MACRO MSG
MOV AH, 09H
; displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
ST1 DB 10,13," Enter the value (>2) : $"
ST2 DB 10,13," Series = $"
ST3 DB " 0 1$"
SPC DB " $"
NUM DW ?
VAL DW ?
NO DW ?
.CODE
MAIN PROC NEAR
MOV AX,@DATA
MOV DS,AX
PRINT ST1
CALL READ
PRINT ST2
MOV NUM,BX
MOV NO,0
MOV VAL,1
CMP NUM,2
JLE EXIT
SUB NUM,2
PRINT ST3
SERIS:
PRINT SPC
XOR AX,AX
XOR BX,BX
MOV AX,VAL
ADD AX,NO
MOV BX,VAL
MOV NO,BX
MOV VAL,AX
CALL PNUM
MOV BX,VAL
CMP BX,NUM
JNGE SERIS
EXIT:
MOV AH,4CH
INT 21H

; Get address of data segment


; Store address in DS register
; Call PRINT macro for ST1
; Call READ procedure
; NUM BX
; NO 0
; VAL 1
; Compare NUM with 2
; If less than or equal go to EXIT
; Substract 2 from NUM
; Call PRINT for space
; Clear AX
; Clear BX
; AX VAL
; Add NO to AX
; BX VAL
; NO BX
; VAL AX
; BX VAL
; Compare BX with NUM
; If no greater or equal goto SERIS
; Request to end process
; Call for DOS

MAIN ENDP
READ PROC NEAR
XOR BX,BX
MOV AH,01H
INT 21H

; Clear BX register
; Read a character
; Call for DOS

GET:
CMP AL,13
JE NEXT
CMP AL,'0'
JNGE CLOSE
CMP AL,'9'
JNLE CLOSE
AND AX,000FH
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP GET
NEXT:
RET
CLOSE:
MOV AH,4CH
INT 21H
READ ENDP
PNUM PROC NEAR
MOV CX,0000H
MOV BX,10
OPUT:
MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE OPUT
SHOW:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP SHOW
RET
PNUM ENDP
END

; Compare AL and 13
; if equal jump to NEXT
; Compare AL and '0'
; if equal jump to CLOSE
; Compare AL and '9'
; if equal jump to CLOSE
; Get the number in to AX
; Move AX to stack
; Multiply AX with BX
; Stack BX

; Go to GET
; Call return to MAIN procedure

; Clear CX register
; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX
; Request to print a character
; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Print the sum of n natural numbers
DISP MACRO MSG
; Macro for message printing
MOV AH, 09H
; displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 13,10," Enter the natural number : $"
MSG2 DB 13,10," Sum of natural numbers = $"
N DW ?
.CODE
MAIN PROC NEAR
MOV AX,@DATA
; Read the data part
MOV DS,AX
; in to DS register.
DISP MSG1
CALL RNUM
MOV N,BX
DISP MSG2
XOR AX,AX
MOV CX,N
SUM:
ADD AX,CX
LOOP SUM
CALL PNUM
MOV AH,4CH
INT 21H
MAIN ENDP
RNUM PROC NEAR
XOR BX,BX
MOV AH,01H
INT 21H
READ:
CMP AL,13
JE NEXT
CMP AL,'0'
JNGE QUIT

; To read the number

; Clear AX register
; CX N
; Add CX to AX
; Do the loop SUM up to CX = 0
; To print the number
; Request an end to execution
; Call dos

; Compare that is end of the num


; Compare that is >=0

CMP AL,'9'
JNLE QUIT
AND AX,000FH
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP READ
NEXT:
RET
QUIT:
MOV AH,4CH
INT 21H
RNUM ENDP
PNUM PROC NEAR
MOV CX,0000H
MOV BX,10
GETN:
MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE GETN
PUTN:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP PUTN
RET
PNUM ENDP
END

; Compare that is <=9

; To get the number


; Move it to stack
; Multiply AX with BX
; Stack BX
; reads a single character
; call DOS

; Call return to MAIN procedure

; Clear CX register
; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX
; Request to print a character
; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Printing biggest of given two numbers
SHOW MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM

; Macro for message printing


; Displays a string
; msg is loaded to DX register
; Exit to DOS

.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 13,10," Enter 1st number : $"
MSG2 DB 13,10," Enter 2nd number : $"
MSG3 DB 13,10," First number is biggest $"
MSG4 DB 13,10," Second number is biggest $"
NUM DW ?
.CODE
BIGGEST PROC NEAR
MOV AX,@DATA
; Read the data part
MOV DS,AX
; in to DS register.
SHOW MSG1
CALL READ_NUM
MOV NUM,BX

; Call SHOW macro forMSG1


; Call READ_NUM procedure
; NUM BX

SHOW MSG2
CALL READ_NUM
CMP NUM,BX
JG FIRST
SHOW MSG4
JMP EXIT
FIRST:
SHOW MSG3
EXIT:
MOV AH,4CH
INT 21H
BIGGEST ENDP

; Call SHOW macro for MSG2


; Call READ_NUM procedure
; Compare NUM with BX
; If greater go to FIRST
; Call SHOW macro for MSG4

READ_NUM PROC NEAR


XOR BX,BX
MOV AH,01H
INT 21H
GETW:

; Call SHOW macro for MSG3


; Request an end to execution
; Call dos

CMP AL,13
JE NEXT

; Compare that is end of the num

CMP AL,'0'
JNGE CLOSE
CMP AL,'9'
JNLE CLOSE

; Compare that is >=0

AND AX,000FH
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP GETW
NEXT:
RET
CLOSE:
MOV AH,4CH
INT 21H
READ_NUM ENDP
END

; Compare that is <=9

; To get the number


; Move it to stack
; Multiply AX with BX
; Stack BX
; reads a single character
; call DOS

; Call return to BIGGEST procedure

PROGRAME CODE :
TITLE Printing the lengthof a string
SHOW MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM
.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 13,10," Enter the string : $"
MSG2 DB 13,10," String length = $"
S1 DB 20 DUP('$')
.CODE
MAIN PROC NEAR
MOV AX,@DATA
MOV DS,AX
SHOW MSG1
LEA SI,S1
XOR CX,CX
NEXT:
INC SI
MOV AH,01H
INT 21H
INC CX
MOV [SI],AL
CMP AL,13
JNE NEXT
SHOW MSG2
SUB CX,1
MOV AX,CX
CALL PRINT_NUM
MOV AH,4CH
INT 21H
MAIN ENDP
PRINT_NUM PROC NEAR
MOV CX,0000H
MOV BX,10
OPUT:

; Macro for message printing


; Displays a string
; msg is loaded to DX register
; Exit to DOS

; Read the data part


; in to DS register.
; Call SHOW macro for msg1
; Load s1 to SI register

; increment SI (points first pos of array)


; Function to read single character
; And store in in AL
; Move AL into location of SI
; Is char not end of string
; If so, goto NEXT
; Substract 1 from CX
; CX AX
; Request an end to execution
; Call dos

; Clear CX register

MOV DX,0000H
DIV BX
PUSH DX
INC CX
OR AX,AX
JNE OPUT
GPUT:
MOV AH,02H
POP DX
OR DL,30H
INT 21H
LOOP GPUT
RET
PRINT_NUM ENDP
END

; Clear DX register
; Divide AX by BX
; Move DX to stack
; Increase CX
; Do OR to before & After AX
; Request to print a character
; stack to DX
; get the character
; Do the loop up to CX=0
; Call return to MAIN procedure

PROGRAME CODE :
TITLE Printing a string in given no.of times
DISP MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM

; Macro for message printing


; Displays a string
; msg is loaded to DX register
; Exit to DOS

.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 13,10," Enter ther string : $"
MSG2 DB 13,10," Enter the no.of times : $"
MSG3 DB 13,10," Result is $"
LINE DB 13,10," $"
FSTR LABEL BYTE
MAX DB 20
ACT DB 0
INFO DB 20 DUP('$')
.CODE
STRING PROC NEAR
MOV AX,@DATA
MOV DS,AX
DISP MSG1
MOV AH,0AH
LEA DX,FSTR
INT 21H

; Read the data part


; in to DS register.
; Call DISP macro for MSG1
; Request to read the string
; Load the string variable to DX
; Call for DOS

DISP MSG2
CALL READ
MOV CX,BX
DISP MSG3
RESULT:
DISP LINE
DISP INFO
LOOP RESULT

; Call DISP macro for MSG1


; Call READ procedure
; CX BX
; Call DISP macro for MSG1

MOV AH,4CH
INT 21H
STRING ENDP

; Request an end to execution


; Call dos

READ PROC NEAR


XOR BX,BX

; Call DISP macro for LINE


; Call DISP macro for INFO

; Clear BX register

MOV AH,01H
INT 21H
GETW:
CMP AL,13
JE NEXT
CMP AL,'0'
JNGE CLOSE
CMP AL,'9'
JNLE CLOSE
PUSH AX
MOV AX,10
MUL BX
POP BX
ADD BX,AX
MOV AH,01H
INT 21H
JMP GETW
NEXT:
RET
CLOSE:
MOV AH,4CH
INT 21H
READ ENDP
END

; Read a character
; Call for DOS
; Compare AL and 13
; if equal jump to NEXT
; Compare AL and '0'
; if equal jump to CLOSE
; Compare AL and '9'
; Get the number in to AX
; Move AX to stack
; Multiply AX with BX
; Stack BX

; Go to GETW
; Call return to MAIN procedure

PROGRAME CODE :
TITLE To check whether the given string is palindrome or not.
OUTPUT MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM

; Macro for message printing


; Displays a string
; msg is loaded to DX register
; Exit to DOS

.MODEL SMALL
.STACK 100H
.DATA
ST1 DB 13,10," Enter the string : $"
ST3 DB 13,10," Given string is not pollindrome $"
ST2 DB 13,10," Given string is pollindrome $"
CHAR LABEL BYTE
MAX DB 20
ACT DB 0
S DB 20 DUP('$')

; Declaring the string valriable


; Maximum length
; Actual length
; String array

.CODE
STRING PROC NEAR
MOV AX,@DATA
MOV DS,AX

; Read the data part


; in to DS register.

OUTPUT MSG1
MOV AH,0AH
LEA DX,CHAR
INT 21H
XOR AX,AX
XOR BX,BX

; Call OUTPUT macro for MSG1


; Request to read the string
; Load the string variable to DX
; Call for DOS
; Clear AX
; Clear AX

LEA SI,S
LEA DI,S
MOV CH,00H
MOV CL,ACT

; Load the string variable to SI


; Load the string variable to si
; Clear CH
; CL Actual length of string

LOOP1:
INC DI
LOOP LOOP1
MOV AL,ACT
MOV BL,02H
DIV BL
MOV CL,AL

; Increase DI
; Do the loop up to CL = 0
; AL Actual length of string
; BL 2
; Divide AL by BL
; CL AL

DEC DI
MOV AL,[SI]

; Decrease DI
; AL Location of SI

CMP AL,[DI]
JE CHECK
JMP NOTPOL

; Compare AL & Location of SI


; If equal go to CHECK
; else go to NOTPOL

CHECK:
INC SI
DEC DI
MOV AL,[SI]
CMP AL,[DI]
JNE NOTPOL
LOOP CHECK
CMP CL,0
JNE NOTPOL
OUTPUT ST2
JMP EXIT
NOTPOL:
OUTPUT ST3
EXIT:
MOV AH,4CH
INT 21H
STRING ENDP
END

; Increase SI
; Decrease DI
; AL Location of SI
; Compare AL & Location of SI
; If no equal go to NOTPOL
; Do the loop up to CHECK
; Compare CL with 0
; Call OUTPUT macro for ST2

; Call OUTPUT macro for ST2


; Request to end the execution
; Call dos

PROGRAME CODE :
TITLE To find the 2s complement of given number
OUTPUT MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM

; Macro for message printing


; Displays a string
; msg is loaded to DX register
; Exit to DOS

.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 13,10," Enter a digit : $"
MSG2 DB 13,10," 2's Complement value : $"
.CODE
TWOSCOMP PROC
MOV AX,@DATA
MOV DS,AX

; Read the data part


; in to DS register

OUTPUT MSG1
MOV AH,01H
INT 21H

; Call OUTPUT macro for MSG1


; Read a character

SUB AL,30H
NOT AL
ADD AL,00000001b
MOV BL,AL
MOV CL,8

; To get the number


; 1's complement
; Add 1 in 8-bit binary form
; BL AL
; CL 8

OUTPUT MSG2
XOR DX,DX
CHANGE:
RCL BL,01H
carry
ADC DX,30H
MOV AH,02H
INT 21H
XOR DX,DX
LOOP CHANGE
MOV AH,4CH
INT 21H
TWOSCOMP ENDP

; Call OUTPUT macro for MSG1


; Clear DX
; Rotate 1-bit to left side & stores
; Add 48 to DX with carry
; Prints one character
; Call for DOS
; Do the loop up to CX = 0
; Request to end the process
; Call for DOS

END

PROGRAME CODE :
TITLE Concatinate two strings
SHOW MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM
.MODEL SMALL
.STACK 64
.DATA
MSG1 DB 13,10," Enter 1st string : $"
MSG2 DB 13,10," Enter 2nd string : $"
MSG3 DB 13,10," Concatinated string : $"
LINE DB 13,10," $"
FSTR LABEL BYTE
MAX1 DB 20
ACT1 DB 0
STR1 DB 20 DUP('$')
SSTR LABEL BYTE
MAX1 DB 20
ACT1 DB 0
STR1 DB 20 DUP('$')
RES DB 40 DUP('$')
.CODE
MOV AX,@DATA
MOV DS,AX

; Macro for message printing


; Displays a string
; msg is loaded to DX register
; Exit to DOS

; Declaring the string valriable


; Maximum length1
; Actual length1
; String array1
; Declaring the string valriable
; Maximum length2
; Actual length2
; String array2
; Read the data part
; in to DS register.

SHOW MSG1
MOV AH,0AH
LEA DX,FSTR
INT 21H

; Call SHOW macro for MSG1


; Request to read the string
; Load the string variable to DX
; Call for DOS

SHOW MSG2
MOV AH,0AH
LEA DX,SSTR
INT 21H

; Call SHOW macro for MSG2


; Request to read the string
; Load the string variable to DX
; Call for DOS

LEA SI,STR1
LEA DI,RES
MOV CH,00H
MOV CL,ACT1
FIRST:

; Load the string variable to SI


; Load the Result string to DI
; Clear CH
; CL First strings Actual length

MOV AL,[SI]
MOV [DI],AL
INC SI
INC DI
LOOP FIRST

LEA SI,STR2
MOV CH,00H
MOV CL,ACT1
NEXT:
MOV AL,[SI]
MOV [DI],AL
INC SI
INC DI
LOOP NEXT
SHOW MSG3
SHOW RES
MOV AH,4CH
INT 21H
END

; Move location of SI into AL


; Is char not end of string
; Increase SI
; Increase DI
; Do the loop up to CL = 0

; Load the string variable to SI


; Clear CH
; CL First strings Actual length
; Move location of SI into AL
; Is char not end of string
; Increase SI
; Increase DI
; Do the loop up to CL = 0
; Call SHOW macro for MSG3
; Call SHOW macro for RES
; Request an end to execution
; Call dos

PROGRAME CODE :
TITLE Find the product of two 4-bit binary numbers & print th result in 8-bit
SHOW MACRO MSG
; Macro for message printing
MOV AH, 09H
; Displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; Exit to DOS
ENDM
.MODEL SMALL
.STACK 100H
.DATA
S1 DB 13,10," Enter 1st number in 4-bit form = $"
S2 DB 13,10," Enter 2nd number in 4-bit form = $"
S3 DB 13,10," Product of two numbers = $"
NUM DB 0
.CODE
BINMUL PROC NEAR
MOV AX,@DATA
; Read the data part
MOV DS,AX
; in to DS register.
SHOW S1
CALL GETIN
MOV NUM,BL

; Call SHOW macro for S1


; Call GETIN procedure
; NUM BL

SHOW S2
CALL GETIN

; Call SHOW macro for S2


; Call GETIN procedure

SHOW S3
MOV AL,NUM
MUL BL
MOV BL,AL
CALL RESULT

; Call SHOW macro for S3


; AL NUM
; Multiply AL with BL
; BL AL
; Call RESULT procedure

MOV AH,4CH
INT 21H
BINMUL ENDP
GETIN PROC NEAR
XOR BL,BL
MOV CL,04H
LOOP1:
MOV AH,01H
INT 21H

; End the process


; Call for DOS

; Clear BL
; CL 4
; Read a Character

SUB AL,30H
SHL BL,1

ADD BL,AL
LOOP LOOP1
RET
GETIN ENDP
RESULT PROC NEAR
MOV CL,08H
LOOP2:
MOV AH,02H
MOV DL,00H
RCL BL,01H
carry
ADC DX,30H
INT 21H
LOOP LOOP2
RET
RESULT ENDP
END

; Substracte 48 from AL
; Do left shift to BL one time

; Add AL to BL
; Do the loop up to CL = 0
; Call return to BINMUL procedure

; CL 8
; Print the character
; DL 0
; Rotate 1-bit to left side & stores
; Add 48 to DX with carry
; Do the loop untill CL = 0
; Call BINMUL procedure

PROGRAME CODE :
TITLE Find the sum of two 4-bit binary numbers & print th result in 8-bit
PRINT MACRO MSG
; Macro for message printing
MOV AH, 09H
; Displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; Exit to DOS
ENDM
.MODEL SMALL
.STACK 100H
.DATA
S1 DB 13,10," Enter 1st number in 4-bit form = $"
S2 DB 13,10," Enter 2nd number in 4-bit form = $"
S3 DB 13,10," Sum of two numbers = $"
NUM DB 0
.CODE
BINSUM PROC NEAR
MOV AX,@DATA
; Read the data part
MOV DS,AX
; in to DS register.
PRINT S1
CALL INPUT
MOV NUM,BL

; Call PRINT macro for S1


; Call INPUT procedure
; NUM BL

PRINT S2
CALL INPUT

; Call PRINT macro for S2


; Call INPUT procedure

ADD NUM,BL
PRINT S3
MOV BL,NUM
CALL OUTPUT

; Add BL to NUM
; Call PRINT macro for S3
; BL NUM
; Call OUTPUT procedure

MOV AH,4CH
INT 21H
BINSUM ENDP
INPUT PROC NEAR
XOR BL,BL
MOV CL,04H
LOOP1:
MOV AH,01H
INT 21H

; End the process


; Call for DOS

; Clear BL
; CL 4
; Read a Character

SUB AL,30H
SHL BL,1

ADD BL,AL
LOOP LOOP1
RET
INPUT ENDP
OUTPUT PROC NEAR
MOV CL,08H
LOOP2:
MOV AH,02H
MOV DL,00H
RCL BL,01H
carry
ADC DX,30H
INT 21H
LOOP LOOP2
RET
OUTPUT ENDP
END

; Substracte 48 from AL
; Do left shift to BL one time

; Add AL to BL
; Do the loop up to CL = 0
; Call return to BINSUM procedure

; CL 8
; Print the character
; DL 0
; Rotate 1-bit to left side & stores
; Add 48 to DX with carry
; Do the loop untill CL = 0
; Call BINSUM procedure

PROGRAME CODE :
TITLE To find the given number is either prime or not
PRINT MACRO MSG
MOV AH,09H
LEA DX,MSG
INT 21H
ENDM
READ MACRO N
MOV AH,01H
INT 21H
MOV BL,10
SUB AL,48
MUL BL
MOV N,AL
MOV AH,01H
INT 21H
SUB AL,48
ADD N,AL
ENDM

; Request display
; Load address of title
; Call to DOS

; Reads a single character


; Call for DOS
; BL 10
; To get number
; Multiply AL with 10
; N AL
; Read a character
; Substract 48 from AL
; N AL

.MODEL SMALL
.STACK 64
.DATA
STR1 DB 13,10," Enter any two digit number <XX> : $"
STR2 DB 13,10," Given number is prime $"
STR3 DB 13,10," Given number is not prime $"
LINE DB 13,10,"$"
N DB ?
.CODE
PRIME PROC
MOV AX,@DATA
MOV DS,AX
PRINT STR1
READ N
MOV DH,00H
MOV DL,N

; for empty line printing


; uninitialized

; get address of data segment


; store address in DS
; Call PRINT macro for STR1
; reads number N
; clear DH
; move N to DL

DEC DL
MOV BL,02H
CMP BL,N
JE YES

NEXT:
MOV AH,00H
MOV AL,N
DIV BL
CMP AH,00
JE NO
INC BL
CMP BL,DL
JLE NEXT
YES:
PRINT LINE
PRINT STR2
PRINT LINE
JMP LAST
NO:
PRINT LINE
PRINT STR3
PRINT LINE
LAST:
MOV AH,4CH
INT 21H
PRIME ENDP
END

; decrement DL by 1
; special case for 2
; Compare BL with N
; if equal goto YES

; clear AH

; is remainder in AH equals to zero


; if so, goto NO
; is BL less than or equal to DL
; if so, goto next
; Call PRINT macro for LINE
; Printing as prime
; goto last

; printing as not prime

; request an end to program execute


; call DOS

PROGRAME CODE :
TITLE Printing the reverse of a string
DISPLAY MACRO MSG
; Macro for message printing
MOV AH, 09H
; Displays a string
LEA DX, MSG
; msg is loaded to DX register
INT 21H
; Exit to DOS
ENDM
.MODEL SMALL
.STACK 64
.DATA
STR1 DB 13,10," Enter ther string : $"
STR2 DB 13,10," Reverse of given is $"
LINE DB 13,10,"$"
S1 DB 20 DUP('$')
S2 DB 20 DUP('$')
.CODE
MOV AX,@DATA
; get address of data segment
MOV DS,AX
; store address into DS
DISPLAY STR1
LEA SI,S1
XOR CX,CX
NEXT:
INC SI
MOV AH,01H
INT 21H
INC CX
MOV [SI],AL
CMP AL,13
JNE NEXT

; Call DISPLAY macro for STR1


; Load string S1 to SI register
; Clear CX register

LEA BX,S2
LAST:
MOV AL,[SI]
MOV [BX],AL
DEC SI
INC BX
LOOP LAST
DISPLAY STR2
DISPLAY LINE
DISPLAY S2
MOV AH,4CH

; Address of S2 is given to BX

; increment SI (points first pos of array)


; Function to read single character
; And store in in AL
; Increment CX by 1
; Move AL into location of SI
; Is char not end of string
; If so, goto NEXT

; Move SI into BX
; Decrement SI by 1
; Increment BX by 1
; Call DISPLAY macro for STR2
; Call DISPLAY macro for LINE
; Printing S2 string (Reversed)
; Request an end to execution

INT 21H
END

; Call dos

Potrebbero piacerti anche