home *** CD-ROM | disk | FTP | other *** search
/ Dream 48 / Amiga_Dream_48.iso / Atari / forth / forst.zoo / forst / lib / regs.s < prev    next >
Text File  |  1990-12-10  |  2KB  |  55 lines

  1. \ REGS.S: examples of the construction of simple words (normally done
  2. \ in assembly code) using direct register access.
  3. \ John Redmond, 30/9/90
  4.  
  5. \ They use the scratch registers D0, D1, A0 and A1, which are not
  6. \ automatically saved and restored.  INC and DEC cause automatic
  7. \ postincrement and predecrement of pointer registers.
  8. \ There is a full discussion in Part 4 of the FD series.
  9.  
  10. \ The code generated from such words can be assessed using
  11. \ wd <wordname>  and
  12. \ what <wordname>
  13.  
  14. \ Their efficiency compares very well with that from assembly source.
  15.  
  16. : task ;  ( for easy forgetting)
  17.  
  18. : dup1  a6 @ ;
  19. : dup2  to d0 ( one off)  d0 d0  ( two back) ;
  20.  
  21. : swap1  to d0 to d1  d0 d1 ;
  22.  
  23. : drop1  to d0 ;
  24. : drop2  4 addto a6 ;
  25.  
  26. : nip1  to d0 to d1  d0 ;
  27. : nip2  a6 ! ;
  28.  
  29. : tuck1  to d0 to d1  d0 d1 d0 ;
  30. : tuck2  a6 @ to d0  to d1  d0 d1 ;
  31.  
  32. : >r1  a7 dec ! ;  ( careful!)
  33. : r>1  a7 inc @ ;  ( here too!)
  34. : r@1  a7 @ ;
  35.  
  36. : rot1  to d0 to d1 to a0  ( pop 3 regs)
  37.    d1 d0 a0  ( put them back) ;
  38.  
  39. : over1  a6 4 + @ ;
  40. : over2  to d0 to d1  d1 d0 d1 ;
  41.  
  42. : count1  to a0  a0 inc c@ to d0  ( hold length in d0)
  43.    a0 d0  ( usual result) ;
  44.  
  45. : ?dup1  a6 @ to d0  d0 if d0 ( second copy) then ;
  46.  
  47. : cmove1  to d1 ( length) to a1 ( dest) to a0 ( source)
  48.    for d1  a0 inc c@  a1 inc c!  next ;
  49.  
  50.  
  51. \ use  wd <wordname> to get a hex dump of these words
  52. \ and compare with the corresponding system words (from Assembly),
  53. \ and use what <wordname> to check size and edges.
  54.  
  55.