zoukankan      html  css  js  c++  java
  • VC++ 汇编相关的东西

    Tips: VC++在新建一个.asm文件后必须重新导入project中才能进行编译。

    下面是一个汇编与C++相互调用的例子:

    Main.cpp

    #include <stdio.h>
    #include <Windows.h>
    #include <string.h>
    
    class CTest
    {
    public:
        void Init()
        {
            m_nSize = 100;
            m_pContent = new char[m_nSize];
            strcpy(m_pContent,"hello world!");
        }
        void Show()
        {
            printf("%s
    ",m_pContent);
        }
        void Destory()
        {
            if (m_pContent)
            {
                delete[] m_pContent;
                m_pContent = NULL;
            }
            m_nSize = 0;
        }
    private:
        int m_nSize;
        char* m_pContent;
    };
    
    extern "C" void __stdcall InitTest(DWORD pThis,DWORD pFunc);
    extern "C" int __stdcall bswap_func(int InputVar);
    
    int main(int agrc,char* argv[])
    {
        CTest* pTest = new CTest();
    #ifdef TEST_ASM_INFILE
        _asm
        {
            mov eax,pTest
            call CTest::Init
        }
    #else
        void (__thiscall CTest::* pFunc)(void) = &CTest::Init;
        InitTest((DWORD)pTest,*(DWORD*)&pFunc);
    #endif
        pTest->Show();
        pTest->Destory();
        delete pTest;
    
        int nTest = 0x12345678;
        int nResult = bswap_func(nTest);
        printf("Original number:0x%x reverse number:0x%x
    ",nTest,nResult);
        return 0;
    }

    Func.asm

    .686
    .model flat, stdcall
    
    .code
    InitTest proc pThis:DWORD,pFunc:DWORD
        mov ecx,pThis
        call pFunc
        ret
    InitTest endp
    
    bswap_func proc InVar:DWORD
        mov        eax,    InVar
        bswap    eax
        ret
    bswap_func endp
    
    end
  • 相关阅读:
    Springboot整合Dubbo
    网站appache的ab命令压力测试性能
    静态页面框架
    CSS布局设计
    弹性盒子的总结
    弹性盒子
    应用媒介查询制作响应式导航栏
    响应式的设计需要遵守的4个原则和媒介查询语句
    media type的类型汇总
    background-orgin属性
  • 原文地址:https://www.cnblogs.com/xylc/p/3540438.html
Copyright © 2011-2022 走看看