Sie sind auf Seite 1von 50

Addressing modes:

data segment
n1 db 22h
n2 dw 1133h
data ends
prg segment
assume cs:prg,ds:data
start: mov ax,data
mov ds,ax
mov al,55h
mov si,2500h
mov bx,si
mov ah,n1
mov cx,n2
mov [si],al
mov dh,[si]
mov dx,[bx-20h]
mov cl,[bx+si]
mov ch,[bx+si+2000h]
mov ah,4ch
int 21h
prg ends
end start

Data transfer without overlap


DATA SEGMENT
ORG 1000H
SCRLIST DB 01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH
ORG 2000H
DSTLIST DB 10 DUP(00)
DATA ENDS
PRG SEGMENT
ASSUME CS:PRG,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV SI,1000H
MOV DI,2000H
MOV CX,000AH
UP: MOV AL,[SI]
MOV [DI],AL
INC SI
INC DI
LOOP UP
MOV AH,4CH
INT 21H
PRG ENDS
END START

Data transfer with overlap:


DATA SEGMENT
ORG 1000H
SCRLIST DB 01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH

DATA ENDS
PRG SEGMENT
ASSUME CS:PRG,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV SI,1009H
MOV DI,100EH
MOV CX,000AH
UP: MOV AL,[SI]
MOV [DI],AL
DEC SI
DEC DI
LOOP UP
MOV AH,4CH
INT 21H
PRG ENDS
END START

Exchange of data:
DATA SEGMENT
ORG 1000H
SCRLIST DB 01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH
ORG 2000H
DSTLIST DB 11H,12H,13H,14H,15H,16H,17H,18H,19H,2AH
DATA ENDS
PRG SEGMENT
ASSUME CS:PRG,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV SI,1000H
MOV DI,2000H
MOV CX,000AH
UP: MOV AL,[SI]
XCHG AL,[DI]
MOV [SI],AL
INC SI
INC DI
LOOP UP
MOV AH,4CH
INT 21H
PRG ENDS
END START

32 bit addition:
data segment
n1 dd 44443333h
n2 dd 22221111h
org 1000h
result dd ?
data ends
prg segment
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
mov ax,word ptr n1
add ax,word ptr n2
mov word ptr result,ax
mov ax,word ptr n1+2
adc ax,word ptr n2+2
mov word ptr result+2,ax
mov ah,4ch
int 21h
prg ends
end start

32 bit subtraction:
data segment
n1 dd 44443333h
n2 dd 22222222h
org 1000h
result dd ?
data ends
prg segment
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
mov ax,word ptr n1
sub ax,word ptr n2
mov word ptr result,ax
mov ax,word ptr n1+2
sbb ax,word ptr n2+2
mov word ptr result+2,ax
mov ah,4ch
int 21h
prg ends
end start

BCD addition:
data segment
m1 db 0ah,0dh,"enter first number : $"
m2 db 0ah,0dh,"enter second number: $"
m3 db 0ah,0dh,"result is : $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start : mov ax,data
mov ds,ax
print m1
call inp
mov ch,bl
call inp
mov cl,bl
print m2
call inp
mov bh,bl
call inp
mov al,cl
add al,bl
daa
mov cl,al
mov al,ch
adc al,bh
daa
mov ch,al
print m3
call dsp
mov bl,ch
call dsp
mov bl,cl
call dsp
mov ah,4ch
int 21h
prg ends
end start

BCD subtraction:
data segment
m1 db 0ah,0dh,"enter first number : $"
m2 db 0ah,0dh,"enter second number: $"
m3 db 0ah,0dh,"result is : $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start : mov ax,data
mov ds,ax
print m1
call inp
mov ch,bl
call inp
mov cl,bl
print m2
call inp
mov bh,bl
call inp
mov al,cl
sub al,bl
das
mov cl,al
mov al,ch
sbb al,bh
das
mov ch,al
print m3
call dsp
mov bl,ch
call dsp
mov bl,cl
call dsp
mov ah,4ch
int 21h
prg ends
end start

