Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. [email protected].

13
Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. [email protected]

Transcript of Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. [email protected].

Page 1: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Computer Science ICSCI-1100-01Summer 2009

David E. Goldschmidt, [email protected]

Page 2: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Hardware

Page 3: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Central Processing Unit (CPU)

ArithmeticLogicUnit

ControlUnit

CPU

Instruction (input) Result (output)

e.g. addition, subtraction, logical AND, OR, NOT

executes machine

language programs

Page 4: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Memory

A section of memory is called a byte.

A section of two or four bytes is often called a word.

Main memory can be visualized as a column or row of cells.

0x0000x001

0x0030x002

0x0040x0050x0060x007

A byte is made up of 8 bits.10101010

Page 5: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Low-Level Languages

000101000011001010000100010010010101010101010010

Machine language program(executable file)

LDA #47STA $570DEXJSR $817CPX #0BNE #14

Assembly language program

Translationprogram

(Assembler)

Page 6: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Compiling a C/C++ Program

#include <iostream>

int main(){ float x; cout << “ ...

C/C++ program

C/C++Compiler

000101000011001010000100010010010101010101010010

Machine language program(object “.obj” file)

000101000011001010000100010010010101010101010010

Precompiled Libraries(e.g. iostream)

C/C++Linker

000101000011001010000100010010010101010101010010

Machine language program(executable “.exe” file)

Page 7: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Fetch-Decode-Execute Cycle

Fetch

The CPU’s control unit fetches, from main memory,the next instruction in the sequence of program instructions.

Decode

The instruction is encoded in the form of a number. The control unit decodes the instruction and generates an electronic signal.

ExecuteThe signal is routed to the appropriate component of the computer (such as the ALU, a disk drive, or some other device). The signal causes the component to perform an operation.

The CPU performs the fetch-decode-execute cycle to “run” program instructions

Page 8: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Numbering Systems

We count using our fingers....Base 10:

Computers count using binary digitsor bits....Base 2:

000001002003004005006007008009010011012013

000000000000000100000010000000110000010000000101000001100000011100001000

Page 9: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Base Conversion

A byte is a grouping of 8 bits

Convert an unsigned binary number (11011001) to decimal (base 10):

What about negative integers?

128

10011011

1248163264128base 10

value

16+ 8+ 1+ = 21764+

unsigned byte ranges

from 0 to 255

Page 10: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Two’s Complement

Conversion from binary to decimal is identical, except the leftmost bit always has a negative weight-128 64 32 16 8 4 2 1

1 1 0 1 1 0 0 1

-128 64 16 8 1

base 10

value

+ + + = -39+

two’s complement byteranges from -128 to 127

Page 11: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Base Conversion (again)

Convert from base 10 to base 2:Find the largest power of 2

that’s less than or equal to the number you’re trying to convert

Subtract it from base 10 numberand repeat...

For example: 217

-128

89

- 64

25

- 16

9

- 8

1

128 64 32 16 8 4 2 1

1 1 0 1 1 0 0 1

Page 12: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Algorithms

What is an algorithm?A solution to a problemA recipeA step-by-step set of English instructions

that describes how inputs are processed to produce expected outputs

Write an algorithm to change a light bulb Write an algorithm to get driving

directionsfrom Albany to Cape Cod

Page 13: Computer Science I CSCI-1100-01 Summer 2009 David E. Goldschmidt, Ph.D. goldschd@strose.edu.

Algorithms

Write an algorithm to sum integers 1 to 100

Write an algorithm to convert an unsigned byte(e.g. 11011001) from base 2 to base 10

Write an algorithm to convert a signedtwo’s complement byte (e.g. 11011001)from base 2 to base 10