Asm in Bmax?

BlitzMax Forums/BlitzMax Programming/Asm in Bmax?

Defoc8(Posted 2006) [#1]
ok..ive looked at the assembly output generated by
bmax - its great that you can access this. However, i have
no idea how you go about writing assembly routines for
use in bmax? - has anyone managed to develop any
8086 flat assembly functions that link correctly with
bmax?


Byteemoz(Posted 2006) [#2]
From the docs:
You can use the Import command to add certain non-BlitzMax source files to your projects, and the Extern command to make the functions in those files available to BlitzMax applications.

The currently supported non-BlitzMax source file types are: .c (C); .cpp (C++); .cxx (C++); .m (ObjectiveC); and .s (Assembler).

BlitzMax will use the GNU compiler tools to compile C, C++ and ObjectiveC files, and either the 'fasm' assembler for x86 assembly or GNU assembler for PowerPC assembly.


And it works like that:
square.bmx :
Import "square.s"

Extern
	Function MySquare:Int(Val:Int) ' the actual name in "square.s" is "_MySquare"
EndExtern

Notify MySquare(7)

square.s :
	format	MS COFF
	public	_MySquare
	section	"code" code

_MySquare:
	push	ebp
	mov	ebp,esp
	mov	eax,dword [ebp+8]
	imul	eax,eax
	mov	esp,ebp
	pop	ebp
	ret


-- Byteemoz


Defoc8(Posted 2006) [#3]
thanks for that :]