Matters of style question
jcwren
Posts: 44
Being a long-time assembly programmer, but new to PASM, there's a couple things I'm curious about.
First, is there an idiom for clearing and setting carry? Right now I'm using "add par, #0" to clear carry (where carry indicates to the caller the routine succeeded).
In PASM, is clkfreq accessible somehow at compile time? I have a couple constants I want to define that are based on the clock rate, but I'd prefer to do this at compile time rather than runtime.
--jc
First, is there an idiom for clearing and setting carry? Right now I'm using "add par, #0" to clear carry (where carry indicates to the caller the routine succeeded).
In PASM, is clkfreq accessible somehow at compile time? I have a couple constants I want to define that are based on the clock rate, but I'd prefer to do this at compile time rather than runtime.
--jc
Comments
CLKFREQ or clkfreq is accessible from PASM or Spin - see page 63 of the propeller manual for an explanation.
clkfreq is readable, but I'm looking for a compile time option. In the SPIN code, delay1200 microseconds would be "delay1200us := clkfreq * 0.00120". In assembly, that would force doing division, something I'd hoped to avoid. I was looking for something like "delay1200us LONG (CLKFREQ / 1_000_000) * 120". While page 63 does state "Objects that are time-sensitive should check CLKFREQ at strategic points in order to adjust to new settings automatically", I'm not worried about this (and I wonder how often people actually change the clock speed on the fly anyway).
I guess I'll have to do that in SPIN code, and pass it in the PASM, rather than a constant.
--jc
At compile time, you can use _CLKFREQ in a constant expression.
If a program is loaded off an SD card, most loaders will set the clock to what's specified in the source code. Some OS like Sphinx normally don't do that and keep the same setting that was specified for the OS. Since several different crystal / clock speed / clock mode combinations are in use, it would be more helpful for a program not to assume what the clock frequency is (at compile time).
results in an 'Undefined symbol' error for me.
As far as setting and clearing the carry and zero flags, whatever works in one instruction is fancy enough.
-Phil
Have you actually tried that piece of code?
In spin what you will get is :
You are multiplying the CLKFREQ with $3A9D4951 which is the floating point representation of 0.0012
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
--jc
Yep. That will do the job. It's how I do it also.
I was looking for a CLKFREQ define I could use in PASM also, but I've just resulted to have SPIN do the calculation at runtime and set the right value in the DAT section before I launch the cog.
It would not be incredibly difficult for the compiler to calculate the clock frequency based on the defines set at compile time, but none of them currently do it. bst does not calculate the clock frequency until the object linking stage, and by then it's too late to use it as a global symbol. (The reason for that is you might have 10 objects with the clock and crystal defines in them, but we only want the one in the top object to be authoritative).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
To your original question about setting flags (carry)...Phil put together a nice summary of ways to set/clear flags a while back. The attached is a slightly-organized rabble of PASM subroutine snippets I've collected over time...the snippets relevant to your carry question start at about line 168.
--jc