示例#1
0
def parse_cui(data):
    """
    assert parse_cui('\x00zcbag')[0] == 0
    assert parse_cui('\x7fzcbag')[0] == 0x7f
    assert parse_cui('\x80\x80zcbag')[0] == 0x80
    assert parse_cui('\xbf\xffzcbag')[0] == 0x3fff
    assert parse_cui('\xc0\x00\x40\x00zcbag')[0] == 0x4000
    assert parse_cui('\xdf\xff\xff\xffzcbag')[0] == 0x1fffffff
    assert parse_cui('\xe0\x20\x00\x00\x00zcbag')[0] == 0x20000000
    assert parse_cui('\xe0\xff\xff\xff\xffzcbag')[0] == 0xffffffff
    assert parse_cui('\xe0\xff\xff\xff\xffzcbag')[1] == 'zcbag'
    """
    _id = ord(data[0]) & 0xf0
    if _id < 0x80:
        length = 1
        diff = 0
    elif _id < 0xc0: #0x80 <= _id < 0xc0:
        length = 2
        diff = 0x8000
    elif _id < 0xe0: #0xc0 <= _id < 0xe0:
        length = 4
        diff = 0xc0000000
    elif _id == 0xe0:
        length = 5
        diff = 0xe000000000
    else:
        raise RuntimeError("Could parse cui: 0x%X" % ord(data[0]))
    res = utils.bin2int(data[:length]) - diff
    return res, data[length:]
示例#2
0
def parse_cui(data):
    """
    assert parse_cui('\x00zcbag')[0] == 0
    assert parse_cui('\x7fzcbag')[0] == 0x7f
    assert parse_cui('\x80\x80zcbag')[0] == 0x80
    assert parse_cui('\xbf\xffzcbag')[0] == 0x3fff
    assert parse_cui('\xc0\x00\x40\x00zcbag')[0] == 0x4000
    assert parse_cui('\xdf\xff\xff\xffzcbag')[0] == 0x1fffffff
    assert parse_cui('\xe0\x20\x00\x00\x00zcbag')[0] == 0x20000000
    assert parse_cui('\xe0\xff\xff\xff\xffzcbag')[0] == 0xffffffff
    assert parse_cui('\xe0\xff\xff\xff\xffzcbag')[1] == 'zcbag'
    """
    _id = ord(data[0]) & 0xf0
    if _id < 0x80:
        length = 1
        diff = 0
    elif _id < 0xc0:  #0x80 <= _id < 0xc0:
        length = 2
        diff = 0x8000
    elif _id < 0xe0:  #0xc0 <= _id < 0xe0:
        length = 4
        diff = 0xc0000000
    elif _id == 0xe0:
        length = 5
        diff = 0xe000000000
    else:
        raise RuntimeError("Could parse cui: 0x%X" % ord(data[0]))
    res = utils.bin2int(data[:length]) - diff
    return res, data[length:]
示例#3
0
	def jal(sim, inst_bin):
		imm = inst_bin[6:]
		return "jal     {}".format(utils.bin2int(imm))
示例#4
0
	def decode_FI(inst_bin):
		fs = int(inst_bin[11:16], 2)
		imm = utils.bin2int(inst_bin[16:])
		return fs, imm
示例#5
0
	def decode_I(inst_bin):
		rs = int(inst_bin[6:11], 2)
		rt = int(inst_bin[11:16], 2)
		imm = utils.bin2int(inst_bin[16:])
		return rs, rt, imm
示例#6
0
	def decode_R(inst_bin):
		rs = int(inst_bin[6:11], 2)
		rt = int(inst_bin[11:16], 2)
		rd = int(inst_bin[16:21], 2)
		shamt = utils.bin2int(inst_bin[21:26])
		return rs, rt, rd, shamt