1%default {"preinstr":"", "result":"a0", "chkzero":"0"}
2    /*
3     * Generic 32-bit "lit8" 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     * CC (a1).  Useful for integer division and modulus.
10     *
11     * For: add-int/lit8, rsub-int/lit8, mul-int/lit8, div-int/lit8,
12     *      rem-int/lit8, and-int/lit8, or-int/lit8, xor-int/lit8,
13     *      shl-int/lit8, shr-int/lit8, ushr-int/lit8
14     */
15    /* binop/lit8 vAA, vBB, #+CC */
16    lbu     a3, 2(rPC)                  # a3 <- BB
17    lb      a1, 3(rPC)                  # a1 <- sign-extended CC
18    srl     a2, rINST, 8                # a2 <- AA
19    GET_VREG a0, a3                     # a0 <- vBB
20    .if $chkzero
21    beqz    a1, common_errDivideByZero  # is second operand zero?
22    .endif
23    FETCH_ADVANCE_INST 2                # advance rPC, load rINST
24    $preinstr                           # optional op
25    $instr                              # $result <- op, a0-a3 changed
26    GET_INST_OPCODE v0                  # extract opcode from rINST
27    SET_VREG $result, a2                # vAA <- $result
28    GOTO_OPCODE v0                      # jump to next instruction
29
30