FASM question

Windows specific forum
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

FASM question

Post by eriansa »

I have a long variable that contains following :

Code: Select all

a.b ;(minvalue)
b.b ;(maxvalue)
c.b ;(value)
varLong.l = 0<<24|a<<16|b<<8|c
Depending on minvalue and maxvalue :

Code: Select all

a.b=varLong>>16
b.b=varLong>>8
c.b=varLong
if a<b
 c+1
 If c>b:c=a:EndIf
else
 c-1
 If c<b:c=a:EndIf
endif

varLong.l = 0<<24|a<<16|b<<8|c
There must be a really fast way to write this in inl. asm.
(but I am a complete idiot in asm)

Anybody?
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Ok, i've got a solution but it's only if you intended the packing of the bytes into the long to work like the line below:

Code: Select all

var1.l = (a&$ff)<<16|(b&$ff)<<8|(c&$ff )
Because of how PB works your version of the line above produces some unwanted (wanted by you?) effects if the byte values are negative.. anyhow below is some asm that should work..(badly commented as usual):

Code: Select all

DisableDebugger

var1.l = 0
var2.l = 0
t1.l = GetTickCount_()

For i.l = 0 To $02ffffff

a.b=i>>16
b.b=i>>8
c.b=i
If a<b
 c+1
 If c>b:c=a:EndIf
Else
 c-1
 If c<b:c=a:EndIf
EndIf

var1.l = (a&$ff)<<16|(b&$ff)<<8|(c&$ff )
Next i

t2.l = GetTickCount_()

For i.l = 0 To $02ffffff

! MOV eax, dword [v_i]
! MOV cl, al
! SHR eax, 8
! MOV bl, al
! SHR eax, 8
; c = cl, b = bl, a = al
! CMP al, bl ; ?a = b
! SETL bh ; if a < b then 'bh = 1' else 'bh = 0'
! ADD cl, bh ; c+1
! DEC bh     ; |
! ADD cl, bh ; | c-1

! CMP cl, bl ; ?c=b
! SETL dh ; if c < b then 'dh = 1' elase 'dh = 0'
! SETG dl ; if c > b then 'dl = 1' else 'dl = 0'
! And dh, bh
! INC bh
! And dl, bh
! MOV bh, al
! Or dl, dh
! DEC dl
! And cl, dl
! NOT dl
! And bh, dl
! Or cl, bh
! SHL eax, 8
! MOV al, bl
! SHL eax, 8
! MOV al, cl

! MOV dword [v_var2], eax

Next i

t3.l = GetTickCount_()

EnableDebugger

Debug "finished!"
Debug "T1 = "+Str(t2-t1)+"ms, T2 = "+Str(t3-t2)+"ms"
There's probably some room for improvements to speed up the asm even more, but i'll leave that to someone else to do..
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Post by eriansa »

Thank you!
doodlemunch
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Apr 05, 2005 11:20 pm

Post by doodlemunch »

i got purebasic.asm [165]:
mov eax, dword [v_i]
error: undefined symbol.

asemblar error when i compileded
what is wrong? i have 3.94 and asm enabled!!
my english is horribel i know - SORRY i am dyslexic - i uses pb 3.94
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

doodlemunch wrote:i got purebasic.asm [165]:
mov eax, dword [v_i]
error: undefined symbol.

asemblar error when i compileded
what is wrong? i have 3.94 and asm enabled!!
Did you use the code as it's posted or have you altered it, i.e. maybe put it inside a procedure etc?

You don't need to enable asm because the asm is passed directly to fasm when a line starts with '!'.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Works fine for me - pb 3.94
Post Reply