informatica di base a.a. 2002/2003
DESCRIPTION
Informatica di base A.A. 2002/2003. Docente: Prof. Francesca Rossi E-mail: [email protected] Tel: 049-8275982 Studio: Via Belzoni 7, primo piano. Organizzazione del corso. 24 ore di lezione (3 crediti) in aula LUM 250 prime tre settimane: Lunedi’- Martedi’ – Mercoledi’ 11:20-13:00 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/1.jpg)
1
Informatica di base A.A. 2002/2003
Docente: Prof. Francesca Rossi
E-mail: [email protected]
Tel: 049-8275982
Studio: Via Belzoni 7, primo piano
![Page 2: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/2.jpg)
2
Organizzazione del corso
24 ore di lezione (3 crediti) in aula LUM 250 prime tre settimane: Lunedi’- Martedi’ – Mercoledi’ 11:20-13:00 altre settimane (dal 21 Ottobre): Martedi’ 11:20-13:00
16 ore di laboratorio (2 crediti) in aula laboratorio
dopo le prime tre settimane tre gruppi di studenti Mercoledi’ 14-16 e 16-18, Giovedi’ 14-16 iscrizione in terminali per login password (tra qualche giorno)
![Page 3: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/3.jpg)
3
Materiale ed esame
Dispensa disponibile alla Libreria Progetto
(Via Marzolo 28, Via Portello 5/7)
Sito web del corso (pronto tra pochi giorni)
Esame con domande a scelta multipla
![Page 4: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/4.jpg)
4
Sommario degli argomenti – parte 1
I circuiti logici
Il sistema binario
L’architettura di Von Neumann
Interi, reali e caratteri in un computer
Linguaggio macchina ed Assembler
![Page 5: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/5.jpg)
5
Sommario degli argomenti – parte 2
Sistemi operativi: DOS, Unix/Linux,WindowsWord processors: WordFogli elettronici: ExcelSistemi per la gestione di basi di datiReti: TCP/IP, Internet, ftp, telnet, posta elettronicaWWW: http, Netscape, HTML, motori di ricerca
![Page 6: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/6.jpg)
6
L’ Hardware di un computer
3 tipi di componenti fondamentali:
un computer è ottenuto assemblando un gran numero di componenti elettronici molto semplici
A
B R
R A
B
A R
A B R
0 0 0
0 1 0
1 0 0
1 1 1
A B R
0 0 0
0 1 1
1 0 1
1 1 1
A R
0 1
1 0
Hardware
![Page 7: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/7.jpg)
AND
OR
NOT
A B A AND B
falso falso falso
falso vero falso
vero falso falso
vero vero vero
A B A OR B
falso falso falso
falso vero vero
vero falso vero
vero vero vero
A NOT A
falso vero
vero falso
00 1
11 1
01 0
00 0
RA B
10 1
11 1
11 0
00 0
RA B
01
10
RA
A
B R
R A
B
A R
![Page 8: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/8.jpg)
8
Completezza di and, or, e not
16 operazioni logiche binarie (tante quante possibili scelte di 4 valori)
4 operazioni logiche unarieTutte possono essere ottenute
componendo and, or, e not
![Page 9: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/9.jpg)
A B A B
falso falso vero
falso vero vero
vero falso falso
vero vero vero
A B A B
0 0 1
0 1 1
1 0 0
1 1 1
R B
A
A B equivale a (NOT A) OR B
A B NOT A (NOT A) OR B
0 0 1 1
0 1 1 1
1 0 0 0
1 1 0 1
![Page 10: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/10.jpg)
A B A B
0 0 1
0 1 0
1 0 0
1 1 1
B
A
R
A B equivale a (A B) AND (B A) A B A B B A (A B)AND(B A)
0 0 1 1 1
0 1 1 0 0
1 0 0 1 0
1 1 1 1 1
![Page 11: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/11.jpg)
o XORA B A B
0 0 0
0 1 1
1 0 1
1 1 0
B
A
R
A XOR B equivale aNOT (A B) A B A B NOT(A B)
0 0 1 0
0 1 0 1
1 0 0 1
1 1 1 0
R A
B X
![Page 12: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/12.jpg)
A = (B A) [(NOT A) (NOT B)]
A B B A NOT A NOT B (NOT A) (NOT B) A
0 0 1 1 1 1 1
0 1 0 1 0 0 1
1 0 1 0 1 1 1
1 1 1 0 0 1 1
Siccome (un rettangolo è un quadrato se ha altezza uguale alla base), allora [se un rettangolo (non è un quadrato) esso (non ha altezza uguale alla base)].
Il risultato è sempre 1, ossia sempre vero.L’asserzione è una tautologia (o un teorema).
A = (B A) [(NOT A) (NOT B)]A = (B A) [(NOT A) (NOT B)]A = (B A) [(NOT A) (NOT B)]
![Page 13: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/13.jpg)
13
Dalla tabella di verita’ ad un circuito
Tanti input quante sono le dimensioni della tabella
Un solo outputUn or all’outputTanti and quanti sono gli 1 della
tabellaInput degli and: 1 se diretto, 0 se
negatoA B A B
0 0 0
0 1 1
1 0 1
1 1 0
B
A
R
![Page 14: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/14.jpg)
14
Nand e nor
Non servono tre operazioni (and, or,
not)
Basta una tra :
nand (not and) e nor (not or)
![Page 15: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/15.jpg)
NAND
NOR
A B A NAND B
falso falso vero
falso vero vero
vero falso vero
vero vero falso
A B A NOR B
falso falso vero
falso vero falso
vero falso falso
vero vero falso
10 1
01 1
11 0
10 0
RA B
00 1
01 1
01 0
10 0
RA B
A
B R
R A
B
![Page 16: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/16.jpg)
AND
OR
A R
NOT
A R
B
R
B
A
![Page 17: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/17.jpg)
17
Memorie
Processore = griglia di milioni di porte logiche
Frequenza (con cui riceve l’input)Esempio: 2 Giga Hertz (2 miliardi di
cicli al secondo)Input ad un ciclo output al ciclo
successivo
![Page 18: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/18.jpg)
18
Rappresentazione binaria
Base 10 cifre da 0 a 9Base 2 cifre 0 e 1Sequenza di cifre decimali dk d k-1 … d1 d0
numero intero dk x 10k + dk-1 x 10 k-1 + … d1 x 10 + d0
Esempio: 101 in base 10 e’ 1x100+0x10+1x1
![Page 19: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/19.jpg)
Circuiti aritmeticiRappresentazione binaria di un intero:
01011012 = 1·25 + 1·23 + 1·22 + 1·20 = 32 + 8 + 4 + 1 = 4510
Valore minimo di una sequenza di n cifre binarie: 000 … 0 (n volte) = 010
Valore massimo: 1111…111 (n volte) = 2n-1 + 2 n-2 + … + 22 + 21 + 20 + 1 = 2n –1
Esempio: 111 = 22 + 2 + 1 = 7 = 23 -1
![Page 20: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/20.jpg)
20
Una proprietà dei numeri binari
1001001= 73
100100 = 36 = 73/2 e questo è il resto
Eliminare il bit più a destra corrisponde a dividere per 2 il valore, ed il bit eliminato è il resto
![Page 21: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/21.jpg)
21
Trasformazione di un numero in base 10 a binario
125
125/2=62 resto 1 62/2=31 resto 0 31/2=15 resto 1 15/2=7 resto 1 7/2=3 resto 1 3/2=1 resto 1 1/2=0 resto 1
125 in binario è 1111101
rappresenta 62
rappresenta 31
etc
![Page 22: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/22.jpg)
Circuiti aritmetici
Riporto: 1 1 1 1 0 0
0111002 + 1001112 = ----------- 10000112
Somma: Colonna per colonna, da destra a sinistra Riporto se la somma su una colonna supera la base Tre cifre binarie (prima riga, seconda riga, riporto), somma =1 se una o tre sono 1, riporto = 1 se almeno due sono 1
![Page 23: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/23.jpg)
23
Somma binaria
1 11 riporti 1010011+ 1100011=
-----------
10110110
Si vuole costruire un circuito per sommare due numeri binari
Iniziamo con un circuito che faccia la somma su di una colonna
![Page 24: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/24.jpg)
Vogliamo un circuito che con input due bit corrispondenti ed il riporto precedente calcola la loro somma ed il nuovo riporto.
yx
S
R
R'
ADD
![Page 25: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/25.jpg)
La somma S è 1 se tutti e tre i bit in input sono 1 oppure solo uno di essi è 1.
Questo si esprime con la formula logica:
S = {[(X AND Y) AND R] OR [X AND (Y NOR R)]} OR {[Y AND (X NOR R)] OR [R AND (X NOR Y)]}
![Page 26: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/26.jpg)
Il nuovo riporto R' è 1 se almeno due bit in input sono 1.
Questo si esprime con la formula logica:
R' = [(X AND Y) OR (X AND R)] OR (Y AND R)
![Page 27: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/27.jpg)
27
2 bit da sommare
riportoriporto per la prossima colonna
risultato su questa colonna
1-ADD
3 input
2 output
![Page 28: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/28.jpg)
28
Tabelle di verità
00 01 10 11
0 1
0 1 1 0 1 0 0 1 00 01 10 11
0 1
0 0 0 1 0 1 1 1
risultato
riporto
riporto
bit da sommare
![Page 29: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/29.jpg)
Dalle tabelle di verità sappiamo come costruire il circuito:
riporto risultato1-ADD
![Page 30: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/30.jpg)
30
1-add 1-add 1-add 1-add
0 riporto inizialeRiporto
finale
risultato
Somma di numeri di 4 bits
![Page 31: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/31.jpg)
31
Componendo 6 circuiti ADD si ottiene il circuito
x0
0
ADD
R
y0
s0
x1
R
y1
s1
x2
R
y2
s2
x3
R
y3
s3
x4
R
y4
s4
x5
R
y5
s5
ADDADDADDADDADD
Che calcola la somma di due numeri di 6 bit
![Page 32: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/32.jpg)
bit
output
reset
flip X A
B
ciclo reset
flip A B output
0 0 0 ? ? ?
1 0 0 ? 1 ?
2 1 0 ? 1 ?
3 1 0 ? 0 ?
4 0 0 ? 0 0
5 0 0 0 1 0
6 0 0 0 1 0
ciclo reset
flip A B output
7 0 1 0 1 0
8 0 1 1 1 0
9 0 0 1 1 1
10 0 0 1 1 1
11 0 0 1 1 1
12 0 0 1 1 1
13 0 0 1 1 1
Memoria (volatile)
![Page 33: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/33.jpg)
bit
output
reset
flip X A
B
ciclo reset flip A B output
14 0 1 1 1 1
15 0 1 0 1 1
16 0 0 0 1 0
17 0 0 0 1 0
18 0 0 0 1 0
19 0 0 0 1 0
20 0 0 0 1 0
![Page 34: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/34.jpg)
34
Ricevimento e sito corso
www.math.unip.it/~frossi/info-base.html
Orario di ricevimento: Mercoledi’ 16:30-18:30 nel mio studio (o in un’aula)
![Page 35: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/35.jpg)
35
Esercizio
•Determinare la tavola di verità del seguente circuito:
and
A
BR
è una tavola nota?
not
not
or
or
![Page 36: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/36.jpg)
36
Esercizio
•Partendo dalla tavola di verità dell’esercizio precedente, costruite un circuito che la realizza seguendo il metodo di costruzione generale visto in classe.
![Page 37: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/37.jpg)
37
Esercizio
•Si disegni un circuito logico che realizza la seguente tavola di verita’:
•A=0, B=0 R = 1
•A=0, B=1 R = 1
•A=1,B=0 R = 1
•A=1, B=1 R = 0
![Page 38: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/38.jpg)
38
Esercizio
•Dare la tavola di verita’ delle formule:
•(A NOT(B)) OR (A AND B)
•A OR (A AND NOT(B))
•(NOT(A) NOT(B)) OR (NOT(A) AND B)
![Page 39: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/39.jpg)
39
Esercizio
•Scrivere la rappresentazione binaria dei numeri decimali:
•30
•36
•15
![Page 40: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/40.jpg)
40
Esercizio
•Scrivere la rappresentazione decimale dei numeri binari:
•1000
•1010
•01011
•10111
![Page 41: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/41.jpg)
41
Iscrizione per l’accesso al laboratorio
Sito per le iscrizioni: http://iscrizioni.math.unipd.it
Dopo tre giorni: ritirare login e password e firmare
Da casa o da due terminali nell’androne del laboratorio
![Page 42: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/42.jpg)
42
L’architettura di Von Neumann
CPU RAMMem
secondI/O
bus
![Page 43: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/43.jpg)
43
RAM= Random Access Memory memoria ad accesso casuale
Nella RAM, come ovunque in un computer, le informazioni sono sempre rappresentate con sequenze di 0 e di 1. Numeri binari.
La RAM quindi è fatta per contenere tali numeri.
un bit può contenere o 0 o 1
un byte è una sequenza di 8 bits
una parola consiste di 4 bytes
![Page 44: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/44.jpg)
quindi la RAM è
una sequenza di bytesbyte
da cui si leggono ed in cui si scrivono singoli byte o blocchi di 4 bytes consecutivi: le parole.
bit
parola
![Page 45: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/45.jpg)
0 0 000000 00
1 000000 01
2 000000 10
3 000000 11
1 4 000001 00
5 000001 01
6 000001 10
7 000001 11
2 8 000010 00
9 000010 01
10 000010 10
11 000010 11
Indirizzamento di byte e parole
![Page 46: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/46.jpg)
46
Unità di misura della RAM
1 K bytes circa 1.000 bytes 210=1024
1 Mega byte circa 1.000.000 bytes 220
1 Giga byte circa 1.000.000.000 bytes 230
1 Tera byte circa 1.000.000.000.000 bytes 240
![Page 47: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/47.jpg)
47
RAM => accedere ad ogni byte ha la stessa durata (10**-7 sec): non dipende da quale byte è stato acceduto prima
è volatile: se tolgo la spina l’informazione è persa (c’è anche la ROM)
ogni byte ha un indirizzo 0,1,2......
il byte e’ la minima quantita’ accessibile (attraverso il suo indirizzo)
PROPRIETA’ della RAM
![Page 48: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/48.jpg)
48
La CPU: unità centrale di calcolo:esegue programmi che sono nella RAM
Cis1 Cis2 Cisk
P
IP
•R0
•Rn
bus
RAM
RCALU
registri di calcolo
CPU
![Page 49: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/49.jpg)
49
La CPU esegue continuamente il ciclo ADE=Access/Decode/Execute
Access: preleva dalla RAM la prossima istruzione da eseguire (l’indirizzo è in P, l’istruzione viene messa in IP)
Decode: capisce che istruzione c’è in IP: isi
Execute: la esegue mediante il circuito Cisi 1 ciclo= 10**-9 sec
![Page 50: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/50.jpg)
50
Memoria Secondaria
è permanente
dischi fissi, floppy, nastri magnetici, CD
accesso sequenziale (il tempo varia a seconda dell’accesso precedente)
è adatta per leggere/scrivere grandi quantita’ di dati (in posizioni contigue)
![Page 51: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/51.jpg)
51
I/O=Input/Output
Dispositivi di comunicazione utente computer. In un computer moderno:
input=tastiera
output=video / stampanti
velocita’ diverse e molto minori delle altre parti del computer (decimi di sec)
![Page 52: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/52.jpg)
52
Componenti di un PC
I componenti del calcolatore si dividono in due categorie: Hardware (parte fisica, meccanica, elettronica) Software (istruzioni e comandi)
Unità di misura: Velocità MHz Milioni di operazioni al
secondo Memoria Byte, KB, MB, GB, TB
![Page 53: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/53.jpg)
Macchina Hardware e Macchina Software
macchina hardware
Agli albori dell'informatica, l’utente programmava in binario (Ling.Mac.) scrivendo i programmi nella RAM
sistema operativo
applicativi
![Page 54: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/54.jpg)
macchina hardware
utente
software
traduce per noi in linguaggio macchina
![Page 55: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/55.jpg)
La macchina software permette:
•input/output facile
•programmazione in linguaggi ad alto livello, come Java (parte III)
•rende disponibili programmi per compiere operazioni molto complicate (applicativi) (parte II)
Tutto viene comunque "fatto" dalla macchina hardware!!
![Page 56: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/56.jpg)
56
INTERI REALI e CARATTERI
Il computer ha memoria finita e quindi l’insieme dei numeri
interi e reali che sono rappresentabili è
necessariamente finito!
![Page 57: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/57.jpg)
57
Rappresentazione binaria
Numero binario: b n-1 b n-2 … b 0, dove
bi=1 o 0Corrisponde al numero decimale (b n-1 x 2 n-1) + (b n-2 x 2 n-2) +… + (b 0 x 2 0)Esempio: 101 corrisponde a
1x4+0x2+1x1 = 5Esempio: 11 = 1x2 + 1x1 = 3
![Page 58: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/58.jpg)
58
Gli interi nel computer
Generalmente gli interi occupano 4 bytes = 32 bit
Con n bit, si rappresentano interi positivi da 0 a 2n –1
0 = n zeri 2 n-1 = n uni, cioe’ 1x2 n + 1x 2 n-1 = … + 1x2 0
e i negativi ?
![Page 59: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/59.jpg)
59
Prima rappresentazione
Il bit n rappresenta il segno:
0 = positivo 1 = negativo
PROBLEMI:
2 zeri (+0 e -0)
operazioni complicate
![Page 60: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/60.jpg)
60
Seconda rappresentazione
Usare la rappresentazione in complemento a 2:
• positivi da 0 a 2n-1 -1 lasciando a 0 il bit n
•negativi da -2 n-1 a -1 si rappresentano come il complemento a 2 del valore assoluto
![Page 61: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/61.jpg)
61
Esempio, con n=6
0, 1,…….31, 32, ……, 63 positivi negativi
32 32-64= -32 33 33-64= -31 ………..
63 63-64= -1
-32............-1
![Page 62: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/62.jpg)
62
Supponiamo n=6
-4 viene rappresentato come complemento a 2 di 000100 (= 4)
cioè 111011+1=111100 = 60 (10)
si calcola anche: -4 + 26 = 60
Esempio:
![Page 63: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/63.jpg)
Complementando 0 si ottiene ancora 0
64- 0=--- 64 ha gli ultimi 6 bit uguali a 0
in binario 1000000- 000000=-------1000000
Complementando 32 si ottiene
64- 32=--- 32 ha il bit 5 uguale a 1(negativo)
in binario 1000000- 100000=-------0100000
![Page 64: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/64.jpg)
64
In generale: con n bits
positivi 0 ….. 2n-1-1
negativi -2n-1 …... -1
![Page 65: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/65.jpg)
65
La somma è semplice n=6
10+ 12=--- 22
in binario 001010+ 001100=-------0010110
Somma di numeri positivi 10+12
![Page 66: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/66.jpg)
71
Altro esempio con n=6
Vogliamo: 10 - 32
-32 -32+64 = 32
10 + 32 = 42 che rappresenta un numero negativo (è >31)
che numero ?
42 - 64 = -22 OK
![Page 67: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/67.jpg)
72
-3 -> 61= 111101
-22 -> 42 = 101010
1 100111=
n=6 -3-22
64 + 39
Basta buttare via l’1 in colonna 7
39 - 64 = -25 come desiderato
![Page 68: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/68.jpg)
Non sempre la somma va bene:
25+10= 35
che con 6 bit rappresenta un numero negativo: 35-64= -29 !!
-22-12 =-34
42+52 = 94 ed anche buttando l’1 in colonna 7, che vale 64, otteniamo 30, che è positivo!
TROPPO GRANDE !!
TROPPO PICCOLO !!
overflow o supero
![Page 69: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/69.jpg)
74
due fatti importanti:
•una somma dà overflow sse i riporti in colonna n ed n+1 sono diversi
•Se non c’è overflow allora basta buttare l’eventuale bit in colonna n+1 per ottenere il risultato corretto
![Page 70: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/70.jpg)
75
test di overflow nel caso di 2 numeri positivi:
•entrambi hanno 0 in colonna n
•sommandoli, in colonna n+1 il riporto è sempre 0
•il test dice che la loro somma da supero sse c’è riporto in colonna n
•la somma è almeno 2n-1 e quindi è maggiore del massimo intero rappresentabile con n bits
![Page 71: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/71.jpg)
consideriamo ora:
-22-5
42= 101010+
59= 111011=1100101
111 1
basta buttare via
la regola dice che non c’è
overflow
37-64=-27 OK
![Page 72: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/72.jpg)
esempio:
7 bits, 27=128 quindi
0....63 normali mentre 64...127
rappresentano -64.....-1
-18 ?? -18+128=110
110-128=-18
![Page 73: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/73.jpg)
somma:
63 - 64
63 -> 0111111
-64 -> 10000001111111 -> 127 -> -1
non c’è overflow visto che non c’è riporto nè in colonna 7 nè in 8
![Page 74: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/74.jpg)
altro esempio:
-23 -> 105 -> 1101001
-45 -> 83 -> 1010011
1101001
1010011
1 0111100
1 11riporto 1 in colonna 8 e 0 in 7
OVERFLOW
![Page 75: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/75.jpg)
80
Reali in notazione binaria
bk-1 bk-2 … b2 b1 b0 , b-1 b-2 …
bk-1 x 2 k-1 + bk-2 x 2 k-2 +… + b2 x 22 + b1 x 2 + b0 x 20 + b-1 x 2-1 + b-2 x 2-2 +…
Da decimale a binario: Per la parte intera, come sappiamo fare
(metodo delle divisioni)
![Page 76: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/76.jpg)
81
REALE--> BINARIO
cosa significa una parte decimale binaria:
.1101001
2-1+ 2-2 + 2-4 + 2-7
![Page 77: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/77.jpg)
.1101001 moltiplicarlo per 2 significa spostare il punto di un posto a destra
1.101001
2-1 2-2...
20 2-1.......
![Page 78: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/78.jpg)
se abbiamo un valore decimale in base 10:
0.99 come troviamo la sua rappresentazione in base 2? Ragioniamo come segue:
supponiamo che .99 = .b1b2b3...bk (binario)
allora 2 .99 = 1.98 = b1.b2b3...bk
quindi b1 è 1
e .98 è rappresentato da .b2b3...bk
![Page 79: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/79.jpg)
per trovare la rappresentazione binaria di un decimale lo moltiplichiamo per 2 ed osserviamo se 1 appare nella parte intera:
.592= 1.18
.182= 0.36
.362= 0.72
.722= 1.44
.442= 0.88
.882= 1.76 .......
.100101.....
dipende da quanti bit abbiamo
rappresentazione binaria di .59
![Page 80: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/80.jpg)
85
esempio
18.59
18 10010
.59 .100101...
10010.100101....
![Page 81: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/81.jpg)
86
Decimali in forma normalizzata
43,5 puo’ essere scritto come: 43,5 x 100
0,0435 x 103
4350,00 x 10–3
4,350 x 101 (forma normalizzata)Lo stesso per i numeri binari decimali:
1001,01 = 1001,01 x 20 = 10,0101 x 22 = 100101,00 x 2–2
Forma normalizzata: la parte intera e’ sempre 1 (es.:1,00101 x 23)
![Page 82: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/82.jpg)
87
Rappresentazione dei Reali in un computer
1 8 23
s e+127 m
Rappresenta:
N = s 2e 1.m
implicito
0 e+127 255 quindi -127 e 128
![Page 83: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/83.jpg)
88
10010.100101...
0 0010100101...........131
131-127= 4 = numero delle posizioni verso sinistra di cui abbiamo dovuto spostare il punto decimale
RAPPRESENTAZIONE UNICA
![Page 84: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/84.jpg)
89
esempio di rappresentazione in virgola mobile:
12.65 -> 1100. ???
.65*2=1.30 .30*2=.60 .60*2=1.20
.20*2=.40 .40*2=.80 .80*2=1.60 ..
101001...
![Page 85: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/85.jpg)
90
1100.101001
mantissa=1.100101001
esponente 130, perchè
130-127=3 e quindi
23* 1.100101001=1100.101001
![Page 86: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/86.jpg)
91
.00101001
deve diventare 1.01001
significa moltiplicare per 23
per rimettere le cose a posto:
esponente 124 visto che 124-127=-3 e
2-3 * 1.01001=.00101001
![Page 87: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/87.jpg)
92
quanti reali si rappresentano?
•con una parola, cioè 32 bits, possiamo rappresentare 232 cose diverse al più 232 reali
•questi valori non sono distribuiti uniformemente come gli interi
•sono maggiormente concentrati tra -1 e 1
•si diradano sempre più allontanandosi dallo 0
![Page 88: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/88.jpg)
93
Distribuzione disuniforme
Supponiamo 2 bits per la mantissa e 2 per l’esponente (-1,0,1,2)
0 .5 .6 .7 .8 1 1.2 1.5 1.7 2 2.5 3 3.5 4 5 6 7
![Page 89: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/89.jpg)
94
caratteri
in generale viene usata la codifica ASCII:
ogni carattere è rappresentato da 1 byte: 256 caratteri. Questo basta per:
a....z A...Z 0...9 . , ;: () ..............
caratteri di controllo: enter, tab...
![Page 90: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/90.jpg)
95
wide characters
nel caso sia necessario rappresentare più caratteri, per esempio gli ideogrammi cinesi, esiste una codifica che associa 2 bytes ad ogni carattere. In questo modo si rappresentano 65536 caratteri diversi
![Page 91: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/91.jpg)
96
esercizi
•quali sono le parti principali dell’architettura di von Neumann?
•citare le caratteristiche salienti della RAM
•quali sono le parti essenziali della CPU
•descrivere il ciclo che la CPU ripete in continuazione
![Page 92: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/92.jpg)
•a cosa servono i registri P e IP della CPU?
•quali sono gli esempi più comuni di memoria secondaria e perchè essa si chiama sequenziale?
•dare alcuni esempi di dispositivi di input e di output.
![Page 93: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/93.jpg)
98
esercizi:
•usando la rappresentazione in complemento a 2, quali valori interi si possono rappresentare con 5 bits ?
•con 5 bits, realizzare la somma: -5-8, come si testa se c’è overflow o no?
•con 5 bits, realizzare 10+8, come si testa se c’è overflow o no?
![Page 94: Informatica di base A.A. 2002/2003](https://reader035.vdocuments.pub/reader035/viewer/2022062516/56812a51550346895d8d9a66/html5/thumbnails/94.jpg)
99
esercizi
•dare la rappresentazione in virgola mobile normalizzata dei valori 0.5, 1.5 e 10.543 avendo 8 bits per l’esponente e 8 per la mantissa.