home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP7 / UTIL.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-16  |  3.8 KB  |  200 lines

  1.     .model    small
  2.     .code
  3.     .data
  4.  
  5.     extrn    DsSave:word
  6.  
  7.     .code
  8.     public    Blank, ScanP, ScanB, Out16, Hex, HexIn
  9.     public    GetEol, HexChk, Address, GetHex, GetHex1, Tab
  10.     public    Backup,PrintMes
  11.  
  12.     extrn    OutCh:near, PErr:near, Error:near
  13.  
  14. BacMes        db    8," ",8+80H
  15.  
  16. ;Output one space
  17.  
  18. BLANK:
  19.     MOV    AL," "
  20.     jmp    OutCh
  21.  
  22. ;Output the number of blanks in CX
  23.  
  24. TAB:
  25.     CALL    BLANK
  26.     LOOP    TAB
  27.     RET
  28.  
  29. ;Scan for parameters of a command
  30.  
  31. SCANP:
  32.     CALL    SCANB        ;Get first non-blank
  33.     CMP    AL,","        ;One comma between params OK
  34.     JNE    EOLCHK        ;If not comma, we found param
  35.     INC    SI        ;Skip over comma
  36.  
  37. ;Scan command line for next non-blank character
  38.  
  39. SCANB:
  40.     LODSB
  41.     CMP    AL," "
  42.     JZ    SCANB        ;Skip over blanks
  43.     cmp    al,9
  44.     jz    ScanB
  45.     DEC    SI        ;Back up to first non-blank
  46. EOLCHK:
  47.     CMP    AL,13
  48.     RET
  49.  
  50. ;Print out 16-bit value in DX in hex
  51.  
  52. OUT16:
  53.     MOV    AL,DH        ;High-order byte first
  54.     CALL    HEX
  55.     MOV    AL,DL        ;Then low-order byte
  56.  
  57. ;Output byte in AL as two hex digits
  58.  
  59. HEX:
  60.     MOV    AH,AL        ;Save for second digit
  61. ;Shift high digit into low 4 bits
  62.     PUSH    CX
  63.     MOV    CL,4
  64.     SHR    AL,CL
  65.     POP    CX
  66.  
  67.     CALL    DIGIT        ;Output first digit
  68. HIDIG:
  69.     MOV    AL,AH        ;Now do digit saved in AH
  70. DIGIT:
  71.     AND    AL,0FH        ;Mask to 4 bits
  72. ;Trick 6-byte hex conversion works on 8086 too.
  73.     ADD    AL,90H
  74.     DAA
  75.     ADC    AL,40H
  76.     DAA
  77.     jmp    OutCh
  78.  
  79. ;Check if next character in the input buffer is a hex digit
  80. ;and convert it to binary if it is. Carry set if not.
  81.  
  82. HEXIN:
  83.     MOV    AL,[SI]
  84.  
  85. ;Check if AL has a hex digit and convert it to binary if it
  86. ;is. Carry set if not.
  87.  
  88. HEXCHK:
  89.     SUB    AL,"0"        ;Kill ASCII numeric bias
  90.     JC    RET2
  91.     CMP    AL,10
  92.     CMC
  93.     JNC    RET2        ;OK if 0-9
  94.     AND    AL,5FH        ;Convert to upper case
  95.     SUB    AL,7        ;Kill A-F bias
  96.     CMP    AL,10
  97.     JC    RET2
  98.     CMP    AL,16
  99.     CMC
  100. Ret2:    RET
  101.  
  102. ;Get an address in Segment:Offset format. Segment may be ommitted
  103. ;and a default (kept in BP) will be used, or it may be a segment
  104. ;register (DS, ES, SS, CS). Return with segment in AX, Offset in DX.
  105.  
  106. ADDRESS:
  107.     CALL    SCANP
  108.     CMP    byte ptr [SI+1],"S"    ;Is second character "S"?
  109.     JZ    SEGREG
  110.     MOV    CX,4
  111.     CALL    GETHEX        ;Get number--may be segment or offset
  112.     MOV    AX,BP        ;Get default segment
  113.     CMP    byte ptr [SI],":"    ;Segment specification?
  114.     JNZ    RET3
  115.     PUSH    DX        ;Save segment while we get offset
  116. GETDISP:
  117.     INC    SI        ;Skip over ":"
  118.     MOV    CX,4
  119.     CALL    GETHEX
  120.     POP    AX        ;Bring segment back
  121. Ret3:    RET
  122.  
  123. SEGREG:
  124.     LODSB            ;First letter of segment register
  125.     MOV    DI,offset DGroup:SEGLET-1
  126.     MOV    CX,4
  127. CSSCAN:
  128.     INC    DI
  129.     CMP    AL,CS:[DI]
  130.     LOOPNZ    CSSCAN
  131.     JNZ    PERR
  132.     INC    SI        ;Skip second letter ("S")
  133.     SHL    CX,1
  134.     MOV    BX,CX
  135.     CMP    byte ptr [SI],":"
  136.     JNZ    ErrorJ
  137.     PUSH    [BX+DSSave]
  138.     jmp    GETDISP
  139.  
  140. SEGLET    DB    "CSED"
  141.  
  142.  
  143. ;Get the next parameter, which must be a hex number.
  144. ;CX is maximum number of digits the number may have.
  145.  
  146. GETHEX:
  147.     CALL    SCANP        ;Scan to next parameter
  148. GETHEX1:
  149.     XOR    DX,DX        ;Initialize the number
  150.     MOV    AH,DH
  151.     CALL    HEXIN        ;Get a hex digit
  152.     JC    ErrorJ        ;Must be one valid digit
  153.     MOV    DL,AL        ;First 4 bits in position
  154. GETLP:
  155.     INC    SI        ;Next char in buffer
  156.     DEC    CX        ;Digit count
  157.     CALL    HEXIN        ;Get another hex digit?
  158.     JC    RET2        ;All done if no more digits
  159.     JCXZ    ErrorJ        ;Too many digits?
  160.     SHL    DX,1        ;Multiply by 16
  161.     SHL    DX,1
  162.     SHL    DX,1
  163.     SHL    DX,1
  164.     OR    DL,AL        ;and combine new digit
  165.     jmp    GETLP        ;Get more digits
  166.  
  167. ErrorJ:    jmp    Error
  168.  
  169. ;Make sure there is nothing more on the line except for
  170. ;blanks and carriage return. If there is, it is an
  171. ;unrecognized parameter and an error.
  172.  
  173. GETEOL:
  174.     PUSH    AX
  175.     CALL    SCANB        ;Skip blanks
  176.     POP    AX
  177.     JNZ    ErrorJ        ;Better be a RETURN
  178.     RET
  179.  
  180. ;Physical backspace - blank, backspace, blank
  181.  
  182. Backup:
  183.     mov    si,offset DGroup:BacMes
  184.  
  185. ;Print ASCII message. Last char has bit 7 set
  186.  
  187. PrintMes:
  188.     push    cs
  189.     pop    ds
  190. PrintLp:
  191.     lodsb            ;Get char to print
  192.     call    OutCh
  193.     shl    al,1        ;High bit set?
  194.     jnc    PrintLp
  195.     push    es
  196.     pop    ds
  197.     ret
  198.  
  199.     end
  200.