Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Cross Compilation and Basics of Interpreters in the Week 2 section #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions week2/week2.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
- [Compiling](#compiling)
- [Assembly](#assembly)
- [Linking](#linking)
- [Cross Compilation](#cross-compilation)
- [Header files](#header-files)
- [Object and source files in C: .o and .c](#object-and-source-files-in-c-o-and-c)
- [Brief overview of GNU Make and CMake build systems](#brief-overview-of-gnu-make-and-cmake-build-systems)
- [GNU Make](#gnu-make)
- [Ninja](#ninja)
- [Basic specifications :](#basic-specifications-)
- [Note :](#note-)
- [CMake](#cmake)
- [Memory allocation in C](#memory-allocation-in-c)
- [Static](#static)
- [Automatic](#automatic)
- [Dynamic](#dynamic)
- [Basics of Interpreter](#basics-of-interpreter)
- [Assignment](#assignment)

## Basics of Embedded Programming
Expand Down Expand Up @@ -209,6 +213,12 @@ So, in the above program we only have a single .c file then why did we need to l

Now, we can run the generated binary: `./main` and then output will be `23`.

### Cross Compilation

- A cross-compiler is a tool that transforms source code into object code that will run on a machine other than the one where the compilation was executed.
- For example, a compiler that runs on a PC but generates code that runs on Android smartphone is a cross compiler.
- Embedded computers where a device has extremely limited resources. For example, a microwave oven will have an extremely small computer to read its keypad and door sensor, provide output to a digital display and speaker, and to control the machinery for cooking food. This computer is generally not powerful enough to run a compiler, a file system, or a development environment. So cross compiled binaries can be flashed on the system.

### Header files

- As we all know that files with .h extension are called header files in C. These header files generally contain function declarations which we can be used in our main C program, like for e.g. there is need to include stdio.h in our C program to use function printf() in the program.
Expand Down Expand Up @@ -617,6 +627,22 @@ For example, if you want to allocate dynamically some space to hold a struct foo
}
```

## Basics of Interpreter

- Interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program.
- An interpreter generally uses one of the following strategies for program execution:

- Parse the source code and perform its behavior directly. Ex:- dBASE and BASIC
- Translate source code into some efficient intermediate representation or object code (ex bytecode) and immediately execute that. Ex:- Java
Copy link
Member

@meshtag meshtag Dec 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In previous property, will there be no IR formation/transformation? My opinion is that regardless of the strategy of interpreter, IR formation/lowering will happen always. If efficiency is the major point of difference between both strategies, can you explicitly highlight that.


- Interpreting a program is much slower than executing native machine code
- Interpreting a high-level language is ~100 times slower
Interpreting an intermediate-level (such as JVM bytecode) language is ~10 slower
- If an instruction is called repeatedly, it will be analysed repeatedly - time-consuming!

*JVM (Java Virtual Machine) is a program which accepts and runs Java bytecode on computers. The Sun's official implementation of JVM is mostly written in C/C++.*

## Assignment

* [Assignment 2](../assets/week2/embedded_assignment_2.pdf)