Non-existant memory location...

Fibonacci code.. works on 23, but not on 24?

Page 1 of 1

3 Replies - 1213 Views - Last Post: 25 January 2010 - 08:04 AM

#1 oryp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-January 10

Non-existant memory location...

Post icon  Posted 24 January 2010 - 03:10 AM

Hi All. I'm working on a code in assembly (ChASM) that is supposed to calculate the Fibonacci value of a given number. I've pretty much completed my code, and it successfully computes the Fib. value of 23, but when I try to have it compute the Fib. value of 24, it says "Execution terminated: Indirection Fault trying to access non-existant memory location $61DD4A." I simply can't figure it out, any help would be appreciated. Thanks.

LDS# $E00
.EQU PUT_NUM, $E00
.EQU GET_NUM, $E01

JSR GET_NUM
STA N
N: .BLKW 1

LDA N
CMA# 1
JEQ end1

LDA N
CMA# 2
JEQ end1

LDA# 1
STA fibprev
fibprev: .BLKW 1
LDA# 1
STA fib
fib: .BLKW 1

LDA# 2
STA cur
cur: .BLKW 1


JMP LOOP

LOOP:
LDA fib
STA temp
temp: .BLKW 1
LDA fibprev
ADA fib
STA fib
LDA temp
STA fibprev
INC cur

LDA cur
CMA N
JLT LOOP
JGE END




END:
LDA fib
JSR PUT_NUM
HLT

end1:
LDA# 1
JSR PUT_NUM
HLT



Is This A Good Question/Topic? 0
  • +

Replies To: Non-existant memory location...

#2 Martyn.Rae   User is offline

  • The programming dinosaur
  • member icon

Reputation: 556
  • View blog
  • Posts: 1,436
  • Joined: 22-August 09

Re: Non-existant memory location...

Posted 24 January 2010 - 01:49 PM

As a rough guess, I suspect that as the Fibonacci value for 23 is 28657 which can be easily accomodated as a positive 16 bit signed value and the Fibonacci value for 24 is 46368 which would be considered a negative value may have something to do with the problem.

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#3 oryp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-January 10

Re: Non-existant memory location...

Posted 24 January 2010 - 03:36 PM

Thanks for the reply. That would make sense. Another possibility is something about overflow - the assembler may be indicating to me that an overflow occured with a signed operation. Unfortunately, either way, I have no idea what to change. Any ideas?
Was This Post Helpful? 0
  • +
  • -

#4 Martyn.Rae   User is offline

  • The programming dinosaur
  • member icon

Reputation: 556
  • View blog
  • Posts: 1,436
  • Joined: 22-August 09

Re: Non-existant memory location...

Posted 25 January 2010 - 08:04 AM

You need to increase the width of the input, output and summation fields to 32-bit from 16-bit. This will give a much better range of Fibonacci values. However, remember once you have reached 31 bits for the result, you will end up with the same problem as you have now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1