Winter 2016CISC101 - Prof. McLeod1 Today Go over the Python disassembly “experiment” again. Code interpretation vs. code compilation. History and features.

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Designing a Program & the Java Programming Language
Programming for Beginners
Chapter 2 Machine Language.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Introducing Programming a general discussion. What is a Program? Sets of instructions that get the computer to do something Programs may be a few lines.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 7: Java basics Stewart Blakeway
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to a Programming Environment
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Activity 1 - WBs 5 mins Go online and spend a moment trying to find out the difference between: HIGH LEVEL programming languages and LOW LEVEL programming.
1 Chapter-01 Introduction to Computers and C++ Programming.
CSC 110 A 1 CSC 110 Introduction to Python [Reading: chapter 1]
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Hello World 2 What does all that mean?.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Programming With C.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
I Power Higher Computing Software Development Development Languages and Environments.
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
 Computer Languages Computer Languages  Machine Language Machine Language  Assembly Language Assembly Language  High Level Language High Level Language.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Winter 2006CISC121 - Prof. McLeod1 Stuff Solution to midterm is posted. Marking has just started… Lab for this week is not posted (yet?). Final exam (full.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 Today Numeric representation (or “How does binary and hexadecimal work?”). How can a CPU understand instructions written.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website:
Quiz 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
Software Engineering Algorithms, Compilers, & Lifecycle.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Evolution and History of Programming Languages
Computer Basics.
Introduction to programming languages, Algorithms & flowcharts
Introduction to programming languages, Algorithms & flowcharts
CSCI-235 Micro-Computer Applications
A451 Theory – 7 Programming 7A, B - Algorithms.
Variables, Expressions, and IO
Teaching Computing to GCSE
Introduction to programming languages, Algorithms & flowcharts
TRANSLATORS AND IDEs Key Revision Points.
CS190/295 Programming in Python for Life Sciences: Lecture 1
Winter 2018 CISC101 11/15/2018 CISC101 Reminders
Hello World 2 What does all that mean?.
Computers: Hardware and Software
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 11/29/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Introduction to Computer Programming
CISC101 Reminders All assignments are now posted.
ICT Programming Lesson 1:
CISC101 Reminders Labs start this week. Meet your TA! Get help with:
Winter 2019 CISC101 4/8/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Chapter 1: Programming Basics, Python History and Program Components
General Computer Science for Engineers CISC 106 Lecture 03
CISC101 Reminders Assignment 3 due today.
1.3.7 High- and low-level languages and their translators
Presentation transcript:

Winter 2016CISC101 - Prof. McLeod1 Today Go over the Python disassembly “experiment” again. Code interpretation vs. code compilation. History and features of Python.

Disassembly Experiment Python has a module called “dis” that can show you the assembly language version of a Python line of code, function, object or an entire module. At the >>> prompt type: >>> import dis >>> a = 10 >>> b = 30 >>> c = 2 >>> dis.dis("z = a + b * c") Winter 2016CISC101 - Prof. McLeod2

Disassembly Experiment, Cont. You see: 1 0 LOAD_NAME 0 (a) 3 LOAD_NAME 1 (b) 6 LOAD_NAME 2 (c) 9 BINARY_MULTIPLY 10 BINARY_ADD 11 STORE_NAME 3 (z) 14 LOAD_CONST 0 (None) 17 RETURN_VALUE Winter 2016CISC101 - Prof. McLeod3

Disassembly Experiment, Cont. One line of Python code required eight lines of assembly! Note that the multiply is carried out before the addition. Why did the interpreter choose that order? In case you are curious, see section in the Python help docs for the meaning of assembly instructions. These ones are explained on the next slide: Winter 2016CISC101 - Prof. McLeod4

Disassembly Experiment, Cont. LOAD_NAME pushes a value onto the stack from a variable name. BINARY_MULTIPLY multiplies the two numbers on top of the stack and puts the result on top of the stack. BINARY_ADD adds the two numbers on top of the stack and puts the result back on the stack. STORE_NAME takes the value on the top of the stack and stores it into a variable name. LOAD_CONST puts a zero on top of the stack, to clear it. RETURN_VALUE returns the value on top of the stack (zero in this case) as a result of the evaluation of the expression. Winter 2016CISC101 - Prof. McLeod5

Disassembly Experiment, Cont. The “stack” is used to temporarily hold values and the results of calculations. How the stack changes after each instruction: top: Winter 2016CISC101 - Prof. McLeod a a b a b c a z b * ca + b * c

Aside – What’s a Stack? A “LIFO” – “Last In, First Out” type of data structure. (Like a plate dispenser in a cafeteria!) You “push” values on to the top of the stack and “pop” them off. (Aside - What is a “stack overflow”? Often results from infinite recursion, for example.) Winter 2016CISC101 - Prof. McLeod7

Machine Code Once code is disassembled, the interpreter needs to generate machine code. It uses the opcodes, opargs and operands from each line of assembly. We can view (and sometimes write) machine code in hex. But, the interpreter will not bother with this stage – it translates from assembly to binary. Winter 2016CISC101 - Prof. McLeod8

Compiled vs Interpreted More on this topic later. Binary commands can be compiled and then written to an *.exe or “executable” file. When you run a file like this the code is sent directly to the CPU, which is very fast! Python does not make these files, but generates binary machine language on the “fly” – sending it directly to the CPU. Python “interprets” source code and generates machine language and executes it immediately. Winter 2016CISC101 - Prof. McLeod9

10 Computer Languages, History After Assembly language, the next generation of computer languages went up one more level, getting closer to something readable - for example: Fortran, Cobol and Lisp. These languages led to an explosion of over 200 languages being developed in the 60’s and 70’s, such as Basic, Pascal, C, Ada and Smalltalk. Python is a relative newcomer, arriving on the scene in the early 90’s. See: ages Winter 2016

Aside – 99 Bottles of Beer… See: Programs in 1500 different programming languages to generate the lyrics to the “song”. CISC101 - Prof. McLeod11Winter 2016

Aside - Malbolge A programming language designed to be extremely hard to program in and impossible to read. Named after the eighth circle of Hell in Dante’s “Inferno”. Featured in an episode of Elementary (S01E10). –They supposedly had a program in Malbolge that de- crypted a safe’s combination. –What they really had was “Hello World” in Malbolge: CISC101 - Prof. McLeod12Winter 2016

“Hello World” in Malbolge CISC101 - Prof. McLeod13Winter 2016

CISC101 - Prof. McLeod14 History of Python The language was created by Guido van Rossum at Stichting Mathematisch Centrum in the Netherlands in the early 90’s. He is still very involved with the language and retains the title “BDFL”, which stands for “Benevolent Dictator for Life”. Python is named after “Monty Python”, not the snake!! Winter 2016

CISC101 - Prof. McLeod15 History of Python, Cont. He wanted to make the language: –an easy and intuitive language, but just as powerful as major competitors. –open source, so anyone can contribute to its development. –use code that is as understandable as plain English. –to be suitable for everyday tasks, allowing for short development times. First released in 1994, the language was inspired by Modula-3, Lisp, SETL, Haskell, Icon and Java. A compilation of all the “Best-Of’s” from many other languages! Winter 2016

CISC101 - Prof. McLeod16 Features of Python High Level –Most notable are the built-in data structures. Object Oriented –OOP helps you to build code in a modular way. But, Python allows you to write code without knowing anything about OOP! Scalable –Packaging of code allows even very large programming projects to be manageable. Extensible –You can easily use external code modules written in Python, C, C++, C#, Java or Visual Basic. Winter 2016

CISC101 - Prof. McLeod17 Features of Python, Cont. Portable –Runs on any platform/OS combination that can run C. Easy to Learn (!) –Relatively few keywords, simple language structure and clear syntax. OOP can be avoided while learning. Easy to Read –Much less punctuation than other languages. Forces you to use good indentation. Easy to Maintain –Results from the two above features! Winter 2016

CISC101 - Prof. McLeod18 Features of Python, Cont. Robust –Exception handlers and safe, sane and informative crashes. Good for Rapid Prototyping –Often used with other languages to create prototypes and provide a testing platform. Built-In Memory Management –Like Java. Avoids a major problem in C/C++. Interpreted –Not compiled – each command is executed as it is read from the program. Speed is increased using byte- compiled files (like Java). Winter 2016

Hello World Write a program that prompts the user for his first name and then displays “Hello name” to the console. Put the code in a main function. Just for fun, disassemble the program when it is done. Winter 2016CISC101 - Prof. McLeod19

Questions Do you have to put code in a main function? Why is it called “main()”? What’s with the “()”? They are empty! Why is there a call to main() at the end of the program? How can you tell what code is inside main() and what is outside? Winter 2016CISC101 - Prof. McLeod20

Questions, Cont. What does the input() BIF return? How can you get a number, like an int, from input()? What does the print() BIF return? What does “+” do with strings? I can add numbers with “+”, as well. Can I add a number to a string? Winter 2016CISC101 - Prof. McLeod21