home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Assembly / VIDEO_14.ASM < prev    next >
Assembly Source File  |  1986-09-23  |  3KB  |  111 lines

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