| 178 | func createAx(op opCode, a int) instruction { return instruction(op)<<posOp | instruction(a)<<posAx } |
| 179 | |
| 180 | func (i instruction) String() string { |
| 181 | op := i.opCode() |
| 182 | s := opNames[op] |
| 183 | switch opMode(op) { |
| 184 | case iABC: |
| 185 | s = fmt.Sprintf("%s %d", s, i.a()) |
| 186 | if bMode(op) == opArgK && isConstant(i.b()) { |
| 187 | s = fmt.Sprintf("%s constant %d", s, constantIndex(i.b())) |
| 188 | } else if bMode(op) != opArgN { |
| 189 | s = fmt.Sprintf("%s %d", s, i.b()) |
| 190 | } |
| 191 | if cMode(op) == opArgK && isConstant(i.c()) { |
| 192 | s = fmt.Sprintf("%s constant %d", s, constantIndex(i.c())) |
| 193 | } else if cMode(op) != opArgN { |
| 194 | s = fmt.Sprintf("%s %d", s, i.c()) |
| 195 | } |
| 196 | case iAsBx: |
| 197 | s = fmt.Sprintf("%s %d", s, i.a()) |
| 198 | if bMode(op) != opArgN { |
| 199 | s = fmt.Sprintf("%s %d", s, i.sbx()) |
| 200 | } |
| 201 | case iABx: |
| 202 | s = fmt.Sprintf("%s %d", s, i.a()) |
| 203 | if bMode(op) != opArgN { |
| 204 | s = fmt.Sprintf("%s %d", s, i.bx()) |
| 205 | } |
| 206 | case iAx: |
| 207 | s = fmt.Sprintf("%s %d", s, i.ax()) |
| 208 | } |
| 209 | return s |
| 210 | } |
| 211 | |
| 212 | func opmode(t, a, b, c, m int) byte { return byte(t<<7 | a<<6 | b<<4 | c<<2 | m) } |
| 213 | |