Page 1 of 1

FASM question

Posted: Fri Nov 18, 2005 12:38 pm
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?

Posted: Fri Nov 18, 2005 7:11 pm
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..

Posted: Sat Nov 19, 2005 2:26 pm
by eriansa
Thank you!

Posted: Sat Nov 26, 2005 7:42 am
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!!

Posted: Sat Nov 26, 2005 12:38 pm
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 '!'.

Posted: Sat Nov 26, 2005 4:41 pm
by rsts
Works fine for me - pb 3.94