MCS-201 · Unit 1

Programming Fundamentals

Section 5 of 9

Block 1 · Unit 1Programming Fundamentals10 min · Section 5 of 9

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.

LevelWhat the programmer writesTranslation needed
Machine language10111000 00000101 00000000 00000000 00000000 then 10000011 11000000 00000011None: the processor runs it directly
Assembly languagemov eax, 5 then add eax, 3An 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 mov or add. 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.

AspectLow-level languagesHigh-level languages
Written in terms ofThe processor’s instructionsThe problem
Machine dependenceDependent; rewritten for each processorIndependent; recompiled for each processor
Ease of writing and readingHardEasy
Control over hardwareCompleteLimited (C allows more than most)
Execution speedTraditionally fasterTraditionally 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

TranslatorConvertsHow it worksExample
AssemblerAssembly language → machine codeWhole program, one instruction for one instructionas, NASM
CompilerHigh-level language → machine codeTranslates the whole program first, producing an executable file that can be run many timesgcc, clang for C
InterpreterHigh-level language → immediate executionTranslates and runs the program statement by statement, with no separate executablePython (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 1 · multiple choice

Which language level uses mnemonics such as mov and add?

Show answer

Answer: B. Assembly language

Assembly language gives each machine instruction a short name. Machine language is pure binary, with no names.

Question 2 · multiple choice

Which translator converts a whole C program into an executable file before it runs?

Show answer

Answer: D. Compiler

A compiler translates the whole high-level program first. An interpreter translates statement by statement while running, and produces no executable.

Question 3 · multiple choice

Why must an assembly language program be rewritten to run on a different processor family?

Show answer

Answer: A. Each assembly statement matches one instruction of a particular processor’s instruction set

The one-to-one match with a specific instruction set makes assembly machine-dependent. Assembly does have strict syntax, so that option is wrong.

Question 4 · multiple choice

A C program is compiled on an ARM-based Mac. A friend with an Intel PC wants to use it. What must the friend do?

Show answer

Answer: C. Recompile the C source code on (or for) the Intel machine

C source code is portable, but the executable contains ARM machine code. Recompiling produces an x86 executable.

Question 5 · multiple choice

One statement in a language usually turns into many machine instructions. Which kind of language is it?

Show answer

Answer: D. High-level language

High-level statements are one-to-many. Assembly is one-to-one, which is why it counts as low-level.

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.

↑ ↓ move↵ openTab switch type