New compiler

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

New compiler

Post by FFMan »

Don,

is it recommended now to change existing putpin/getpin calls to the appropriate new calls where the pin is know at compile time ?

Is the code overhead reduction significant ?

Are there any downsides known at the moment ?

thanks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: New compiler

Post by dkinzer »

FFMan wrote:is it recommended now to change existing putpin/getpin calls to the appropriate new calls where the pin is know at compile time ?
Unless you just want to try them, I would recommend leaving existing applications as they are. The primary advantage to using the new functions is that they have a very low and constant overhead, allowing very fast pin manipulation. This is accomplished by having the compiler emit code to directly read and/or write the I/O port containing the pin - that's why the pin must be known at compile-time.

As an example of the speed difference, consider the program below that can be compiled to use either PinOutput() or PutPin() in a loop to toggle an output pin. With PinOutput() the loop cycle time on a ZX-24n is 890nS and with PutPin() it is 10uS. Note, however, that the code size for the application compiled the two ways happens to be the same. This won't always be the case but it is unlikely that the code size would ever be larger when using the direct pin functions.

Code: Select all

Const pin as Byte = 13

' uncomment the next line to use direct pin functions
#define USE_PIN_FUNC

Sub Main()
   Dim b as Byte
   b = 0
   Call PutPin(pin, b)
   Do
      b = b Xor 1
#if defined(USE_PIN_FUNC)
      Call PinOutput(pin, b)
#else
      Call PutPin(pin, b)
#endif
   Loop
End Sub
- Don Kinzer
Post Reply