汇编---十进制到十六进制的转换

stacker segment stack
dw 400 dup(?)
top label word
stacker ends

code segment
assume cs:code,ss:stacker

main proc near
call decibin
call crlf
call binihex
call crlf
mov ah,4ch
int 21h
main endp

decibin proc near
push ax
push cx
push dx
mov bx,0
L1:
mov ah,01h
int 21h
sub al,30h
cmp al,0d
jb exit
cmp al,9d
ja exit
xor ah,ah
xchg ax,bx
mov cx,10
mul cx
xchg bx,ax
add bx,ax
jmp L1
exit:
pop dx
pop cx
pop ax
ret
decibin endp

binihex proc near
push ax
push bx
push cx
push dx
mov ch,4d
L2:
mov cl,4d
rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jbe print
add al,7h
print:
mov dl,al
mov ah,02h
int 21h
dec ch
jnz L2
pop dx
pop cx
pop bx
pop ax
ret
binihex endp

crlf proc near
push ax
push dx
mov dl,0dh
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
pop dx
pop ax
ret
crlf endp

code ends
end main

你可能感兴趣的:(MASM--汇编)