w1coding.comAll tutorials

Assembly Operators

Assembly lessons
  1. Environment Setup
  2. Introduction
  3. Syntax
  4. Datamovement
  5. Operators
  6. Control
  7. Loops
  8. Interupts
  9. Functions
  10. Memory
  11. System
  12. Debugging
  13. Macros
  14. Execution
  15. Floating
  16. Interupts
  17. Optimization
  18. Linking
  19. Inline
  20. Registers
  21. Bootloader
  22. Macros
  23. Stack
  24. Call
  25. Technique
  26. Responsive

Arithmetic Operations

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

Arithmetic Instructions

  • add: Adds the source to the destination.
  • sub: Subtracts the source from the destination.
  • mul: Multiplies the accumulator by the source.
  • div: Divides the accumulator by the source.

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