z
Chapter 3.6
Source Code and Machine Code
z
Lesson Objectives
- UNDERSTAND HOW THE - LEARN HOW SOURCE
COMPUTER RUNS A CODE IS TURNED INTO
PROGRAM MACHINE CODE
z
- Machine code is the
Machine language the computer
Code understands.
- It consists entirely of
numbers.
- Each computer action
has a number in
machine code.
- Hard for humans to
read or write.
z
Machine Code Example
z
Executable - A file made of
File machine code is called
an executable file.
- Executes many
commands at once.
- Examples: Apps on
your phone are
executable files.
z
z
Executable
File Example
z
Source Code
- Written by programmers in
programming languages.
- Examples: Python, Scratch.
- Must be translated into
machine code before execution.
z
Source Code Example
z
Translating Source Code
- Conversion from
programming language
to machine code is called
translating.
- This allows the
computer to
understand and
execute commands.
z
Translating Source Code Example
z
z
Compiling
1 2 3
- Turning a program - A compiler is used - Example: A
into an executable to perform this task. professional
file is compiling. programmer creating
a game app.
z
Compiling Here's a breakdown for you guy’s:
Explanation
Imagine you're making a scrapbook
about your favorite animal.
You would compile information about
the animal from books, websites, and
maybe even videos.
You would compile pictures of the
animal from different sources.
You would then compile all of this into
your scrapbook, arranging it in a way
that makes sense.
z
Interpreting
- Translating source code into
machine code in real time.
- The computer reads and
executes one command at a time.
- No machine code is stored;
translation occurs each time.
z
Interpreting Explanation
Here's a simpler analogy:
Imagine you have a friend who only speaks
Spanish, and you only speak English.
You want to tell them a story. Interpreting: You
have a friend who knows both languages.
They sit next to you, listen to you speak English
sentence by sentence, and tell your Spanish-
speaking friend what you just said immediately.
This is like how an interpreter works with code.
z
Scratch
- A visual
programming
language used in
web browsers.
- Scratch uses an
interpreter to
translate
commands into
machine code.
- Popular for
teaching
programming to
beginners.
z
Python
- A widely used
programming language.
- Python's interpreter
converts source code into
machine code.
- Installed as part of
Python software on
computers.
z
Debugging Example
- A common mistake:
- Example of Python
misspelling variables
code to input and
(e.g., 'inpt' instead of
multiply numbers.
'input').
- The program stops
and shows an error
message.
z
Why Translating is Important
- Computers cannot
understand source code
directly.
- Translating ensures
commands are
understandable for execution.
z
Summary
- Machine code is the computer's native
language.
- Source code must be translated into
machine code.
- Compilers and interpreters are used for
this purpose.
- Tools like Python and Scratch simplify
programming.
z
Homework
- Write a short explanation of the differences
Write between source code and machine code.
- Research two programming languages and their
Research translators (compiler or interpreter).
Create - Create a small program in Python or Scratch.
z