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

Last edited on 2017-11-06 12:09:25 by CamilDemetrescu
Additions:
~- Indirizzo: 0x1000 0x1001 0x1002 0x1003
~- Contenuto: 0xAA 0xBB 0xCC 0xDD
Deletions:
Indirizzo: 0x1000 0x1001 0x1002 0x1003
Contenuto: 0xAA 0xBB 0xCC 0xDD


Revision [3230]

Edited on 2017-11-06 12:08:34 by CamilDemetrescu
Additions:
===Fac-simile esonero Sistemi di Calcolo (SC1) A.A. 2017-18===
**Q1.** Preso da: 29/01/15 A
**Q2.** Preso da: 29/01/15 A
**Q3.** Preso da: 29/01/15 A
**Q4.** Variante: 27/01/2017 A
Deletions:
== Q1 ==
Preso da: 29/01/15 A
==Q2==
Preso da: 29/01/15 A
==Q3==
Preso da: 29/01/15 A
==Q4==
Variante: 27/01/2017 A


Revision [3229]

Edited on 2017-11-06 12:07:05 by CamilDemetrescu
Additions:
==Soluzione==
==Soluzione==
==Soluzione==
Deletions:
===Soluzione===
===Soluzione===
===Soluzione===


Revision [3228]

Edited on 2017-11-06 12:06:29 by CamilDemetrescu
Additions:
== Q1 ==
==Q2==
==Q3==
==Q4==
Deletions:
=== Q1 ===
===Q2===
===Q3===
===Q4===


Revision [3225]

Edited on 2017-11-06 10:57:11 by EmilioCoppa
Additions:
Variante: 27/01/2017 A


Revision [3224]

Edited on 2017-11-06 10:56:23 by EmilioCoppa
Additions:
===Q4===
Si assuma di operare in una architettura IA32 sul seguente frammento di memoria:
Indirizzo: 0x1000 0x1001 0x1002 0x1003
Contenuto: 0xAA 0xBB 0xCC 0xDD
Eseguendo le seguenti istruzioni:
movw $0xFFEE, 0x1000
movl 0x1000, %eax # legge all'indirizzo 0x1000
Cosa conterrĂ  il registro %eax?
A) 0xFFEECCDD
B) 0xFFEEAABB
C) 0xAABBFFEE
D) 0xEEFFBBAA


Revision [3223]

Edited on 2017-11-06 10:44:36 by EmilioCoppa
Additions:
Corrisponde al seguente codice C:
===Q2===
int f(short* v, int n);
short v[] = { 1, 2, 3, 4 };
printf("%d\n", f(v, 4));
%%(c, f.s)
f: pushl %esi
movl 12(%esp), %ecx
xorl %eax, %eax
testl %ecx, %ecx
jle L2
movl 8(%esp), %edx
xorl %eax, %eax
L1: decl %ecx
movswl (%edx,%ecx,2), %esi
addl %esi, %eax
testl %ecx, %ecx
jg L1
L2: popl %esi
Risultato:
A) 10
B) 20
C) 15
D) 5
===Q3===
int f(int x, int y) {
return x-2*y;
Codice IA32 corretto (rispetta convenzioni ABI):
f: movl 4(%esp), %eax
movl 8(%esp), %ecx
addl %ecx, %ecx
subl %ecx, %eax
f: movl 8(%esp), %eax
movl 12(%esp), %ecx
addl %ecx, %ecx
subl %ecx, %eax
f: movl 4(%esp), %eax
movl 8(%esp), %esi
addl %esi, %esi
subl %esi, %eax
f: movl 8(%esp), %eax
movl 4(%esp), %edx
addl %edx, %edx
subl %edx, %eax


Revision [3222]

Edited on 2017-11-06 10:39:34 by EmilioCoppa
Additions:
A)
Deletions:
1)


Revision [3221]

