Menu
Coddy logo textTech

MOV Register to Memory

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

Now that you know how to load data from memory into a register, you will learn the reverse: storing data from a register into memory.

Syntax:

mov [address], register

The brackets [ ] mean: "store the value from the register into this memory address."

Think of it like this:

Imagine at memory address destination there is an empty box. You have a value sitting in a register (for example, al contains the number 7).

When you write:

mov [destination], al

You are telling the CPU: "Take the value from the al register (7) and put it into the box called destination."

After this instruction is executed, the memory address destination now contains the value 7. The value in al stays there — it is not removed.

Example:

mov al, 7            ; Put 7 into al register
mov [destination], al ; Store the value from al into memory address "destination"

Note: In this exercise, the data in memory is 1 byte (8 bits). That is why we use al — it is the 8-bit register that matches the size. You will learn more about register sizes later.

Important rules:

RuleExplanation
The brackets are requiredmov destination, al would be wrong
The destination must be a memory addressUse a label like [destination]
Size must matchFor this exercise, use al (8 bits)

Common mistake:

; Wrong: missing brackets
mov destination, al

; Correct: stores the value into memory
mov [destination], al

In the challenge below, the memory address destination is already created for you. You will learn how to create your own data in Chapter 3. For now, just focus on the MOV instruction.

challenge icon

Challenge

Write two lines of assembly to:

  1. Put the number 9 into the al register
  2. Store the value from al into the memory address destination

(The memory address destination is already created for you.)

Try it yourself

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

section .bss
    digit resb 1

section .text
    global _start

_start:
    ; solution.asm is included here
    ; It defines destination AND the student's MOV instructions
    
    %include "solution.asm"
    
    ; Load the stored value from memory into al for printing
    mov al, [destination]
    
    ; Save it
    mov r12, rax
    
    ; Print "destination = "
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, msg_len
    syscall
    
    ; Print the value
    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