High-Level and Low-Level Programming Languages: A Comprehensive Study Guide

Introduction to Computer Programs

  • Definition of a Computer Program: A computer program is a set of instructions that enables a computer to perform a specific, intended task.

  • Levels of Programming: Programs can be categorized based on their proximity to human language versus hardware interaction. These categories include:

    • High-level languages: Designed for human readability.

    • Low-level languages: Closer to the machine's architecture; includes Assembly language and Machine code.

    • Machine code: Directly understandable by the computer hardware (binary/hexadecimal).

High-Level Languages (HLL)

  • Definition: High-level languages allow programmers to write code without requiring deep knowledge of the specific computer's hardware architecture or instruction sets.

  • Key Characteristics:

    • Portability: Programs written in HLLs are portable, meaning they can be used and executed on different types of computer systems.

    • Human-Centric: HLLs use statements that are easy for humans to read and understand.

    • Examples: Common high-level languages include Java, C++, and Python.

    • Transferable Concepts: Programming concepts (loops, logic, variables) are generally the same across different high-level languages.

  • Typical Logic Statement:

    • Example: Difference=number1−number2\text{Difference} = \text{number1} - \text{number2}

  • Advantages of HLLs:

    • Programs are written in a shorter amount of time compared to low-level languages.

    • Errors are easier to debug during the development stage.

    • Programs can be effectively maintained and updated while they are in use.

Low-Level Languages (LLL)

  • Definition: Low-level languages are closely related to the specific hardware architecture and the instruction set of the processor.

  • Types of Low-Level Languages:

    1. Machine Code: Raw binary instructions that the computer understands directly.

    2. Assembly Language: Uses mnemonics to represent machine operations; requires conversion to machine code.

Assembly Language and Hardware Interaction

  • Usage: Programmers use Assembly language when they need to make use of specialized hardware features or optimize for specific machine types.

  • Performance and Memory: Assembly code performs tasks very quickly and occupies minimal space in the primary memory compared to high-level code.

  • Machine Dependency: Instructions used in Assembly are highly dependent on the specific type of machine and processor.

  • Registers: These are high-speed data storage areas located within the computer's CPU.

  • Code Example and Anatomy:

    • Instruction (Mnemonic): ADD\text{ADD} (An operation to be performed).

    • Operands: These are the data or register locations involved, such as AX\text{AX} and [15][15].

Instruction

Operand

Function

MOV\text{MOV}

AX, 22h\text{AX, 22h}

Move the hex number 2222 to the register AX\text{AX}

ADD\text{ADD}

AX, 15h\text{AX, 15h}

Add the number in register AX\text{AX} with hex number 1515

HLT\text{HLT}

(none)

Stop the execution

Machine Code

  • Format: Machine code is written in hexadecimal or binary form.

  • Complexity: It is extremely difficult for humans to understand and is complicated to manage in terms of how data is stored and manipulated.

  • Anatomy of a Machine Code Instruction:

    • Opcode (Operation Code): The part of the instruction that informs the CPU which specific operation to perform.

    • Operand: The data or memory address used by the opcode.

Opcode

Operand

Function

A1A1

2222

Move the hex number 2222 to the register AX\text{AX}

0505

1515

Add the number in register AX\text{AX} with hex number 1515

F4F4

(none)

Stop the execution

Program Translators

  • Definition: A translator is a utility program that converts source code (HLL or Assembly) into binary machine code that the computer can interpret and execute.

  • Input/Output Flow:

    • Compiler/Interpreter: Input is High-level language.

    • Assembler: Input is Assembly language.

    • Output: Machine code (or direct execution for interpreters).

Detailed Breakdown of Translators

Compiler
  • Function: Translates a high-level program into machine code in one complete process.

  • Optimization: Compilers optimize the code for efficiency.

  • Error Detection: Errors are only reported after the entire program has been compiled.

  • Executables: Produces a standalone executable file of machine code. Once compiled, it can be run multiple times without re-compiling.

  • Instruction Ratio: One statement in HLL can translate into several machine code instructions.

Interpreter
  • Function: Reads one statement at a time from a high-level program, performs the action, and then moves to the next statement.

  • Error Handling: If an error is found, the interpreter stops and prompts the user to correct the error before continuing.

  • Executables: No standalone machine code file is produced; the program can only run if the interpreter is present.

  • Instruction Ratio: One statement in HLL may require several machine code instructions to be executed internally.

Assembler
  • Function: Translates a program written in Assembly language into machine code.

  • Executables: Produces a standalone executable file of machine code that can be run independently after assembly.

  • Instruction Ratio: Usually a one-to-one mapping, where one Assembly statement translates into exactly one machine code instruction.

Programming Errors

  • Syntax Errors:

    • Cause: Occurs when the specific rules of the programming language are not followed.

    • Effect: The program cannot be translated (compiled or interpreted).

    • Feedback: Compilers notify the user of line numbers after completing the pass; interpreters stop immediately at the line with the error.

  • Logic Errors:

    • Cause: The program runs, but it produces incorrect, unexpected, or unintended results.

    • Detection: Identified using test data. This involves "tracing" each statement and comparing the actual result with the expected result.

Integrated Development Environment (IDE)

  • Definition: An IDE is a complex software suite that provides tools for software development, typically consisting of an editor, a compiler and/or interpreter, and debugging tools.

  • The Editor:

    • Purpose: Used to write, edit, and save program code.

    • Comparison: It resembles a word processor but lacks standard formatting options (like bold or italics) because such formatting could contaminate the code.

    • Features for Readability:

      • Indentation: Conditional and iterative (loop) statements are indented automatically to show structure.

      • Color Coding: Variables, keywords, and other syntax elements are presented in different colors.

  • Example: IDLE is the IDE commonly used for Python programming.

Run-Time Environments and Portability

  • Definition: A run-time environment allows a program to be executed on a platform different from the one on which it was originally created.

  • Capabilities: It allows execution but generally does not allow the user to edit the code.

  • Cross-Platform Execution: This enables developers to write code once and execute it across many different platforms.

  • Implementation Mechanisms:

    • Plug-ins: Specialized code installed on platform platforms to execute specific languages like Java.

    • Virtual Machines: A software-based simulation of a particular computer system that creates the necessary environment for the program to run on foreign hardware.

Questions and Discussion

Activity 1
  • Prompt: A programmer writes codes in two different ways: high-level language and assembly code. How can these codes be translated to be understood by the CPU? Draw diagrams to explain your answer.

  • Duration: 1010 minutes.

End of Topic Review Questions
  • Q: What are the advantages of writing programs in high-level language?

  • Q: In what case does a programmer choose low-level languages over high-level language?

  • Q: What are translators?

  • Q: How is the function of a compiler different from an interpreter?

  • Q: What are the components of an IDE? Specify the function of each component.

  • Q: What are the advantages of a run-time environment?