汇编语言(王爽)14章端口读写和移位指令shlshr

端口读写 in out

assume cs:code
code segment
	start:  
		mov al,2
		out 70h,al
		;//out 70h,2		;//must be acuumulator register
		in al,71h
		mov al,0
		out 71h,al
		mov al,0eeh
		in al,71h
		
		mov ax,4c00h
		int 21h

code ends
end start

使用加法和移位指令计算(ax)=(ax)*10

(ax)*10=(ax)*8+(ax)*2,需要考虑进位,把进位部分保存在dx。
mov cl,3;shl bx,cl可以左移3位,即乘以8,
但是一次性左移3位可能出现多次进位的情况,此时cf=1,无法判断进位了几次,
所以每次移动一位。

assume cs:code,ss:stack
stack segment
	db 8 dup(0)
stack ends
code segment
	start:  
		mov ax,stack
		mov ss,ax
		push cx
		mov sp,0
		mov dx,0
		mov cx,3	
		mov ax,3eeeh		;61166*2=9554cH
		
	loop1:
		;sub ax,0		;//设置cf=0,这里不需要设置
		shl dx,1	
		shl ax,1
		jnc s1
		inc dx
	s1:	
		cmp cx,3
		jnz s2		;//==jne s2
		push dx
		push ax
	s2:
		loop loop1
		pop cx
		add ax,cx
		jnc s3		
		inc dx
	s3:
		pop cx
		add dx,cx
		
		pop cx
		mov ax,4c00h
		int 21h

code ends
end start
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值