Multiplication of HEX:
data segment
m1 db 0ah,0dh,"enter first number : $"
m2 db 0ah,0dh,"enter second number: $"
m3 db 0ah,0dh,"result is : $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start : mov ax,data
mov ds,ax
print m1
call inp
mov ch,bl
call inp
mov cl,bl
print m2
call inp
mov bh,bl
call inp
mov dx,0000h
mov ax,cx
mul bx
print m3
mov bl,dh
call dsp
mov bl,dl
call dsp
mov bl,ah
call dsp
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Division of HEX:
data segment
m1 db 0ah,0dh,"enter first number : $"
m2 db 0ah,0dh,"enter second number: $"
m3 db 0ah,0dh,"quotient is : $"
m4 db 0ah,0dh,"remender is:$"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start : mov ax,data
mov ds,ax
print m1
call inp
mov ch,bl
call inp
mov cl,bl
print m2
call inp
mov bh,bl
call inp
mov dx,0000h
mov ax,cx
div bx
print m4
mov bl,dh
call dsp
mov bl,dl
call dsp
print m3
mov bl,ah
call dsp
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Square of no.
data segment
m1 db 0ah,0dh,"enter number : $"
m2 db 0ah,0dh,"square is : $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start: mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
mul al
print m2
mov bl,ah
call dsp
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Cube of no.
data segment
m1 db 0ah,0dh,"enter number : $"
m2 db 0ah,0dh,"cube is : $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start: mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
mov cl,bl
mov dx,0000h
mul al
mul cl
print m2
mov bl,dh
call dsp
mov bl,dl
call dsp
mov bl,ah
call dsp
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Hex calculator:
data segment
m1 db 0ah,0dh,"enter first digit :$"
m2 db 0ah,0dh,"enter second digit :$"
m3 db 0ah,0dh,"enter 01 for add , 02 for substract 03 for mul , 04 for division : $"
m4 db 0ah,0dh,"enter your choice:$"
m5 db 0ah,0dh,"the results is :$"
m6 db 0ah,0dh,"invalid choice !!!!!!!! $"
data ends.
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start: mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
print m2
call inp
mov ch,bl
print m3
print m4
call inp
cmp bl,01h
je dn1
cmp bl,02h
je dn2
cmp bl,03h
je dn3
cmp bl,04h
je dn4
print m6
jmp last
dn1:add cl,ch
mov bl,cl
print m5
call dsp
jmp last
dn2:sub cl,ch

mov bl,cl
print m5
call dsp
jmp last
dn3:mov al,cl
mov ah,00h
mul ch
mov bl,ah
print m5
call dsp
mov bl,al
call dsp
jmp last
dn4:mov al,cl
mov ah,00h
div ch
mov bl,ah
print m5
call dsp
mov bl,al
call dsp
last:mov ah,4ch
int 21h
prg ends
end start

GCD of no.
data segment
m1 db 0ah,0dh,"enter first digit:$"
m2 db 0ah,0dh,"enter second digit :$"
m3 db 0ah,0dh,"GCD is : $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start: mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
print m2
call inp
up1: cmp al,bl
je dn1
cmp al,bl
jc dn2
sub al,bl
jmp up1
dn2: sub bl,al
jmp up1
dn1:print m3
mov bl,al
call dsp
mov ah,4ch
prg ends
end start

LCM of no:
data segment
m1 db 0ah,0dh,"enter first digit:$"
m2 db 0ah,0dh,"enter second digit :$"
m3 db 0ah,0dh,"LCM is : $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start: mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
mov ch,bl
print m2
call inp
mov cl,bl
up1:cmp al,bl
je dn1
jc dn2
sub al,bl
jmp up1
dn2:sub bl,al
jmp up1
dn1:mov al,ch
mul cl
div bl
print m3
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Factorial of a no:
data segment
m1 db 0ah,0dh,"Enter the no $"
m2 db 0ah,0dh,"factorial of no is $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov ch,00h
mov ax,0001h
up:mul cx
loop up
mov cx,ax
print m2
mov bl,ch
call dsp
mov bl,cl
call dsp
mov ah,4ch
int 21h
prg ends
end start

