Startseite Stand: 26.02.2025

CORDIC

Sinus und Cosinus in 680x0 Assembler

	move.l  #$3243F6A8, d0	; z=Pi/4 cos=sin=0,707106=>2D413CCC
	move.l	#$6487ED51, d0	; z=Pi/2 cos=0 sin=1

; Festkommawerte Q2.30 ; Bereich für d0 in Radiant 0-Pi/2 (0-90°)
; Die Schleife passt (32 byte) in den 68020 cache
; Beim 68000 steigt mit 8+2*i auch die Dauer der asl.l!

; ***** bekommt: d0(rad) - liefert: d1(cos),d2(sin)
CORDIC:
		move.l	#$26DD3B6A, d1	; cosx Korrekturfaktor 0,607252
		moveq	#0, d2		; siny
		moveq	#0, d5		; Iterationen
		lea		ArcTan, a0	; Tabelle für Annäherungswerte
.L
		move.l	d1, d3		; tx=cosx
		asr.l	d5, d3		; tx >> i
		move.l	d2, d4		; ty=siny
		asr.l	d5, d4		; ty >> i
	
		tst.l	d0			; z>0?
		bmi.s	.kleiner	; springt bei z<0
	
		sub.l	d4, d1		; cosx-ty
		add.l	d3, d2		; siny+tx
		sub.l	(a0)+, d0	; z-arctan(2^-i)
		bra.s	.w
.kleiner
		add.l	d4, d1		; cosx+ty
		sub.l	d3, d2		; siny-tx
		add.l	(a0)+, d0	; z+arctan(2^-i)
.w
		addq.w	#1, d5
		cmpi.w	#18, d5
		bls.s	.L
	rts

; *****
ArcTan: ; arctan(2^-i)
 dc.l $3243F6A8 ;00 0,785398 Q2.30
 dc.l $1DAC6705 ;01 0,463647
 dc.l $0FADBAFC ;02 0,244978
 dc.l $07F56EA6 ;03 0,124354
 dc.l $03FEAB76 ;04 0,062418
 dc.l $01FFD55B ;05 0,031239
 dc.l $00FFFAAA ;06 0,015623
 dc.l $007FFF55 ;07 0,007812
 dc.l $003FFFEA ;08 0,003906
 dc.l $001FFFFD ;09 0,001953
 dc.l $000FFFFF ;10 0,000976
 dc.l $0007FFFF ;11 0,000488
 dc.l $0003FFFF ;12 0,000244
 dc.l $0001FFFF ;13 0,000122
 dc.l $0000FFFF ;14 0,000061
 dc.l $00007FFF ;15 0,000030
 dc.l $00003FFF ;16 0,000015
 dc.l $00001FFF ;17 0,000007
 dc.l $00000FFF ;18 0,000003