CS111 Lecture 01: Computer Concepts Hardware and Software Binary - - PDF document

cs111 lecture 01
SMART_READER_LITE
LIVE PREVIEW

CS111 Lecture 01: Computer Concepts Hardware and Software Binary - - PDF document

CS111 Lecture 01: Computer Concepts Hardware and Software Binary Representation Programming Languages Aaron Stevens 29 June 2009 1 What is a computer? What is a computer, anyway? Give some examples of computers: 2 2 1 What is a


slide-1
SLIDE 1

1

1

Aaron Stevens

29 June 2009

CS111 Lecture 01:

Computer Concepts Hardware and Software Binary Representation Programming Languages

2

2

What is a computer, anyway? Give some examples of computers:

What is a computer?

slide-2
SLIDE 2

2

3

3

Computer Takes an input (some data), applies a process, and produces an output. Examples

– Abacus? – Slide rule – Smoke Alarm – Pocket Calculator – Game Console (i.e. Nintendo Wii) – Cell Phone, Blackberry, iPod – Laptop/PC/iMac

What is a Computer?

4

Slide Rule

The slide rule is a mechanical calculator. It works by aligning two logarithmic scales. Align the inputs, and read off the output. This slide rule is showing values of 2 X C e.g. 2 X 2 = 4, 2 X 2.8 = 5.6, etc.

slide-3
SLIDE 3

3

5

3

Analog Computers Information is processed directly in its indigenous form. Digital Computers Information processing and storage occurs using a symbolic representation of the data.

Analog or Digital?

6

3

Information processing and storage occurs using a symbolic representation of the data – each symbol encoded as a discrete pattern of electrical charges. Input must be converted to electrical signals, processed as electrical signals, and then converted back to analog output for consumption by people.

Digital Computers

slide-4
SLIDE 4

4

7

3

Hardware The physical elements of a computing system (chips, circuit boards, monitor, keyboard, disk drives, printer, wires, …) Software The programs that provide the instructions for a computer to execute.

Hardware and Software

8

Hardware Basics

The von Neumann computer architecture.

Hardware: the machinery of computing.

slide-5
SLIDE 5

5

9

Thinking Inside the Box

A computer’s internals are typically hidden from the user. They consist of:

– Integrated circuit chips such as the central processing unit (CPU), memory circuits, and device controllers. – Integrated devices for storage (e.g. hard disk), communication (e.g. network adapter, Bluetooth). – Greenboard and connecting wires.

10

Thinking Inside the Box

A computer motherboard A CPU Chip

Some typical components in 1993.

slide-6
SLIDE 6

6

11

Thinking Outside the Box

The stuff that connects to the computer’s box are called peripherals. These include:

– Input devices (e.g. keyboard, mouse) – Output devices (e.g. video displays, printers) – Storage devices (e.g. hard drive, USB key)

12

Moore’s Law

slide-7
SLIDE 7

7

13

Moore’s Law

The capabilities of computing hardware have improved at an exponential rate.

– Computational power has doubled every 2 years (since 1975), and this trend is expected to continue for the foreseeable future. – Other formulations: hard disk capacity, RAM memory, pixels (for digital cameras) Read about Moore’s Law on Wikipedia.

14

30,000 Foot View of Software

slide-8
SLIDE 8

8

15

9

Digital computers are made up of electronic circuits, which have exactly 2 states: on and off. Human languages are based on MANY discrete symbols! And what about multimedia stuff? All information processed by a digital computer must be represented in this simple/finite scheme: on and off.

Data Representation

16

What Would Pooh Do?

slide-9
SLIDE 9

9

17

9

Humans have 10 fingers, so a base-10 numbering system makes sense for us. Pooh is a very simple bear – he only has 2 paws, and no fingers! The Pooh Numbering System would count using all the paws he has – 2 of them.

What Would Pooh Do?

18

9

Digital computers are made up of electronic circuits, which have exactly 2 states: on and off. Computers use a numbering system which has exactly 2 symbols, representing on and off.

Binary Numbers

slide-10
SLIDE 10

10

19

9

Decimal is base 10 and has 10 digits: 0,1,2,3,4,5,6,7,8,9 Binary is base 2 and has 2, so we use only 2 symbols: 0,1

For a given base, valid numbers will only contain the digits in that base, which range from 0 up to (but not including) the base.

Binary Numbers

20

A binary digit or bit can take on only these two values. Binary numbers are built by concatenating a string of bits together. Example: 10101010 Low Voltage = 0 High Voltage = 1 each bit holds 0 or 1

22

Binary Numbers and Computers

slide-11
SLIDE 11

11

21

Positional Notation: Binary Numbers

Each column has a value based on its position. Consider this general form: This can be applied to base-2 numbers: 1011(binary) = 1 * 23 (1 * 8)

+ 0 * 22

(0 * 4)

