def execute_mv(self, cmd):
        """ This command moves an immediate value to a register or copies the \
            value of a register to another register

        :param cmd: the command which triggered the function call
        :type cmd: int
        :return: No value returned
        :rtype: None
        :raise data_specification.exceptions.DataSpecificationSyntaxError: \
                if the destination register is not correctly specified - the \
                destination must be a register and the appropriate bit needs \
                to be set in the specification
        """
        self.__unpack_cmd__(cmd)

        if not self.use_dest_reg:
            raise exceptions.DataSpecificationSyntaxError(
                "Destination register not correctly specified")

        if self.use_src1_reg:
            self.registers[self.dest_reg] = self.registers[self.src1_reg]
        else:
            data_encoded = self.spec_reader.read(4)
            data = struct.unpack("<I", str(data_encoded))[0]
            self.registers[self.dest_reg] = data
    def execute_end_spec(self, cmd):
        """ Return the value which terminates the data spec executor

        :param cmd: the command which triggered the function call
        :type cmd: int
        :return: constants.END_SPEC_EXECUTOR
        :rtype: int
        :raise None
        """
        read_data = self.spec_reader.read(4)
        value = struct.unpack("<i", str(read_data))[0]
        if value != -1:
            raise exceptions.DataSpecificationSyntaxError(
                "Command END_SPEC requires an argument equal to -1. The "
                "current argument value is {0:d}".format(value))
        return constants.END_SPEC_EXECUTOR
    def execute_write(self, cmd):
        """
        This command writes the given value in the specified region a number\
         of times as identified by either a value in the command or a register\
         value

        :param cmd: the command which triggered the function call
        :type cmd: int
        :return: No value returned
        :rtype: None
        :raise data_specification.exceptions.DataSpecificationSyntaxError:\
            If there is an error in the command syntax
        """
        self.__unpack_cmd__(cmd)

        if self.use_src2_reg:
            n_repeats = self.registers[self.src2_reg]
        else:
            n_repeats = cmd & 0xFF

        # Convert data length to bytes
        data_len = (1 << self.data_len)

        if self.use_src1_reg:
            value = self.registers[self.src1_reg]
        else:
            if self._cmd_size == constants.LEN2 and data_len != 8:
                read_data = self.spec_reader.read(4)
                value = struct.unpack("<I", str(read_data))[0]
            elif self._cmd_size == constants.LEN3 and data_len == 8:
                read_data = self.spec_reader.read(8)
                value = struct.unpack("<Q", str(read_data))[0]
            else:
                raise exceptions.DataSpecificationSyntaxError(
                    "Command {0:s} requires a value as an argument, but the "
                    "current encoding ({1:X}) is specified to be {2:d} words "
                    "long and the data length command argument is specified "
                    "to be {3:d} bytes long".format("WRITE", cmd,
                                                    self._cmd_size, data_len))

        # Perform the writes
        self._write_to_mem(value, data_len, n_repeats, "WRITE")
    def execute_reserve(self, cmd):
        """
        This command reserves a region and assigns some memory space to it

        :param cmd: the command which triggered the function call
        :type cmd: int
        :return: No value returned
        :rtype: None
        :raise data_specification.exceptions.DataSpecificationSyntaxError:\
            If there is an error in the command syntax
        :raise data_specification.exceptions.\
            DataSpecificationParameterOutOfBoundsException:\ If the requested \
            size of the region is beyond the available memory space
        """
        self.__unpack_cmd__(cmd)
        region = cmd & 0x1F  # cmd[4:0]

        if self._cmd_size != constants.LEN2:
            raise exceptions.DataSpecificationSyntaxError(
                "Command {0:s} requires one word as argument (total 2 words), "
                "but the current encoding ({1:X}) is specified to be {2:d} "
                "words long".format("RESERVE", cmd, self._cmd_size))

        unfilled = (cmd >> 7) & 0x1 == 0x1

        if not self.mem_regions.is_empty(region):
            raise exceptions.DataSpecificationRegionInUseException(region)

        size_encoded = self.spec_reader.read(4)
        size = struct.unpack("<I", str(size_encoded))[0]
        if size & 0x3 != 0:
            size = (size + 4) - (size & 0x3)

        if (size <= 0) or (size > self.memory_space):
            raise exceptions.DataSpecificationParameterOutOfBoundsException(
                "region size", size, 1, self.memory_space, "RESERVE")

        self.mem_regions[region] = MemoryRegion(memory_pointer=0,
                                                unfilled=unfilled,
                                                size=size)
        self.space_allocated += size