View Single Post
Old 07 July 2019, 16:54   #1150
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 51
Posts: 1,152
Originally Posted by mcgeezer View Post
You are welcome, I actually ditched my reverse byte generator in favour of Ross', but kept my longword reverse code, Ross's generator has a slight error in that d1 needs to be 0 on entry. (I'm sure he won't mind me showing it).

Here is the code now in Rygar.

; Input d1=longword
; Output d1=longword reversed
	movem.l	d0/d2/a0,-(a7)
	lea	BYTE_REVERSE_TAB(a4),a0
;	moveq	#8,d3

       moveq #0,d0    ; +
; Do first 3 bytes
	rept	3
;	moveq	#0,d0
	move.b	d1,d0
	move.b	(a0,d0),d2
	lsr.l	#8,d1
	lsl.l	#8,d2

; Final byte but without shift
;	moveq	#0,d0
	move.b	d1,d0
	move.b	(a0,d0),d2
	move.l	d2,d1
	movem.l	(a7)+,d0/d2/a0
; Ross's code to generate a byte swap table
; Conisderably more efficient and smaller than my effort.
	movem.l	d0-d3/a0,-(a7)
	moveq	#0,d1
	lea     BYTE_REVERSE_TAB(a4),a0
	moveq   #0,d3
.k:	moveq   #7,d2
	move.b  d3,d0
.l:	add.b   d0,d0
	roxr.b  #1,d1
	dbf     d2,.l
	move.b  d1,(a0)+
	addq.b  #1,d3
	bne.b   .k
	movem.l	(a7)+,d0-d3/a0
A few bytes shortest version. No d3 needed.
Don_Adan is offline  
Page generated in 0.04235 seconds with 11 queries