version 1.3, 1999/10/13 13:00:07
|
version 1.5, 2000/06/17 19:38:28
|
Line 2
|
Line 2
|
\ bernd thallner 9725890 881 |
\ bernd thallner 9725890 881 |
\ assembler in forth for alpha |
\ assembler in forth for alpha |
|
|
\ requires code.fs |
\ require ../../code.fs |
|
|
\ also assembler definitions |
get-current |
|
also assembler definitions |
|
|
\ register |
\ register |
|
|
Line 24
|
Line 25
|
$d constant s4 |
$d constant s4 |
$e constant s5 |
$e constant s5 |
$f constant fp |
$f constant fp |
$10 constant a0 |
\ commented out to avoid shadowing hex numbers |
$11 constant a1 |
\ $10 constant a0 |
$12 constant a2 |
\ $11 constant a1 |
$13 constant a3 |
\ $12 constant a2 |
$14 constant a4 |
\ $13 constant a3 |
$15 constant a5 |
\ $14 constant a4 |
|
\ $15 constant a5 |
$16 constant t8 |
$16 constant t8 |
$17 constant t9 |
$17 constant t9 |
$18 constant t10 |
$18 constant t10 |
Line 79 endif
|
Line 81 endif
|
4 allot |
4 allot |
; |
; |
|
|
\ format |
\ operands |
|
|
: Bra ( oo ) \ branch instruction format |
: check-range ( u1 u2 u3 -- ) |
create , |
within 0= -24 and throw ; |
does> ( ra, branch_disp, addr ) |
|
@ 26 lshift |
: rega ( rega code -- code ) |
swap $1fffff and or |
\ ra field, named rega to avoid conflict with register ra |
swap $1f and 21 lshift or h, |
swap dup 0 $20 check-range |
; |
21 lshift or ; |
|
|
: Mbr ( oo.h ) \ memory branch instruction format |
: rb ( rb code -- code ) |
create 2, |
swap dup 0 $20 check-range |
does> ( ra, rb, hint, addr ) |
16 lshift or ; |
2@ 14 lshift |
|
swap 26 lshift or |
: rc ( rc code -- code ) |
swap $3fff and or |
swap dup 0 $20 check-range |
swap $1f and 16 lshift or |
or ; |
swap $1f and 21 lshift or |
|
h, |
: hint ( addr code -- code ) |
; |
swap 2 rshift $3fff and or ; |
|
|
: F-P ( oo.fff ) \ floating-point operate instruction format |
: disp ( n code -- code ) |
create 2, |
swap dup -$8000 $8000 check-range |
does> ( fa, fb, fc, addr ) |
$ffff and or ; |
2@ 5 lshift |
|
swap 26 lshift or |
: branch-disp ( addr code -- code ) |
swap $1f and or |
swap here 4 + - |
swap $1f and 16 lshift or |
dup 3 and 0<> -24 and throw |
swap $1f and 21 lshift or |
dup -$100000 $100000 check-range |
h, |
$1fffff and or ; |
; |
|
|
: imm ( u code -- code ) |
: Mem ( oo ) \ memory instruction format |
swap dup 0 $100 check-range |
create , |
13 lshift or ; |
does> ( ra, memory_disp, rb, addr ) |
|
@ 26 lshift |
: palcode ( u code -- code ) |
swap $1f and 16 lshift or |
swap dup 0 $4000000 check-range or ; |
swap $ffff and or |
|
swap $1f and 21 lshift or |
\ formats |
h, |
|
; |
: Bra ( opcode -- ) \ branch instruction format |
|
create 26 lshift , |
: Mfc ( oo.ffff ) \ memory instruction with function code format |
does> ( rega target-addr -- ) |
create 2, |
@ branch-disp rega h, ; |
does> ( ra, rb, addr ) |
|
2@ |
: Mbr ( opcode hint -- ) \ memory branch instruction format |
swap 26 lshift or |
create 14 lshift swap 26 lshift or , |
swap $1f and 16 lshift or |
does> ( rega rb hint -- ) |
swap $1f and 21 lshift or |
@ hint rb rega h, ; |
h, |
|
; |
: F-P ( opcode func -- ) \ floating-point operate instruction format |
|
create 5 lshift swap 26 lshift or , |
: Opr ( oo.ff ) \ operate instruction format |
does> ( fa fb fc -- ) |
create 2, |
@ rc rb rega h, ; |
does> ( ra, rb, rc, addr ) |
|
2@ |
: Mem ( opcode -- ) \ memory instruction format |
5 lshift |
create 26 lshift , |
swap 26 lshift or |
does> ( rega memory_disp rb -- ) |
swap $1f and or |
@ rb disp rega h, ; |
swap $1f and 16 lshift or |
|
swap $1f and 21 lshift or |
: Mfc ( opcode func -- ) \ memory instruction with function code format |
h, |
create swap 26 lshift or , |
; |
does> ( rega rb -- ) |
|
@ rb rega h, ; |
: Opr# ( oo.ff ) \ operate instruction format |
|
create 2, |
: Opr ( opcode.ff ) \ operate instruction format |
does> ( ra, lit, rc, addr ) |
create 5 lshift swap 26 lshift or , |
2@ |
does> ( rega rb rc -- ) |
5 lshift |
@ rc rb rega h, ; |
swap 26 lshift or |
|
1 12 lshift or |
: Opr# ( opcode func -- ) \ operate instruction format |
swap $1f and or |
create 5 lshift swap 26 lshift or 1 12 lshift or , |
swap $ff and 13 lshift or |
does> ( rega imm rc -- ) |
swap $1f and 21 lshift or |
@ rc imm rega h, ; |
h, |
|
; |
: Pcd ( opcode -- ) \ palcode instruction format |
|
create 26 lshift , |
: Pcd ( oo ) \ palcode instruction format |
does> ( palcode addr -- ) |
create , |
@ palcode h, ; |
does> ( palcode, addr ) |
|
@ 26 lshift |
|
swap $3ffffff and or |
|
h, |
|
; |
|
|
|
\ instructions |
\ instructions |
|
|
Line 191 $38 Bra blbc,
|
Line 188 $38 Bra blbc,
|
$3c Bra blbs, |
$3c Bra blbs, |
$3b Bra ble, |
$3b Bra ble, |
$3a Bra blt, |
$3a Bra blt, |
$3d Bra bne, |
$3d Bra bne, |
$30 Bra br, |
$30 Bra br, |
$34 Bra bsr, |
$34 Bra bsr, |
$00 Pcd call_pal, |
$00 Pcd call_pal, |
Line 400 $12 $30 Opr# zap#,
|
Line 397 $12 $30 Opr# zap#,
|
$12 $31 Opr zapnot, |
$12 $31 Opr zapnot, |
$12 $31 Opr# zapnot#, |
$12 $31 Opr# zapnot#, |
|
|
\ structures |
\ conditions |
|
|
|
' beq, constant ne |
|
' bge, constant lt |
|
' bgt, constant le |
|
' blbc, constant lbs |
|
' blbs, constant lbc |
|
' ble, constant gt |
|
' blt, constant ge |
|
' bne, constant eq |
|
' fbeq, constant fne |
|
' fbge, constant flt |
|
' fbgt, constant fle |
|
' fble, constant fgt |
|
' fblt, constant fge |
|
' fbne, constant feq |
|
|
|
\ control structures |
|
|
\ <register_number> if, <if_code> [ else, <else_code> ] endif, |
\ <register_number> if, <if_code> [ else, <else_code> ] endif, |
|
|
|
\ : magic-asm ( u1 u2 -- u3 u4 ) |
|
\ \ turns a magic number into an asm-magic number or back |
|
\ $fedcba0987654321 xor ; |
|
|
|
\ : patch-branch ( branch-delay-addr target-addr -- ) |
|
\ \ there is a branch just before branch-delay-addr; PATCH-BRANCH |
|
\ \ patches this branch to branch to target-addr |
|
\ over - ( branch-delay-addr rel ) |
|
\ swap cell - dup >r ( rel branch-addr R:branch-addr ) |
|
\ @ asm-rel r> ! ; \ !! relies on the imm field being 0 before |
|
|
|
|
|
|
: ahead, ( -- asmorig ) |
: ahead, ( -- asmorig ) |
31 0 br, |
31 0 br, |
here 4 - |
here 4 - |
Line 458 $12 $31 Opr# zapnot#,
|
Line 485 $12 $31 Opr# zapnot#,
|
endif, |
endif, |
; |
; |
|
|
\ jump marks |
\ \ jump marks |
|
|
\ example: |
\ \ example: |
|
|
|
\ \ init_marktbl \ initializes mark table |
|
\ \ 31 0 br, |
|
\ \ 0 store_branch \ store jump address for mark 0 |
|
\ \ 1 2 3 addf, |
|
\ \ 0 set_mark \ store mark 0 |
|
\ \ 2 3 4 addf, |
|
\ \ 2 0 beq, |
|
\ \ 0 store_branch \ store jump address for mark 0 |
|
\ \ calculate_marks \ calculate all jumps |
|
|
|
\ \ with <mark_address> <jump_address> calculate_branch you can calculate the |
|
\ \ displacement field without the mark_table for one branch |
|
|
|
\ \ example: |
|
\ \ here 31 0 br, |
|
\ \ here 1 2 3 addf, |
|
\ \ calculate_branch |
|
|
|
\ 5 constant mark_numbers |
|
\ 5 constant mark_uses |
|
|
|
\ create mark_table |
|
\ mark_numbers mark_uses 1+ * cells allot |
|
|
|
\ : init_marktbl ( -- ) \ initializes mark table |
|
\ mark_table mark_numbers mark_uses 1+ * cells + |
|
\ mark_table |
|
\ begin |
|
\ over over > |
|
\ while |
|
\ dup 0 swap ! |
|
\ 1 cells + |
|
\ repeat |
|
\ drop drop |
|
\ ; |
|
|
|
\ : set_mark ( mark_number -- ) \ sets mark, store address in mark table |
|
\ dup mark_numbers >= abort" error, illegal mark number" |
|
\ mark_uses 1+ * cells |
|
\ mark_table + here 8 - swap ! |
|
\ ; |
|
|
|
\ : store_branch ( mark_number -- ) \ stores address of branch in mark table |
|
\ dup mark_numbers >= abort" error, illegal mark number" |
|
\ mark_uses 1+ * cells |
|
\ mark_table + 1 cells + |
|
\ dup mark_uses cells + swap |
|
\ begin |
|
\ over over > over @ and |
|
\ while |
|
\ 1 cells + |
|
\ repeat |
|
\ swap over = abort" error, not enough space in mark_table, increase mark_uses" |
|
\ here 4 - swap ! |
|
\ ; |
|
|
|
\ : calculate_branch ( mark_addr branch_addr -- ) \ calculate branch displacement field for one branch |
|
\ swap over - 4 + 4 / |
|
\ $1fffff and |
|
\ over h@ or swap h! |
|
\ ; |
|
|
|
\ : calculate_mark ( tb mark_address -- tb ) \ calculates branch displacement field for one mark |
|
\ over 1 cells + |
|
\ dup mark_uses cells + swap |
|
\ begin |
|
\ over over > |
|
\ while |
|
\ 2over swap drop ( ei i markaddr ej j markaddr ) |
|
\ over @ |
|
\ dup if |
|
\ calculate_branch |
|
\ else |
|
\ drop drop |
|
\ endif |
|
\ 1 cells + |
|
\ repeat drop drop drop |
|
\ ; |
|
|
|
\ : calculate_marks ( -- ) \ calculates branch displacement field for all marks |
|
\ mark_table mark_numbers 1- mark_uses 1+ * cells + |
|
\ mark_table |
|
\ begin |
|
\ over over >= |
|
\ while |
|
\ dup @ |
|
\ dup if \ used mark |
|
\ calculate_mark |
|
\ else |
|
\ drop |
|
\ endif |
|
\ mark_uses 1+ cells + |
|
\ repeat |
|
\ drop drop |
|
\ ; |
|
|
|
previous set-current |
|
|
\ init_marktbl \ initializes mark table |
|
\ 31 0 br, |
|
\ 0 store_branch \ store jump address for mark 0 |
|
\ 1 2 3 addf, |
|
\ 0 set_mark \ store mark 0 |
|
\ 2 3 4 addf, |
|
\ 2 0 beq, |
|
\ 0 store_branch \ store jump address for mark 0 |
|
\ calculate_marks \ calculate all jumps |
|
|
|
\ with <mark_address> <jump_address> calculate_branch you can calculate the |
|
\ displacement field without the mark_table for one branch |
|
|
|
\ example: |
|
\ here 31 0 br, |
|
\ here 1 2 3 addf, |
|
\ calculate_branch |
|
|
|
5 constant mark_numbers |
|
5 constant mark_uses |
|
|
|
create mark_table |
|
mark_numbers mark_uses 1+ * cells allot |
|
|
|
: init_marktbl ( -- ) \ initializes mark table |
|
mark_table mark_numbers mark_uses 1+ * cells + |
|
mark_table |
|
begin |
|
over over > |
|
while |
|
dup 0 swap ! |
|
1 cells + |
|
repeat |
|
drop drop |
|
; |
|
|
|
: set_mark ( mark_number -- ) \ sets mark, store address in mark table |
|
dup mark_numbers >= abort" error, illegal mark number" |
|
mark_uses 1+ * cells |
|
mark_table + here 8 - swap ! |
|
; |
|
|
|
: store_branch ( mark_number -- ) \ stores address of branch in mark table |
|
dup mark_numbers >= abort" error, illegal mark number" |
|
mark_uses 1+ * cells |
|
mark_table + 1 cells + |
|
dup mark_uses cells + swap |
|
begin |
|
over over > over @ and |
|
while |
|
1 cells + |
|
repeat |
|
swap over = abort" error, not enough space in mark_table, increase mark_uses" |
|
here 4 - swap ! |
|
; |
|
|
|
: calculate_branch ( mark_addr branch_addr -- ) \ calculate branch displacement field for one branch |
|
swap over - 4 + 4 / |
|
$1fffff and |
|
over h@ or swap h! |
|
; |
|
|
|
: calculate_mark ( tb mark_address -- tb ) \ calculates branch displacement field for one mark |
|
over 1 cells + |
|
dup mark_uses cells + swap |
|
begin |
|
over over > |
|
while |
|
2over swap drop ( ei i markaddr ej j markaddr ) |
|
over @ |
|
dup if |
|
calculate_branch |
|
else |
|
drop drop |
|
endif |
|
1 cells + |
|
repeat drop drop drop |
|
; |
|
|
|
: calculate_marks ( -- ) \ calculates branch displacement field for all marks |
|
mark_table mark_numbers 1- mark_uses 1+ * cells + |
|
mark_table |
|
begin |
|
over over >= |
|
while |
|
dup @ |
|
dup if \ used mark |
|
calculate_mark |
|
else |
|
drop |
|
endif |
|
mark_uses 1+ cells + |
|
repeat |
|
drop drop |
|
; |
|