Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Josephus-problem/6502-Assembly/josephus-problem.6502
Normal file
34
Task/Josephus-problem/6502-Assembly/josephus-problem.6502
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
JSEPHS: STA $D0 ; n
|
||||
STX $D1 ; k
|
||||
LDA #$FF
|
||||
LDX #$00
|
||||
SETUP: STA $1000,X ; populate array with hex FF
|
||||
INX
|
||||
CPX $D0
|
||||
BEQ KILL
|
||||
JMP SETUP
|
||||
KILL: LDA #$00 ; number killed so far
|
||||
STA $D2
|
||||
LDX #$00 ; position within array
|
||||
LDY #$01 ; counting up to k
|
||||
FIND: INY
|
||||
SCAN: INX
|
||||
CPX $D0
|
||||
BMI TEST
|
||||
LDX #$00 ; circle back around
|
||||
TEST: LDA $1000,X
|
||||
CMP #$FF
|
||||
BNE SCAN ; already been killed
|
||||
CPY $D1
|
||||
BMI FIND ; if y < k keep going round
|
||||
LDA $D2
|
||||
STA $1000,X ; mark as dead
|
||||
CLC
|
||||
ADC #$01
|
||||
STA $D2
|
||||
CMP $D0 ; have we killed all but 1?
|
||||
BPL RETURN
|
||||
LDY #$00
|
||||
JMP FIND
|
||||
RETURN: TXA ; a <- index of survivor
|
||||
RTS
|
||||
Loading…
Add table
Add a link
Reference in a new issue