Has anyone tried to implement simple linear functions like A*X+B in assembly for the AVR?

## Linear Functions

Hi,

Where's your input coming from, and where's your output going? The AVR can do these operations, but not all devices can do a hardware multiply. The ATmega163 can do this, so if it's a real-time operation, maybe this is your choice?

If you're looking for a software multiplier, there's an application note on this :)

I notice I haven't answered your question: No, I haven't done this, but I think I should help kick-starting the discussion. If I should make a function (like in C?), I'd do it something like this (note that I haven't run this):

.define X = r16

.define a = r17

.define b = r18

.define temp = r19

rjmp start

multiply: ;load X before you call this

mul X, a ;the answer comes in r1:r0

add r0, b ;add b to the answer

ldi temp, 0

adc r1, temp ;adds carry if it's there

ret ;now the answer is in r1:r0

start:

;your main loop here

Corinthian

Somebody thought about asm (???) and mathematics already, try that:

http://www.avr-forum.com/avrsour...

There are some floating point libraries. I don't know, if it is of any use for you, I just remembered, thare was something related to maths.

Regards

Chris

The input is X coming from the ADC register and the output is simply stored in a temp 8bit register. A & B are loaded into registers just like you outlined. However, my problem is that I'm using the Tiny which doesn't have the Hardware multiply. I'll look for the app note.

Thanks,

Jesse

Hi!

The app note you're all looking for is this one:

http://www.avrfreaks.net/Tools/s...

it describes software routines for multiplication and division. There's another one about how the AVR handles 16-bit arithmetics:

http://www.avrfreaks.net/Tools/s...

Best regards,

Morten, AVR tech. support