tisc

tiny instruction set computer
Log | Files | Refs | README

test_segments.tac (2588B)


      1 # test_segment - This file demonstrates how to call and return between segments
      2 #                of memory that expands the program memory size limit to 0xFFFF
      3 #
      4 # The program counter of the TISC is only able to address the 8-bit space: this
      5 # allows for an architecture that uses an absolute one byte unit as the atomic
      6 # size for processing instruction metadata. This program explores expanding the
      7 # executable instruction space to a 16-bit space.
      8 #
      9 # The method in which we are able to expand the executable instruction space is
     10 # through the use of external instruction memory with a writable register mapped
     11 # to a 8-bit RAM space.
     12 
     13 #-------------------------------------------------0x00 SEGMENT START------------
     14 #-------------------------------------------------0x00 SEGMENT INDEX START------
     15 # Segment index, responsible for "routing" calls to other segments
     16 # Expects:
     17 #     GRA = jump address in new segment
     18 #     GRB = new segment address
     19 index@00: nand NIL NIL GRC
     20           sp GRC # the segment address location is 0xFF on MMIO
     21           lbs    # push our current segment to the stack
     22           sb GRB # set the segment address we should be in
     23 #                  the next instruction will be at the same PC address but in 
     24 #                  the segment we set. e.g. 0x0004 -> 0xFF04 if GRB = 0xFF
     25 #
     26 # Since this is in segment 0x00, we must test if we are just starting
     27           sop_and
     28           cmp GRA GRA  # test if the jump pointer is null
     29           jmp begin@00 # jump to the actual beginning of the program
     30           goto         # jump to the pointer if it isn't 0
     31 #-------------------------------------------------0x00 SEGMENT INDEX END--------
     32 #
     33 begin@00: lli 0x1 # segment address
     34           mov GRA GRB
     35           getlabel test@01 # get the address of our target function in 0x01
     36           pcr
     37           jmp index@00
     38           pop
     39 loop@00:  jmp loop@00
     40 #-------------------------------------------------0x00 SEGMENT END--------------
     41 #-------------------------------------------------0x01 SEGMENT START------------
     42 #-------------------------------------------------0x01 SEGMENT INDEX START------
     43 segment 0x0100
     44 index@01: nand NIL NIL GRC
     45           sp GRC
     46           lbs
     47           sb GRB
     48           goto
     49 #-------------------------------------------------0x01 SEGMENT INDEX END--------
     50 # set this bit of code in a random spot of memory within the 0x01 segment
     51 segment 0x019F
     52 test@01: pop # pop the segment address
     53       mov GRA GRB
     54       pop # pop the return address
     55       jmp index@01
     56 #-------------------------------------------------0x01 SEGMENT END--------------