Skip to content

Commit 896b7ab

Browse files
🧑‍💻 🎓 ESAP --- Negative operands for load direct instructions (#229)
1 parent aebc5e3 commit 896b7ab

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
14.6 KB
Loading

site/topics/control-logic/instructions-microcodes.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,34 @@ The 13 Instructions
534534
* Output the operand (data) from the instruction register and put it into register A
535535

536536

537+
.. warning::
538+
539+
This load *direct* instruction has a limitation caused by the underlying hardware --- only positive integers can
540+
be loaded directly to the register.
541+
542+
.. figure:: instruction_register_operand_padded_zeros.png
543+
:width: 333 px
544+
:align: center
545+
546+
Since each operand is only 4 bits wide, but the data bus is expecting 8 bits, the 4 most significant bits
547+
are padded with zeros.
548+
549+
550+
Consider the 8 bit number ``0b11111111``. Although this number may be ``255`` or ``-1``, depending on if it is
551+
a signed integer, adding ``0b00000001`` to this number results in ``0b1_00000000`` regardless. This number is
552+
``256``, but because only 8 bits can be represented and the overflow carry bit is ignored, the number is
553+
ultimately truncated to ``0``.
554+
555+
However, consider the 4 bit number ``0b1111``, which may be ``15`` or ``-1``. The programmer may intend for this
556+
bit pattern to mean ``-1``, but the operand for the load direct instructions are only four bits wide and are
557+
padded with zeros, thus this bit pattern would become ``0b00001111`` when it is added to the register. This 8
558+
bit number, signed or not, is ``15`` and adding ``1`` to this number results in ``0b00010000``.
559+
560+
One may try to address this issue with hardware and additional logic, but one must ask --- is this additional
561+
complexity worth it?
562+
563+
564+
537565
* ``0011`` --- ``LDBR``
538566

539567
* Load data into register B from some specified RAM address

site/topics/programming/assembler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
VALID_SYNTAX = {
3838
r"NOOP",
3939
r"LDAR\s+\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
40-
r"LDAD\s+-?\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
40+
r"LDAD\s+\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
4141
r"LDBR\s+\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
42-
r"LDBD\s+-?\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
42+
r"LDBD\s+\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
4343
r"SAVA\s+\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
4444
r"SAVB\s+\b(0x[0-9a-fA-F]+|0b[0-1]+|[0-9]+)\b",
4545
r"ADAB",

0 commit comments

Comments
 (0)