;8086 alp to print BCD hex equivalent of the 8-bit value in AL.
;this means suppose AL has 3Eh, then 3E is displayed on the console. (showb)
;suppose AX has 1A3Bh, then 1A3B is displayed on console. (showw)

;al and ax are inputs for showb and showw resp.
;only flags go to dogs


assume cs:code


code segment
start:

public showb
public showw


showb proc near
push cx
push si
push ax
push dx

 mov ah,al
 and ah,0Fh  ;00001111b

 shr al,1
 shr al,1
 shr al,1
 shr al,1

 ;by now, both AH and AL are between 00h and 0Fh
 push ax

 cmp al,10d
 jae lblletter   ;unsigned comparison

 add al,48d
 jmp lbldo
 
 lblletter:
 add al,55d
 
 lbldo:
 mov dl,al
 mov ah,06h
 int 21h

 ;repeat (to show lower nibble of the original number)

 ;put back from save since ah was destroyed
 pop ax

 cmp ah,10d
 jae lblletter2

 add ah,48d
 jmp lbldo2 

 lblletter2:
 add ah,55d

 lbldo2: 
 mov dl,ah
 mov ah,06h
 int 21h

;put a space
 mov dl,' '
 mov ah,06h
 int 21h



 pop dx
 pop ax
 pop si
 pop cx
ret
showb endp







showw proc
xchg ah,al
call showb
xchg ah,al
call showb
;putting an extra space here involves again saving dl and ah which is not worth it.
ret
showw endp

code ends
end start

