home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / nor_asm / video_10.asm < prev    next >
Assembly Source File  |  1989-05-01  |  3KB  |  109 lines

  1. .MODEL    SMALL
  2. .CODE
  3.  
  4. TEST_WRITE_DECIMAL    PROC
  5.     MOV    DX,12345
  6.     CALL    WRITE_DECIMAL
  7.     INT    20h            ;Return to DOS
  8. TEST_WRITE_DECIMAL    ENDP
  9.  
  10.     PUBLIC    WRITE_HEX
  11. ;-----------------------------------------------------------------------;
  12. ; This procedure converts the byte in the DL register to hex and writes    ;
  13. ; the two hex digits at the current cursor position.            ;
  14. ;                                    ;
  15. ; On entry:    DL    Byte to convert to hex.                ;
  16. ;                                    ;
  17. ; Uses:        WRITE_HEX_DIGIT                        ;
  18. ;-----------------------------------------------------------------------;
  19. WRITE_HEX    PROC            ;Entry point
  20.     PUSH    CX            ;Save registers used in this procedure
  21.     PUSH    DX
  22.     MOV    DH,DL            ;Make a copy of byte
  23.     MOV    CX,4            ;Get the upper nibble in DL
  24.     SHR    DL,CL
  25.     CALL    WRITE_HEX_DIGIT        ;Display first hex digit
  26.     MOV    DL,DH            ;Get lower nibble into DL
  27.     AND    DL,0Fh            ;Remove the upper nibble
  28.     CALL    WRITE_HEX_DIGIT        ;Display second hex digit
  29.     POP    DX
  30.     POP    CX
  31.     RET
  32. WRITE_HEX    ENDP
  33.  
  34.     PUBLIC    WRITE_HEX_DIGIT
  35. ;-----------------------------------------------------------------------;
  36. ; This procedure converts the lower 4 bits of DL to a hex digit and    ;
  37. ; writes it to the screen.                        ;
  38. ;                                    ;
  39. ; On entry:    DL    Lower 4 bits contain number to be printed    ;
  40. ;            in hex.                        ;
  41. ;                                    ;
  42. ; Uses:        WRITE_CHAR                        ;
  43. ;-----------------------------------------------------------------------;
  44. WRITE_HEX_DIGIT        PROC
  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 DX
  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. ; On entry:    DL    Byte to print on screen.            ;
  64. ;-----------------------------------------------------------------------;
  65. WRITE_CHAR    PROC
  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.     PUBLIC    WRITE_DECIMAL
  74. ;-----------------------------------------------------------------------;
  75. ; This procedure writes a 16-bit, unsigned number in decimal notation.    ;
  76. ;                                    ;
  77. ; On entry:    DX    N : 16-bit, unsigned number.            ;
  78. ;                                    ;
  79. ; Uses:        WRITE_HEX_DIGIT                        ;
  80. ;-----------------------------------------------------------------------;
  81. WRITE_DECIMAL    PROC
  82.     PUSH    AX            ;Save registers used here
  83.     PUSH    CX
  84.     PUSH    DX
  85.     PUSH    SI
  86.     MOV    AX,DX
  87.     MOV    SI,10            ;Will divide by 10 using SI
  88.     XOR    CX,CX            ;Count of digits placed on stack
  89. NON_ZERO:
  90.     XOR    DX,DX            ;Set upper word of N to 0
  91.     DIV    SI            ;Calculate N/10 and (N mod 10)
  92.     PUSH    DX            ;Push one digit onto the stack
  93.     INC    CX            ;One more digit added
  94.     OR    AX,AX            ;N = 0 yet?
  95.     JNE    NON_ZERO        ;Nope, continue
  96. WRITE_DIGIT_LOOP:
  97.     POP    DX            ;Get the digits in reverse order
  98.     CALL    WRITE_HEX_DIGIT
  99.     LOOP    WRITE_DIGIT_LOOP
  100. END_DECIMAL:
  101.     POP    SI
  102.     POP    DX
  103.     POP    CX
  104.     POP    AX
  105.     RET
  106. WRITE_DECIMAL    ENDP
  107.  
  108.     END    TEST_WRITE_DECIMAL
  109.