Recap: MOV Challenge
Part of the Fundamentals section of Coddy's Assembly journey — lesson 22 of 45.
Challenge
This challenge will test your understanding of:
- Loading values from memory
- Storing values to memory
- Copying between registers
- Using the correct register size
The data addresses are already created for you. You only need to write the MOV instructions.
Challenge
Complete the following tasks in order. Write one line of assembly for each task.
Data already provided:
num1— contains the value 8 (1 byte)num2— contains the value 3 (1 byte)result— empty space (1 byte)
Tasks:
- Load the value from
num1intoal - Load the value from
num2intobl - Copy the value from
blintocl - Store the value from
alintoresult
After your code:
alshould contain 8blshould contain 3clshould contain 3- Memory at
resultshould contain 8
Try it yourself
section .data
msg_al db 'al = '
msg_al_len equ $ - msg_al
msg_bl db 'bl = '
msg_bl_len equ $ - msg_bl
msg_cl db 'cl = '
msg_cl_len equ $ - msg_cl
msg_result db 'result = '
msg_result_len equ $ - msg_result
newline db 0xa
section .bss
digit resb 1
section .text
global _start
_start:
; Student's code runs first
%include "solution.asm"
mov r12, rax
mov r13, rbx
mov r14, rcx
mov r15, 0
mov r15b, [result]
mov rax, 1
mov rdi, 1
mov rsi, msg_al
mov rdx, msg_al_len
syscall
mov rax, r12
add rax, 48
mov [digit], al
mov rax, 1
mov rdi, 1
mov rsi, digit
mov rdx, 1
syscall
mov rax, 1
mov rdi, 1
mov rsi, newline
mov rdx, 1
syscall
mov rax, 1
mov rdi, 1
mov rsi, msg_bl
mov rdx, msg_bl_len
syscall
mov rax, r13
add rax, 48
mov [digit], al
mov rax, 1
mov rdi, 1
mov rsi, digit
mov rdx, 1
syscall
mov rax, 1
mov rdi, 1
mov rsi, newline
mov rdx, 1
syscall
mov rax, 1
mov rdi, 1
mov rsi, msg_cl
mov rdx, msg_cl_len
syscall
mov rax, r14
add rax, 48
mov [digit], al
mov rax, 1
mov rdi, 1
mov rsi, digit
mov rdx, 1
syscall
mov rax, 1
mov rdi, 1
mov rsi, newline
mov rdx, 1
syscall
mov rax, 1
mov rdi, 1
mov rsi, msg_result
mov rdx, msg_result_len
syscall
mov rax, r15
add rax, 48
mov [digit], al
mov rax, 1
mov rdi, 1
mov rsi, digit
mov rdx, 1
syscall
mov rax, 1
mov rdi, 1
mov rsi, newline
mov rdx, 1
syscall
mov rax, 60
mov rdi, 0
syscallAll lessons in Fundamentals
1The Machine
What is CPUMemoryRegisters vs MemoryHow instructions workTwo-File PatternThe x86-64 Architecture3First instruction - MOV
What is MOV?MOV ImmediateMOV Register to RegisterMOV Memory to RegisterMOV Register to MemoryLEA - Load AddressMOV with Different SizesPractice: Swap RegistersRecap: MOV Challenge