Code in C Journey
In this blog, we want to talk about how the software code journey starts from a meeting with the client on the requirement specification of a specific software to the hardware of the machine running this software.
SDLC is software development life cycle is a cycle to produce the software Starting from Planning, Requirements, Analysis, and Design.
After we pass all the previous phases, we must know
- Architecture (Web - Mobile - Embedded)
- Database (SQL - NO SQL - JSON {"key": "value"})
- UI/UX
User interacts with an application with one of 2 main things GUI, or CLI An application interacts with an application with just one thing API
Operating system OS is just software which runs another software on top of it like applications/programs system calls API is the intermediate layer between both of them..
Every program = instructions + data
CPU can only understand some set of instructions called ISA (Instruction Set Architecture) so,
Not all CPUs can understand/execute the same instructions.
All arithmetic operations in CPU are about electricity High voltage and low voltage binary 1 - 0 ON - OFF ISA Example which changes by changing CPU HW (Hardware) Add 1110001 Sub 1101110 Mul 1101010
The first programming language is about ml (machine language) zeros and ones.
Assume 0110101011010 is an application that will be loaded in RAM and executed by CPU.
So after writing an app in ML with a type of CPU and changing the CPU this app won't run on any CPU except the one written for or another with similar ISA.
of course, ML is hard to remember debug and understand it's completely a disaster.
some apps depend on the architecture of CPUs like x64 or x32 and overall OS was the solution to all of these as it became the layer between Hardware and every application.
So, the application became dependent on the operating system, not the hardware.
Soon Assembly became available with some keywords
like add R1, 351
And it depended on HW.
Search for Datasheet CPU?
But as CPU can't understand assembly but only one's and zero's so it needed assembler to translate from assembly to ML (Machine Language).
NOW, C Programming appeared after some unwanted untold other programming languages.
C was close to the developer (easy to understand) and away from HW.
Memory-mapping is mapping a place in RAM with an I/O device (Hardware) which if you write data in this place it will reflect to the HW directly. (i.e. turn a bulb ON or OFF).
in the past high-level language - > assembly - > ML
NOW The Journey:
High-level language ==> Translator (compiler / interpreter) ==> ML ==> OS
- provide//allocated resources
- provide system calls
- provides protection
- Load the app in RAM and the CPU executes consequently)
==> HW.
If :
- No OS, change HW ==> change compiler.
- Yes OS, change HW ==> no change compiler (as OS is isolation layer and responsible for any conflicts handling).
- Change OS (change sys calls & APIs) ==> change compiler.
VIP NOTE Libraries in C depend on sys calls i.e. (printf).
Compiler deals with HW using system calls provided by OS.
If no OS compiler would write to HW directly in ML i.e. (01110101)
system calls depend on the OS
The operating System doesn't execute the program it only provides needed resources and supervises everything and, the CPU does execute the program.
If the compiler changes, will the code written (in C for example) change?
Answer: Conditions, and loops will not change if HW changes that's why it's called High-level languages.
Assume there's an application
- This app depends on OS (contains system call commands (printf).
- OS can translate commands into something compatible with HW.
- OS is responsible for this layer, not the developer.
- You create a system calls layer which will then be converted in lib to ML.
printf When called in C, actually it calls a system call which will connect to the screen afterwards for printing.
(Windows) Vs (Linux) in terms of System Calls
Windows somehow handles this thing instead of you as a user.
Linux enables you to do whatever you want with sys calls. (Man sheet)
Aside Note
Not every machine language is runnable (linker-related topic)