BCD to HEX:
data segment
m1 db 0ah,0dh,"enter bcd no:$"
m2 db 0ah,0dh,"hex eq bcd no:$"
data ends
print macro m
push dx
push ax
lea dx,m
mov ah,09h
int 21h
pop ax
pop dx
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
and al,0f0h
mov cl,04h
ror al,cl
mov cl,0ah
mul cl
and bl,0fh
add al,bl
print m2
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

HEX to BCD:
data segment
m1 db 0ah,0dh,"enter hex number:$"
m2 db 0ah,0dh,"bcd equ of hex number is:$"
data ends
print macro m
push dx
push ax
lea dx,m
mov ah,09h
int 21h
pop ax
pop dx
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start:mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
mov ah,00h
mov bl,64h
div bl
print m2
mov bl,al
call dsp
mov al,ah
mov bl,0ah
mov ah,00h
div bl
mov cl,04h
ror al,cl
add al,ah
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

HEX to ASCII:
data segment
m1 db 0ah,0dh,"enter the hex number: $"
m2 db 0ah,0dh,"ascii equivalent of hex is: $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start: mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
mov ah,00h
aam
add ax,3030h
print m2
mov bl,ah
call dsp
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Count 1s and 0s:


data segment
m1 db 0ah,0dh,"enter the number:$"
m2 db 0ah,0dh,"number of ones is:$"
m3 db 0ah,0dh,"number of zeros is:$"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:near
start:mov ax,data
mov ds,ax
print m1
call inp
mov cl,08h
mov ch,00h
mov ah,00h
mov al,00h
up:rol bl,01h
jc dn3
inc al
loop up
jmp last
dn3:inc ah
loop up
last:print m2
mov bl,ah
call dsp
print m3
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Check 2 out of 5 code:


data segment
m1 db 0ah,0dh,"enter the no:$"
m2 db 0ah,0dh,"the number is two out of five:$"
m3 db 0ah,0dh,"the number is not two out of five:$"
data ends

print macro m
push dx
push ax
lea dx,m
mov ah,09h
int 21h
pop ax
pop dx
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start :mov ax,data
mov ds,ax
print m1
call inp
mov al,bl
and al,0e0h
jnz dn1
mov ah,00h
mov cx,00005h
up1:ror bl,01h
jnc dn2
inc ah

dn2:loop up1
cmp ah,02h
jne dn1
print m2
jmp last
dn1:print m3
last: mov ah,4ch
int 21h
prg ends
end start

Nibblewise palindrome:
data segment
m1 db 0ah,0dh,"enter the 16 bit no: $"
m2 db 0ah,0dh,"the no is nibble wise palindrom $"
m3 db 0ah,0dh,"the no is not nibblewise palindrom $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov bh,bl
call inp
mov cl,04h
ror bl,cl
cmp bl,bh
jne dn1
print m2
jmp last
dn1:print m3
last:mov ah,4ch
int 21h
prg ends
end start

Bitwise Palindrome:
data segment
m1 db 0ah,0dh,"enter the 16 bit no: $"
m2 db 0ah,0dh,"the no is bitwise palindrom $"
m3 db 0ah,0dh,"the no is not bitwise palindrom $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov ah,bl
call inp
mov al,bl
mov bx,ax
mov cx,0010h
up:rol bx,1
rcr ax,1
loop up
xor ax,bx
jnz npal
print m2
jmp last
npal:print m3
last:mov ah,4ch
int 21h
prg ends
end start

