; multi-segment executable file template.
data segment
; add your data here!num dw0string1 db'please choose 1 (dec->hex) or 2 (hex->dec)]:$'inputDec db'please input a Dec number :$'inputHex db'please input a Hex number :$'ends
stack segment
dw128 dup(0)
ends
code segment
start:
;setsegment registers:
mov ax, data
mov ds, ax
mov es, ax
;-------------选择模式------------------model:
lea dx, string1
mov ah,9
int21h
mov ah,1
int21h
sub al,30h
cmp al,1mov cx,10;乘10
jz option1
call CRLF
cmp al,2mov cx,16jz option2
call CRLF
jmp model
;----------------------------------------;***********十进制转十六进制*****************;-----------输入一个十进制数-------------option1:
call CRLF
lea dx,inputDec
mov ah,9
int21h
rotate1:
mov ah,1
int21h
cmp al,0dh ;回车结束十进制数的输入
jz DectoHex
sub al,30h
cbw
push ax
mov ax,bx
mul cx
mov bx,ax
pop ax
add bx,ax ;输入结果保存在bx中
jmp rotate1
;-----------------------------------------;---------开始转换(10->16)-------------DectoHex:
call CRLF
mov ch,4rotatecur:
mov cl,4rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl print1
add al,7h
print1:
mov dl,al
mov ah,2
int21h
dec ch
jnz rotatecur
call exit
;**************十六进制转十进制*******************;-------------输入一个十六进制数------------------option2:
call CRLF
lea dx,inputHex
mov ah,9
int21h
rotate2:
mov ah,1
int21h
cmp al,0dh ;回车结束十六进制数的输入
jz HextoDec
sub al,30h
cmp al,9jg Other
L:
cbw
push ax
mov ax,num
mul cx
mov num,ax
pop ax
add num,ax ; 输入结果保存在num中
jmp rotate2
Other:
sub al,7h
jmp L
HextoDec:
call CRLF
mov cx,1000;----------重复的输出代码。。。-----mov ax, num
mov dx,0div cx
mov num, dx
mov dl, al
add dl,30h
mov ah,02hint21h
;--------------------mov cx,100;----------mov ax, num
mov dx,0div cx
mov num, dx
mov dl, al
add dl,30h
mov ah,02hint21h
;----------mov cx,10;----------mov ax, num
mov dx,0div cx
mov num, dx
mov dl, al
add dl,30h
mov ah,02hint21h
;----------mov cx,1;----------mov ax, num
mov dx,0div cx
mov num, dx
mov dl, al
add dl,30h
mov ah,02hint21h
;----------call exit
;----------取每一位------------------;-----------------------------------;--------回车换行------------------CRLF proc near
push ax
push dx
pushf
mov dl,0dh;回车
mov ah,2
int21h
mov dl,0ah;换行
mov ah,2
int21h
popf
pop dx
pop ax
ret
CRLF endp
;-----------------------------------------;-----------------退出---------------------exit proc
mov ax, 4c00h ; exit to operating system.int21h
exit endp
;------------------------------------------ends
end start ;set entry point and stop the assembler.