这道题的大概思路是:输入一个字符串(由0和1组成),然后根据为0还是为1,通过循环移位将寄存器DX中的各位变成相应的0或1,再将DX右移4位,最后根据DX中各位的情况转换成一个字符串输出。现在程序有错,我实在找不出来,恳请高人相助,谢谢!
data segment
buf db 18
db ?
db 16 dup(?)
crlf db 13,10,'$'
b db 16 dup(?)
db '$'
message db 'input 16 bits binary numbers:$'
data ends
code segment
assume cs:code,ds:data
begin: mov ax,data
mov ds,ax
lea dx,message
mov ah,9
int 21h
mov ah,10
lea dx,buf
int 21h
lea dx,crlf
mov ah,9
int 21h
mov cl,buf+1
lea si,buf+2
next: mov dl,[si]
mov ah,2
int 21h
inc si
dec cl
jne next
lea si,buf+2
mov dx,0
mov cx,16
clc
l1: cmp [si],30h
je next2
stc
next2: rcl dx,1
inc si
dec cx
jne l1
mov cl,4
shr dx,cl
lea si,b
mov cx,16
l2: shl dx,1
jnb next3
mov [si],31h
jmp next4
next3: mov [si],30h
next4: inc si
dec cx
jne l2
mov dl,13
int 21h
mov dl,10
int 21h
lea dx,b
mov ah,9
int 21h
mov ah,4ch
int 21h
code ends
end begin