Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 汇编中的整数排序_Sorting_Assembly_Bubble Sort - Fatal编程技术网

Sorting 汇编中的整数排序

Sorting 汇编中的整数排序,sorting,assembly,bubble-sort,Sorting,Assembly,Bubble Sort,该项目将在程序集中创建一个冒泡排序算法,该算法将对给定的整数列表进行排序。我有上升下降,我的输出在某种程度上是正确的。似乎当组合数字的顺序变得混乱时,我的意思是: 10-20512130-5-225520 整数个数=10 上升或下降=1 051012305255-22-20-5 以下是代码,包括测试的主要方法: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <io.

该项目将在程序集中创建一个冒泡排序算法,该算法将对给定的整数列表进行排序。我有上升下降,我的输出在某种程度上是正确的。似乎当组合数字的顺序变得混乱时,我的意思是:

10-20512130-5-225520

整数个数=10 上升或下降=1

051012305255-22-20-5

以下是代码,包括测试的主要方法:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>

int sorter (int* list, int count, int opcode)
{
__asm
{
mov eax, 0          ; zero out the result
mov ebx, opcode     ; move opcode to ebx for comparison

mov ecx, count; //OuterLoop counter
cmp ecx, 1; //check length  
jle Return;  

OuterLoop:
   mov edi, list; //move in list    
   push ecx; 

   mov ecx, count; 
   dec ecx; //Decrement inner loop
InnerLoop:
   mov eax, [edi]; //First Value in list
   cmp ebx, 1; 
   je  Ascending; 
   cmp eax, [edi+4]; //next int is 4 bits away
   jb  Swap; 
   jmp Continue; 
Ascending:
   cmp eax, [edi+4]; //Again compare with next int
   ja  Swap; //if no swap
   jmp Continue; 
Swap:
   mov edx, [edi+4]; //Move to temp register
   mov [edi+4], eax; //Move stored value there
   mov [edi], edx; //Return temp value to list
Continue:
   add edi, 4; //Increment to move to next int
   loop InnerLoop; 
   pop ecx; //reset counter
   loop OuterLoop; 
Return:; 
}

}


int main(int argc, char** argv)
{
int numlist[1000], asc;
FILE *fptr;

int i = 0;

if (argc != 3)
{
    printf("Usage: %s filename asc_des\n", argv[0]);
    return 1;
}

asc = atoi (argv[2]);
asc = (asc == 1) ? 1 : 2;

printf("\n");

fptr = fopen((argv[1]), "rtc");
if (fptr == NULL)
  printf( "File %s was not opened\n",argv[1] );
else
{
  /* Set pointer to beginning of file: */
  fseek( fptr, 0L, SEEK_SET );

  /* Read data from file: */
  while ( fscanf(fptr, "%d", &numlist[i]) != EOF )
  {
      printf( "%d ", numlist[i] );
      i++;
  }

  printf( "\n\nNumber of integer = %d\n", i );
  printf( "Ascend_or_Descend = %d\n\n", asc );
  fclose( fptr );
  }

  sorter( numlist, i, asc);

  for (int j = 0; j < i; j++)
      printf( "%d ", numlist[j] );

  printf("\n");

  return 0;
  }
#包括
#包括
#包括
#包括
内部分拣机(内部*列表、内部计数、内部操作码)
{
__asm
{
mov eax,0;将结果归零
mov ebx,操作码;将操作码移动到ebx进行比较
mov ecx,count;//OuterLoop计数器
cmp ecx,1;//检查长度
jle返回;
外部环路:
mov edi,列表;//移入列表
推动ecx;
mov-ecx,计数;
dec ecx;//递减内循环
内循环:
mov eax,[edi];//列表中的第一个值
cmp-ebx,1;
乙脑上升;
cmp eax,[edi+4];//下一个int距离为4位
jb互换;
jmp继续;
提升:
cmp eax,[edi+4];//再次与下一个int进行比较
ja Swap;//如果没有交换
jmp继续;
互换:
mov edx,[edi+4];//移动到临时寄存器
mov[edi+4],eax;//将存储值移到那里
mov[edi],edx;//将临时值返回列表
继续:
添加edi,4;//递增以移动到下一个int
内环;
pop ecx;//重置计数器
环外环;
返回:;
}
}
int main(int argc,字符**argv)
{
int numlist[1000],asc;
文件*fptr;
int i=0;
如果(argc!=3)
{
printf(“用法:%s文件名asc_des\n”,argv[0]);
返回1;
}
asc=atoi(argv[2]);
asc=(asc==1)?1:2;
printf(“\n”);
fptr=fopen((argv[1]),“rtc”);
如果(fptr==NULL)
printf(“文件%s未打开,\n”,argv[1]);
其他的
{
/*设置指向文件开头的指针:*/
fseek(fptr,0L,SEEK_SET);
/*从文件中读取数据:*/
而(fscanf(fptr、%d、&numlist[i])!=EOF)
{
printf(“%d”,numlist[i]);
i++;
}
printf(“\n\n整数的数目=%d\n”,i);
printf(“上升或下降=%d\n\n”,asc);
fclose(fptr);
}
分拣机(numlist、i、asc);
对于(int j=0;j
来自英特尔手册:

术语“上方”和“下方”与
CF
标志相关联,指的是两个无符号标记之间的关系 整数值。术语“较大”和“较小”与
标志的
SF
相关联,并指关系
在两个有符号整数值之间

通过使用
jb
ja
可以将比较结果视为无符号比较的结果,因此,有符号数字最终位于排序数组的末尾(例如,当解释为无符号32位值时,-22是4294967274)

您应该使用英特尔手册中的
jl
而不是
jb
,以及
jg
而不是
ja

术语“上方”和“下方”与
CF
标志相关联,指的是两个无符号标记之间的关系 整数值。术语“较大”和“较小”与
标志的
SF
相关联,并指关系
在两个有符号整数值之间

通过使用
jb
ja
可以将比较结果视为无符号比较的结果,因此,有符号数字最终位于排序数组的末尾(例如,当解释为无符号32位值时,-22是4294967274)


您应该使用
jl
而不是
jb
,使用
jg
而不是
ja

很抱歉,您的回答很晚,但您是正确的。新来的,谢谢!很抱歉反应太晚,但你是对的。新来的,谢谢!