Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Fibonacci sequence (12-bit)
- ; Stores 12-bit Fibonacci values into @2000 upward, low word then high word
- ; per entry, and runs until the next value would overflow twelve bits.
- ; Soft reset
- .ORG @0000
- LD XY,#@2000
- ; Prep: seed the sequence with 1,1 and write both into the output table
- LD A,#1
- ST A,@3000
- LD A,#0
- ST A,@3001
- LD A,#1
- ST A,@3002
- LD A,#0
- ST A,@3003
- LD A,#1
- ST A,IXY
- INC XY
- LD A,#0
- ST A,IXY
- INC XY
- LD A,#1
- ST A,IXY
- INC XY
- LD A,#0
- ST A,IXY
- INC XY
- ; Main loop: sum = a + b, twelve bits wide; stop if it overflows
- seq:
- CLC
- LD A,@3000
- ADC @3002
- ST A,@3004
- LD A,@3001
- ADC @3003
- BR CC,cont
- JP done
- cont:
- ST A,@3005
- LD A,@3004
- ST A,IXY
- INC XY
- LD A,@3005
- ST A,IXY
- INC XY
- LD A,@3002
- ST A,@3000
- LD A,@3003
- ST A,@3001
- LD A,@3004
- ST A,@3002
- LD A,@3005
- ST A,@3003
- JP seq
- done:
- HLT
Advertisement
Add Comment
Please, Sign In to add comment