def p_instruction_r_imm(p): """instruction : OPERATOR REGISTER COMMA IMMEDIATE NEWLINE""" logging.debug('r_imm OPRT %s REG %s IMM %s, size=%s', p[1], p[2], p[4], 4) inc(4) p[0] = InstRImm(p[1], p[2], sgn(p[4], 0xffff))
def p_instruction_imm(p): """instruction : OPERATOR IMMEDIATE NEWLINE""" size, operand = 2, p[2] if 'jr' in p[1]: operand = sgn(p[2], 0xff) elif 'jmp' in p[1]: size = 4 logging.debug('imm OPRT %s IMM %s, size=%s', p[1], operand, size) inc(size) p[0] = InstImm(p[1], operand)
def p_instruction_label(p): """instruction : OPERATOR LABEL NEWLINE""" logging.debug('label OPRT %s LABEL %s, size=%s', p[1], p[2], 2) inc() if 'jr' not in p[1]: operand = PendingLabel(p[2], sgn, [0xff]) else: # this is a relative jump instruction current_byte = get() # immediately get the current position operand = PendingLabel(p[2], lambda l_imm: sgn(l_imm - current_byte, 0xff)) p[0] = InstImm(p[1], operand)