I am making a simple function in assembly which copies an array of bytes from one memory address to another.
The program takes 2 memory addresses (_source and _destiny), and loops over each element copying _source[i] element to _destiny[i] element. However, I can't find any information about how to use a register's value as a memory address. In this code, $[eax] and $[ecx] are supposed to be used as memory addresses.
void Copy(void const* _source, void* _destiny, size_t _byteSize) { char* destiny = new char[_byteSize]; for (size_t i = 0; i < _byteSize; i++) { __asm ("" "mov eax, %[_source]\n\t" "add eax, %[i]\n\t" "mov bl, $[eax]\n\t" "mov ecx, %[destiny]\n\t" "add ecx, %[i]\n\t" "mov $[ecx], bl" : [destiny] "=r" (destiny) : [_source] "r" (_source), [i] "r" (i) : "eax", "ecx", "bl" ); } _destiny = destiny; } In the following code, I am getting two errors. "Operand Size Mismatch for 'mov'", and "No instruction mnemonic suffix given and no register operands; can't size instruction" My question is, what am I doing wrong and how can register values be used as memory addresses?
Edit 1: Code was changed to fit Intel Assembly Syntax
https://stackoverflow.com/questions/67255300/using-a-register-value-as-a-memory-address-in-gcc April 25, 2021 at 11:47PM
没有评论:
发表评论