-1

I know it is not possible in one register but what is the best method to store it? I am trying to solve Euler's problem 25 in arm assembly. I have the fibonacci part completed but cannot figure out how to keep doing it until I get to a thousand digits. It would be around the 4782th fibonacci number.

Storing in separate registers, but that would require a lot of registers.

Link to eulers problem: https://projecteuler.net/problem=25

1 Answers1

2

The number 101000 consists of a little over 3300 bits. Unless ARM has hundreds of 32-bit registers that you can use for this, it's not going to be done in registers.

Even if it did have that many registers, it's probably still not optimised toward treating them all as a single unit.

What you will probably need to do is to store these things in memory (as a {sign, numBytes, byteArray[]} structure of some description). You can look at this earlier answer of mine to see one way for implementing basic arithmetic operations on "bignum" types.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Sorry my wording for my question was a little weird. I know its not possible to store a number that large in a register, but I need help on how I could go about storing it so I could use it in assembly. – TerminatorDe Apr 30 '19 at 01:20
  • AArch64 has thirty-two 128-bit vector registers, `q0..31` so there actually *is* enough room (4096 bits). Not on ARM32 though, with only q0..15 or d0..31. But with no mechanism for carry propagation from one SIMD element to the next, that's not useful. :P – Peter Cordes Apr 30 '19 at 02:04
  • Anyway, @TerminatorDe: you probably don't want a byte array, but rather an array of words, so you can work in base 2^32. Or since you care about *decimal* digits, maybe in base 10^9 in a 32-bit word (like Python does), emulating carry with compares. For more tricks for working with large Fibonacci numbers, see [Extreme Fibonacci](//codegolf.stackexchange.com/q/133618). e.g. you can find `F(2n)` from `F(n)` (but then you'd need to implement extended-precision multiply). Or keeping only the leading several digits of `F(n)` because it grows quickly enough to make the low digits irrelevant. – Peter Cordes Apr 30 '19 at 02:12