home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD1.img / d1xx / d105 / asmprogs / stack / stack.asm < prev    next >
Assembly Source File  |  1987-10-25  |  5KB  |  161 lines

  1. ; Stack
  2. ; Copyright 1987 Glen McDiarmid
  3. ; Use and distribute freely
  4.  
  5. ; I may be contacted at:-
  6. ; Glen McDiarmid
  7. ; 28 Marginson Street,
  8. ; Ipswich, Queensland
  9. ; Australia  4305
  10.  
  11. ; (07) 812-2963
  12.  
  13. _LVOAlert              equ     -$6c
  14. _LVOAllocMem           equ     -$c6
  15. _LVOFreeMem            equ     -$d2
  16. _LVOFindTask           equ     -$126
  17. _LVOCloseLibrary       equ     -$19e
  18. _LVOOpenLibrary        equ     -$228
  19.  
  20.  
  21.  
  22. _LVOWrite              equ     -$30
  23. _LVOOutput             equ     -$3c
  24.  
  25. cli_DefaultStack       equ     $34
  26. pr_CLI                 equ     $AC
  27. execbase               equr    a2
  28. dosbase                equr    d6
  29. outputhandle           equr    a3
  30.  
  31. start:
  32.  
  33.                movea.l a0,a5   
  34.                move.l  d0,d5   
  35.                movea.l $4,execbase
  36.                movea.l execbase,a6
  37.                lea.l   dosname(pc),a1  
  38.                eor.l   d0,d0   
  39.                jsr     _LVOOpenLibrary(a6) 
  40.                move.l  d0,dosbase  
  41.                movea.l d0,a6
  42.                jsr     _LVOOutput(a6)  
  43.                move.l  d0,outputhandle
  44.                move.l  execbase,a6
  45.                suba.l  a1,a1 
  46.                jsr     _LVOFindTask(a6)
  47.                movea.l d0,a0
  48.                movea.l pr_CLI(a0),a4 
  49.                adda.l  a4,a4 
  50.                adda.l  a4,a4 
  51.                move.l  cli_DefaultStack(a4),d7 
  52.                asl.l   #$2,d7   
  53.                subi.w  #$2,d5   
  54.                bge     isparms
  55.                move.l  #message,d2
  56.                move.l  #messagelength,d3
  57.                bsr.s   print   
  58.  
  59.                eor.l   d3,d3
  60.                clr.l   -(a7)   
  61.                move.l  #$1,d0   
  62. loop7:         move.l  d0,-(a7)  
  63.                asl.l   #1,d0   
  64.                move.l  d0,d1   
  65.                asl.l   #$2,d0   
  66.                add.l   d1,d0   
  67.                bcc.s   loop7   
  68. loop8:         move.l  (a7)+,d0  
  69.                beq.s   divdone   
  70.                move.b  #$2f,d1   
  71. loop9:         addi.b  #$1,d1   
  72.                sub.l   d0,d7
  73.                bcc.s   loop9
  74.                add.l   d0,d7
  75.                cmpi.b  #$30,d1
  76.                bne.s   notzero
  77.                tst.b   d3
  78.                beq.s   loop8
  79. notzero        move.b d1,-(a7)  
  80.                move.l  a7,d2   
  81.                bsr.s   print2
  82.                tst.w   (a7)+   
  83.                bra.s   loop8   
  84. divdone:       move.l  #finishmessage,d2 
  85.                move.l  #finishmessagelength,d3
  86.                bsr.s   print
  87. exit:          move.l  dosbase,a1
  88.                jsr     _LVOCloseLibrary(a6)
  89.                eor.l   d0,d0   
  90.                rts      
  91. badparms:      move.l  #errmessage,d2
  92.                move.l  #errmessagelength,d3
  93.                bsr.s   print   
  94. skip:          move.l  10,d0   
  95. errorexit:     rts
  96.  
  97. print2:        moveq.l #$1,d3   
  98. print:         move.l  outputhandle,d1
  99.                move.l  dosbase,a6
  100.                jsr     _LVOWrite(a6)  
  101.                move.l  execbase,a6
  102.                rts
  103. jtoosmall:     lea.l   toosmall(pc),a5 
  104.                bra     sizejoin
  105. jtoobig:       lea.l   toobig(pc),a5
  106. sizejoin:      move.l  #badsize,d2  
  107.                move.l  #badsizelength,d3
  108.                bsr.s   print
  109.                move.l  a5,d2
  110.                move.l  #$6,d3
  111.                bsr.s   print   
  112.                bra     skip
  113. isparms:       eor.l   d2,d2
  114.                move.l  d2,d0
  115. anotherspace:  move.b  (a5)+,d0  
  116.                cmpi.b  #$20,d0   
  117.                dbne    d5,anotherspace
  118.  
  119. loop2:         cmpi.b  #$20,d0   
  120.                beq     endofnumber
  121.                subi.b  #$30,d0   
  122.                blt     badparms  
  123.                cmpi.b  #$9,d0
  124.                bgt     badparms  
  125.                mulu    #$A,d2   
  126.                add.l   d0,d2   
  127.                move.b  (a5)+,d0  
  128.                dbra    d5,loop2(pc)  
  129. endofnumber:   cmpi.l  #1600,d2  
  130.                blt     jtoosmall
  131.                move.l  d2,d0
  132.                moveq.l #$1,d1   
  133.                jsr     _LVOAllocMem(a6) 
  134.                tst.l   d0
  135.                beq     jtoobig   
  136.                movea.l d0,a1   
  137.                move.l  d2,d0   
  138.                jsr     _LVOFreeMem(a6)  
  139.                asr.l   #$2,d2   
  140.                move.l  d2,cli_DefaultStack(a4)
  141.                bra     exit  
  142.  
  143.  
  144. dosname:       dc.b    'dos.library',0
  145.  
  146. message:       dc.b    'current stack size is '
  147. messagelength  equ *-message
  148.  
  149. finishmessage: dc.b    ' bytes',$a
  150. finishmessagelength equ *-finishmessage
  151.  
  152. errmessage:    dc.b    'Usage: STACK [size]',$a
  153. errmessagelength equ *-errmessage
  154.  
  155. badsize:       dc.b    'suggested stack size too '
  156. badsizelength  equ *-badsize
  157.  
  158. toosmall:      dc.b    'small',$a
  159.  
  160. toobig:        dc.b    'large',$a
  161. ; Sorry about the lack of comments - I prefer informative labels