Commit c2024585 authored by bp's avatar bp

Forward label declaration


git-svn-id: https://www.forth-ev.de/repos/b16@290 3b8d8251-53f3-0310-8f3b-fd1cb8370982
parent d8f6c0c1
#! /usr/bin/gforth b16-asm.fs #! /usr/bin/gforth b16-asm.fs
: reset \ label reset : reset \ label reset
fw jmp \ jump forward to boot ' boot jmp \ jump forward to boot
: stack \ stack test : stack \ stack test
1 #c 2 #c 3 # \ fill stack with 1 2 3 4 5 6 7 8 9 A B 1 #c 2 #c 3 # \ fill stack with 1 2 3 4 5 6 7 8 9 A B
4 # 5 #c 6 #c 4 # 5 #c 6 #c
...@@ -52,11 +52,12 @@ ...@@ -52,11 +52,12 @@
0 # com cIF drop 5 # + THEN 0 # com cIF drop 5 # + THEN
0 #c 0 #c + -cIF drop 6 # + THEN 0 #c 0 #c + -cIF drop 6 # + THEN
; \ return to caller ; \ return to caller
: boot THEN \ resolve forward jump from reset : boot \ resolve forward jump from reset
stack \ call stack test stack \ call stack test
alu \ call ALU test alu \ call ALU test
$1234 # $5678 # mul \ multiply 1234 with 5678 (hex) $1234 # $5678 # mul \ multiply 1234 with 5678 (hex)
$789a # div drop drop \ divide by 789A, drop results $789a # div drop drop \ divide by 789A, drop results
jumps -jumps \ call jump tests jumps -jumps \ call jump tests
BEGIN jmp ; \ endless loop ; \ endless loop
.end \ end of test program .end \ end of test program
.hex
...@@ -274,9 +274,35 @@ Forth ...@@ -274,9 +274,35 @@ Forth
: .end inst, ; : .end inst, ;
: macro: : ; : macro: : ;
: end-macro postpone ; ; immediate : end-macro postpone ; ; immediate
: : Create inst, IP @ , DOES> @ inst, 1 jmp, ;
: | Create inst, IP @ , DOES> @ ; \ label handling
: ' ' >body @ ; : :-does DOES> @ inst, 1 jmp, ;
: |-does DOES> @ ;
: label-resolve ( addr -- )
cell+ @ BEGIN
dup -1 <> WHILE
dup >r @ $FC00 [ b16-asm ] THEN [ Forth ] r> cell+ @
REPEAT drop ;
: ?Create >in @ >r name find IF
rdrop lastcfa ! inst,
IP @ lastcfa @ >body !
lastcfa @ >body label-resolve
lastcfa @ >body cell+ off
ELSE drop r> >in ! Create inst, IP @ , 0 , THEN ;
: : ?Create :-does ;
: | ?Create |-does ;
: ' ( "name" -- addr )
>in @ >r name find
IF >body dup @ swap cell+
dup @ IF here IP @ , over @ , swap !
IP @ $FC00 and
ELSE drop THEN rdrop
ELSE
drop r> >in !
Create 0 , here cell+ , IP @ $FC00 and dup , -1 , |-does
THEN ;
$00 inst nop $00 inst nop
$01 2 insts3 exec goto $01 2 insts3 exec goto
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment