Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.2
 
1.3
 
MAIN:ragge:20140603201950
 
README
_>66 Arrays allocated as automatics are stored on the stack with a pointer
 77 in zero page to its destination.
 88 
<>9 -0-7     Unused
  9+0-7     Unused (by us)
1010 10      Stack pointer
 1111 11      Frame pointer
 1212 12-14   Unused
<>13 -15      Used by prolog
  13+15      Prolog private word
1414 16      Prolog address, written in crt0
 1515 17      Epilog address, written in crt0
<>16 -20-27   Auto-increment, scratch
 17 -30-37   Auto-decrement, scratch
 18 -40-47   Unused
 19 -50-57   Scratch/Arguments
 20 -60-77   Permanent, save before use.
 21 -100-377 Addresses for subroutines, written by the assembler
  16+20-27   (Auto-increment), scratch
  17+30-37   (Auto-decrement), scratch
  18+40-47   Used by HW stack and MMPU
  19+50-77   Permanent, save before use.
  20+100-377 Addresses for subroutines, written by the linker
2221 
 2322 The normal registers (AC0-AC3) are all considered scratch registers.
 2423 
 2524 Register classes are assigned as:
 2625         AC0-AC3: AREGs.
 2726         AC2-AC3: BREGs.
<>28 -        50-77:   CREGs.
 29 -        ...and eventually register pairs as DREGs.
  27+        ...and eventually register pairs/floats as EREGs, double in FREGs.
3028 
<>31 -In byte code the low half of a word is the first byte (little-endian).
 32 -This is bit 8-15 in Nova syntax.
 33 -
  29+In byte code the left half of a word is the first byte (big-endian).
  30+This is bit 0-7 in Nova syntax.
3431 The stack is growing towards lower adresses (as opposed to the Eclipse stack).
<> 32+Stack pointer points to the last used stack entry, which means:
  33+PUSH: dec sp, store value
  34+POP:  fetch val, inc sp
  35+
  36+Note that internally is the first 24 words stored in loc 50-77!
  37+So an offset is subtracted in adrput().
  38+
3539 Stack layout:
 3640 
<>37 -        ! arg1  !
 38 -        ! arg0  !
 39 - fp ->  ! old pc!
 40 -        ! old fp!
 41 - pc ->  ! saved !
  41+        ! arg1  ! 1
  42+ fp ->  ! arg0  ! 0
  43+        ! old pc! -1
  44+        ! old fp! -2
  45+ sp ->  ! saved ! -3
4246 
<>43 -A reference to a struct member in assembler, a = b->c; b is in ZP 50
  47+
  48+Stack references to zero page are converted to NAMEs, using word addresses.
  49+References to the stack itself are using byte offsets.
  50+
  51+Arguments are transferred on the stack.  To avoid unneccessary double instructions
  52+they are copied to the zp use area initially. XXX? Need tests here.
  53+Return values in ac0 and ac1.
  54+
  55+A reference to a struct member in assembler, a = b->c; b is in ZP 50 (or on stack)
4456 + is zeropage-addressing
<>45 -* is fp-adressing
  57+* is fp-adressing, assume fp in ac3
4658 
 4759 # offset 0
 4860 +       lda 0,@50       # load value from indirect ZP 50 into ac0
<> 61+or
4962 *       lda 2,,3        # load value from (ac3) into ac2
 5063 *       lda 0,,2        # load value from (ac2) into ac0
 5164 
 5265 # offset 12
 5366 +       lda 2,50        # load value from ZP 50 into ac2
 5467 +       lda 0,12,2      # load value from (ac2+12) into ac0
<> 68+or
5569 *       lda 2,,3        # load value from (ac3) into ac2
 5670 *       lda 0,12,2      # load value from 12(ac2) into ac0
 5771 
 5872 # offset 517
<>59 -+       lda 2,50        # load value from ZP 50 into ac2
 60 -+       lda 0,.L42-.,1  # load offset from .L42 PC-indexed
 61 -+       addz 0,2,skp    # add offset to ac2 and skip
  73++       lda %2,50       # load value from ZP 50 into ac2
  74++       lda %0,.L42-.,%1        # load offset from .L42 PC-indexed
  75++       addz %0,%2,skp  # add offset to ac2 and skip
