ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Computer Organization and Assembly Language
    COMP3137
    Progress0 / 73 topics
    Topics
    1. Introduction to Computer Organization2. Assembly Language3. Comparison of Low-Level and High-Level Languages4. Register Types (16-bit): General Purpose and Special Purpose Registers5. Introduction and Usage of RAM6. Processor7. Registers8. System Bus9. Instruction Execution Cycle10. Assembly and Machine Language11. Assembler12. Linker and Link Libraries13. Programmer's View of a Computer System14. RISC and CISC Architecture15. Physical Address Calculation16. Basic Memory Organization17. CPU Organization18. Top Level View of Computer Function and Interconnection19. Assembler Instruction Cycle20. Execute Cycle21. Interrupts22. Interrupt Cycle23. Memory Connection24. Input/Output Connection25. CPU Connection26. MASM27. MIPS28. Defining Data in MASM Assembler29. Elements of Assembly Language30. Integer Constants31. Integer Expressions32. Real Number Constants33. Character Constants34. String Constants35. Reserved Words36. Identifiers37. Directives38. Instructions39. The NOP (No Operation) Instruction40. Adding and Subtracting Integer41. INC and DEC Instructions42. NEG Instruction43. How to Move Integer Number in Register44. Adding and Subtracting Numbers in Registers45. Declaration and Initialization of Variables46. Moving Data from Variable to Register47. Data Definition Statement48. BYTE and SBYTE Data49. WORD and SWORD Data50. Defining DWORD and SDWORD Data51. Knowledge about Different Data Types52. Operations, Array & Loops53. Division and Multiplication in Assembly54. Jumps Based on Specific Flags55. Jumps Based on Equality56. Simple Jump Statements57. Jumps Based on Specific Condition58. Code Examples59. Practice on MASM60. Procedures61. File Operations Procedures62. Labels in Procedures63. Stack64. Runtime Stack65. Conditional Control Flow Directives66. Compound Expressions67. Data Representation & Conversion68. Architecture69. Data Path70. Control Unit71. Critical Path72. General Principles of Pipelining73. Pipelined Y86 Implementations
    COMP3137›Directives
    Computer Organization and Assembly LanguageTopic 37 of 73

    Directives

    7 minread
    1,150words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time7 min
      Word count1,150
      Code examples0
      DifficultyIntermediate