home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PP002.ZIP / LIB.ASM < prev    next >
Assembly Source File  |  1993-04-22  |  4KB  |  123 lines

  1.                EXTRN   DOS32EXIT:NEAR
  2.                EXTRN   DOS32WRITE:NEAR
  3.  
  4.  
  5. _EXIT:         PUSHD   1
  6.                CALL    DOS32EXIT
  7.  
  8.  
  9. PutC:          push    eax         ; Store character on stack
  10.                mov     eax,1
  11.                push    eax         ; put the length below it
  12.                mov     edx,esp     ; EDX points at this
  13.                call    WriteStr
  14.                add     esp,8
  15.                ret
  16.  
  17.  
  18.  
  19. WriteEAX:      pushad
  20.                lea     edx,NumBuffer
  21.                call    Int_Str
  22.                call    WriteStr
  23.                popad
  24.                ret
  25.  
  26. DoCr:          lea     edx,CrLfStr       ; Write a CR/LF pair
  27.                call    WriteStr
  28.                xor     eax,eax
  29.                mov     OutPos,eax
  30.                ret
  31.  
  32. WriteStr:                           ; writes string at [EDX]
  33.                pushad
  34.                xor     eax,eax      ; used as "actual count" storage
  35.                push    eax
  36.                mov     eax,esp      ; push the address of the previous push
  37.                push    eax
  38.                mov     eax,[edx]    ; push the string length
  39.  
  40.                add     OutPos,eax   ; update output position
  41.  
  42.                push    eax
  43.                add     edx,4        ; push the string address
  44.                push    edx
  45.                pushd   stdout       ; push the handle to write to
  46.                call    Dos32Write   ; do the write.
  47.                add     esp,20       ; set the stack back to semi-normal
  48.                popad
  49.                ret
  50.  
  51.  
  52. Int_Str:       pushad               ; No length required...
  53.                mov     ebx,0
  54.                jmp     Int_Str0
  55.  
  56. Int_StrLen:    pushad
  57. Int_Str0:                           ; eax-value to print
  58.                                     ; ebx-number of digits..
  59.                                     ; edx-address of buffer to put it in.....
  60.                pushd   0            ;
  61.                mov     edi,ebx      ; edi now has count
  62.                mov     ebx,edx      ; buffer address now in ebx
  63.                mov     ecx,number_base
  64.                lea     esi,table
  65. Int_Str1:
  66.                mov     edx,0
  67.                div     ecx
  68.                mov     edx,[edx+esi]
  69.                push    edx
  70.                dec     edi          ; bump counter
  71.                and     eax,eax
  72.                jnz     Int_Str1
  73.                mov     edx,ebx      ; ebx --> count
  74.                add     edx,4        ; edx --> string data
  75.                mov     ecx,0        ; ecx = counter
  76. Int_Str1a:
  77.                or      edi,edi
  78.                jle     Int_Str2
  79.                xor     eax,eax
  80.                mov     al,Number_Fill
  81.                push    eax
  82.                dec     edi
  83.                jmp     Int_Str1a
  84. Int_Str2:
  85.                pop     eax
  86.                or      al,al
  87.                jz      Int_Str3
  88.                mov     [edx],al
  89.                inc     edx
  90.                inc     ecx
  91.                jmp     Int_Str2
  92. Int_Str3:
  93.                mov     [ebx],ecx
  94.                popad
  95.                ret
  96.  
  97.  
  98.                .stack  8192
  99.                .DATA
  100.  
  101. ;---------------- I/O DOS Calls Only---------------
  102. stdin          equ     0
  103. stdout         equ     1
  104. stderr         equ     2
  105.  
  106. ;---------------- Useful ---------------
  107. cr             equ     0dh
  108. lf             equ     0ah
  109. BEL            equ     07h
  110. NULL           equ     0000h
  111.  
  112. Number_Base    DD      10
  113. numbuffer      db      104h dup(?)   ; for number strings for debugging
  114.  
  115. number_fill    db      30h           ; '0'
  116. table          db      '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  117.  
  118. CrLfStr        dd      2
  119.                db      0dh,0ah
  120.  
  121. OutPos         dd      0
  122.  
  123.