从键盘上接收二进制数并转换为十六进制数显示
为什么我改成16位后结果就是错的?
应该怎么改?
data segment
num db 8 dup(0)
data ends
code segment
main proc far
assume cs:code,ds:data
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
lea si,num
mov cx,7
loopa:
cmp cx,0
jl next1
mov ah,1
int 21h
cmp al,30h
jb loopa
cmp al,31h
ja loopa
and al,0fh
shl al,cl
mov [si],al
inc si
dec cx
jmp loopa
next1:
mov si,offset num
mov bl,[si]
add bl,[si+1]
add bl,[si+2]
add bl,[si+3]
add bl,[si+4]
add bl,[si+5]
add bl,[si+6]
add bl,[si+7]
MOV dl, 0dh
MOV ah, 02h
int 21h
MOV dl, 0ah
MOV ah, 02
int 21h
mov ch,2
rotate: mov cl,4
rol bl,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl printit
add al,7h
printit:
mov dl,al
mov ah,2
int 21h
dec ch
jnz rotate
ret
main endp
code ends
end start
修改后 :
data segment
num db 16 dup(0) ;这修改了
data ends
code segment
main proc far
assume cs:code,ds:data
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
lea si,num
mov cx,15;这修改了
loopa:
cmp cx0
jl next1
mov ah,1
int 21h
cmp al,30h
jb loopa
cmp al,31h
ja loopa
and al,0fh
shl al,cl
mov [si],al
inc si
dec cx
jmp loopa
next1: mov si,offset num
mov bx,[si]
add bx,[si+1]
add bx,[si+2]
add bx,[si+3]
add bx,[si+4]
add bx,[si+5]
add bx,[si+6]
add bx,[si+7]
add bx,[si+8] ;这往下修改了
add bx,[si+9]
add bx,[si+10]
add bx,[si+11]
add bx,[si+12]
add bx,[si+13]
add bx,[si+14]
add bx,[si+15]
mov dl, 0dh
mov ah, 02h
int 21h
mov dl, 0ah
mov ah, 02
int 21h
mov cl,4 ;这修改了
mov ch,4
rotate: rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl printit
add al,7h
printit:
mov dl,al
mov ah,2
int 21h
dec ch
ja rotate
MOV DL,'H'
MOV AH,2
INT 21H
ret
main endp
code ends
end start
那出问题了?