mov ax,bx ;the paramenter is in bx
push ax
mov cx,1h ;set 1 into cx
xor ax,ax
mov dx,ax ;set result into dx
repeat: pop ax ;get ax
mov bl,10d ;set 10d to bl
div bl ;ax div bl
mov bl,ah ;save the remainder in bl
xor ah,ah ;set ah to 00h
cbw ;change al(quotient) to type word
push ax ;push the quotient into stack
mov al,bl ;save the remainder back to al
cbw ;change it to word
mul cx ;mul cx
mov bx,dx ;add it to old remainder
add ax,bx ;
mov dx,ax ;
pop ax ; pop the quotient from stack
cmp ax,0d ;compare with zero
je exit2 ; if equ then exit
push ax ;else save it back to the stack
mov ax,cx ;make cx mul by 10h
mov cx,10h
mul cx
mov cx,ax
晕!
data segment
temp dw ?
data ends
decihex segment
assume cs:decihex,ds:data
main proc far
loop1:
call decibin
mov temp ,bx
call decibin
mov ax,temp
add ax,bx
mov bx,ax
call hexibin
call crlf
call binihex
call crlf
jmp loop1
main endp
hexibin proc near
mov ax,bx 'the paramenter is in bx
push ax
mov cx,1h 'set 1 into cx
xor ax,ax
mov dx,ax 'set result into dx
repeat: pop ax 'get ax
mov bl,10d 'set 10d to bl
div bl 'ax div bl
mov bl,ah 'save the remainder in bl
xor ah,ah 'set ah to 00h
cbw 'change al(quotient) to type word
push ax 'push the quotient into stack
mov al,bl 'save the remainder back to al
cbw 'change it to word
mul cx 'mul cx
mov bx,dx 'add it to old remainder
add ax,bx '
mov dx,ax '
pop ax ' pop the quotient from stack
cmp ax,0d 'compare with zero
je exit2 ' if equ then exit
push ax 'else save it back to the stack
mov ax,cx ' make cx mul by 10h
mov cx,10h
mul cx
mov cx,ax
jmp repeat
exit2:
mov bx,dx
ret
hexibin endp
binihex proc near
mov ch,4
rotate: mov cl,4
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
jnz rotate
ret
binihex endp
decibin proc near
mov bx,0
newchar:
mov ah,1
int 21h
sub al,30h
jl exit
cmp al,9d
jg exit
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar
exit:
ret
decibin endp
crlf proc near
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
ret
crlf endp