Micro­power

  

Volume 1 · Number 3 · November 1981

Page 5 of 33

memory, so that you can modify or read its contents. However, because PEEK & POKE operate only on single bytes the highest value that you can POKE into a memory is 255; similarly, PEEK(X) returns the value held in the single byte whose address is X.

When using DEEK & DOKE two consecutive bytes are accessed. This means that there are sixteen bits available for arithmetic, giving a theoretical maximum of 65535 (that is two to the sixteenth power, less one). When you DOKE a value to a specific address, the least significant byte is stored at the next byte above. Why are they stored in that order? Simply because that is the normal order in which the Z80 microprocessor stores sixteen-bit values. In order to cope with negative numbers the most significant bit of the high order byte is used to indicate the sign; if this bit is set, then the number is to be read as negative. The range of available values is thus −32768 to +32767.

Let’s try an example:–

Enter DOKE 3200,32767. If you now return to NAS-SYS and tabulate from 0C80, you will find 0C80 contains FF (low-order byte with all bits set) and 0C81 contains 7F (high-order byte having all bits except the most significant one set).

Now try DOKE 3200,-1:DOKE 3202,-2:DOKE 3204,-32767

The result should be as follows:–

0C80 (low byte) FF
0C81 (high byte) FF

Note computer holds this as 65536-1 i.e. (15x4096) + (15x256) + (15x16) + (15x1)

0C82 (low byte) FE
0C83 (high byte) FF

The computer has 65536-2, i.e. (15x4096) + (15x256) + (15x16) + (14x1)

0C84 (low byte) 01
0C85 (high byte) 80

The computer stores 65536-32767, i.e. (8x4096) + (1x1)

Why, though, do we have to bother with all this complicated nonsense? Let us have a look at a few examples. Firstly, a series of DOKES is very useful for setting up short machine code subroutines, which are to be called from a BASIC program. Here the values DOKE’d have no meaning in the BASIC program – they are just the decimal values which when converted to hexadecimal can be interpreted by the computer as machine code instructions. The USR(0) routine (given in the manual) to scan the keyboard for a key depression is a very good example of this.

Page 5 of 33