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 [3194]

Last edited on 2017-10-31 07:44:07 by CamilDemetrescu
Additions:
===Lunedì 23 e giovedì 26 ottobre 2017 (Lezione 7 - 150 min) - Demetrescu/Coppa===
Deletions:
==Lunedì 23 e giovedì 26 ottobre 2017 (Lezione 7 - 150 min) - Demetrescu/Coppa==


Revision [3193]

Edited on 2017-10-31 07:43:52 by CamilDemetrescu
Additions:
==Lunedì 23 e giovedì 26 ottobre 2017 (Lezione 7 - 150 min) - Demetrescu/Coppa==


Revision [3171]

Edited on 2017-10-24 08:21:23 by CamilDemetrescu
Additions:
== Esercizio 2 (compito C, esonero 2016/2017)==
%%(c;es-equiv.c)
void arrayCrossMean(unsigned* x, // x <-> eax
unsigned* y, // y <-> ebx
unsigned* z, // z <-> ecx
unsigned n) {
unsigned temp; // temp <-> esi
unsigned* end = x; // end <-> edx
end += n;
y += n;
y--;
L: if (x >= end) goto E;
temp = *x;
temp += *y;
*z = temp; // *x + *y
if (temp == 0) goto F;
*z >>= 1; // *z = (*z) >> 1
F: x++;
z++;
y--;
goto L;
E: ;
# void arrayCrossMean(unsigned* x, // x <-> eax
# unsigned* y, // y <-> ebx
# unsigned* z, // z <-> ecx
# unsigned n) {
pushl %ebx # prologo
movl 12(%esp), %eax # carico x
movl 16(%esp), %ebx # carico y
movl 20(%esp), %ecx # carico z
# unsigned temp; // temp <-> esi
movl %eax, %edx # unsigned* end = x; // end <-> edx
movl 24(%esp), %esi
imull $4, %esi # esi == 4*n
addl %esi, %edx # end += n;
addl %esi, %ebx # y += n;
subl $4, %ebx # y--;
L: cmpl %edx, %eax # if (x >= end)
jae E # goto E;
movl (%eax), %esi # temp = *x;
addl (%ebx), %esi # temp += *y;
movl %esi, (%ecx) # *z = temp; // *x + *y
testl %esi, %esi # if (temp == 0)
je F # goto F;
shrl (%ecx) # *z >>= 1; // *z = (*z) >> 1
F: addl $4, %eax # x++;
addl $4, %ecx # z++;
subl $4, %ebx # y--;
jmp L # goto L;
E: popl %esi # epilogo
//Suggerimento//: semplificare la soluzione sopra usando l'istruzione LEA.
Deletions:
== Esercizio 2 (es2, compito C, esonero 2016/2017)==
pushl %ebx
pushl %edi
movl 16(%esp), %ebx # x <-> ebx
movl 20(%esp), %edi # y <-> edi
movl 24(%esp), %esi # z <-> esi
movl 28(%esp), %ecx # n <-> ecx
leal (%ebx, %ecx, 4), %eax # end = x+n end <-> %eax
leal -4(%edi, %ecx, 4), %edi # y = y+n-1
W: cmpl %eax, %ebx
jge E
movl (%ebx), %edx # *x
addl (%edi), %edx # *x+*y
movl %edx, (%esi) # *z = *x + *y
testl %edx, %edx
jz U
shrl %edx # shift logico a destra di 1
movl %edx, (%esi)
U: addl $4, %ebx
addl $4, %esi
subl $4, %edi
jmp W
E: popl %esi
popl %edi


Revision [3167]

Edited on 2017-10-24 06:23:41 by CamilDemetrescu
Additions:
== Esercizio 2 (es2, compito C, esonero 2016/2017)==
Deletions:
==Esercizio 2 (es2 dell'esonero di prova)==
Tradurre in IA32 la funzione C ##fix##.
%%(c;fix.c)
int media(int,int);
void fix(const int* u, int* v, int n) {
int i;
for (i=0; i int m = media(u[i],u[i+1]);
if (m > media(v[i],v[i+1])) v[i]=m;
%%(c; main.c)
void fix(int* u, const int* v, int n);
int a[] = { 10, 20, 30, 40 };
int b[] = { 0, 25, 28, 30 };
fix(a,b,4);
printf("%d|%d|%d|%d (corretto=15|25|35|30)\n",
b[0], b[1], b[2], b[3]);
%%(c;media.s)
.globl media
media:
movl 8(%esp), %eax
addl 4(%esp), %eax
xorl %ecx, %ecx
movl %eax, %edx
shrl $31, %edx
addl %edx, %eax
sarl %eax
%%(c;fix.s)
.globl fix
fix:
movl 16(%esp), %ebx # u
movl 20(%esp), %esi # v
xorl %edi, %edi # i
L: movl 24(%esp), %ecx # rileggo n ad ogni iterazione: media() sporca %ecx
decl %ecx
cmpl %ecx, %edi
subl $8, %esp
movl 4(%ebx, %edi, 4), %eax # u[i+1]
movl %eax, 4(%esp)
movl (%ebx, %edi, 4), %eax # u[i]
movl %eax, (%esp)
call media
addl $8, %esp
pushl %eax # m
subl $8, %esp
movl 4(%esi, %edi, 4), %eax # v[i+1]
movl %eax, 4(%esp)
movl (%esi, %edi, 4), %eax # v[i]
movl %eax, (%esp)
call media
addl $8, %esp
popl %edx # m
incl %edi # i++
cmpl %eax, %edx #
jle L
movl %edx, -4(%esi, %edi, 4) # i è stato incrementato quindi -4
jmp L
E: popl %edi
popl %esi
== Esercizio 3 (es2, compito C, esonero 2016/2017)==


Revision [3166]

Edited on 2017-10-24 06:22:51 by CamilDemetrescu
Additions:
leal (%ebx, %ecx, 4), %eax # end = x+n end <-> %eax
leal -4(%edi, %ecx, 4), %edi # y = y+n-1
shrl %edx # shift logico a destra di 1
Deletions:
leal (%ebx, %ecx, 4), %eax # end = x+n end <-> %eax
leal -4(%edi, %ecx, 4), %edi # y = y+n-1
shrl %edx # shift logico a destra di 1


Revision [3165]

Edited on 2017-10-24 06:22:25 by CamilDemetrescu
Additions:
==Esercizio 1==
movl 16(%esp), %ebx # x <-> ebx
movl 20(%esp), %edi # y <-> edi
movl 24(%esp), %esi # z <-> esi
movl 28(%esp), %ecx # n <-> ecx
leal (%ebx, %ecx, 4), %eax # end = x+n end <-> %eax
shrl %edx # shift logico a destra di 1
Deletions:
==Esercizio 1 (es1 seconda esercitazione IA32)==
movl 16(%esp), %ebx # x
movl 20(%esp), %edi # y
movl 24(%esp), %esi # z
movl 28(%esp), %ecx # n
leal (%ebx, %ecx, 4), %eax # end = x+n
shrl %edx


Revision [3164]

The oldest known version of this page was created on 2017-10-24 06:20:03 by CamilDemetrescu
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.0319 seconds