6276 +.L42:  .word 517       # offset value
<>63 -+       lda 0,,2        # load value from (ac2) into ac0
  77++       lda %0,,%2      # load value from (ac2) into ac0
  78+or
6479 
<>65 -The prolog/epilog implementation; it is implemented as subroutines.
  80+The prolog/epilog; they are implemented as subroutines.
  81+Both can be omitted if the function do not need it.
6682 
<>67 -.L42:   .word 13        # number of words to save
  83+
  84+        .word 012       # total words that needs to be saved
6885 func:
<>69 -        sta 3,@40       # save return address on stack
 70 -        lda 2,.L42-.,1  # get save word count
 71 -        jsr @45         # go to prolog
  86+        mov 3,0         # avoid trashing return address
  87+        jsr @prolog     # go to prolog
7288         ...
<>73 -        lda 2,.L42-.,1  # get restore word count
 74 -        jmp @46         # jump to epilog
  89+        jmp @epilog     # jump to epilog
7590 
<>76 -# words to save in 2, return address in 3
  91+#ifdef prolog
  92+        lda 0,sp
  93+        sta 3,@sp
  94+        lda 1,fp
  95+        sta 1,@sp
  96+        sta 0,fp
  97+        lda 1,[Css]
  98+        sub 1,0
  99+        sta 0,sp
  100+#endif
  101+
  102+...
  103+
  104+        lda 2,fp
  105+        lda 3,-1,2
  106+        lda 0,-2,2
  107+        sta 0,fp
  108+        sta 2,sp
  109+        jmp 0,3
  110+
  111+
  112+#
  113+# decrement from stack, and save permanent registers.
  114+#       push retreg
  115+#       push fp
  116+#       mov sp,fp
  117+#       sub $w,sp
  118+#       
  119+# prolog: return in ac3, fun in ac0.
  120+prolog: lda 1,sp
  121+        sta 0,@sp
  122+        lda 0,fp
  123+        sta 0,@sp
  124+        sta 1,fp
  125+        lda 0,-3,3
  126+        sub 0,1
  127+        sta 1,sp
  128+        jmp 0,3
  129+
  130+epilog: lda 3,fp
  131+        sta 3,sp
  132+        lda 3,@fp
  133+        lda 2,@fp
  134+        sta 2,fp
  135+        jmp 0,3
  136+
  137+        
  138+
  139+
  140+
  141+
  142+
77143 prolog:
<>78 -        sta 2,45        # save # of words to move at scratch
 79 -        lda 0,41        # get old fp
 80 -        lda 1,40        # get sp
 81 -        sta 1,41        # save new fp
 82 -        dsz 40          # decrement stack, will never be 0
 83 -        sta 0,@40       # save old fp
 84 -        dsz 40
  144+        lda 2,sp        # sp points to the first argument
  145+        sta 2,30        # store at auto-dec location
  146+        sta 0,@30       # store fun return address
  147+        lda 0,fp        # fetch old fp
  148+        sta 0,@30       # store saved fp
  149+        sta 2,fp        # save frame pointer
85150 
<>86 -        lda 0,off57     # fetch address of regs to save - 1
 87 -        sta 0,20        # store address at autoincr
 88 -1:      lda 0,@20       # get word to copy
 89 -        sta 0,@40       # push on stack
 90 -        dsz 40          # manually decrement sp
 91 -        dsz 45          # copied all words?
 92 -        jmp 1b,1        # no, continue
 93 -        jmp 0,3         # return
  151+        lda 0,-3,3      # stack size to subtract
  152+        neg 0,0,snr     # Any words?
  153+        jmp 1f          # no, get away
  154+        lda 1,$51       # fetch zp offset
  155+        sub 0,1         # get highest word
  156+        sta 1,31        # at auto-dec location
