Register Addressing Mode

Register Addressing Mode

Register addressing mode involves specifying one or more processor registers directly as operands in assembly instructions. This mode eliminates the need to access data from memory, thereby reducing memory latency and enhancing program performance.

Syntax:

Intel Syntax:

In Intel syntax, register addressing mode is typically expressed by specifying the source and destination registers directly in the instruction mnemonic. For example:

MOV eax, ebx    ; Move the contents of ebx register to eax register
ADD edx, ecx    ; Add the contents of ecx register to edx register
SUB esi, edi    ; Subtract the contents of edi register from esi register

Here, eax, ebx, ecx, edx, esi, and edi represent general purpose registers.

Moving Different sizes of data

1 Moving Byte-sized Data:

; NASM Syntax
mov al, byte [source_address]

; Intel Syntax
mov al, byte ptr [source_address]

2 Moving Word-sized Data:

; NASM Syntax
mov ax, word [source_address]

; Intel Syntax
mov ax, word ptr [source_address]

3 Moving Doubleword-sized Data:

; NASM Syntax
mov eax, dword [source_address]

; Intel Syntax
mov eax, dword ptr [source_address]

4 Moving Quadword-sized Data:

; NASM Syntax
mov rax, qword [source_address]

; Intel Syntax
mov rax, qword ptr [source_address]

AT&T Syntax:

In AT&T syntax, register addressing mode is denoted by using the % symbol preceding the register names. Additionally, the source and destination operands are reversed compared to Intel syntax. For example:

movl %ebx, %eax    ; Move the contents of ebx register to eax register
addl %ecx, %edx    ; Add the contents of ecx register to edx register
subl %edi, %esi    ; Subtract the contents of edi register from esi register

In AT&T syntax, the instruction mnemonic is followed by  the source register and then the destination register. The l suffix indicates that the operation applies to 32-bit operands. Different suffixes such as b (byte), w (word), l (long) and q (quadword) denote operand size.

Different Suffixes used in AT&T Syntax:

These suffixes provide clarity regarding the size of operands being operated on, ensuring proper interpretation by the assembler and facilitating correct execution of instruction.

  1. b: This suffix denotes a byte-sized operand (8 bits). It is used for byte-level operations.
    1. Example: movb %al, %bl (Move the byte from AL register to BL register)
  2. w: This suffix denotes a word-sized operand (16 bits). It is typically used for operations involving 16-bit data.
    1. Example: movw %ax, %bx (Move the word from AX register to BX register)
  3. l: This suffix denotes a long-sized operand (32 bits). It is commonly used for 32-bit operations.
    1. Example: movl %eax, %ebx (Move the long from EAX register to EBX register)
  4. q: This suffix denotes a quadword-sized operand (64 bits). It is used for operations involving 64-bit data.
    1. Example: movq %rax, %rbx (Move the quadword from RBX register to RBX register)