CMPT 120 How computers run programs Summer 2012 Instructor: Hassan Khosravi.

Slides:



Advertisements
Similar presentations
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Advertisements

 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
The Binary Numbering Systems
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
COMP3221: Microprocessors and Embedded Systems--Lecture 1 1 COMP3221: Microprocessors and Embedded Systems Lecture 3: Number Systems (I)
COMP3221 lec05-numbers-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 5: Number Systems – I
Chapter 2 : Number System
Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
1 CSE1301 Computer Programming Lecture 29: Number Representation (Part 1)
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital.
Data Representation COE 205
Connecting with Computer Science, 2e
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Introduction to Programming with Java, for Beginners
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Assembly Language for Intel-Based Computers, 4th Edition
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
1 CSE1301 Computer Programming Lecture 28 Number Representation (Integer)
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
Data Representation in Computers
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
CENG 311 Machine Representation/Numbers
Lecture 5.
Computers Organization & Assembly Language
Topics Introduction Hardware and Software How Computers Store Data
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
Computer Science 111 Fundamentals of Programming I Number Systems.
IT253: Computer Organization
CS Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
Binary Arithmetic & Data representation
Chapter 1: Basic Concepts
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Data Representation.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Number Systems Spring Semester 2013Programming and Data Structure1.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
CPU Internal memory I/O interface circuit System bus
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
THE BINARY SYSTEM.
Data Representation, Number Systems and Base Conversions
CSIS The Bit A binary digit The smallest unit of storage Vacuum tubes Transistors A simple circuit.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
CSE1301 Computer Programming Lecture 32: Number Representation
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
Programming and Data Structure
Integer Real Numbers Character Boolean Memory Address CPU Data Types
March 2006 Saeid Nooshabadi
University of Gujrat Department of Computer Science
C1 Number systems.
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Presentation transcript:

CMPT 120 How computers run programs Summer 2012 Instructor: Hassan Khosravi

1.2 How Computers Represent Information All information that is stored and manipulated with a computer is represented in binary with zeros and ones. Why just zeros and ones? Computer’s memory is a whole bunch of tiny rechargeable batteries (capacitors). discharged (0) or charged (1).  It’s easy for the computer to look at one of these capacitors and decide if it’s charged or not. This could be done to represent digits from 0 to 9  di ffi cult to distinguish ten di ff erent levels of charge in a capacitor  hard to make sure a capacitor doesn’t discharge a little to drop from a 7 to a 6

1.3 How Computers Represent Information A single piece of storage that can store a zero or one is called a bit. Bits are often grouped. It’s common to divide a computer’s memory into eight-bit groups called bytes and Number of bits or bytes quickly becomes large For example, “12 megabytes” is 12 × 2 20 bytes = 12,582,912 bytes = × 8 bits = 100,663,296 bits Note that values are approximations Kilo is 1000 here it is 1024

1.4 Unsigned Integers Consider the number = (1 × 10 2 ) + (5 × 10 1 ) + (7 × 10 0 ). Applying the same logic, there is a counting system with bits, binary or base 2 arithmetic The rightmost bit will be the number of 1s(2 0 ), the next will be the number of 2s (2 1 ), then 4s (2 2 ), 8s (2 3 ), 16s (2 4 ), and so on = (1 × 2 3 ) + (0 × 2 2 ) + (0 × 2 1 ) + (1 × 2 0 ) = = (1 × 2 7 ) + (0 × 2 6 ) + (0 × 2 5 ) + (1 × 2 4 ) + (1 × 2 3 ) + (1 × 2 2 ) + (0 × 2 1 ) + (1 × 2 0 ) = =

1.5

1.6 The computer can do operations like addition and subtraction on binary integers the same way you do with decimal numbers Keep in mind that = 2 10 = 10 2

1.7 Positive and Negative Integers One easy way to think of this is to have the left most bit as the sign (0 = positive, 1 = negative) With four bits  would 7  1111 would be -7 Pros: Its easy for the human eye to understand It’s easy to tell if the value is negative: if the first bit is 1, it’s negative. For positive numbers the values are the same as the unsigned representation. Cons Addition and subtraction does not work as before The value 0 has two representations 1000 and 0000.

1.8 two’s complement notation To convert a positive value to a negative value in two’s complement, you first flip all of the bits (convert 0s to 1s and 1s to 0s) and then add one. For example to show -5 Start with the positive version: 0101 Flip all of the bits: 1010 Add one: 1011 With 4bits using two’s complement we can show -8, 7

1.9 Pros and cons of two’s complement Pros It’s easy to tell if the value is negative: if the first bit is 1, it’s negative. For positive numbers the values are the same as the unsigned representation. Addition and subtraction works the same unsigned method The value 0 now has 1 representations 0000 Cons Not as easy for humans to see

1.10 Examples of two’s complement with 4 digits Start with 6  0110 Complement  1001 Add 1  1010 What value is 1110? Take one away  1101 Complement  0010  which is

1.11 Examples of two’s complement −3 + 5 = 2 Start with 3  0011 Complement  1100 Add 1  1101 We only have 4 bits of memory for values -8 to 7 so we ignore last carried one

– 4 What is 1111 Take one away  1110 Complement 

1.13 I-clicker A: I feel comfortable with binary values and mathematical operations on them B: I was following the class and got the basics, I need to practice some more to be comfortable with it I had difficulty in understanding binary values. I need to go over the theory again. D: I didn’t understand binary values and operators on them at all

1.14 Characters A character is a single letter, digit or punctuation Storing characters is as easy as storing unsigned integers. For a byte (8 bits) in the computer’s memory, there are 2 8 = 256 di ff erent unsigned numbers Assign each possible character a number and translate the numbers to characters. The character set used by almost all modern computers, when dealing with English and other western languages, is called ASCII  T =84  $= 36  Number 4 as a string = 52 –Why not give numbers their own value?

1.15 ASCII code

1.16 Extended ASCII codes

1.17 Strings A string is a collection of several characters. Some strings are "Jasper", "742", and "bhay-gn-flay-vn". The particular character set that is used by almost all modern computers, when dealing with English and other western languages, is called ASCII The binary is the same as how does the computer know whether this is “hi” or 18537? The programming language should take care of that.

1.18 Unicode With only one byte per character, we can only store 256 di ff erent characters in our strings But gets quite hard with languages like Chinese and Japanese The Unicode character set was created to overcome this limitation. Unicode can represent up to 2 32 characters. Read topic 2.6 from introduction to computing science and programming

1.19 The Python programming language The programming language we will use in this course is Python. Python is an example of a high-level language; Other high-level languages are C, C++, Perl, and Java. Much easier to program Less time to read and write More likely to be correct Portable Low-level languages, sometimes referred to as “machine languages" or “assembly languages” Only used for a few specialized applications. Computers can only execute programs written in low level. Programs written in high level have to be processed before then can be run. Two kinds of programs process high-level languages into low-level languages:

1.20 Interpreters An interpreter reads a high-level program and executes it, It processes the program a little at a time, alternately reading lines and performing computations. Python is interpreted

1.21 Compiler A compiler reads the program and translates it completely before the program starts running. In this case, the high-level program is called the source code, and the translated program is called the object code or the executable Read chapter 1 from how to think like a computer scientist