reyyetry
8086 PROGRAMS
Thursday, 21 July 2016
Thursday, 6 August 2015
Sorting of Array
.model small
printmsg macro
msg
push ax
push dx
lea dx,msg
mov ah,09h
int 21h
pop dx
pop ax
endm
.data
msg4 db 0ah,0dh,"Enter the
limit$"
msg1 db 0ah,0dh,"Enter the
numbers$"
a dw 20 dup(0)
n dw ?
cnt dw 0
num dw 0
.code
mov ax,@data
mov ds,ax
printmsg msg4
call readnum
mov cx,num
mov n,cx
printmsg msg1
mov si,00h
l1:
call readnum
mov ax,num
mov a[si],ax
add si,02h
loop l1
mov cx,n
dec cx
l4: push cx
mov di,00
l3: mov ax,a[di]
cmp ax,a[di+2]
jng l2
xchg ax,a[di+2]
xchg ax,a[di]
l2:
add di,02h
loop l3
pop cx
loop l4
mov cx,n
mov si,00h
l6:
mov ax,a[si]
mov num,ax
call print
add si,02h
loop l6
l5: mov ah,4ch
int 21h
readnum proc near
push ax
push bx
push cx
push dx
mov num,00h
next1:
mov ah,01h
int 21h
cmp al,0dh
je next2
sub al,30h
mov cx,ax
and cx,00ffh
mov ax,num
mov bx,10
mul bx
mov num,ax
add num,cx
jmp next1
next2:
pop dx
pop cx
pop bx
pop ax
ret
readnum endp
print proc near
push ax
push bx
push cx
push dx
mov ax,num
mov bx,10
next3:
mov dx,00
div bx
push dx
inc cnt
cmp ax,00
jne next3
next4:
cmp cnt,00
je next5
pop dx
add dl,30h
dec cnt
mov ah,02h
int 21h
jmp next4
next5:
pop dx
pop cx
pop bx
pop ax
ret
print endp
end
Friday, 19 September 2014
Decimal Number to Binary
.model small
printmsg macro msg
push ax
push dx
lea dx,msg
mov ah,09h
int 21h
pop dx
pop ax
endm
.data
msg1 db 0ah,0dh,"Enter Decimal:$"
msg2 db 0ah,0dh,"Binary is:$"
cnt dw 0
num dw 0
a dw 0
.code
mov ax,@data
mov ds,ax
printmsg msg1
call readnum
mov bx,num
mov cx,10h
l7: mov ax,bx
and ax,0001
shr bx,01
add al,30h
push ax
inc cnt
loop l7
mov cx,cnt
printmsg msg2
l8:pop ax
mov dl,al
mov ah,02h
int 21h
loop l8
ext:mov ah,4ch
int 21h
readnum proc near
push ax
push bx
push cx
push dx
mov num,00h
next1:
mov ah,01h
int 21h
cmp al,0dh
je next2
sub al,30h
mov cx,ax
and cx,00ffh
mov ax,num
mov bx,10
mul bx
mov num,ax
add num,cx
jmp next1
next2:
pop dx
pop cx
pop bx
pop ax
ret
readnum endp
end
printmsg macro msg
push ax
push dx
lea dx,msg
mov ah,09h
int 21h
pop dx
pop ax
endm
.data
msg1 db 0ah,0dh,"Enter Decimal:$"
msg2 db 0ah,0dh,"Binary is:$"
cnt dw 0
num dw 0
a dw 0
.code
mov ax,@data
mov ds,ax
printmsg msg1
call readnum
mov bx,num
mov cx,10h
l7: mov ax,bx
and ax,0001
shr bx,01
add al,30h
push ax
inc cnt
loop l7
mov cx,cnt
printmsg msg2
l8:pop ax
mov dl,al
mov ah,02h
int 21h
loop l8
ext:mov ah,4ch
int 21h
readnum proc near
push ax
push bx
push cx
push dx
mov num,00h
next1:
mov ah,01h
int 21h
cmp al,0dh
je next2
sub al,30h
mov cx,ax
and cx,00ffh
mov ax,num
mov bx,10
mul bx
mov num,ax
add num,cx
jmp next1
next2:
pop dx
pop cx
pop bx
pop ax
ret
readnum endp
end
Subscribe to:
Posts (Atom)