Sistemi di Calcolo

Corso di Laurea in Ingegneria Informatica e Automatica - A.A. 2017-2018

HomePage | Avvisi | Diario lezioni | Programma | Materiale didattico | Esami | Forum | Login

Revision [2268]

Last edited on 2016-11-07 20:00:35 by DanieleDelia
Additions:
Variante di ##bubblesort## che ad ogni chiamata ##makepass## rilegge dallo stack frame del chiamante i parametri da passare:
Deletions:
Variante di ##bubblesort## che rilegge dallo stack frame del chiamante i valori dei parametri da passare:


Revision [2267]

Edited on 2016-11-07 19:59:55 by DanieleDelia
Additions:
jne bubblesort
Deletions:
R: subl $8, %esp
jne R


Revision [2266]

Edited on 2016-11-07 19:58:40 by DanieleDelia
Additions:
Variante di ##bubblesort## che utilizza i registri ##caller-save## per il passaggio dei parametri, preservandone il contenuto:
Variante di ##bubblesort## che rilegge dallo stack frame del chiamante i valori dei parametri da passare:
R: subl $8, %esp
movl 12(%esp), %eax
movl %eax, (%esp)
movl 16(%esp), %eax
jne R
Deletions:
Variante di ##bubblesort## che utilizza i registri ##caller-save## per il passaggio dei parametri:


Revision [2265]

Edited on 2016-11-07 19:53:11 by DanieleDelia
Additions:
L: subl $8, %esp
L: pushl %ecx
Deletions:
L:
L:
pushl %ecx


Revision [2249]

Edited on 2016-11-07 14:52:10 by DanieleDelia

No differences.

Revision [2248]

Edited on 2016-11-07 14:50:59 by DanieleDelia

No differences.

Revision [2247]

Edited on 2016-11-07 14:49:03 by DanieleDelia
Additions:
Variante di ##bubblesort## che utilizza i registri ##caller-save## per il passaggio dei parametri:
%%(c;)
movl 4(%esp), %ecx
movl 8(%esp), %edx
pushl %ecx
pushl %edx
movl %ecx, (%esp)
movl %edx, 4(%esp)
popl %ecx
popl %edx


Revision [2246]

Edited on 2016-11-07 14:41:33 by DanieleDelia

No differences.

Revision [2245]

Edited on 2016-11-07 14:41:21 by DanieleDelia

No differences.

Revision [2244]

Edited on 2016-11-07 14:40:48 by DanieleDelia
Additions:
Variante ottimizzata che ricorre a ##CMOV## in luogo di ##jl MI## per gestire la ## if ... else ## nel ciclo:


Revision [2243]

Edited on 2016-11-07 14:36:40 by DanieleDelia
Additions:
MI: movl %edi, %ecx # n = k
Deletions:
MI: movl %edi, %ecx # n = k


Revision [2242]

Edited on 2016-11-07 14:36:23 by DanieleDelia
Additions:
# v->eax, n->ecx, x->edx, m->ebx, k->edi
L: cmpl %ecx, %ebx
movl %ebx, %edi # k = m
addl %ecx, %edi # k = m+n
sarl $1, %edi # k = (m+n) >> 1
cmpl (%eax, %edi, 4), %edx # x vs v[k]
movl %edi, %ebx
incl %ebx
MI: movl %edi, %ecx # n = k
jmp E
E: popl %edi
%%(c;es1-cmov.s)
# v->eax, n->ecx, x->edx, m->ebx, k->edi
L: cmpl %ecx, %ebx
movl %ebx, %edi # k = m
addl %ecx, %edi # k = m+n
sarl $1, %edi # k = (m+n) >> 1
cmpl (%eax, %edi, 4), %edx # x vs v[k]
cmovll %edi, %ecx # n = k if (x < v[k])
leal 1(%edi), %edi
cmovgl %edi, %ebx # m = ++k if (x > v[k])
jmp E
E: popl %edi
Deletions:
L: cmpl %ecx, %ebx # n, m
movl %ebx, %esi
addl %ecx, %esi
sarl $1, %esi # k = (m+n) >> 1
cmpl (%eax, %esi, 4), %edx # v[k], x
movl %esi, %ebx
incl %ebx # m = k+1
MI: movl %esi, %ecx # n = k
jmp P
P: popl %esi


Revision [2237]

Edited on 2016-11-07 14:28:45 by DanieleDelia
Additions:
sarl $1, %esi # k = (m+n) >> 1
Deletions:
sarl $1, %esi # k = (m + n) >> 1


Revision [2236]

Edited on 2016-11-07 14:28:27 by DanieleDelia
Additions:
sarl $1, %esi # k = (m + n) >> 1
Deletions:
sarl $1, %esi # k = m + n


Revision [2235]

Edited on 2016-11-07 14:28:09 by DanieleDelia
Additions:
L: cmpl %ecx, %ebx # n, m
Deletions:
L: cmpl %ecx, %ebx # n,m


Revision [2234]

Edited on 2016-11-07 14:27:55 by DanieleDelia
Additions:


Revision [2233]

