home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 488.lha / FDStub_v0.6a / CodeGen.DOC < prev    next >
Text File  |  1991-02-08  |  3KB  |  108 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                  FDStub
  7.                  
  8.             The C to ASM interface generator
  9.              Written by Bruce Mackey
  10.                     (c) 1991
  11.                 All rights reserved.
  12.  
  13.  
  14.                   Version 0.6a
  15.  
  16.  
  17.          -=== CODE GENERATION DOCUMENTATION ===-        
  18.  
  19.  
  20. Here are a few things to know about FDStub.
  21.         
  22.  
  23.  
  24.     0.    I am completly self taught in programming.
  25.         So I am explaining things as I understand them,
  26.         its possible that I am wrong about everything.. 
  27.         but not probable. :)
  28.  
  29.     1.    D0 REGISTER. FDstub NEVER SAVES the D0 register. If D0     
  30.         is declared in the function definition the register 
  31.         WILL BE loaded from the stack BUT FDStub WILL NOT save 
  32.         D0 to the stack before loading.
  33.  
  34.     2.    MOVEM INSTUCTIONS. This is my understanding:
  35.         MOVEM always saves DATA regs first followed by
  36.         the ADDRESS regs EVEN if you specify the regs in 
  37.         a different order.
  38.  
  39.         SomeFunction(a1,d1) which has a stack like
  40.                 
  41.                   |------|
  42.                   |  D1  |
  43.                   |------|
  44.                   |  A1  | lowest
  45.                   |------|
  46.  
  47.         and issuing a MOVEM.L A1/D1,-(SP) will cause reg A1
  48.         to be loaded with the value intended for D1 and 
  49.         visa versa.
  50.  
  51.         So the trick is to try to use the most efficient 
  52.         way of getting parameters off the stack    while     
  53.         maitaining the LEFT to RIGHT order.
  54.  
  55.         
  56.         here's an example:
  57.             these are the registers for BltBitMap
  58.         
  59.             (A0,D0/D1,A1,D2/D3/D4/D5/D6/D7/A2)
  60.  
  61.             if you issued a command like this 
  62.  
  63.         MOVEM.L    44(sp),A0/D0/D1/A1/D2/D3/D4/D5/D6/D7/A2
  64.         
  65.         DON'T expect the registers to be loaded correctly.
  66.  
  67.         registers D0-D7 will be loaded first followed by
  68.         A0-A2 defeating the LEFT to RIGHT order of the regs,
  69.  
  70.  
  71.         This is what FDStub does instead:
  72.  
  73.             _BltBitMap:
  74.                 MOVEM.L    D1-D7/A0-A2,-(SP)
  75.                 MOVE.L    44(SP),A0
  76.                 MOVEM.L    52(SP),D0-D1
  77.                 MOVE.L    64(SP),A1
  78.                 MOVEM.L    72(SP),D2-D7
  79.                 MOVE.L    100(SP),A2
  80.                 MOVE.L    _GfxBase,A6
  81.                 JSR    _LVOBltBitMap(A6)
  82.                 MOVEM.L    (SP)+,D1-D7/A0-A2
  83.                 RTS
  84.  
  85.         which is better than 11 MOVE.L instructions!
  86.  
  87.     
  88.     3.    SAVING/RESTORING REGISTERS TO THE STACK.
  89.         FDStub makes what I consider a logical assumtion: 
  90.             that all LIKE regs defined for a function will 
  91.             have a progression from lowest reg to highest 
  92.             WITHOUT SKIPPING a register.
  93.  
  94.         Now to expalin what I mean by that. Let's use AmigaDOS
  95.         function Write(d1/d2/d3), when 'Write' was created the
  96.         author started at D1 and progressed up to D3 and didn't
  97.         skip any registers. If you were to redefine 'Write' to
  98.         Write(d1/d2/d4), FDStub will pull registers D1-D4
  99.         you'll get 4 registers instead of 3.
  100.  
  101.         you can see what will happen if this rule is not followed, 
  102.         when you use the stub in question your computer will do 
  103.         some stange things.
  104.         
  105.         (I thought about using a bad pun.. about stubbing... but...)        
  106.  
  107. My pain has a name... that name is "WRITING DOCUMENTATION".
  108.