flat assembler
Message board for the users of flat assembler.

 Index > Main > code resolving magic Goto page 1, 2  Next
Author
 Thread
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8132
Location: Kraków, Poland
Tomasz Grysztar 24 Jan 2006, 10:53
This would go to the fasm's "Did you know..." section if there was one.

One of the cases when fasm is actually able to solve a set of equations:
Code:
```x = (y-2)*(y+1)/2-2*y
y = x+1

dd x,y    ```
24 Jan 2006, 10:53
gunblade

Joined: 19 Feb 2004
Posts: 209
gunblade 24 Jan 2006, 10:57
Thats indeed very impressive, could save some pressious cycles in certain situations. Any idea to the limits of the complexity of the function?

Thanks,
gunblade
24 Jan 2006, 10:57
decard

Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 24 Jan 2006, 10:58
wow :O
24 Jan 2006, 10:58
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8132
Location: Kraków, Poland
Tomasz Grysztar 24 Jan 2006, 11:00
There are no limits to the complexity of function, but there are other limits: mainly that iterated searching for solution will actually fail in most cases of complex arithmetic equations - fasm's code resolving was designed to deal rather with code optimization than mathematic problems. The above is just a kind of curiosity.
24 Jan 2006, 11:00
RedGhost

Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 25 Jan 2006, 04:31
i have used this for row/column pixel drawing in my hobby os in graphics mode

its alot easier than doing it in my head (i suck at math) and alot faster than letting it assemble with add, sub, div, and etc

i found this out by accident, and it just made me love fasm even more!

_________________
redghost.ca
25 Jan 2006, 04:31
edemko

Joined: 18 Jul 2009
Posts: 549
edemko 09 Jul 2010, 18:47
Code:
```x = (y-2)*(y+1)/2-2*y ;\
y = x+1               ; \
dd x,y                ;/ my new signature on wasm.ru, thanks TG

;Having seen it my eyes became hugged with hands.
;Nice blast.
;Internals and thanks:
x = (x+1-2)*(x+1+1)/2-2*(x+1)
y = x+1
dd x,y
```
09 Jul 2010, 18:47
ass0

Joined: 31 Dec 2008
Posts: 518
Location: ( . Y . )
ass0 09 Jul 2010, 19:15
Are you all being sarcastic? or i am missing something. =S

Code:
```x = (y-2)*(y+1)/2-2*y
y = x+1
dd x,y ;6,7
```

Code:
```;but this:
x = (y-2)*(y+1)/3-2*y
y = x+1
dd x,y;error: value out of range.
```

Code:
```;and this:
x = (y-2)*(y+1)/2*y
y = x+1
dd x,y;error: code cannot be generated.
```

_________________

Nombre: Aquiles Castro.
Location2: about:robots
09 Jul 2010, 19:15
edemko

Joined: 18 Jul 2009
Posts: 549
edemko 09 Jul 2010, 19:25
when i try compiling all 3 samples it says "symbol 'y' out of scope"
?
09 Jul 2010, 19:25
baldr

Joined: 19 Mar 2008
Posts: 1651
baldr 11 Jul 2010, 04:47
ass0,

No wonder it gives you errors in latter two cases: it's all about the way fasm resolves dependencies.

fasm doesn't try to solve system of equations: it performs multiple passes, up to 100 or whichever value you've specified in -p option (or Passes value in [Compiler] section of FASMW.INI), and uses some hints from previous passes to get closer to (or farther from) the solution (one of many possible, perhaps).

Let's consider simple case:
Code:
```sqrt = (25/approx+approx)/2
approx = sqrt+1    ```
Pass 0: approx is neither defined yet, nor have predicted value, thus sqrt is assigned default value (0); then approx becomes 1.
Pass 1: approx still not defined yet, but it has predicted value of 1 (from previous pass), sqrt is set to 13; approx receives new value of 14.
Pass 2: sqrt = (25/14+14)/2 = 7; approx = 8.
Pass 3: sqrt = (25/8+8)/2 = 5; approx = 6.
Pass 4: sqrt = (25/6+6)/2 = 5; approx = 6. Solution is stable: there were no mispredictions during this pass, so it's final.

