csis 20801 the bit a binary digit the smallest unit of storage vacuum tubes transistors a simple...

36
CSIS 2080 1 The Bit The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

Upload: melvin-webb

Post on 17-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 1

The BitThe Bit

A binary digit

The smallest unit of storage

Vacuum tubes

Transistors

A simple circuit

Page 2: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 2

Vacuum TubesCreated by Lee DeForest in 1906Airless tube that contains a filament, a grid of nickel wire, and a metal plate As the filament heats up, electrons boil off and are sent through the tube to the plate, creating an electrical currentA small voltage applied to the grid keeps electrons from getting to the plate A small voltage can control the flow of a large currentThe tube acts as a switch

Page 3: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 3

Transistors

Work on the same principle (but generally in the reverse)

Are much smaller

Are much faster

Consume much less power

Page 4: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 4

A Simple Circuit

A capacitor is a component that can hold an electric charge for a short period of timeOne transistor and one capacitor can represent a bitThe capacitor holds a charge—or it doesn’t—and that represents a 1 or 0Transistors are used to select certain capacitors out of a very large number of capacitors

Page 5: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 5

Page 6: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 6

A Simple Circuit (cont.)

When a current is sent through an address line, it opens the transistors that connect the capacitors to the data line

If there is a current on the data line, that charges the capacitor

A similar process is used to read bits

Page 7: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 7

So What?All data is a collection of bits, and is manipulated by machine codeAll machine code is also a collection of bits, which is interpreted by a gargantuan assemblage of interconnected transistors, capacitors, diodes, and other tiny components we call a CPUTransistors (and other components) give us the ability to structure output based on inputUnderstanding how your computer’s internals work is critical to programming in assembly language

Page 8: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 8

Data Storage in Bits

Base ten

Base two

Bytes

Counting in binary

Page 9: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 9

Base Ten

Grouping base-ten digits gives us the ability to represent much larger numbers than 9

Each place is a power of ten

Multiplying the numbers in each place by their powers of ten and adding them together yields the same number

Base ten works well for humans, but it can’t be represented directly in a computer

Page 10: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 10

Base Two

Bits by themselves can only hold two values

Grouping base-two digits gives us the ability to represent much larger numbers than 1

Each place is a power of two

Multiplying the numbers in each place by their powers of two and adding them together yields the same number in decimal

Page 11: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 11

Bytes

Generally, bits are dealt with in groups of eight, 16, 32, or 64 A byte is an eight-bit integer that can hold 256 distinct values (256 distinct combinations of bits) An unsigned byte can represent any integer from 0 to 255 A signed byte can represent any integer from -128 to 127

Page 12: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 12

Counting in Binary

Grouping bits gives us the binary number system

Counting to 1111—0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111

In our examples, we’ll use nibbles, because they’re smaller than bytes but the principles remain the same

Page 13: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 13

Binary Arithmetic

All mathematical operations can be done exactly as they are in base ten

Addition

Subtraction

Multiplication

Division

Page 14: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 14

Bitwise Operations

Called logical operations in the book Take single bits or groups of bits as input Always return one bit or one group of bits as output Groups of bits are operated on one bit at a time Generally have intuitive names

Page 15: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 15

AND

Two inputs, one output

The result is 1 only if both inputs are 1; otherwise, it’s 0

AND 0 1

0 0 0

1 0 1

Page 16: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 16

OR

Two inputs, one output

The result is 1 if either input is 1; otherwise, it’s 0

OR 0 1

0 0 1

1 1 1

Page 17: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 17

XOR (eXclusive OR)

Two inputs, one output

The result is 1 only if exactly one input is 1; otherwise, it’s 0

XOR 0 1

0 0 1

1 1 0

Page 18: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 18

NOT

One input, one output

The output is always the exact opposite of the input

Page 19: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 19

Bit Shifting

Shifting bits left and right multiplies and divides values by two (doing the same to a decimal number multiplies and divides by ten)

Extremely fast—especially compared to multiplication and division

Page 20: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 20

Two’s Complement

Most computers’ way of storing signed integers

Called two’s complement because of the method for negating values

Page 21: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 21

Overflow and Underflow

A group of bits, such as a byte, can only hold a certain number of combinations The results of mathematical operations are often too large (negatively or positively) to fit in a byte When this happens, the CPU happily stuffs in as many bits as will fit and throws out the rest This makes the byte act sort of like an odometer

Page 22: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 22

Two’s Complement Theory

Assign new interpretations to half of a byte’s possible values

Use the principles of overflow and underflow to properly calculate using negative values

Page 23: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 23

Addition and Subtraction

The CPU performs these operations just as if the values were unsigned

It’s easier to understand how it works if you regard the binary number line as circular

Page 24: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 24

Negating Values

Step 1: NOT the input (AKA one’s complement)

Step 2: Add one

Performing the above steps on a value is taking the two’s complement of that value

The sign bit

Page 25: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 25

Base 16: Hexadecimal

A more convenient, slightly more human-readable system When we run out of digits, we use the alphabet Each hexadecimal digit is a nibble, so two can fit in a byte (see pages 56-57)Counting to 10h—00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h, 08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh, 10h

Page 26: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 26

Data Types

A group of bits has only the meaning that we assign to it ASCII is a mapping of bytes to meaningful symbols In a 32-bit color image, four bytes represent a color—one each for red, green, and blue, and another to hold an alpha (transparency) value

Page 27: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 27

Data Types (cont.)

In a floating point number (a computer’s approximation of the mathematical real number), one group of bits represents a number, another represents the exponent, and one more bit represents the sign Higher-level languages allow us to deal with our assigned meanings by giving us types and hiding most calculations In any case—even with high-level languages—the CPU really only deals with bits

Page 28: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 28

Storing Code

A group of bits has only the meaning that we assign to it

The people who make the CPU decide that certain combinations of bits represent instructions for the CPU to carry out (to the CPU, instructions are just data that need to be processed)

These combinations of bits are called machine code

Page 29: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 29

Storing Code (cont.)

The CPU sequentially fetches multiple series’ of bits from memory and executes the instructions that the bits represent

To write machine code, one only needs to put together a sequence of instructions for the CPU

Any program that executes on your computer has to be, in the end, machine code

Page 30: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 30

Assembly Language

Machine code is not human-friendly

Machine code forces absolute memory access (no variables)

Assembly language is more human-friendly, uses symbolic names, and is the closest humans generally get to programming directly in machine code

Page 31: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 31

Assembly Language (cont.)

It is also generally regarded as a very big improvement

Each assembly language instruction is translated into one machine code instruction (in higher-level languages, most instructions are translated into multiple machine code instructions)

Assembly language is translated directly into machine code by an assembler

Page 32: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 32

Why Assembly?

Advantages

Disadvantages

Other considerations

Page 33: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 33

Advantages

Low-level access to the computer and its resources—this is usually kept from you in a higher-level language Total control over the CPU and the possibility of incredible speed—these details are hidden in the compilation process of higher-level languages Size—assembled executables are generally very small compared to their compiled counterparts

Page 34: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 34

Disadvantages

Increased risk of bugs—and increased potency of bugs

Reduced portability—assembly language programs will only run on the processor they were written for

Absence of library routines—assembly language forces you to write your own routines to accomplish what are generally regarded as simple tasks

Page 35: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 35

Other Considerations

Higher-level languages present you with a “virtual machine”—one that understands mathematical expressions and nearly English terminology—assembly language doesn’t

Learning assembly language gives you a good idea of what your compiler is doing, what your program is doing, and what your computer is doing

Choose the right tool for the job

Page 36: CSIS 20801 The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit

CSIS 2080 36

Assignment 1

Chapter 1, Exercises 4, 9, and 10 (page 17)

Chapter 3, Exercises 4, 5, 8, 12 and 14 (pages 71-72)