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 / writeshort.asm < prev    next >
Assembly Source File  |  1989-11-20  |  2KB  |  62 lines

  1.  
  2. *    WriteShort.asm (of PCQ Pascal runtime library)
  3. *    Copyright (c) 1989 Patrick Quaid
  4.  
  5. *    Write a short integer to a text file.  The only difference between
  6. *    this and WriteInt is that this routine uses the 68000 div operation.
  7.  
  8. *    Upon entry, d0 holds the value to write.  The word on top of
  9. *    the stack holds the minumum field width, and the long word
  10. *    below that holds the file record address
  11. *
  12.  
  13.     SECTION    one
  14.  
  15.     XREF    _p%PadOut
  16.     XREF    outbuffer
  17.     XREF    _p%WriteText
  18.     XREF    _p%IOResult
  19.  
  20.     XDEF    _p%WriteShort
  21. _p%WriteShort:
  22.  
  23.     tst.l    _p%IOResult        ; is IO system OK?
  24.     bne    5$
  25.     move.l    #outbuffer+31,a1    ; get the last position
  26.     tst.l    d0            ; is integer < 0 ?
  27.     bge.s    1$            ; if not, skip ahead
  28.     move.w    #-1,-(sp)        ; put -1 on stack
  29.     neg.l    d0            ; and make d0 positive
  30.     bra.s    2$            ; go around
  31. 1$    move.w    #1,-(sp)        ; d0 is positive, so mark it
  32. 2$    divu    #10,d0            ; base 10
  33.     move.l    d0,d1            ; d0 := d0 div 10
  34.     ext.l    d0            ; make d0 32 bits
  35.     swap    d1            ; d1 := d0 mod 10
  36.     add.b    #'0',d1            ; make value a char digit
  37.     move.b    d1,(a1)            ; put it into buffer
  38.     subq.l    #1,a1            ; and move buffer pointer
  39.     tst.l    d0            ; is d0 zero yet?
  40.     bgt    2$            ; if not, continue
  41.     move.w    (sp)+,d0        ; was it negative?
  42.     bgt.s    3$            ; if not, go on
  43.     move.b    #'-',(a1)        ; append minus sign
  44.     subq.l    #1,a1            ; advance pointer
  45. 3$    move.l    a1,d3            ; move pointer to d3
  46.     sub.l    #outbuffer+31,d3    ; subtract the original position
  47.     neg.l    d3            ; get the length
  48.     move.l    6(sp),a0        ; a0 := file record address
  49.     move.w    4(sp),d0        ; get the field width
  50.     ext.l    d0            ; make it an integer
  51.     sub.l    d3,d0            ; how many extras?
  52.     ble    4$            ; if none, skip this
  53.     move.l    a1,-(sp)        ; save first buffer position
  54.     jsr    _p%PadOut        ; write d0 spaces to a0 file rec
  55.     move.l    (sp)+,a1        ; retrieve position
  56. 4$    adda.l    #1,a1            ; point to actual first char
  57.     jsr    _p%WriteText        ; write d3 bytes at a1 to a0
  58.  
  59. 5$    rts
  60.  
  61.     END
  62.