ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3137Directives
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3137

    Computer Organization and Assembly Language

    Progress0 / 73 done
    Topics73
    1Introduction to Computer Organization2Assembly Language3Comparison of Low-Level and High-Level Languages
    4General Purpose and Special Purpose Registers5Introduction and Usage of RAM6Processor7Registers8System Bus9Instruction Execution Cycle10Assembly and Machine Language11Assembler12Linker and Link Libraries13Programmer's View of a Computer System14RISC and CISC Architecture15Physical Address Calculation16Basic Memory Organization17CPU Organization18Top Level View of Computer Function and Interconnection19Assembler Instruction Cycle20Execute Cycle21Interrupts22Interrupt Cycle23Memory Connection24Input/Output Connection25CPU Connection26MASM27MIPS28Defining Data in MASM Assembler29Elements of Assembly Language30Integer Constants31Integer Expressions32Real Number Constants33Character Constants34String Constants35Reserved Words36Identifiers37Directives38Instructions39The NOP (No Operation) Instruction40Adding and Subtracting Integer41INC and DEC Instructions42NEG Instruction43How to Move Integer Number in Register44Adding and Subtracting Numbers in Registers45Declaration and Initialization of Variables46Moving Data from Variable to Register47Data Definition Statement48BYTE and SBYTE Data49WORD and SWORD Data50Defining DWORD and SDWORD Data51Knowledge about Different Data Types52Operations, Array & Loops53Division and Multiplication in Assembly54Jumps Based on Specific Flags55Jumps Based on Equality56Simple Jump Statements57Jumps Based on Specific Condition58Code Examples59Practice on MASM60Procedures61File Operations Procedures62Labels in Procedures63Stack64Runtime Stack65Conditional Control Flow Directives66Compound Expressions67Data Representation & Conversion68Architecture69Data Path70Control Unit71Critical Path72General Principles of Pipelining73Pipelined Y86 Implementations
    7 min read
    Topic 37 of 73
    Topic Study Note Illustration
    37

    Directives

    Directives (sometimes referred to as pseudo-ops ) are special instructions in assembly language that provide guidance to the assembler (the tool that translates assembly code into machine...

    Directives in Assembly Language

    Directives (sometimes referred to as pseudo-ops) are special instructions in assembly language that provide guidance to the assembler (the tool that translates assembly code into machine code) rather than to the CPU. Unlike regular assembly instructions (such as MOV, ADD, or JMP), which are executed by the CPU, directives are used to control the assembly process or provide information about how the code should be organized, how data is stored, or how memory is allocated.

    Directives don’t generate machine code directly but help the assembler understand how to interpret the program. They can define memory spaces, set constants, allocate space, specify data sections, and much more.

    Categories of Directives

    Directives in assembly can be categorized into different types based on their function. Here are the most common types of directives:

    1. Data Definition Directives
    2. Memory Allocation Directives
    3. Program Control Directives
    4. Section or Segment Directives
    5. Macro Directives
    6. Other Miscellaneous Directives

    1. Data Definition Directives

    These directives are used to define and initialize data in the program. Data is typically stored in memory, and these directives tell the assembler how to allocate and initialize space for data.

    1.1. DB (Define Byte)

    • Purpose: Defines a byte (8 bits) or a series of bytes in memory. You can initialize the byte(s) with values.
    • Syntax: DB value1, value2, ..., valueN

    Example:

        message DB 'Hello, World!', 0   ; Define a string with a null terminator
    

    This example defines a byte array message containing the string "Hello, World!" followed by a null terminator (0).

    1.2. DW (Define Word)

    • Purpose: Defines a word (usually 2 bytes or 16 bits) or a series of words.
    • Syntax: DW value1, value2, ..., valueN

    Example:

        dataWords DW 100, 200, 300   ; Define three 16-bit words
    

    This defines three 16-bit words with values 100, 200, and 300.

    1.3. DD (Define Doubleword)

    • Purpose: Defines a doubleword (usually 4 bytes or 32 bits) or a series of doublewords.
    • Syntax: DD value1, value2, ..., valueN

    Example:

        longNumbers DD 1000, 2000, 3000   ; Define three 32-bit values
    

    This defines three 32-bit values with the specified integers.

    1.4. DQ (Define Quadword)

    • Purpose: Defines a quadword (usually 8 bytes or 64 bits) or a series of quadwords.
    • Syntax: DQ value1, value2, ..., valueN

    Example:

        bigNumbers DQ 1000000000, 2000000000
    

    This defines two 64-bit values.

    1.5. DT (Define Ten Bytes)

    • Purpose: Defines a ten-byte block (typically used for large floating-point numbers or complex data).
    • Syntax: DT value1, value2, ..., valueN

    Example:

        realData DT 3.14159, 2.71828
    

    This defines a ten-byte area for floating-point data.

    2. Memory Allocation Directives

    These directives are used to reserve space in memory without initializing it. The data space is not filled with any value but simply allocated.

    2.1. RESB (Reserve Byte)

    • Purpose: Reserves a specific number of bytes in memory.
    • Syntax: RESB number_of_bytes

    Example:

        buffer RESB 128   ; Reserves 128 bytes for a buffer
    

    This reserves 128 bytes of space for the buffer without initializing the data.

    2.2. RESW (Reserve Word)

    • Purpose: Reserves a specific number of words (usually 2 bytes each) in memory.
    • Syntax: RESW number_of_words

    Example:

        stack RESW 64   ; Reserves 64 words (128 bytes) for the stack
    

    This reserves 128 bytes for the stack, where each word is 2 bytes.

    2.3. RESD (Reserve Doubleword)

    • Purpose: Reserves a specific number of doublewords (usually 4 bytes each) in memory.
    • Syntax: RESD number_of_doublewords

    Example:

        array REVD 10   ; Reserves 10 doublewords (40 bytes) for an array
    

    This reserves 40 bytes for an array, where each doubleword is 4 bytes.

    3. Program Control Directives

    These directives control the flow and execution of the program. They can be used to define program properties, constants, or control how the program is compiled and linked.

    3.1. EQU (Equate)

    • Purpose: Defines a constant value. You can assign a constant to a name using the EQU directive.
    • Syntax: name EQU value

    Example:

        MAX_SIZE EQU 1024   ; Define a constant MAX_SIZE with value 1024
    

    This defines a constant named MAX_SIZE with the value 1024.

    3.2. GLOBAL

    • Purpose: Declares a symbol (variable or function) to be accessible from outside the current module. Typically used when working with multiple files (linking).
    • Syntax: GLOBAL symbol_name

    Example:

        GLOBAL _start   ; Declare the symbol _start to be accessible outside the module
    

    This makes the label _start accessible from other modules or external files during linking.

    3.3. EXTERN

    • Purpose: Declares an external symbol (a variable or function) that will be defined elsewhere, often in another module.
    • Syntax: EXTERN symbol_name

    Example:

        EXTERN printf   ; Declare that 'printf' will be defined elsewhere
    

    This tells the assembler that printf is an external function that will be linked during the linking stage.

    4. Section or Segment Directives

    These directives define sections or segments in the program. A section is a portion of memory designated for specific purposes, such as data or code.

    4.1. .data

    • Purpose: Marks the section where initialized data (like variables) will be stored. This section typically contains global variables and constants.
    • Syntax: .data

    Example:

        .data
        message DB 'Hello, World!', 0
    

    This tells the assembler that the following data is initialized and should be placed in the .data section.

    4.2. .text

    • Purpose: Marks the section where executable code (program instructions) will be stored. This section typically contains the program's logic.
    • Syntax: .text

    Example:

        .text
        MOV AX, 1   ; Example of program logic
    

    This marks the following code as executable and places it in the .text section.

    4.3. .bss

    • Purpose: Marks the section where uninitialized data will be stored. The .bss section is used for variables that are declared but not yet initialized.
    • Syntax: .bss

    Example:

        .bss
        counter RESB 4   ; Reserve 4 bytes for an integer counter (uninitialized)
    

    This reserves 4 bytes for the variable counter without initializing it.

    5. Macro Directives

    Assemblers can include macros, which are essentially blocks of code that can be reused multiple times within the program. Macros are expanded by the assembler during the assembly process.

    5.1. MACRO

    • Purpose: Defines a macro, which is a reusable block of code that can be invoked with parameters.
    • Syntax:
      MACRO
          ; macro code
      ENDM
      

    Example:

        PRINT_MACRO MACRO msg
            MOV AH, 09h
            MOV DX, msg
            INT 21h
        ENDM
    

    This defines a macro PRINT_MACRO, which prints a string using DOS interrupt 21h. The msg parameter will be replaced by the actual string when the macro is used.

    6. Other Miscellaneous Directives

    6.1. ALIGN

    • Purpose: Aligns the next data or instruction to a specified boundary (e.g., 2-byte, 4-byte, etc.).
    • Syntax: ALIGN boundary

    Example:

        ALIGN 4   ; Align the next data on a 4-byte boundary
    

    This ensures that the next data starts at an address that is divisible by 4.

    6.2. INCLUDE

    • Purpose: Includes the contents of another file (e.g., a header file) into the current assembly
    ← Previous topic 36
    Identifiers
    Next topic 38 →
    Instructions

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    7mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language