Menu
Coddy logo textTech

MOV Memory to Register

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

So far, you have moved numbers directly into registers (immediate) and copied values between registers. Now you will learn how to load data from memory into a register.

Why this matters:

Remember from Chapter 0: the CPU cannot work directly with memory. Data must be loaded into registers first. This is how you do it.

Syntax:

mov register, [address]

The brackets [ ] mean: "go to this memory address and get the value stored there."

Think of it like this:

Imagine at memory address number there is a box. Inside that box is a value, for example the number 5. When you write:

mov al, [number]    ; Load the value from memory address "number" into al

You are telling the CPU: "Go to the box called number, take whatever value is inside (in this case 5), and copy it into the al register."

After this instruction is executed, the value 5 is now stored in al. The original value inside the box at address number stays there — it is not removed.

Important rules:

RuleExplanation
The source must be a memory address[label] or [address]
The brackets are requiredmov al, myNumber loads the address, not the value
Size must matchIf memory stores a byte, use al (not rax)

Common mistake:

; Wrong: loads the ADDRESS of myNumber, not the value
mov al, myNumber

; Correct: loads the VALUE stored at myNumber
mov al, [myNumber]
challenge icon

Challenge

Write one line of assembly to load the value from memory address value into the al register.

Try it yourself

section .data
    msg db 'al = '
    msg_len equ $ - msg

section .bss
    digit resb 1

section .text
    global _start

_start:
    ; The student's code runs first (loads value into al)
    
    %include "solution.asm"
    
    ; Save the value from al
    mov r12, rax
    
    ; Print "al = "
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, msg_len
    syscall
    
    ; Print the value in al
    mov rax, r12
    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