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 ...
随机推荐
- mysql与sqlserver之间的关系转换
sqlserver中的数据类型与mysql之间的对应 --sqlserver = 只复制表结构 = 复制表结构和表数据 --mysql create table xx like xx; 只复制表结构 ...
- placeholder 使用
这个属性是用于INPUT当中. 实现效果: 1.鼠标点击进入<input type='buttom' placeholder='用户名'> 2.用户名内容消失:不在使用以前的Value,来 ...
- c语言基础数据类型及命名规范
1. 常量是程序运行期间不能被改变的量; 变量代表一个存储区域,存储区域内存储的内容就是变量的值, 变量的值可以在程序运行期间改变 (变量就像一个杯子, 用来存放水, 杯子里的水即变量的值是可以改变 ...
- MFC之键盘和键盘消息处理
今天学习了最基本的MFC操作,键盘及键盘消息函数,跟着书中的内容自己编了个小程序.检测用户是否同时按下SHIFT和B键 第一步:先是建了一个单文档模式的MFC程序,添加了键盘消息及处理函数.键盘消息处 ...
- 面试复习(C++)之快速排序
#include <iostream> using namespace std; void Quicksort(int *a,int low,int high) { if(low>h ...
- 制造行业流程管理的“IPO”思维
流程管理是企业从流程角度出发,关注流程是否增值的一套管理体系.从认识流程.到建立流程.到管理流程.再到优化流程,企业管理人员要去除不增值和低价值的流程,减少员工犯错误的机会,建立一套卓越的流程体系. ...
- 读取微博feed伪代码
// 读取我的好友fids $db = new DB(); $mc = new Memcached(); $_uid = 1; // my uid $sql = "select * from ...
- 手把手教你在ubuntu上安装apache和mysql和php
1:首先安装apache:打开终端(ctrl+Alt+t), 输入命令:sudo apt-get install apache2即可安装, 安装完后,打开浏览器,在地址栏输入:localhost或者h ...
- tesseract 编译与使用(windows)
tesseract是google的一个开源OCR项目,项目地址已经迁移到github(现在 2016/09),地址 https://github.com/tesseract-ocr/tesseract ...
- 近期编程问题——read:resource temporarily unavailable
EAGAIN错误 出现问题:read:resource temporarily unavailable 原因:这种错误一般出现宰非阻塞的socket编程中,资源暂时不可用. 我的解决方法:囧,后来改成 ...