汇编:一些语法1

1,
汇编指令:具有对应的机器码指令,被编译为机器指令,最终由CPU执行。
伪指令:由编译器来执行的指令,编译器据其执行相关的编译工作。

2,
segment和ends定义一个段的起始,指令、数据、堆栈被划分到不同的栈。
end标示一个汇编程序结束,assume假设某一段寄存器与segment…ends定义的段相关联。
end后面加标号通知编译器程序入口,设置CS:IP。

3,
mov cx,3
s:
    add    ax,ax
    loop s
执行loop时先cx减1,若cx不位0就跳转至s处。

4,
and al,01110011B
or al,00111010B

5,
段寄存器:ds, ss, cs, es;
寄存器:ax, bx, cx, dx,
     ah, al, bh, bl, ch, cl, dh, dl,
     sp, bp, si, di。

6,
[bx], [bx+si], [bx+di], [bx+si+3], [bx+di+3] 段都为ds;
[bp], [bp+si], [bp+di], [bp+si+5], [bx+di+5] 段都为ss。

7,
除法,后面可跟寄存器或内存单元。
div 寄存器
div 内存单元
al = 16位/8位; ah = 16位%8位。
ax= 32位/16位;dx = 32位%8位。
地位商,高位余。
div word ptr [dx+si+8];ax为ax除该内存单元值的商,dx为ax除改内存单元的余数。

8,
dup数据复制
db 3 dup (0); 0 0 0
db 3 dup (0, 1,2);0,1,2, 0,1,2, 0,1,2
db一个数据一个字节;dw一个数据一个字word,双字节;dd一个数据双字double word,四字节。

9,
操作符offset取得标号的偏移地址,是由编译器处理的符号。
mov ax, offset start;取标号start的偏移地址赋值给 ax

10,
jmp通过修改ip或cs:ip无条件跳转。
jmp short 标号;ip = ip + (8位位移)
jmp near ptr 标号; ip = ip + (16位位移)
short是段内短转移,对ip的修改范围是(-128--127)前后2的7次方
near ptr 段内近转移,范围是(-32768--32767)前后2的15次方
这个位移不是标号的目的地址,是更具标号位置计算出来的当前ip值距离标号位置的的差,jmp根据这个相对位移位置加当前ip的值得到标号位置赋值给ip使其跳转。

段间转移:
jmp far ptr 标号;cs=标号所在段cs,ip=标号所在段ip
jmp ax; ip = ax
jmp word ptr ds:[0] ;ip = ds:[0]
jmp dword ptr ds:[0]; ip = ds:[0], cs = ds:[2]

11,
jcxz 标号; if(cx ==0){jmp short 标号}
loop 标号;cx--; if(cx!=0){ jmp short 标号}
ret; pop ip
retf ;pop ip 和pop cs
call 标号;push ip和 jmp near ptr 标号
call ax; push ip 和jmp near ptr ax
call word ptr ds:[0];同上

12,
乘法,后面可跟寄存器或内存单元。
mul 寄存器
mul 内存单元
如果是8位乘发结果放入 ax中,18位乘发高位放dx低位放ax
mul byte [0]; ax = al * ds:[0]
mul bx; ax = ax*bx的低位值,dx = ax*bx的高位值

13,
add ax, 9; ax = ax + 9
sub ax, 5; ax = ax – 9
inc ax; ax = ax + 1
dec ax; ax = ax -1

posted @ 2016-04-13 20:07  细雨细语  阅读(217)  评论(0编辑  收藏  举报