;从键盘上输入4位十六进制数,将其转换为16位二进制数并在显示器上显示出来。
DATAS SEGMENT
notice db 'Please input chars:$'
arr db 7
arrlength db ?
arrchars db 4 dup(?)   
DATAS ENDS
STACKS SEGMENT
dw 256 dup(?)
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV SS,AX
;提示输入
call notices
;回车换行
call hh
;开始输入
call input
CALL COMPARES
;转成计算机中的16进制
call change
;回车换行
call hh
;显示
CALL DISPBXB
;返回dos
EXIT:
MOV AH,4CH
INT 21H
notices proc
mov dx,offset notice
mov ah,9
int 21h
ret
notices endp
input proc
mov dx,offset arr
mov ah,10
int 21h
ret
input endp
COMPARES PROC
mov si,0
mov cl,arrlength
CMP arrchars[si],30H
JL  EXIT
CMP arrchars[si],3AH;是数字
JL LOP1
CMP arrchars[si],41H
JL EXIT
CMP arrchars[si],47H;是大写
JL LOP2
CMP arrchars[si],61H
JL EXIT
CMP arrchars[si],67H;是小写
JL LOP3
CMP arrchars[si],67H
JG EXIT
lop1:
sub arrchars[si],30h
inc si
dec cl
万能在线进制转换器转换器网
jnz lop1
lop2:
sub arrchars[si],37h
inc si
dec cl
jnz lop2
lop3:
sub arrchars[si],57h
inc si
dec cl
jnz lop3
RET
COMPARES ENDP
change proc
mov bx,0
mov di,0
mov cl,4
mov ch,arrlength
mov ax,0
continue:
shl bx,cl
mov al,arrchars[di]
add bx,ax
inc di
dec ch
jnz continue
ret
change endp
DISPBXB PROC NEAR
;push cx
;push bx
;push dx
;push ax
MOV CX,16
LP1:
ROL BX,1
push bx
JC D1
MOV DL,30H
JMP OUTP
D1:
MOV DL,31H
OUTP:
MOV AH,2
INT 21H
pop bx
LOOP LP1
MOV DL,'B' ;显示字母“B”
MOV AH,2
INT 21H
;pop ax
;pop dx
;pop bx
;pop cx
RET
DISPBXB ENDP
hh proc
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
RET 
hh endp 
CODES ENDS
END START

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。