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

  1.       .386                        
  2.       .model   flat,syscall,os_os2
  3.       .code                       
  4. _DEMO:
  5.       LEA   EDX,_STR0
  6.       CALL  WriteStr
  7.       CALL  DoCR
  8.       RET
  9. MAIN:
  10.       LEA   EDX,_STR1
  11.       CALL  WriteStr
  12.       CALL  DoCR
  13.       LEA   EDX,_STR2
  14.       CALL  WriteStr
  15.       MOV   EAX,65
  16.       MOV   WORD  PTR[_A],AX 
  17.       MOV   EAX,90
  18.       MOV   DWORD PTR[Lim_A],EAX
  19. L0:
  20.       XOR   EAX,EAX
  21.       MOV   AX,WORD PTR[_A]
  22.       PUSH  EAX
  23.       MOV   EAX,DWORD PTR[Lim_A]
  24.       POP   EBX
  25.       SUB   EAX,EBX
  26.       MOV   EAX,0
  27.       SBB   EAX,0
  28.       OR    EAX,EAX
  29.       JNZ   L1
  30.       XOR   EAX,EAX
  31.       MOV   AX,WORD PTR[_A]
  32.       CALL  PUTC
  33.       INC   [_A]
  34.       JMP   L0
  35. L1:
  36.       CALL  DoCR
  37.       LEA   EDX,_STR3
  38.       CALL  WriteStr
  39.       CALL  DoCR
  40.       CALL  _DEMO
  41.       LEA   EDX,_STR4
  42.       CALL  WriteStr
  43.       CALL  DoCR
  44.       CALL  _EXIT
  45. ; ***** Library Code ***** 
  46.                EXTRN   DOS32EXIT:NEAR
  47.                EXTRN   DOS32WRITE:NEAR
  48.  
  49.  
  50. _EXIT:         PUSHD   1
  51.                CALL    DOS32EXIT
  52.  
  53.  
  54. PutC:          push    eax         ; Store character on stack
  55.                mov     eax,1
  56.                push    eax         ; put the length below it
  57.                mov     edx,esp     ; EDX points at this
  58.                call    WriteStr
  59.                add     esp,8
  60.                ret
  61.  
  62.  
  63.  
  64. WriteEAX:      pushad
  65.                lea     edx,NumBuffer
  66.                call    Int_Str
  67.                call    WriteStr
  68.                popad
  69.                ret
  70.  
  71. DoCr:          lea     edx,CrLfStr       ; Write a CR/LF pair
  72.                call    WriteStr
  73.                xor     eax,eax
  74.                mov     OutPos,eax
  75.                ret
  76.  
  77. WriteStr:                           ; writes string at [EDX]
  78.                pushad
  79.                xor     eax,eax      ; used as "actual count" storage
  80.                push    eax
  81.                mov     eax,esp      ; push the address of the previous push
  82.                push    eax
  83.                mov     eax,[edx]    ; push the string length
  84.  
  85.                add     OutPos,eax   ; update output position
  86.  
  87.                push    eax
  88.                add     edx,4        ; push the string address
  89.                push    edx
  90.                pushd   stdout       ; push the handle to write to
  91.                call    Dos32Write   ; do the write.
  92.                add     esp,20       ; set the stack back to semi-normal
  93.                popad
  94.                ret
  95.  
  96.  
  97. Int_Str:       pushad               ; No length required...
  98.                mov     ebx,0
  99.                jmp     Int_Str0
  100.  
  101. Int_StrLen:    pushad
  102. Int_Str0:                           ; eax-value to print
  103.                                     ; ebx-number of digits..
  104.                                     ; edx-address of buffer to put it in.....
  105.                pushd   0            ;
  106.                mov     edi,ebx      ; edi now has count
  107.                mov     ebx,edx      ; buffer address now in ebx
  108.                mov     ecx,number_base
  109.                lea     esi,table
  110. Int_Str1:
  111.                mov     edx,0
  112.                div     ecx
  113.                mov     edx,[edx+esi]
  114.                push    edx
  115.                dec     edi          ; bump counter
  116.                and     eax,eax
  117.                jnz     Int_Str1
  118.                mov     edx,ebx      ; ebx --> count
  119.                add     edx,4        ; edx --> string data
  120.                mov     ecx,0        ; ecx = counter
  121. Int_Str1a:
  122.                or      edi,edi
  123.                jle     Int_Str2
  124.                xor     eax,eax
  125.                mov     al,Number_Fill
  126.                push    eax
  127.                dec     edi
  128.                jmp     Int_Str1a
  129. Int_Str2:
  130.                pop     eax
  131.                or      al,al
  132.                jz      Int_Str3
  133.                mov     [edx],al
  134.                inc     edx
  135.                inc     ecx
  136.                jmp     Int_Str2
  137. Int_Str3:
  138.                mov     [ebx],ecx
  139.                popad
  140.                ret
  141.  
  142.  
  143.                .stack  8192
  144.                .DATA
  145.  
  146. ;---------------- I/O DOS Calls Only---------------
  147. stdin          equ     0
  148. stdout         equ     1
  149. stderr         equ     2
  150.  
  151. ;---------------- Useful ---------------
  152. cr             equ     0dh
  153. lf             equ     0ah
  154. BEL            equ     07h
  155. NULL           equ     0000h
  156.  
  157. Number_Base    DD      10
  158. numbuffer      db      104h dup(?)   ; for number strings for debugging
  159.  
  160. number_fill    db      30h           ; '0'
  161. table          db      '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  162.  
  163. CrLfStr        dd      2
  164.                db      0dh,0ah
  165.  
  166. OutPos         dd      0
  167.  
  168. ; ***** Library Ends *****
  169. ; Variable Area
  170. _B    DB    2    DUP (?)
  171. _A    DB    2    DUP (?)
  172. Lim_A    DB    4    DUP (?)
  173. ; String constants
  174. _STR0    DD    12
  175.     DB    'Inside Demo!'
  176. _STR1    DD    42
  177.     DB    'Sample program to demonstrate Power Pascal'
  178. _STR2    DD    21
  179.     DB    'Sample ASCII String: '
  180. _STR3    DD    24
  181.     DB    'We will now call "demo" '
  182. _STR4    DD    27
  183.     DB    'That wasn''t so bad, was it?'
  184.       db      100 dup(0)
  185.       end     main   
  186.