Skip to content
Tactiverge
Level 4Registers and memoryWork it out

The program that rewrites itself

Bench-8 has no indexed addressing, so this program walks through memory by changing the operand byte of its own STA instruction (put+1 is the address of that operand).

After the program halts, what byte is stored at address 0xF2?

New to this? Silicon Studio 13: Basic memory

How results are computed: model assumptions.

Bench-8 listing
loop:   LDA val
put:    STA 0xF0
        LDA put+1
        ADD one
        STA put+1
        SUB last
        JZ  done
        LDA val
        ADD one
        STA val
        JMP loop
done:   HALT
val:    DB 5
one:    DB 1
last:   DB 0xF4