0

I've recently started to learn about SUBLEQ One Instruction Set Computers and am currently trying to write a simple assembler for a SUBLEQ emulator i wrote. So far I've implemented DB, MOV, INC and DEC, but I am struggling a bit with the MOV instruction, when it has pointers as arguments.
For example: MOV 20, 21 to move data from address 21 to address 20 in SUBLEQ looks like this (assuming address 100 is zero and the program starts at address zero):

sble 20 20 3
sble 21 100 6
sble 100 20 9

The content at the target address is zeroed and the content at the source address is added to the destination by subtracting it two times.

Now to my problem: If one argument is a pointer, for example MOV 20, [21] so that the contents of address 21 are pointing to the real data I want to to copy to address 20, how can that be represented using SUBLEQ?

Merlin0216
  • 39
  • 1
  • 5

1 Answers1

1

I'll start off by saying I know very little about how subleq is used in practice, so take this answer with a grain of salt:

One downside of subleq is that it is notoriously difficult to use pointers, but it can edit its own code. This means that you will have to use the code to rewrite the address being looked at with the value at 21.

for example, if you somehow got the code to go to a line appended after your current code you could use this:

# (I used the quotes to mean next line)
sble 3 3 " # set the first value of the second instruction to 0
sble 21 101 " # put the value of 21 into an unused address
sble 101 3 " # subtract the value of 101 and put it back into the code
sble 3 3 " # reset the value at 3 to 0

it might be a good decision to have to have a movp (move-pointer) command, so you don't accidentally mess up your mov command code at runtime

this means that a new method of using pointers has to be thought of differently for every problem someone comes across, but will usually be done by editing the code with the code