当前位置: 代码迷 >> 汇编语言 >> 将寄存器al中二进制数输出有关问题,请指点
  详细解决方案

将寄存器al中二进制数输出有关问题,请指点

热度:5765   发布时间:2013-02-26 00:00:00.0
将寄存器al中二进制数输出问题,请指点
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
  相关解决方案