黑客风云——风云网络
设为首页 加入收藏 我要投稿 网站地图

您现在的位置: 黑客风云 >> 黑客文章 >> 黑客进阶 >> 软件破解 >> 正文
·完美空间提供500M免费AS04-10·企业安全之YY内网准入以04-09
·企业安全之意识与策略04-09·剑走偏锋:IIS漏洞利用04-09
·我来免费网提供100M免费04-09·1122mb.com提供20G超大免04-08
·映像劫持与反劫持技术04-07·让所有"暴力删除工具"无04-07
·入侵88red系统的详细过程04-07·Sql Injection脚本注入终04-07
·vbs+delphi 反弹后门生成04-07·飞讯网提供100MB免费PHP04-07
·突破SQL注入攻击时输入框04-04·结合内核和病毒技术的最04-04
·Real Player rmoc3260.d04-04·亿万网络今月最后为您提04-04
·php+mysql 5 sql inject04-03·Real Player rmoc3260.d04-03
·oblog文件下载漏洞04-03·免费啦提供1G-2G免费全能04-03
·完全解析网页后门和挂马04-02·一句话开3389(只测试过04-02
·萧萧免费空间网提供100M04-02·谷道免费空间网提供1G免04-01
·从本地入手解决双线路由03-31·sablog 1.6 多个跨站漏洞03-31
·富文本编辑器的跨站脚本03-31·Cookie注入是怎样产生的03-31
[推荐]汇编知识:32位汇编代码优化
      ★★★★★

汇编知识:32位汇编代码优化

文章整理发布:黑客风云 文章来源:www.05112.com 更新时间:2006-12-2 11:22:32

11.其他技巧:
如果EAX小于80000000h,edx清0:
--------------------------------------------------
1) xor edx, edx ;2 bytes, but faster
2) cdq ;1 byte, but slower
我一直使用cdq,为什么不呢?体积更小...

下面这种情况一般不要使用esp和ebp,使用其他寄存器.
-----------------------------------------------------------
1) mov eax, [ebp] ;3 bytes
2) mov eax, [esp] ;3 bytes
3) mov eax, [ebx] ;2 bytes

交换寄存器中4个字节的顺序?用bswap
---------------------------------------------------------
mov eax, 12345678h ;5 bytes
bswap eax ;2 bytes
;eax = 78563412h now
Wanna save some bytes replacing CALL ?
---------------------------------------

1) call _label_ ;5 bytes
ret ;1 byte
2) jmp _label_ ;2/5 (SHORT/NEAR)
如果仅仅是优化,并且不需要传递参数,请尽量用jmp代替call

比较 reg/mem 时如何节省时间:
------------------------------------------
1) cmp reg, [mem] ;slower
2) cmp [mem], reg ;1 cycle faster

乘2除2如何节省时间和空间?
------------------------------------------------------------
1) mov eax, 1000h
mov ecx, 4 ;5 bytes
xor edx, edx ;2 bytes
div ecx ;2 bytes
2) shr eax, 4 ;3 bytes
3) mov ecx, 4 ;5 bytes
mul ecx ;2 bytes
4) shl eax, 4 ;3 bytes


loop指令
------------------------
1) dec ecx ;1 byte
jne _label_ ;2/6 bytes (SHORT/NEAR)

2) loop _label_ ;2 bytes

再看:
3) je $+5 ;2 bytes
dec ecx ;1 byte
jne _label_ ;2 bytes

4) loopXX _label_ (XX = E, NE, Z or NZ) ;2 bytes
loop体积小,但486以上的cpu上执行速度会慢一点...


比较:
---------------------------------------------------------
1) push eax ;1 byte
push ebx ;1 byte
pop eax ;1 byte
pop ebx ;1 byte


2) xchg eax, ebx ;1 byte

3) xchg ecx, edx ;2 bytes
如果仅仅是想移动数值,用mov,在pentium上会有较好的执行速度:
4) mov ecx, edx ;2 bytes


比较:
--------------------------------------------

1) 未优化:
lbl1: mov al, 5 ;2 bytes
stosb ;1 byte
mov eax, [ebx] ;2 bytes
stosb ;1 byte
ret ;1 byte
lbl2: mov al, 6 ;2 bytes
stosb ;1 byte
mov eax, [ebx] ;2 bytes
stosb ;1 byte
ret ;1 byte
---------
;14 bytes
2) 优化了:
lbl1: mov al, 5 ;2 bytes
lbl: stosb ;1 byte
mov eax, [ebx] ;2 bytes
stosb ;1 byte
ret ;1 byte
lbl2: mov al, 6 ;2 bytes
jmp lbl ;2 bytes
---------
;11 bytes

读取常数变量,试试在指令中直接定义:
-----------------------------

...
mov [ebp + variable], eax ;6 bytes
...
...
variable dd 12345678h ;4 bytes

2) 优化为:

mov eax, 12345678h ;5 bytes
variable = dword ptr $ - 4
...
...
mov [ebp + variable], eax ;6 bytes

呵呵,好久没看到这么有趣的代码了,前提是编译的时候支持代码段的写入属性要被设置.

最后介绍未公开指令SALC,现在的调试器都支持...什么含义呢:就是CF位置1的话就将al置为0xff
------------------------------------------------------------------

1) jc _lbl1 ;2 bytes
mov al, 0 ;2 bytes
jmp _end ;2 bytes
_lbl: mov al, 0ffh ;2 bytes
_end: ...

2) SALC db 0d6h ;1 byte ;)

上一页  [1] [2] [3] 

文章录入:cainiaowang    责任编辑:cainiaowang 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    VIP 专 区
    Copyright @2006 黑客风云 ●业务联系:QQ 联系怪人 联系奇人 Email:给怪人发邮件 给奇人发邮件
    ICP备案:冀06009886