Now take a look at
Code:
```x = (y-2)*(y+1)/3-2*y
y = x+1    ```
There is a solution for x = ((x+1)-2)*((x+1)+1)/3-2*(x+1) equation (x = 9; you can check it by replacing y = x+1 with y = 9+1), but it is unattainable using the steps explained above (iterations don't converge to solution, they simply miss it by 5 on fifth pass), and value of x after dozen passes overflows signed 64-bit integer.

Your next example exhibits another behavior: first pass finishes with (x, y) = (0, 1), second one with (-1, 0), next with (0, 1) and values oscillate so on, until compiler says it's tired.

Corollary: fasm can do amazing things it's not supposed to, but you must know enough of its inner workings to be sure that the result is correct/reachable.

----8<----
edemko,

Have you compiled exactly the code shown?
11 Jul 2010, 04:47
ass0

Joined: 31 Dec 2008
Posts: 518
Location: ( . Y . )
ass0 11 Jul 2010, 09:31
Cooooool! Yet is a little dangerous feature. =D

_________________

Nombre: Aquiles Castro.
Location2: about:robots
11 Jul 2010, 09:31
edemko

Joined: 18 Jul 2009
Posts: 549
edemko 11 Jul 2010, 11:24
baldr wrote:

Have you compiled exactly the code shown?

all three ass0's samples in same order
11 Jul 2010, 11:24
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19254
Location: In your JS exploiting you and your system
revolution 11 Jul 2010, 11:38
edemko wrote:
baldr wrote:

Have you compiled exactly the code shown?

all three ass0's samples in same order
Then something is very wrong with your assembler. What version are you using? The Wink version?
11 Jul 2010, 11:38
edemko

Joined: 18 Jul 2009
Posts: 549
edemko 11 Jul 2010, 11:43
i do
Code:
```/*
x = (y-2)*(y+1)/2-2*y ;\
y = x+1               ; \
dd x,y                ;/ my new signature on wasm.ru, thanks TG

;Having seen it my eyes became hugged with hands.
;Nice blast.
;Internals and thanks:
x = (x+1-2)*(x+1+1)/2-2*(x+1)
y = x+1
dd x,y
*/

;ass0
;Are you all being sarcastic? or i am missing something. =S

;Code:
x = (y-2)*(y+1)/2-2*y
y = x+1
dd x,y ;6,7

;Code:
;but this:
x = (y-2)*(y+1)/3-2*y
y = x+1
dd x,y;error: value out of range.

;Code:
;and this:
x = (y-2)*(y+1)/2*y
y = x+1
dd x,y;error: code cannot be generated.
```
11 Jul 2010, 11:43
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19254
Location: In your JS exploiting you and your system
revolution 11 Jul 2010, 13:11
You have to do each as a separate file. You can't combine all three together like that unless you change the variable names.
11 Jul 2010, 13:11
baldr

Joined: 19 Mar 2008
Posts: 1651
baldr 11 Jul 2010, 21:38
revolution,

Not a completely new definition of "all 3 samples", but I'm shocked.
11 Jul 2010, 21:38
edfed

Joined: 20 Feb 2006
Posts: 4302
Location: Now
edfed 12 Jul 2010, 23:13
it is simply amazing how nature is...

just see it as a basic rule of a world (fasm directives resolution), and then, see how the simple rule for resolution can give complex results.
exactlly as particles, two particles of same charge will repulse.
then, put a lot of particles in vacumm, and lets play the nature, the sun appear, planets, humans, and computer with fasm "installed".

some 256 bytes demos uses only few instructions and will give really cool effects.

the rules are the engine of a game.
12 Jul 2010, 23:13
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19254
Location: In your JS exploiting you and your system
revolution 13 Jul 2010, 01:45
Simple rules can give complex results.

Anyone up for a game of Go?
13 Jul 2010, 01:45
baldr

Joined: 19 Mar 2008
Posts: 1651
baldr 13 Jul 2010, 13:38
revolution,

I'm up to, on FlyOrDie.
13 Jul 2010, 13:38
ender

Joined: 03 Nov 2004
Posts: 11
Location: London, UK
ender 13 Jul 2010, 13:50
As for Go - I'm in. I'm not very strong but... well, I may take the goban with me - anyone for a little bit of tournament?

_________________
&r
13 Jul 2010, 13:50
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 13 Jul 2010, 13:52
ender: I never played it "in real", and I would enjoy trying it out.
13 Jul 2010, 13:52
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area
Goto page 1, 2  Next

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum

Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.