-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hi
There's this guide Moonforth to build a Forth for the DCPU-16. You can run the code interactively but it's not as nice as using your debugger. Thus I used the code from the first example and everything was working great.
But then I noticed that the ADD-command wasn't executed. I compared the generated object code from both assemblers and lo and behold: your assembler appears to ignore this label. I imagined that the reason could be that ADD is a key-word for the assembler and changed the label to ADDER. With this workaround everything works fine.
I'm not familiar with the specification of the DCPU-16 and thus it might be correct as it's currently implemented. On the other hand I assume that there shouldn't be a problem using a key-word as a label.
I've included the aforementioned code below. However I assume there is a minor bug in the original. A comma is missing in this assignment instruction:
:LOOP_XTO
SET PC, LOOP_XTO
Kind regards
:START SET PC, MAIN ; JUMP MAIN
:NEXT
:WORD_FROM_CODE
SET J, [I] ; WORD-R <- *CODE-R
:NEXT_WORD
ADD I, 0x01 ; CODE-R++
:JUMP_INTO_XTO
SET PC, [J] ; JUMP *WORD-R
:ENTER
:R_PUSH
SET [Z], I ; *RET-R <- CODE-R (PUSH PART 1)
ADD Z, 0x01 ; RET-R++ (PUSH PART 2)
:WORD_AFTER_XTO
SET I, J ; CODE-R <- WORD-R
ADD I, 0x01 ; CODE-R++
SET PC, NEXT ; JUMP NEXT
:EXIT
DAT EXIT_XTO
:EXIT_XTO
:R_POP
SUB Z, 0x01 ; RET-R-- (POP PART 1)
SET I, [Z] ; CODE-R <- *RET-R (POP PART 2)
SET PC, NEXT ; JUMP NEXT
:DOUBLE
DAT ENTER DUP ADD EXIT
:DUP
DAT DUP_XTO
:DUP_XTO
SET PUSH, PEEK ; STACK DUP
SET PC, NEXT ; JUMP NEXT
:ADD
DAT ADD_XTO
:ADD_XTO
SET X, POP ; STACK POP
ADD PEEK, X ; ADD X to top of stack
SET PC, NEXT ; JUMP NEXT
:LOOP
DAT LOOP_XTO
:LOOP_XTO
SET PC LOOP_XTO
:CODE_1 DAT DOUBLE
:CODE_2 DAT DUP
:CODE_3 DAT LOOP
:MAIN
SET I, CODE_1 ; CODE-R <- CODE_1
SET PUSH, 0x05 ; STACK PUSH 0x05
SET PC, NEXT ; JUMP NEXT