Archive for the ‘Advanced Mu P’ Category
AMP-switch cases-version2
To change upper case to lower and vice versa
; program for operations on strings
page 100,50
title string operations
mess macro msg ;definition of macro mess
mov ah, 09h
lea dx, msg
int 21h
endm
.model small
.stack 100h
.data
str1 db 25 , ? , 25 dup(‘$’)
str2 db 25 , ? , 25 dup(‘$’)
str3 db 25 , ? , 25 dup(‘$’)
msg1 db 0ah,0dh,’menu $’
msg21 db 0ah,0dh,’accept the string $’
msg6 db 0ah,0dh,’string is : $’
msg7 db 0ah,0dh,’ $’
.code ; data initialisation
mov ax,@data
mov ds,ax
mov es,ax
mess msg21
mov ah,0ah
lea dx,str1
int 21h
call convert
endd: mov ah,4ch
int 21h
;***************************************************************************
; convert cases
;***************************************************************************
convert proc near
lea si,str1+2 ; source string
lea di,str2+2 ; destination string
mov cl,str1+1
back: mov al,byte ptr[si]
cmp al,41h ; check if letter
jge bigg
jmp stop
smal : cmp al,61h ; check if letter is lower case
jge subb
bigg : cmp al,5ah ; check if letter is upper case
jge smal ; if greater letter is small case
add al,20h ; make letter lower case
branc:mov byte ptr[di],al ; move letter to destination
inc di
inc si
dec cl ; decrememt count
cmp cl, 00h
jne back ; check next character
jmp stop
subb: cmp al,7ah ; if small case letter
jge stop ; if not letter display as is
sub al,20h ; make letter upper case
jmp branc
stop: mess msg7 ; display result
mov ah,09h
lea dx,str2+2
int 21h
ret
convert endp
end
AMP-Devnagiri
AIM:-To convert english to devnagiri
.model small
; PROGRAM TO TYPE DEVANAGARI CHARACTER
.data
BUFF DB 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,1,1,1,1,1,1,1,1,1,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
COL DW 0010H
ROW DW 0010H
SCOL DW 001FH
SROW DW 001FH
.code
START : MOV AX,@data ; Initialise data segment
MOV DS,AX
MOV AH,00H
MOV AL,06H ; Set graphics mode
INT 10H
MOV DX,ROW ; Initialise row and column
MOV CX,COL
XOR SI,SI
MOV AH,08H ; I/P from keyboard
INT 21H
CMP AL,’P’ ; If character is P, print
JNE STOP ; Otherwise terminate the
; program
DISP : MOV AH,0CH ; Write pixel
MOV AL,BUFF [SI]
MOV BH,00H
MOV CX,COL
MOV DX,ROW
INT 10H
INC SI
INC COL ; Increment column
MOV DI,SCOL
CMP COL,DI
JNE DISP
SUB COL,0FH
INC ROW ; Increment ROW
MOV BP,SROW
CMP ROW,BP
JNE DISP
MOV AH,08H ; I/P from keyboard
INT 21H
STOP: MOV AH,00H
MOV AL,03H ; Change mode
INT 10H
MOV AH,4CH ; Terminate
INT 21H
END START
AMP-Nested Rectangles
AIM:-Nested rectangles
.model small
.data
a dw 019fH
b dw 019fH
c dw 0090H
.code
mov ax, @data
mov ds, ax
mov ax, 0012H
int 10H
x: mov cx, 00h
mov dx, b
dec b
mov al, 01H
mov ah, 0cH
int 10H
jnz x
y: mov dx, 00h
mov cx, a
dec a
mov al, 01H
mov ah, 0cH
int 10H
jnz y
mov b,019fh
z: mov cx, 019fh
mov dx, b
dec b
mov al, 01H
mov ah, 0cH
int 10H
jnz z
mov a,019fh
w: mov cx, a
mov dx, 019fh
dec a
mov al, 01H
mov ah, 0cH
int 10H
jnz w
mov a,00f0h
mov b,00f0h
p: mov cx, 0090h
mov dx, b
dec b
cmp b,90h
mov al, 01H
mov ah, 0cH
int 10H
jne p
q: mov dx, 0090h
mov cx, a
dec a
cmp a,90h
mov al, 01H
mov ah, 0cH
int 10H
jne q
mov b,00f0h
r: mov cx, 00f0h
mov dx, b
dec b
cmp b,90h
mov al, 01H
mov ah, 0cH
int 10H
jne r
mov a,00f0h
s: mov cx, a
mov dx, 00f0h
dec a
cmp a,90h
mov al, 01H
mov ah, 0cH
int 10H
jne s
mov ah, 08H
int 21H
mov ax, 0003H
int 10H
end
AMP-Count diff char type
AIM:- To count the no of special characters, alphabets and numbers
.model small
.stack 100
TITLE TOTAL
; (THIS PROGRAM GIVES THE TOTAL NUMBERS, ALPHABETS, SPECIAL
; CHARACTERS IN THE GIVEN STRING)
.data
BUF DB 80 ;(MAX LENGTH OF ARRAY)
DB 00 ;(ACTUAL LENGTH OF ARRAY)
DB 80 DUP (0) ;(STARTING OF ARRAY)
STR1 DB 10,13,’ENTER THE STRING:$’
STR2 DB 10,13,’TOTAL NO:$’
STR3 DB 10,13,’TOTAL ALPHABETS:$’
STR4 DB 10,13,’TOTAL SPECIAL CHAR:$’
NUM DB 0
SPC DB 0
ALPHA DB 0
.code
START: MOV AX,@data ; Initialisation
MOV DS,AX
MOV AH,09H
MOV DX,OFFSET STR1 ; Address of STR1
INT 21H
MOV AH,0AH
MOV DX,OFFSET BUF ; Address of max length
INT 21H
MOV BX,OFFSET BUF
INC BX ; Address of actual
MOV DL,[BX] ; Length
INC BX ; Starting of array
NEXT: MOV AL,[BX]
CMP AL,30H
JB INCSPC ; SPC character
CMP AL,3AH ; If < 3AH it is a number
JB INCNUM
CMP AL,41H ; Between 3AH & 41H it
JB INCSPC ; SPC character
CMP AL,5BH ; If < 5BH it is a alphabet
JB INALP
CMP AL,61H ; Between 5BH & 61H it
JB INCSPC ; Is a SPC char
CMP AL,7BH ; If < 7BH it is a alphabet
JB INALP
INCSPC: MOV AL,SPC
ADD AL,01H ; INCR SPC counter
DAA
MOV SPC,AL
INC BX ; Next character
DEC DL ; DECR counter
JNZ NEXT
JMP DISPLY
INCNUM: MOV AL,NUM
ADD AL,01H ; INCR number counter
DAA
MOV NUM,AL
INC BX
DEC DL
JNZ NEXT
JMP DISPLY
INALP: MOV AL,ALPHA
ADD AL,01H ; INCR ALPHABET COUNTER
DAA
MOV ALPHA,AL
INC BX
DEC DL
JNZ NEXT
JMP DISPLY
DISPLY: MOV DX,OFFSET STR2 ; ADDRS of STR2
MOV AH,09H
INT 21H
MOV AL,NUM
AND AL,0F0H ; Get MSB in AL rotate AL
MOV CL,04H ; Four times
ROR AL,CL
ADD Al,30H ; Convert to ASCII
MOV DL,AL
MOV AH,02H ; Output character
INT 21H
MOV AL,NUM
AND AL,0FH ; Get LSB in AL
ADD AL,30H
MOV DL,AL ; Convert to ASCIII
INT 21H
MOV DX,OFFSET STR3 ; Address of STR34
MOV AH,09H ; Output character string
INT 21H
MOV AL,ALPHA
AND AL,0F0H
MOV CL,04H
ROR AL,CL
ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
MOV AL,ALPHA
AND AL,0FH
ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
MOV DX,OFFSET STR4 ; ADDRS of STR4
MOV AH,09H
INT 21H
MOV AL,SPC
AND AL,0F0H
MOV CL,04
ROR AL,CL
ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
MOV AL,SPC
AND AL,0FH
ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
MOV AH,4CH ; Terminate program
INT 21H
END START
AMP-Reverse String
AIM:- To reverse the given string
.model small
.data
ms1 db 10, 13, “enter the string: $”
ms2 db 10, 13, “$”
ms3 db 10, 13, “reverse string is: $”
buff db 81
db 0
db 81 dup(0)
.code
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, ms1
int 21h
mov ah, 0ah
lea dx, buff
int 21h
mov ch, 00
mov cl, buff+1
lea bx, buff
inc bx
mov di, cx
mov ah, 09h
lea dx, ms1
int 21h
back: mov ah, 02h
mov dl, [bx+di]
int 21h
dec di
jnz back
mov ah, 4ch
int 21h
end
AMP-Check String Palindrome
AIM:Check if given string is palindrome or not
.model small
.data
M1 DB 10, 13, ‘Enter the string : $’
M2 DB 10, 13, ‘String is palindrome $’
M3 DB 10, 13, ‘String is not palindrome $’
BUFF DB 80
DB 0
DB 80 DUP (0)
.code
START: MOV AX, @data
MOV DS, AX
MOV AH, 09H ; Display message M1
MOV DX, OFFSET M1
INT 21H
MOV AH, 0AH ; input the string
LEA DX, BUFF
INT 21H
LEA BX, BUFF+2
MOV CH, 00H
MOV CL, BUFF+1
MOV DI, CX
DEC di
SAR CL, 1
MOV SI, 00H
BACK: MOV AL, [BX + DI] ; Get the right most character
MOV AH, [BX + SI] ; Get the left most character
CMP AL, AH
JNZ LAST
DEC DI
INC SI
DEC CL
JNZ BACK
MOV AH, 09H ; Display message 2
MOV DX, OFFSET M2
INT 21H
JMP TER
LAST: MOV AH, 09H
MOV DX, OFFSET M3 ; Display message 3
INT 21H
TER: MOV AH, 4CH
INT 21H
END START
AMP-Upper to lower & vice versa
AIM:-Write a program to convert the string from upper case to lower case and vice versa.
.model small
.data
str1 db 25 , ? , 25 dup(‘$’)
str2 db 25 , ? , 25 dup(‘$’)
str3 db 25 , ? , 25 dup(‘$’)
msg1 db 0ah,0dh,’menu $’
msg21 db 0ah,0dh,’accept the string $’
msg6 db 0ah,0dh,’string is : $’
msg7 db 0ah,0dh,’ $’
.code
mov ax,@data
mov ds,ax
mov ah,0ah
lea dx,str1
int 21h
endd: mov ah,4ch
int 21h
lea si,str1+2 ; source string
lea di,str2+2 ; destination string
mov cl,str1+1
back: mov al,byte ptr[si]
cmp al,41h ; check if letter
jge bigg
jmp stop
smal : cmp al,61h ; check if letter is lower case
jge subb
bigg : cmp al,5ah ; check if letter is upper case
jge smal ; if greater letter is small case
add al,20h ; make letter lower case
branc: mov byte ptr[di],al ; move letter to destination
inc di
inc si
dec cl ; decrememt count
cmp cl, 00h
jne back ; check next character
jmp stop
subb: cmp al,7ah ; if small case letter
jge stop ; if not letter display as is
sub al,20h ; make letter upper case
jmp branc
stop:
mov ah,09h ; display result
lea dx,str2+2
int 21h
end
AMP-Line of diff colour
AIM:- Write a program to draw lines of different colors
.model small
.code
mov ax,@data
mov ds,ax
mov ax,0012h
int 10h
mov ah,0ch
mov al,01h
mov dx,0010h
l2:mov cx,0001h
l1:int 10h
inc cx
cmp cx,100h
jne l1
inc dx
inc al
cmp dx,100h
jne l2
mov ah,08h
int 21h
mov ax,0003h
int 10h
mov ah,4ch
int 21h
end
OUTPUT:-
Lines of different colors have been displayed.
Leave a Comment