data segment
data ends
code segment
assume ds:data,cs:code
start: mov al,0ffh
mov cx,8
again: shl al,1
jnc disp_0
jc disp_1
disp_1: mov dl,31h
mov ah,2
int 21h
dec cx
cmp cx,0
jz done
jnz again
disp_0: mov dl,30h
mov ah,2
int 21h
dec cx
cmp cx,0
jz done
jnz again
done: mov ax,4c00h
int 21h
code ends
end start
该程序的目的是吧al中所存储的二进制数输出,为什么输出的结果总是不对呢?高手指点
------解决方案--------------------------------------------------------
那是因为你程序中
disp_1: mov dl,31h
mov ah,2
int 21h
和
disp_0: mov dl,30h
mov ah,2
int 21h
改变了al的值
下面这样写就可以了:
- Assembly code
data segment n db ?data endscode segmentassume ds:data,cs:codestart: mov al,0ffh mov n, al mov cx,8 again: shl n,1 jnc disp_0 jc disp_1disp_1: mov dl,31h mov ah,2 int 21h dec cx cmp cx,0 jz done jnz againdisp_0: mov dl,30h mov ah,2 int 21h dec cx cmp cx,0 jz done jnz againdone: mov ax,4c00hint 21hcode ends end start