People are much happier moving up the ladder,socially or even technically.So our profession has moved from machine code to C/Win32 API,to C++/MFC,to java/AWT(Abstract Window Toolkit,classes for building graphics user interface in Java)/JFC(Java Foundation Classes,a new set of user interface classes which improve AWT),leaving only a few poor guys to implement the link backwards.

It's a good thing we can move forward in increasing productivity,but it's a sad thing that every time we move up the ladder,we quickly accept the new step as the only standard,and forget what's underneath.It's not strange nowadays to open a book on Visual C++ to find only pure MFC stuff inside or to hear questions like "How can I do this in MFC?"

Every time we add a layer of abstraction,a new layer of indirction is added.Someone has to implement each layer using the layers underneath,which id ultimately the assembly language.Even if you're not one of those people,having a deep understanding of assembly language gives you lots of advantages in your professional life.Assembly language helps you debug problems,understanding the working of the underlying OS(for example,just imagine that you got an exception in kernel32.dll).Assembly language helps you optimize your code to the highest performance;just try to understand why memory is implemented in such a comlicated way.Assembly language exposes features of the CPU that are normally not accessible in high-level language-for example,Intel's MMX(Multi-Media Extension)instructions.

Here is a sample program that uses KTimer to measure your CPU clock speed and the time it takes to create a solid bursh:

//Timer.h
#pragma once inline unsigned _int64 GetCycleCount(void)
{
_asm _emit 0x0F
_asm _emit 0x31
} class KTimer
{
unsigned _int64 m_startcycle;
public:
unsigned _int64 m_overhead;
KTimer(void)
{
m_overhead=;
Start();
m_overhead=Stop();
} void Start(void)
{
m_startcycle=GetCycleCount();
} unsigned _int64 Stop(void)
{
return GetCycleCount()-m_startcycle-m_overhead;
}
};
//GDISpeed.cpp

#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include ".\timer.h"
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE,
LPSTR lpCmd, int nShow)
{
KTimer timer;
TCHAR mess[];
timer.Start();
Sleep();
unsigned cpuspeed10 = (unsigned)(timer.Stop()/);
timer.Start();
CreateSolidBrush(RGB(0xAA, 0xAA, 0xAA));
unsigned time = (unsigned) timer.Stop(); wsprintf(mess, _T("CPU speed %d.%d mhz\n")
_T("KTimer overhead %d clock cycles\n")
_T("CreateSolidBrush %d clock cycles %d ns"),
cpuspeed10 / , cpuspeed10 % ,
(unsigned) timer.m_overhead,
time, time * / cpuspeed10); MessageBox(NULL, mess, _T("How fast is GDI?"), MB_OK);
return ;
}

GetCycleCount使用了RDTSC(Read Time Stamp Counter,读取时间计数器)指令。RDTSC以64位无符号整数形式,通过EDX和EAX 32位普通寄存器时,返回自CPU引导后时针走过的圈数。RDTSC的使用方法即,

_emit 0x0F
_emit 0x31

