Is anyone using freebasic as a macro assembler?

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
vvanag
Posts: 3
Joined: Mar 28, 2025 19:49

Is anyone using freebasic as a macro assembler?

Post by vvanag »

Freebasic with inline asm sounds as a masm alternative, am I right?
RetardedAndProud
Posts: 35
Joined: Jun 09, 2024 18:26

Re: Is anyone using freebasic as a macro assembler?

Post by RetardedAndProud »

vvanag wrote: Mar 28, 2025 19:57 Freebasic with inline asm sounds as a masm alternative, am I right?
No.

For one example...

Code: Select all

DIM i AS INTEGER

FOR i = 0 TO 99
	ASM
		nop
	END ASM
NEXT i
Will not inline 100 nop's into the compiled code, it loops over 100 single nop intructions.
Neither specifying -funroll-all-loops to gcc will produce the desired outcome.
vvanag
Posts: 3
Joined: Mar 28, 2025 19:49

Re: Is anyone using freebasic as a macro assembler?

Post by vvanag »

So it is something fixable in Freebasic.
RetardedAndProud
Posts: 35
Joined: Jun 09, 2024 18:26

Re: Is anyone using freebasic as a macro assembler?

Post by RetardedAndProud »

Fixable?

I think that would turn FreeBASIC into something akin to an Acorn/BBC BASIC with it's inbuilt assembler, is that what you are thinking?
If so, just use BBCSDL/BB4W.

You can always include GAS directives (.rept & .endr) for example into the assembly block thus...

This would produce the correct/desired output that my first "example" wouldn't by using GAS to do the inlining.

Code: Select all

ASM
    .rept 100
    nop
    .endr
END ASM
END

Or, for example...

Code: Select all

DIM a AS INTEGER

a = 0

ASM
    .rept 100
    mov rax,[a]
    add rax,69
    mov [a],rax
    .endr
END ASM

PRINT a

END
BasicCoder2
Posts: 3955
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Is anyone using freebasic as a macro assembler?

Post by BasicCoder2 »

Just received these error message 100 times,
C:\FreeBASIC_CODE\ASM_ADD.asm: Assembler messages:
C:\FreeBASIC_CODE\ASM_ADD.asm:28: Error: too many memory references for `mov'
C:\FreeBASIC_CODEt\ASM_ADD.asm:28: Error: ambiguous operand size for `add'


The word "add" is reserved?

Put [ target, ] [ STEP ] ( x,y ), source [ ,( x1,y1 )-( x2,y2 ) ], Add[ ,multiplier ]
RetardedAndProud
Posts: 35
Joined: Jun 09, 2024 18:26

Re: Is anyone using freebasic as a macro assembler?

Post by RetardedAndProud »

BasicCoder2 wrote: Mar 29, 2025 17:32 Just received these error message 100 times,
C:\FreeBASIC_CODE\ASM_ADD.asm: Assembler messages:
C:\FreeBASIC_CODE\ASM_ADD.asm:28: Error: too many memory references for `mov'
C:\FreeBASIC_CODEt\ASM_ADD.asm:28: Error: ambiguous operand size for `add'


The word "add" is reserved?

Put [ target, ] [ STEP ] ( x,y ), source [ ,( x1,y1 )-( x2,y2 ) ], Add[ ,multiplier ]
Sorry, I'm unable to help regarding Windows (mingw) builds of FreeBASIC.
Just for the record, the above code is Linux x86_64 tested only in its current state. For 32bit the registers and maybe pointer sizes will need changing/prefixing.

Again, sorry!
vvanag
Posts: 3
Joined: Mar 28, 2025 19:49

Re: Is anyone using freebasic as a macro assembler?

Post by vvanag »

RetardedAndProud wrote: Mar 29, 2025 14:38 Fixable?

I think that would turn FreeBASIC into something akin to an Acorn/BBC BASIC with it's inbuilt assembler, is that what you are thinking?
If so, just use BBCSDL/BB4W.

BBC BASIC is not open source and it is interpreted.
Post Reply