Register Units
isa_manim.isa_objects.reg_unit presents one register or a group of registers. It can
be used for general-purpose registers, vector registers, and matrix registers.
One example of a single register is shown below:

Source code: test_one_dim_reg.py
One example of a list of registers is shown below:

Source code: test_two_dim_reg.py
As shown in the above figures, one register unit contains the following Manim objects:
- reg_rect presents the register.
- The width of reg_rect presents the bit width of the register.
- The height of reg_rect presents the number of registers or the row count of
one matrix register. If there is only one register, the height is 1.0.
- label_text_list contains the labels that present the name of the register. The
vertical distance between the position of labels is 1.0. The right boundary of
labels is close to the left boundary of reg_rect.
As the green dot shown in the above figures, the origin point of one register unit is located in the centre position of the first row in
reg_rect, which is different from the geometry centre position of this object. It is suggested to use functionshiftrather than functionmove_toto change the location of the register.
Function get_elem_center returns the position of one specified element. The bit width
of the specified element can be different from the element bit width of the vector.
Register units can maintain values of the register in the format of one single value
(for GPRs), a 1-D array of values (for vector registers), or a 2-D array of values (for
matrix registers). Function get_elem_value returns the value of one specified element,
while function set_elem_value modifies the value of one specified element.
Thus, arguments for all methods are designed to support matrix registers. If creating or operating on vector registers,
nregmust be 1 in the constructor function andreg_idxis ignored in other methods. If creating or operating on general-purpose registers,elementsmust be 1 in the constructor function andindexis ignored in other methods.
RegUnit
Bases: VGroup
Object for one register.
Attributes:
| Name | Type | Description |
|---|---|---|
name_text_list |
List[Text]
|
List of label text objects. |
reg_rect |
Rectangle
|
List of register rectangle objects. |
reg_name_list |
List[str]
|
List of register names. |
reg_color |
Color
|
Color of register rectangle and labels. |
reg_font_size |
int
|
Font size of register labels. |
reg_value_format |
str
|
Format string for output values. Inherented by element units. |
reg_value |
Union[Any, List[Any], List[List[Any]], None]
|
Register value. Inherented by element units. |
reg_width |
int
|
Bit width of register. |
reg_count |
int
|
Number of registers, or row count of matrix registers. |
elem_count |
int
|
Number of elements. |
elem_width |
int
|
Bit width of elements. |
require_serialization = False
class-attribute
instance-attribute
Animation related with this object does not need to be serialized.
__init__(name_list, color, width, elements, nreg, value, font_size, value_format)
Constructor a register.
- When construct a scalar register,
elementsis 1 andnregis 1. - When construct a vector register,
elementsis the number of elements, andnregis 1. - When construct a matrix register or a list of registers,
elementsis the number of elements andnregis the number of registers or the row count of matrix registers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_list
|
List[str]
|
Register names which could be a string or a list of string. |
required |
color
|
Color
|
Color of register and label. |
required |
width
|
int
|
Width of register, in bits. |
required |
elements
|
int
|
Number of elements in one register. |
required |
nreg
|
int
|
Number of registers, used to create matrix registers or a list of registers. |
required |
value
|
Union[Any, List[Any], List[List[Any]], None]
|
Value of this element. None is provided if not necessary. |
required |
font_size
|
int
|
Font size of label. |
required |
value_format
|
str
|
Format string for output values. Inherented by element units. |
required |
__repr__()
Return a string for debugging.
Returns:
| Type | Description |
|---|---|
str
|
A string for debugging. |
__str__()
Return a string for debugging.
Returns:
| Type | Description |
|---|---|
str
|
A string for debugging. |
get_elem_pos(index, reg_idx, offset, elem_width)
Return the center position of one specified element.
The element is specified by index and reg_idx. In general, index and
reg_idx should within the scope of the register. If index or reg_idx
beyond the scope of the register, this function returns one element specified as
below:
- The actual index to access element is
index % elem_count - The actual row index to access element is
(reg_idx + index // elem_count) % reg_count.
The width to index elements is determined by the construtor function. However, it is not possible to operate on only a part of the element. For example, one 128 bit vector has eight 16-bit elements.
- The 4-th element [79:64] is accessed if
indexis 4,offsetis 0 andelem_widthis 16. - Lower half of the 4-th element [71:64] is accessed if
indexis 4,offsetis 0 andelem_widthis 8. - Higher half of the 4-th element [79:72] is accessed if
indexis 4,offsetis 8 andelem_widthis 8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of elements. |
required |
reg_idx
|
int
|
Index of register. |
required |
offset
|
int
|
Offset of lower bits. |
required |
elem_width
|
int
|
Width of element in bits. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Position of the specified element. |
get_elem_value(index, reg_idx)
Return the value of one specified element. Return None if the value of this register is not specified in the constructor function.
- Return
self.elem_valuefor scalar registers. - Return
self.elem_value[index]for vector registers. - Return
self.elem_value[reg_idx][index]for a list of registers or matrix registers.
The element is specified by index and reg_idx. In general, index and
reg_idx should within the scope of the register. If index or reg_idx
beyond the scope of the register, this function returns one element specified as
below:
- The actual index to access element is
index % elem_count - The actual row index to access element is
(reg_idx + index // elem_count) % reg_count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of elements. |
required |
reg_idx
|
int
|
Index of register. |
required |
Returns:
| Type | Description |
|---|---|
Union[Any, List[Any], List[List[Any]], None]
|
Value of the specified element. |
get_placement_height()
Return the height of this object for placement. The height is ceil to an integer.
Returns:
| Type | Description |
|---|---|
int
|
The height of this object. |
get_placement_mark()
Return the marker of this object for placement, which is 2.
Returns:
| Type | Description |
|---|---|
int
|
Marker of this object. |
get_placement_width()
Return the width of this object for placement. The width is ceil to an integer.
Returns:
| Type | Description |
|---|---|
int
|
The width of this object. |
set_elem_value(value, index, reg_idx)
Modify the value of one specified element.
- Modify
self.elem_valuefor scalar registers. - Modify
self.elem_value[index]for vector registers. - Modify
self.elem_value[reg_idx][index]for a list of registers or matrix registers.
The element is specified by index and reg_idx. In general, index and
reg_idx should within the scope of the register. If index or reg_idx
beyond the scope of the register, this function returns one element specified as
below:
- The actual index to access element is
index % elem_count - The actual row index to access element is
(reg_idx + index // elem_count) % reg_count.
If the value of this register is not specified in the constructor function
(self.elem_value is None), and this register is one vector register, matrix
register, or a group of registers, one 1-D/2-D array of values is created with
None elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of elements. |
required |
reg_idx
|
int
|
Index of register. |
required |
value
|
Any
|
Value of this element. |
required |
set_placement_corner(row, col)
Set the position of object by the left-up corner position. Move object to the specified position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
int
|
Vertical ordinate of left-up corner. |
required |
col
|
int
|
Horizontal ordinate of left-up corner. |
required |