zoukankan      html  css  js  c++  java
  • x86---32汇编(0)


      一直都想要系统的学习一下计算机知识,汇编知识对于计算机的学习会有很大的帮助,现在笔者准备学习一下汇编打算使用碎片的化的时间,记录自己写的一些程序和一些心得,方便自己以后学习和使用,所以笔者很难每日一更。我使用的软件仍然是vs2017,参考书用的是《现代x86汇编语言》。大家有兴趣可以去下载看一下。
     我简单根据书上的代码写了一个求和:

     1 #include "stdafx.h"
     2 
     3 extern "C" int CalcSum_(int a, int b, int c);
     4 
     5 int _tmain(int argc, _TCHAR* argv[])
     6 {
     7     int a = 17, b = 11, c = 14;
     8     int sum = CalcSum_(a, b, c);
     9 
    10     printf("  a:   %d
    ", a);
    11     printf("  b:   %d
    ", b);
    12     printf("  c:   %d
    ", c);
    13     printf("  sum: %d
    ", sum);
    14     return 0;
    15 }
    Calsum.cpp
     1     .model flat,c
     2     .code
     3 
     4 ; extern "C" int CalcSum_(int a, int b, int c)
     5 ;
     6 ; Description:  This function demonstrates passing arguments between
     7 ;               a C++ function and an assembly language function.
     8 ;
     9 ; Returns:      a + b + c
    10 
    11 CalcSum_ proc
    12 
    13 ; Initialize a stack frame pointer
    14         push ebp
    15         mov ebp,esp
    16 
    17 ; Load the argument values
    18         mov eax,[ebp+8]                     ; eax = 'a'
    19         mov ecx,[ebp+12]                    ; ecx = 'b'
    20         mov edx,[ebp+16]                    ; edx = 'c'
    21 
    22 ; Calculate the sum
    23         add eax,ecx                         ; eax = 'a' + 'b'
    24         add eax,edx                         ; eax = 'a' + 'b' + 'c'
    25 
    26 ; Restore the caller's stack frame pointer
    27         pop ebp
    28         ret
    29 
    30 CalcSum_ endp
    31         end
    Calsum.asm
  • 相关阅读:
    Markdown语法
    简易银行管理系统
    登录sql sever
    MainActivity中R为红色
    PLC STL any数据类型
    Oracle ORA-12541,ORA-12514错误
    Myeclispe下struts-config.xml文件无法图形界面打开
    SSH报错
    Myeclispe 代码自动补全
    Mac下多个jdk自由切换
  • 原文地址:https://www.cnblogs.com/xuelanga000/p/12651206.html
Copyright © 2011-2022 走看看