Programming with FASM – copy memory.

By | 02/02/2019

The goal of this tutorial is to show how to copy memory using the destination source and registers.
Copy memory is a complex issue and depends on the rule of addressing.
In this case I used the registers: edi, esi, ecx.
My example uses also a structure to understand another step into assembly programming with FASM the structure area.
This structure named MY_STRUC starts with this template:

I create a procedure named copy_memory to copy memory.
The source code has commented lines that let you see how this working.
Some parts of these comments let you create an executable to test with the debugger.
The base of this copy memory issue is the assembly instruction named movsb.
The movsb moves only a single byte from the source string to the destination.
To move the entire string, first, initialize ecx to the number N of bytes in the source string and execute rep movsb.
As you know the ecx is a 32-bit register.
Let’s see the example:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.