According to the DCPU specification, the only time a SET
instruction fails is if the a
value is a literal.
So would the following work?
SET [PC],0x1000
A more useful version would be setting an offset of PC
, so a rather strange infinite loop would be:
SET [PC+0x2],0x89C3 ; = SUB PC,0x2
Probably (= I think it should work but I didn't try).
This is called "self modifying" code and was quite common the 8bit era because of a) limited RAM and b) limited code size. Code like that is very powerful but error prone. If your code base grows, this can quickly become a maintenance nightmare.
Famous use cases:
JMP
)PC
values are in a completely different memory space to the stack/ram, so SET PC,###
cannot be made to jump onto the stack - Matt 2012-04-05 15:44
By using 0x18, 0x19, 0x1a as POP, PEEK and PUSH, there's a reverse stack starting at memory location 0xfff - Kevin Coffey 2012-04-05 23:58
There's no value for [PC], so I'm guessing you need to do it in a round-about way by storing PC in something you can use as a pointer (registry or memory).
SET A , PC SET [A+3], 0x8dc3 ; SUB PC, 3 (if A can't be changed from outside SUB PC,2 works too.)
A
after that statement would evaluate to a number, and then [A+3]
would refer to that position in memory, rather than in the code section - Matt 2012-04-05 17:36