memory-size-access
Problem
This problem comes from pwn.college: Assembly Crash Course ⤴.
We will now set some values in memory dynamically before each run. On each run, the values will change. This means you will need to perform some type of formulaic operation with registers. We will tell you which registers are set beforehand and where you should put the result. In most cases, it’s
rax.In this level, you will be working with memory. This will require you to read or write to things stored linearly in memory. If you are confused, refer to the linear addressing module in ‘ike. You may also be asked to dereference things, possibly multiple times, to things we dynamically put in memory for your use.
Recall the following:
- The breakdown of the names of memory sizes:
- Quad Word = 8 Bytes = 64 bits
- Double Word = 4 bytes = 32 bits
- Word = 2 bytes = 16 bits
- Byte = 1 byte = 8 bits
In x86_64, you can access each of these sizes when dereferencing an address, just like using bigger or smaller register accesses:
mov al, [address]⇿ moves the least significant byte from address toraxmov ax, [address]⇿ moves the least significant word from address toraxmov eax, [address]⇿ moves the least significant double word from address toraxmov rax, [address]⇿ moves the full quad word from address toraxPlease perform the following:
- Set
raxto the byte at0x404000- Set
rbxto the word at0x404000- Set
rcxto the double word at0x404000- Set
rdxto the quad word at0x404000
Solution
.intel_syntax noprefix
.global _start
_start:
mov al, [0x404000]
mov bx, [0x404000]
mov ecx, [0x404000]
mov rdx, [0x404000]
Alternatively, you may
.intel_syntax noprefix
.global _start
_start:
mov rax, byte ptr [0x404000]
mov rbx, word ptr [0x404000]
mov rcx, dword ptr [0x404000]
mov rdx, qword ptr [0x404000]