1.2 ASSEMBLY LANGUAGE的更多相关文章

  1. Notes on <Assembly Language step by step>

    By brant-ruan Yeah, I feel very happy When you want to give up, think why you have held on so long. ...

  2. Calling 64-bit assembly language functions lodged inside the Delphi source code

    Code: http://www.atelierweb.com/calling-64-bit-assembly-language-functions-lodged-inside-the-delphi- ...

  3. PythonStudy——汇编语言 Assembly Language

    汇编语言 汇编语言(assembly language)是一种用于电子计算机.微处理器.微控制器或其他可编程器件的低级语言,亦称为符号语言.在汇编语言中,用助记符(Mnemonics)代替机器指令的操 ...

  4. An Assembly Language

    BUFFER OVERFLOW 3 An Assembly Language Introduction Basic of x86 Architecture Assembly Language Comp ...

  5. CS萌新的汇编学习之路02 Learning of Assembly Language

    第二节课  寄存器 1. 寄存器的定义: 进行信息储存的器件,是CPU中程序员可以读写的部件,通过改变各种寄存器中的内容来实现对CPU的控制 2. 寄存器的种类: 本节课学习通用寄存器和段寄存器 2. ...

  6. CS萌新的汇编学习之路(其实是老师作业呵呵哒)Learning of Assembly Language

    第一节课学习汇编语言,做笔记,做笔记 1.概念 首先是汇编语言这门课程的定义以及对于学习高级语言.深入理解计算机系统的作用 软硬件接口机器语言 汇编语言 高级语言 关系 机器语言和汇编语言可移植性差 ...

  7. 汇编语言教材assembly language

    https://en.wikipedia.org/wiki/Assembly_language https://baike.baidu.com/item/%E6%B1%87%E7%BC%96%E8%A ...

  8. 《PC Assembly Language》读书笔记

    本书下载地址:pcasm-book. 前言 8086处理器只支持实模式(real mode),不能满足安全.多任务等需求. Q:为什么实模式不安全.不支持多任务?为什么虚模式能解决这些问题? A: 以 ...

  9. IA-32 Assembly Language Reference Manual

    Load Full Pointer (lds,les, lfs, lgs, and lss) lds{wl} mem[32|48], reg[16|32]les{wl} mem[32|48], reg ...

随机推荐

  1. java selenium (一) selenium 介绍

    Selenium 是目前用的最广泛的Web UI 自动化测试框架. 本系列文章,将深入简出来讲解selenium 的用法 文章的末尾处, 有整个系列的链接 阅读目录 selenium 的命名 sele ...

  2. Apache、NGINX支持中文URL

    Apache(32位):安装环境:CentOS 5.6 + Apache 2.2.15安装结果:安装后支持“中文图片.文件名”链接直接打开以下为安装过程:1.下载安装包 wget ftp://ftp. ...

  3. UVA 11624 Fire!

    题目大意: F代表火焰 J代表人 一个人想在火焰烧到自己之前逃出着火地区 . 为路,人可以走,火可以燃烧(当然如果火先烧到就不能走了) #为墙,不可走 如果能逃出,输出时间,不能,输出IMPOSSIB ...

  4. JavaScript中常用语句

    1.document.write( " "); 输出语句 2.JS中的行注释为:// 块注释:/**/ 3.传统的HTML文档顺序是:document- >html- > ...

  5. 用 QGIS 画矢量交通路线图

    一.准备工作 1.安装插件 为了方便画图,我们安装了OpenLayers,QuickOSM两个插件. 如何安装插件,度娘上都有答案.下图中打勾的部分为安装好的插件: OpenLayers提供了一些开放 ...

  6. Leetcode 详解(股票交易日)(动态规划DP)

    问题描述: 在股市的交易日中,假设最多可进行两次买卖(即买和卖的次数均小于等于2),规则是必须一笔成交后进行另一笔(即买-卖-买-卖的顺序进行).给出一天中的股票变化序列,请写一个程序计算一天可以获得 ...

  7. 杭电--1102--Constructing Roads--并查集

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. python 获取脚本所在目录

    平时写python经常会想获得脚本所在的目录,例如有个文件跟脚本文件放在一个相对的目录位置,那就可以通过脚本文件的目录找到对应的文件,即使以后脚本文件移到其他地方,脚本也基本不需要改动(相对于写死目录 ...

  9. visor 发布

    2014-4-10 visor.com.cn  的域名备案终于审核通过了.http://www.visor.com.cn 终于可以访问了,欢迎大家使用免费的线框图应用设计工具.

  10. Graphics2D字符串根据文本框缩小字体自动换行

    /** * *描述: 长字符串缩小字体自动换行 *@param g  *@param text 字符串 *@param lineWidth 单元格宽度 *@param cellHeight 单元格高度 ...