Smallest no.
data segment
m1 db 0ah,0dh,"Enter the value on N: $"
m2 db 0ah,0dh,"enter the no one by one:$"
m3 db 0ah,0dh,"smallest no is: $"
m4 db 0ah,0dh,"$"
list db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov dl,bl
print m2
mov ch,00h
lea si,list
up:print m4
call inp
mov [si],bl
inc si
loop up
lea si,list
dec dl
mov cl,dl
mov al,[si]
up1:inc si
cmp al,[si]
jc dn
mov al,[si]
dn:loop up1
print m3
mov bl,al
call dsp
mov ah,4ch

int 21h
prg ends
end start

Largest no.
data segment
m1 db 0ah,0dh,"Enter the value on N: $"
m2 db 0ah,0dh,"enter the no one by one:$"
m3 db 0ah,0dh,"largest no is: $"
m4 db 0ah,0dh,"$"
list db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov dl,bl
print m2
mov ch,00h
lea si,list
up:print m4
call inp
mov [si],bl
inc si
loop up
lea si,list
dec dl
mov cl,dl
mov al,[si]
up1:inc si
cmp al,[si]
jnc dn
mov al,[si]

dn:loop up1
print m3
mov bl,al
call dsp
mov ah,4ch
int 21h
prg ends
end start

