怎样将4位16进制数转换成10进制数?如果可以的话请用汇编语言实现?谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/29 05:51:46

思路:先将键盘接收的16进制数转换为2进制,然后由2进制转换为10进制
提示:键盘接收时可接收0-ffffh之间的任意数且可循环转换,比如要将12H转换为十进制,只需输入12然后回车即可,其它数同上,当然也包括你说的指定的四位16进制数
code segment
main proc far
assume cs:code
start:
call hexibin ;16-2
call crlf ;换行

call binidec ;2-10
call crlf

jmp main ;get next input
ret
main endp

hexibin proc near
mov bx,0 ;clear BX for number
newchar:
mov ah,01h ;keyboard input
int 21h ;call DOS
sub al,30h ;ASCII to binary
jl exit ;jump if<0
cmp al,10d ;is it > 9d
jl add_to ;yes,so it's digit

;not digit(0-9),may be letter(a to f)
sub al,27h ;convert ASCII to binary
cmp al,0ah ;is it <0a hex?
jl exit ;yes,not letter
cmp al,10h ;is it > 0f hex?
jge exit ;yes,not letter
;is hex digit,add to number in BX
add_to:
mov cl,4
shl bx,