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›Reserved Words
    Computer Organization and Assembly LanguageTopic 35 of 73

    Reserved Words

    7 minread
    1,185words
    Intermediatelevel

    Reserved Words in Assembly Language

    In assembly language, reserved words (also known as keywords) are predefined words that have a specific meaning to the assembler and cannot be used as identifiers (like variable names, labels, etc.) in your program. These reserved words are essential for defining and controlling the behavior of the program, as they help the assembler understand how to interpret the source code.

    Reserved words are often part of the assembler's syntax and are used to specify various elements of the program, such as data types, memory allocation, instruction formats, and control flow. Each assembler may have a slightly different set of reserved words, but many of them are common across assemblers.

    Categories of Reserved Words in Assembly

    1. Directives: These are used to define how the assembler should process the program. They specify things like data storage, memory allocation, or the beginning of sections of code.
    2. Instructions: These are opcodes (operation codes) that the CPU understands, used to perform specific operations like loading values, arithmetic, and control flow.
    3. Registers: Many assemblers have reserved names for CPU registers.
    4. Control Flow Keywords: These are used for defining loops, conditional statements, and jumps.
    5. Data Types and Size Keywords: These are used to define the size and type of data to be stored in memory.

    Common Reserved Words in Assembly

    1. Directives

    Directives are used to control the assembly process. They aren't part of the instruction set but tell the assembler how to handle the code.

    • DB: Define Byte. Used to allocate memory for a single byte or a sequence of bytes.

      DB 10, 20, 30    ; Defines 3 bytes with values 10, 20, and 30.
      
    • DW: Define Word. Used to allocate memory for a word (typically 2 bytes, or 16 bits).

      DW 1000           ; Defines a word with value 1000.
      
    • DD: Define Doubleword. Used to allocate memory for a doubleword (typically 4 bytes, or 32 bits).

      DD 5000           ; Defines a doubleword with value 5000.
      
    • RESB, RESW, RESD: Reserved memory for byte(s), word(s), or doubleword(s).

      RESB 10            ; Reserves 10 bytes of memory.
      
    • SECTION / .data, .text, .bss: These directives define different sections of the program.

      • .data: Data section where variables are declared.
      • .text: Code section where instructions are written.
      • .bss: Block Started by Symbol, used for uninitialized data.
      .data
      message DB 'Hello', 0
      
      .text
      ; code here
      
    • EQU: Define a constant. Used to create constants that can be used in the code.

      MAX_SIZE EQU 256   ; Define MAX_SIZE constant as 256
      

    2. Instructions

    These are the actual commands that perform the operations on the processor. Some instructions are used for arithmetic operations, while others handle data movement, comparisons, and control flow.

    • MOV: Move data from one location to another.

      MOV AX, 5   ; Move the value 5 into register AX
      
    • ADD, SUB, MUL, DIV: Arithmetic operations.

      ADD AX, BX   ; Add the value in register BX to AX
      
    • CMP: Compare two values.

      CMP AX, BX   ; Compare the values in AX and BX
      
    • JMP: Jump to another location in the program (unconditional).

      JMP label    ; Jump to the instruction labeled 'label'
      
    • JE, JNE, JL, JLE, JG, JGE: Conditional jumps based on comparison results (e.g., Jump if Equal, Jump if Not Equal).

      JE label     ; Jump to 'label' if the last comparison was equal
      
    • NOP: No operation. A placeholder that does nothing but can be used for alignment or timing purposes.

      NOP
      

    3. Registers

    Registers are special memory locations in the CPU that hold data temporarily for computation and processing. The names of these registers are reserved and cannot be used as labels or variables.

    • AX: Accumulator register (16-bit in x86, part of the general-purpose registers).
    • BX: Base register (16-bit in x86).
    • CX: Count register (used in loops, 16-bit in x86).
    • DX: Data register (16-bit in x86).
    • SI, DI: Source and destination index registers, respectively.
    • SP: Stack pointer register.
    • BP: Base pointer register.

    In 32-bit and 64-bit systems (e.g., x86-64):

    • EAX, EBX, ECX, EDX (32-bit versions of AX, BX, etc.).
    • RAX, RBX, RCX, RDX (64-bit versions of AX, BX, etc.).

    Example:

    MOV AX, 5    ; Load the value 5 into the AX register
    MOV BX, 10   ; Load the value 10 into the BX register
    

    4. Control Flow Keywords

    Control flow instructions direct the flow of execution, either by looping, jumping, or conditional branching.

    • CALL: Call a function or procedure.

      CALL my_function  ; Call a function named 'my_function'
      
    • RET: Return from a function.

      RET  ; Return from the current procedure
      
    • PUSH, POP: Push and pop values onto and off the stack.

      PUSH AX   ; Push AX register value onto the stack
      POP BX    ; Pop the top value of the stack into BX register
      
    • LOOP: Loop a certain number of times.

      LOOP start   ; Loop to the label 'start' based on the CX register value
      

    5. Data Types and Size Keywords

    Assemblers often provide reserved words for defining the size and type of data that will be stored in memory. These keywords are used to allocate and reserve space for specific types of data, such as bytes, words, doublewords, etc.

    • BYTE: A byte (8 bits).
    • WORD: A word (16 bits).
    • DWORD: A doubleword (32 bits).
    • QWORD: A quadword (64 bits).

    Example:

        DB 20         ; Define byte with value 20
        DW 500        ; Define word with value 500
        DD 1000       ; Define doubleword with value 1000
    

    Examples of Reserved Words

    MASM (Microsoft Macro Assembler) Syntax Example:

    .data           ; Data segment
        msg DB 'Hello, World!', 0  ; Null-terminated string
    
    .text           ; Code segment
        MOV AX, 4C00h  ; Terminate program (interrupt 21h)
        INT 21h        ; DOS interrupt
    

    In the above example:

    • .data and .text are reserved directives to define the data and code sections.
    • MOV, INT, AX, and 0 are part of the reserved words of the assembler and CPU instructions.

    NASM (Netwide Assembler) Syntax Example:

    section .data
        message db 'Hello, world!', 0   ; Null-terminated string
    
    section .text
        global _start
    
    _start:
        mov eax, 4     ; Syscall number for sys_write
        mov ebx, 1     ; File descriptor 1 (stdout)
        mov ecx, message  ; Address of message
        mov edx, 13    ; Length of message
        int 0x80       ; Call kernel
        mov eax, 1     ; Syscall number for sys_exit
        xor ebx, ebx   ; Exit status 0
        int 0x80       ; Call kernel
    

    In this NASM example:

    • section, mov, eax, int, and other similar words are reserved keywords.

    Conclusion

    Reserved words in assembly language are predefined words that the assembler and processor recognize for specific tasks. These reserved words are essential to writing assembly programs because they define instructions, control flow, memory management, and data types. Understanding how to use and avoid using these reserved keywords is crucial for successful assembly programming.

    While the exact set of reserved words can vary slightly depending on the assembler (MASM, NASM, GNU Assembler, etc.),

    Previous topic 34
    String Constants
    Next topic 36
    Identifiers

    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,185
      Code examples0
      DifficultyIntermediate