Micro­power

  

Volume 1 · Number 1 · August 1981

Page 29 of 33

The Nas-Sys 3 table contains a repeat keyboard routine, which is not available under Nas-Sys 1.

The next two restarts (relative call, £D7, and subroutine call, £DF) both use the byte following the restart code to determine the address of the routine they are accessing. In a relative call the second byte is used as an offset to the routine being accessed, and as in the case of a relative jump instruction the distance is measured from the code following the second byte. If the offset lies in the range £80 – £FF the subroutine will precede the instruction calling it.

.
FB
FC|
FDNegative offsets
D7 XX<Position of relative call
00<Distances measured from here
01Positive offsets
02|
03
.

By using the relative call routine you can write programs that are completely relocatable – that is, they will work at any address without modification. This is particularly useful for programs that are to be stored in EPROM, as you can plug the device in any spare socket. Of course, you don’t get this for nothing; the routine has quite a lot of software manipulation to carry out, and consequently it is much slower than a normal subroutine call. So, if you want a program to run as quickly as possible you will have to avoid relative calls in the critical parts of the code.

The subroutine call, £DF, uses the second byte to access a table which contains the addresses of monitor subroutines. In Nas-sys 3 this table starts at £0782; the first 26 addresses are the routines for the single letter commands. Only F and L are unused, and the table contains the address of the error-message routine for these letters. If you have an EPROM blower you can add extra commands by using these letters, or by replacing any of the standard commands that you don’t use. As an example, here is a routine which compares two blocks of memory and list four lines of each block whenever it finds a difference.

1BDEC DE; On entry DE and HL point
2BDEC HL; to the start of the blocks
13CPLOOPINC DE; Increment the block pointers
23INC HL
1ALD A (DE); Get byte from block 1 in
BECP (HL); Is it the same as block 2?
28 FAJR Z CPLOOP; If so, keep going
D7 0CRCAL TAB; Tabulate first block
EBEX DE HL; Swap the pointers to the blocks
D7 09RCAL TAB; Tabulate the second block
EBEX DE HL; Swap pointers back
CFRST 8; Wait for user to press any key
Page 29 of 33