Annotation of sbbs/steve/mviow, revision 1.1

1.1     ! root        1:        .386P
        !             2: 
        !             3: vseg   equ     0b000h  ;video ram segment address
        !             4: 
        !             5: ;****************************************************************************
        !             6: ;*                                                                         *
        !             7: ;*  Procedure msout    On entry ds:si -> text, terminated with 0.          *
        !             8: ;*                                                                         *
        !             9: ;*  Display message on standard output, convert parameters to hex ascii or  *
        !            10: ;*  decimal ascii for each �n, �n, �n in message where n=number of digits.  *
        !            11: ;*  Repeat character c for �nc, where n=(number of repetitions plus 30h).   *
        !            12: ;*                                                                         *
        !            13: ;****************************************************************************
        !            14: 
        !            15: litsg  equ     '�'             ;next character is to be output directly
        !            16: hexsg  equ     '�'             ;hexadecimal conversion signal
        !            17: decsg  equ     '�'             ;decimal conversion signal
        !            18: decsgn equ     '�'             ;decimal conversion, leading spaces suppressed
        !            19: decsgc equ     '�'             ;decimal conversion, use commas
        !            20: repsg  equ     '�'             ;repeat character signal
        !            21: sgchk  equ     '�'             ;all characters below this value are literals
        !            22: 
        !            23: msout  proc    near
        !            24:        pushad
        !            25:        push    ds
        !            26:        push    es
        !            27:        push    ax
        !            28: 
        !            29:        mov     ax,cs
        !            30:        mov     ds,ax
        !            31:        mov     es,ax
        !            32:        mov     di,os iobuf     ;output buffer
        !            33:        mov     bx,os msval     ;parameter list
        !            34:        cld
        !            35: 
        !            36: msorc: lodsb                   ;read character
        !            37:        cmp     al,sgchk
        !            38:        jc      short msowc     ;not conversion character
        !            39: 
        !            40:        cmp     al,hexsg
        !            41:        jz      short mscvh     ;hex conversion character
        !            42:        xor     dh,dh           ;decimal type flag
        !            43:        cmp     al,decsg
        !            44:        jz      short mscvd     ;decimal conversion
        !            45:        mov     dh,40h          ;leading space suppress, bit 6
        !            46:        cmp     al,decsgn
        !            47:        jz      short mscvd     ;decimal, suppress leading spaces
        !            48:        shl     dh,1            ;include commas, bit 7
        !            49:        cmp     al,decsgc
        !            50:        jz      short mscvd     ;decimal with commas
        !            51:        cmp     al,repsg
        !            52:        jnz     short msolc     ;not repeat character
        !            53:        lodsb                   ;get number of repeats
        !            54:        sub     al,30h          ;ascii zero based
        !            55:        movzx   cx,al           ;count
        !            56:        lodsb                   ;character to repeat
        !            57:        rep     stosb           ;expand
        !            58:        jmp     short msorc
        !            59: 
        !            60: msolc: cmp     al,litsg
        !            61:        jnz     short msowc     ;not literal signal
        !            62:        lodsb                   ;no translation on character following
        !            63: 
        !            64: msowc: stosb                   ;write character to buffer
        !            65:        or      al,al
        !            66:        jnz     short msorc     ;not at end
        !            67: 
        !            68:        mov     si,os iobuf
        !            69:        sub     di,si           ;length
        !            70:        dec     di
        !            71:                                ;       jz      msox            ;what?
        !            72:        mov     cx,di
        !            73:        pop     di              ;dest
        !            74:                                ;       mov     ah,40h
        !            75:                                ;       mov     bx,1            ;stdout
        !            76:                                ;       int     21h             ;write line
        !            77:        mov     ax,vseg
        !            78:        mov     es,ax           ;video segment
        !            79:        mov     ah,7            ;attr
        !            80: wrsc:  lodsb
        !            81:        stosw
        !            82:        loop    wrsc            ;write ms to screen
        !            83: 
        !            84: msox:  pop     es
        !            85:        pop     ds
        !            86:        popad
        !            87:        ret
        !            88: 
        !            89: 
        !            90: ; Binary to Hex Ascii Conversion
        !            91: 
        !            92: ; ds:si->source text, es:di->output text, ds:bx->current binary parameter
        !            93: 
        !            94: mscvh: lodsb                   ;read character after signal
        !            95:        dec     al
        !            96:        and     al,7            ;number of digits (0-7 for 1-8)
        !            97:        shl     al,2            ;times bits per digit
        !            98:        movzx   cx,al           ;number of bits minus 4
        !            99:        mov     eax,[bx]        ;get parameter
        !           100:        add     bx,4            ;address next parameter
        !           101:        ror     eax,cl          ;bits 3-0 are ms digit
        !           102:        shr     cx,2
        !           103:        inc     cx              ;number of digits
        !           104: 
        !           105: mshxd: mov     dh,al           ;save 2 digits
        !           106:        call    cvhn            ;convert al{3:0}
        !           107:        mov     al,dh           ;restore 2 digits
        !           108:        rol     eax,4           ;pull up next digit
        !           109:        loop    mshxd
        !           110:        jmp     short msorc     ;continue with text
        !           111: 
        !           112: ; Convert Binary in al to Hex Ascii at es:[di]+
        !           113: ;      Affects: ax, di
        !           114: 
        !           115: cvhb:  cld
        !           116:        push    ax              ;save low digit
        !           117:        shr     al,4
        !           118:        call    cvhn            ;convert high digit
        !           119:        pop     ax              ;convert low digit
        !           120: cvhn:  and     al,0fh
        !           121:        or      al,90h          ;90-99, 9A-9F
        !           122:        daa                     ;90-99, 100-105
        !           123:        adc     al,40h          ;D0-D9, 41-46
        !           124:        daa                     ;130-139, 41-46
        !           125:        stosb                   ;store ascii 0-9, A-F
        !           126:        ret
        !           127: 
        !           128: 
        !           129: ; Binary to Decimal Ascii Conversion
        !           130: 
        !           131: ; ds:si->source text, es:di->output text, ds:bx->current binary parameter
        !           132: 
        !           133: ; dh = 80h, include commas; dh = 40h, suppress leading spaces
        !           134: 
        !           135: mscvd: lodsb                   ;read character after signal
        !           136:        xor     ecx,ecx         ;clear for use as index
        !           137:        cmp     al,'w'
        !           138:        jz      short msdwp     ;16-bit conversion
        !           139:        cmp     al,'b'
        !           140:        jnz     short msdlp     ;32-bit conversion
        !           141: 
        !           142:        mov     1[bx],cl        ;8-bit conversion, zero high byte of low word
        !           143: msdwp: mov     2[bx],cx        ;zero high word for 8/16-bit
        !           144:        lodsb                   ;get next source character
        !           145: 
        !           146: msdlp: dec     al
        !           147:        and     al,0fh
        !           148:        mov     cl,al           ;number of decimal digits (0-9 for 1-10)
        !           149:        mov     ebp,[bx]        ;get parameter
        !           150:        add     bx,4            ;update current parameter address
        !           151:        push    bx
        !           152: 
        !           153: msdsc: sub     al,3
        !           154:        jnc     short msdsc     ;reduce al mod 3
        !           155:        add     al,3            ;add remainder
        !           156:        mov     bl,al           ;number of digits before first comma
        !           157:        push    si              ;save place in source text
        !           158: 
        !           159:        jcxz    msd1            ;one digit only
        !           160:        lea     si,dcval[ecx*4] ;index into 10� list for number of digits
        !           161: 
        !           162: msdxd: std                     ;count downward
        !           163:        lodsd                   ;get 10� where n is current digit
        !           164:        cld                     ;count upward
        !           165: 
        !           166:        mov     dl,2fh          ;ascii count
        !           167: msdxi: inc     dl
        !           168:        js      short msdov     ;overflow
        !           169:        sub     ebp,eax         ;subtract 10� from parameter value
        !           170:        jnc     short msdxi
        !           171: msdov: add     ebp,eax         ;leave remainder
        !           172: 
        !           173:        cmp     dl,3ah
        !           174:        jc      short msdno     ;no overflow
        !           175:        stc
        !           176:        rcr     ebp,1           ;make sure it propagates
        !           177:        mov     dl,'*'          ;overflow character
        !           178: 
        !           179: msdno: or      dh,dl           ;bits 3-0 are zero if this is a leading zero
        !           180:        test    dh,0fh          ;check whether all zeros so far
        !           181:        mov     al,dl           ;current digit
        !           182:        jnz     short msdpc     ;display non-leading-zero
        !           183:        mov     al,' '          ;change leading zero to space
        !           184: 
        !           185:        test    dh,40h
        !           186:        jnz     short msdx      ;skip leading spaces and commas
        !           187: 
        !           188: msdpc: stosb                   ;write digit to output buffer
        !           189: 
        !           190:        or      dh,dh
        !           191:        jns     short msdx      ;no commas
        !           192: 
        !           193:        dec     bl              ;decrement comma counter
        !           194:        jns     short msdx      ;no action until zero
        !           195:        cmp     al,' '
        !           196:        jz      short msdco     ;leave leading space
        !           197:        mov     al,','
        !           198: msdco: stosb                   ;write comma to output buffer
        !           199: 
        !           200:        mov     bl,2            ;reload counter
        !           201: msdx:  loop    msdxd           ;next digit
        !           202: msd1:  mov     ax,bp           ;last digit
        !           203:        cmp     ax,10
        !           204:        jc      short msd1n     ;no overflow
        !           205:        mov     al,1ah          ;display *
        !           206: msd1n: xor     al,30h
        !           207:        stosb
        !           208: 
        !           209:        pop     si              ;restore current index in source text
        !           210:        pop     bx              ;restore current parameter index
        !           211:        jmp     msorc           ;continue with text
        !           212: 
        !           213:        align   4
        !           214: 
        !           215: dcval  equ     $-4             ;10� table
        !           216: 
        !           217:        dd      10,100,1000,10000,100000,1000000
        !           218:        dd      10000000,100000000,1000000000
        !           219: 
        !           220: msval:                         ;parameter list
        !           221: mv1:   dd      0
        !           222: mv2:   dd      0
        !           223: mv3:   dd      0
        !           224: mv4:   dd      0
        !           225: mv5:   dd      0
        !           226: mv6:   dd      0
        !           227: mv7:   dd      0
        !           228: mv8:   dd      0
        !           229: 
        !           230: iobuf: db      512 dup (99h)   ;output buffer
        !           231: 
        !           232: msout  endp

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.