README.md (4335B)
1 # Example guide for TISC Assembly Code -> "tac" 2 3 TODO: Implement some kind of variables / defines 4 5 TODO: Hardcoded string constant meta-instruction 6 7 ### Structure 8 9 Each assembly line must start with either a comment, 10 11 #Some words 12 13 An Instruction: 14 15 [opcode] [arguments] 16 17 Or a label, followed with an instruction, 18 19 [label]: [opcode] [arguments] 20 21 Please refer to the examples as reference. 22 23 ### Argument Legend 24 25 * `A<type>, B<type> , C<type>` specifies the positional arguments as types 26 27 * `<GR>` specifies the argument type as a General Register 28 * The following types are accepted: 29 * `GRA` General Purpose Register A 30 * `GRB` General Purpose Register B 31 * `GRC` General Purpose Register C 32 * `NIL` No register referenced 33 34 * `<label>` specifies the argument as a label 35 36 * `<0-15>` `<0-255>` specifies an integer value 37 * The following formats are accepted: 38 * Base 10 39 * Base 16: Prefixed with `0x` 40 * Base 2: Prefixed with `0b` 41 42 * `<bytes>` An array of integers within `<0-255>` e.g. `0xff,255,0b11111111` 43 44 ## 0 Argument Instructions 45 46 Push `GRA` to the stack 47 48 push 49 50 Pop the stack to `GRA` 51 52 pop 53 54 Peek the stack to `GRA` 55 56 peek 57 58 Pushes a byte from memory into stack. Uses the memory pointer 59 60 lbs 61 62 Pops from the stack into memory. Uses the memory pointer 63 64 sbs 65 66 Pops from the stack to use as the memory pointer 67 68 sps 69 70 Set ADD Operation for `cmp` and `op` instructions. `cmp` will flag if there is 71 an overflow. `op` will perform addition. 72 73 sop_add 74 75 Set SUBTRACT Operation for `cmp` and `op` instructions. `cmp` will flag if the 76 result has a positive sign. `op` will perform subtraction. 77 78 sop_sub 79 80 Set AND Operation for `cmp` and `op` instructions. `cmp` will flag if the result 81 is nonzero. `op` will perform bitwise AND. 82 83 sop_and 84 85 Set XOR Operation for `cmp` and `op` instructions. `cmp` will flag if the result 86 is nonzero. `op` will perform bitwise XOR. 87 88 sop_xor 89 90 Set XNOR Operation for `cmp` and `op` instructions. `cmp` will flag if the 91 result is nonzero. `op` will perform bitwise XNOR. 92 93 sop_xnor 94 95 Set CIN Operation for `cmp` and `op` instructions. `cmp` will flag if there is 96 an overflow. `op` will perform addition with the carry in set. 97 98 sop_cin 99 100 Set Left Shift operation for `cmp` and `op` instructions. `cmp` will flag if 101 there is overflow. `op` will perform A << B. 102 103 sop_lsh 104 105 Set Right Shift operation for `cmp` and `op` instructions. `cmp` will flag if 106 there is underflow. `op` will perform A >> B. 107 108 sop_rsh 109 110 Program Counter Return Address - pushes program counter return address to stack 111 112 pcr 113 114 Unconditionally branch to the address in `GRA` 115 116 goto 117 118 Increment memory pointer (set with the `sp` instruction) by `1` 119 120 ptrinc 121 122 ## 1 Argument Instructions 123 124 Meta-instruction that is identical to `li` that gets the assigned address of 125 the label to use as an immediate 126 127 getlabel A<label> 128 129 Load Lower Immediate to `GRA`, Least Significant 4 bits of a byte 130 131 lli A<0-15> 132 133 Load Immediate to `GRA`, next byte in program memory is used 134 135 li A<0-255> 136 137 Load `N` Bytes to `STACK`. `len(<bytes>)` must be > 1 138 > Note: This instruction loads a set of bytes on to the stack, in string form 139 or in byte array form 140 141 lni A<bytes> 142 143 Jumps to particular label unless the flag is set by the `cmp` instruction 144 executed prior to the `jmp` instruction. 145 146 jmp A<label> 147 148 Loads a byte from memory into the specified register. Uses the memory pointer 149 150 lb A<GR> 151 152 Stores a byte from the specified register into memory. Uses the memory pointer 153 154 sb A<GR> 155 156 Set the memory pointer from the specified register 157 158 sp A<GR> 159 160 # 2 Argument Instructions 161 162 Increment the specified register `A` and save in register `B` 163 164 cin A<GR> B<GR> 165 166 Move the contents of `A` to `B` 167 168 mov A<GR> B<GR> 169 170 Compare `A` and `B` and generate a flag based on the current compare operation 171 172 cmp A<GR> B<GR> 173 174 # 3 Argument Instructions 175 176 Logical OR the contents of `A` and `B`, store the result in `C` 177 178 or A<GR> B<GR> C<GR> 179 180 Logical NAND the contents of `A` and `B`, store the result in `C` 181 182 nand A<GR> B<GR> C<GR> 183 184 Perform the operation set with the `sop_*` opcode, with `A` and `B`, store the result in `C` 185 186 op A<GR> B<GR> C<GR> 187 188 # Assembler Instructions 189 190 > These instructions are meta-instructions that configure a parameter within the 191 assembler 192 193 Set the program address of the next instruction to the specified address in memory 194 195 segment A<0-255>