八位十六进制转二进制数的汇编源代码

如题,本人是初学汇编的小小菜,找到了一个四位十六进制转二进制的汇编源代码,想改成八位十六进制转二进制的,不晓得怎么弄,请求达人帮帮忙,帮忙改下代码,谢谢了.
这是四位十六进制转二进制的代码,望达人帮忙.
;;数据段
data segment
inData dw ?
inputInfo db 'Please input a hex of 4 bits: $'
errorInfo db 'Input error, please repeat$'
resultInfo db 'The result is : $'
newlineInfo db 0dh, 0ah, '$'
data ends

;;代码段
code segment

main proc far
assume cs:code, ds:data

start:
;;set up for return
push ds
xor ax, ax
push ax

;;set ds register to current data segment
mov ax, data
mov ds, ax

call InputData ;;input data

call ToBin ;;turn to bin and show the result

ret
main endp

;;输入四位的十六进制数,并转换为十进制保存在inData里
;;输入参数:
;;输出参数:inData
InputData proc near

push dx
push ax
push cx
push bx

input: ;;output message and input data
mov cx, 5
xor ax, ax
mov [inData], ax

;;show the infomation of input
lea dx, inputInfo
mov ah, 09h
int 21h

inputLoop: ;;input the data
mov ah, 01h
int 21h

cmp al,'0'
jl showErr
cmp al, 'G'
jnl showErr

cmp al, ':'
jl sub1
cmp al, 'A'
jnl sub2

jmp showErr

sub1: ;;将0-9之间的字符转化为数值
sub al, 30h
jmp mul16

sub2: ;;将A-F之间的字符转化为数值
add al, 10
sub al, 41h
jmp mul16

mul16: ;;将inData的值乘以16
mov bx, 0
mov bl, al
mov al, cl
mov cl, 4
shl [inData], cl ;;相当于将inData的值乘以16
add [inData], bx
mov cl, al

sub cx, 1
cmp cx, 1
jz exit

jmp inputLoop

showErr: ;;show the error message
call NewLine
lea dx, errorInfo
mov ah, 09h
int 21h

call NewLine
call NewLine

jmp input

exit:
pop bx
pop cx
pop ax
pop dx
ret
InputData endp

;;把一个十进制的整数转化为十六位的二进制数输出
;;输入参数:inData
ToBin proc near
push dx
push ax
push cx

call NewLine
call NewLine

lea dx, resultInfo ;;output the information
mov ah, 09h
int 21h

mov cx, 16 ;;the times of loop

next: ;;循环显示'0'或'1'
sub cx, 1
cmp cx, 0
jl exit2

shl [inData], 1
jc show1

mov dl, '0'
mov ah, 02h
int 21h
jmp next

show1: ;;显示字符'1'
mov dl, '1'
mov ah, 02h
int 21h
jmp next

exit2:
pop cx
pop ax
pop dx
ret
ToBin endp

;;start with a new line
NewLine proc near
push dx
push ax

lea dx, newlineInfo
mov ah, 09h
int 21h

pop ax
pop dx
ret
NewLine endp

code ends

end main

;-------------------------------------------------
;可转换16位以内任意无符号数(1或8 或4 或n n<=16)
;或者修改data段 可转换更多位
;Esc键退出 回车键后就开始转换转换
;-------------------------------------------------

data segment
assume ds:data
indata db 16 dup(20h)
inputinfo db 'Please input one hex=<16 bits: $'
errorinfo db 'Input error, please repeat$'
resultinfo db 'The result is : $'
newlineinfo db 0dh, 0ah, '$'
data ends
;-------------------------------------------------
;-------------------------------------------------

code segment
assume cs:code

main proc far
mov ax,data
mov ds,ax
mov es,ax

call inputdata
call hextobin

mov ah,4ch
int 21h
main endp
;--------------------------------------
;--------------------------------------

hextobin proc near
mov ah,9
mov dx,offset resultinfo
int 21h

mov si,offset indata

next:
lodsb
mov bl,al ;先备份al,因后面sub*会改变al

cmp al,20h
jz exit

cmp al,3ah ;分号
jl sub1
cmp al,47h ;G
jl sub2
cmp al,67h ;g
jl sub3

sub1:
sub al,30h ;判断0--9
jmp begin

sub2:
mov al,bl
sub al,37h ;判断A--F
jmp begin

sub3:
mov al,bl
sub al,57h ;判断a--f
jmp begin

begin:
mov cx,4 ;每4位二进制即可表示1位十六进制
mov ah,2 ;依次检验al中的低四位的0和1是循环的目的所在
mov bl,al
mov bh,8 ;8h=1000b

show:
mov dl,30h
and al,bh ;and xxxx,1000 可得 al=x000
jz tobin ;即保留了al中的最高位
mov dl,31h ;

tobin:
int 21h
mov al,bl ;恢复al
ror bh,1 ;1000b循环右移1位 变成0100b
loop show
mov ah,0
jmp next
exit:ret

hextobin endp
;---------------------------------------
;---------------------------------------

inputdata proc near

input:
mov ah,9
mov dx,offset inputinfo
int 21h

mov di,offset indata

inchar:
mov ah,1
int 21h
push ax

cmp al,1bh ;如果是Esc键,则退出
je quit
cmp al,0dh ;如果是回车,表示结束输入,则跳去转换
je hex

cmp al,67h ;三个条件区间
jnl showerr
cmp al,61h
jnl start
cmp al,47h
jnl showerr
cmp al,41h
jnl start
cmp al,3ah
jnl showerr
cmp al,30h
jnl start

start:
pop ax
mov ah,0
stosb
jmp inchar

quit:
mov ah,4ch
int 21h

hex: call newline
call hextobin
ret

showerr:
call newline
call newline
mov ah,9
mov dx,offset errorinfo
int 21h
call newline
call newline
jmp input

inputdata endp
;----------------------------------------
;----------------------------------------

newline proc near
mov dx,offset newlineinfo
mov ah,9
int 21h
ret
newline endp
;----------------------------------------
;----------------------------------------

code ends
end main
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-01-10
八位16进制怎么表示数啊,有FFFFFFFF吗?