1%default {"preinstr":"", "result":"a0", "chkzero":"0"}
2    /*
3     * Generic 32-bit "lit16" binary operation.  Provide an "instr" line
4     * that specifies an instruction that performs "result = a0 op a1".
5     * This could be an MIPS instruction or a function call.  (If the result
6     * comes back in a register other than a0, you can override "result".)
7     *
8     * If "chkzero" is set to 1, we perform a divide-by-zero check on
9     * CCCC (a1).  Useful for integer division and modulus.
10     *
11     * For: add-int/lit16, rsub-int, mul-int/lit16, div-int/lit16,
12     *      rem-int/lit16, and-int/lit16, or-int/lit16, xor-int/lit16
13     */
14    /* binop/lit16 vA, vB, #+CCCC */
15    lh      a1, 2(rPC)                  # a1 <- sign-extended CCCC
16    ext     a2, rINST, 8, 4             # a2 <- A
17    ext     a3, rINST, 12, 4            # a3 <- B
18    GET_VREG a0, a3                     # a0 <- vB
19    .if $chkzero
20    beqz    a1, common_errDivideByZero  # is second operand zero?
21    .endif
22    FETCH_ADVANCE_INST 2                # advance rPC, load rINST
23    $preinstr                           # optional op
24    $instr                              # $result <- op, a0-a3 changed
25    GET_INST_OPCODE v0                  # extract opcode from rINST
26    SET_VREG $result, a2                # vA <- $result
27    GOTO_OPCODE v0                      # jump to next instruction
28
29