Edited on 2017-11-06 10:39:08 by EmilioCoppa
Additions:
==Esercizio 4==
=== Q1 ===
Preso da: 29/01/15 A
%%(c)
f: movl 4(%esp), %ecx
movl %ecx, %eax
negl %eax
cmovll %ecx, %eax
ret
1)
int f(int x) {
return x>0 ? -x:x;
B)
short f(short x) {
return x<0 ? -x:x;
C)
int f(int x) {
return x<0 ? -x:x;
D)
unsigned f(unsigned x) {
return x>0 ? -x:x;


Revision [3220]

Edited on 2017-11-06 10:33:31 by EmilioCoppa
Additions:
Preso da: 18/02/16 C
void mystrcat(char* a, const char* b) {
while (*a) a++;
while (*b) *a++ = *b++;
*a = 0;
void mystrcat(char* a, const char* b);
char s1[11] = "Han\0------";
char s2[17] = "Obi-Wan\0--------";
char s3[19] = "Anakin Skywalker\0-";
mystrcat(s1, " Solo");
printf("mystrcat(s1, \" Solo\")=\"%s\" [corretto=\"Han Solo\" - terminatore %s]\n",
s1, s1[8]==0 && s1[9]=='-' ? "OK" : "ERR");
mystrcat(s2, " Kenobi");
printf("mystrcat(s2, \"Kenobi\")=\"%s\" [corretto=\"Obi-Wan Kenobi\" - terminatore %s]\n",
s2, s2[14]==0 && s2[15]=='-' ? "OK" : "ERR");
mystrcat(s3, "");
printf("mystrcat(s3, \"\")=\"%s\" [corretto=\"Anakin Skywalker\" - terminatore %s]\n",
s3, s3[16]==0 && s3[17]=='-' ? "OK" : "ERR");
# void mystrcat(char* a, const char* b) {
# while (*a) a++;
# while (*b) *a++ = *b++;
# *a = 0;
.globl mystrcat
mystrcat:
movl 4(%esp), %eax # a
movl 8(%esp), %ecx # b
L1: cmpb $0, (%eax)
je L2
incl %eax
jmp L1
L2: cmpb $0, (%ecx)
je L3
movb (%ecx), %dl
movb %dl, (%eax)
incl %eax
incl %ecx
jmp L2
L3: movb $0, (%eax)
== Esercizio 2 (IA32) ==
== Esercizio 3 (ottimizzazione work) ==
Preso da: 18/02/16 C
#include "es4.h"
nodo* get(nodo* p, int i) {
for (; p != NULL && i--; p = p->next);
return p;
int sum_range(nodo* list, int a, int b) {
int i, s = 0;
for (i=a; i s += get(list, i)->info;
return s;
%%(c;es4.h)
#ifndef __ES4__
#define __ES4__
#include
typedef struct nodo nodo;
struct nodo {
int info;
nodo* next;
};
int sum_range(nodo* list, int a, int b);
#endif
#include
#include "es4.h"
#define N 100000
nodo* add_to_list(nodo* list, int val) {
nodo* p = malloc(sizeof(nodo));
assert(p != NULL);
p->info = val;
p->next = list;
return p;
nodo* init(int n) {
nodo* list = NULL;
while (n--) list = add_to_list(list, 1);
return list;
void cleanup(nodo* p) {
while (p != NULL) {
nodo* dead = p;
p = p->next;
free(dead);
}
int s;
nodo* list = init(N);
s = sum_range(list, N/2, 3*N/4);
printf("Risultato %d [corretto=%d]\n", s, N/4);
cleanup(list);
%%(c;f-opt.c)
#include "es4.h"
int sum_range(nodo* p, int a, int b) {
int i = 0, s = 0;
for (; p != NULL && inext, i++);
for (; p != NULL && inext, i++) s += p->info;
return s;


Revision [3219]

Edited on 2017-11-06 10:23:39 by EmilioCoppa
Additions:
Preso da: Esame 13/09/2017 A
vvoid str_to_upper(const char* a, char* b) {
int i=0;
do {
b[i] = a[i];
if (b[i] < 'a' || b[i] > 'z') continue; // 'a'==97, 'z'==122
to_upper(b+i);
} while (a[i++] != 0);
%%(c;to_upper.s)
# void to_lower(char* a) {
# *a -= 'a' - 'A';
.global to_upper
to_upper:
pushl %ebx
movl 8(%esp), %ebx
movl $0xABADCAFE, %eax
movl $0xDEADBEEF, %ecx
movl $0xCAFEBABE, %edx
subb $32, (%ebx)
popl %ebx
ret
void str_to_upper(char* a, char* b);
char s1[] = "[Knock@Knock]";
char c1[sizeof(s1)];
str_to_upper(s1,c1);
printf("\"%s\" [corretto: \"[KNOCK@KNOCK]\"]\n", c1);
char s2[] = "Bazinga!";
char c2[sizeof(s2)];
str_to_upper(s2,c2);
printf("\"%s\" [corretto: \"BAZINGA!\"]\n", c2);
char s3[] = ">>";
char c3[sizeof(s3)];
str_to_upper(s3,c3);
printf("\"%s\" [corretto: \">>\"]\n", c3);
char s4[] = "";
char c4[sizeof(s4)];
str_to_upper(s4,c4);
printf("\"%s\" [corretto: \"\"]\n", c4);
===Soluzione===
%%(c;f.s)
# void str_to_upper(const char* a, char* b) {
# int i=0;
# do {
# b[i] = a[i];
# if (b[i] < 'a' || b[i] > 'z') continue; // 'a'==97, 'z'==122
# to_upper(b+i);
# } while (a[i++] != 0);
# void str_to_upper(const char* a, char* b) { // a <-> esi, b <-> edi
# int i = 0; // i <-> ebx
# L: char c = a[i]; // c <-> cl
# b[i] = c;
# if (c < 97) goto C;
# if (c > 122) goto C;
# to_upper(b+i);
# C: i++;
# if (c != 0) goto L;
.globl str_to_upper
str_to_upper:
pushl %esi
pushl %edi
pushl %ebx
subl $4, %esp
movl 20(%esp), %esi
movl 24(%esp), %edi
xorl %ebx, %ebx # i = 0
L: movb (%esi, %ebx), %cl # c = a[i]
movb %cl, (%edi, %ebx) # b[i] = c
cmpb $97, %cl # if (c < 97)
jl C # goto C
cmpb $122, %cl # if (c > 122)
jg C # goto C
leal (%edi, %ebx), %ecx
movl %ecx, (%esp)
call to_upper # to_upper(b+i)
C: incl %ebx
testb %cl, %cl # if (c != 0)
jne L # goto L
E: addl $4, %esp
popl %ebx
popl %edi
popl %esi
ret
Deletions:
Preso da: Esame 20/01/2016 D
void count_space(char* s, int* c) {
*c = 0;
while (*s) {
if (*s == 32) (*c)++;
s++;
}
void count_space(char* s, int* c);
char s1[]="Star Wars 7 ";
char s2[]="Obi-Wan Kenobi";
char s3[]=" Chewbecca";
char s4[]="";
int c1, c2, c3, c4;
count_space(s1, &c1);
printf("%d [corretto = 3]\n", c1);
count_space(s2, &c2);
printf("%d [corretto = 1]\n", c2);
count_space(s3, &c3);
printf("%d [corretto = 1]\n", c3);
count_space(s4, &c4);
printf("%d [corretto = 0]\n", c4);
# void count_space(char* s, int* c) {
# *c = 0;
# while (*s) {
# if (*s == 32) (*c)++;
# s++;
# }
.globl count_space
count_space:
movl 4(%esp), %eax
movl 8(%esp), %ecx
movl $0, (%ecx)
L: cmpb $0, (%eax)
je F
cmpb $32, (%eax)
jne E
incl (%ecx)
E: incl %eax
jmp L
F: ret


Revision [3218]

Edited on 2017-11-06 10:19:46 by EmilioCoppa
Additions:
%%(c;main.c)
Deletions:
%%(C;main.c)
%%(C;f.c)


Revision [3217]

The oldest known version of this page was created on 2017-11-06 10:19:32 by EmilioCoppa
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.0676 seconds