Assembly Language Programs

UNPACKED PACKED BCD
num1 db 00h                                  num1 dw 1234h 
num2 db 00h                                  num2 dw 5678h 
data ends                                         res dw 00h 
code segment                                  data ends 
assume cs:code,ds:data                    code segment 
start:                                                 assume cs:code, ds:data 
mov ax,data                                     start: 
mov ds,ax                                                 mov ax,data 
mov ah,00h                                               mov ds,ax 
mov al,num                                               mov ax,num1 
and al,0fh                                                   mov bx,num2 
mov num1,al                                              add ax,bx 
mov al,num                                                mov ax,num1 
and al,0f0h                                                 mov bx,num2 
mov cl,04h                                                 add al,bl 
shr al,cl                                                         daa 
mov num2,al                                              mov cl,al 
mov ah,4ch                                                adc ah,bh 
int 21h                                                       mov al,ah 
code ends                                                     daa 
end start                                                  mov ch,al 
                                                               mov res,cx 

AADITION OF BCD


data segment                    msg db “Enter a number : $” 
num dw 1234h                  num db 00h 
zeros dw 00h                    res1 dw 00h 
ones dw 00h                     res2 dw 00h 
data ends                          data ends 
code segment                   assume cs:code, ds:data 
assume                              cs:code,ds:data   start: 
start:                                   mov ax,data 
mov ax,data                        mov ds,ax 
mov ds,ax                           lea dx,msg 
mov ax,num                       mov ah,09h 
mov bx,00h                        int 21h 
mov dx,00h                        mov ah,01h 
mov cl,10h                          int 21h 
up:rol ax,01h                       sub al,48 
jc one                                  call facte 
inc bx                                  mov ah,4ch 
jmp down                           int 21h 
one:inc dx                           facte proc: 
down:loop up                     mov num,al 
mov zeros , bx                    mov cl,al 
mov ones,dx                       mov ch,00h 
mov ah,4ch                         mov ax,0001h 
int 21h                                mov dx,0000h 
code ends                           up: mul cx 
end start                             loop up 
                                           mov res1,ax 
                                          mov res2,dx 
                                          ret 
                                           facte endp 

ZEROS AND ONES             FACTORIAL 


LINEAR SEARCH                      EXTRA SEGMENT BLOCK  
data segment                           data segment 
arr dB 25h,32h,20h,16h,9h       arr1 dB 1,2,3,4,5,6,7,8,9  
msg1 dB “Number found$”        data ends  
msg2 dB “number not found$”    extra segment  
element dB 13h                          arr2 dB 9 dup(‘?’)  
data ends                                    extra ends  
print macro msg                           code segment  
mov ah,09h                                  assume ….
lea dx ,msg                                 start:  
int 21h                                             mov ax,data  
endm                                               mov ds,ax  
code segment                                 mov ax,extra  
assume cs:code,ds:data                   mov es,ax  
start:                                                 lea si,arr1  
mov ax,data                                     lea di,arr2  
mov ds,ax                                         mov cx,0009h  
mov cx,05h                                      rep movsb  
lea si,arr                                          mov cx,0009h  
mov bl,element                              lea si,arr1  
up: cmp bl,[si]                                 l2:  
je found                                            mov dl,[si]  
inc si                                                  add dl,48  
loop up                                               mov ah,02h  
print msg2                                           int 21h  
jmp exit                                               mov dl,32  
found: print msg1                              mov ah,02h  
exit: mov ah,4ch                                   int 21h  
int 21h                                                  inc si  
                                                              loop l2  
                                                               mov ah,4ch  
                                                               int 21h  


PALINDROME  
data segment  
len db 00h   msg0 db 10,13,”Enter the string–>$”   msg1 db 0fh dup(‘?’)  
msg2 db 0fh dup(‘?’)   msg3 db 10,13,”$”   msg4 db 10,13,”$”  
data ends  
disp macro msg  
lea dx,msg   mov ah,09h   int 21h  
endm  
code segment   assume cs:code, ds:data  
start:  mov ax, data  
mov ds, ax  
disp msg0  
lea dx, msg1  
mov ah, 0ah  
int 21h  
mov cl, [msg1+1]  
mov len ,cl  
lea si,[msg1+2]  
lea di, [msg2+2]  
reverse:mov al,[si]  
mov [di], al  
inc si  
inc di  
dec cl  
jnz reverse  
lea si,[msg1+2]  
dec di  
mov cl, len  
mov ch, 00h  
up: mov al, [si]   

cmp al, [di]  
jnz notpal  
inc si  
dec di  
loop up  
disp msg3  
jmp exit  
notpal: disp msg4  
exit: mov ah, 4ch   int 21h