今天学习了汇编语言的串操作指令,大概做以下笔记,
movs 串传送
cmps 串比较
scas 串扫描
lods 从串取
stos 存入串
与它们一起搭配的指令是
rep 重复
repne/repnz 不相等/不为零
与rep配合的movs,stos,lods
操作
start:
if(CX==0)
exit;
CX--;
execute str instruction;
goto start;
如果str instruction为movs
movs具体格式为
movs dst,src
movsb 字节方式传输
movsw 字方式传输
执行的操作是
1) ((DI))<--((SI))
2) 字节操作 根据df使得di加或者减1
3) 字操作 根据df使得di加或者减2
df由std和cld来控制
cld ---》df=0
std ---》df=1
如果str instruction为stos
从寄存器取得数据写入到存储器中(也就是写缓存)
执行操作
字节操作:((DI))<--(AL) , (DI)<--(DI)+/-1
字操作:((DI))<--(AX) , (DI)<--(DI)+/-2
如果str instruction为loas
从存储器写入数据到寄存器(al或者ax)
执行操作
字节操作:(AL)<--((SI)) , (SI)<--(SI)+/-1
字操作:(AX)<--((SI)) , (SI)<--(SI)+/-2
而repe/repz,repne/repnz实际条件也就是多了一个对psw中ZF位
置的判断而已。
cmps
是存储器两个地址的连续地址的比较
执行的操作是
((SI))-((DI))
2) 字节操作 根据df使得di,si加或者减1
3) 字操作 根据df使得di,si加或者减2
scas
是在存储器中查找与al(ax)中相等的位置单元
以下给出来了一个查找字符串"PERSONAL COMPUTER"中是否存
在'C'的例子,如果存在打印"Find String",否则打印"Not Find
String"
%define _BOOT_DEBUG_
%ifdef _BOOT_DEBUG_
org 0100h;
%else
org 07c00h ; 告诉编译器程序加载到7c00 处
%endif
mov ax, cs
mov ds, ax
mov es, ax
cld
mov al, 43h
mov cx, 11h
mov di, StrMessage
repne scasb
jz Find
call DispNo
jmp $
Find:
call DispStr ; 调用显示字符串例程
jmp $ ; 无限循环
DispStr:
mov ax, StrFind
mov bp, ax ; es:bp = 串地址
mov cx, 11 ; cx = 串长度
mov ax, 01301h ; ah = 13, al = 01h
mov bx, 000ch ; 页号为0(bh = 0) 黑底红字(bl = 0Ch,
高亮)
mov dl, 0
int 10h ; 10h 号中断
ret
DispNo:
mov ax, StrNotFind
mov bp, ax ; es:bp = 串地址
mov cx, 15 ; cx = 串长度
mov ax, 01301h ; ah = 13, al = 01h
mov bx, 000ch ; 页号为0(bh = 0) 黑底红字(bl = 0Ch,
高亮)
mov dl, 0
int 10h ; 10h 号中断
ret
StrFind: db "Find String"
StrNotFind: db "Not Find String"
StrMessage: db "PERSONAL COMPUTER"
times 510-($-$$) db 0 ; 填充剩下的空间,使生成的二
进制代码恰好为
; 512 字节
dw 0xaa55 ; 结束标志