首页 新闻 会员 周边 捐助

C 语言中如何内嵌 汇编 语言?

0
悬赏园豆:5 [待解决问题]

刚刚学完C,后来在网上看到有人说C还能内嵌汇编,书上没说有这事啊。。哪位能给个小例子(代码)?谢谢!

hexllo的主页 hexllo | 菜鸟二级 | 园豆:318
提问于:2013-07-24 14:03
< >
分享
所有回答(2)
0

参考:C嵌入汇编

dudu | 园豆:30948 (高人七级) | 2013-07-24 14:46
0
void flipIt(void* buffer)                       // Flips The Red And Blue Bytes (256x256)
{
    void* b = buffer;                       // Pointer To The Buffer
    __asm                               // Assembler Code To Follow
    {
        mov ecx, 256*256                    // Set Up A Counter (Dimensions Of Memory Block)
        mov ebx, b                      // Points ebx To Our Data (b)
        label:                          // Label Used For Looping
            mov al,[ebx+0]                  // Loads Value At ebx Into al
            mov ah,[ebx+2]                  // Loads Value At ebx+2 Into ah
            mov [ebx+2],al                  // Stores Value In al At ebx+2
            mov [ebx+0],ah                  // Stores Value In ah At ebx
             
            add ebx,3                   // Moves Through The Data By 3 Bytes
            dec ecx                     // Decreases Our Loop Counter
            jnz label                   // If Not Zero Jump Back To Label
    }
}
zlt | 园豆:237 (菜鸟二级) | 2013-07-26 08:11

编译不过啊,void * pointer,void不是表示空类型吗?这种类型的指针代表什么?

支持(0) 反对(0) hexllo | 园豆:318 (菜鸟二级) | 2013-07-30 14:56

@hexllo: 

任意类型的指针,你用的啥编译器,我在vs2008下,编译没有问题。

支持(0) 反对(0) zlt | 园豆:237 (菜鸟二级) | 2013-07-30 18:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册