+ 1 * 21 (1 * 2) + 1 * 20 (1 * 1)

1011(binary) =8 + 0 + 2 + 1 = 11(decimal) dn * Bn-1 + dn-1 * Bn-2 + ... + d1 * B0

22

What is the decimal equivalent of the binary number 01101110?

(you try it! Work left-to-right) 13

Converting Binary to Decimal

slide-12
SLIDE 12

12

23

What is the decimal equivalent of the binary number 01101110?

0 x 27 = 0 x 128 = 0 + 1 x 26 = 1 x 64 = 64 + 1 x 25 = 1 x 32 = 32 + 0 x 24 = 0 x 16 = 0 + 1 x 23 = 1 x 8 = 8 + 1 x 22 = 1 x 4 = 4 + 1 x 21 = 1 x 2 = 2 + 0 x 2º = 0 x 1 = 0 = 110 (decimal) 13

Converting Binary to Decimal

24

Try another one. What is the decimal equivalent of the binary number 10101010?

(you try it! Work left-to-right) 13

Converting Binary to Decimal

slide-13
SLIDE 13

13

25

Try another one. What is the decimal equivalent of the binary number 10101010?

1 x 27 = 1 x 128 = 128 + 0 x 26 = 0 x 64 = 0 + 1 x 25 = 1 x 32 = 32 + 0 x 24 = 0 x 16 = 0 + 1 x 23 = 1 x 8 = 8 + 0 x 22 = 0 x 4 = 0 + 1 x 21 = 1 x 2 = 2 + 0 x 2º = 0 x 1 = 0 = 170 (decimal) 13

Converting Binary to Decimal

26

While (the quotient is not zero) Divide the decimal number by the new base* Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient * Using whole number (integer) division only. Example: 3 / 2 gives us a quotient of 1 and a remainder 1

Algorithm (process) for converting number in base 10 to other bases

19

Converting from Decimal to Other Bases

slide-14
SLIDE 14

14

27

Converting Decimal to Binary

What is the binary equivalent of the decimal number 103? 103 / 2 = 51, remainder 1  rightmost bit 51 / 2 = 25, remainder 1 25 / 2 = 12, remainder 1 12 / 2 = 6, remainder 0 6 / 2 = 3, remainder 0 3 / 2 = 1, remainder 1 1 / 2 = 0, remainder 1 leftmost bit 103 (decimal) = 1 1 0 0 1 1 1 (binary)

28

Converting Decimal to Binary

Now you try one. What is the binary equivalent of the decimal number 201?

Recall the algorithm:

While (the quotient is not zero) Divide the decimal number by the new base* Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient

slide-15
SLIDE 15

15

29

Converting Decimal to Binary

What is the binary equivalent of the decimal number 201? 201 / 2 = 100, remainder 1  rightmost bit 100 / 2 = 50, remainder 0 50 / 2 = 25, remainder 0 25 / 2 = 12, remainder 1 12 / 2 = 6, remainder 0 6 / 2 = 3, remainder 0 3 / 2 = 1, remainder 1 1 / 2 = 0, remainder 1 leftmost bit 201 (decimal) = 1 1 0 0 1 0 0 1 (binary)

30

Hexadecimal Number System

The hexadecimal number system is a “short-hand” technique for representing binary numbers. Each group of 4 bits is represented by one hex digit.

http://www.dewassoc.com/support/msdos/decimal_hexadecimal.htm

Typically, we write Hexadecimal numbers with a prefix of 0x, e.g. 0x9400D3

slide-16
SLIDE 16

16

31

Representing Text

What must be provided to represent text?

There are finite number of characters to represent, so list them all and assign each a binary number. Character set A list of characters and the binary codes used to represent each one. Computer manufacturers agreed to standardize in the early 1960s.

32

The ASCII Character Set

ASCII stands for American Standard Code for Information Interchange ASCII originally used seven bits to represent each character, allowing for 128 unique characters Later extended ASCII evolved so that all eight bits were used.

slide-17
SLIDE 17

17

33

The ASCII Character Set (7 bits)

34

The Extended ASCII Character Set

slide-18
SLIDE 18

18

35

The Unicode Character Set

Extended ASCII is not enough for international use. Unicode uses 16 bits per character How many characters can UNICODE represent? Unicode is a superset of ASCII. The first 256 characters correspond exactly to the extended ASCII character set

36

The Unicode Character Set

Figure 3.6 A few characters in the Unicode character set

slide-19
SLIDE 19

19

37

Computer Programming

The CPU does some low-level tasks, and each one is specified as a machine-language instruction.

– How do we get the CPU to do stuff for us?

Computer programming is the process of analyzing a problem, designing a solution, and expressing that solution as a series of computer instructions. Computer programs must be written in the language the computer understands.

38

Machine Language

Characteristics of machine language:

