Lecture 07 – October 11, 2001 Programming our toy machine Review of hardware Storing images and sounds Compression Administrivia –send questions to

Slides:



Advertisements
Similar presentations
RAM (cont.) 220 bytes of RAM (1 Mega-byte) 20 bits of address Address
Advertisements

Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor Department of Computer Science James Madison University 1 Some sldes are adapted from.
A Digital Imaging Primer Nick Dvoracek Instructional Resources Center University of Wisconsin Oshkosh.
What Is A Computer System?
Henry Hexmoor1 Chapter 7 Henry Hexmoor Registers and RTL.
1 Foundations of Software Design Lecture 3: How Computers Work Marti Hearst Fall 2002.
Traffic Light Behavior IF A=1 AND B=0 Car Sensors B A.
Connecting with Computer Science, 2e
Midterm Review October 23, 2001.
Machine Languages Different types of CPU’s understand different instructions Pentium family / Celeron / Xeon / AMD K6 / Cyrix … (Intel x86 family) PowerPC.
Counters and Registers
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
CS 1308 Computer Literacy and the Internet. Creating Digital Pictures  A traditional photograph is an analog representation of an image.  Digitizing.
Representing Information Digitally. Digitization Initially transforming data for computer use Assigning people social security numbers The creation of.
CSCI-235 Micro-Computers in Science Hardware Part II.
HARDWARE: CPU & STORAGE How to Buy a Multimedia Computer System.
Lab #5-6 Follow-Up: More Python; Images Images ● A signal (e.g. sound, temperature infrared sensor reading) is a single (one- dimensional) quantity that.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Adding some light to computing ….
Computer Terms. Computer A machine designed to run programs and store information that you create.
Chapter 11 Fluency with Information Technology 4 th edition by Lawrence Snyder (slides by Deborah Woodall : 1.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 14 Introduction to Computer Graphics.
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
Data Representation CS280 – 09/13/05. Binary (from a Hacker’s dictionary) A base-2 numbering system with only two digits, 0 and 1, which is perfectly.
Exam Format  105 Total Points  25 Points Short Answer  20 Points Fill in the Blank  15 Points T/F  45 Points Multiple Choice  The above are approximations.
Marwan Al-Namari 1 Digital Representations. Bits and Bytes Devices can only be in one of two states 0 or 1, yes or no, on or off, … Bit: a unit of data.
CSCI-100 Introduction to Computing Hardware Part II.
COMP135/COMP535 Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 2 Lecture 2 – Digital Representations.
Computers. Light A Review: State Machine IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always.
Control units In the last lecture, we introduced the basic structure of a control unit, and translated our assembly instructions into a binary representation.
REGISTER TRANSFER LANGUAGE (RTL) INTRODUCTION TO REGISTER Registers1.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Information in Computers. Remember Computers Execute algorithms Need to be told what to do And to whom to do it.
Computer Basics Just How Does a Computer Work?
DATA Unit 2 Topic 2. Different Types of Data ASCII code: ASCII - The American Standard Code for Information Interchange is a standard seven-bit code that.
Lecture # 36 Computer Architecture and Organization.
Computer System Hardware
Computer Architecture and Number Systems
Introduction to Computers
DIGITAL MEDIA FOUNDATIONS
Understanding Web Graphics
Dr.Ahmed Bayoumi Dr.Shady Elmashad
Data Representation.
Everything is a number Everything in a computer memory and on storages is a number. Number  Number Characters  Number by ASCII code Sounds  Number.
Denary to Binary Numbers & Binary to Denary
REGISTER TRANSFER LANGUAGE (RTL)
Topics Introduction Hardware and Software How Computers Store Data
What is a computer? Simply put, a computer is a sophisticated electronic calculating machine that: Accepts input information, Processes the information.
Control Unit Lecture 6.
Data Compression.
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
Morgan Kaufmann Publishers
Data Compression.
Chapter III, Desktop Imaging Systems and Issues: Lesson IV Working With Images
Data Compression CS 147 Minh Nguyen.
Instructions at the Lowest Level
Introduction to Computing Lecture # 1
The Building Blocks: Binary Numbers, Boolean Logic, and Gates
Computer Systems – Unit 1
Topics Introduction Hardware and Software How Computers Store Data
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Logical Computer System
Branch instructions We’ll implement branch instructions for the eight different conditions shown here. Bits 11-9 of the opcode field will indicate the.
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Control units In the last lecture, we introduced the basic structure of a control unit, and translated our assembly instructions into a binary representation.
Review: The whole processor
Registers Today we’ll see some common sequential devices: counters and registers. They’re good examples of sequential analysis and design. They are also.
WJEC GCSE Computer Science
Computer Operation 6/22/2019.
CS 1308 Exam 2 Review.
Presentation transcript:

Lecture 07 – October 11, 2001 Programming our toy machine Review of hardware Storing images and sounds Compression Administrivia –send questions to not –NO lab sessions on Fridays (do the lab before Friday if you want help from the lab TAs) –Collaboration policy Everyone does their own writeup

CPU Memory Registers Register 0Register 1Register 2Register 3Instruction RegisterInstr. Pointer (IP) Arithmetic / Logic Unit Control Unit (State Machine)

Our Example CPU We’ll look at a toy CPU’s Machine Language: Our CPU has: 8 Registers – each holds 16 bits (2 bytes) Our RAM: Works in blocks of 16 bits (2 bytes) Has 2 8 = 256 addresses Total Memory: 512 bytes

Machine “Core” Everything is in binary (hex) Registers R0: 0000 R1: 0CA8 R2: A9DB R3: 0705 R4: 1011 R5: 90A0 R6: 0807 R7: 00A0 00: : : C: : B106B200B … F8: FC: Memory

Representing Instructions Machine instructions will also be represented by 16 bits. We divide those bits into 4 groups - 4 bits each: The first group of 4 bits is called the Op-Code: Tells what instruction it is. 6 C A 5

Instructions 16 possible Op-Codes: We’ll only look at a few in detail… 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left

Halt Instruction 0 : Halt This just tells the machine to stop. Other 12 bits are ignored: All have same effect. 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left F F F 0 9 A C

Data Instructions B : Load Direct / Address Sets a Register to a fixed Specified Value Encoding: Effect: Register A becomes the specified value 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left B regA value (8 bits)

Arithmetic/Logic Instructions 1 : Add Adds contents of two registers together and puts result in third register Encoding: Effect: Register A becomes Register B + Register C 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left 1 regA regB regC

Adding Numbers Simple Program to calculate = 21 = 15 (hex) 10: Load R0  0001 (always 1) 11: Load R2  0000 (running total) 12: Load R1  0001 (current number) 13: Add R2  R2 + R1 (R2=1) 14: Add R1  R1 + R0 (R1=2) 15: Add R2  R2 + R1 (R2=3) 16: Add R1  R1 + R0 (R1=3) 17: Add R2  R2 + R1 (R2=6) 18: Add R1  R1 + R0 (R1=4) 19: Add R2  R2 + R1 (R2=A) 1A: Add R1  R1 + R0 (R1=5) 1B: Add R2  R2 + R1 (R2=F) 1C: Add R1  R1 + R0 (R1=6) 1D: Add R2  R2 + R1 (R2=15) 1E: halt

Adding Numbers Simple Program to calculate = 21 = 15 (hex) Let’s watch it execute

Arithmetic/Logic Instructions 2 : Subtract Similar to Add… Encoding: Effect: Register A becomes Register B - Register C 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left 2 regA regB regC

Control Instructions 6 : Jump if Positive Jump to a different place in memory if Register is > 0 Encoding: Effect: If Register A > 0, Go To Instruction at specified address 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left 6 regA address (8 bits)

Adding Numbers Use a Loop to calculate … + N 10: Load R1  0006 (N) 11: Load R2  0000 (running total) 12: Load R0  0001 (always 1) 13: Add R2  R2 + R1 (add in N) 14: Sub R1  R1 - R0 (N = N-1) 15: Jump to 13 if (R1>0) (If N isn’t 0 yet, go back) 16: halt (N is now 0, and R2 = 1+2+…+N)

Adding Numbers Use a Loop to calculate … + N Execution

Control Instructions 7 : Jump and count (backwards) Jump to a different place in memory if Register is > 0, AND decrement by 1 Encoding: Effect: If Register A > 0, Go To Instruction at specified address, and A = A - 1 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left 7 regA address (8 bits)

Adding Numbers Alternate Loop using Jump & Count for … + N 10: Load R1  0006 (N) 11: Load R2  0000 (running total) 12: Add R2  R2 + R1 (add in N) 13: Jump to 12 and (If N isn’t 0 yet, decrease R1 if (R1>0) Let N=N-1, and go back) 14: halt (N is now 0, and R2 = 1+2+…+N)

Adding Numbers Alternate Loop using Jump & Count for … + N Execution

Memory Instructions 9 : Load (from memory) Load from Memory into Register Encoding: Effect: Load from RAM at specified address into Register A 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left 9 regA address (8 bits)

Memory Instructions A : Store (into memory) Store Register into Memory Encoding: Effect: Store contents of Register A into memory at specified address 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left A regA address (8 bits)

Memory Instructions: Indirect 9 : Load (from memory) Load from Memory into Register Encoding: Effect: Load from RAM at address [B+C] into Register A 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left 9 regA regB regC

How can CPU tell these apart? Sneaky trick: CPU has 8 Registers, so only need 3 bits to specify Register A Use extra bit to tell which type of LOAD Memory Instructions: Indirect 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left 9 regA regB regC 9 regA address (8 bits)

This is called a HACK! Hacks are terrible! Generally should be avoided. Sadly, they are everywhere. Some CS people get perverse pleasure out of hacks. This is a major source of bugs! Hacks 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left

A Virus! Copies itself on top of other programs! 10: Load R1  0006 (Length of Virus) 11: Load R2  001F (Memory Location to copy self To -1) 12: Load R3  000F (Memory Location to copy self From -1) 13: Load R0  Memory[R3+R1] (Load instruction from source) 14: Store Memory[R2+R1]  R0 (Store instruction in destination) 15: Jump to 13 and (If haven’t copied whole virus, decrease R1 if (R1>0) decrease R1, and go back) 16: halt (Virus has replicated)... ______________________________________________________________ 20:.... (Program about to be destroyed.) 21:

A Virus! Copies itself on top of other programs! Execution

We looked at a typical Machine Language and how instructions are represented. Halt Instruction Data Instructions Arithmetic/Logic Instructions Control Instructions Memory Instructions Summary

We saw a few simple examples of programs you can write in Machine Language. You now have a pretty solid understanding of how computers really work ! Summary (cont.)

Hardware Wrap-up

Layers of Abstraction Build more and more powerful tools out of simpler ones. Really Simple Stuff Computers

Logic Gates AND X Y Z OR X Y Z X Y NOT X Y

Universal Method AND A C B A C A C B B A B C F First, make circuits for each row in Truth Table with a 1 in the output.

OR Universal Method (cont.) AND A C B A C A C B B Finally, combine them with an OR gate. F

Universality For ANY Truth Table we can write down, we can make a circuit for it using only 3 Logic Gates: AND, OR, NOT In real life, make AND/OR/NOT gates out of Transistors.

Representing Information Information in the world comes in many forms – letters, numbers, pictures, sounds… How can we represent these things with 0’s and 1’s? Start with numbers.

The Flip-Flop OR AND Set Reset M M becomes 1 if Set is turned on M becomes 0 if Reset is turned on Otherwise (if Set and Reset are both 0), M just remembers its value

“Snapshot” Memory When Write changes from 1 to 0, the value of D gets stored in M. (“snapshot”) Otherwise, M just remembers its value. (It ignores D.) D Write M

Design for Any State Machine Memory Register Clock Inputs Logic For Next State & Output Outputs Current State

Review On our way to building a computer… Computers We are here … Represent & Manipulate Info. with 0’s & 1’s (aka bits) Memory Circuits State Machines

Putting it all together Bus CPU RAM Keyboard Hard Disk Display CD-ROM Computer has many parts, connected by a Bus: Each part is a state machine.

Putting it all together This cycle is orchestrated by the Control Unit in the CPU. Memory Registers Register 0Register 1Register 2Register 3Instruction RegisterInstr. Pointer (IP) Arithmetic / Logic Unit Control Unit (State Machine)

Instructions 0: halt 1: add 2: subtract 3: multiply 4: bus output 5: jump 6: jump if positive 7: jump & count 8: bus input 9: load A: store B: load direct/addr. C: NAND D: AND E: Shift Right F: Shift Left

Adding Numbers Simple Program to calculate = 21 = 15 (hex) 10: Load R0  0001 (always 1) 11: Load R2  0000 (running total) 12: Load R1  0001 (current number) 13: Add R2  R2 + R1 (R2=1) 14: Add R1  R1 + R0 (R1=2) 15: Add R2  R2 + R1 (R2=3) 16: Add R1  R1 + R0 (R1=3) 17: Add R2  R2 + R1 (R2=6) 18: Add R1  R1 + R0 (R1=4) 19: Add R2  R2 + R1 (R2=A) 1A: Add R1  R1 + R0 (R1=5) 1B: Add R2  R2 + R1 (R2=F) 1C: Add R1  R1 + R0 (R1=6) 1D: Add R2  R2 + R1 (R2=15) 1E: halt

Adding Numbers Use a Loop to calculate … + N 10: Load R1  0006 (N) 11: Load R2  0000 (running total) 12: Load R0  0001 (always 1) 13: Add R2  R2 + R1 (add in N) 14: Sub R1  R1 - R0 (N = N-1) 15: Jump to 13 if (R1>0) (If N isn’t 0 yet, go back) 16: halt (N is now 0, and R2 = 1+2+…+N)

A Virus! Copies itself on top of other programs! 10: Load R1  0006 (Length of Virus) 11: Load R2  001F (Memory Location to copy self To -1) 12: Load R3  000F (Memory Location to copy self From -1) 13: Load R0  Memory[R3+R1] (Load instruction from source) 14: Store Memory[R2+R1]  R0 (Store instruction in destination) 15: Jump to 13 and (If haven’t copied whole virus, decrease R1 if (R1>0) decrease R1, and go back) 16: halt (Virus has replicated)... ______________________________________________________________ 20:.... (Program about to be destroyed.) 21:

We’ve covered the basics of computers. What we’ve left out: How to make computers faster. How to make circuits more efficient Large machine languages “Pipelining” – make the computer execute more than one instruction at once. Parallelism – having many CPUs work together To learn more, take CS courses (217,306,471) Further Directions

Sounds and Images How do we represent sounds? How do we represent images? These representations are too big, can we compress? How do we manipulate them? –Next few lectures –Next 2 labs

Representing sounds Start from waveform of the sound Then digitize Eventually, consider frequencies

The waveform

Sampling

The approximation

Finer sampling

Even finer sampling

Analog vs. digital In analog technology, a wave is recorded or used in its original form. For example, in an analog tape recorder, a signal is taken straight from the microphone and laid onto tape. The wave is analog. It can be read, amplified and sent to a speaker to produce the sound. In digital technology, the analog wave is sampled at some interval, and then turned into numbers that can be stored digitally.

Digital sound On a CD, the sampling rate is 44,100 samples per second. Each sample is quantized into a number in the range from 0 to 65,535, So a CD has 44,100 numbers (each 2 bytes) per second of music. Numbers are used to make a voltage wave that approximates the original wave. Advantages of digital technology –Recording does not degrade over time. –Groups of numbers can often be compressed by finding patterns in them. –It is easy to use special computers called digital signal processors (DSPs) to process streams of numbers.

Numeracy CD has 44,100 2 byte samples per second. 44,100 x 2 x 60 x 2 (channels) = megabytes per CD minute A CD is 74 minutes (746 megabytes) long. MP3 players typically use memory 32 or 64 megabytes in size. (or 3-6 minutes) Compression is needed

Frequency domain Sounds are made up of frequencies. We often want to filter out certain frequencies – scratches, background noise, … or because we are unable to hear them. How do we do such things?

Enter Jean Baptiste Joseph Fourier He lived in France Developed the idea of building trigonometric series for turning signals measured over time into signals measured by frequency His ideas are the basis of digital signal processing (DSP)

Demonstration Fourier transform

Representing Images Start from analog representation (waveform) of the image Then digitize Eventually, consider frequencies

Digital resolution A printer will display 300 or 600 or 1200 dots per inch (dpi). Visually –Less than 150 dots per inch is tiring –200 dots per inch makes a very crisp screen display –600 dots per inch is now the norm –1200 dots per inch was what phototypesetters did –Photograph negatives typically have 2000 dots per inch Each dot can have 256 shades of selected colors. –Printers use Cyan, Yellow, Magenta and sometimes blacK –Monitors use Red, Green and Blue.

Numeracy An 8”x10” picture at 600 dpi has –80 square inches 360,000 dots per square inch –28,800,000 dots per picture Each dots can be 3 bytes –86.4 Megabytes of storage So, compression is needed

Representing Images Each dot is a picture element (or a pixel) So, a picture is just a stream of bytes. When we process the picture (as we will in the next lab) we manipulate the bytes.

Frequency domain for images Images are made up of frequencies. We often want to filter out certain frequencies – scratches, background of image, … By checking for frequencies, we can find places where the image changes. How do we do such things?

The need for compression A CD is 746 megabytes long A printed page requires 86.4 Megabytes of storage

Compression Start with text –Eliminate duplication –Be more clever Move to sounds and images –Remove frequencies that won’t be heard/seen –Apply text ideas –Be willing to lose part of the image/sound that doesn’t matter

Simple compression A sentence to compress –"Ask not what your country can do for you - - ask what you can do for your country."

Simple compression (cont.) "Ask not what your country can do for you -- ask what you can do for your country." –The quote has 17 words, made up of 61 letters, 16 spaces, one dash and one period. Storing this, takes 79 units of memory.

How to shrink Use redundancy Immediately, we notice that: "ask", "what", "your", "country", "can", "do", "for", and "you" appear two times.

Shrink via redundancy Immediately, we notice that: "ask", "what", "your", "country", "can", "do", "for", and "you" appear two times. Build a dictionary: 1 => ask 2 => what3 => your 4 => country5 => can6 => do 7 => for8 => you Our sentence now reads: "1 not “

Using redundancy Build a dictionary: 1 => ask 2 => what3 => your 4 => country5 => can6 => do 7 => for8 => you Our sentence now reads: "1 not “ Ask what your country can do for you*1 not Memory usage –37 units and 37 units for dictionary = 74 units –Need a symbol to tell when the dictionary ends –Need to know that there are no numbers or * in text

Use patterns to further shrink New dictionary 1.Ask_ 2.what_ 3.you 4.r_country 5._can_do_for_you New encoding of sentence –“1not_2345_--_12354" Ask_#what_#you#r_country# _can_do_for_you*1not_2345_--_12354 Memory usage –18 units and 41 units for dictionary = 59 units

Typical savings Text files (unstructured) –Usually can compress by half Text files (structured – e.g. computer programs) –Compression is greater Music/Image files –Can usually reduce by factor of 10 with some loss Jpeg, mp3, … files –Usually no savings – they’re already compresed

More complex compression Lossy compression –Can save space by eliminating parts of the image/sound that don’t matter very much –Big savings compared to lossless –Ideas Dropping frequencies you can’t hear Dropping small differences you won’t notice –Generally large savings compared to lossless

Formats GIF – original graphics compression format –Can be lossy or lossless –Limits numbers of colors to 256 (2 8 vs ) –Can be progressive JPEG ( Joint Photographic Experts Group ) –Can adjust level of lossy-ness –Most popular format MPEG (Moving Picture Experts Group) –Built on JPEG –Works also in the time dimension

MPEG-3 Audio layer This is MP3 Compresses sound by about a factor of 10 Preserves CD quality sound