HINTS & TIPS

Another collection of Archimedes hints and tips rounded up by David Spencer.

LINE IT UP

Matthew White

Because the ARM is a 32-bit processor and RAM is addressed bytewise, it is often necessary to align an address to a word boundary when using data blocks. From within the assembler, the ALIGN directive can be used, but within Basic the easiest way to align an address addr to the next word boundary is to use:
addr=addr+3 AND NOT 3

MORE ALIGNMENT

David Spencer

A cautionary word of warning for assembly language programmers. Basic's assembler will automatically ensure that all instructions are word aligned, so for example:
BL grabbyte
EQUB 123
LDMFD R13!,{PC}

causes three zeros to be inserted after the value 123 to align the next instruction. However, if the LDM instruction had a label associated with it, then this label must appear on the same program line as the instruction. If the label is on a line of its own preceding the instruction then it will be given the value of the program counter before alignment. This causes havoc when the machine code is run, and is very hard to spot because it generates no assembly-time errors and is not at all obvious at a first glance. The safest solution is to always put an ALIGN directive after byte and half-word values.

LIST OPTIONS

Glynn Clements

The Basic command LISTO can be used to provide a number of different formats for program listings. The command is followed by a number which specifies the format, the default setting being zero. The number representing the desired format is chosen by adding together the appropriate values from the list below:
1Print space after line number
2Indent structures (REPEAT etc.)
4Split multi-statement lines
8Don't list line numbers
(Gives error if any line numbers referenced in program)
16List Basic keywords in lower case

A value of 16 is useful for separating keywords and variable names if you have used upper-case for the latter, while a value of 14 (indent, split and no line numbers) gives a listing which resembles a Pascal program more than Basic.

RISC OS ASSEMBLER LIMITS

Andrew Johnson

The Basic assembler in RISC OS has been extended to check against the code running over the end of the allocated space. By adding 8 to the OPT setting, the assembler will give an error if the value of P% exceeds that of L%. A statement such as:
DIM code% 1000, L% -1
will set L% to the address of the end of the area DIMed for code. Therefore, by enabling the checking you can ensure that the code doesn't run over the end of the allocated area.

CLARIFYING COLOURS

Robert Long

Anybody who has tried to manipulate screen memory directly in a 256 colour mode may have discovered that the layout of bits within a pixel is not documented anywhere. The actual allocation for each bit (with the default palette settings) is:
0Tint low
1Tint high
2Red low
3Blue low
4Red high
5Green low
6Green high
7Blue high

The two tint bits correspond to the value given to TINT divided by 64. See the descriptions of VDU17 and VDU23 in the Programmer's Reference Manual for more details of the 256 colour numbers.

TIME ON A KEY

Graeme Davidson

The commands:
*SETMACRO Key$1 <Sys$Date>
*SETMACRO Key$2 <Sys$Time>

will set up functions keys one and two to produce the current date and time respectively. These could be used to insert the current values into a REM statement to identify different versions of a program under development, or they could be used to insert the current date into a word processor document.