ASM junk error

DOS specific questions.
Post Reply
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

ASM junk error

Post by Cpcdos »

Hi guys

I've want to test this program viewtopic.php?f=7&t=3545
with -lang fb, -gen gcc (or gas)

And i've this error :
Image
i've already coded with inline asm.. hmm it's strange i'm lost lol.
he can't take account my [a] and variable what ?

Code: Select all

private function fbmld_search _
	( _
		byval root    as fbmld_t ptr ptr, _
		byval pt      as any ptr _
	) as fbmld_t ptr ptr

	dim as fbmld_t ptr ptr node = root
	dim as any ptr a = pt, b = any

		
	asm
		mov eax, dword ptr [a]     <--- HERE
		bswap eax
		mov dword ptr [a], eax     <--- HERE
	end asm

	while *node <> NULL
		b = (*node)->pt
		asm
			mov eax, dword ptr [b]     <--- HERE
			bswap eax
			mov dword ptr [b], eax     <--- HERE
		end asm
		if a < b then
			node = @(*node)->left
		elseif a > b then
			node = @(*node)->right
		else
			exit while
		end if
	wend

	function = node

end function
Can you help me ! :(
Thank you!
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: ASM junk error

Post by D.J.Peters »

I'm not at home so I can't test it but you can try this:

Code: Select all

mov dword eax,a ' get address of a in eax
mov eax, dword ptr [eax] ' get 32-bit value from address
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: ASM junk error

Post by Cpcdos »

True coder can code out of home aha :D Thank you for your reply

Same problem, junk error, he can't reconize syntax.. it's strange, i've tested more combinaisons with without [], swap "dword ptr" etc..
i can write the Freebasic code for swap 0-7 <-> 24-32 & 8-15 <-> 16-23
like

Code: Select all

    Dim pp As ubyte ptr = cptr(Ubyte Ptr, @MyVariable)
    dim result as Uinteger = cuint(pp[0]) Shl 24 Or cuint(pp[1]) Shl 16 Or cuint(pp[2]) Shl  8 Or cuint(pp[3])
and this problem is maybe resolved but.. it's more optimised to use this bswap native x86 instruction :(

Regards
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: ASM junk error

Post by angros47 »

it's more optimised to use this bswap native x86 instruction
And it's more portable to use FreeBasic syntax (perhaps in the future you might want to port your software to an ARM processor)
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: ASM junk error

Post by marcov »

Well, then it is probably the GAS version. Intel syntax in GAS used to be quite buggy, so if you have something old there, that might be the reason.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: ASM junk error

Post by Munair »

Have you tried to compile a simple example, as posted in the thread you linked to?

Code: Select all

#define FBMLD_NO_MULTITHREADING
#include once "fbmld.bi"

DECLARE FUNCTION Dummy () AS UBYTE PTR

FUNCTION Dummy () AS UBYTE PTR
DIM buffer AS UBYTE PTR
buffer = Allocate((50*50+1)*4)
'BLOAD "50x50.bmp", buffer
RETURN buffer
END FUNCTION

SCREENRES 640,480,16
DIM Buffer AS UBYTE PTR
Buffer = Dummy()
PUT (100,100), Buffer, PSET
DeAllocate (Buffer)
SLEEP
END
It compiles and runs just fine here on Linux 64 bit with the same parameters: fbc -gen gcc fbmld.bas I also tested by not deallocating the buffer. Works like a charm. Have you checked your gcc version or could it be a 32bits issue on your system?

Image
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: ASM junk error

Post by Munair »

Also, I don't think the error occurs where you pointed to

Code: Select all

mov eax, dword ptr [a]     <--- HERE
Looking at your screenshot, it seems that PTR PTR isn't accepted at the stack frame (ebp-24).
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: ASM junk error

Post by Cpcdos »

Thank you for replies guys !
I think that effectively, Intel syntax in GAS used to be quite buggy (And GCC generation have same problem)
Finally, i've used

Code: Select all

Dim pp As ubyte ptr = cptr(Ubyte Ptr, @MyVariable)
dim result as Uinteger = cuint(pp[0]) Shl 24 Or cuint(pp[1]) Shl 16 Or cuint(pp[2]) Shl  8 Or cuint(pp[3])
Thank you all!

Regards
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: ASM junk error

Post by MrSwiss »

Do yourself a favor, and change from UInteger to ULong (compatibility: FBC 32/64):

Code: Select all

Dim pp As ubyte ptr = cptr(Ubyte Ptr, @MyVariable)    ' OK
dim result as Uinteger = cuint(pp[0]) Shl 24 Or cuint(pp[1]) Shl 16 Or cuint(pp[2]) Shl  8 Or cuint(pp[3])  ' NOK (breaks in FBC 64)
Dim result As ULong = CULng(pp[0]) Shl 24 Or CULng(pp[1]) Shl 16 Or CULng(pp[2]) Shl 8 Or CULng(pp[3])  ' OK (both versions of FBC)
The same thing, as a Function:

Code: Select all

Declare Function SwapULong(ByVal in As ULong) As ULong

Const As ULong  tst1 = &hFF7F0F00, tst2 = &h01020304

Width 80, 25
Print Hex(tst1, 8), Hex(tst2, 8)
Print
Print "swapped bytes:"
Print
Print Hex(SwapULong(tst1), 8), Hex(SwapULong(tst2), 8)
Print
Print
Print "press a key, to EXIT! ";
Sleep : End 0

Function SwapULong(ByVal in As ULong) As ULong
    Swap CPtr(UByte Ptr, @in)[3], CPtr(UByte Ptr, @in)[0]
    Swap CPtr(UByte Ptr, @in)[2], CPtr(UByte Ptr, @in)[1]
    Return in
End Function
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: ASM junk error

Post by Cpcdos »

Okay thank you!


Regards
Post Reply