Programming Languages - Quick Notes
Machine Language
- Lowest-level language; binary digits 0 and 1; Directly understood by CPU; No translation needed; Example: 10110000 01100001
- Also known as machine codes or object code; Very fast execution; Hardware dependent; Difficult for humans to read
Assembly Language
- Uses mnemonics (short codes) instead of binary; Example: MOV A, B; Easier than machine language but hardware dependent
- Requires an Assembler to convert into machine code
- Extensions: .asm, .s, .asmx
How to execute Assembly Language
- Write assembly code in a text editor; Save with proper extension
- Assemble: convert to machine language
- Generate object file: extension obj
- Link: link multiple sources with libraries to create executable (linker, e.g., lk)
- Run the program
High-Level Language
- Similar to human language; Examples: C, Java, Python
- Portable across different hardware; Higher level of abstraction than low-level languages
- Requires a Compiler or Interpreter to convert to machine language
Execution of High-Level Languages
- Interpreted: executed by an interpreter without prior compilation; examples: Python, Ruby, JavaScript
- Compiled: translated into executable machine code; examples: C, C++ (via compilers like GCC)
Assembler
- Translates Assembly Language → Machine Language; One-to-one translation
- Example: ADD R1, R2 → 11001010
- Role: translator from human-readable assembly to machine code; output is machine code
Compiler
- Translates entire High-Level Program → Machine Code at once; Generates an executable file
- Advantage: Fast execution after compilation
- Examples: GCC (C, C++)
Interpreter
- Translates line by line (one instruction at a time)
- Does not create a separate executable file
- Slower execution than compiler
- Examples: Python, JavaScript
Difference: Assembler, Compiler & Interpreter
- Input Language: Assembler → Assembly; Compiler → High-Level; Interpreter → High-Level
- Output: Assembler → Machine Code; Compiler → Machine Code (Executable); Interpreter → Line-by-Line Execution
- Translation: Assembler → One-to-one; Compiler → Whole Program at once; Interpreter → One statement at a time
- Speed: Assembler → Fast; Compiler → Fast after compile; Interpreter → Slower
- Example: NASM; GCC (C, C++); Python, JS
Evolution and Translators
- Programming languages evolved from machine → assembly → high-level
- Translators bridge the gap between human and machine
- Choosing between compiler or interpreter depends on the language and use-case
Diagram: Evolution of Programming Languages
- Machine Language (0s and 1s) → Assembly Language (Mnemonics) → High-Level Language
- Asembler (Assembly → Machine Code), Compiler (High-Level → Machine Code), Interpreter (High-Level → Line by Line)