### Author Topic: Floats? (First ASM question O.O)  (Read 5194 times)

0 Members and 1 Guest are viewing this topic.

#### aeTIos

• Nonbinary computing specialist
• LV12 Extreme Poster (Next: 5000)
• Posts: 3913
• Rating: +184/-32
##### Floats? (First ASM question O.O)
« 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

I'm not a nerd but I pretend:

#### Ikkerens

• LV6 Super Member (Next: 500)
• Posts: 378
• Rating: +28/-9
• JavaScript Magician
##### Re: Floats? (First ASM question O.O)
« Reply #1 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.

Splut for Android [----------]
Paused/halted indefinitely, might be abandoned, our graphic designer quit and the rest of us simply doesn't have the time to work on it...

#### AngelFish

• Is this my custom title?
• LV12 Extreme Poster (Next: 5000)
• Posts: 3242
• Rating: +270/-27
• I'm a Fishbot
##### Re: Floats? (First ASM question O.O)
« Reply #2 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...
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

#### Hot_Dog

• CoT Emeritus
• LV12 Extreme Poster (Next: 5000)
• Posts: 3005
• Rating: +445/-10
##### Re: Floats? (First ASM question O.O)
« Reply #3 on: March 22, 2011, 01:13:56 pm »
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.

#### aeTIos

• Nonbinary computing specialist
• LV12 Extreme Poster (Next: 5000)
• Posts: 3913
• Rating: +184/-32
##### Re: Floats? (First ASM question O.O)
« Reply #4 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. 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 (as in -1.337x103), so you need to know what power of 10 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. So instead, you add $80 to whatever the exponent is, then store it. So for -1337, or -1.337x103, it would be 3 +$80, 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) 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

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, don't bother (unless for some reason you're working with 14-digit numbers).
Thanks for:
-the rickroll
-made me losing the game
-this tutorial

its really useful!
« Last Edit: July 16, 2011, 12:15:39 pm by Deep Thought »
I'm not a nerd but I pretend:

#### Hot_Dog

• CoT Emeritus
• LV12 Extreme Poster (Next: 5000)
• Posts: 3005
• Rating: +445/-10
##### Re: Floats? (First ASM question O.O)
« Reply #5 on: March 22, 2011, 02:06:26 pm »
What rickroll?

#### aeTIos

• Nonbinary computing specialist
• LV12 Extreme Poster (Next: 5000)
• Posts: 3913
• Rating: +184/-32
##### Re: Floats? (First ASM question O.O)
« Reply #6 on: March 22, 2011, 02:15:02 pm »
Exponent (Exp)

Here's where the fun starts. Floating points are always stored in scientific notation (as in -1.337x103), so you need to know what power of 10 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.

So instead, you add $80 to whatever the exponent is, then store it. So for -1337, or -1.337x103, it would be 3 +$80, or \$83.

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

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
« Last Edit: March 22, 2011, 02:16:48 pm by aeTIos »
I'm not a nerd but I pretend:

#### calc84maniac

• eZ80 Guru
• Coder Of Tomorrow
• LV11 Super Veteran (Next: 3000)
• Posts: 2906
• Rating: +469/-17
##### Re: Floats? (First ASM question O.O)
« Reply #7 on: March 22, 2011, 02:30:44 pm »
If you want to know how to math with floating point, check out the official documentation (specifically System Routines - Math)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

#### aeTIos

• Nonbinary computing specialist
• LV12 Extreme Poster (Next: 5000)
• Posts: 3913
• Rating: +184/-32
##### Re: Floats? (First ASM question O.O)
« Reply #8 on: March 22, 2011, 03:17:35 pm »
I'm not a nerd but I pretend:

#### Deep Toaster

• So much to do, so much time, so little motivation
• LV13 Extreme Addict (Next: 9001)
• Posts: 8217
• Rating: +758/-15
##### Re: Floats? (First ASM question O.O)
« Reply #9 on: March 22, 2011, 04:31:53 pm »

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

#### aeTIos

• Nonbinary computing specialist
• LV12 Extreme Poster (Next: 5000)
• Posts: 3913
• Rating: +184/-32
##### Re: Floats? (First ASM question O.O)
« Reply #10 on: March 23, 2011, 04:48:31 am »
Wow. Yeah, I have Adobe Acrobat, so thats okay
And I'm never, ever gonna print this :x
I'm not a nerd but I pretend: