27
Computer Architecture Perspectives on Computing - COMP1200 Chris Johnson The Australian National University Semester 1   2005

comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Embed Size (px)

Citation preview

Page 1: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Computer ArchitecturePerspectives on Computing ­ COMP1200

Chris Johnson

The Australian National UniversitySemester 1   2005

Page 2: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Acknowledgment

The Lecture Slides Were Written by Eric McCreath with Minor Modificationsby Weifa Liang 2004 and Chris Johnson 

2005

Page 3: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

lecture 1: Computer ArchitectureBinary Information

Storing, transferring, and processing informa­tion.

Basic Bits.

Interpretation of binary information:

non­negative integers, integers, floating number, and characters.

Measuring information.

Page 4: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Information

Information is the life blood of a computer sys­tem.  That is, a computer is a machine that op­erates upon information.

This information must bestored, processed and transferredvia a physical medium. There are many possi­ble media.

Binary information is the simplest way of storing information.

Page 5: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Informationstorage, processing, and transfer

The physical medium that information is stored in places limitations on the amount that can be stored.

The physical medium that information is pro­cessed within places bounds on the speed at which it may be processed.

Finally, the physical medium that information is transferred via places limitations on the speed (or rate) it can be transferred.

Page 6: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Binary information

A single bit  is in one of two states, these are usually labeled either 0 or 1. 

By collecting a number of bits together more than two states can be represented within a computer.

n bits can represent 2n   states.

000000001100102

:111115

:4bits16 states

Page 7: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

The Byte

A byte consists of 8 bits.

A byte forms a basic unit of binary information.

A byte can represent 256 states.

A nibble refers to 4 bits.

2, 4, or 8 bytes are placed together to form a word.  The word size is dependent on the archi­tecture in question. 

Page 8: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Decimal

Binary is often a cumbersome representation for humans to manipulate. One approach is to use decimal.

Binary can be changed to decimal:

Decimal can also be simply changed to binary:

However, this is a slow and error prone task for humans to undertake.

bn−1 bn−2 .... b2 b1 b0∑k=0

n−1

bk 2k

bk=d÷2k mod 2

Page 9: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Hexadecimal

A more common way of representing binary in­formation is using base 16.   This is known as Hexadecimal.

It is  easy and quick to change between Hex and binary.  e.g.  

10008100191010 A1011B1100C1101D1110E1111F

000000001100102001130100 4010150110601117

00011010110001001 AC 4

Page 10: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Octal

Octal is sometimes used. Octal is base 8.

Changing between Octal and Binary is also simple.  e.g.  

00000011010201131004101511061117

010111001271

Page 11: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

MemoryA contiguous list of bytes forms the memory within the computer.  These bytes are indexed with binary addresses.

 Larger amounts of memory are specified using the prefixes: K(kilo), M(mega), G(giga), and T(tera).  These have different meanings from their standard scientific meaning.

Prefix Scientific ComputerK 103=1000 210=1024M 106=1000000 220=1048576G 109=1000000000 230=1073741824T 1012=1000000000000 240=1099511627776

Page 12: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Memory

These prefixes are used inconsistently within the computer industry.

For example:2 MB means 2×210 bytes

5 Mb /sec means 5×106 bits are transfered per second .

Page 13: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Interpretation of Binary InfoAn interpretation is placed upon a binary pat­tern. This gives the binary information meaning.

It is important that the intended interpretation is used on this information.

Consider the binary pattern:  

01100001  

If it was interpreted as an ASCII character then it would be the letter 'a'. However, if it is interpreted as an integer then it would be the number 97 !!!!

Page 14: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Non­Negative 

The non­negative integers are the numbers 0,1,2,....  This is an infinite set and hence it can't be represented with a fixed sized binary pattern.

However, we can simply bound the integers represented.

A binary pattern can be interpreted as a binary number. e.g.  01100001 is 97.  

Page 15: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

A ProblemOne problem that often arises is determining what order to interpret the bit pattern. Is the first bit the least or most significant bit?

Also a question remains over the ordering of bytes when larger integers are considered.

It is important that there is consistency across all interpretations. 

Fortunately the architecture/compiler does most of this work. 

Page 16: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Integers 

We also wish to be able to represent negative numbers.

A simple way of doing this is to use the first bit to indicate the sign of the number. With 0 mean­ing a positive number and 1 meaning that it is negative.

We end up with two zeros!

This wastes a bit pattern and makes equality more complex.

10001010−1000001001 900000000 010000000 0

Page 17: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Integers

The most common approach for repre­senting negative numbers is twos­com­plement.

The first bit also indicates that the num­ber is negative.

To negate a number you "invert all bits and add one".

This removes the problem of multiple ze­ros.

0111 70110 60101 50100 40011 30010 20001 10000 01111−11110−21101−31100−41011−51010−61001−71000−8

Page 18: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Twos­complement

The twos­complement approach also simplifies arithmetic operations as an ordinary adder(op­erates on non­negatives) will correctly handle negative numbers.

Often representations are selected to simplify computation.

00111011

1110

3−5−2

Page 19: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Floating Point NumbersFloating point numbers provided a way of ap­proximating continuous/real numbers.

The binary pattern is divided up into two parts, the mantissa and the exponent. The exponent operates on the mantissa shifting it left or right.

This representation works in a similar way to that of scientific notation. 

0.314×101

Mantissa ExponentSign

Page 20: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Floating Point Numbers

The IEEE Standard Double is 64 bits with a 52 bit mantissa and a 11 bit exponent.

If 'm' is the mantissa and 'e' is the exponent and 's' is the sign bit then the value of the floating point number is:

 

Rounding errors can often be introduced due to the inexact nature or floating point numbers.

V=−1s×1. m×2e−1024

Page 21: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

ASCII

ASCII is the American Standard Code for Infor­mation Interchange.  It is a 7 bit code.

See "man ascii".

The ISO 8859 standard includes several 8 bit extensions to the ASCII character set.

Page 22: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Boolean DataThe boolean data type is another basic data type within a computer system.  A boolean vari­able is either "true" or "false".  

The operations performed on booleans include: not, or, and, xor, ...

Booleans are central to conditional operations.

A single bit would be sufficient to capture a boolean, however, an entire word is often used given the way memory is used.

Page 23: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Other Interpretations

There are many other ways binary information is interpreted. These include: strings, records, arrays, list, images, sounds, etc.

Binary information does not have meaning in and of itself. It only has meaning when an inter­pretation is placed upon it.

Page 24: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Communication

We often wish to communicate binary informa­tion. 

There are a number of important parameters which characterize the communication channel. These include: 

Latency ­time to communicate empty package.

Transfer rate ­ number of bits per second that can be transmitted for one message.

Page 25: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

MeasuringThe simplest way of measuring the amount of binary information is to count the number of bytes. However, if a message contains the same information repeated over and over, it may be many bytes long, but contains only a small amount information.

Shannon and Weaver (1949) usedentropy to measure and amount of information in a communication channel.  

00000000. ......000000001−0.99 lg 0.99−0.01 lg 0.01=0.081 bits /symbol

00110111. ......101011000−0.5 lg0.5−0.5 lg 0.5=1bit /symbol

Page 26: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Reading and Self Assessment

Chapter 1 (Required reading)

1.1, 1.2, 1.4, 1.5, 1.6, 1.7

Questions/Exercises (Students are encouraged to do all questions in the sections that are required reading.  However, the list be­low give a set of questions to help you gain some feedback on how you are going.  You are strongly encouraged to do these. Questions like this make good exam questions!)

1.1 : 1,6,7 (Note that we come back to this section in the next lec­ture.) 

1.2 : 1,3.   1.4 : 1,3,5,6.  1.5 : 3,4.  1.6 : 1,2,5.   1.7 : 1,2.       

Page 27: comp1200 notes arch1 - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/courses/archive/comp1200.2005/lectures/... · 000 0 001 1 010 2 011 3 100 4 101 5 110 6 ... Consider the binary

Challenge

This challenge is just for fun.

Write the shortest program(you may use any lan­guage) that will output to standard out the following string:

01010101010101010101010101010101010101010101010101010101

How about this string?01101101011101011000001011101001100011010101101011110101