home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / codehigh.seq < prev    next >
Text File  |  1988-09-20  |  2KB  |  56 lines

  1. \ CODEHIGH.SEQ  Call high level code from assembly & return
  2.  
  3. comment:
  4.  
  5.   Allow calling high level words from within a CODE definition.
  6.  
  7.   WARNING ! You must not assume your registers are preserved across a
  8. group of high level words within the CODE definition. They ARE NOT !
  9. If you need to preserve some registers, then doit yourself.
  10.  
  11. comment;
  12.  
  13. only forth also assembler definitions also
  14.  
  15. label hdoes     ( --- )
  16.                 pop ax          \  8 cycles
  17.                 xchg rp, sp     \  4 cycles
  18.                 push ax         \ 11 cycles
  19.                 xchg rp, sp     \  4 cycles
  20.                 sub ax, # 3     \  4 cycles
  21.                 jmp >nest       \ 16 cycles
  22.                 end-code
  23.  
  24. code hret       ( --- )
  25.                 xchg rp, sp     \ 4 cycles
  26.                 pop ip          \ 8 cycles
  27.                 pop es          \ 8 cycles
  28.                 pop ax          \ 8 cycles
  29.                 xchg rp, sp     \ 4 cycles
  30.                 add ax, # 2     \ 5 cycles
  31.                 jmp ax
  32.                 end-code
  33.  
  34. : >h            ( --- )
  35.                 xhere paragraph + dup xdpseg !          \ setup LIST space
  36.                 xdp off
  37.                 also forth
  38.                 >pre call hdoes a; xseg @ - , pre> ] ;
  39.  
  40. : h>            ( --- )
  41.                 previous
  42.                 compile hret  [compile] [ ; immediate
  43.  
  44. \s
  45.  
  46. Example         A simple example of the use of High level in a code word.
  47.  
  48.         CODE TST
  49.                 MOV AX, # 23
  50.                 PUSH AX
  51.                 >H DUP . H>     \ you MUST come back with "H>".
  52.                 POP AX
  53.                 NEXT
  54.                 END-CODE
  55.  
  56.