I like weird machines. Bonus points if they are small, or fast, or extra weird.

In the previous post, we designed a wierd machine 3BINS interpreter:

// run(payload, payload_length)
usize run(u32 *pl, usize p_len) {
    u8 *m = calloc(0xFFFF + 0xFF, sizeof(u8));
    for (
        ;
        ( dbg0 ) | (
            ( !(m32(BSR) & 0x00000001) || ((p_len = (usize)m)*0 | (usize)(m = malloc(0)) * 0) ) &&
            ( m32(BPC) < p_len-1 )
        );
        (
            (/* MOV */ (OP_M(BPC_OP) == 0x00000000) && (
                /* MOV */  ( (!FLG16_M(BPC_OP) && !FLGC_M(BPC_OP)) && (m16(ARG1_12_M(BPC_OP)) = m16(ARG2_12_M(BPC_OP)))             +1) ||
                /* MMI */  ( (!FLG16_M(BPC_OP) &&  FLGC_M(BPC_OP)) && (m16(ARG1_12_M(BPC_OP)) = ARG2_12_M(BPC_OP))                  +1) ||
                /* MOVW */ ( ( FLG16_M(BPC_OP) && !FLGC_M(BPC_OP)) && (m16(m16(ARG1_12_M(BPC_OP))) = m16(m16(ARG2_12_M(BPC_OP))))   +1) ||
                /* MMIW */ ( ( FLG16_M(BPC_OP) &&  FLGC_M(BPC_OP)) && (m16(BT1_M(BPC_OP)) = ARG2_16_M(BPC_OP))                      +1)
            )) ||
            (/* ADD */ (OP_M(BPC_OP) == 0x20000000) && (
                /* ADD */  ( (!FLG16_M(BPC_OP) ) && (m16(ARG1_12_M(BPC_OP)) += m16(ARG2_12_M(BPC_OP)))                              +1) ||
                /* ADDW */ ( ( FLG16_M(BPC_OP) ) && (m16(m16(ARG1_12_M(BPC_OP))) += m16(m16(ARG2_12_M(BPC_OP))))                    +1)
            )) ||
            (/* SUB */ (OP_M(BPC_OP) == 0x40000000) && (
                /* SUB */  ( (!FLG16_M(BPC_OP) ) && (m16(ARG1_12_M(BPC_OP)) -= m16(ARG2_12_M(BPC_OP)))                              +1) ||
                /* SUBW */ ( ( FLG16_M(BPC_OP) ) && (m16(m16(ARG1_12_M(BPC_OP))) -= m16(m16(ARG2_12_M(BPC_OP))))                    +1)
            )) ||
            (/* OR  */ (OP_M(BPC_OP) == 0x60000000) && (
                /* OR */  ( (!FLG16_M(BPC_OP) ) && (m16(ARG1_12_M(BPC_OP)) = m16(ARG1_12_M(BPC_OP)) | m16(ARG2_12_M(BPC_OP)))                +1) ||
                /* ORW */ ( ( FLG16_M(BPC_OP) ) && (m16(m16(ARG1_12_M(BPC_OP))) = m16(m16(ARG1_12_M(BPC_OP))) | m16(m16(ARG2_12_M(BPC_OP)))) +1)
            )) ||
            (/* NOT */ (OP_M(BPC_OP) == 0x80000000) && (
                /* NOT */  ( (!FLG16_M(BPC_OP) ) && (m16(ARG1_12_M(BPC_OP)) = !m16(ARG1_12_M(BPC_OP)))                +1) ||
                /* NOTW */ ( ( FLG16_M(BPC_OP) ) && (m16(m16(ARG1_12_M(BPC_OP))) = !m16(m16(ARG1_12_M(BPC_OP))))      +1)
            )) ||
            (/* INT */ (OP_M(BPC_OP) == 0xa0000000) && (true)) ||
            (/* CMP */ (OP_M(BPC_OP) == 0xc0000000) && (true)) ||
            (/* JMP */ (OP_M(BPC_OP) == 0xe0000000) && (true)) ||
            (m32(BSR) = m32(BSR) ^ 0x00000001) // Failure. Unknown Opcode, set DMP Flag.
            ) & ( m32(BPC) += 1 )
        );
    free(m);
    return p_len;
}

Now, to finish the project we need to implement comparisons, jumps, and at least the three stack interrupts. Let’s set up the stack interrupts first, since they are very straightforward: