106 of 172
ZBasic Language Reference 99 ZX Microcontroller Family The second method for guaranteeing atomicity of a sequence of one or more statements is to use the System Library routines DisableInt() and EnableInt() in matched pairs as shown in the example below. Dim i as Integer Sub Main() Dim stat as Byte stat = DisableInt() i = 200 Call EnableInt(stat) End Sub The disadvantage of using this method is that the compiler does not attempt to verify that the disabling and enabling are properly paired. Consequently, you might inadvertently omit the call to EnableInt() which would prevent any further interrupts, effectively disabling serial I/O, the RTC, etc. A third method of guaranteeing atomicity is to explicitly disable and re-enable interrupts as depicted below. Dim i as Integer Sub Main() Register.SREG = &H00 i = 200 Register.SREG = &H80 End Sub Although this technique may be useful in rare cases, its use is strongly discouraged. The primary problem with this method is that it unconditionally re-enables interrupts without regard to whether or not interrupts were enabled beforehand. A related technique using inline assembly language code, having the same disadvantage, is shown below. Dim i as Integer Sub Main() #asm cli #endasm i = 200 #asm sei #endasm End Sub 4.5 Attributes for Procedures and Variables This section describes several special attributes that you can apply to variables or procedures with native mode devices to obtain special effects. To apply special attributes, you list the desired attributes (see the table below) in a comma-separated list enclosed in parentheses following the keyword Attribute. This entire construction is placed at the end of a normal variable, subroutine or function definition as illustrated in the example below.