.. index:: !HP;instructions
.. index:: !instructions;HP

==================
HP instruction set
==================

This chapter summarizes the instruction set without going into deep
details. If you want more details, consult the
`NEWT manual <http://systemyde.com/pdf/newt.pdf>`_ which
describes the enhanced NEWT architecture. Instruction wise it is
almost identical to the original Nut.


.. index:: jumps;non-local, non-local jumps, mainframe;calling

Non-local jump instructions
---------------------------

These instructions will jump to an absolute address within the 64K
memory space. They are used for calling entries in the mainframe ROM
and some fixed page located ROMs, typically in the address range
``0000``--``7FFF``.

There are in reality 4 instructions and everyone will examine the
carry to decide whether the jump should be taken or not. While
``gosub`` and ``gsubnc`` are the same instruction, the mnemonics serve
two different purposes.

#. Unconditional non-local jumps using ``gosub`` or ``golong`` . The
   previous instruction should leave the carry flag cleared, and most
   instructions behave like this,
#. Test instruction followed by a non-local jump. In this case you
   want to use a variant that reflect that you are making use of the
   status of the carry flag, like ``gsubnc`` (even though it is the same
   instruction as ``gosub``).

.. table:: Non-local jumps
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+----------------+
 |Mnemonic        |Operand         |Description     |
 +================+================+================+
 |``gosub``       |*expr*          |Absolute jump to|
 |                |                |subroutine      |
 +----------------+----------------+----------------+
 |``gsubnc``      |*expr*          |Synonym for     |
 |                |                |``gosub``       |
 +----------------+----------------+----------------+
 |``gsubc``       |*expr*          |Absolute jump to|
 |                |                |subroutine on   |
 |                |                |carry set       |
 +----------------+----------------+----------------+
 |``golong``      |*expr*          |Absolute jump   |
 +----------------+----------------+----------------+
 |``golnc``       |*expr*          |Synonym for     |
 |                |                |``golong``      |
 +----------------+----------------+----------------+
 |``golc``        |*expr*          |Absolute jump on|
 |                |                |carry set       |
 +----------------+----------------+----------------+


.. index:: jumps;local, local jumps, local branch instructions

Local branches
--------------

Local branch instructions are position independent branches.
They are rather short distance, -63 to 64 words.

There are in reality 2 instructions, both will examine the carry to
decide whether the jump should be taken or not.

The ``goto`` instruction is intended to be used when you make a
unconditional jump knowing that the carry will always be clear.

.. table:: Local jumps
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+----------------+
 |Mnemonic        |Operand         |Description     |
 +================+================+================+
 |``goto``        |*expr*          |Short branch (on|
 |                |                |carry clear)    |
 +----------------+----------------+----------------+
 |``gonc``        |*expr*          |Synonym for     |
 |                |                |``goto``        |
 +----------------+----------------+----------------+
 |``goc``         |*expr*          |Short branch on |
 |                |                |carry set       |
 +----------------+----------------+----------------+


.. index:: page relocatable jumps, jumps;page relocatable

Page relocatable jumps
----------------------

These instructions take 3 words and are made up by a 2-word non-local
``gosub`` to a mainframe routine that reads the third word and uses
that as part of the destination. They work inside a 4K ROM page.

As they are implemented with the ``gosub`` instruction, you need to
ensure that the carry flag is not set when executing the instruction,
otherwise the ``gosub`` will be skipped and you end up executing the
third (page offset) word as an instruction, which is probably not what
you intended.

The linker will pick the appropriate mainframe routine to use
depending on the jump location and its destination.


.. table:: Page relative jumps
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+----------------+
 |Mnemonic        |Operand         |Description     |
 +================+================+================+
 |``gsbp``        |*expr*          |4K page         |
 |                |                |relocatable jump|
 |                |                |to subroutine   |
 +----------------+----------------+----------------+
 |``gsb41c``      |*expr*          |Synonym for     |
 |                |                |``gsbp``        |
 +----------------+----------------+----------------+
 |``golp``        |*expr*          |4K page         |
 |                |                |relocatable jump|
 +----------------+----------------+----------------+
 |``gol41c``      |*expr*          |Synonym for     |
 |                |                |``golp``        |
 +----------------+----------------+----------------+

.. note::
   The ``gsbsam`` and ``golsam`` that exist in the original HP
   instruction set are currently not supported. They are
   limited to have the call and destination in the same 1024-word
   sub-page, while the more general routines can reach anywhere in the
   4K page. The linker will choose the 1024-word variant whenever
   possible, but it will not do active section placement to ensure it
   happens.

   The benefits of the 1024-word variants are that it does not
   temporarily use a stack level (limiting it to three levels of the
   four available) and that it runs slightly faster.

   If you want to ensure that the 1024-word variant is used, simply
   use a specific section name for each such 1024-word area and
   limit the address range accordingly in the linker description. Then
   use that section name for code that belongs together in this
   respect. This way you can ensure that the 1024-word variants
   are used when it matters, but still give the linker freedom to
   place things when it does not matter.


.. index:: return instructions, instructions;return, instructions;indirect jumps

Other jump and subroutine instructions
--------------------------------------

.. table::
 :widths: 1 4
 :column-dividers: none single none

 +----------------+----------------+
 |Mnemonic        |Description     |
 +================+================+
 |``gotoc``       |Jump to address |
 |                |in ``C[6:3]``   |
 |                |                |
 +----------------+----------------+
 |``stk=c``       |Push ``C[6:3]`` |
 |                |on stack        |
 |                |                |
 +----------------+----------------+
 |``c=stk``       |Pop stack to    |
 |                |``C[6:3]``      |
 +----------------+----------------+
 |``spopnd``      |Pop stack and   |
 |                |discard value   |
 +----------------+----------------+
 |``rtn``         |Return from     |
 |                |subroutine      |
 +----------------+----------------+
 |``rtnnc``       |Return from     |
 |                |subroutine if   |
 |                |carry clear     |
 +----------------+----------------+
 |``rtnc``        |Return from     |
 |                |subroutine if   |
 |                |carry set       |
 +----------------+----------------+


.. index:: pointer instructions, instructions;pointer

Pointer instructions
--------------------

There are two pointers, P and Q. They are used to describe which part
of a 56-bit register to operate on, but they can also be used as
counters. One pointer register is active at any given time.

.. table:: Pointer instructions
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+----------------+
 |Mnemonic        |Operand         |Description     |
 +================+================+================+
 |``selp``        |                |Select pointer P|
 +----------------+----------------+----------------+
 |``selq``        |                |Select pointer Q|
 +----------------+----------------+----------------+
 |``?p=q``        |                |Test if P and Q |
 |                |                |pointers are    |
 |                |                |equal           |
 +----------------+----------------+----------------+
 |``decpt``       |                |Decrement       |
 |                |                |current pointer |
 +----------------+----------------+----------------+
 |``incpt``       |                |Increment       |
 |                |                |current pointer |
 +----------------+----------------+----------------+
 |``pt=``         |*expr*          |Set current     |
 |                |                |pointer         |
 +----------------+----------------+----------------+
 |``?pt=``        |*expr*          |Test if current |
 |                |                |pointer equals  |
 |                |                |value           |
 +----------------+----------------+----------------+



.. index:: arithmetic instructions, class two instructions, instructions;class two

Arithmetic instructions
-----------------------

Arithmetic instructions take a *field* argument describing which part of
the register to operate on.

.. table:: Fields
 :widths: 1 4
 :column-dividers: none single none

 +----------------+---------------------+
 |Field           |Description          |
 +================+=====================+
 |``pt``          |At pointer           |
 +----------------+---------------------+
 |``x``           |Exponent             |
 +----------------+---------------------+
 |``wpt``         |Word up to pointer   |
 +----------------+---------------------+
 |``w``           |Word                 |
 +----------------+---------------------+
 |``pq``          |Between pointers     |
 +----------------+---------------------+
 |``xs``          |Exponent sign        |
 +----------------+---------------------+
 |``m``           |Mantissa             |
 +----------------+---------------------+
 |``s``           |Sign of mantissa     |
 +----------------+---------------------+


