Download presentation
Presentation is loading. Please wait.
Published byMark Mervin Cross Modified over 8 years ago
1
How does a computer works Hyoungshick Kim Department of Computer Science and Engineering College of Information and Communication Engineering Sungkyunkwan University Computer Programming for Engineers (2016 Spring)
2
Objectives In this course, you will learn about What computer is How a computer works
3
What is computer? (Discussion time)
4
Arduino Computer www.arduino.cc
5
Computer Computer = Hardware + Software Like piano and music “Hardware” refers to the physical parts of the computer (cf. “software” refers to the code that runs on the computer)
6
Computer Hardware
7
CPU CPU - Central Processing Unit The brains of the computers Performs simple operations e.g. Add two numbers Computer can run 2 billion operations per second Run button... code "runs" on the CPU
8
RAM RAM - Memory, Random Access Memory Temporary, working storage bytes RAM is "volatile", not "persistent",.. gone when power goes out
9
Persistent Storage Persistent storage "Non volatile".. preserved when not powered Hard drive - stores bytes as a magnetic pattern on a spinning disk Flash drive - stores bytes as electrons in a chip SD card, flash chips built into a phone or tablet Not to be confused with "Adobe Flash", a proprietary media format
10
Software Code that runs on the hardware CPU implements "machine code" instructions Each machine code instruction is extremely simple e.g. add 2 numbers e.g. compare 2 numbers
11
Machine Code A CPU understands a low level "machine code" language The language of the machine code is hardwired into the design of the CPU hardware Each family of compatible CPUs (e.g. the very popular Intel x86 family) has its own, idiosyncratic machine code which is not compatible with the machine code of other CPU families
12
What is a Program? What is Running? "Program" e.g. Firefox, millions of simple machine code instructions Machine code is particular to the type of CPU: Intel, ARM, etc. CPU runs a "fetch/execute cycle" fetch one instruction in sequence execute (run) that instruction, e.g. do the addition fetch the next instruction, and so on "loop" instruction: jump back 10 instructions Loops are implemented this way "if" instruction: skip ahead if a certain condition is true If statements are implemented this way
13
Running a Program How can we run a program (e.g. Firefox.exe)? Firefox.exe is just a file consisting of the bytes of millions of instructions (with about 4 bytes) 0. When we double click a program execution file …
14
Running Instructions The CPU runs instructions using a "fetch-execute" cycle: the CPU gets the first instruction in the sequence, executes it, then fetches the next instruction and executes it, and so on.
15
Syntax, Semantics and Program Translation It is extremely rare to write machine code by hand We write code in a more "high level" computer language with features that are more useful and powerful than the simple operations found in machine code Programming languages (called “artificial languages”) are languages just as “natural languages” such as English and Chinese. Syntax and Semantics are important concepts that apply to all languages. 15
16
Syntax The syntax of a language is a set of characters and the acceptable sequences (arrangements) of those characters. English, for example, includes the letters of the alphabet, punctuation, and properly spelled words and sentences. The following is a syntactically correct sentence in English, “what time is it now?” The following, however, is not syntactically correct, “what tyme is it now?” The sequence of letters “tyme” is not a word in the English language.
17
Semantics The semantics of a language is the meaning associated with each syntactically correct sequence of characters. Consider the following sentence: “A silent noise drinks stones.” This sentence is syntactically correct, but has no meaning. Thus, it is semantically incorrect. Every language has its own syntax and semantics.
18
Syntax Errors vs. Semantic Errors Program debugging is the process of finding and correcting errors (“bugs”) in a computer program. Syntax errors are caused by invalid syntax. (for example, entering prnt instead of print). Since a translator (compiler or interpreter) can detect syntax errors (e.g. prnt), translators terminate and indicate where the error occurred.
19
In contrast, semantic errors are errors in program logic. Such errors cannot be automatically detected, because translators cannot understand the original intention. For example, if a program computes the average of five numbers ; ( 5 + 6 + 3 + 8 + 1) / 4 The divisor should be 5 and not 4, but translators do not understand what a programmer is meant to do. => It is up to the programmer to detect such errors. Program debugging is not a trivial task, and consumes much of the time of program developments.
20
Program Translation A central processing unit (CPU) is designed to interpret and execute a specific set of instructions represented in binary form (i.e., 1s and 0s) called machine code. Only machine code can be executed by a CPU. 20
21
Compiler "Compiler" looks at the source code Compiler translates the source code into a large number of machine code instructions e.g. Firefox -- written in C++ Compiler takes in Firefox C++ source code, produces Firefox.exe The end user does not need to the source code or the compiler. Distribute the program.exe file in working form Does not work backwards -- having the.exe, you cannot recover the source code (well)
22
Visual Representation of Compiler The Compiler for the C++ language, (1) reads that C++ code and (2) translates and expands it to a larger sequence of the machine code instructions to implement the sequence of actions specified by the C++ code
23
Interpreter Interpreter is a program which "runs" other code e.g. web browsers includes a Javascript interpreter Browser "runs" bits of Javascript code in a web page, such as ours Interpreter looks at one line at a time The interpreter then does that action, in the moment Then proceeds to the next line
24
Interpreter vs Compiler The compiler translates source code to equivalent machine code The interpreter does the code, looking at each line and doing it See an example: // Javascript code a = 1; b = a + 2; Interpreter looks at a = 1;, does it Interpreter looks at b = a + 2;, does it
25
Interpreter vs Compiler Discuss their pros and cons
26
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.