I am programming in c++ with x86 assembly integrated with block _asm {} but I keep running into the same error C2400. I’m trying to calculate the first n prime numbers.
Error: Error C2400 assembly code syntax error inserted in 'second operand'; found 'PTR'
The problem is on line 2.
void primosx86(int n, vector<int>& primos) {
primos.resize(n);
int* ptr = primos.data();
__asm {
mov ecx, n
lea edi, [ptr]
mov edi, [edi]
mov esi, 2
outer_loop:
mov eax, esi
mov ebx, 2
inner_loop :
cmp ebx, eax
jge is_prime
mov edx, 0
div ebx
cmp edx, 0
je not_prime
inc ebx
jmp inner_loop
is_prime :
mov[edi], eax
add edi, 4
dec ecx
jz finished
not_prime :
inc esi
jmp outer_loop
finished :
}
}
I asked chatGPT, but even though it suggested modifications to the code, I ended up in the same place and receiving the same error.
PTR
is a reserved word in MASM. Pick a different name for your variable.