Omnimaga
Calculator Community => TI Calculators => ASM => Topic started 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
thanks in advance!

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
thanks in advance!
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.

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...

This is NOT an advertisment. aeTIos, you might try reading this:
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.

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.337x10^{3}), 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.337x10^{3}, it would be 3 + $80 (http://lmgtfy.com/?q=0x80+%2B+3), or $83.
Significand (S0S6)
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 TI83 Plus series calc).
It's stored in BCD (binarycoded decimal) (http://en.wikipedia.org/wiki/Binarycoded_decimal) format, in which each nibble holds a decimal digit (09). 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.337x10^{3}).
You could actually store a nonBCD 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 floatingpoint 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 floatingpoint 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 14digit numbers).
Thanks for:
the rickroll ;D
made me losing the game
this tutorial
its really useful!

What rickroll?

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.337x10^{3}), 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
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.337x10^{3}, 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

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)

Thanks! downloaded it immediately!

Thanks! downloaded it immediately!
You'll need a good PDF reader for that. It's HUGE.
Trust me, I once tried printing it all off. Gave up after the first half (~300 of ~600 pages).

Wow. Yeah, I have Adobe Acrobat, so thats okay
And I'm never, ever gonna print this :x