tisc

tiny instruction set computer
Log | Files | Refs | README

weird_loop_test.tac (895B)


      1 # weird_loop_test - exemplifies the ability to modify executing memory when the
      2 #                   program is running from the internal RAM instead of an
      3 #                   external ROM. The program will calculate two addresses that
      4 #                   are used to write out to memory, overwriting the jmp address
      5 start: jmp weird
      6 loop:  jmp loop
      7 # offset this bit of code
      8        segment 0x42
      9 # push the return address
     10 weird: pcr
     11 # calculate the memory address, and the jump address we will use
     12        lli 5
     13        mov GRA GRC
     14 # these instructions calculate the jump address
     15        pop
     16        op GRA GRC GRA
     17 # this instruction calculates the memory address (+1 from the jump address)
     18        cin GRA GRB
     19 # write out to memory now that we know our memory address + jump address
     20        sp GRB
     21        sb GRA
     22 # after the last two instructions, this instruction will jump to itself.
     23        jmp loop