Additions:
===Venerdì 20 e martedì 24 ottobre 2017 (Lezione 6 - 90 min) - Demetrescu/Coppa===
Additions:
# int sumsqr(int* v, int n) { // v <-> esi, n <-> edi, s <-> ebx
Deletions:
# int sumsqr(int* v, int n) { // v <-> esi, n <-> edi, s <-> ebx
Additions:
# int sumsqr(int* v, int n) { // v <-> esi, n <-> edi, s <-> ebx
Deletions:
# int sumsqr(int* v, int n) { # v <-> esi, n <-> edi, s <-> ebx
Additions:
%%(c;f.s)
Deletions:
%%(c, f.s.)
Deletions:
==Esercizio: calcolo espressione con LEA==
int f(int x, int y) {
return x+2*y-7;
%%(c,f.s)
movl 4(%esp), %ecx
movl 8(%esp), %edx
leal -7(%ecx, %edx, 2), %eax
Additions:
movl 20(%esp), %esi # esi <- v
movl 24(%esp), %edi # edi <- n
movl $0, %ebx # int s = 0;
L: cmpl $0, %edi # L: if (n<=0) goto E;
decl %edi # n--;
addl %eax, %ebx # s += sqr(v[n]);
jmp L # goto L;
E: movl %ebx, %eax # E: return s;
Deletions:
movl 20(%esp), %esi # esi <- v
movl 24(%esp), %edi # edi <- n
movl $0, %ebx # int s = 0;
L: cmpl $0, %edi # L:if (n<=0) goto E;
decl %edi # n--;
addl %eax, %ebx # s += sqr(v[n]);
jmp L # goto L;
E: movl %ebx, %eax # E:return s;
Additions:
movl 20(%esp), %esi # esi <- v
movl 24(%esp), %edi # edi <- n
movl $0, %ebx # int s = 0;
L: cmpl $0, %edi # L:if (n<=0) goto E;
decl %edi # n--;
addl %eax, %ebx # s += sqr(v[n]);
jmp L # goto L;
E: movl %ebx, %eax # E:return s;
Deletions:
movl 20(%esp), %esi # esi <- v
movl 24(%esp), %edi # edi <- n
movl $0, %ebx # int s = 0;
L: cmpl $0, %edi # L:if (n<=0) goto E;
decl %edi # n--;
addl %eax, %ebx # s += sqr(v[n]);
jmp L # goto L;
E: movl %ebx, %eax # E:return s;
Additions:
# int sumsqr(int* v, int n) { # v <-> esi, n <-> edi, s <-> ebx
# int s = 0;
# while (n>0) {
# n--;
# s += sqr(v[n]);
# }
# return s;
.globl sumsqr
sumsqr:
movl 20(%esp), %esi # esi <- v
movl 24(%esp), %edi # edi <- n
movl $0, %ebx # int s = 0;
L: cmpl $0, %edi # L:if (n<=0) goto E;
decl %edi # n--;
movl (%esi, %edi, 4), %eax
addl %eax, %ebx # s += sqr(v[n]);
jmp L # goto L;
E: movl %ebx, %eax # E:return s;
Deletions:
.globl sommaQuadrati
sommaQuadrati:
# prologo
#
movl 20(%esp), %esi # v <-> esi
movl 24(%esp), %edi # n <-> edi
movl $0, %ebx # s <-> ebx
L:
cmpl $0, %edi
decl %edi
movb (%esi, %edi, 1), %al
movsbl %al, %eax
addl %eax, %ebx
jmp L
E:
movl %ebx, %eax
# epilogo
Additions:
%%(c;test-equiv.c)
Deletions:
%%(c)
Additions:
%%(c)
a |= c;
a &= c;
Deletions:
a = a | c;
a = a & c;
Additions:
int si, di, d;
char a, c;
si = min;
di = max;
d = *x;
a = d < si;
c = d > di;
a = a | c;
c = di > si;
a = a & c;
return (int)a;
Additions:
==Esercizio: calcolo espressione con LEA==
int f(int x, int y) {
return x+2*y-7;
%%(c,f.s)
movl 4(%esp), %ecx
movl 8(%esp), %edx
leal -7(%ecx, %edx, 2), %eax
==Esercizio: SETcc (esempio esonero 2016/2017)==
Deletions:
==Esercizio SETcc (esempio esonero 2016/2017)==
Additions:
subl $8, %esp # prologo
leal 4(%esp), %eax
call g
movl 4(%esp), %eax
addl $8, %esp # epilogo
*p = 23;
printf("%d\n", f());
Deletions:
subl $8, %esp # prologo
leal 4(%esp), %eax
movl %eax, (%esp)
call g
movl 4(%esp), %eax
addl $8, %esp # epilogo
ret
*p = 23;
printf("%d\n", f());
return 0;
Additions:
subl $8, %esp # prologo
leal 4(%esp), %eax
movl %eax, (%esp)
call g
movl 4(%esp), %eax
addl $8, %esp # epilogo
ret
%%(c;main.c)
int f();
void g(int * p) {
*p = 23;
printf("%d\n", f());
return 0;
Deletions:
subl $8, %esp # prologo
leal 4(%esp), (%esp)
call g
movl 4(%esp), %eax
addl $8, %esp # epilogo
Additions:
==Esercizio ripasso: array + passaggio parametri + registri callee-save + cast==
==Esercizio: variabili locali con LEA==
%%(c; f.c)
int f() {
int x;
g(&x);
return x;
%%(c, f.s.)
.globl f
f:
subl $8, %esp # prologo
leal 4(%esp), (%esp)
call g
movl 4(%esp), %eax
addl $8, %esp # epilogo
Deletions:
==Esercizio ripasso: array + passaggio parametri + registri callee-save ==
Additions:
movl $0, %ebx # s <-> ebx
Deletions:
movl $0, %ebx # s <-> ebx
Additions:
char v[] = {2,3,4};
Deletions:
char v = {2,3,4};
No differences.
Additions:
%%(c; main.c)
#include
int sommaQuadrati(char * v, int n);
int main() {
char v = {2,3,4};
printf("res=%d (atteso: %d)\n", sommaQuadrati(v, 3), 29);
return 0;