• No results found

Key Concept: Encodings

N/A
N/A
Protected

Academic year: 2021

Share "Key Concept: Encodings"

Copied!
21
0
0

Loading.... (view fulltext now)

Full text

(1)

Fundamentals of Computer Science

Fundamentals of Computer Science

Course introduction Course introduction

Prof.

(2)

Iscrizione

Iscrizione al

al corso

corso

 E’ E’ statastata abilitataabilitata l’iscrizionel’iscrizione al al corsocorso 

 Non Non èè obbligatoriaobbligatoria, la , la richiedorichiedo per per finifini statisticistatistici e per e per megliomeglio programmare

programmare ilil corsocorso

(3)

Key Concept: Encodings

We can interpret the 0’s and 1’s in computer memory any way we want.

n We can treat them as

numbers.

n We can encode information in

those numbers

3

 Even the notion that the computer understands numbers is an

interpretation

n We encode the voltages on

wires as 0’s and 1’s,

eight of these defining a byte

n Which we can, in turn, interpret

as a decimal number

BTW: why do we interpret this string of 0’s an 1’s as 74 ?

(4)

Layer the encodings as deep as you want

 ASCII encoding for characters

n “A” coded as 65 n “B” coded as 66 n …

n If there’s a byte with a 65 in it, and we decide that it’s a

character, POOF! It’s an “A”! character, POOF! It’s an “A”!

 We can string together lots of these numbers together to make usable text

n “77, 97, 114, 107” stands for “Mark”

n “60, 97, 32, 104, 114, 101, 102, 61” stands for

(5)

Layered encodings

 A number is just a number

 If you have to treat it as a letter, there’s a piece of software that does it

n For example, that associates 65 with the graphical

representation for “A”

 If you have to treat it as part of an HTML document, there’s a

 If you have to treat it as part of an HTML document, there’s a piece of software that does it

n That understands that “<A HREF=“ is the beginning of a link

 That part that knows HTML communicates with the part that knows that 65 is an “A”

(6)

Multimedia is unimedia

 But that same byte with a 65 in it might be interpreted as…

n A very small piece of sound (e.g., 1/44100-th of a second) n The amount of redness in a single dot in a larger picture

n The amount of redness in a single dot in a larger picture which

is a single frame in a full-length motion picture

We use software to manage all these layers

 We use software to manage all these layers

n How do you decide what a number should mean, and how you

should organize your numbers to represent all the data you want?

n That’s data structures

 If that sounds like a lot of data, it is

n To represent all the dots on your screen probably takes more

than 3.145.728 bytes

(7)

Interactions between Hardware and

Interactions between Hardware and

Software

Software

(8)

talking” with computers

We need a language to exchange information with computers

n data, recipes, …

 Different programming languages are different ways (encodings) to tell computers same things

Programming languages:

First generation, or machine languagesSecond Generation, assembly languageThird generation. C,C++, fortran, Basic • Forth generation: Java, Matlab

(9)

Programming languages and layers of abstraction

Programming languages and layers of abstraction

 DifferentDifferent languageslanguages atat differentdifferent layerslayers 

 Machine Machine languagelanguage

0100 0000 0000 1000 0100 0000 0000 1000 0100 0000 0000 1001 0100 0000 0000 1001 0000 0000 0000 1000 0000 0000 0000 1000

Sequence of binary instructions, directly executable by CPU

9   AssemblerAssembler LOAD X LOAD X ADD Y ADD Y STORE STORE ZZ 

 high high levellevel languagelanguage

def

def funfun():(): a = 0; a = 0;

print a+5 print a+5

Instructions in 1-to-1 correspondence with binary instructions, but

expressed with symbolic (human understandable) names

Machine independent. Data abstraction

(10)

 defined bydefined by

n

n

a grammar (syntax)

a grammar (syntax)

n

n

a semantic

a semantic

n

n

a vocabulary

a vocabulary

n

n key wordskey words

Language programming

n

n key wordskey words n

n variablesvariables

 A A naturalnatural languagelanguage sentencesentence can be

can be syntacticallysyntactically correctcorrect, , butbut with no

with no meaningmeaning atat allall ! !

n

n the the grassgrass readsreads the the househouse

 The The samesame for for programmingprogramming languages

(11)

Program Development Sequence

Program Development Sequence

1-11

Compiler

+

(12)

translation from layer to layer

translation from layer to layer

