;PROGRAM TO CONVERT 8-BIT BINARY NUMBER TO ITS GRAY CODE FORM
data segment
opr db 34h
res db ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov al,opr
mov bl,al
rcr al,1
xor al,bl
mov res,bl
int 3
code ends
end start
16-bit binary to BCD conversion
;PROGRAM TO CONVERT 16-BIT BINARY NUMBER TO ITS EQUIVALENT BCD FORM
data segment
bin equ 1011b
result dw ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov bx,bin
mov ax,0h
mov cx,0h
again0:
cmp bx,0h
jz endprg
dec bx
mov al,cl
add al,01h
daa
mov cl,al
mov al,ch
adc al,00h
daa
mov ch,al
jmp again0
endprg:
mov result,cx
int 3
code ends
end start
data segment
bin equ 1011b
result dw ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov bx,bin
mov ax,0h
mov cx,0h
again0:
cmp bx,0h
jz endprg
dec bx
mov al,cl
add al,01h
daa
mov cl,al
mov al,ch
adc al,00h
daa
mov ch,al
jmp again0
endprg:
mov result,cx
int 3
code ends
end start
BCD to Binary conversion
;PROGRAM TO CONVERT BCD NUMBER TO BINARY NUMBER
data segment
bcd equ 4567h
result dw ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov bx,bcd
mov ax,0h
mov cx,0h
again0:
cmp bx,0h
jz endprg
mov al,bl
sub al,01h
das
mov bl,al
mov al,bh
sbb al,00h
das
mov bh,al
inc cx
jmp again0
endprg:
mov result,cx
int 3
code ends
end start
data segment
bcd equ 4567h
result dw ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov bx,bcd
mov ax,0h
mov cx,0h
again0:
cmp bx,0h
jz endprg
mov al,bl
sub al,01h
das
mov bl,al
mov al,bh
sbb al,00h
das
mov bh,al
inc cx
jmp again0
endprg:
mov result,cx
int 3
code ends
end start
Arranging numbers in Descending order
;PROGRAM TO ARRANGE NUMBERS IN DESCENDING ORDER
data segment
list dw 53h,25h,19h,44h,13h,02h
count equ $-list-1
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov dx,5h
again0: mov cx,dx
mov si,offset list
again1: mov ax,[si]
cmp ax,[si+2]
jg pr1
xchg [si+2],ax
xchg [si],ax
pr1:
add si,02h
loop again1
dec dx
jnz again0
int 03h
code ends
end start
data segment
list dw 53h,25h,19h,44h,13h,02h
count equ $-list-1
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov dx,5h
again0: mov cx,dx
mov si,offset list
again1: mov ax,[si]
cmp ax,[si+2]
jg pr1
xchg [si+2],ax
xchg [si],ax
pr1:
add si,02h
loop again1
dec dx
jnz again0
int 03h
code ends
end start
Arranging numbers in Ascending order
:PROGRAM TO ARRANGE NUMBERS IN ASCENDING ORDER
data segment
list dw 53h,25h,19h,44h,13h,02h
count equ $-list-1
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov dx,5h
again0: mov cx,dx
mov si,offset list
again1: mov ax,[si]
cmp ax,[si+2]
jl pr1
xchg [si+2],ax
xchg [si],ax
pr1:
add si,02h
loop again1
dec dx
jnz again0
int 03h
code ends
end start
data segment
list dw 53h,25h,19h,44h,13h,02h
count equ $-list-1
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov dx,5h
again0: mov cx,dx
mov si,offset list
again1: mov ax,[si]
cmp ax,[si+2]
jl pr1
xchg [si+2],ax
xchg [si],ax
pr1:
add si,02h
loop again1
dec dx
jnz again0
int 03h
code ends
end start
Many number Addition
;PROGRAM TO ADD MANY NUMBERS
data segment
list db 24h,56h,0aah,7ah
cnt equ $-list
res db 0
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov cl,cnt
lea si,list
mov al,[si]
dec cl
cnti:
inc si
add al,[si]
jnc pos
inc [res+1]
pos:
dec cl
jnz cnti
mov res,al
int 3
code ends
end start
data segment
list db 24h,56h,0aah,7ah
cnt equ $-list
res db 0
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov cl,cnt
lea si,list
mov al,[si]
dec cl
cnti:
inc si
add al,[si]
jnc pos
inc [res+1]
pos:
dec cl
jnz cnti
mov res,al
int 3
code ends
end start
Delete repeated charcaters
;PROGRAM TO DELETE REPEATED CHARACTERS AND REPLACE THEM WITH SINGLE CHARCATER
data segment
strip db 'aarrbccddeeffffz ','$'
count equ $-strip
strop db count+1 dup(?)
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ch,count
lea si,strip
lea di,strop
inc di
loopin:
mov cl,ch
mov bp,si
mov al,[bp]
chek:
dec cl
jz copy
inc bp
cmp al,[bp]
jne chek
jmp loopout
copy:
inc di
mov [di],al
loopout:
inc si
dec ch
jnz loopin
mov ah,09h
lea dx,strip
int 21h
lea dx,strop
int 21h
int 3
code ends
end start
data segment
strip db 'aarrbccddeeffffz ','$'
count equ $-strip
strop db count+1 dup(?)
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ch,count
lea si,strip
lea di,strop
inc di
loopin:
mov cl,ch
mov bp,si
mov al,[bp]
chek:
dec cl
jz copy
inc bp
cmp al,[bp]
jne chek
jmp loopout
copy:
inc di
mov [di],al
loopout:
inc si
dec ch
jnz loopin
mov ah,09h
lea dx,strip
int 21h
lea dx,strop
int 21h
int 3
code ends
end start
Subscribe to:
Posts (Atom)