1: \ PIE MISC assembler
2:
3: \ Copyright (C) 1998,2000,2003 Free Software Foundation, Inc.
4:
5: \ This file is part of Gforth.
6:
7: \ Gforth is free software; you can redistribute it and/or
8: \ modify it under the terms of the GNU General Public License
9: \ as published by the Free Software Foundation; either version 2
10: \ of the License, or (at your option) any later version.
11:
12: \ This program is distributed in the hope that it will be useful,
13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: \ GNU General Public License for more details.
16:
17: \ You should have received a copy of the GNU General Public License
18: \ along with this program; if not, write to the Free Software
19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20:
21: Vocabulary assembler
22: also assembler also definitions forth
23: \ [IFUNDEF] cross
24: \ : X ;
25: \ [THEN]
26:
27: \ sources
28:
29: $0 Constant PC $1 Constant PC+2
30: $2 Constant PC+4 $3 Constant PC+6
31:
32: $8 Constant ACCU $9 Constant SF
33: $A Constant ZF $C Constant CF
34:
35: \ destinations
36:
37: $0 Constant JMP $1 Constant JS
38: $2 Constant JZ $4 Constant JC
39:
40: $7 Constant *ACCU
41: ( $8 Constant ACCU ) $9 Constant SUB
42: ( $A Constant SUBR ) $B Constant ADD
43: $C Constant XOR $D Constant OR
44: $E Constant AND $F Constant SHR
45:
46: $FFFC Constant txd
47: $FFFF Constant rx?
48: $FFFE Constant rxd
49: \ $FFF0 Constant tx
50:
51: : end-label previous ;
52:
53: Create marks $10 cells allot
54:
55: : ahere X here 2/ ;
56:
57: : m ( n -- ) cells marks + ahere 2* swap ! 0 ;
58: : r ( n -- ) cells marks + @ ahere swap s" !" evaluate 0 ;
59:
60: \ intel hex dump
61:
62: : 0.r ( n1 n2 -- ) 0 swap <# 0 ?DO # LOOP #> type ;
63:
64: : tohex ( dest addr u -- ) base @ >r hex
65: ." :" swap >r >r
66: r@ dup 2 0.r over 4 0.r ." 00"
67: over 8 rshift + +
68: r> r> swap bounds ?DO I ( 1 xor ) c@ dup 2 0.r + LOOP
69: negate $FF and 2 0.r r> base ! ;
70:
71: : 2hex ( dest addr u -- )
72: BEGIN dup WHILE
73: >r 2dup r@ $10 min tohex cr
74: r> $10 /string 0 max rot $10 + -rot
75: REPEAT drop 2drop ;
76:
77: \ : sym
78: \ base @ >r hex
79: \ cr ." sym:s/PC=" ahere 4 0.r ." /" bl word count type ." /g" cr
80: \ r> base ! ;
81: : sym bl word drop ;
82:
83: : label
84: >in @ bl word count X here symentry >in !
85: ahere Constant ;
86:
87: : code
88: -1 ABORT" Need end-code or end-label before a new code definition" ;
89:
90: also forth definitions
91:
92: : label also assembler label ;
93:
94: : (code) also assembler ;
95: : (end-code) previous ;
96:
97: previous previous previous
98:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>