#extract all op and funct codes op_codes = {} funct_codes = {} for m in re_op_code.finditer(src): op_codes[m.group('op').lower()] = m.group('code') for m in re_funct_code.finditer(src): funct_codes[m.group('funct').lower()] = m.group('code') return op_codes, funct_codes op_codes = {'bltz': '000001', 'lbu': '100100', 'sw': '101011', 'blez': '000110', 'lb': '100000', 'lh': '100001', 'lw': '100011', 'jal': '000011', 'mfc0': '010000', 'lui': '001111', 'addi': '001000', 'sltiu': '001011', 'bgez': '000001', 'ori': '001101', 'xori': '001110', 'andi': '001100', 'mtc0': '010000', 'bgtz': '000111', 'addiu': '001001', 'rtype': '000000', 'j': '000010', 'slti': '001010', 'lhu': '100101', 'sh': '101001', 'bne': '000101', 'sb': '101000', 'beq': '000100'} funct_codes = {'and': '100100', 'subu': '100011', 'mflo': '010010', 'syscall': '001100', 'mfhi': '010000', 'sltu': '101011', 'addu': '100001', 'xor': '100110', 'jalr': '001001', 'add': '100000', 'nor': '100111', 'jr': '001000', 'break': '001101', 'srav': '000111', 'divu': '011011', 'mult': '011000', 'sub': '100010', 'sra': '000011', 'slt': '101010', 'sllv': '000100', 'srl': '000010', 'sll': '000000', 'mthi': '010001', 'mtlo': '010011', 'srlv': '000110', 'div': '011010', 'or': '100101', 'multu': '011001'} register_names = ['$zero','$at','$v0','$v1','$a0','$a1','$a2','$a3','$t0','$t1','$t2','$t3','$t4','$t5','$t6','$t7','$s0','$s1','$s2','$s3','$s4','$s5','$s6','$s7','$t8','$t9','$k0','$k1','$gp','$sp','$fp','$ra'] registers = {} for i, name in enumerate(register_names): registers["$%d"%i] = conversions.bin2c(i, 5) registers[name] = conversions.bin2c(i, 5) if __name__ == "__main__": args = parser.parse_args() if args.parse_codes: op_codes, funct_codes = parse_codes(args.assembly) sys.stderr.write( "op_codes = " + op_codes.__repr__() + "\n" ) sys.stderr.write( "funct_codes = " + funct_codes.__repr__() + "\n" ) sys.exit(0) radix = 16 if args.format == 'memb': radix = 2
'mtlo': '010011', 'srlv': '000110', 'div': '011010', 'or': '100101', 'multu': '011001' } register_names = [ '$zero', '$at', '$v0', '$v1', '$a0', '$a1', '$a2', '$a3', '$t0', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6', '$t7', '$s0', '$s1', '$s2', '$s3', '$s4', '$s5', '$s6', '$s7', '$t8', '$t9', '$k0', '$k1', '$gp', '$sp', '$fp', '$ra' ] registers = {} for i, name in enumerate(register_names): registers["$%d" % i] = conversions.bin2c(i, 5) registers[name] = conversions.bin2c(i, 5) if __name__ == "__main__": args = parser.parse_args() if args.parse_codes: op_codes, funct_codes = parse_codes(args.assembly) sys.stderr.write("op_codes = " + op_codes.__repr__() + "\n") sys.stderr.write("funct_codes = " + funct_codes.__repr__() + "\n") sys.exit(0) radix = 16 if args.format == 'memb': radix = 2 labels = {} parsed_lines = []