func getDataJFromParts(parts ...uint32) (*DataJ, error) {

	// check length of parts and set parts into the right operands
	if len(parts) != 2 {
		return nil, errors.New(fmt.Sprintf("Data J expecting 2 parts and got %d", len(parts)))
	}

	return &DataJ{
		Opcode:  bits.FromUint32(parts[0], 6),
		Address: bits.FromUint32(parts[1], 26),
	}, nil
}
func getDataJFromUint32(data uint32) (*DataJ, error) {
	bits := bits.FromUint32(data, 32)
	return &DataJ{
		Opcode:  bits.Slice(31, 26),
		Address: bits.Slice(25, 0),
	}, nil
}
func getDataIFromUint32(data uint32) (*DataI, error) {
	bits := bits.FromUint32(data, 32)
	return &DataI{
		Opcode:    bits.Slice(31, 26),
		RegisterD: bits.Slice(25, 21),
		RegisterS: bits.Slice(20, 16),
		Immediate: bits.Slice(15, 0),
	}, nil
}
func getDataIFromParts(parts ...uint32) (*DataI, error) {

	// check length of parts and set parts into the right operands
	var values []uint32
	if len(parts) == 4 {
		values = []uint32{parts[0], parts[1], parts[2], parts[3]}
	} else if len(parts) == 3 {
		values = []uint32{parts[0], parts[1], 0, parts[2]}
	} else {
		return nil, errors.New(fmt.Sprintf("Data I expecting 3 or 4 parts and got %d", len(parts)))
	}

	return &DataI{
		Opcode:    bits.FromUint32(values[0], 6),
		RegisterD: bits.FromUint32(values[1], 5),
		RegisterS: bits.FromUint32(values[2], 5),
		Immediate: bits.FromUint32(values[3], 16),
	}, nil
}
func getDataRFromUint32(data uint32) (*DataR, error) {
	bits := bits.FromUint32(data, 32)
	return &DataR{
		Opcode:    bits.Slice(31, 26),
		RegisterD: bits.Slice(25, 21),
		RegisterS: bits.Slice(20, 16),
		RegisterT: bits.Slice(15, 11),
		Shamt:     bits.Slice(10, 6),
		Funct:     bits.Slice(5, 0),
	}, nil
}
func getDataRFromParts(parts ...uint32) (*DataR, error) {

	// check length of parts and set parts into the right operands
	if len(parts) != 4 {
		return nil, errors.New(fmt.Sprintf("Data R expecting 4 parts and got %d", len(parts)))
	}

	return &DataR{
		Opcode:    bits.FromUint32(parts[0], 6),
		RegisterD: bits.FromUint32(parts[1], 5),
		RegisterS: bits.FromUint32(parts[2], 5),
		RegisterT: bits.FromUint32(parts[3], 5),
		Shamt:     bits.FromUint32(0, 5),
		Funct:     bits.FromUint32(0, 6),
	}, nil
}
func (this *DataI) SetRegisterD(value uint32) {
	this.RegisterD = bits.FromUint32(value, 5)
}
Beispiel #8
0
func GetOpcodeFromUint32(value uint32) uint8 {
	bits := bits.FromUint32(value, 32)
	return uint8(bits.Slice(31, 26).ToUint32())
}