home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / bbl / doc / alpha4.doc < prev    next >
Encoding:
Text File  |  1986-10-25  |  3.5 KB  |  84 lines

  1. Further Notes on BBL Forth
  2.  
  3. The PC/Forth+ 2.00 is the one I use now.  When definitions are
  4. compiled at addresses greater than 32K, it uses 3 byte tokens
  5. that takes 87 cycles through NEXT.  BLL uses 2-byte tokens and
  6. 23 cycles through NEXT.
  7.  
  8. In BBL most of my addresses are absolute SEG:OFFSET.  BBL was
  9. written primarily to support Abundance -- not as a general
  10. purpose Forth, and Abundance has no need for linear addresses.
  11.  
  12. However a SEG:OFFSET can nearly always be treated as if it were
  13. a true 32 bit number.  You can add and subtract small numbers to
  14. them for example.  If you need to compare them for equality, you
  15. must be sure they are canonical -- ie. offset portion is in the
  16. range 0..15.  If you wish to subtract them, they both must have
  17. the same SEG portion.  It turns out this comes out in the wash
  18. 95% of the time because CREATE canonizes HERE.  If you need to
  19. work with data arrays larger than 64K, you have to explicitly
  20. convert addresses to relative, do your arithmetic and then
  21. convert them back.  Cfa type addresses are built by Tick in such
  22. a way that the segment portion is always equal to CS:
  23.  
  24. When you design a 32-bit Forth, you could have have 32-bit
  25. relative addresses, relative segment:offset or absolute
  26. segment:offset as the input to @ CMOVE etc.  If you use anything
  27. other than absolute segments, @ and CMOVE must do the conversion
  28. every time they are used!
  29.  
  30. The conversion, as long as you don't do it all that often, is
  31. not all that painful -- no divides or multiplies needed.  Here
  32. is the code:
  33.  
  34.     CHEAD plainFL,TOREL,">REL"
  35.     ;   Converts absolute seg:offset to relative 32-bit address.
  36.     ;   ( CX=seg BX=offset --- CX=msw BX=lsw of 32-bit relative addr )
  37.     ;   CX is absolute seg, BX may be larger than 15
  38.     ;   Even handles crazy addresses like FFFF:FFFF by wrap around.
  39.     ;   The largest real address is FFFF:000F.
  40.     ;   If CX:BX is effectively < CS:0 then result will be negative.
  41.     MOV     AX,CS
  42.     SUB     CX,AX    ; now have relative seg:offset in CX:BX
  43.     MOV     AX,CX    ; AX:BX now has relative seg:off
  44.     CLEAR   CX       ; MOV CX,DI - DI always 0
  45.     SBB     CX,DI    ; CX=-1 if final result is -ve
  46.                      ; CX=0 if final result is +ve
  47.                      ; This step could be omitted if we were
  48.                      ; sure the relative is positive
  49.                      ; shift 4 high order bits of seg into CX
  50.     SHL     AX,1     ; and also shift seg AX left 4 bits
  51.     RCL     CX,1     ; must do multi-register shifts a bit at a time
  52.     SHL     AX,1     ; even on NEC chips
  53.     RCL     CX,1
  54.     SHL     AX,1
  55.     RCL     CX,1
  56.     SHL     AX,1
  57.     RCL     CX,1
  58.     ADD     BX,AX    ; add shifted seg to offset
  59.     ADC     CX,DI    ; add carry and 4 high order bits
  60.                      ; DI is always 0
  61.     QNEXT
  62. ;=============================================
  63.     CHEAD plainFL,RELFROM,"REL>"
  64. ;    ( 32-bit relative address -- absolute SEG:OFF )
  65. ;    Also handles negative relative addresses that point prior to
  66. ;    CS:.
  67. ;    ( CX:BX -- CX seg BX off)
  68.      MOV     DX,CX
  69.      MOV     CX,BX
  70.      AND     BX,0Fh   ; ensure offset lies in [0..15]
  71.                       ; BX now has the final offset
  72.      SHR     DX,1     ; shift DX:CX right 4 bits
  73.      RCR     CX,1     ; multi-register shifts must be done
  74.      SHR     DX,1     ; a bit at a time even on NEC chips
  75.      RCR     CX,1
  76.      SHR     DX,1
  77.      RCR     CX,1
  78.      SHR     DX,1
  79.      RCR     CX,1
  80.      MOV     AX,CS
  81.      ADD     CX,AX    ; rel seg:off to abs seg:off
  82.      QNEXT
  83. ;====
  84.