zoukankan      html  css  js  c++  java
  • 05 内嵌汇编的编程

    说明:参考狄泰软件学院相关课程

     示例如下:

    #include <stdio.h>
    
    int main()
    {
        int result = 0;
        int input = 1;
        
        int a = 1;
        int b = 2;
        
        asm volatile (
            "movl %1, %0
    "
            : "=r"(result)
            : "r"(input)
            );
            
        printf("result = %d
    ", result);
        printf("input = %d
    ", input);
        
        asm volatile (
            "movl %%eax, %%ecx
    "
            "movl %%ebx, %%eax
    "
            "movl %%ecx, %%ebx
    "
            : "=a"(a), "=b"(b)
            : "a"(a), "b"(b)
            );
            
        printf("a = %d
    ", a);
        printf("b = %d
    ", b);
        
        return 0;
    }  

     结果如下:

    result = 1
    input = 1
    a = 2
    b = 1
    

      

     示例代码:

    #include <stdio.h>
    
    int main()
    {
        char* s = "D.T.Software
    ";
        int l = 13;
        
        printf("main begin
    ");
        
        asm volatile(
            "movl $4, %%eax
    "
            "movl $1, %%ebx
    "
            "movl %0, %%ecx
    "
            "movl %1, %%edx
    "
            "int $0x80     
    "
            :
            : "r"(s), "r"(l)
            : "eax", "ebx", "ecx", "edx"
        );
        
        
        asm volatile(
            "movl $1,  %eax
    "
            "movl $42, %ebx
    "
            "int $0x80     
    "
        );
        
        
        printf("main end
    ");
        
        return 0;
    }  

    运行结果:

     

  • 相关阅读:
    thinkphp 模板文件
    thinkphp 目录安全文件
    thinkphp 防止sql注入
    thinkphp 表单令牌
    thinkphp 表单合法性检测
    thinkphp 输入过滤
    thinkphp 静态缓存
    thinkphp sql解析缓存
    thinkphp 查询缓存
    thinkphp 快速缓存
  • 原文地址:https://www.cnblogs.com/lh03061238/p/13098488.html
Copyright © 2011-2022 走看看