#99 Article 1046 Posted at 1995/12/18 02:59:40 by MSP-Iris (MAP4370) [SAHOU.3]
Subject: Re: Re: プログラミング作法・お題3 /1032 /1029
C+ASM 版。先日の同様、同着順位に対応。
ソート対象は63個まで、1個あたり31文字まで。
ちょっとだけ工夫。あと、ASM ルーチンの切り詰めはきちっとやりました。
----------------------------
.model small,c
.186
locals __
.code
public SORTIT
SORTIT proc near uses SI DI ES,Amj:word,Arnk:word,Anum:word,Alen:word
mov ax,ds
mov es,ax
cld
xor ax,ax
mov si,ax
mov di,ax
mov bx,Arnk
mov dx,Alen
dec si
iloop: inc si
mov ax,si
mov [bx+si],al
mov di,si
jloop: and di,di
jz nexti
__cmploop:
dec di
mov al,[bx+si]
cmp al,[bx+di]
jb __resultbelow
mov ax,si
push si
push di
mov si,Amj
mov di,si
mul dl
add si,ax
pop ax
push ax
mul dl
add di,ax
mov cx,Alen
repe cmpsb
pop di
pop si
ja jloop
je __resulteven
__resultbelow:
dec byte ptr [bx+si]
inc byte ptr [bx+di]
jmp short jloop
__resulteven:
dec byte ptr [bx+si]
jmp short jloop
nexti: cmp si,Anum
jne iloop
fin: ret
endp
end
----------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern void SORTIT (char *,char *,int,int);
void errend (s) char *s; {
printf("%s\n",s);
abort();
}
main (int argc,char *argv[]) {
static char mjstr[64][32]; static char rank[64];
int i,j;
if(argc<2|argc>64)
errend("ソート対象は1~63個です");
for(i=1;i<=argc-1;i++)
strncpy(mjstr[i],argv[i],31);
SORTIT(&mjstr[0][0],&rank[0],argc-1,32);
printf("順位 文字列\n");
for(i=1;i<=argc-1;i++) /* sorted data print */
{ /* from here */
for(j=1;j<=argc-1;j++)
{
if((unsigned int)rank[j]==i)
printf("%2i %s\n",i,argv[j]);
}
} /* ends here */
}
----------------------------
MAP4370 MSP-Iris