如题,本人是初学汇编的小小菜,找到了一个四位十六进制转二进制的汇编源代码,想改成八位十六进制转二进制的,不晓得怎么弄,请求达人帮帮忙,帮忙改下代码,谢谢了.
这是四位十六进制转二进制的代码,望达人帮忙.
;;数据段
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