94157 
<> 158+2:      lda 1,@31       # fetch word to copy
  159+        sta 1,@30       # on stack
  160+        inc 0,0,szr     # count words
  161+        jmp 1b          # more to go
  162+
  163+1:      lda 0,30        # finished, get stackptr
  164+        sta 0,sp        #
  165+        jmp 0,3         # get back!
  166+
  167+# epilog, need save frame pointer in ac3
95168 epilog:
<>96 -        sta 2,45        # save # of words to move at scratch
  169+        lda 0,-3,3      # get words to save
  170+        neg 0,0,snr     # any words to save?
  171+        jmp 1f          # No, get out
97172 
<>98 -        lda 3,off57     # fetch address of regs to save
 99 -        sta 3,20        # store at autoincr
 100 -        lda 3,41        # fetch fp
 101 -        sta 3,30        # store at autodecr
 102 -        lda 3,@30       # get old fp
  173+        lda 1,$51       # get zp offset
  174+        sub 0,1         # Highest word
  175+        sta 1,31        # auto-dec loc
103176 
<>104 -1:      lda 2,@30       # fetch word from stack
 105 -        sta 2,@20       # store at orig place
 106 -        dsz 45          # enough?
 107 -        jmp 1b,1        # no, continue
  177+        lda 2,fp        # get fp
  178+        adczl 1,1       # -2
  179+        add 1,2         # 2 now offset
  180+        sta 2,30        # auto-dec loc
108181 
<>109 -        lda 2,41        # get new fp
 110 -        sta 2,40        # restore stack
 111 -        sta 3,41        # restore old fp
 112 -        jmp @40         # Return
  182+2:      lda 1,@30
  183+        sta 1,@31
  184+        inc 0,0,szr
  185+        jmp 2b
113186 
<> 187+1:      lda 2,fp        # fetch current fp
  188+        lda 3,-1,2      # return pc
  189+        lda 0,-2,2      # fetch old fp
  190+        sta 0,fp        # restore fp
  191+        sta 2,sp        # stack pointer restored
  192+        jmp 0,3         # Done!
  193+
  194+#if 0
114195 Assembler syntax and functions.
 115196 
<>116 -The assembler syntax mimics the DG assembler.
  197+The assembler syntax mimics the DG assembler but uses AT&T syntax.
117198 Load and store to addresses is written "lda 0,foo" to load from address foo.
 118199 If foo is not in zero page then the assembler will put the lda in the
 119200 text area close to the instruction and do an indirect pc-relative load.
 120201 
<_ 202+Arithmetic instruction:         
  203+        subsl#  %0,%1,snr               skip code may be omitted
  204+        subsl#  %0,%1
  205+
  206+Load/store/jmp/jsr/isz/dsz:
  207+        lda %1,@disp,2          or
  208+        mov *disp(%2),%1
  209+                index may be omitted if 0 (ZP)
  210+                disp can only be +-127 words.
  211+
  212+        It's allowed to write "mov $32,%0" which will be converted
  213+        to an indirect load by the assembler.
  214+
  215+        Example of AT&T arguments:
  216+                01234   - Zero-page
  217+                L11     - Relative.  Will be converted to
  218+                          indirect + addr if distance too long
  219+                (%2)    - indexed
  220+                012(%2) - indexed with offset
  221+                * in front of any of these will generate indirection
  222+#endif
  223+
  224+lbyte:  movr 2,2        # get byte ID into C bit
  225+        lda 0,,2        # word into ac0
  226+        mov 2,2,snc     # skip if right byte
  227+        movs 0,0        # swap bytes
  228+        jmp 0,3         # get back
  229+
  230+sbyte:  sta 3,@sp
  231+
  232+        movr 2,2        # get byte ID into C bit
  233+        lda 1,,2        # get word
  234+        lda 3,[377]     # get mask
  235+        and 3,0,snc     # clear left input + skip if right byte
  236+        movs 1,1        # swap bytes
  237+        and 3,1         # clear old bits
  238+        add 0,1,snc     # swap back if necessary
  239+        movs 1,1        # swap
  240+        sta 1,2
  241+
  242+        lda 3,sp
  243+        isz sp
  244+        jmp @0,3
  245+
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-11-01 00:49 +0100