<!-- PDF page 59 -->

<table>
<tbody>
<tr><td><strong>DPEEK</strong> <em>a</em></td><td>Read word[^p59-2] from memory (double <strong>PEEK</strong>) – See <em>Chapter 23</em></td></tr>
<tr><td><strong>USR</strong>[^p59-3] <em>a</em></td><td>Execute Machine Code routine – See <em>Chapter 25</em></td></tr>
<tr><td><strong>USR$</strong> <em>a</em></td><td>Execute Machine Code routine – See <em>Chapter 25</em></td></tr>
<tr><td><strong>BIN</strong> <em>n</em></td><td>Synonym for <em>@n</em>, specifying binary values</td></tr>
<tr><td><strong>RND</strong> <em>n</em></td><td>Generates pseudo-random value in range <strong>0</strong> to <strong>n–1</strong><br>(equivalent to floating-point <strong>INT (RND*n)</strong> )</td></tr>
<tr><td><strong>BANK</strong> <em>b</em> <strong>PEEK</strong> <em>o</em></td><td>Read byte at offset <em>o</em> from bank <em>b</em> – See <em>Chapter 23</em></td></tr>
<tr><td><strong>BANK</strong> <em>b</em> <strong>DPEEK</strong> <em>o</em></td><td>Read word at offset <em>o</em> from bank <em>b</em> (double <strong>PEEK</strong>) – See <em>Chapter 23</em></td></tr>
<tr><td>B<strong>ANK</strong> <em>b</em> <strong>USR</strong> <em>o</em></td><td>Execute Machine Code routine at offset <em>o</em> in bank <em>b</em> – See <em>Chapters 23</em> and <em>25</em></td></tr>
<tr><td>B<strong>ANK</strong> <em>b</em> <strong>USR$</strong> <em>o</em></td><td>Execute Machine Code routine at offset <em>o</em> in bank <em>b</em> – See <em>Chapters 23</em> and <em>25</em></td></tr>
</tbody>
</table>

These are written by including a **%** sign in front of them like all integer expressions. For example to read from hardware port 254:

```
%a = % IN 254
```

Or to check what speed your ZX Spectrum Next is running (masking the speed bits of NextREG 7) you could give :

```
PRINT %REG 7 & BIN 00000011
```

Randomly read a byte from the ROM:

```
%a=%RND 16384:PRINT %a,% PEEK a
```

### Exercise

1. Use the function **FN sq(x)=x*x** to test **SQR**. You should find that:

   **FN sq(SQR x)=x**

   if you substitute any positive number for x, and:

   **SQR FN s(x)=ABS x**

   whether x is positive or negative (Why the **ABS**?)

2. Write functions **FN RIGHT$** and **FN MID$**

[^p59-2]: *A word in standard computer terminology is a two-byte (ie. 16 bit) value. 32 bit values (two-word) are called Long Words.*
[^p59-3]: *USR and USR$ are very special functions as they also act like commands but using a function syntax*

