Ensamblador - Ayuda con la función asm() dentro de un código en c

 
Vista:

Ayuda con la función asm() dentro de un código en c

Publicado por Paloma (1 intervención) el 06/05/2018 16:07:20
Hola chic@s, recién inicio con la programación en ensamblador acabo de instalar Kubuntu a mi notebook y queria ver si pueden ayudarme con estos códigos de ordenamiento, uno es el de Shellsort y otro es el de Cocktailsort, están en lenguaje c pero la función o bien el método es el que quiero poner con la instrucción asm(), ya lo puse, corren pero el de Shellsort me retorna la cadena de números tal cual el usuario la ingresa, no los ordena. El cocktailsort no me regresa nada. espero me puedan ayudar

CÓDIGO SHELLSORT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<stdio.h>
int main()
{
    int arr[30];
    int i,j,k,tmp,  num;
    printf("\n¿Cuantos elementos desea odenar? ");
    scanf("%d", &num);
    printf("\nIngrese %d numeros: ", num);
 
    for (k =  0 ; k < num; k++)
    {
        scanf("%d", &arr[k]);
    }
    asm(
    "movl   -152(%ebp), %eax\n\t"
    "movl   %eax, %edx\n\t"
    "shrl   $31, %edx\n\t"
    "addl   %edx, %eax\n\t"
    "sarl   %eax\n\t"
    "movl   %eax, -148(%ebp)\n\t"
    "jmp    L4\n\t"
    "L11:\n\t"
    "movl   -148(%ebp), %eax\n\t"
    "movl   %eax, -144(%ebp)\n\t"
    "jmp    L5\n\t"
    "L10:\n\t"
    "movl   -144(%ebp), %eax\n\t"
    "subl   -148(%ebp), %eax\n\t"
    "movl   %eax, -140(%ebp)\n\t"
    "jmp    L6\n\t"
    "L9:\n\t"
    "movl   -140(%ebp), %edx\n\t"
    "movl   -148(%ebp), %eax\n\t"
    "addl   %edx, %eax\n\t"
    "movl   -132(%ebp,%eax,4), %edx\n\t"
    "movl   -140(%ebp), %eax\n\t"
    "movl   -132(%ebp,%eax,4), %eax\n\t"
    "cmpl   %eax, %edx\n\t"
    "jge    L16\n\t"
    "movl   -140(%ebp), %eax\n\t"
    "movl   -132(%ebp,%eax,4), %eax\n\t"
    "movl   %eax, -136(%ebp)\n\t"
    "movl   -140(%ebp), %edx\n\t"
    "movl   -148(%ebp), %eax\n\t"
    "addl   %edx, %eax\n\t"
    "movl   -132(%ebp,%eax,4), %edx\n\t"
    "movl   -140(%ebp), %eax\n\t"
    "movl   %edx, -132(%ebp,%eax,4)\n\t"
    "movl   -140(%ebp), %edx\n\t"
    "movl   -148(%ebp), %eax\n\t"
    "addl   %eax, %edx\n\t"
    "movl   -136(%ebp), %eax\n\t"
    "movl   %eax, -132(%ebp,%edx,4)\n\t"
    "movl   -148(%ebp), %eax\n\t"
    "subl   %eax, -140(%ebp)\n\t"
    "L6:\n\t"
    "cmpl   $0, -140(%ebp)\n\t"
    "jns    L9\n\t"
    "jmp    L8\n\t"
    "L16:\n\t"
    "nop\n\t"
    "L8:\n\t"
    "addl   $1, -144(%ebp)\n\t"
    "L5:\n\t"
    "movl	-152(%ebp), %eax\n\t"
    "cmpl	%eax, -144(%ebp)\n\t"
    "jl	L10\n\t"
    "movl   -148(%ebp), %eax\n\t"
    "movl   %eax, %edx\n\t"
    "shrl   $31, %edx\n\t"
    "addl   %edx, %eax\n\t"
    "sarl   %eax\n\t"
    "movl   %eax, -148(%ebp)\n\t"
    "L4:\n\t"
    "cmpl   $0, -148(%ebp)\n\t"
    "jg	L11\n\t"
    );
    printf("\nVector ordenado con shellsort\n");
    for (k = 0; k < num; k++)
        printf("%d ", arr[k]);
    printf("\n");
    return 0;
}


