operators

Arithmetic Operations in Assembly

Arithmetic Operations

Assembly supports basic arithmetic operations such as addition, subtraction, multiplication, and division.

Arithmetic Instructions

Example: Basic Arithmetic

section .text
    global _start

_start:
    mov rax, 10      ; Load 10 into rax
    add rax, 5       ; Add 5 to rax (rax = 15)
    sub rax, 3       ; Subtract 3 from rax (rax = 12)
    

Example: Multiplication and Division

section .text
    global _start

_start:
    mov rax, 6       ; Load 6 into rax
    mov rbx, 2       ; Load 2 into rbx
    mul rbx          ; Multiply rax by rbx (rax = 12)
    mov rcx, 3       ; Load 3 into rcx
    div rcx          ; Divide rax by rcx (rax = 4)
    

Note: Multiplication and division affect specific registers (e.g., rax for results).