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 PortalCOMP3137Reserved Words
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 35 of 73
    Topic Study Note Illustration
    35

    Reserved Words

    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...

    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 view and download past papers

    Click on Show Past Papers to load available exam papers.

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

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language