– Each instruction is an operation code and an

  • perand, expressed in binary.

– Every processor type has its own set

  • f specific machine instructions.

– The relationship between the processor type and the instructions it can carry out is completely integrated. – Each machine-language instruction does only

  • ne very low-level task.
slide-20
SLIDE 20

20

39

Machine Language Example

40

Assembly Language

Assembly language A language that uses mnemonic codes to represent machine-language instructions. Mnemonic code examples:

– LOADA means “load value into accumulator” – ADDA means “add value into accumulator” – STOREA means “store value from accumulator”

slide-21
SLIDE 21

21

41

The Assembly Process

Assembler A program that reads each of the instructions in mnemonic form and translates it into the machine-language equivalent.

42

Example: Assembly Program

slide-22
SLIDE 22

22

43

High-level Programming Languages

High-level language

A language that provides a richer (more English like) set of instructions.

Example: int a = 2; int b = 5; int total = a + b; System.out.println(total);

How can the computer understand this kind of language?

44

Source Code and Translation

A high-level language program is written in a plain-text format called source code. There are 2 approaches to translating source code into the machine-level instructions that the computer can execute.

– Typically, a high-level language is either compiled OR interpreted, not both.

slide-23
SLIDE 23

23

45

A compiler is a program that translates a high-level language program into machine code. The “compile step” is done all at once, in advance

  • f running the program, usually by the programmer

who wrote the high-level source code.

Compilers

Figure 8.1 Compilation process

46

Most Popular Compiled Languages

Fortran, 1952

– IBM, Numeric and Scientific Computing – Still in use in biology dept at BU!

Pascal, 1970

– Developed for teaching students structured Programming – Early Macintosh operating system, Apple Lisa written in Pascal

C, 1972

– Ritchie and Kernigan, AT&T Bell Laboratories – Developed for system software, UNIX

C++, 1979

– Bjarne Stroustrup, AT&T Bell Laboratories – Backwards compatible with C, and objects

ADA, 1983

– Department of Defense – 1970s: concern that DoD had too many programming languages – By 1996: down to only 37

C and C++ together have been the most popular compiled languages with the most programmers and applications.

slide-24
SLIDE 24

24

47

Interpreters

An interpreter is a program that translates and executes the program’s source code statements in sequence.

– An interpreter translates a statement and then immediately executes the statement.** – Interpreters can be viewed as simulators. ** Whereas an assembler or compiler produces machine code as output; executing the code is a separate step.

48

Most Popular Interpreted Languages

BASIC, 1963

– Beginner’s All-purposes Special Instruction Code – Kemeny and Kurtz, Dartmouth College – Invented for non-science and non-mathematics users.

Perl, 1987

– Invented by Larry Wall of Unisys Corporation – Regular Expression engine for text processing

Visual Basic/Visual Basic .NET, 1991

– Invented at Microsoft, a GUI scripting language – Extremely popular; huge installed business application base

Python, 1991

– Guido van Rossum, researcher at BDFL in the Netherlands – Minimalist semantics – Named after Monty Python

slide-25
SLIDE 25

25

49

Portability

Portability is the ability of a program written on one machine to be run on different machines. Compiler portability A program gets compiled for a particular CPU instruction set, and can only be run on a computer with that type of CPU. Source code portability A program in an interpreted language can be distributed and run (interpreted) on any machine that has the appropriate interpreter.

50

Compiled vs. Interpreted

Compiled Languages

– Speed: tend to run faster than interpreted languages. – Portability: virtually none. To port to new CPU architecture, must re-compile the source code and distribute new executable file.

Interpreted Languages

– Speed: tend to run more slowly than compiled languages. – Portability: virtually seamless. Distribute source code directly, and it will run on any suitable interpreter.

slide-26
SLIDE 26

26

51

Compiled Language

Source Code (Program) Compiler Machine Code Program Inputs Running Program Outputs

A compiler takes source code, and produces executable machine code (stored in a file on disk). The machine code program is executed by the user. Advantage: speed at time of execution.

52

Interpreted Language

Source Code (Program) Computer Running an Interpreter Inputs Outputs

An interpreter takes source code as input, and then compiles each statement and executes it immediately. Advantage: portability

slide-27
SLIDE 27

27

53

Java Technology

Introduced in 1996 and became instantly popular for the World Wide Web.

– Portability was of primary importance.

Java is a hybrid language: Java is both compiled and interpreted.

– Java is compiled into a standard machine language called Java Bytecode, for the Java Virtual Machine. – A software program called the Java Virtual Machine executes the Bytecode program by translating the JVM instructions into native instructions.

54

Student To Dos

– Lab 00: Sign up for lab account

  • Start today, finish by WEDNESDAY!

– Read chapter 1 of the book. – Thursday: meet at teaching lab, EMA 304. – Thursday: lab 01, homework 01