home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / KEYINT.ZIP / BWPRINT.ASM next >
Assembly Source File  |  1993-03-28  |  5KB  |  271 lines

  1.     DOSSEG
  2.  
  3.     .MODEL SMALL
  4.     .386
  5.     .CODE
  6.     ASSUME cs:@code, ds:@code
  7.  
  8.     GLOBAL  PrintByte:PROC, PrintWord:PROC, PrintBig:PROC
  9.     GLOBAL  PrintHexByte:PROC, PrintHexWord:PROC, PrintHexBig:PROC
  10.     GLOBAL  PrintHex:PROC, PrintNum:PROC
  11.     GLOBAL  PrintString:PROC
  12.  
  13.     TextNumBIG  db  "00000"
  14.     TextNum     db  "00000"
  15.     TextNumEnd  db  0,"$"
  16.  
  17.     HexResult   db  "00000000",0,'$'
  18.     HexChart    db  "0123456789ABCDEF"
  19.  
  20. ;==- Subroutines
  21.     ;ds:dx points to a string to print.  
  22.     ;cx is the length if cx= 0 prints until whats in al is hit
  23. PrintString PROC NEAR
  24.     pusha
  25.     jcxz    DoAlTerm
  26.  
  27.     mov     si,dx
  28.     mov     ah,2
  29. PSloop:
  30.     mov     dl,ds:[si]
  31.     int     21h
  32.     inc     si
  33.     
  34.     dec     cx
  35.     jne     PsLoop
  36. AllDonePr:
  37.     popa
  38.     ret
  39.  
  40. DoAlTerm:
  41.     mov     si,dx
  42.     mov     ah,2
  43. PSloop2:
  44.     mov     dl,ds:[si]
  45.     cmp     al,dl
  46.     je      AllDonePr
  47.     push    ax
  48.     int     21h
  49.     pop     ax
  50.     inc     si
  51.     jmp     PsLoop2
  52.  
  53. PrintString ENDP
  54.  
  55.     ;es:di points to start of 10 byte buffer to throw results in
  56.     ;eax is number to display
  57.     ;bp is the number of digits max 10
  58. PrintNum PROC NEAR
  59.     pusha
  60.  
  61.     mov     cx,10
  62.     mov     ebx,10
  63. DLNum:
  64.     xor     edx,edx
  65.     div     ebx
  66.     add     dl,'0'
  67.     push    dx      ;push the result
  68.     loop    DLNum
  69.  
  70.     mov     cx,10
  71. DLNum2:
  72.     pop     ax
  73.     cmp     cx,bp
  74.     ja      DontPrintThisYet
  75.     stosb
  76. DontPrintThisYet:
  77.     loop    DLNum2
  78.     
  79.     popa
  80.     ret
  81. PrintNum ENDP
  82.  
  83.     ;es:di points to start of 8 byte buffer to throw results in
  84.     ;eax is number to display
  85.     ;bp is # of hex to display MAX 8
  86. PrintHex PROC NEAR
  87.         pusha
  88.         cld
  89.         mov     cx,seg HexChart
  90.         mov     ds,cx
  91.  
  92.         mov     dx,8
  93.         xor     bx,bx
  94. PHexLoop:
  95.         mov     bl,al
  96.         and     bl,0fh
  97.         mov     cl,ds:[HexChart+bx]
  98.         push    cx
  99.  
  100.         shr     eax,4
  101.         dec     dx
  102.         jne     PhexLoop
  103.  
  104.         mov     cx,8
  105. PhexLoop2:
  106.         pop     ax
  107.         cmp     cx,bp
  108.         ja      NoPrintHex
  109.         stosb
  110. NoPrintHex:
  111.         loop    PhexLoop2
  112.         
  113.         popa
  114.         ret
  115. PrintHex ENDP
  116.  
  117. PrintHexByte PROC NEAR
  118.         pusha
  119.         and     eax,0ffh
  120.         mov     di,offset HexResult
  121.         mov     cx,seg HexResult
  122.         mov     es,cx
  123.  
  124.         call    PrintHex
  125.         mov     dx,offset HexResult+6
  126.         mov     ah,9
  127.         int     21h
  128.         popa
  129.         ret
  130. PrintHexByte ENDP
  131.  
  132. PrintHexWord PROC NEAR
  133.         pusha
  134.         and     eax,0ffffh
  135.         mov     di,offset HexResult
  136.         mov     cx,seg HexResult
  137.         mov     es,cx
  138.  
  139.         call    PrintHex
  140.         mov     dx,offset HexResult+4
  141.         mov     ah,9
  142.         int     21h
  143.         popa
  144.         ret
  145. PrintHexWord ENDP
  146.  
  147. PrintHexBig PROC NEAR
  148.         pusha
  149.         mov     di,offset HexResult
  150.         mov     cx,seg HexResult
  151.         mov     es,cx
  152.  
  153.         call    PrintHex
  154.         mov     dx,offset HexResult
  155.         mov     ah,9
  156.         int     21h
  157.         popa
  158.         ret
  159. PrintHexBig ENDP
  160.  
  161. BinToAscII PROC
  162.         mov     bx,10
  163.         mov     si,SEG TextNum
  164.         mov     es,si
  165.         mov     si,offset textnumend-1
  166.         mov     cx,5
  167. DivLoop:
  168.         sub     dx,dx
  169.         div     bx
  170.         add     dl,'0'
  171.         mov     es:[si],dl
  172.         dec     si
  173.         loop    DivLoop
  174.         ret
  175. ENDP BinToAscII
  176.  
  177. B2ABig PROC
  178.         mov     ebx,10
  179.         mov     si,SEG TextNum
  180.         mov     es,si
  181.         mov     si,offset textnumend-1
  182.         mov     cx,10
  183. DLBig:
  184.         sub     edx,edx
  185.         div     ebx
  186.         add     dl,'0'
  187.         mov     es:[si],dl
  188.         dec     si
  189.         loop    DLBig
  190.         ret
  191. ENDP B2ABig
  192.  
  193. PrintBig PROC
  194.     pushad
  195.  
  196.     call    b2aBig
  197.     mov     ax,SEG TextNumBig
  198.     mov     ds,ax
  199.     mov     dx,offset textnumBig
  200.     mov     ah,9
  201.     int     21h
  202.  
  203.     popad
  204.     ret
  205. ENDP PrintBig
  206.  
  207. PrintByte PROC
  208.     pusha
  209.     jnc     skipsignb
  210.     xor     ah,ah
  211.     test    al,10000000b
  212.     jz      skipsignb
  213.     neg     al
  214.     push    ax
  215.     mov     ah,2
  216.     mov     dl,"-"
  217.     int     21h
  218.     pop     ax
  219.     jmp     skipb
  220.  
  221. skipsignb:
  222.     xor     ah,ah
  223.     push    ax
  224.     mov     ah,2
  225.     mov     dl," "
  226.     int     21h
  227.     pop     ax
  228. skipb:
  229.     call    bintoascii
  230.     mov     ax,SEG TextNum
  231.     mov     ds,ax
  232.     mov     dx,offset textnum+2
  233.     mov     ah,9
  234.     int     21h
  235.     popa
  236.     ret
  237. ENDP PrintByte
  238.  
  239. PrintWord PROC
  240.     pusha
  241.     jnc     skipsignw
  242.     test    ah,10000000b
  243.     jz      skipsignw
  244.     neg     ax
  245.     push    ax
  246.     mov     ah,2
  247.     mov     dl,"-"
  248.     int     21h
  249.     pop     ax
  250.     jmp     skipw
  251. Skipsignw:        
  252.     push    ax
  253.     mov     ah,2
  254.     mov     dl," "
  255.     int     21h
  256.     pop     ax
  257. Skipw:
  258.     call    bintoascii
  259.     mov     ax,SEG TextNum
  260.     mov     ds,ax
  261.     mov     dx,offset textnum
  262.     mov     ah,9
  263.     int     21h
  264.     popa
  265.     ret
  266. ENDP PrintWord
  267.  
  268.     END
  269.     
  270.  
  271.