.model small

.code

                  public write_hex

                  ;ON ENTRY DL CONTAINS THE HEX BYTE TO BE WRITTEN

                  ;USES write_hex_digit PROCEDURE

write_hex         proc 

                  ; does the masking of dl; first higher order then lower

                  ; order     

                  push dx

                  shr dl,4

                  and dl,0fh

                  call write_hex_digit

                  pop dx

                  push dx

                  and dl,0fh

                  call write_hex_digit

                  pop dx

                  ret

write_hex         endp

 

                  public write_hex_digit

                  ;ON ENTRY LOWER NIBBLE OF DL CONTAINS NUMBER TO BE PRINTED

                  ; IN HEX

                  ;USES write_char PROCEDURE

write_hex_digit   proc 

                  ; does the convertion of contents of dl into hex ascii char

                  push dx

                  add dl,"0"

                  cmp dl,"9"

                  jbe less

                  add dl,07h

less :            call write_char

                  pop dx

                  ret

write_hex_digit   endp

 

                  public write_char

                  extrn cursor_right:proc

write_char        proc

                  ; just calls the DOS function call for printing the

                  ; char in dl

                  push ax

                  push bx

                  push cx

                  push dx

                  mov ah,9

                  mov bh,0

                  mov cx,1

                  mov al,dl

                  mov bl,7

                  int 10h

                  call cursor_right

                  pop dx

                  pop cx

                  pop bx

                  pop ax

                  ret

write_char        endp

 

                  public write_decimal

                  ;ON ENTRY DX CONTAINS NUMBER TO BE PRINTED IN DECIMAL

                  ;USED write_hex PROCEDURE

write_decimal     proc 

                  push dx

                  push ax

                  push cx

                  push si

                  mov ax,dx

                  mov si,10d

                  xor cx,cx

non_zero :        xor dx,dx

                  div si

                  push dx

                  inc cx

                  or ax,ax

                  jne non_zero

write_digit_loop: pop dx

                  call write_hex_digit

                  loop write_digit_loop

decimal_end:      pop si

                  pop cx

                  pop ax

                  pop dx

                  ret

write_decimal     endp

 

                  public write_char_n_times

                  ;on entry dl contains the char to be printed

                  ;cx contains number of times it is to be  printed

write_char_n_times proc

                  push cx

n_times :         call write_char

                  loop n_times

                  pop cx

                  ret

write_char_n_times endp

 

                  public write_pattern

                  ;on entry ds:dx contains the address of the  pattern

                  ;to draw

write_pattern proc

                  push ax

                  push cx

                  push dx

                  push si

                  pushf

                  cld

                  mov si,dx

pattern_loop:     lodsb

                  or al,al

                  jz end_pattern

                  mov dl,al

                  lodsb

                  mov cl,al

                  xor ch,ch

                  call write_char_n_times

                  jmp pattern_loop

end_pattern:      popf

                  pop si

                  pop dx

                  pop cx

                  pop ax

                  ret

write_pattern endp

 

                public write_string

write_string proc

                push ax

                push dx

                push si

                pushf

                cld

                mov si,dx

string_loop:    lodsb

                or al,al

                jz end_of_string

                mov dl,dl

                call write_char

                jmp string_loop

end_of_string:  popf

                pop si

                pop dx

                pop ax

                ret

write_string endp

 

                end