summaryrefslogtreecommitdiff
path: root/test/rotate.s
blob: 90f16ba992fe31e9de0d9ecf332b7c0f0f30397e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
; Test rol, and ror.

.org 0
count:
	.res 1
tmp:
	.res 8

.org $8000
reset:
	cps		;
	ldx.d #$2FFFF	;
	txs		;
	and #0		;
	tax		;
	tab		;
	tay		;


start:
	ldb #8		; Set the loop count to 8.
@loop:
	lda #$AA	; Set A to magic byte.
	deb		; Decrement the loop count.
	beq @savemagic	; Save the magic number, if the loop count is zero.
	lsl #8		; Shift the magic number by one byte, if the loop count is non zero.
	bra @loop	; Keep looping.
@savemagic:
	sta.q tmp	; Save the magic number.


rotate:
	ldb #0		; Reset B.
@loop:
	and #0		; Reset A.
	lda #$40	; Set the shift count to 64.
	sta count	;
	lda.q tmp	; Get our magic number.
	inb		; Increment our shift amount by one.
	cpb #$40	; Is the shift amount greater than, or equal to 64?
	bcs rotate	; Yes, so reset B.
@rotl:
	rol b		; Rotate the magic number left by our shift amount.
	dec count	; Decrement the shift count.
	beq @rotr	; Start rotating right, if the shift count is zero.
	bra @rotl	; Keep looping, if the shift count is non zero.
@rotr:
	and #0		; Reset A.
	lda #$40	; Set the shift count to 64.
	sta count	;
	lda.q tmp	; Get our magic number.
@rotr2:
	ror b		; Rotate the magic number right by our shift amount.
	dec count	; Decrement the shift count.
	beq @loop	; Increment the shift amount, if the shift count is zero.
	bra @rotr2	; Keep looping, if the shift count is non zero.

.org $FFC0
.qword reset
a
d