16. HP instruction set¶
This chapter summarizes the instruction set without going into deep details. If you want more details, consult the NEWT manual which describes the enhanced NEWT architecture. Instruction wise it is almost identical to the original Nut.
16.1. 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
gosuborgolong. 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 asgosub).
Mnemonic |
Operand |
Description |
|---|---|---|
|
expr |
Absolute jump to subroutine |
|
expr |
Synonym for
|
|
expr |
Absolute jump to subroutine on carry set |
|
expr |
Absolute jump |
|
expr |
Synonym for
|
|
expr |
Absolute jump on carry set |
16.2. 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.
Mnemonic |
Operand |
Description |
|---|---|---|
|
expr |
Short branch (on carry clear) |
|
expr |
Synonym for
|
|
expr |
Short branch on carry set |
16.3. 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.
Mnemonic |
Operand |
Description |
|---|---|---|
|
expr |
4K page relocatable jump to subroutine |
|
expr |
Synonym for
|
|
expr |
4K page relocatable jump |
|
expr |
Synonym for
|
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.
16.4. Other jump and subroutine instructions¶
Mnemonic |
Description |
|---|---|
|
Jump to address
in |
|
Push |
|
Pop stack to
|
|
Pop stack and discard value |
|
Return from subroutine |
|
Return from subroutine if carry clear |
|
Return from subroutine if carry set |
16.5. 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.
Mnemonic |
Operand |
Description |
|---|---|---|
|
Select pointer P |
|
|
Select pointer Q |
|
|
Test if P and Q pointers are equal |
|
|
Decrement current pointer |
|
|
Increment current pointer |
|
|
expr |
Set current pointer |
|
expr |
Test if current pointer equals value |
16.6. Arithmetic instructions¶
Arithmetic instructions take a field argument describing which part of the register to operate on.
Field |
Description |
|---|---|
|
At pointer |
|
Exponent |
|
Word up to pointer |
|
Word |
|
Between pointers |
|
Exponent sign |
|
Mantissa |
|
Sign of mantissa |
Mnemonic |
Operand |
Description |
|---|---|---|
|
field |
Clear (part of) |
|
field |
Clear (part of) |
|
field |
Clear (part of) |
|
field |
Exchange (part of) |
|
field |
Move (part of) |
|
field |
Exchange (part of) |
|
field |
Move (part of) |
|
field |
Exchange (part of) |
|
field |
Move (part of) |
|
field |
Add (part of) register |
|
field |
Add (part of) register |
|
field |
Increment (part of) register |
|
field |
Subtract (part of) register |
|
field |
Decrement (part of) register |
|
field |
Subtract (part of) register |
|
field |
Bit shift left (part of) |
|
field |
Add (part of) register |
|
field |
Synonym for previous instruction |
|
field |
Increment (part of) register |
|
field |
Subtract (part of) register |
|
field |
Decrement (part of) register |
|
field |
One complement (part of ) register |
|
field |
Two complement (part of) register |
|
field |
Test if (part of) |
|
field |
Test if (part of) |
|
field |
Test if (part of) |
|
field |
Test if (part of) |
|
field |
Test if (part of) |
|
field* |
Test if (part of) |
|
field* |
Nibble shift (part of) |
|
field* |
Nibble shift (part of) |
|
field* |
Nibble shift (part of) |
|
field |
Nibble shift (part of) |
The following two word pseudo instructions are supported:
Mnemonic
Operand
Description
b=cfield
Move (part of)
CtoBregister
c=afield
Move (part of)
AtoCregister
a=bfield
Move (part of)
BtoAregister
The following synonyms are supported:
Mnemonic
Operand
Description
cbexfield
Exchange (part of)
BandCregisters
baexfield
Exchange (part of)
AandBregisters
caexfield
Exchange (part of)
AandCregisters
16.7. Flag instructions¶
Mnemonic |
Operand |
Description |
|---|---|---|
|
expr |
Clear flag |
|
Clear flag,
replace |
|
|
expr |
Set flag |
|
Set flag,
replace |
|
|
expr |
Test flag |
|
expr |
Test flag |
|
Test flag,
replace |
|
|
Clear flags
|
|
|
Copy |
|
|
Copy flags
|
|
|
Exchange
|
16.8. 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, 1 but in practise, this is only useful for the very first 16 registers.
Mnemonic |
Operand |
Description |
|---|---|---|
|
Select RAM memory register location |
|
|
Write |
|
|
Read from selected
RAM location to
|
|
|
register |
Write |
|
register |
Read given RAM
register to
|
Register number |
Alternative |
|---|---|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
Footnotes
- 1
Reading register
0is special because it does not exist. Instead that opcode is used forc=data, read the current selected register.
16.9. ROM memory instructions¶
Mnemonic |
Description |
|---|---|
|
Read word from ROM memory |
|
Write to simulated MLDL ROM |
|
Enable ROM bank 1 |
|
Enable ROM bank 2 |
|
Enable ROM bank 3 |
|
Enable ROM bank 4 |
16.10. Keyboard instructions¶
Mnemonic |
Description |
|---|---|
|
Read keycode to
|
|
Put keycode into
low part of
|
|
Reset keyboard |
|
Test if key is down |
16.11. Miscellaneous instructions¶
Mnemonic |
Operand |
Description |
|---|---|---|
|
No operation |
|
|
Stop CPU |
|
|
expr |
Load 4-bit value to |
|
expr |
Load 10-bits immediate to
|
|
expr |
Select smart peripheral |
|
expr |
Test if I/O flag is pulled |
|
expr |
Test if I/O flag is
pulled, replace |
|
expr |
Rotate |
|
Set binary arithmetic mode |
|
|
Set BCD arithmetic mode |
|
|
Move |
|
|
Move |
|
|
Exchange |
|
|
Move |
|
|
Move |
|
|
Exchange |
|
|
Move |
|
|
Move |
|
|
Exchange |
|
|
Move status byte to tone register |
|
|
Move tone register to status byte |
|
|
Exchange tone register and status byte |
|
|
Low level detect, check for low battery |
|
|
Bitwise or |
|
|
Bitwise and |
|
|
Clear |
|
|
Select peripheral |
The following synonyms are supported:
Mnemonic
Operand
Description
ncexExchange
CandNregisters
mcexExchange
CandMregisters
16.12. 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:
Mnemonic |
Description |
|---|---|
|
Turn display off |
|
Toggle display on or off |
|
Shift right long, load A |
|
Shift right long, load B |
|
Shift right long, load C |
|
Shift right long, load AB |
|
Shift right long, load ABC |
|
Shift left long, load AB |
|
Shift left long, load ABC |
|
Shift right short, load A |
|
Shift right short, load B |
|
Shift right short, load C |
|
Shift left short, load A |
|
Shift left short, load B |
|
Shift right short, load AB |
|
Shift left short, load AB |
|
Shift right short, load ABC |
|
Shift left short, load ABC |
|
Write annunciators |
|
Read left long A |
|
Read left long B |
|
Read left long C |
|
Read left long AB |
|
Read left long ABC |
|
Read annunciators |
|
Read right short A |
|
Read right short B |
|
Read right short C |
|
Read left short A |
|
Read left short B |
|
Read left short C |
|
Read right short AB |
|
Read left short AB |
|
Read right short ABC |
|
Read left short ABC |
|
Read right short ABC |
|
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.
16.13. Timer chip instructions¶
Mnemonic |
Description |
|---|---|
|
Write time |
|
Write time and hold |
|
Write alarm |
|
Write status |
|
Write scratch |
|
Write interval timer |
|
Stop interval timer |
|
Disable test mode |
|
Enable test mode |
|
Disable alarm |
|
Enable alarm |
|
Stop clock |
|
Start clock |
|
Select timer B |
|
Select timer A |
|
Read clock |
|
Read clock and correct |
|
Read alarm |
|
Read status |
|
Read scratch |
|
Read interval timer |
|
Test if alarm |
|
Test timer access failure |
16.14. 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.
Mnemonic |
Description |
|---|---|
|
Start write cycle |
|
End write cycle |
|
Start read cycle |
|
End read cycle |
|
Test write protect |
|
Fetch card over head flag |
|
Test if card inserted |
|
Test card read/write buffer |
|
Set card trip flag |
|
Test and clear card trip flag |
|
Fetch card reader external flag |
|
Set carry on card reader flag (peripheral flag 1) |
16.15. Wand instructions¶
Mnemonic |
Description |
|---|---|
|
Set carry when data in Wand buffer (peripheral flag 2) |
16.16. HP-IL instructions¶
Mnemonic |
Operand |
Description |
|---|---|---|
|
Test output register available |
|
|
Test if frame is available |
|
|
Test if IFC command received |
|
|
Test frame received no as sent |
|
|
Test for service request received |
|
|
IL-register |
|
|
IL-register |
|
|
IL-register |
|
|
expr |
Specifies char used in hpl=c |
16.17. Peripheral instructions¶
Mnemonic |
Operand |
Description |
|---|---|---|
|
0-15 |
Set carry if peripheral flag N is set |
|
Add |
|
|
Read status |
|
|
||
|
16.18. Hepax instructions¶
Mnemonic |
Operand |
Description |
|---|---|---|
|
Move ROM block |
|
|
Toggle write protection |
16.19. NEWT specific instructions¶
NEWT specific instructions are recognized if you specify the command
line option --core newt.
Mnemonic |
Operand |
Description |
|---|---|---|
|
Write command |