1 / 124

Program Translation

Program Translation. Module 6. Mid-Term Results. Mid-term. Above 93/100 is A. Mid-term. 93/100 or above is A. 60/100 or below is fail. Mid-term. Above 93/100 is A. 60/100 or below is fail. For students who got 120/200 or less at mid-term attendance in make-up is mandatory. Mid-term.

pbeach
Download Presentation

Program Translation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Program Translation Module 6

  2. Mid-Term Results

  3. Mid-term • Above 93/100 is A.

  4. Mid-term • 93/100 or above is A. • 60/100 or below is fail.

  5. Mid-term • Above 93/100 is A. • 60/100 or below is fail. • For students who got 120/200 or less at mid-term attendance in make-up is mandatory.

  6. Mid-term • Above 93/100 is A. • 60/100 or below is fail. • For students who got 120/200 or less at mid-term attendance in make-up is mandatory. • Note that April 10th 2008 is the course withdrawal deadline.

  7. Mid-term • Above 93/100 is A. • 60/100 or below is fail. • For students who got 120/200 or less at mid-term attendance in make-up is mandatory. • Note that April 10th 2008 is the course withdrawal deadline. • I will send a private email to those students who are below the fail threshold so far and let them know how good they should perform from now (future exams and HWs) on to avoid being failed.

  8. Questions • Mid-term? • Assignment 3? • Assignment 3 is due mid-night April 4th.

  9. Program Translation Module 6

  10. Introduction • Computers are not smart. • They do only what we ask them to do.

  11. Introduction • Computers are not smart. • They do only what we ask them to do. • That is they can do whatever we know how to order it to perform. • But we use computers because they are fast and precise.

  12. The Binary Machine • A modern computer can run programs written in Java, C, C++, Lisp, JavaScript, Cobol and many others. • So the computers appear to be Multilingual.

  13. The Binary Machine • A modern computer can run programs written in Java, C, C++, Lisp, JavaScript, Cobol and many others. • So the computers appear to be Multilingual. • But every computer ever built “understands” only one language:

  14. The Binary Machine • A modern computer can run programs written in Java, C, C++, Lisp, JavaScript, Cobol and many others. • So the computers appear to be Multilingual. • But every computer ever built “understands” only one language: the machine language it is wired to use.

  15. The Binary Machine • A modern computer can run programs written in Java, C, C++, Lisp, JavaScript, Cobol and many others. • So the computers appear to be Multilingual. • But every computer ever built “understands” only one language: the machine language it is wired to use. • Thus, the machine language of an Intel PC is different than an IBM personal computer or Sun Workstation.

  16. The Binary Machine • If we want to use a language like JavaScript to write a program, first we need to have a tool to translate the program to machine language which our computer understands.

  17. Program Translation • The notion of translation is central to our discussion. • A modern programming language is designed with two audiences in mind:

  18. Program Translation • The notion of translation is central to our discussion. • A modern programming language is designed with two audiences in mind: • The programmers who use the language to write programs for computers. • The computer, which needs to execute (run) the instructions in the language.

  19. Program Translation

  20. Machine Language Here is a sample of a machine language for a hypothetical computer: 0000010010000000 0000000010000001 0000111100000000

  21. Binary Presentation • The instructions of a machine language are represented using just 0s and 1s.

  22. Binary Presentation • The instructions of a machine language are represented using just 0s and 1s. • In the next module we’ll see that all computers represent all the information in binary notation.

  23. Binary Presentation • The instructions of a machine language are represented using just 0s and 1s. • In the next module we’ll see that all computers represent all the information in binary notation because they can only distinguish between two values (low voltage level and high voltage level), which we label as 0 and 1.

  24. Binary Presentation • The instructions of a machine language are represented using just 0s and 1s. • In the next module we’ll see that all computers represent all the information in binary notation because they can only distinguish between two values (low voltage level and high voltage level), which we label as 0 and 1. • Binary notation: a notation which uses only two symbols, 0 and 1, to present information.

  25. Binary Presentation • If the computer can work only in terms of 0 and 1, how are we going to represent, store and manipulate the information?

  26. Binary Presentation • If the computer can work only in terms of 0 and 1, how are we going to represent, store and manipulate the information? • We can use some sort of binary notation.

  27. Binary Presentation • For example we can have an easy form of binary representation called binary-coded decimal (BCD) notation, in which we use a table for converting a number to this notation and vice versa.

  28. Binary Presentation • For example we can have an easy form of binary representation called binary-coded decimal (BCD) notation, in which we use a table for converting a number to this notation and vice versa. Here is the table:

  29. Examples of BCD Convert number 5683 to BCD format.

  30. Examples of BCD Convert number 5683 to BCD format. 5 6 8 3

  31. Examples of BCD Convert number 5683 to BCD format. 5 6 8 3 By looking at BCD table and inserting the BCD code for each digit we have: 0101 0110 1000 0011

  32. Examples of BCD Convert number 5683 to BCD format. 5 6 8 3 By looking at BCD table and inserting the BCD code for each digit we have: 0101 0110 1000 0011 So the BCD equivalent is: 0101011010000011

  33. Examples of BCD Convert the BCD code 0100100000010000 to a decimal (base 10) number.

  34. Examples of BCD Convert the BCD code 0100100000010000 to a decimal (base 10) number. 1- Divide the sequence into chunks of length 4. Why? 0100 1000 0001 0000

  35. Examples of BCD Convert the BCD code 0100100000010000 to a decimal (base 10) number. 1- Divide the sequence into chunks of length 4. Why? 0100 1000 0001 0000 2- Use the BCD table to find the corresponding digit for each chunk. 4 8 1 0

  36. Examples of BCD Convert the BCD code 0100100000010000 to a decimal (base 10) number. 1- Divide the sequence into chunks of length 4. Why? 0100 1000 0001 0000 2- Use the BCD table to find the corresponding digits for each chunk. 4 8 1 0 3- Put the numbers together in the same order: 4810

  37. Do it yourself? • Convert the number 873 into BCD format. • Convert 0111000010010101 to a decimal number.

  38. Do it yourself? • Convert the number 873 into BCD format. answer: 100001110011 • Convert 0111000010010101 to a decimal number. answer: 7095

  39. BCD notation Disadvantages • For each decimal number of length n we have a BCD code of length 4n. Example: 211 and 001000010001 2. Arithmetic on numbers in BCD format is complicated.

  40. Base-10 Notation • In everyday life we represent numbers in base 10 Positional Notation. • positional: the value of a digit within a number depends on its position. Example: 342 and 432 • base 10 : the value of any position is a multiple of a power of 10. • The digits we use in this notation are: {0, 1, 2, 3, 4, 5, 6, 7,8 ,9 }

  41. Base-10 Notation Example: the number 7689 is interpreted as:

  42. Base-10 Notation Example: the number 129 is interpreted as:

  43. Base 2 Notation • There is nothing special about base 10 notation. • We can use any base to represent numbers. But since computers only understand 0 and 1 we use base 2 notation.

  44. Base 2 Notation • In base two notation we have only two digits: {0, 1} • Each digit in this notation is a multiple of a power of 2 just as in base 10 where each digit is a multiple of a power of 10. • 11010101 is an example of a number in base-2 format.

  45. Base-2 Example The number 11010101 is interpreted as :

  46. Base 2 Example • 213 in base 10 = 11010101 in base 2

  47. Do it yourself • What base-10 number the following base-2 number represents? 10010

  48. Do it yourself • What base-10 number the following base-2 number represents? 10010 Answer: 18

  49. How to Convert Base-10 to Base-2 • We can convert a decimal number to base-2 using a simple algorithm. • Lets see the algorithm through examples.

More Related