Tag: masm

在Visual Studio中将C与程序集链接

我正在尝试将main.c程序与procedure.asm链接。 我有以下C程序和汇编程序。 main.c中 #include #include using namespace std; extern “C” { void ClearUsingIndex(int[], int); } static int Array[10] ={1, 2, 3, 4, 5, 6, 7, 8, 9, -1}; int main() { int size = 10; ClearUsingIndex( Array, size); system(“pause”); return 0; } procedure.asm ; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1 TITLE c:\Users\GS\documents\visual […]

MASM:从程序集访问全局C变量

我正在编写一个程序来转换图像并比较C和汇编中处理数据的速度。 我有3个项目: C的主要项目 C中的DLL转换图像 ASM中的DLL转换图像 在C DLL头文件中,我只是写道: #ifdef PROJEKTC_EXPORTS #define PROJEKTC_API __declspec(dllexport) #else #define PROJEKTC_API __declspec(dllimport) #endif … extern PROJEKTC_API unsigned int ThreadID; PROJEKTC_API void __cdecl funkcjaC(void* Args); 包含此标题后,我可以在主项目和C DLL中访问变量ThreadID。 当我尝试在ASM中执行相同操作时,问题就开始了。 我在extern ASMThreadID:dword块中尝试过像extern ASMThreadID:dword这样的构造,但它不起作用。 我得到的错误: error LNK2019: unresolved external symbol _ASMThreadID referenced in function _MyProc1 我觉得这是1-2行代码的问题,但我无法弄清楚应该使用哪条指令。 我通过ASM中的模块定义文件链接项目,并将ASM.lib文件添加到主项目的链接器 – >输入中。 你有什么建议吗?

内联汇编跳转错误

一旦Masm达到jmp,为什么会失败呢? struct gdt_entry { unsigned short limit_low; unsigned short base_low; unsigned char base_middle; unsigned char access; unsigned char granularity; unsigned char base_high; }; struct gdt_ptr { unsigned short limit; unsigned int base; }; struct gdt_entry gdt[3]; struct gdt_ptr gp; void gdt_flush() { __asm{ lgdt [gp] mov ax, 0x10 mov ds, ax mov es, ax mov […]

在x64 Visual Studio中内联汇编函数

我知道x64模式下的MSVC编译器不支持内联汇编代码片段,并且为了使用汇编代码,你必须在一些外部my_asm_funcs.asm文件中定义你的函数,如下所示: my_asm_func PROC mov rax, rcx ret my_asm_func ENDP 然后在你的.c或.h文件中为这个函数定义一个标题: int my_asm_func(int x); 虽然该解决方案解决了许多问题,但我仍然有兴趣使汇编代码函数内联,换句话说 – 在编译之后我不想对my_asm_func进行任何“调用”,我只是希望这个程序集被粘合进入我的最终编译代码。 我尝试使用inline和__forceinline关键字声明函数 ,但似乎没有任何帮助。 还有什么办法可以做我想要的吗?

从C / C ++代码执行RDMSR和WRMSR指令

我需要控制C-State配置。 具体来说,我可能想执行以下asm代码: __asm { rdmsr and eax, 0x00 or eax, 0x01 wrmsr } 目前,我在rdmsr行上rdmsr了这个exception: MessWithCStates.exe中0x00e3139e处的未处理exception:0xC0000096:特权指令。 我如何(永久)提升我的应用程序的权限,以便它可以执行上面的代码? 我使用VS 2010。 注意:无需编写内核模式驱动程序即可。 见R / W Everything 。