so you can't just do
movl 8(%ebp), -8(%ebp)
I asked chatgpt why and it just blurted out nonsense. Bard came to the rescue. It's answer:
The provided assembly code movl 8(%ebp), -8(%ebp)
throws an error because it violates the single memory reference restriction of the mov instruction in most architectures.
Here's why:
Single Memory Reference Restriction: The mov
instruction is designed to perform a single memory operation. This means it can either load a value from memory or store a value to memory in one instruction.
Multiple Memory References: The provided code attempts to perform two memory operations within a single mov instruction. It tries to:
- Load a value from memory: The source operand
8(%ebp)
specifies the memory location from which the value needs to be loaded. - Store the value to memory: The destination operand
-8(%ebp)
specifies the memory location where the loaded value needs to be stored. Since both the source and destination operands involve memory references, the instruction violates the single memory reference restriction. This is why the assembler throws an error message.
Solution :
movl 8(%ebp), %eax movl %eax, -8(%ebp)