SPLat Logo

Semaphore instructions

NOTICE: SPLat Controls has moved. We are now at 1/85 Brunel Rd, Seaford, 3198. map

Semaphore instructions

Note: The following is a short-form introduction to semaphores. The semaphore tutorial has much more information, especially if you are unfamiliar with "bits" and "bytes". Semaphores were introduced with dialect 12.

"Semaphore" is the term we use to describe a 1-bit variable. The semaphore instructions allow you to set, clear and test semaphores in a variety of ways. You can use all of user RAM as semaphores, so in a SPLat board with 128 bytes of RAM you have potentially 1024 semaphores.

Note: Semaphores are stored in, and are part of, SPLat's user RAM (formerly called Data Memory). You must take care not to accidentally use the same memory location for semaphores as well as for other types of data.

The word semaphore is a time-honoured name in programming. Other terms that have been used are "flag" or "switch". If your background is with relay logic you will be accustomed to "internal relay".

In SPLat instructions semaphores are addressed (selected) by a semaphore number 'ss' and a base address 'bb'. Both these are 8-bit numbers, so they can have values between 0 and 255.

The base address defines the byte address or location within RAM where the semaphore counting is to start. This can be any address within the existing RAM. The semaphore number is counted starting from the base address, with 8 semaphores per byte. Thus if the base address is 5, semaphore 0 will be bit 0 of location 5.

The base address is an optional part of every semaphore instruction (not a separate register). If you omit the base address it defaults to 0. Hence, it is perfectly possible to never specify the base address, in which case the first 32 bytes of RAM will become 256 semaphores.

In the indexed form, the index register is added to the base address, not to the semaphore number.