.model small
.stack 100h
.data
MsgInput db "Input number: $"
MsgOutput db 10, 13, "Result: $"
Base1 dw 10 ; Input base
Base2 dw 7 ; Output base
.code
start:
mov ax, @data
mov ds, ax
lea dx, MsgInput
mov ah, 09h
int 21h
input: mov ah, 00h
int 16h
cmp al, 0Dh
je a0
cmp al, '0'
jl input
cmp al, '9'
jle ii
cmp al, 'A'
jl input
cmp al, 'F'
jg input
ii: mov dl, al
mov ah, 02h
int 21h
sub al, 30h
xor ah, ah
xchg ax, bx
mov dx, Base1
mul dx
add bx, ax
jmp input
a0: lea dx, MsgOutput
mov ah, 09h
int 21h
xor cx, cx
mov ax, bx
mov dx, Base2
a1: xor bx, bx
a2: cmp ax, dx
jb a3
sub ax, dx
inc bx
jmp a2
a3: add ax, '0'
cmp ax, ':'
jb a4
add ax, 'A' - ':'
a4: push ax
inc cx
xchg ax, bx
cmp ax, 0
jne a1
output: pop dx
mov ah, 02h
int 21h
loop output
exit: mov ah, 00h
int 16h
mov ah, 4ch
int 21h
end start