Edited on 2016-11-07 14:27:38 by DanieleDelia
Additions:
# int m = 0;
# int k = (m+n) >> 1;
# if (x == v[k]) return 1;
# if (x > v[k]) m = k+1;
# else n = k;
Deletions:
# int m = 0; // restituisce 1 <=> x è nell'array ordinato v di dimensione n
# int k = (m+n) >> 1; // indice dell'elemento a meta' fra m ed n
# if (x == v[k]) return 1; // x e' in posizione k => trovato
# if (x > v[k]) m = k+1; // x puo' essere a destra fra k+1 ed n
# else n = k; // x puo' essere a sinistra fra m e k


Revision [2232]

Edited on 2016-11-07 14:27:06 by DanieleDelia
Additions:
===Soluzioni esercitazione 3 presentate a lezione (Canale 2)===
Deletions:
===Soluzione esercitazione 3 presentate a lezione (Canale 2)===


Revision [2231]

Edited on 2016-11-07 14:26:20 by DanieleDelia
Additions:
movl 8(%esp), %eax
movl 12(%esp), %ecx
movl (%eax), %ebx
movl (%ecx), %edx
movl %ebx, (%ecx)
movl %edx, (%eax)
movl 16(%esp), %ebx # v
movl 20(%esp), %edi # n
xorl %esi, %esi # cont = 0
W: decl %edi
testl %edi, %edi
jle E
leal (%ebx, %edi, 4), %eax # &v[n]
subl $4, %eax # &v[n-1]
movl (%eax), %ecx # v[n-1]
cmpl (%ebx, %edi, 4), %ecx
jle W
movl %eax, (%esp) # &v[n-1]
addl $4, %eax # &v[n]
movl %eax, 4(%esp)
call swap
movl $1, %esi
jmp W
E: movl %esi, %eax
bubblesort:
movl 12(%esp), %ebx
movl 16(%esp), %edi
L:
movl %ebx, (%esp)
movl %edi, 4(%esp)
jne L
Deletions:
%%(c;es2.c)
void cancspazi(char* s) {
char *p = s;
while (*s != 0) {
if (*s != 32) *p++ = *s; // ' ' = 32
s++;
}
*p = 0;
}
movl 8(%esp), %eax # eax = a
movl 12(%esp), %ebx # ebx = b
movl (%eax), %ecx # ecx = *a
movl (%ebx), %edx # edx = *b
movl %ecx, (%ebx) # *b = ecx
movl %edx, (%eax) # *a = edx
makepass: # edi <-> v, esi <-> n, ebx <-> cont
movl 24(%esp), %esi # esi = v
movl 28(%esp), %edi # edi = n
xorl %ebx, %ebx # cont = 0
decl %edi # --n
testl %edi, %edi # res = n
jle E # if (res <= 0) goto E
L: leal -4(%esi,%edi,4), %eax # eax = v+n-1
movl (%eax), %ecx # ecx = v[n-1]
cmpl (%esi,%edi,4), %ecx # res = v[n-1] - v[n]
jle C # if (res <= 0) goto C
movl %eax, (%esp) # 1st param = eax = v+n-1
addl $4, %eax # eax += 4
movl %eax, 4(%esp) # 2nd param = eax = v+n
call swap # swap()
movl $1,%ebx # cont = 1
C: decl %edi # --n
testl %edi, %edi # res = n
jg L # if (res > 0) goto L
E: movl %ebx, %eax
bubblesort: # v <-> esi, n <-> edi
movl 20(%esp), %esi # esi = v
movl 24(%esp), %edi # edi = n
R: movl %esi, (%esp) # 1st param = v
movl %edi, 4(%esp) # 2nd param = n
jne R
Variante 2 (makepass):
# int makepass(int* v, int n) { // esi <-> v, edi <-> n
# int cont = 0; ebx <-> cont
# L: n--;
# if (n<=0) goto E;
# if (v[n]>=v[n-1]) goto L;
# swap(v+n, v+n-1);
# cont = 1;
# goto L;
# E: return cont;
subl $8, %esp # prologo
movl 24(%esp), %esi # v
movl 28(%esp), %edi # n
xorl %ebx, %ebx # int cont = 0; ebx <-> cont
L: decl %edi # L: n--
cmpl $0, %edi # tmp = n-0
jle E # if (tmp<=0) goto E
movl (%esi,%edi,4), %ecx # c = v[n]
cmpl -4(%esi,%edi,4), %ecx # tmp = c-v[n-1]
jge L # if (tmp>=0) goto L;
leal (%esi,%edi,4), %ecx # c = &v[n]
movl %ecx, (%esp) # 1mo param
leal -4(%esi,%edi,4), %ecx # c = &v[n-1]
movl %ecx, 4(%esp) # 2do param
call swap # swap(v+n, v+n-1);
movl $1, %ebx # cont = 1;
jmp L # goto L;
E: movl %ebx, %eax # E: return cont;
addl $8, %esp # epilogo


Revision [2228]

The oldest known version of this page was created on 2016-11-07 14:25:19 by DanieleDelia
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.0658 seconds