.. table:: Arithmetic instructions
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+---------------------------------------+
 |Mnemonic        |Operand         |Description                            |
 +================+================+=======================================+
 |``a=0``         |*field*         |Clear (part of) ``A`` register         |
 +----------------+----------------+---------------------------------------+
 |``b=0``         |*field*         |Clear (part of) ``B`` register         |
 +----------------+----------------+---------------------------------------+
 |``c=0``         |*field*         |Clear (part of) ``C`` register         |
 +----------------+----------------+---------------------------------------+
 |``abex``        |*field*         |Exchange (part of) ``A`` and ``B``     |
 |                |                |registers                              |
 +----------------+----------------+---------------------------------------+
 |``b=a``         |*field*         |Move (part of) ``A`` to ``B`` register |
 +----------------+----------------+---------------------------------------+
 |``acex``        |*field*         |Exchange (part of) ``A`` and ``C``     |
 |                |                |registers                              |
 +----------------+----------------+---------------------------------------+
 |``c=b``         |*field*         |Move (part of) ``B`` to ``C`` register |
 +----------------+----------------+---------------------------------------+
 |``bcex``        |*field*         |Exchange (part of) ``B`` and ``C``     |
 |                |                |registers                              |
 +----------------+----------------+---------------------------------------+
 |``a=c``         |*field*         |Move (part of) ``C`` to ``A`` register |
 +----------------+----------------+---------------------------------------+
 |``a=a+b``       |*field*         |Add (part of) register                 |
 +----------------+----------------+---------------------------------------+
 |``a=a+c``       |*field*         |Add (part of) register                 |
 +----------------+----------------+---------------------------------------+
 |``a=a+1``       |*field*         |Increment (part of) register           |
 +----------------+----------------+---------------------------------------+
 |``a=a-b``       |*field*         |Subtract (part of) register            |
 +----------------+----------------+---------------------------------------+
 |``a=a-1``       |*field*         |Decrement (part of) register           |
 +----------------+----------------+---------------------------------------+
 |``a=a-c``       |*field*         |Subtract (part of) register            |
 +----------------+----------------+---------------------------------------+
 |``c=c+c``       |*field*         |Bit shift left (part of) ``C``         |
 |                |                |register                               |
 +----------------+----------------+---------------------------------------+
 |``c=a+c``       |*field*         |Add (part of) register                 |
 +----------------+----------------+---------------------------------------+
 |``c=c+a``       |*field*         |Synonym for previous instruction       |
 +----------------+----------------+---------------------------------------+
 |``c=c+1``       |*field*         |Increment (part of) register           |
 +----------------+----------------+---------------------------------------+
 |``c=a-c``       |*field*         |Subtract (part of) register            |
 +----------------+----------------+---------------------------------------+
 |``c=c-1``       |*field*         |Decrement (part of) register           |
 +----------------+----------------+---------------------------------------+
 |``c=-c``        |*field*         |One complement (part of )              |
 |                |                |register                               |
 +----------------+----------------+---------------------------------------+
 |``c=-c-1``      |*field*         |Two complement (part of)               |
 |                |                |register                               |
 +----------------+----------------+---------------------------------------+
 |``?a#0``        |*field*         |Test if (part of) ``A`` is non-zero    |
 +----------------+----------------+---------------------------------------+
 |``?b#0``        |*field*         |Test if (part of) ``B`` is non-zero    |
 +----------------+----------------+---------------------------------------+
 |``?c#0``        |*field*         |Test if (part of) ``C`` is non-zero    |
 +----------------+----------------+---------------------------------------+
 |``?a<c``        |*field*         |Test if (part of) ``A`` is less than   |
 |                |                |``C``                                  |
 +----------------+----------------+---------------------------------------+
 |``?a<b``        |*field*         |Test if (part of) ``A`` is less than   |
 |                |                |``B``                                  |
 +----------------+----------------+---------------------------------------+
 |``?a#c``        |*field**        |Test if (part of) ``A`` is not equal   |
 |                |                |to ``C``                               |
 +----------------+----------------+---------------------------------------+
 |``asr``         |*field**        |Nibble shift (part of) ``A`` right     |
 +----------------+----------------+---------------------------------------+
 |``bsr``         |*field**        |Nibble shift (part of) ``B`` right     |
 +----------------+----------------+---------------------------------------+
 |``csr``         |*field**        |Nibble shift (part of) ``C`` right     |
 +----------------+----------------+---------------------------------------+
 |``asl``         |*field*         |Nibble shift (part of) ``A`` left      |
 +----------------+----------------+---------------------------------------+


The following two word pseudo instructions are supported:

 +----------------+----------------+---------------------------------------+
 |Mnemonic        |Operand         |Description                            |
 +================+================+=======================================+
 |``b=c``         |*field*         |Move (part of) ``C`` to ``B`` register |
 +----------------+----------------+---------------------------------------+
 |``c=a``         |*field*         |Move (part of) ``A`` to ``C`` register |
 +----------------+----------------+---------------------------------------+
 |``a=b``         |*field*         |Move (part of) ``B`` to ``A`` register |
 +----------------+----------------+---------------------------------------+


