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. 小书翻译完成,分享啦--《用Python操作大数据[MapReduceHadoop和Spark]》
  2. Window服务安装方式汇总
  3. BizTalk动手实验(三)BizTalk开发综合实验
  4. Javascript基础系列之(三)数据类型 (类型转化)
  5. Spring学习笔记之模块简介
  6. JAVA虚拟机内存分配与回收机制
  7. 关于sql server 代理(已禁用代理xp)解决办法
  8. JavaScript之事件委托(附原生js和jQuery代码)
  9. 谈谈JAVA中的安全发布
  10. BZOJ1757 : Apple 偷苹果
  11. HBase篇--HBase常用优化
  12. 《机器学习实战》之一:knn(python代码)
  13. 查找单链表中倒数第K个位置上的结点,若查找成功返回该节点的data域,若不成功只返回0
  14. python中和生成器协程相关的yield之最详最强解释,一看就懂(一)
  15. callback源码分析——callbacks
  16. vue 兼容360及safari的方法
  17. Android sdk manager 下载速度慢的问题
  18. arcgis python添加几何属性
  19. bond下改变网卡
  20. python---tornado补充(异步非阻塞)

热门文章

  1. Mac Mysql初始密码重置
  2. 四核RP4412开发板使用Xshell连接的com口应与电脑端口一致
  3. 推荐一个实用的css工具
  4. struts文件上传、文件下载
  5. eclipse 字体、背景、自动提示设置
  6. android editText 监听事件
  7. spring入门教程——笔记
  8. 2.4G/5G频段WLAN各国使用信道表
  9. 初学mongodb笔记
  10. Spring学习笔记(一)