Giomancer

12-bit Fibonacci

Aug 20th, 2026
32
0
315 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Fibonacci sequence (12-bit)
  2. ; Stores 12-bit Fibonacci values into @2000 upward, low word then high word
  3. ; per entry, and runs until the next value would overflow twelve bits.
  4.  
  5.  
  6. ; Soft reset
  7.     .ORG @0000
  8.     LD XY,#@2000
  9.  
  10. ; Prep: seed the sequence with 1,1 and write both into the output table
  11.     LD A,#1
  12.     ST A,@3000
  13.     LD A,#0
  14.     ST A,@3001
  15.     LD A,#1
  16.     ST A,@3002
  17.     LD A,#0
  18.     ST A,@3003
  19.  
  20.     LD A,#1
  21.     ST A,IXY
  22.     INC XY
  23.     LD A,#0
  24.     ST A,IXY
  25.     INC XY
  26.     LD A,#1
  27.     ST A,IXY
  28.     INC XY
  29.     LD A,#0
  30.     ST A,IXY
  31.     INC XY
  32.  
  33. ; Main loop: sum = a + b, twelve bits wide; stop if it overflows
  34. seq:
  35.     CLC
  36.     LD A,@3000
  37.     ADC @3002
  38.     ST A,@3004
  39.  
  40.     LD A,@3001
  41.     ADC @3003
  42.     BR CC,cont
  43.     JP done
  44. cont:
  45.     ST A,@3005
  46.  
  47.     LD A,@3004
  48.     ST A,IXY
  49.     INC XY
  50.     LD A,@3005
  51.     ST A,IXY
  52.     INC XY
  53.  
  54.     LD A,@3002
  55.     ST A,@3000
  56.     LD A,@3003
  57.     ST A,@3001
  58.  
  59.     LD A,@3004
  60.     ST A,@3002
  61.     LD A,@3005
  62.     ST A,@3003
  63.  
  64.     JP seq
  65.  
  66. done:
  67.     HLT
Advertisement
Add Comment
Please, Sign In to add comment