c++ - 内联汇编器在 vs 2015 中给出了 c2400

标签 c++

尝试实现一个基本的操作系统,但我正在使用 vs2015,但这些 asm 的东西让我很困惑

出错的代码

inline cpu_flags DisableInterrupts()

{
cpu_flags fl;


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


return fl;
}

它给出这样的错误

Error C2400 'opcode' 中的内联汇编语法错误;找到“数据类型”

删除 volatile 后也没有运气

inline cpu_flags DisableInterrupts()
 {



 cpu_flags fl;


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


return fl;`
}

它给

Error C2400 'opcode' 中的内联汇编语法错误;找到 '('

谢谢

最佳答案

这是 gcc 使用的 AT&T 语法。

Visual Studio 的内联汇编程序使用 Intel 语法。但是,还有一个内置的 _disable()不需要任何汇编代码的函数。

也不是关于限制使用该功能的备注:

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

关于c++ - 内联汇编器在 vs 2015 中给出了 c2400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43157143/

相关文章:

c++ - Opencv 功能匹配在 iPhone 上中断,但在模拟器上没有

c++ - 像素数据传输 : 24BPP images and GL_UNPACK_ALIGNMENT set to 4

c++ - GDB。只捕获未捕获的异常

c++ - 别名到数组

c++ - 类 std::out_of_range 在哪里完全定义?

c++ - 无效* p ...; if (p > 0) .... 这是未定义的行为吗?

c++ - 将 std::string 转换为 std::chrono::duration

c# - .NET 和 PCL(点云库)

c++ - 尽管已声明,但找不到模板化函数

c++ - 如何根据另一个 vector 对一个 vector 进行排序?