I would like to move a variable that is pointed by a pointer to another pointer using inline assembly. And as we all know that in X86 there is no memory-memory instruction. Therefore moving from one memory location to another will always go through a x86 register. As I would like to track this mov instructions in a simulator, I extend the instruction by adding a prefix to the mov
instruction.
Coming to my problem, when I add a prefix to the mov
instruction and view the assembly file via -S flag, only one of the mov
instruction has a prefix, whereas I would like all the instructions involved in moving the variable via the pointer to have the prefix, How can I achieve this.
My simple workload is as follows:
#include <stdio.h>
#include <stdlib.h>
template<typename T>
void spmmov(T &dst, T &src) {
asm("repne;nop");
asm("repne;movl %1, %0"
: "=r"(dst)
: "m" (src)
: // no clobbers
);
}
void movetospm(int *dst, int *src)
{
spmmov(*dst, *src);
}
int main()
{
int x = 700;
int y = 50;
int *Pointer2 = &y;
int *Pointer = &x;
movetospm(Pointer2,Pointer);
printf("%d\n",*Pointer2);
printf("%d\n",x);
}
compiled with the -S flag i get the following output for my spmmov function:
_Z6spmmovIiEvRT_S1_:
.LFB17:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -8(%rbp)
movq %rsi, -16(%rbp)
#APP
# 7 "newspm.cpp" 1
repne;nop
# 0 "" 2
#NO_APP
movq -16(%rbp), %rax #would like this one to have the repne prefix
#APP
# 14 "newspm.cpp" 1
repne;movl (%rax), %edx
# 0 "" 2
#NO_APP
movq -8(%rbp), %rax #would like this one to have the repne prefix
movl %edx, (%rax) #would like this one to have the repne prefix
nop
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
As stated in the comments of the assembly code, is it possible to have all the mov
instructions to have the repne prefix?
any help would be appreciated.