Counter with bipolar incrementation

Algorithm development and general DSP issues

Moderator: frank

Post Reply
knutolai
Posts: 86
Joined: Wed Nov 23, 2016 9:43 am
Location: Bergen, Norway

Counter with bipolar incrementation

Post by knutolai »

I use a lot of counters in my projects but always found working with bipolar incrementation tricky. This is probably not news to more seasoned forum members but I thought I'd share my method here. Feel really dumb that I didn't think of this sooner. Feel free to critique/improve:

This should work for any continuous negative counter (-1 to -LSB).

Code: Select all

ldax increment     ; any number from -1 to +1
AND $7fffff     ; offset all negative increments to positive (GEZ) range (+1)
rdax counter, 1     ; add counter (negative value)
OR $800000     ; offset all positive values to negative range (-1)
wrax counter, 0     ; store new counter value
Post Reply