home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Low Level Languages / Assembly / VIDEO_9.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-09-22  |  2.3 KB  |  76 lines

  1. CODE_SEG    SEGMENT
  2.     ASSUME    CS:CODE_SEG
  3.     ORG    100h
  4.  
  5. TEST_WRITE_HEX    PROC    NEAR
  6.     MOV    DL,3Fh            ;Test with 3Fh
  7.     CALL    WRITE_HEX
  8.     INT    20h
  9. TEST_WRITE_HEX    ENDP
  10.  
  11.     PUBLIC    WRITE_HEX
  12. ;-----------------------------------------------------------------------;
  13. ; This procedure converts the byte in the DL register to hex and writes    ;
  14. ; the two hex digits at the current cursor position.            ;
  15. ;                                    ;
  16. ;    DL    Byte to be converted to hex.                ;
  17. ;                                    ;
  18. ; Uses:        WRITE_HEX_DIGIT                        ;
  19. ;-----------------------------------------------------------------------;
  20. WRITE_HEX    PROC    NEAR        ;Entry point
  21.     PUSH    CX            ;Save registers used in this procedure
  22.     PUSH    DX
  23.     MOV    DH,DL            ;Make a copy of byte
  24.     MOV    CX,4            ;Get the upper nibble in DL
  25.     SHR    DL,CL
  26.     CALL    WRITE_HEX_DIGIT        ;Display first hex digit
  27.     MOV    DL,DH            ;Get lower nibble into DL
  28.     AND    DL,0Fh            ;Remove the upper nibble
  29.     CALL    WRITE_HEX_DIGIT        ;Display second hex digit
  30.     POP    DX
  31.     POP    CX
  32.     RET
  33. WRITE_HEX    ENDP
  34.  
  35.     PUBLIC    WRITE_HEX_DIGIT
  36. ;-----------------------------------------------------------------------;
  37. ; This procedure converts the lower 4 bits of DL to a hex digit and    ;
  38. ; writes it to the screen.                        ;
  39. ;                                    ;
  40. ;    DL    Lower 4 bits contain number to be printed in hex.    ;
  41. ;                                    ;
  42. ; Uses:        WRITE_CHAR                        ;
  43. ;-----------------------------------------------------------------------;
  44. WRITE_HEX_DIGIT        PROC    NEAR
  45.     PUSH    DX            ;Save registers used
  46.     CMP    DL,10            ;Is this nibble <10?
  47.     JAE    HEX_LETTER        ;No, convert to a letter
  48.     ADD    DL,"0"            ;Yes, convert to a digit
  49.     JMP    Short WRITE_DIGIT    ;Now write this character
  50. HEX_LETTER:
  51.     ADD    DL,"A"-10        ;Convert to hex letter
  52. WRITE_DIGIT:
  53.     CALL    WRITE_CHAR        ;Display the letter on the screen
  54.     POP    DX            ;Restore old value of AX
  55.     RET
  56. WRITE_HEX_DIGIT        ENDP
  57.  
  58.     PUBLIC    WRITE_CHAR
  59. ;-----------------------------------------------------------------------;
  60. ; This procedure prints a character on the screen using the DOS        ;
  61. ; function call.                            ;
  62. ;                                    ;
  63. ;    DL    Byte to print on screen.                ;
  64. ;-----------------------------------------------------------------------;
  65. WRITE_CHAR    PROC    NEAR
  66.     PUSH    AX
  67.     MOV    AH,2            ;Call for character output
  68.     INT    21h            ;Output character in DL register
  69.     POP    AX            ;Restore old value in AX
  70.     RET                ;And return
  71. WRITE_CHAR    ENDP
  72.  
  73. CODE_SEG    ENDS
  74.  
  75.     END    TEST_WRITE_HEX
  76.