1.2 ASSEMBLY LANGUAGE
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的更多相关文章
- 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. ...
- 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- ...
- PythonStudy——汇编语言 Assembly Language
汇编语言 汇编语言(assembly language)是一种用于电子计算机.微处理器.微控制器或其他可编程器件的低级语言,亦称为符号语言.在汇编语言中,用助记符(Mnemonics)代替机器指令的操 ...
- An Assembly Language
BUFFER OVERFLOW 3 An Assembly Language Introduction Basic of x86 Architecture Assembly Language Comp ...
- CS萌新的汇编学习之路02 Learning of Assembly Language
第二节课 寄存器 1. 寄存器的定义: 进行信息储存的器件,是CPU中程序员可以读写的部件,通过改变各种寄存器中的内容来实现对CPU的控制 2. 寄存器的种类: 本节课学习通用寄存器和段寄存器 2. ...
- CS萌新的汇编学习之路(其实是老师作业呵呵哒)Learning of Assembly Language
第一节课学习汇编语言,做笔记,做笔记 1.概念 首先是汇编语言这门课程的定义以及对于学习高级语言.深入理解计算机系统的作用 软硬件接口机器语言 汇编语言 高级语言 关系 机器语言和汇编语言可移植性差 ...
- 汇编语言教材assembly language
https://en.wikipedia.org/wiki/Assembly_language https://baike.baidu.com/item/%E6%B1%87%E7%BC%96%E8%A ...
- 《PC Assembly Language》读书笔记
本书下载地址:pcasm-book. 前言 8086处理器只支持实模式(real mode),不能满足安全.多任务等需求. Q:为什么实模式不安全.不支持多任务?为什么虚模式能解决这些问题? A: 以 ...
- 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 ...
随机推荐
- Swift 06.Closures
Closures --闭包 看了好些文章.由于自己也是刚开始学习swift,闭包还是不是很明白.暂时先放放.等看完后面的.加深感触后,在回头总结闭包的概念. 数组中常用的闭包函数 在Swift的数组中 ...
- 吐槽!important专用博文
在IT公司实习了1个多月,氛围还是不错的,也算是积累了一些项目经验,同时在代码模块化.版本控制.任务优先级等方面有了更进一步的体会和理解,深刻认识到在一个团队,最重要的是沟通和负责. 嗯,说了下题外话 ...
- ORM
参考:http://wenku.baidu.com/link?url=Kc9KHESrzLUp8KtcQH4Ls4QQpKosNiyQAVgkNX-UN4j9QuRhS-Hy5FGJjmWW2oszT ...
- Bootstrap<基础一> CSS 概览
HTML 5 文档类型(Doctype) Bootstrap 使用了一些 HTML5 元素和 CSS 属性.为了让这些正常工作,您需要使用 HTML5 文档类型(Doctype). 因此,请在使用 B ...
- 基于H5的移动端开发,window.location.href在IOS系统无法触发问题
最近负责公司的微信公众号开发项目,基于H5进行开发,某些页面window.location.href在Android机上能正常运行而IOS系统上无法运行,导致无法重定向到指定页面,查了好久终于找到方法 ...
- 【转帖】Python在大数据分析及机器学习中的兵器谱
Flask:Python系的轻量级Web框架. 1. 网页爬虫工具集 Scrapy 推荐大牛pluskid早年的一篇文章:<Scrapy 轻松定制网络爬虫> Beautiful Soup ...
- Titanium studio安装
在Win7 Titanium Studio的安装过程. 1.准备工作 Titanium存储空间的要求,Titanium Studio 需要1 GB.Android SDK需要1.5 GB.Blackb ...
- IOS App 右上脚红色数字提醒
IOS8.0以前直接显示: UIApplication *application=[UIApplication sharedApplication]; //设置图标上的更新数字 application ...
- MAC上显示隐藏文件夹
第一步:打开「终端」应用程序. 第二步:输入如下命令: defaults write com.apple.finder AppleShowAllFiles -boolean true ; killal ...
- Activity中获取当前Fragment 中的子控件
XXXAdapter中 增加 public Fragment currentFragment; @Override public void setPrimaryItem(ViewGroup conta ...