swap: muli $2, $5, 4 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 def swap(v, k) : temp = v[k] v[k] = v[k+1] v[k+1] = temp compiler

Program in a high level language Program in assembler language Introduzione 12 assembler 00000000101000010000000000011000 00000000100011100001100000100001 10001100011000100000000000000000 10001100111100100000000000000100 10101100111100100000000000000000 10101100011000100000000000000100 00000011111000000000000000001000 Programm in binary machine language

(13)

Program execution

Program execution

Processor Control Memory Devices Input 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Input: Code/Data

Computer Skills - Lesson 2 - L.Ingrosso

Control Datapath Memory Input Output 10/03 /14

(14)

Program execution

Program execution

Processor Control Memory Devices Input 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 Code/Data stored in memory

Computer Skills - Lesson 2 - L.Ingrosso

Control Datapath Input Output 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 10/03 /14

(15)

Program execution

Program execution

Processor Control Memory Devices Input 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000

The processor fetches an instruction

Computer Skills - Lesson 2 - L.Ingrosso

Control Datapath Input Output 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 10/03 /14

(16)

Program execution

Program execution

Processor Control Memory Devices Input 000000 00100 00010 0001000000100000

The CPU decodes the instruction What I have to do?

Computer Skills - Lesson 2 - L.Ingrosso

Datapath Memory Input Output 000000 00100 00010 0001000000100000 10/03 /14

(17)

Program execution

Program execution

Processor Control Memory Devices Input 000000 00100 00010 0001000000100000

The processing unit executes the instruction (eventually

interacting with the memory loading operands and saving results)

Computer Skills - Lesson 2 - L.Ingrosso

Datapath

Memory Input

Output

contents Reg #4 ADD contents Reg #2

results put in Reg #2

000000 00100 00010 0001000000100000

10/03 /14

(18)

Program execution

Program execution

Processor Control Datapath Memory Devices Input Output 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000

Computer Skills - Lesson 2 - L.Ingrosso

Datapath Output Fetch Decode Exec 10/03 /14

(19)

Program execution

Program execution

Processor Control Memory Devices Input

When the program terminates, the results are sent to the output device

Computer Skills - Lesson 2 - L.Ingrosso

Control Datapath Input Output 00000100010100000000000000000000 00000000010011110000000000000100 00000011111000000000000000001000 00000100010100000000000000000000 00000000010011110000000000000100 00000011111000000000000000001000 10/03 /14

(20)

Why should you need to study computer science? or “recipes”?

 To understand better the “recipe-way” of thinking

n It’s influencing everything, from computational science to bioinformatics n Eventually, it’s going to become part of everyone’s notion of a liberal

education

n That’s the process argument

n BTW, to work with and manage computer scientists

 AND … to communicate!

n Writers, marketers, producers communicate through computation

 We’ll somehow take these in opposite order

(21)

Summary

Summary

 EncodingEncoding 

 Computing Computing llayersayers

 Programming Programming languageslanguages n

n

translation

translation from

from layer

layer to

to layer

layer

References

Related documents

If you’re a beer buff, take a guided tour at Deschutes Brewery to learn more about how the craft beer scene got its start in Central Oregon, then visit a few.. of the city’s

We performed a wind tunnel study at Politecnico di Milano to measure the drag force on handbikers in different layouts to investigate the effect of the athlete position and

The HistoryMakers is a national 501(c)(3) non profit educational institution founded in 1999, committed to preserving, developing and providing easy access to an

Request approval to 1) accept a grant award from, and enter into a grant agreement with, the American Psychological Association Board of Educational Affairs to pursue accreditation

The State of California, Department of Insurance (CDI) has awarded the District Attorney¶s Office (DA) $4,700,955 for the Automobile Insurance Fraud (AIF) Program, $2,121,829 for

77273 with Caban Resources, LLC (Caban), effective upon Board approval to: (i) extend the term of the Agreement for the period July 1, 2015 through June 30, 2016 with an option

Pursuant to Insurance Code Sections 1872.8(b)(1)(d) (AIF), 1874.8 (Urban Grant), 1872.83(d) (WCIF), and 1872.85(c)(2) (DHIF), CDI is authorized to award and distribute certain funds

Trauma  Rehabilita>on  Database   — Microsoft  Access  designed  by  Consultant  in  RM   — Simple  data  input  for  administrative  staff   — Daily