Avg of N nos:
data segment
m1 db 0ah,0dh,"enter the value of n:$"
m2 db 0ah,0dh,"enter the nos 1 by 1:$"
m3 db 0ah,0dh,"the average is $"
m4 db 0ah,0dh,"$"
list db 100 dup (00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
extrn inp:far,dsp:far
start:mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov dl,bl
mov ch,00h
lea si,list
print m2
up:print m4
call inp
mov [si],bl
inc si
loop up
mov cl,dl
mov ax,00h
lea si,list
up1:mov bl,[si]
mov bh,00h
add ax,bx
inc si
loop up1
div dl
print m3
mov bl,al

call dsp
mov ah,4ch
int 21h
prg ends
end start

Ascending Order:
data segment
m1 db 0ah,0dh,"Enter the value of N $"
m2 db 0ah,0dh,"Enter the no 1 by 1 $"
m3 db 0ah,0dh,"The ascending order is $"
m4 db 0ah,0dh,"$"
list db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov dl,bl
mov ch,00h
mov dh,bl
lea si,list
print m2
up:print m4
call inp
mov [si],bl
inc si
loop up
dec dh
up2:lea si,list
mov cl,dh
up1:mov al,[si]
mov bl,[si+01]
cmp al,bl
jc dn

xchg al,bl
mov [si],al
mov [si+01],bl
dn:inc si
loop up1
dec dh
jnz up2
print m3
lea si,list
mov cl,dl
up3:print m4
mov bl,[si]
call dsp
inc si
loop up3
mov ah,4ch
int 21h
prg ends
end start

Descending Order:
data segment
m1 db 0ah,0dh,"Enter the value of N $"
m2 db 0ah,0dh,"Enter the no 1 by 1 $"
m3 db 0ah,0dh,"The descending order is $"
m4 db 0ah,0dh,"$"
list db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov dl,bl
mov ch,00h
mov dh,bl
lea si,list
print m2
up:print m4
call inp
mov [si],bl
inc si
loop up
dec dh
up2:lea si,list
mov cl,dh
up1:mov al,[si]
mov bl,[si+01]
cmp al,bl
jnc dn

xchg al,bl
mov [si],al
mov [si+01],bl
dn:inc si
loop up1
dec dh
jnz up2
print m3
lea si,list
mov cl,dl
up3:print m4
mov bl,[si]
call dsp
inc si
loop up3
mov ah,4ch
int 21h
prg ends
end start

Positive & negative no.


data segment
m1 db 0ah,0dh,"enter the value of n$"
m2 db 0ah,0dh,"enter the no one by one $"
m3 db 0ah,0dh,"the +ve no list $"
m4 db 0ah,0dh,"the -ve no list $"
m5 db 0ah,0dh,"$"
list db 100 dup(00)
plist db 100 dup(00)
nlist db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg, ds:data
extrn inp:far,dsp:far
start: mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov bh,cl
print m2
lea si,list
mov ch,00h
up1:print m5
call inp
mov [si],bl
inc si
loop up1
lea si,list
lea di,plist
mov dh,00h
mov cl,bh
up2:mov al,[si]
rol al,01h
jc up3
mov al,[si]
mov [di],al
inc di
inc dh

up3:inc si
loop up2
lea si,list
lea di,nlist
mov dl,00h
mov cl,bh
up4: mov al,[si]
rol al,01h
jnc up5
mov al,[si]
mov [di],al
inc di
inc dl
up5: inc si
loop up4
print m3
lea si,plist
mov cl,dh
up6:print m5
mov bl,[si]
call dsp
inc si
loop up6
print m4
mov cl,dl
lea si,nlist
up7:print m5
mov bl,[si]
call dsp
inc si
loop up7
mov ah,4ch
int 21h
prg ends
end start

Even and Odd:


data segment
m1 db 0ah,0dh,"enter the value of n: $"
m2 db 0ah,0dh,"enter the no one by one: $"
m3 db 0ah,0dh,"the even no list :$"
m4 db 0ah,0dh,"the odd no list:$"
m5 db 0ah,0dh,"$"
list db 100 dup(00)
plist db 100 dup(00)
nlist db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg, ds:data
extrn inp:far,dsp:far
start: mov ax,data
mov ds,ax
print m1
call inp
mov cl,bl
mov bh,cl
print m2
lea si,list
mov ch,00h
up1:print m5
call inp
mov [si],bl
inc si
loop up1
lea si,list
lea di,plist
mov dh,00h
mov cl,bh
up2:mov al,[si]
ror al,01h
jc up3
mov al,[si]
mov [di],al
inc di
inc dh

up3:inc si
loop up2
lea si,list
lea di,nlist
mov dl,00h
mov cl,bh
up4: mov al,[si]
ror al,01h
jnc up5
mov al,[si]
mov [di],al
inc di
inc dl
up5: inc si
loop up4
print m3
lea si,plist
mov cl,dh
up6:print m5
mov bl,[si]
call dsp
inc si
loop up6
print m4
mov cl,dl
lea si,nlist
up7:print m5
mov bl,[si]
call dsp
inc si
loop up7
mov ah,4ch
int 21h
prg ends
end start

Key in a string:
data segment
m1 db 0ah,0dh,"enter the string:$"
m2 db 0ah,0dh,"enter the key to be searched:$"
m3 db 0ah,0dh,"the key is present:$"
m4 db 0ah,0dh,"the key is not present:$"
str db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
mov cx,0000h
lea si,str
up:mov ah,01h
int 21h
cmp al,0Dh
je dn
mov [si],al
inc si
inc cx
jmp up
dn:print m2
mov ah,01h
int 21h
lea si,str
up1:cmp al,[si]
je dn1
inc si
loop up1

print m4
jmp last
dn1:print m3
last: mov ah,4ch
int 21h
prg ends
end start

Concatenate two strings:


data segment
m1 db 0ah,0dh,"enter the first string:$"
m2 db 0ah,0dh,"enter the second string:$"
m3 db 0ah,0dh,"concantinated string is:$"
str1 db 100 dup(00)
str2 db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
mov cx,0000h
lea si,str1
up:mov ah,01h
int 21h
cmp al,0Dh
je dn
mov [si],al
inc si
inc cx
jmp up
dn:mov bx,cx
mov cx,0000h
print m2
lea si,str2
up1:mov ah,01h
int 21h
cmp al,0dh
je dn1

mov [si],al
inc si
inc cx
jmp up1
dn1:lea si,str1
add si,bx
lea di,str2
up2:mov al,[di]
mov [si],al
inc si
inc di
loop up2
mov byte ptr[si],'$'
print m3
print str1
mov ah,4ch
int 21h
prg ends
end start

Rev and check string is palindrome


data segment
m1 db 0ah,0dh,"Enter the string: $"
m2 db 0ah,0dh,"The reversed string is: $"
m3 db 0ah,0dh,"the string is palindrome: $"
m4 db 0ah,0dh,"The string is not a palindrome: $"
str1 db 100 dup(00)
str2 db 100 dup(00)
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
lea si,str1
mov cx,0000h
up:mov ah,01h
int 21h
cmp al,0dh
je dn
mov [si],al
inc si
inc cx
jmp up
dn:mov bx,cx
lea si,str1
lea di,str2
add si,bx
dec si
up1:mov al,[si]
mov [di],al
inc di
dec si
loop up1

print m2
lea di,str2
mov cx,bx
up3: mov dl,[di]
mov ah,02h
int 21h
inc di
loop up3
lea si,str1
lea di,str2
mov cx,bx
up2:mov al,[si]
cmp al,[di]
jne dn2
inc si
inc di
loop up2
print m3
jmp last
dn2:print m4
last :mov ah,4ch
int 21h
prg ends
end start

Change case of string:


data segment
m1 db 0ah,0dh,"enter the string:$"
m2 db 0ah,0dh,"the result:$"

str db 100 dup(00)


data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
print m1
mov cx,0000h
lea si,str
up:mov ah,01h
int 21h
cmp al,0Dh
je dn
mov [si],al
inc si
inc cx
jmp up
dn:lea si,str
up1:mov al,[si]
cmp al,'A'
jc d2
cmp al,'Z'
jnc d1
add al,20h
mov [si],al
jmp d2

d1:cmp al,'a'
jc d2
cmp al,'z'
jnc d2
sub al,20h
mov [si],al
d2:inc si
loop up1
mov byte ptr[si],'$'
print m2
print str
mov ah,4ch
int 21h
prg ends
end start

System date on console:


data segment
m1 db 0ah,0dh,"the system date is :$"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
Prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
mov ah,2ah
int 21h
print m1
mov bh,dl
mov bl,al
call dsp
mov dl,':'
mov ah,02h
int 21h
mov bl,bh
call dsp
mov dl,':'
mov ah,02h
int 21h
mov bl,dh
call dsp
mov ah,02h
int 21h
mov bl,ch
call dsp
mov bl,cl
call dsp
mov ah,4ch
int 21h
prg ends
end start

system time on console:


data segment
m1 db 0ah,0dh,"the system time is: $"
data ends
print macro m
push ax
push dx
lea dx,m
mov ah,09h
int 21h
pop dx
pop ax
endm
prg segment
extrn inp:far,dsp:far
assume cs:prg,ds:data
start:mov ax,data
mov ds,ax
mov ah,2ch
int 21h
print m1
mov bl,ch
call dsp
mov dl,':'
mov ah,02h
int 21h

mov bl,cl
call dsp
mov dl,':'
mov ah,02h
int 21h
mov bl,dh
call dsp
mov ah,4ch
int 21h
prg ends
end start

Procedure:
data segment
data ends
prg segment
assume cs:prg,ds:data
public inp,dsp
start : mov ax,data
mov ds,ax
inp proc near
push ax
push cx
push dx
pushf
mov ah,01h
int 21h
cmp al,41h
jc dn1
sub al,07h
dn1:sub al,30h
mov cl,04h
ror al,cl
mov bl,al
mov ah,01h
int 21h
cmp al,41h
jc dn2
sub al,07h
dn2:sub al,30h
add bl,al
popf
pop dx
pop cx
pop ax
ret
inp endp
dsp proc near
push ax
push bx

push cx
push dx
pushf
mov dl,bl
and dl,0f0h
mov cl,04
ror dl,cl
cmp dl,0ah
jc dn3
add dl,07h
dn3:add dl,30h
mov ah,02h
int 21h
mov dl,bl
and dl,0fh
cmp dl,0ah
jc dn4
add dl,07h
dn4: add dl,30h
mov ah,02h
int 21h
popf
pop dx
pop cx
pop bx
pop ax
ret
dsp endp
mov ah,4ch
int 21h
prg ends
end start

Das könnte Ihnen auch gefallen