Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: aeTIos on March 22, 2011, 12:48:22 pm

Title: Floats? (First ASM question O.O)
Post by: aeTIos on March 22, 2011, 12:48:22 pm
Hi,

first things first, this is my 1st question on ASM programming!

The question is: how easy (or hard) is it to use floats?
if easy, please qive some code

Title: Re: Floats? (First ASM question O.O)
Post by: Ikkerens on March 22, 2011, 12:55:07 pm
Hi,

first things first, this is my 1st question on ASM programming!

The question is: how easy (or hard) is it to use floats?
if easy, please qive some code

I can't tell you how to do it, but it ain't easy, as the calc only "thinks" in integers.
And besides that, it has a huge impact on speed.
Title: Re: Floats? (First ASM question O.O)
Post by: AngelFish on March 22, 2011, 01:05:55 pm
By floats, I'll assume you mean Floating point numbers and not parade floats, which are a legendary dark programming secret.
First of all, on the 8x calcs, floating point numbers are kept in a specific format that's different from regular assembly numbers. Starting with the basics, each floating point real number is 9 bytes in length. The first byte is known as the sign byte and the second byte is called the exponent. The 7 bytes after that are known as the mantissa and they store the actual value of the number in a manner similar to  scientific notation. The number is multiplied by 10^<value of the exponent> and then the sign bit is added to get the value of the number. To define a floating point number as real, you have to change the sign byte, which for positive real numbers is 0x00h and 0x80h if negative. The exponent is defined by a similar format, with bytes 0x80h through 0xFFh as positive exponents and 0x7Fh through 0x00h as negative -1 through -127. The actual data bytes of the floating point number are stored with one digit per nibble. The most significant digit of the data is always the only number in front of the decimal point, with all other digits falling behind.

Hope that helps a bit, until someone else explains how to manipulate the floating point number.

And I just know I'm going to be ninja'd on this...
Title: Re: Floats? (First ASM question O.O)
Post by: Hot_Dog on March 22, 2011, 01:13:56 pm

http://www.omnimaga.org/index.php?action=dlattach;topic=2076.0;attach=3418

I'm assuming you know a little bit about ASM.  You can ignore the section on Index Registers.
Title: Re: Floats? (First ASM question O.O)
Post by: aeTIos on March 22, 2011, 02:04:05 pm
Quick tutorial:

Floating point numbers are stored differently than you're used to. It's still stored the same way, but it's a data structure in itself.

Each floating point number is 9 bytes, stored one after the other, always in scientific notation. For example, this is what -1337 looks like:

 Sign Exp S0 S1 S2 S3 S4 S5 S6 \$80 \$83 \$13 \$37 \$00 \$00 \$00 \$00 \$00

Sign/Number Line (Sign)

Bit 7 (the bit furthest to the left when you write it out) tells you whether it's positive or negative, while bits 2 and 3 tell you whether it's real or complex (http://en.wikipedia.org/wiki/Complex_number). In other words:

 If this byte is: Then the number is: %00000000 Positive and real %10000000 Negative and real %00001100 Positive and complex %10001100 Negative and complex

So in this case, it would be %10000000, or \$80.

Exponent (Exp)

Here's where the fun starts. Floating points are always stored in scientific notation (http://en.wikipedia.org/wiki/Scientific_notation) (as in -1.337x103), so you need to know what power of 10 (http://www.youtube.com/watch?v=0fKBhvDjuy0) it's being taken to. In this case, it would be three.

But you don't just store a three here; no, that would be too easy, and remember that TI wants to screw us up (http://www.youtube.com/watch?v=oHg5SJYRHA0). So instead, you add \$80 to whatever the exponent is, then store it. So for -1337, or -1.337x103, it would be 3 + \$80 (http://lmgtfy.com/?q=0x80+%2B+3), or \$83.

Significand (S0-S6)

This is the actual number itself. There are 7 bytes per number, each of which holds two digits (hence the 14 digits of accuracy on a TI-83 Plus series calc).

It's stored in BCD (binary-coded decimal) (http://en.wikipedia.org/wiki/Binary-coded_decimal) format, in which each nibble holds a decimal digit (0-9). So a valid byte in the significand would be one of the following:

• \$00-\$09
• \$10-\$19
• \$20-\$29
• \$30-\$39
• \$40-\$49
• \$50-\$59
• \$60-\$69
• \$70-\$79
• \$80-\$89
• \$90-\$99

The first digit (upper nibble of S0) is the characteristic, or the number before the decimal point when written in scientific notation (the 1 in -1.337x103).

You could actually store a non-BCD value there (such as \$BA). It causes some interesting effects when you try doing math with it XD

Also, when the calculator actually operates on floating-point numbers (when you give it something to calculate), it adds two more bytes to the significand (making the significand 9 bytes and the entire number 11 bytes). This is so it has two more bytes of precision to work with.

All right, so that's a floating-point number. When do you use it? FP is nearly always used for math, because it's inherently slow and cumbersome to work with. So if you want to use it for scores in a game (http://en.wikipedia.org/wiki/The_Game_(mind_game)), don't bother (unless for some reason you're working with 14-digit numbers).
Thanks for:
-the rickroll ;D
-this tutorial

its really useful!
Title: Re: Floats? (First ASM question O.O)
Post by: Hot_Dog on March 22, 2011, 02:06:26 pm
What rickroll?
Title: Re: Floats? (First ASM question O.O)
Post by: aeTIos on March 22, 2011, 02:15:02 pm
Exponent (Exp)

Here's where the fun starts. Floating points are always stored in scientific notation (http://en.wikipedia.org/wiki/Scientific_notation) (as in -1.337x103), so you need to know what power of 10 (http://www.youtube.com/watch?v=0fKBhvDjuy0) it's being taken to. In this case, it would be three.

But you don't just store a three here; no, that would be too easy, and remember that TI wants to

THIS

So instead, you add \$80 to whatever the exponent is, then store it. So for -1337, or -1.337x103, it would be 3 + \$80 (http://lmgtfy.com/?q=0x80+%2B+3), or \$83.

um, you can find it, i think. italic, bold, underlined :D

Oh, and your explaination in your tutorial is great, too! In fact, this has brought me to learning ASM programming. but, OMG, I think i should just work through it, starting at lesson 13 is a bit hard :P
Title: Re: Floats? (First ASM question O.O)
Post by: calc84maniac on March 22, 2011, 02:30:44 pm
If you want to know how to math with floating point, check out the official documentation (http://education.ti.com/guidebooks/sdk/83p/83psysroutines.pdf) (specifically System Routines - Math)
Title: Re: Floats? (First ASM question O.O)
Post by: aeTIos on March 22, 2011, 03:17:35 pm