1.5Programs and Programming Languages
Covers IGNOU MCS-201 §1.5
A processor understands only binary instructions, while people think in words and formulas. Programming languages sit at different points between these two, and translator programs bridge the gap. Understanding this explains why C needs a compiler and why a program compiled on one machine may not run on another.
Program and programming language
A programming language is a formal language with fixed rules of grammar, called syntax, used to write programs.
The three levels of language
The table shows the same task, “put 5 in a register and add 3”, at each level for an Intel/AMD x86 processor.
| Level | What the programmer writes | Translation needed |
|---|---|---|
| Machine language | 10111000 00000101 00000000 00000000 00000000 then 10000011 11000000 00000011 | None: the processor runs it directly |
| Assembly language | mov eax, 5 then add eax, 3 | An assembler |
| High-level language (C) | sum = 5 + 3; | A compiler or interpreter |
- Machine language is binary. Each processor family (x86, ARM and others) has its own instruction set, so machine code is machine-dependent.
- Assembly language replaces each binary instruction with a short name called a mnemonic, such as
movoradd. Each assembly statement matches exactly one machine instruction, so it is still machine-dependent. - High-level languages describe the problem rather than the hardware. One statement can become many machine instructions, and the same source code can be translated for different processors.
The study material calls machine and assembly languages low-level or machine-oriented, and high-level languages problem-oriented.
| Aspect | Low-level languages | High-level languages |
|---|---|---|
| Written in terms of | The processor’s instructions | The problem |
| Machine dependence | Dependent; rewritten for each processor | Independent; recompiled for each processor |
| Ease of writing and reading | Hard | Easy |
| Control over hardware | Complete | Limited (C allows more than most) |
| Execution speed | Traditionally faster | Traditionally slower |
Low-level programs are traditionally faster because there is no translation layer and the programmer controls every instruction directly. Modern optimising compilers, however, often produce code as fast as hand-written assembly.
Translators
| Translator | Converts | How it works | Example |
|---|---|---|---|
| Assembler | Assembly language → machine code | Whole program, one instruction for one instruction | as, NASM |
| Compiler | High-level language → machine code | Translates the whole program first, producing an executable file that can be run many times | gcc, clang for C |
| Interpreter | High-level language → immediate execution | Translates and runs the program statement by statement, with no separate executable | Python (Unit 9), shell scripts |
Key takeaways
- Machine language is binary; assembly uses mnemonics with a one-to-one match; high-level languages map one statement to many instructions.
- Low-level languages are machine-dependent; high-level source code is portable.
- Assemblers, compilers and interpreters are all translators.
- C is compiled: the whole program becomes an executable file before it runs.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Give three differences between a compiler and an interpreter.
Show worked answer
1. A compiler translates the whole program before it runs; an interpreter translates and executes it one statement at a time. 2. A compiler produces an executable file that can be run many times without translating again; an interpreter produces no executable, so the source is translated every time it runs. 3. A compiler reports all syntax errors of the program before anything runs; an interpreter stops at the first erroneous statement it reaches while running. Example: C is normally compiled with gcc or clang; Python is normally interpreted.