home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-06 | 5.2 KB | 191 lines | [TEXT/ttxt] |
- \ Assembler ReeseWarner 3/85
- \ 02/28/86 GDC Fixed :MCODE
- \ 7/10/86 mrh Fixed ASM to accept a label on a blank line
- \ 6/06/93 rfl added documentation fix...since double pass assm, need to
- \ divide line# by 2.
-
- 0 -> dlevel
-
- 0 value endLen
- 0 value endAddr
-
- : MOVEBACK
- addr: topFile 3 charCount negate (lseek) drop
- ;
-
- : INITP { #pass -- }
- #pass -> pass
- 0 -> charCount
- tiblen -> pos
- 0 -> linect
- 0 -> codePos
- 0 -> errflag
- 0 -> storedToken
- ;
-
- \ Eliminates any blank lines
- : KILLEOLS ( -- )
- BEGIN
- nextToken 4 = not
- UNTIL
- ;
-
- : DOMIDDLE
- msg" top"
- errflag
- IF \ if error then
- 211 asmError \ abort
- abort
- ELSE \ else
- moveBack \ set up pass 2
- 2 initP
- THEN
- ;
-
- \ Assemble instructions, main control loop
- : ASM { \ mnemonic endFlag -- }
- false -> endFlag
- BEGIN
- endFlag
- IF \ if end flag then
- false \ get out of loop
- ELSE \ else
- KillEols \ get rid of blank lines
- start: token \ get a token
- EndAddr EndLen get: token s= not val" ENDflag F=Found"
- THEN \ if end of asm code then exit
- WHILE
- token query: codes -> mnemonic \ get label of opcode
- mnemonic val" mnemonic is" 0= \ check for label
- IF \ Label
- msg" It's a label!"
- pass 1 =
- IF \ if pass 1 then
- codePos 2* token enter: symtab \ put label on simtab
- THEN
- ELSE
- opsize: mnemonic -> opSize
- mnemonic val" final mnemonic is" 0=
- IF
- true -> endFlag \ end of asm code
- ELSE
- pass 1 =
- IF
- length: mnemonic \ dup . cr \ for debuging
- ++> codePos \ add length to codepos
- ELSE
- here -> keephere \ builds bit codes
- build: mnemonic
- here keephere - ++> codePos
- THEN
- THEN
- THEN
- REPEAT
- pass 1 =
- IF
- doMiddle
- ASM msg" after pass-2" \ starts pass 2 recursively
- ELSE
- msg" pre-next"
- [compile] next,
- msg" post-next"
- THEN
- ;
-
- TRUE value InitASM? \ jaf 12/13 has ASM been init'd?
-
- 2 0 0 to: next.state
- 1 0 1 to: next.state
- 0 0 2 to: next.state
- 0 0 3 to: next.state
- 0 1 0 to: next.state
- 1 1 1 to: next.state
- 0 1 2 to: next.state
- 0 1 3 to: next.state
- 2 2 0 to: next.state
- 2 2 1 to: next.state
- 0 2 2 to: next.state
- 0 2 3 to: next.state
-
- 0 0 0 to: action
- 0 0 1 to: action
- 2 0 2 to: action
- 4 0 3 to: action
- 1 1 0 to: action
- 0 1 1 to: action
- 1 1 2 to: action
- 1 1 3 to: action
- 0 2 0 to: action
- 0 2 1 to: action
- 3 2 2 to: action
- 3 2 3 to: action
-
- : InitASM { \ xecho -- } \ jaf 12/13 created asm init word
-
- new: token
- decho -> xecho -echo \ Preserve echo status
- " Operands" loadOps \ get operands in "operands"
- " AsmCodes" loadcodes \ get opcode codes in AsmCodes
- false -> InitASM?
- xecho -> decho \ Restore echo status
- ;
-
- : EndASM \ jaf 12/13 use when done with ASM
- dispose: codes
- dispose: operands
- dispose: symTab
- release: token
- TRUE -> INITASM?
- ;
-
- 0 value keepLine
- \ :CODE - word exported to dictionary. Begins compilation of code word
- : :CODE
- " ;CODE" -> endLen -> endAddr
- dispose: symTab
- create \ start the :code definition
- line# -> keepLine
- 0 -> line#
- InitASM? IF InitASM THEN \ jaf 12/13 init ASM if not already done
- 1 initP
- asm \ does the work
- msg" post-asm"
- line# 2/ keepLine + -> line#
- query: topfile drop
- ;
-
- \ ADD-HDR-CODE - this word ,'s in the appropriate machine instructions to
- \ set up a code method definition. Whatever they might be.
- : ADD-HDR-CODE
- here 24 + , \ 0CFA - for public objects
- here 4+ , \ 1CFA - for ivars
- $ 301C w, \ move.w (a4)+,d0
- $ 6C02 w, \ bge +2
- $ 4280 w, \ clr.l d0
- $ 2445 w, \ movea.l d5,a2
- $ 2452 w, \ movea.l (a2),a2
- $ D5C0 w, \ adda.l d0,a2
- $ 4EFA0004 , \ JMP to code
- $ 245F w, \ movea.l (a7)+,a2
- ;
-
- \ :MCODE - word exported to dictionary. Begins compilation of code method
- : :MCODE { \ selID -- } ?class
- " ;MCODE" -> endLen -> endAddr
- dispose: symTab
- getSelect -> selID
- selID ^class mfa ((findm)) \ is method already defined
- IF
- here count type ." method redefined as code" cr drop \ drop method addr
- THEN
- here selID w, \ name is selector's hashed value
- ^class mfa dup @ \ get mfa, old link
- , ! \ establish the links
- add-hdr-code
- InitASM? IF InitASM THEN \ jaf 12/13 init ASM if not already done
- 1 initP
- asm
- query: topfile drop
- ;
- immediate
-