|
| 1 | +Implementation Specific (implspec.py) |
| 2 | +===================================== |
| 3 | + |
| 4 | + |
| 5 | +This page contains informations about the :ref:`utility` functions |
| 6 | +needed to operated the CPU such as generating bits, inverting bits, |
| 7 | +bit and reading bits. |
| 8 | + |
| 9 | +.. _utility: |
| 10 | + |
| 11 | +Utility Functions |
| 12 | +***************** |
| 13 | + |
| 14 | +These functions exist due the the implementation in Python and to |
| 15 | +make testing the functions and methods easier. The logic remains |
| 16 | +the same without these functions. |
| 17 | + |
| 18 | +Push to Tuple |
| 19 | +------------- |
| 20 | + |
| 21 | +`Push to tuple` takes in an `n` sized array of binary values and |
| 22 | +creates a tuple of binary values **Tuple-binary**. |
| 23 | + |
| 24 | +.. TIP:: |
| 25 | + The bits are reversed to make trailing zeros important |
| 26 | + For example: ``1,0,0, 0...`` is 4 (in binary) but will not be recognised |
| 27 | + because when pushed to the tuple it will be ``(...,0,0,1)`` is |
| 28 | + which means 1 (in binary). When reversed: ``0,0,1,...`` and pushed |
| 29 | + to a tuple it will be ``(0,0,1,...)`` |
| 30 | + |
| 31 | +.. HINT:: |
| 32 | + Tuple-binary values are always in reverse binary order. Where the |
| 33 | + left most bit is the least and the vice-versa. |
| 34 | + |
| 35 | +.. _generate-bits: |
| 36 | + |
| 37 | +Generate X Bits |
| 38 | +--------------- |
| 39 | + |
| 40 | +Generator function exists to make writing tests and inputs easier. Without |
| 41 | +this function I would have to `'cheat'` in a sense and use string subscripting |
| 42 | +with integer conversion. |
| 43 | + |
| 44 | +There are `4`, `8` and `16` bit generators. |
| 45 | + |
| 46 | +They take in a one `n-bit binary number` (where n < specified-bit). |
| 47 | + |
| 48 | +Returns a tuple-binary of size `n`. |
| 49 | + |
| 50 | +.. code-block:: |
| 51 | +
|
| 52 | + generate8Bits(0b10) |
| 53 | + Output: (0,1,0,0,0,0,0,0) |
| 54 | +
|
| 55 | + generate16Bits(0b10) |
| 56 | + Output: (0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0) |
| 57 | +
|
| 58 | +Generate Stream Bits |
| 59 | +-------------------- |
| 60 | + |
| 61 | +Due the implementation of the :ref:`generate-bits`, the 16-bit variant of :ref:`stream-bits` |
| 62 | +needs to be of size 16. |
| 63 | + |
| 64 | +Where the function does this: |
| 65 | + |
| 66 | +.. code-block:: |
| 67 | +
|
| 68 | + if bit == 1: |
| 69 | + return 0b1111111111111111 |
| 70 | + else: |
| 71 | + return 0b0000000000000000 |
| 72 | +
|
| 73 | +Call the function ``generateStreamBits`` and provide one 1-bit value. |
| 74 | + |
| 75 | +.. code-block:: |
| 76 | + |
| 77 | + generateStreamBits(1) |
| 78 | + Output: 65535 # decimal representation |
| 79 | +
|
| 80 | +Tuple to Binary |
| 81 | +--------------- |
| 82 | + |
| 83 | +Tuple-to-binary takes in a tuple-binary of size `n` and produces |
| 84 | +a value of size `n` in an integer representation (it will be of type ``int`` |
| 85 | +in Python). |
| 86 | + |
| 87 | +The argument supplied is the `tuple-binary`. |
| 88 | + |
| 89 | +The return value is an `integer`. |
| 90 | + |
| 91 | +.. code-block:: |
| 92 | + |
| 93 | + tupleToBinary((1,0)) |
| 94 | + Output: 2 # decimal representation |
| 95 | +
|
| 96 | +.. Decimal to Binary |
| 97 | +.. ----------------- |
| 98 | +.. |
| 99 | +.. Decimal-to-binary takes in a decimal number |
| 100 | +
|
| 101 | +Less Than Zero |
| 102 | +-------------- |
| 103 | + |
| 104 | +In order to determine if a number is negative (less than zero) the 16th |
| 105 | +bit is read. If it's 1 then the number is negative. |
| 106 | + |
| 107 | +The argument supplied is the `tuple-binary`. |
| 108 | + |
| 109 | +The return value is an `integer`, 1 if its true, zero if false. |
| 110 | + |
| 111 | +.. code-block:: |
| 112 | +
|
| 113 | + isLessThanZero((1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)) |
| 114 | + Output: 1 |
| 115 | +
|
| 116 | + isLessThanZero((0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1)) |
| 117 | + Output: 0 |
| 118 | +.. |
| 119 | +.. Reverse Bits |
| 120 | +.. ------------ |
| 121 | +.. |
| 122 | +.. Reverse-bits reverses the order of the supplied tuple-binary. |
| 123 | +.. |
| 124 | +.. The argument supplied is the `tuple-binary`. |
| 125 | +.. |
| 126 | +.. The return value is the reversed `tuple-binary`. |
0 commit comments