assume cs:code
code segment
mov ax,0ffffH
mov bx,ax
mov dx,0
mov cx,3
s: shl dx,1
shl ax,1
adc dx,0
loop s
add bx,bx
adc dx,0
add ax,bx
adc dx,0
mov ax,4c00H
int 21H
code ends
end
ax*10=ax+ax+ax+ax+ax+ax+ax+ax+ax+ax=ax*2+ax*2+ax*2+ax*2+ax*2
ax*10=[(ax*2+ax*2)+(ax*2+ax*2)]+ax*2
shl ax,1 就是ax+ax
在用 shl ax,1 就是ax+ax+ax+ax
在用 shl ax,1 就是ax+ax+ax+ax+ax+ax+ax+ax
在用 shl ax,1 就是16个ax相加
所以只能连续用3次 shl ax,1
如果写成: mov cl,3
shl ax,cl
也就是连续3位移,不过要是数据大的话就要丢掉前两位 第3位在cf中,所以着样是错的。
换一种思考方法 ax和dx都是 16 bit ,ax和dx可一看成一个32 bit的寄存器,
比如 sh1 ax,1 要是cf=1的话可以用 adc dx,0来实现 高位位移到了dx 中
程序可写成
mov cx,3
s: shl dx,1
shl ax,1
adc dx,0
loop s
呵呵 后面的我就不用说了吧!
::我也是刚学到着一章,不知道大家怎么写的,希望大家发表自己的看法。 |