Register Addressing Mode in Assembly Language

29 Apr 2023 Balmiki Mandal 0 Assembly language

What is Register Addressing Mode Syntax and Instruction

Register addressing mode is a type of memory addressing that uses processor registers to store data and instructions. It's used in assembly language programming as a way to quickly access data and instructions stored in the processor's registers. The syntax for register addressing mode instruction is quite simple, consisting of two parts: the destination register and the source register. The destination register is the instruction's target, while the source register is the register that contains the data or instruction to be accessed.

As an example, let's take the following instruction: MOV R1, R2. In this instruction, the destination register is R1, and the source register is R2. This instruction will move the contents of R2 into R1. This instruction is just one of many that can be used in register addressing mode.

 

Register addressing mode program using Assembly Language using 

Here is an example program written in assembly language using register addressing mode:

MOV R1, #10

move 10 into R1 MOV R2, #20

move 20 into R2 MOV R3, R1

move the value in R1 into R3 ADD R3, R2

add the value in R2 to R3 JMP 0x1234

jump to address 0x1234

This program will first move the value 10 into the register R1, then moves the value 20 into the register R2. Next, it will move the value in R1 into R3. Finally, it will add the value from R2 to the value in R3 and then jump to address 0x1234.

 

The syntax for register addressing mode depends on the specific instruction set architecture of the processor being used. Here's an example using the x86 assembly language syntax to move a value from one register to another:

mov eax, ebx

In this example, eax is the destination register and ebx is the source register. The instruction moves the value stored in ebx into eax.

Here's a simple program using register addressing mode to add two numbers together in x86 assembly language:

section .data
    num1 dd 10
    num2 dd 20
    result dd ?

section .text
    global _start

_start:
    mov eax, [num1]
    mov ebx, [num2]
    add eax, ebx
    mov [result], eax

    ; exit program
    mov eax, 1
    xor ebx, ebx
    int 0x80

In this program, num1 and num2 are defined in the .data section as doubleword (32-bit) variables, and result is a variable to hold the sum of num1 and num2. In the .text section, the program loads the values of num1 and num2 into registers eax and ebx, respectively, adds them together using the add instruction, and stores the result in result using register addressing mode. Finally, the program exits using a system call.

 

Write an Assebly language program to swap R5 and R6 Register value

assembly language program that swaps the values of R5 and R6 registers using only register-to-register instructions:

SWAP:
    mov r0, r5      ; move the value of R5 into a temporary register
    mov r5, r6      ; move the value of R6 into R5
    mov r6, r0      ; move the original value of R5 (now in R0) into R6
    bx lr           ; return from the subroutine

In this program, we define a subroutine called SWAP that uses three mov (move) instructions to swap the values of R5 and R6 registers. The first instruction moves the value of R5 into a temporary register (here, we use R0). The second instruction moves the value of R6 into R5, effectively swapping the values of R5 and R6. Finally, the third instruction moves the original value of R5 (now stored in R0) into R6, completing the swap. The bx lr instruction returns from the subroutine.

Note that this program assumes an ARM architecture, as indicated by the use of the bx lr instruction for returning from the subroutine. The specific syntax and instructions may vary depending on the instruction set architecture of the processor being used.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.