Document Details

CongratulatoryNephrite3972

Uploaded by CongratulatoryNephrite3972

Lehman College, CUNY

2018

Tags

computer programming CPU operations high-level languages programming concepts

Summary

This document explains how a program works, from basic CPU operations to high-level languages. It includes diagrams and explains concepts such as compilers and interpreters.

Full Transcript

Copyright © 2018 Pearson Education, Inc. How a Program Works CPU designed to perform simple operations on pieces of data Examples: reading data, adding, subtracting, multiplying, and dividing numbers Understands instructions written in machine language and included in its...

Copyright © 2018 Pearson Education, Inc. How a Program Works CPU designed to perform simple operations on pieces of data Examples: reading data, adding, subtracting, multiplying, and dividing numbers Understands instructions written in machine language and included in its instruction set Each brand of CPU has its own instruction set To carry out meaningful calculations, CPU must perform many operations Copyright © 2018 Pearson Education, Inc. How a Program Works (cont’d.) Program must be copied from secondary memory to RAM each time CPU executes it CPU executes program in cycle: Fetch: read the next instruction from memory into CPU Decode: CPU decodes fetched instruction to determine which operation to perform Execute: perform the operation Copyright © 2018 Pearson Education, Inc. How a Program Works (cont’d.) Figure 1-16 The fetch-decode-execute cycle Copyright © 2018 Pearson Education, Inc. From Machine Language to Assembly Language Impractical for people to write in machine language Assembly language: uses short words (mnemonics) for instructions instead of binary numbers Easier for programmers to work with Assembler: translates assembly language to machine language for execution by CPU Copyright © 2018 Pearson Education, Inc. High-Level Languages Low-level language: close in nature to machine language Example: assembly language High-Level language: allows simple creation of powerful and complex programs No need to know how CPU works or write large number of instructions More intuitive to understand Copyright © 2018 Pearson Education, Inc. Key Words, Operators, and Syntax: an Overview Key words: predefined words used to write program in high-level language Each key word has specific meaning Operators: perform operations on data Example: math operators to perform arithmetic Syntax: set of rules to be followed when writing program Statement: individual instruction used in high-level language Copyright © 2018 Pearson Education, Inc. Compilers and Interpreters Programs written in high-level languages must be translated into machine language to be executed Compiler: translates high-level language program into separate machine language program Machine language program can be executed at any time Copyright © 2018 Pearson Education, Inc. Compilers and Interpreters (cont’d.) Interpreter: translates and executes instructions in high-level language program Used by Python language Interprets one instruction at a time No separate machine language program Source code: statements written by programmer Syntax error: prevents code from being translated Copyright © 2018 Pearson Education, Inc. Compilers and Interpreters (cont’d.) Figure 1-19 Executing a high-level program with an interpreter Copyright © 2018 Pearson Education, Inc.

Use Quizgecko on...
Browser
Browser