home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / sampler0 / ltr.asm < prev    next >
Assembly Source File  |  1988-10-25  |  4KB  |  109 lines

  1. «RHA«VA$FI»          p. «pn» of «fp»
  2.  
  3. »«PT3»«AL1»«LM0»«RM80»
  4. ;----------------------------------------------------------------------
  5. ;  freq.asm - count the letter frequency on the command line
  6. ;  PC Magazine * PC Tutor
  7. ;----------------------------------------------------------------------
  8. CSEG    SEGMENT PARA PUBLIC 'CODE'              ;Start CODE segment
  9.         ASSUME  CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG ;Set by DOS Loader
  10.                 ORG     100H                    ;COM file format
  11.  
  12. ENTPT:          JMP     MAIN
  13.  
  14. CR              EQU     0DH
  15. LF              EQU     0AH
  16.  
  17. COPYRIGHT    DB    "FREQ 1.0 (c) Ziff Communications Co.",CR,LF
  18.         DB    "PC Magazine ",254," Robert L. Hummel",CR,LF,"$",26
  19.  
  20. USAGE$          DB      "Usage: FREQ text",CR,LF,"$"
  21.  
  22. ABC             DB      26 DUP(0)
  23.  
  24. MAIN    PROC    NEAR
  25.  
  26.         MOV    DX,OFFSET COPYRIGHT
  27.         MOV    AH,9
  28.         INT    21H
  29.  
  30.                 XOR     CH,CH            ;Zero high byte
  31.                 MOV     CL,DS:[80H]        ;Get command line length
  32.                 OR      CL,CL            ;If > 0
  33.                 JNZ     HAVE_INPUT        ; count letters
  34.  
  35.                 MOV     DX,OFFSET USAGE$    ;Address of message
  36.                 MOV     AH,9            ;Display string
  37.                 INT     21H            ; Thru DOS
  38.                 MOV     AX,4C01H        ;Terminate with error
  39.                 INT     21H            ; Thru DOS
  40. HAVE_INPUT:
  41.                 MOV     SI,81H            ;Start of command tail
  42.                 XOR     BH,BH            ;Zero high byte of index
  43. READ_CHAR:                LODSB                ;Get character in AL
  44.                 OR      AL,20H            ;Make lower case
  45.                 SUB     AL,"a"            ;Convert to number
  46.         CMP    AL,25
  47.         JA    NEXT
  48.                 MOV     BL,AL            ;Put into BL
  49.                 INC     BYTE PTR ABC[BX]    ; to use as index
  50. NEXT:
  51.                 LOOP    READ_CHAR        ;Scan entire line
  52.  
  53.                 MOV     SI,OFFSET ABC        ;Offset of table
  54.                 MOV     CX,26            ;Number of entries
  55.                 XOR     BL,BL            ;BL = 0
  56. PR_CHAR:
  57.                 MOV     AH,2                    ;Write TTY
  58.                 MOV     DL,CR                   ; carriage return
  59.                 INT     21H                     ; thru DOS
  60.  
  61.                 MOV     AH,2                    ;Write TTY
  62.                 MOV     DL,LF            ; line feed
  63.                 INT     21H                     ; thru DOS
  64.  
  65.                 MOV     DL,BL                   ;Build character in DL
  66.                 INC     BL            ; move char counter
  67.                 ADD     DL,"A"            ;Make ASCII value
  68.                 MOV     AH,2            ;Write TTY
  69.                 INT     21H            ; Thru DOS
  70.  
  71.                 MOV     AH,2            ;Write TTY
  72.                 MOV     DL,20H            ; a space
  73.                 INT     21H            ; Thru DOS
  74.  
  75.                 LODSB                           ;Get character count
  76.                 CALL    BYTE2DEC        ;Print as decimal number
  77.  
  78.                 LOOP    PR_CHAR            ;Continue for entire table
  79.  
  80.                 MOV     AX,4C00H                ;Terminate program
  81.                 INT     21H                     ;Thru DOS
  82. MAIN    ENDP
  83.  
  84. ;======================================================================
  85. ; binary to decimal conversion.  arguments 0 - 99 in AL
  86. ; Destroys AX, DL
  87. ;----------------------------------------------------------------------
  88. BYTE2DEC        PROC    NEAR
  89.  
  90.                 XOR     AH,AH
  91.                 AAM
  92.                 OR      AX,"00"         ;Make them ascii
  93.                 PUSH    AX
  94.                 MOV     DL,AH                   ; carriage return
  95.                 MOV     AH,2                    ;Write TTY
  96.                 INT     21H                     ; thru DOS
  97.                 POP     AX
  98.                 MOV     DL,AL
  99.                 MOV     AH,2
  100.                 INT     21H
  101.                 RET
  102.  
  103. BYTE2DEC        ENDP
  104.  
  105. ;-----------------------------------------------------------------------------
  106.  
  107. CSEG    ENDS
  108.         END     ENTPT
  109.