Menu
Coddy logo textTech

MOV Immediate

Part of the Fundamentals section of Coddy's Assembly journey — lesson 15 of 45.

The simplest form of MOV is MOV immediate. "Immediate" means the value is written directly in the instruction itself.

Syntax:

mov register, value

The value is copied into the register.

Examples:

InstructionWhat it does
mov rax, 5Copies the number 5 into rax
mov rbx, 100Copies the number 100 into rbx
mov rcx, 0Copies the number 0 into rcx

This code does nothing visible (no output yet), but it successfully puts numbers into registers.

Note: You will see the effect of these MOV instructions in later lessons when you learn to print or debug. For now, just know that the numbers are stored in the registers.

Important rules:

RuleExplanation
The value must fit in the registerrax can hold very large numbers (up to 2⁶⁴-1)
The value is copied, not movedThe original number still exists (it is just a number)
Registers on the leftmov rax, 5 is correct. mov 5, rax is wrong
challenge icon

Challenge

Write one line of assembly code for each task:

  1. Put the number 5 into the rax register.
  2. Put the number 7 into the rbx register.
  3. Put the number 3 into the rcx register.

Try it yourself

section .data
    msg_rax db 'rax = '
    msg_rax_len equ $ - msg_rax
    msg_rbx db 'rbx = '
    msg_rbx_len equ $ - msg_rbx
    msg_rcx db 'rcx = '
    msg_rcx_len equ $ - msg_rcx

section .bss
    digit resb 1

section .text
    global _start

_start:
    %include "solution.asm"
    
    ; Save values
    mov r12, rax
    mov r13, rbx
    mov r14, rcx
    
    ; Print "rax = "
    mov rax, 1
    mov rdi, 1
    mov rsi, msg_rax
    mov rdx, msg_rax_len
    syscall
    
    ; Print rax value
    mov rax, r12
    add rax, 48
    mov [digit], al
    mov rax, 1
    mov rdi, 1
    mov rsi, digit
    mov rdx, 1
    syscall
    
    ; Print "rbx = "
    mov rax, 1
    mov rdi, 1
    mov rsi, msg_rbx
    mov rdx, msg_rbx_len
    syscall
    
    ; Print rbx value
    mov rax, r13
    add rax, 48
    mov [digit], al
    mov rax, 1
    mov rdi, 1
    mov rsi, digit
    mov rdx, 1
    syscall
    
    ; Print "rcx = "
    mov rax, 1
    mov rdi, 1
    mov rsi, msg_rcx
    mov rdx, msg_rcx_len
    syscall
    
    ; Print rcx value
    mov rax, r14
    add rax, 48
    mov [digit], al
    mov rax, 1
    mov rdi, 1
    mov rsi, digit
    mov rdx, 1
    syscall
    
    ; Exit
    mov rax, 60
    mov rdi, 0
    syscall
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals