home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff339.lzh / PCQ / Runtime.lzh / Runtime / Writers / writestring.asm < prev    next >
Assembly Source File  |  1989-11-20  |  1KB  |  43 lines

  1.  
  2. *    WriteString.asm (of PCQ Pascal runtime library)
  3. *    Copyright (c) 1989 Patrick Quaid
  4.  
  5. *    Writes a string to a text file.
  6.  
  7. *    Upon entry, d0 holds the address of the string to write.
  8. *    The word on top of the stack holds the minimum field width,
  9. *    and the longword below that holds the address of the file
  10. *    record
  11.  
  12.     SECTION    ONE
  13.  
  14.     XREF    _p%WriteText
  15.     XREF    _p%PadOut
  16.     XREF    _p%IOResult
  17.  
  18.     XDEF    _p%WriteString
  19. _p%WriteString
  20.  
  21.     tst.l    _p%IOResult    ; is IO system in order?
  22.     bne    3$
  23.     move.l    6(sp),a0    ; get the file record address
  24.     move.l    d0,a1        ; move string address
  25.     move.w    4(sp),d0    ; d0 holds the minimum field width
  26.     ext.l    d0        ; make it 32 bits
  27. 5$    move.l    #-1,d3
  28. 1$    addq.l    #1,d3        ; first find the length
  29. 2$    tst.b    0(a1,d3.l)
  30.     bne    1$        ; if not null byte, loop
  31.     sub.l    d3,d0        ; subtract string length
  32.     ble.s    4$        ; if no extra padding needed, skip
  33.     movem.l    a1/d3,-(sp)    ; save string address and length
  34.     jsr    _p%PadOut    ; write padding spaces
  35.     movem.l    (sp)+,a1/d3    ; restore regs
  36. 4$    tst.l    d3        ; is string zero length?
  37.     beq.s    3$        ; if so, skip the write
  38.     jsr    _p%WriteText    ; write the string
  39. 3$    rts
  40.  
  41.     END
  42.  
  43.