The following synonyms are supported:

 +----------------+----------------+---------------------------------------+
 |Mnemonic        |Operand         |Description                            |
 +================+================+=======================================+
 |``cbex``        |*field*         |Exchange (part of) ``B`` and ``C``     |
 |                |                |registers                              |
 +----------------+----------------+---------------------------------------+
 |``baex``        |*field*         |Exchange (part of) ``A`` and ``B``     |
 |                |                |registers                              |
 +----------------+----------------+---------------------------------------+
 |``caex``        |*field*         |Exchange (part of) ``A`` and ``C``     |
 |                |                |registers                              |
 +----------------+----------------+---------------------------------------+


.. index:: flag instructions, instructions;flags

Flag instructions
-----------------

.. table::
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+--------------------+
 |Mnemonic        |Operand         |Description         |
 +================+================+====================+
 |``st=0``        |*expr*          |Clear flag          |
 +----------------+----------------+--------------------+
 |``sN=0``        |                |Clear flag,         |
 |                |                |replace ``N``       |
 |                |                |with flag number    |
 |                |                |``0`` to ``13``     |
 +----------------+----------------+--------------------+
 |``st=1``        |*expr*          |Set flag            |
 +----------------+----------------+--------------------+
 |``sN=1``        |                |Set flag,           |
 |                |                |replace ``N``       |
 |                |                |with flag number    |
 |                |                |``0`` to ``13``     |
 +----------------+----------------+--------------------+
 |``?st=1``       |*expr*          |Test flag           |
 +----------------+----------------+--------------------+
 |``st=1?``       |*expr*          |Test flag           |
 +----------------+----------------+--------------------+
 |``?sN=1``       |                |Test flag,          |
 |                |                |replace ``N``       |
 |                |                |with flag number    |
 |                |                |``0`` to ``13``     |
 +----------------+----------------+--------------------+
 |``clrst``       |                |Clear flags         |
 |                |                |``0``--``7``        |
 +----------------+----------------+--------------------+
 |``st=c``        |                |Copy ``C[0:1]``     |
 |                |                |to flags            |
 |                |                |``0``--``7``        |
 +----------------+----------------+--------------------+
 |``c=st``        |                |Copy flags          |
 |                |                |``0``--``7`` to     |
 |                |                |``C[0:1]``          |
 +----------------+----------------+--------------------+
 |``cstex``       |                |Exchange            |
 |                |                |``C[0:1]`` with     |
 |                |                |flags               |
 |                |                |``0``--``7``        |
 +----------------+----------------+--------------------+


.. index:: RAM memory instructions, instructions;RAM memory

RAM memory instructions
-----------------------

