کد:
;this program convert N to base in 4 and 8 and 16
; by computer.parsx.com
.model small
CR macro
mov ah,2
mov dl,10;cr
int 21h
mov dl,13;lf
int 21h
endm
.stack 64 ;byte
.data
n db 20
text4 db '4 base:$'
text8 db '8 base:$'
text16 db '16 base:$'
.code
start:
mov ax,@data
mov ds,ax
lea dx,text4
mov ah,9
int 21h
call proc4 ; decode to 4th base
cr
lea dx,text8
mov ah,9
int 21h
call proc8 ; decode to octal
cr
lea dx,text16
mov ah,9
int 21h
call proc16; decode to hex
mov ah,4ch
int 21h
proc4 proc near
mov cl,8
parsx4:
mov ah,n
sub cl,2
shr ah,cl
and ah,3
add ah,'0'
mov dl,ah
mov ah,2
int 21h
cmp cl,0
jne parsx4
ret
proc4 endp
proc8 proc
mov cl,9
parsx8:
mov ah,n
sub cl,3
shr ah,cl
and ah,7
add ah,'0'
mov dl,ah
mov ah,2
int 21h
cmp cl,0
jne parsx8
ret
proc8 endp
proc16 proc
mov cl,16
parsx16:
mov ah,n
sub cl,4
shr ah,cl
and ah,7
cmp ah,9
jb hexa
sub ah,10
hexa:
add ah,'0'
mov dl,ah
mov ah,2
int 21h
cmp cl,0
jne parsx16
ret
proc16 endp
end start;