Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Torio on January 24, 2012, 12:15:20 pm

Title: 4-byte integer
Post by: Torio on January 24, 2012, 12:15:20 pm
Hello,
I would like to know if it is possible to handle 4-byte integers in Axe Parser.
I would like to do divisions and modulo operations with those numbers.

Thank you !

(Sorry about my mistakes, I'm French.)
Title: Re: 4-byte integer
Post by: Xeda112358 on January 24, 2012, 02:48:45 pm
There were no mistakes that I could see actually :)
As for your question, I do not believe Axe normally supports 4-byte (32-bit/octet) values :/
I might have a hex opcode for 32 bit/16 bit and the same for modulo, though :)
Title: Re: 4-byte integer
Post by: Torio on January 24, 2012, 03:09:09 pm
Dommage...

I think I have to give up my idea in Axe and to program it in TI-Basic, but it is so sloooooow...
Title: Re: 4-byte integer
Post by: Xeda112358 on January 24, 2012, 03:10:38 pm
Hmm, what inputs and outputs do you need? There are lots of folks around that are better than I (I don't know Axe very well)
Title: Re: 4-byte integer
Post by: Torio on January 24, 2012, 03:25:27 pm
Well, I would like to make a program that gives the decomposition in primary numbers (is this the right word ?) of a number.
I need to make a 32b/16b division and modulo, as well as a 32b square root.

Is your hexcode usable in Axe, because it could be interesting ?
Title: Re: 4-byte integer
Post by: Xeda112358 on January 24, 2012, 03:35:37 pm
o.o Okay, I see why you need this, now. Are you saying you want to factor a number (I am an almost mathematician, so I understand your words). You mean like 78 is 2*3*13?

I can see what I can do... I know I could do the math parts in assembly, but it may take a while
Title: Re: 4-byte integer
Post by: Torio on January 24, 2012, 04:03:29 pm
Yes, you have understood what I want to do.
I have already done a version in TI-Basic, but too slow for great numbers, so I wanted to make it in Axe. Yet it is perfectly functional for usual numbers (lower than 1 million), so don't waste your time for a program that in fact wouldn't be very useful.
Title: Re: 4-byte integer
Post by: Xeda112358 on January 24, 2012, 04:07:15 pm
EDIT2: This code does not work yet :/

Okay :)
I have not tested this code, but it might work for 32/16:
Code: [Select]
A/C→D
A^C*256+B/256→A
B*256→B
D+A/C→D
A^C*256+B/256→A
A^C→E
D+A/C→D
It does AB/C and returns the division in D and the mod in E
(well, it is supposed to)

EDIT: Made it faster/smaller
Title: Re: 4-byte integer
Post by: Quigibo on January 24, 2012, 05:08:52 pm
Axe does not natively support integers larger than 16-bits since it is a game oriented language and most games don't need large integers.  However, if you know a little bit about arithmetic algorithms you can definitely code these routines in Axe as Xeda has done above, or even some inline assembly if you want a more optimized version and you know z80.
Title: Re: 4-byte integer
Post by: Xeda112358 on January 24, 2012, 05:10:01 pm
Also, Jacobly has found my code not to work (and I had syntax issues, too) :/
Title: Re: 4-byte integer
Post by: Torio on January 25, 2012, 09:29:55 am
Ok, thank you for your help !

I have found the code for the modulo, but it is the easiest for the three operations.

To make AB^P and store it into R :
Code: [Select]
65535^P+1^P*A^P+B^P=>R
I'm going to try the square root now !
Title: Re: 4-byte integer
Post by: Xeda112358 on January 25, 2012, 11:14:09 am
Is an approximation okay? I have some algorithms that could work for you and I am working on some more :) A very small and easy algorithm looks like this:
(This is not Axe code, but it will work very nicely for 32-bit integers)
Code: [Select]
65535→B          ;just the initial condition. Feel free to experiment, this can be anything. (try 32767?)
Repeat abs(X-B)<2
(B+X/B)/2→B
End
It will need at most 16 iterations for a 32-bit number (fewer iterations for larger numbers) for a 32-bit number. There are, however, faster methods, but I don't know how to do it in Axe :/ Again, I could write some assembly code, possibly or a mix of Assembly and Axe.

EDIT: Fixed my code, I accidentally forgot to remove some scratch work