LinuxAsm#Chapter10
Dividing and Conquering
Book: Assembly Language step by step
Complexity kills programs.
Remember to use comment headers.(Comment is very very important!)
More Than 25 lines and you're doing too much in one procedure.Split it up.
Calling and Returning
call LoadBuff
...
loadBuff:
push eax ; a1
push ebx ; a2
push edx ; a3
mov eax, 3 ; sys_read call
mov ebx, 0 ; File Descriptor 0: stdin
mov ecx, Buff ; offset of the buffer to read to
mov edx, BUFFLEN ; number of bytes to read at one pass
int 80h ; sys_read
mov ebp, eax
xor ecx, ecx
pop edx ; b1
pop ebx ; b2
pop eax ; b3
ret
- a1~a3 and b1~b3 are store of stack
- "xor ecx, ecx" is faster than "mov ecx, 0"
Saving the Caller's Registers
pushad
...
popad
Table Tricks
DumpLin db " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
DUMPLEN equ $-DumpLin
ASCLin db "|................|", 10
ASCLEN equ $-ASCLin
FULLLEN equ $-DumpLin
lea edi, [edx*2+edx] ; trick to calculate 3*edx
Local Labels and the Lengths of Jumps
Scan:
xor eax, eax
...
.modTest:
test esi, 0000000Fh
...
- "Scan" is a nonlocal label.(global label)
- ".modTest" is a local label.
- Local labels are local to the first nonlocal label that precedes them in the code.
- A local label cannot be referenced higher in the source code file than the global label that owns it.
- Local labels are not accessible as breakpoints from the command-line interface of GDB.
- Good habits: local labels and all jumps to them should occur within a single screen of code.
Type of Jumps
jne Scan ; Short jump, to within 127 bytes in either direction
jne near Scan ; Near jump, anywhere in the current code segment
Building External Procedure Libraries
Each executable file can only contain one _start: label. External modules do not contain _start:
External modules do not return to Linux.(Only the main program module can make sys_exit INT 80h call)
main-program.asm:
section .text
extern ClearLine
global _start
_start:
...
call ClearLine
...
lib.asm:
section .text
global ClearLine
...
ClearLine:
...
Rules:
- "extern" to declare all the labels that don't belong to the current file.
- "global" to declare all the labels in the current file needed by other files.
Simple Cursor Control in the Linux Console
[section .data]
PositionTerm db 27, "[01;01H" ; <ESC>[<Y>;<X>H -This sequences move the cursor to (X, Y)
ClearTerm db 27, "[2J" ; <ESC>[2J -This sequences clears the display.
GreenBack db 27, "[42m" ; <ESC>[42m -turns the consoles background green
For more details about console escape codes: man console_codes
Creating and Using Macros
%macro WriteStr 2 ; 2 arguments
push eax
push ebx
mov ecx, %1 ; %1 invokes the first argument (Prompt)
mov edx, %2 ; %2 invokes the second argument (PROMPTLEN)
mov eax, 4
mov edx, 1
int 80h
pop ebx
pop eax
%endmacro
....
....
WriteStr Prompt, PROMPTLEN
; When a macro is invoked, its arguments are separated by commas.
Local Labels Within Macros
%macro UpCase 2
mov edx, %1
mov ecx, %2
%%IsLC:
cmp byte [edx+ecx-1], 'a'
jb %%Bump
cmp byte [edx+ecx-1], 'z'
ja %%Bump
sub byte [edx+ecx-1], 20h
%%Bump:
dec ecx
jnz %%IsLC
%endmacro
Macro Libraries As Include Files
%include "mylib.mac"
LinuxAsm#Chapter10的更多相关文章
- 【Python编程:从入门到实践】chapter10 文件和异常
chapter10 文件和异常 10.1 从文件中读取数据 10.1.1 读取整个文件 with open("pi.txt") as file_object: contents = ...
- 【Linux_Unix系统编程】Chapter10 时间
chapter10 时间 1:真实时间:度量这一时间的起点有二:(1)某个标准点:(2)进程生命周期内的某个固定时点(通常为程序启动) 2:进程时间:一个进程所使用的CPU时间总量,适用于对程序,算法 ...
- Chapter10
package scala import java.io.{PrintStream, PrintWriter}import java.util.Date import scala.util.loggi ...
- 【笔记】《Redis设计与实现》chapter10 RDB持久化
chapter10 RDB持久化 10.1 RDB文件的创建和载入 有两个Redis命令可以用于生成RDB文件,SAVE和BGSAVE SAVE阻塞服务器进程进行RDB文件的创建,BGSAVE则创建服 ...
- JavaWeb chapter10 JavaWeb开发模式
1. 开发模式 (1)开发模式1:JSP+JavaBean (2)开发模式2:Servlet+JSP+JavaBean (MVC) 2.JavaBean 本质上是一个普通的Java类:需要遵循一定的 ...
- Chapter10:泛型算法
泛型算法的基础是迭代器. 迭代器令算法不依赖于容器,但是算法依赖于元素类型的操作.也即:算法永远不会执行容器的操作. 那么,如果想向容器中添加元素或者执行其他的一些操作呢?标准库提供了插入迭代器来完成 ...
- Chapter10(泛型算法)--C++Prime笔记
关键:算法通过在迭代器上进行操作来实现类型无关.算法不改变所操作序列的大小. 1.算法大多都定义在algorithm头文件中,标准库还在头文件numeric中定义了一组数值泛型算法. 2.泛型算法永远 ...
- 【APUE】Chapter10 Signals
Signal主要分两大部分: A. 什么是Signal,有哪些Signal,都是干什么使的. B. 列举了非常多不正确(不可靠)的处理Signal的方式,以及怎么样设计来避免这些错误出现. 10.2 ...
- [SharePoint][SharePoint Designer 入门经典]Chapter10 Web部件链接
本章概要: 1.Web部件作用 2.如何添加和配置 3.如何个性化 4.如何导出,并在其他站点重利用 5.通过组合web part创建复杂的用户界面
随机推荐
- Elastic Image Slider 带缩略图功能的幻灯片
今天我们要为您展示如何创建一个简单的弹性幻灯片,带有缩略图预览功能.Elastic Image Slider 这款幻灯片能够自动调整以适应到其父容器,我们可以通过幻灯片使用缩略图预览或幻灯片的自动播放 ...
- js引入php 用来加载静态页面 输出到页面中
HTML页面中加入代码 <script type="text/javascript" src="http://www.域名.com/js.php?id=tjyd&q ...
- 如何使用代码或脚本启用SharePoint的备用语言
SP的多语言,需要安装语言包,然后手工去sharepoint下启动备用语言,如下图: [网站操作]-[语言设置]: 方法一:采用powershell处理 在很多项目情况下,需要用代码进行备用语言启动. ...
- Autodesk 360 Mobile不能显示图片?
在6月21号的DevLab上,有一位朋友说Autodesk 360 Mobile在iPad上不能显示JPG图片预览.我当时没带iPad,不能测试.后天回家在Autodesk 360 Mobile 3. ...
- Android HTTP实例 使用GET方法和POST方法发送请求
Android HTTP实例 使用GET方法和POST方法发送请求 Web程序:使用GET和POST方法发送请求 首先利用MyEclispe+Tomcat写好一个Web程序,实现的功能就是提交用户信息 ...
- android加固系列—2.加固前先要学会破解,调试内存值修改程序走向
[版权所有,转载请注明出处.出处:http://www.cnblogs.com/joey-hua/p/5138585.html] 因公司项目需要对app加固,经过本人数月的研究,实现了一套完整的仿第三 ...
- 深入.net(集合)
集合技术: 用于“批量数据”管理的重要技术,是数组技术的替代技术! 与数组技术的对比: 数组:只提供“存储的空间”,但缺乏各种数据管理措施! 集合:在数组的基础上,提供丰富的“属性”和“方法”,来方便 ...
- 利用grep命令查找文件内容
例如查找PHP源码某个函数的具体实现 grep -rn "PHP_FUNCTION(socket_accept)" ./ext
- 赫夫曼\哈夫曼\霍夫曼编码 (Huffman Tree)
哈夫曼树 给定n个权值作为n的叶子结点,构造一棵二叉树,若带权路径长度达到最小,称这样的二叉树为最优二叉树,也称为哈夫曼树(Huffman Tree).哈夫曼树是带权路径长度最短的树,权值较大的结点离 ...
- 世道变了 – 你愿意成为微软认证Linux工程师吗?
随笔世道变了 – 你愿意成为微软认证Linux工程师吗? 世道变了 – 你愿意成为微软认证Linux工程师吗? leixu十二月 14, 2015随笔 2015年12月9日,微软发布了全新的MCS ...