Search found 96 matches

by dioxin
Wed Dec 09, 2009 1:10 pm
Forum: Coding Questions
Topic: Math related question, level 2
Replies: 10
Views: 2021

Re: Math related question, level 2

A and B are close enough together that we can ignore the curvature of the Earth and still get a good result so just use basic trigonometry.

A is North of B by 48d30m - 48d00m = 0d30m = 0.5d
A is East of B by 6d20m - 5d20m = 1d00m = 1.0d

North is therefore off to the bottom left of the grid at an ...
by dioxin
Sun Jul 19, 2009 5:38 pm
Forum: Coding Questions
Topic: Factorial
Replies: 10
Views: 2377

The FPU can handle 80bit Extended floating point numbers which will give you up to 1754! before it overflows but you'll have to program it in ASM as PB doesn't handle extended FP values. Psuedo code follows.
!fld1
!fld1
!fld Argument 'the input argument

lp:
!fmul st(1),st(0)
!fsub st(0),st(2 ...
by dioxin
Thu Apr 16, 2009 2:59 pm
Forum: Coding Questions
Topic: Assembler optimizing - simple questions
Replies: 13
Views: 3772

Probably faster because it avoids the jump but uses edx register as well:

Code: Select all

!mov eax,MyValue
!cdq
!xor eax,edx
!sub eax,edx
'eax now contains ABS(MyValue)
by dioxin
Mon Apr 13, 2009 10:27 pm
Forum: Coding Questions
Topic: Assembler optimizing - expert section
Replies: 12
Views: 2770

If x1>=0 And x1<ScreenX And y1>=0 And y1<ScreenY
CallFunctionFast(DxFunction,x1,y1,r,g,b,255)
EndIf
Untested but should show you one way:
!mov eax,xCoOrdinate 'get x
!mov ecx,yCoOrdinate 'get y
!cmp eax,ScreenSizeX 'is x greater than the screen x size?
!jg ExitIf 'yes, then exit
!cmp ecx ...
by dioxin
Mon Apr 13, 2009 9:44 pm
Forum: Coding Questions
Topic: can this FPU assembly code be optimised
Replies: 7
Views: 1753

also I want to see the FPU stack what do I do
Get Ollydbg from here:
http://www.ollydbg.de/

Once installed, you place a !INT 3 opcode just ahead of the code which is of interest and the debugger will start and allow you to single step while showing you the stack and all registers and a lot more.
by dioxin
Mon Apr 13, 2009 9:26 pm
Forum: Coding Questions
Topic: Assembler optimizing - simple questions
Replies: 13
Views: 3772

Please give me a hint
Try using the conditional move instructions as they'll cut out all the jumps

'syntax may need revising to work with PB
mn = 0 'the lower bound
mx = 255 'the upper bound

!mov eax,YourInputNumber
!cmp eax,mx 'compare with top limit
!cmovg eax,mx 'if greater then set value to ...
by dioxin
Fri Apr 10, 2009 5:37 pm
Forum: Coding Questions
Topic: can this FPU assembly code be optimised
Replies: 7
Views: 1753

If you're going to take ASM programming seriously then you need to know what instructions are available and what they do.
Get the manuals from intel, they're free downloads:
http://www.intel.com/products/processor/manuals/
Volumes 2A and 2B are the ones you need most of the time as they describe all ...
by dioxin
Fri Apr 10, 2009 12:17 pm
Forum: Coding Questions
Topic: can this FPU assembly code be optimised
Replies: 7
Views: 1753

You can add the number without loading it from memory first:

Code: Select all

a.d = 3 

FLDPI   'get pi
FADD a  'add in the variable direct from memory
FSTP a  'store the result and clear up the stack

Debug a
by dioxin
Tue Mar 31, 2009 4:44 pm
Forum: Tricks 'n' Tips
Topic: SendKeys Procedure
Replies: 11
Views: 10199

For multiple keys use SendInput:

http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx

The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events are not interspersed with other keyboard or mouse input events inserted ...
by dioxin
Tue Nov 18, 2008 12:18 am
Forum: Tricks 'n' Tips
Topic: StrE(FPnumber, sig_digits)
Replies: 5
Views: 2838

akj,
I suspect that the FNINIT instruction should be replaced by something less drastic
You could save and restore the full FPU state so it's not messed up by your code but this is a bit slow:

'save the full FPU state
!sub esp,108 'make room for 108 bytes of FPU status
!fsave [esp]

..do what ...
by dioxin
Sat Nov 15, 2008 7:09 pm
Forum: Coding Questions
Topic: Fastest way to get the decimals of a float?
Replies: 28
Views: 3781

Trond,
your method would appear more impressive if you called decimals3 somewhere instead of calling decimals2 twice!
by dioxin
Sat Nov 15, 2008 4:53 pm
Forum: Coding Questions
Topic: Fastest way to get the decimals of a float?
Replies: 28
Views: 3781

superadnim,
even though the benchmarks take much longer

That's the answer, "even though it takes much longer".
For the sake of argument, let's say the INT() method takes 500clks and the ASM method takes 50clks and your generating of random numbers takes 2,000clks.

Total time would then be 2,500 ...
by dioxin
Sat Nov 15, 2008 3:14 pm
Forum: Coding Questions
Topic: Fastest way to get the decimals of a float?
Replies: 28
Views: 3781

superadnim,
It doesn't matter if you store the value before or after that final ADD.

Something doesn't add up. Looking at the ASM code produced by the compiler for your original macro (_n_-Int(_n_)) there's no way that the ASM I posted above should be only 29% faster.
How long does your 10,000 ...
by dioxin
Sat Nov 15, 2008 1:54 pm
Forum: Coding Questions
Topic: Fastest way to get the decimals of a float?
Replies: 28
Views: 3781

Superadnim,
I'd have expected better than 20% improvement, it runs in about 30clks on my PC. Have you tried using a macro for the ASM function instead of calling it in a procedure? For very short code like this the overhead of calling the procedure becomes significant.
by dioxin
Fri Nov 14, 2008 1:10 pm
Forum: Coding Questions
Topic: Fastest way to get the decimals of a float?
Replies: 28
Views: 3781

I don't mind ASM
!push &h1f7f0000 'the FP control word needed to round to zero
!fstcw [esp] 'save the current FP control word
!fldcw [esp+2] 'set the FP to round to zero
!fld MyNumber 'load the FP with the number to work on
!fld st(0) 'replicate that number on the stack
!frndint 'round number to ...