; program to print 16 bit numerical values in hexadecimal .model small .386 .stack 100h .data ; ascii values of hex digits 0-F asciis db 48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70 buffer db 64 dup(0) ; not used endl db 13,10,'$' .code mymain proc start: mov ax,@data mov ds,ax ; assume value to be printed is in cx mov cx,111 ; sample value call printhex mov cx,0abcdh call printhex mov ax,4c00h int 21h mymain endp ;printhex proc printhex: push ax ; save registers push bx push dx mov dx,cx shr dx,12 ; first 4 bits now can be used as offset mov bx,offset asciis add bx,dx mov dl,[bx] mov ah,2 int 21h ; print the first char mov dx,cx and dx,0F00h ; mask out other 12 bits before shift shr dx,8 mov bx,offset asciis add bx,dx mov dl,[bx] int 21h ; print second char mov dx,cx and dx,00F0h shr dx,4 mov bx,offset asciis add bx,dx mov dl,[bx] int 21h ; print the third char mov dx,cx and dx,000Fh mov bx,offset asciis add bx,dx mov dl,[bx] int 21h ; print the last char mov dx,offset endl ; print "\n" mov ah,9 int 21h pop dx ; restore registers and return pop bx pop ax ret ;printhex endp end