home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / a / ask.zoo / ask.asm next >
Assembly Source File  |  1992-10-06  |  6KB  |  157 lines

  1. ;┌──────────────────────────────────────────────────────────────┐
  2. ;│   ASK was compiled with MASM v5.10 and has been placed into  │
  3. ;│   the public domain.                                         │
  4. ;│   Direct any questions to Michael Stangel                    │
  5. ;│                           (217)367-1095                      │
  6. ;│                           stangel@uiuc.edu  (Internet)       │
  7. ;│                           September 19, 1991                 │
  8. ;└──────────────────────────────────────────────────────────────┘
  9. STKSEG  SEGMENT STACK                   ;Stack segment
  10.         DB      128 DUP(?)              ;(128 bytes ought to do)
  11. STKSEG  ENDS
  12.  
  13. CSEG    SEGMENT                         ;Code segment
  14.         ASSUME  CS:CSEG, DS:CSEG, SS:STKSEG, ES:NOTHING
  15.  
  16. CR      EQU     0Dh
  17. LF      EQU     0Ah
  18.  
  19. QUERY    DB    128 DUP(?)        ;Query string
  20. TESTR   DB      'Enter character to get ASCII value: ',CR,LF,'$'
  21. TESTFL  DB      0
  22. ANSWER  DB      CR,LF,'The corresponding ASCII value is '
  23. ANSVAL  DB      '***.',CR,LF,'$'
  24. HELPFL  DB      0
  25. HELP1   DB      'ASK.EXE will allow you to obtain simple interactive input',CR,LF
  26.         DB      'in a batch file.  The response to the question may only be',CR,LF
  27.         DB      'a single character.  The utility will set the DOS errorlevel',CR,LF
  28.         DB      'equal to the ASCII value of the character typed.  You should',CR,LF
  29.         DB      'use the errorlevel as follows:',CR,LF,CR,LF
  30.         DB      '         ask Do you want to run the word processor?',CR,LF
  31.         DB      '         if errorlevel==89 wp.exe',CR,LF
  32.         DB      '         if errorlevel==121 wp.exe',CR,LF,CR,LF
  33.         DB      'Note that you should test for both the capital Y and',CR,LF
  34.         DB      'the small y.  You can also test whether or not the',CR,LF
  35.         DB      'errorlevel is less than or equal to a number, such as:',CR,LF,CR,LF
  36.         DB      '        ask Enter 1, 2 or 3 for instructions:',CR,LF
  37.         DB      '        if errorlevel 51 help.com',CR,LF,CR,LF
  38.         DB      '(Recall the the ASCII value for the digit 3 is 51)',CR,LF,CR,LF
  39.         DB      'If you like a space between the end of your query string',CR,LF
  40.         DB      'and the cursor that waits for the input, you may put a',CR,LF
  41.         DB      'NULL character there by typing ALT+255.',CR,LF,CR,LF
  42.         DB      '***PRESS ANY KEY***$'
  43. HELP2   DB      CR,LF,'Some common ASCII values you may wish to test for:',CR,LF
  44.         DB      '        Y = 089',CR,LF
  45.         DB      '        y = 121',CR,LF
  46.         DB      '        N = 078',CR,LF
  47.         DB      '        n = 110',CR,LF
  48.         DB      '        0 = 048',CR,LF
  49.         DB      '        1 = 049',CR,LF
  50.         DB      '        9 = 057',CR,LF
  51.         DB      '  [Enter] = 013',CR,LF
  52.         DB      '    [Esc] = 027',CR,LF,CR,LF
  53.         DB      'Furthermore, you can find the ASCII value of a character',CR,LF
  54.         DB      'by typing ask -q and entering the character when asked.',CR,LF,CR,LF
  55.         DB      'ASK was compiled with MASM v5.10 and has been placed into',CR,LF
  56.         DB      'the public domain.',CR,LF,CR,LF
  57.         DB      'Direct any questions to Michael Stangel',CR,LF
  58.         DB      '                        (217)367-1095',CR,LF
  59.         DB      '                        stangel@uiuc.edu  (Internet)',CR,LF,CR,LF
  60.         DB      'September 19, 1991',CR,LF,CR,LF,'$'
  61.  
  62.  
  63. MAIN    PROC    FAR
  64.         MOV     AX, CSEG                ;Initialize DS register
  65.         MOV     DS, AX
  66.     CALL    ARG            ;get argument into QUERY
  67.     LEA    DX,QUERY
  68.     MOV    AH,9
  69.     INT    21h            ;print query
  70.     MOV    AH,1
  71.         CMP     HELPFL,1                ;was this a help screen?
  72.         JE      QUIT
  73.         INT     21h                     ;wait for key (put into AL)
  74.         CMP     TESTFL,1                ;was this a test?
  75.         JNE     QUIT
  76.         MOV     AH,0                    ;clear out word
  77.         MOV     BL,100                  ;first divide by 100
  78.         DIV     BL                      ;get 100s digit
  79.         ADD     AL,30h                  ;make it an ASCII digit
  80.         MOV     ANSVAL,AL
  81.         MOV     AL,AH
  82.         MOV     AH,0                    ;clear out word
  83.         MOV     BL,10                   ;now divide by 10
  84.         DIV     BL
  85.         ADD     AL,30h                  ;make them ASCII
  86.         ADD     AH,30h
  87.         MOV     ANSVAL+1,AL
  88.         MOV     ANSVAL+2,AH
  89.         LEA     DX,ANSWER
  90.         MOV     AH,9
  91.         INT     21h
  92. QUIT:   MOV     AH,4Ch                  ;DOS code to exit
  93.         INT     21h                     ;(exit)
  94. MAIN    ENDP
  95.  
  96. ;ARG will get the command-line argument and store it in QUERY
  97. ;unless it detects a switch char ('-') at the beginning
  98. ARG     PROC    NEAR
  99.     PUSH    AX
  100.     PUSH    BX
  101.     PUSH    DX
  102.     PUSH    DS
  103.     PUSH    ES            ;transfer ES to data seg
  104.     POP    DS
  105.     LEA    BX,QUERY        ;get location of QUERY
  106.     MOV    SI,80h            ;get length of parameter string
  107.     CMP    BYTE PTR [SI],0        ;nul parameter?
  108.     JZ    DONE
  109.     INC    SI            ;move into text
  110.     INC    SI
  111.         CMP     BYTE PTR [SI],'-'       ;switch char?
  112.         JE      SWITCH
  113. PRM:    LODSB                ;get next char
  114.     CMP    AL,0Dh            ;end of line?
  115.     JZ    DONE            ;yes--done
  116.     MOV    CS:[BX],AL        ;store char in QUERY
  117.     INC    BX
  118.     LOOP    PRM
  119.         JMP     DONE
  120. SWITCH: INC     SI                      ;move past '-'
  121.         CMP     BYTE PTR [SI],'q'       ;querying a character?
  122.         JNE     NOQ1
  123.         POP     DS                      ;restore data segment
  124.         PUSH    DS
  125.         LEA     SI,TESTR
  126.         MOV     CS:TESTFL,1
  127.         JMP     PRM
  128. NOQ1:   CMP     BYTE PTR [SI],'Q'
  129.         JNE     NOQ2
  130.         POP     DS
  131.         PUSH    DS
  132.         LEA     SI,TESTR
  133.         MOV     CS:TESTFL,1
  134.         JMP     PRM
  135. NOQ2:   CMP     BYTE PTR [SI],'?'       ;help request?
  136.         POP     DS
  137.         PUSH    DS
  138.         LEA     DX,HELP1
  139.         MOV     AH,9
  140.         INT     21h
  141.         MOV     AH,1
  142.         INT     21h
  143.         LEA     DX,HELP2
  144.         MOV     AH,9
  145.         INT     21h
  146.         MOV     HELPFL,1
  147. DONE:    MOV    BYTE PTR CS:[BX],'$'    ;End-Of-String
  148.     POP    DS
  149.     POP    DX
  150.     POP    BX
  151.     POP    AX
  152.     RET
  153. ARG    ENDP
  154.  
  155. CSEG    ENDS                            ;End of code segment
  156.         END     MAIN                    ;Start execution at "MAIN".
  157.