437 130 BNE loop \ if not, load next item 140 RTS \ return to BASIC 150 ] 160 NEXT opt% 170 !data=&04190416 180 data!4=&00C800C8 190 data!8=&00C80119 200 data!&C=&01190000 210 data!&10=&00ADFF9C 220 data!&14=&FF9C0119 230 data!&18=&0000FF53 240 CALL entry This program uses OSWRCH to perform operations equivalent to BASIC’s VDU command, drawing a triangle on the screen in MODE 4 . Note the use of indexed addressing at line 90 to load values from a table. Extensive use is made of indirection operators (see chapter 39 for details). The first pass of the assembly language loop is equivalent to VDU &16,&04 (see line 170, reading from the right) or VDU 22,4 (ie change to MODE 4 ). Note line 20.
This use of the DIM statement causes (in this case) 100 bytes of memory to be reserved, the start address of the block being transferred to the variable GAP% . The start address will always be greater than the value of TOP and below the start of screen memory, and so is ‘safe’ (the allocation is made in the same way as the allocation of a BASIC variable). The value in GAP% is transferred to P% at line 50, and so gives the address where the machine code will be assembled. Line 30 uses DIM to reserve 28 memory locations for the data table to be used by the program, the start address of the table being stored in the variable data.
Although for most applications machine code will be assembled and run at the same place in memory, it is possible to assemble code at one location and run it at another. Setting the resident integer variable O% to an address (and at the same time setting the pseudo variable OPT to a certain value, see below) will cause the machine code to be assembled at that address but assembled to run at the address given by P%; in other words the program counter is still controlled by P% during assembly. O% can be used, for example, to get a machine code program to run in the I/O processor which has been assembled in a second processor. See the description of the OPT keyword below for further details.