Has anyone tried to implement simple linear functions like A*X+B in assembly for the AVR?
admin's test signature
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
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
;your main loop here
Somebody thought about asm (???) and mathematics already, try that:
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.
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.
The app note you're all looking for is this one:
it describes software routines for multiplication and division. There's another one about how the AVR handles 16-bit arithmetics:
Morten, AVR tech. support
© 2018 Microchip Technology Inc.