flat assembler
Message board for the users of flat assembler.

Index > Main > code resolving magic

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
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    
Post 24 Jan 2006, 10:53
View user's profile Send private message Visit poster's website Reply with quote
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
Post 24 Jan 2006, 10:57
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 24 Jan 2006, 10:58
wow :O
Post 24 Jan 2006, 10:58
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
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.
Post 24 Jan 2006, 11:00
View user's profile Send private message Visit poster's website Reply with quote
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
Post 25 Jan 2006, 04:31
View user's profile Send private message AIM Address MSN Messenger Reply with quote
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
    
Post 09 Jul 2010, 18:47
View user's profile Send private message Reply with quote
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.
    

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 09 Jul 2010, 19:15
View user's profile Send private message Reply with quote
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"
?
Post 09 Jul 2010, 19:25
View user's profile Send private message Reply with quote
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?
Post 11 Jul 2010, 04:47
View user's profile Send private message Reply with quote
ass0



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

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 11 Jul 2010, 09:31
View user's profile Send private message Reply with quote
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
Post 11 Jul 2010, 11:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
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?
Post 11 Jul 2010, 11:38
View user's profile Send private message Visit poster's website Reply with quote
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.
    
Post 11 Jul 2010, 11:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
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.
Post 11 Jul 2010, 13:11
View user's profile Send private message Visit poster's website Reply with quote
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. Wink
Post 11 Jul 2010, 21:38
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
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". Smile

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

the rules are the engine of a game.
Post 12 Jul 2010, 23:13
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
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?
Post 13 Jul 2010, 01:45
View user's profile Send private message Visit poster's website Reply with quote
baldr



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

I'm up to, on FlyOrDie.
Post 13 Jul 2010, 13:38
View user's profile Send private message Reply with quote
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? Wink

_________________
&r
Post 13 Jul 2010, 13:50
View user's profile Send private message Reply with quote
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.
Post 13 Jul 2010, 13:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


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

Website powered by rwasa.