Can you write on [pc]?

According to the DCPU specification, the only time the SET command fails is that the value of a is a literal.

So will the following work:

 SET [PC],0x1000 

A more useful version would be to set the offset of the PC , so a rather strange endless loop:

 SET [PC+0x2],0x89C3 ; = SUB PC,0x2 
+7
source share
2 answers

Probably (= I think it should work, but I have not tried).

This is called "self-modifying" code and is fairly common in the 8-bit era due to: a) limited RAM and b) limited code size. Such code is very powerful, but error prone. If your code base is growing, it can quickly become a maintenance nightmare.

Known use cases:

  • Windows 95 used such code to create graphics rendering code on the stack.
  • Viruses and trojans use this as an attack vector (write code on the stack or manipulate return addresses to use JMP )
  • Simulate switch statements on C64
+7
source

There is no value for [PC], so I assume that you need to do this in a circular way, keeping the PC in what 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.)
+4
source

All Articles