RAM comes in units of 16 registers. You select a register to operate
on and then read or write that particular register. It is also
possible to access registers within the same 16 register unit, [#RegZero]_
but in practise, this is only useful for the very first 16 registers.


.. table:: RAM memory instructions
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+-------------------+
 |Mnemonic        |Operand         |Description        |
 +================+================+===================+
 |``dadd=c``      |                |Select RAM         |
 |                |                |memory register    |
 |                |                |location           |
 +----------------+----------------+-------------------+
 |``data=c``      |                |Write ``C``        |
 |                |                |register to        |
 |                |                |selected RAM       |
 |                |                |location           |
 +----------------+----------------+-------------------+
 |``c=data``      |                |Read from selected |
 |                |                |RAM location to    |
 |                |                |``C`` register     |
 +----------------+----------------+-------------------+
 |``regn=c``      |*register*      |Write ``C``        |
 |                |                |register to        |
 |                |                |given RAM          |
 |                |                |register           |
 +----------------+----------------+-------------------+
 |``c=regn``      |*register*      |Read given RAM     |
 |                |                |register to        |
 |                |                |``C`` register     |
 |                |                |                   |
 +----------------+----------------+-------------------+


.. index:: RAM registers

.. table:: RAM registers
 :widths: 1 1
 :column-dividers: none single single none

 +--------+-----------+
 |Register|Alternative|
 |number  |           |
 +========+===========+
 |0       |``T``      |
 +--------+-----------+
 |1       |``Z``      |
 +--------+-----------+
 |2       |``Y``      |
 +--------+-----------+
 |3       |``X``      |
 +--------+-----------+
 |4       |``L``      |
 +--------+-----------+
 |5       |``M``      |
 +--------+-----------+
 |6       |``N``      |
 +--------+-----------+
 |7       |``O``      |
 +--------+-----------+
 |8       |``P``      |
 +--------+-----------+
 |9       |``Q``      |
 +--------+-----------+
 |10      |``+``      |
 +--------+-----------+
 |10      |``|-``     |
 +--------+-----------+
 |11      |``a``      |
 +--------+-----------+
 |12      |``b``      |
 +--------+-----------+
 |13      |``c``      |
 +--------+-----------+
 |14      |``d``      |
 +--------+-----------+
 |15      |``e``      |
 +--------+-----------+

.. rubric:: Footnotes
.. [#RegZero] Reading register ``0`` is special because it does not
              exist. Instead that opcode is used for ``c=data``, read
              the current selected register.




.. index:: ROM memory instructions, instructions;ROM memory

ROM memory instructions
-----------------------

.. table::
 :widths: 1 3
 :column-dividers: none single none

 +----------------+------------------------+
 |Mnemonic        |Description             |
 +================+========================+
 |``cxisa``       |Read word from          |
 |                |ROM memory              |
 +----------------+------------------------+
 |``wmldl``       |Write to simulated MLDL |
 |                |ROM                     |
 +----------------+------------------------+
 |``enrom1``      |Enable ROM bank         |
 |                |1                       |
 +----------------+------------------------+
 |``enrom2``      |Enable ROM bank         |
 |                |2                       |
 +----------------+------------------------+
 |``enrom3``      |Enable ROM bank         |
 |                |3                       |
 +----------------+------------------------+
 |``enrom4``      |Enable ROM bank         |
 |                |4                       |
 +----------------+------------------------+

.. index:: keyboard instructions, instructions;keyboard

Keyboard instructions
---------------------

.. table::
 :widths: 1 3
 :column-dividers: none single none

 +----------------+----------------+
 |Mnemonic        |Description     |
 +================+================+
 |``c=keys``      |Read keycode to |
 |                |``C[4:3]``      |
 +----------------+----------------+
 |``gokeys``      |Put keycode into|
 |                |low part of     |
 |                |``PC``          |
 +----------------+----------------+
 |``rstkb``       |Reset keyboard  |
 +----------------+----------------+
 |``chkkb``       |Test if key is  |
 |                |down            |
 +----------------+----------------+


Miscellaneous instructions
--------------------------

.. table::
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+---------------------------+
 |Mnemonic        |Operand         |Description                |
 +================+================+===========================+
 |``nop``         |                |No operation               |
 +----------------+----------------+---------------------------+
 |``powoff``      |                |Stop CPU                   |
 +----------------+----------------+---------------------------+
 |``lc``          |*expr*          |Load 4-bit value to ``C``  |
 |                |                |register at pointer        |
 |                |                |selected nibble            |
 +----------------+----------------+---------------------------+
 |``ldi``         |*expr*          |Load 10-bits immediate to  |
 |                |                |``C.X``                    |
 +----------------+----------------+---------------------------+
 |``selpf``       |*expr*          |Select smart peripheral    |
 +----------------+----------------+---------------------------+
 |``?flg=1``      |*expr*          |Test if I/O flag is pulled |
 +----------------+----------------+---------------------------+
 |``?fN=1``       |*expr*          |Test if I/O flag is        |
 |                |                |pulled, replace ``N`` with |
 |                |                |flag number                |
 |                |                |``0`` to ``13``            |
 +----------------+----------------+---------------------------+
 |``rcr``         |*expr*          |Rotate ``C`` register      |
 |                |                |right, both positive and   |
 |                |                |negative values are        |
 |                |                |accepted                   |
 +----------------+----------------+---------------------------+
 |``sethex``      |                |Set binary arithmetic mode |
 +----------------+----------------+---------------------------+
 |``setdec``      |                |Set BCD arithmetic mode    |
 +----------------+----------------+---------------------------+
 |``c=n``         |                |Move ``N`` to ``C``        |
 |                |                |register                   |
 +----------------+----------------+---------------------------+
 |``n=c``         |                |Move ``C`` to ``N``        |
 |                |                |register                   |
 +----------------+----------------+---------------------------+
 |``cnex``        |                |Exchange ``C`` and ``N``   |
 |                |                |registers                  |
 +----------------+----------------+---------------------------+
 |``c=m``         |                |Move ``M`` to ``C``        |
 |                |                |register                   |
 +----------------+----------------+---------------------------+
 |``m=c``         |                |Move ``C`` to ``M``        |
 |                |                |register                   |
 +----------------+----------------+---------------------------+
 |``cmex``        |                |Exchange ``C`` and ``M``   |
 |                |                |registers                  |
 +----------------+----------------+---------------------------+
 |``c=g``         |                |Move ``G`` to ``C``        |
 |                |                |register at pointer        |
 |                |                |position                   |
 +----------------+----------------+---------------------------+
 |``g=c``         |                |Move ``C`` to ``G``        |
 |                |                |register at pointer        |
 |                |                |position                   |
 +----------------+----------------+---------------------------+
 |``cgex``        |                |Exchange ``C`` and ``G``   |
 |                |                |registers at pointer       |
 |                |                |position                   |
 +----------------+----------------+---------------------------+
 |``f=sb``        |                |Move status byte to tone   |
 |                |                |register                   |
 +----------------+----------------+---------------------------+
 |``sb=f``        |                |Move tone register to      |
 |                |                |status byte                |
 +----------------+----------------+---------------------------+
 |``fexsb``       |                |Exchange tone register and |
 |                |                |status byte                |
 +----------------+----------------+---------------------------+
 |``?lld``        |                |Low level detect, check for|
 |                |                |low battery                |
 +----------------+----------------+---------------------------+
 |``c=cora``      |                |Bitwise or ``A`` to ``C``  |
 |                |                |register                   |
 +----------------+----------------+---------------------------+
 |``c=c&a``       |                |Bitwise and ``A`` to ``C`` |
 |                |                |register                   |
 +----------------+----------------+---------------------------+
 |``clrabc``      |                |Clear ``A``, ``B`` and     |
 |                |                |``C`` registers            |
 +----------------+----------------+---------------------------+
 |``pfad=c``      |                |Select peripheral          |
 +----------------+----------------+---------------------------+


The following synonyms are supported:

 +----------------+----------------+---------------------------+
 |Mnemonic        |Operand         |Description                |
 +================+================+===========================+
 |``ncex``        |                |Exchange ``C`` and ``N``   |
 |                |                |registers                  |
 +----------------+----------------+---------------------------+
 |``mcex``        |                |Exchange ``C`` and ``M``   |
 |                |                |registers                  |
 +----------------+----------------+---------------------------+



.. index:: instructions;LCD, instructions;display, LCD
.. _peripheralInstructions:

LCD instructions
----------------


I/O instructions like the ones for the LCD are shared with the RAM
access instructions. The assembler provides synonym instructions for
the LCD as follows:

.. table:: LCD instructions
 :widths: 1 3
 :column-dividers: none single none

 +----------------+---------------------------------+
 |Mnemonic        |Description                      |
 +================+=================================+
 |``disoff``      |Turn display off                 |
 +----------------+---------------------------------+
 |``distog``      |Toggle display on or off         |
 +----------------+---------------------------------+
 |``srlda``       |Shift right long, load A         |
 +----------------+---------------------------------+
 |``srldb``       |Shift right long, load B         |
 +----------------+---------------------------------+
 |``srldc``       |Shift right long, load C         |
 +----------------+---------------------------------+
 |``srldab``      |Shift right long, load AB        |
 +----------------+---------------------------------+
 |``srlabc``      |Shift right long, load ABC       |
 +----------------+---------------------------------+
 |``slldab``      |Shift left long, load AB         |
 +----------------+---------------------------------+
 |``sllabc``      |Shift left long, load ABC        |
 +----------------+---------------------------------+
 |``srsda``       |Shift right short, load A        |
 +----------------+---------------------------------+
 |``srsdb``       |Shift right short, load B        |
 +----------------+---------------------------------+
 |``srsdc``       |Shift right short, load C        |
 +----------------+---------------------------------+
 |``slsda``       |Shift left short, load A         |
 +----------------+---------------------------------+
 |``slsdb``       |Shift left short, load B         |
 +----------------+---------------------------------+
 |``srsdab``      |Shift right short, load AB       |
 +----------------+---------------------------------+
 |``slsdab``      |Shift left short, load AB        |
 +----------------+---------------------------------+
 |``srsabc``      |Shift right short, load ABC      |
 +----------------+---------------------------------+
 |``slsabc``      |Shift left short, load ABC       |
 +----------------+---------------------------------+
 |``wrten``       |Write annunciators               |
 +----------------+---------------------------------+
 |``fllda``       |Read left long A                 |
 +----------------+---------------------------------+
 |``flldb``       |Read left long B                 |
 +----------------+---------------------------------+
 |``flldc``       |Read left long C                 |
 +----------------+---------------------------------+
 |``flldab``      |Read left long AB                |
 +----------------+---------------------------------+
 |``fllabc``      |Read left long ABC               |
 +----------------+---------------------------------+
 |``readen``      |Read annunciators                |
 +----------------+---------------------------------+
 |``frsda``       |Read right short A               |
 +----------------+---------------------------------+
 |``frsdb``       |Read right short B               |
 +----------------+---------------------------------+
 |``frsdc``       |Read right short C               |
 +----------------+---------------------------------+
 |``flsda``       |Read left short A                |
 +----------------+---------------------------------+
 |``flsdb``       |Read left short B                |
 +----------------+---------------------------------+
 |``flsdc``       |Read left short C                |
 +----------------+---------------------------------+
 |``frsdab``      |Read right short AB              |
 +----------------+---------------------------------+
 |``flsdab``      |Read left short AB               |
 +----------------+---------------------------------+
 |``rabcr``       |Read right short ABC             |
 +----------------+---------------------------------+
 |``rabcl``       |Read left short ABC              |
 +----------------+---------------------------------+
 |``frsabc``      |Read right short ABC             |
 +----------------+---------------------------------+
 |``flsabc``      |Read left short ABC              |
 +----------------+---------------------------------+

.. note::
   The register names A, B and C used here have nothing to do with the
   CPU registers with the same name.



.. index:: instructions;timer, timer

Timer chip instructions
-----------------------

.. table::
 :widths: 1 3
 :column-dividers: none single none

 +----------------+--------------------------------+
 |Mnemonic        |Description                     |
 +================+================================+
 |``wrtime``      |Write time                      |
 +----------------+--------------------------------+
 |``wdtime``      |Write time and hold             |
 +----------------+--------------------------------+
 |``wralm``       |Write alarm                     |
 +----------------+--------------------------------+
 |``wrsts``       |Write status                    |
 +----------------+--------------------------------+
 |``wrscr``       |Write scratch                   |
 +----------------+--------------------------------+
 |``wsint``       |Write interval timer            |
 +----------------+--------------------------------+
 |``stpint``      |Stop interval timer             |
 +----------------+--------------------------------+
 |``dswkup``      |Disable test mode               |
 +----------------+--------------------------------+
 |``enwkup``      |Enable test mode                |
 +----------------+--------------------------------+
 |``dsalm``       |Disable alarm                   |
 +----------------+--------------------------------+
 |``enalm``       |Enable alarm                    |
 +----------------+--------------------------------+
 |``stopc``       |Stop clock                      |
 +----------------+--------------------------------+
 |``startc``      |Start clock                     |
 +----------------+--------------------------------+
 |``pt=b``        |Select timer B                  |
 +----------------+--------------------------------+
 |``pt=a``        |Select timer A                  |
 +----------------+--------------------------------+
 |``rdtime``      |Read clock                      |
 +----------------+--------------------------------+
 |``rctime``      |Read clock and correct          |
 +----------------+--------------------------------+
 |``rdalm``       |Read alarm                      |
 +----------------+--------------------------------+
 |``rdsts``       |Read status                     |
 +----------------+--------------------------------+
 |``rdscr``       |Read scratch                    |
 +----------------+--------------------------------+
 |``rdint``       |Read interval timer             |
 +----------------+--------------------------------+
 |``alarm?``      |Test if alarm                   |
 +----------------+--------------------------------+
 |``fatl?``       |Test timer access failure       |
 +----------------+--------------------------------+



Card reader instructions
------------------------


The card reader (peripheral ``0xFC``). PPC calculator journal V11N6
page 18--20 has an article about the programming internals of the card
reader.

.. index:: instructions;card reader, card reader

.. table:: Card reader instructions
 :widths: 1 3
 :column-dividers: none single none

 +----------------+--------------------------------+
 |Mnemonic        |Description                     |
 +================+================================+
 |``stwrit``      |Start write cycle               |
 +----------------+--------------------------------+
 |``enwrit``      |End write cycle                 |
 +----------------+--------------------------------+
 |``stread``      |Start read cycle                |
 +----------------+--------------------------------+
 |``enread``      |End read cycle                  |
 +----------------+--------------------------------+
 |``crdwpf``      |Test write protect              |
 +----------------+--------------------------------+
 |``crdohf``      |Fetch card over head flag       |
 +----------------+--------------------------------+
 |``crdinf``      |Test if card inserted           |
 +----------------+--------------------------------+
 |``tstbuf``      |Test card read/write buffer     |
 +----------------+--------------------------------+
 |``trpcrd``      |Set card trip flag              |
 +----------------+--------------------------------+
 |``tclcrd``      |Test and clear card trip flag   |
 +----------------+--------------------------------+
 |``crdflg``      |Fetch card reader external flag |
 +----------------+--------------------------------+
 |``crdr?``       |Set carry on card reader flag   |
 |                |(peripheral flag 1)             |
 +----------------+--------------------------------+


Wand instructions
-----------------


.. index:: instructions;wand, wand

.. table:: Wand instructions
 :widths: 1 3
 :column-dividers: none single none

 +----------------+--------------------------------+
 |Mnemonic        |Description                     |
 +================+================================+
 |``wndb?``       |Set carry when data in Wand     |
 |                |buffer (peripheral flag 2)      |
 +----------------+--------------------------------+



.. index:: instructions;HP-IL, HP-IL

HP-IL instructions
------------------

.. table::
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+-----------------------------------------+
 |Mnemonic        |Operand         |Description                              |
 +================+================+=========================================+
 |``orav?``       |                |Test output register available           |
 +----------------+----------------+-----------------------------------------+
 |``frav?``       |                |Test if frame is available               |
 +----------------+----------------+-----------------------------------------+
 |``ifcr?``       |                |Test if IFC command received             |
 +----------------+----------------+-----------------------------------------+
 |``frns?``       |                |Test frame received no as sent           |
 +----------------+----------------+-----------------------------------------+
 |``srqr?``       |                |Test for service request                 |
 |                |                |received                                 |
 +----------------+----------------+-----------------------------------------+
 |``hpil=c``      | *IL-register*  |Write to HP-IL register *n*              |
 |                |                | where *IL register* is 0-7              |
 +----------------+----------------+-----------------------------------------+
 |``c=hpil``      | *IL-register*  |Read from HP-IL register *n*             |
 |                |                | where *n* is 0-7                        |
 +----------------+----------------+-----------------------------------------+
 |``hpl=c``       | *IL-register*  |Write 8-bit *expr* to HP-IL register *n* |
 |                |                | where *n* is 0-7                        |
 +----------------+----------------+-----------------------------------------+
 |``ch=``         |*expr*          |Specifies char used in `hpl=c`           |
 |                |                |                                         |
 +----------------+----------------+-----------------------------------------+


Peripheral instructions
-----------------------

.. table::
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+-----------------------------------------+
 |Mnemonic        |Operand         |Description                              |
 +================+================+=========================================+
 |``?pfset``      |0-15            |Set carry if peripheral flag N is set    |
 +----------------+----------------+-----------------------------------------+
 |``printc``      |                |Add ``C[1:0]`` to print buffer           |
 +----------------+----------------+-----------------------------------------+
 |``rdptrn``      |                |Read status                              |
 +----------------+----------------+-----------------------------------------+
 |``rdptrr``      |                |                                         |
 +----------------+----------------+-----------------------------------------+
 |``rtncpu``      |                |                                         |
 +----------------+----------------+-----------------------------------------+



.. index:: instructions;Hepax, Hepax

Hepax instructions
------------------

.. table::
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+-----------------------------------------+
 |Mnemonic        |Operand         |Description                              |
 +================+================+=========================================+
 |``romblk``      |                |Move ROM block                           |
 +----------------+----------------+-----------------------------------------+
 |``wptog``       |                |Toggle write protection                  |
 +----------------+----------------+-----------------------------------------+


.. index:: instructions;NEWT, NEWT;instructions

NEWT specific instructions
--------------------------

NEWT specific instructions are recognized if you specify the command
line option ``--core newt``.

.. table::
 :widths: 1 1 4
 :column-dividers: none single single none

 +----------------+----------------+-----------------------------------------+
 |Mnemonic        |Operand         |Description                              |
 +================+================+=========================================+
 |``wcmd``        |                |Write command                            |
 +----------------+----------------+-----------------------------------------+
