Thursday, January 21, 2010

8086 or MASM PROGRAM to input 9 digits and display the second biggest number that can be formed using those digits

assume ds:data1,cs:code1,ss:stack1
stack1 segment
store1 db 10,0,10 dup('$')
stack1 ends
data1 segment
msg db 0ah,0dh,'enter the 9 digit number$'
number db 12,0,12 dup('$')
msg1 db 0ah,0dh,'the rearranged order is=$'
data1 ends
stack1 segment
store db 10,0,10 dup('$')
stack1 ends
code1 segment
start;mov ax,seg data1
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
lea dx,number
mov ah,0ah
int 21h
mov cx,0008h
pass:push cx
mov cx,0008h
lea dx,number+2
mov si,dx
again:mov al,[si]
cmp al,[si+1]
jnc down
xchg al,[si+1]
xchg al,[si]
down:
inc si
loop again
pop cx
loop pass
mov al,[si]
xchg al,[si-1]
xchg al,[si]
lea dx,msg1
mov ah,09h
int 21h
lea dx,number+2
mov ah,09h
int 21h
mov ah,4ch
int 21h
code1 ends
end start

No comments:

Post a Comment