write macro s lea dx,s mov ah,9 int 21h endm sseg segment stack db 64 dup(?) sseg ends dseg segment cnt dw 0 offs dw str_arr,255 dup(?) str_arr db 60000 dup(?) idx_arr db 255 dup(?) mlen db 255 alen db ? str db 255 dup(?) ln db 13,10,'$' dseg ends cseg segment assume cs:cseg,ss:sseg,ds:dseg strcmp proc near;in: ah=idx_s1, al=idx_s2; out: ax=1/0/-1, s1>=<s2 push bx cx xor bx,bx mov bl,al shl bl,1 mov cx,offs[bx+2] mov si,offs[bx] sub cx,si xor bx,bx mov bl,ah shl bl,1 mov dx,offs[bx+2] mov di,offs[bx] sub dx,di ;[si]->s1; [di]->s2; cx=strlen(s1); dx=strlen(s2); cmp cx,dx jle s1longer mov cx,dx s1longer: repe cmpsb mov ah,[si-1] mov al,[di-1] cmp ah,al jg s1gr je eq mov ax,-1 jmp _ret s1gr: mov ax,1 jmp _ret eq: xor ax,ax _ret: pop cx bx ret strcmp endp main proc far push ds xor ax,ax push ax mov ax,dseg mov ds,ax mov es,ax ;------------- input: mov ah,10 lea dx,mlen int 21h;read string write ln xor ch,ch mov cl,alen test cl,cl;is string empty? jz in_over lea si,str;prepare for copy string to array mov bx,cnt shl bx,1 mov di,offs[bx] rep movsb;copy string to array mov byte ptr[di],0 inc di shr bx,1 mov idx_arr[bx],bl inc bx mov cnt,bx shl bx,1 mov offs[bx],di jmp input in_over: mov cx,cnt test cx,cx jnz strings_are ret strings_are: cmp cx,1 je output dec cx sort1: mov bp,cx xor bx,bx sort2: mov ax,word ptr idx_arr[bx] call strcmp cmp ax,1 jne next_iter mov ax,word ptr idx_arr[bx] xchg ah,al mov word ptr idx_arr[bx],ax next_iter: inc bx loop sort2 mov cx,bp loop sort1 mov cx,cnt output: mov bx,cnt sub bx,cx mov bl,idx_arr[bx] shl bx,1 mov di,offs[bx+2] mov byte ptr[di-1],'$' mov dx,offs[bx] mov ah,9 int 21h write ln loop output ;------------- ret main endp cseg ends end main |