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.
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
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
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
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
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
.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.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.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.),
Open this section to load past papers