🧠 High-level Language vs Low-level Language

High-level languages must be translated into low-level languages so the computer can understand them.

🔽 Types of Low-level Languages

  • Assembly
    - More human-readable than machine code, but still considered low-level.
    - Requires an assembler to convert it into machine code.
  • Machine Code
    - Binary code (0s and 1s) that the CPU can execute directly.

Binary code (0s and 1s) that the CPU can execute directly.

❓ How is high-level code converted into machine code?
There are two main approaches, depending on whether the language is compiled or interpreted.
🔧 Compile

  • A compiler reads the entire code, checks for errors, and converts it into object code (machine code) all at once.
  • Faster at runtime but fails entirely if there's a critical error.

📝 Interpret

  • An interpreter reads and converts code line by line, executing it as it goes.
  • Slower than compiled code but can run parts of the program even if later lines have errors.

❓ What’s the difference between an object file and an executable file?
A. An object file is the result of compilation, but it can't run on its own.
To become an executable, the object file must go through a linking process:

  • Links together multiple object files or external libraries
  • Resolves function references that are declared but not defined in the current file

🔗 Example:

  • main.c uses a function called HELPER_ADD, but it's defined in helper.c
  • The main.o file also uses a print function from a system library
  • These must be linked to produce the final executable file
    ✅ Only after linking can the program run properly.

🧠 Instructions

An instruction is made up of two main parts:
1️⃣ Operation Code (Opcode)

  • Specifies what the CPU should do, with or without using data
    (e.g., ADD, MOVE, LOAD)
    2️⃣ Operand
  • Represents the data or location (address) to be used in the operation
  • Often holds the address where the actual data is stored
    That operand could:
    • Contain actual data
    • Contain a memory address
    • even point to something that points to the data

      Addressing mode: How should I find the real data (effective address) using the operand in the instruction?
      🔽 Types of Addressing Modes:
      1) Direct Addressing
      -> The operand contains the memory address directly
      -> The range of accessible memory is limited by the size of the operand field
      2) Indirect Addressing:
      -> The operand contains the address of a memory location,
      and that memory location contains the effective address (where the data is)
      -> This allows access to a wider range of memory, since the real address is stored in memory, not in the instruction
      3) Regiser Addressing
      -> The operand contains the name or ID of a register
      4) Register Indirect Addressing
      -> The operand refers to a register
      -> That register contains the effective memory address where the actual data is stored

0개의 댓글