;Quadrat für ATmega (nicht auf Multiplikation aufbauend)
;h#s 01/06
#ifndef SQR2_I90
#define SQR2_I90
;Quelle: 16-bit-Zahl
;Ziel: 32-bit-Zahl (optional 24bit)
; r5:r4:r3:r2=sqr2(r17:r16) vzl.
; r5:r4:r3:r2=sqrs2(r17:r16) vzb.
;ifdef SQR3 (alternativ, bisschen schneller)
; r4:r3:r2=sqr2(r17:r16) vzl.
; r4:r3:r2=sqrs2(r17:r16) vzb.
.include "makros.i90"
#ifdef SQR3
sqr2:
;PE: R17:R16 = vzl. Zahl (das Quadrat muss in 24 Bit passen!)
;PA: R4:R3:R2 = Ergebnis
;VR: R0..R4
mul r16,r16 ;Lowteil multiplizieren (b²)
movw r3:r2,r1:r0 ;Ergebnis in mittleres und niedrigstes Byte
mul r17,r17 ;Highteil multiplizieren (A²)
mov r4,r0 ;r0 als Ergebnis im höchsten Byte
fmul r17,r16
add r3,r0
adc r4,r1
ret
;Vorschrift:
;(A+b)² = A² + 2Ab + b²
;A=High-Teil, b=Low-Teil
sqrs2:
;PE: R17:R16 = vzb. Zahl (das Quadrat muss in 24 Bit passen!)
;PA: R4:R3:R2 = Ergebnis (nie negativ:-)
;VR: R0..R4
subi r17,0x80
rcall sqr2
subi r17,0x80 ;überflüssiges Rückstellen?
sub r4,r16
ret
#else
.error "Hier gibt's noch Arbeit!"
#endif
#endif//SQR2_I90
Detected encoding: ANSI (CP1252) | 4
|
|