2
votes

try to implement a basic operating system but this asm stuff is messing with my head i am using vs2015

the code that gives error

inline cpu_flags DisableInterrupts()

{
cpu_flags fl;


_asm volatile ("pushfl; popl %0; cli" : "=g" (fl));


return fl;
}

it gives error like this

Error C2400 inline assembler syntax error in 'opcode'; found 'data type'

after removing volatile also no luck

inline cpu_flags DisableInterrupts()
 {



 cpu_flags fl;


_asm ("pushfl; popl %0; cli" : "=g" (fl));


return fl;`
}

it gives

Error C2400 inline assembler syntax error in 'opcode'; found '('

thank you

2

2 Answers

1
votes

That's AT&T syntax used by gcc.

Visual Studio uses Intel syntax for its inline assembler. However, there is also a built in _disable() function that doesn't require any assembler code.

Also not the remarks about the limited use of this function:

This function is only available in kernel mode. If used in user mode, a Privileged Instruction exception is thrown at run time.

0
votes

There are many different compilers in the world, and they all work a bit differently.

The syntax you are using in your question comes from gcc made by gnu.

However, you say you are trying to use it with Visual Studio which is made by Microsoft. Visual Studio uses a very different syntax for inline asm than gcc.

I'm not going to try to teach you everything about Visual Studio's inline asm. See their docs.