CÓDIGO COCKTAILSORT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<stdio.h>
#define MAX 50
int main()
{
      int a[MAX],b[MAX];
      int n,i,j,sw=1,temp;
      printf("\n¿Cuantos elementos desea odenar? ");
      scanf("%d",&n);
      printf("\nDato: ");
      for(i=0;i<n;i++)
      {
          scanf("%d",&a[i]);
          b[i]=a[i];
      }
      sw=1;
      asm(	"movl	$1, -420(%ebp)\n\t"
	"movl	$0, -428(%ebp)\n\t"
	"jmp	L4\n\t"
"L10:\n\t"
	"movl	$0, -420(%ebp)\n\t"
	"movl	$0, -424(%ebp)\n\t"
	"jmp	L5\n\t"
"L8:\n\t"
	"movl	-424(%ebp), %eax\n\t"
	"movl	-212(%ebp,%eax,4), %edx\n\t"
	"movl	-424(%ebp), %eax\n\t"
	"addl	$1, %eax\n\t"
	"movl	-212(%ebp,%eax,4), %eax\n\t"
	"cmpl	%eax, %edx\n\t"
	"jle	L6\n\t"
	"movl	-424(%ebp), %eax\n\t"
	"addl	$1, %eax\n\t"
	"movl	-212(%ebp,%eax,4), %eax\n\t"
	"movl	%eax, -416(%ebp)\n\t"
	"movl	-424(%ebp), %eax\n\t"
	"leal	1(%eax), %edx\n\t"
	"movl	-424(%ebp), %eax\n\t"
	"movl	-212(%ebp,%eax,4), %eax\n\t"
	"movl	%eax, -212(%ebp,%edx,4)\n\t"
	"movl	-424(%ebp), %eax\n\t"
	"movl	-416(%ebp), %edx\n\t"
	"movl	%edx, -212(%ebp,%eax,4)\n\t"
	"movl	$1, -420(%ebp)\n\t"
"L6:\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$1, %eax\n\t"
	"subl	-424(%ebp), %eax\n\t"
	"movl	-212(%ebp,%eax,4), %edx\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$2, %eax\n\t"
	"subl	-424(%ebp), %eax\n\t"
	"movl	-212(%ebp,%eax,4), %eax\n\t"
	"cmpl	%eax, %edx\n\t"
	"jge	L7\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$2, %eax\n\t"
	"subl	-424(%ebp), %eax\n\t"
	"movl	-212(%ebp,%eax,4), %eax\n\t"
	"movl	%eax, -416(%ebp)\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$1, %eax\n\t"
	"subl	-424(%ebp), %eax\n\t"
	"movl	%eax, %edx\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$2, %eax\n\t"
	"subl	-424(%ebp), %eax\n\t"
	"movl	-212(%ebp,%edx,4), %edx\n\t"
	"movl	%edx, -212(%ebp,%eax,4)\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$1, %eax\n\t"
	"subl	-424(%ebp), %eax\n\t"
	"movl	-416(%ebp), %edx\n\t"
	"movl	%edx, -212(%ebp,%eax,4)\n\t"
	"movl	$1, -420(%ebp)\n\t"
"L7:\n\t"
	"addl	$1, -424(%ebp)\n\t"
"L5:\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$1, %eax\n\t"
	"subl	-428(%ebp), %eax\n\t"
	"cmpl	%eax, -424(%ebp)\n\t"
	"jl	L8\n\t"
	"addl	$1, -428(%ebp)\n\t"
"L4:\n\t"
	"movl	-432(%ebp), %eax\n\t"
	"subl	$1, %eax\n\t"
	"cmpl	%eax, -428(%ebp)\n\t"
	"jge	L9\n\t"
    "cmpl	$1, -420(%ebp)\n\t"
    "je	L10\n\t"
    "L9:\n\t"
);
      printf("\nVector ordenado con cocktailsort\n");
      for(j=0;j<n;j++)
         printf("%d\t",b[j]);
      printf("\n");
      return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder